Merge PR #1073: Units: inches show four decimals, as InDesign's fields (0.1667 in, 8.2677 in)

This commit is contained in:
aiongg
2026-10-16 03:53:24 +00:00
3 changed files with 18 additions and 3 deletions
+1
View File
@@ -438,6 +438,7 @@ Newest first.
- **2026-10-15** · The CJK leading model and character alignment take effect only in paragraphs set with a Japanese composer (`HL Composer J`, `HL Single J`), which IDML import and export keep: Western and Arabic paragraphs set baseline to baseline on the Roman baseline, a paragraph switched to a Japanese composer gets the file's Aki Below spacing, and under Aki Below a line's leading is the space below it. No readiness percentage change.
- **2026-10-15** · Document pages follow their parent page's margins and columns unless margins were set on the page itself (`Page::local_margins`): applying a different parent gives a page that parent's margins, a page that changes side after an insert takes the other parent page's, and a page given margins equal to its parent's keeps them when the parent changes. IDML import and older files mark pages whose margins differ from their parent as their own. No readiness percentage change.
- **2026-10-15** · Start-up picks the GPU that drives the display (or the kind `WGPU_POWER_PREF` or the adapter `WGPU_ADAPTER_NAME` names), and when a start-up fails or hangs it restarts on the next adapter, then the next backend, then a software renderer, keeping recovered documents; start-up errors are logged to standard error and the log file (#273, #334). No readiness percentage change.
- 2026-10-15: Measures in inches show four decimals, as InDesign's fields do (A4 is 8.2677 × 11.6929 in, a 1p0 gutter 0.1667 in); other units keep three.
- **2026-10-14** · The Type tool draws a new text frame over a locked empty frame, as InDesign does, instead of turning the locked frame into a text frame. No readiness percentage change.
- **2026-10-14** · 100% black shows as pure black on screen by default, as InDesign's Appearance of Black does out of the box (Display All Blacks as Rich Black); Preferences › Appearance of Black › Display All Blacks Accurately still shows it as the dark grey it prints, and a saved choice is kept. No readiness percentage change.
- **2026-10-14** · Pathfinder keeps the frontmost object, as InDesign does: a photo placed over shapes and intersected with them shows through the shapes (it was dropped, and the shapes kept their black fill); Add, Exclude Overlap and Minus Back take the front object's fill too, Subtract still keeps the back one. No readiness percentage change.
+15 -1
View File
@@ -258,7 +258,10 @@ fn parse_single(tok: &str, default: Unit, percent_base: Option<f64>) -> Option<f
/// Format a value (points) in `unit` the way InDesign fields show it: up to 3 decimals, trailing
/// zeros trimmed; picas as `3p6`, ciceros as `2c4`.
pub fn format_measure(pt: f64, unit: Unit) -> String {
format_measure_prec(pt, unit, 3)
// As InDesign shows them: inches to four decimals (a 1p gutter is 0.1667 in, A4 is
// 8.2677 in wide), the other units to three.
let decimals = if matches!(unit, Unit::Inches | Unit::InchesDecimal) { 4 } else { 3 };
format_measure_prec(pt, unit, decimals)
}
pub fn format_measure_prec(pt: f64, unit: Unit, decimals: usize) -> String {
@@ -301,6 +304,17 @@ mod tests {
(a - b).abs() < 1e-6
}
/// Inches show four decimals, as InDesign's fields do; other units three.
#[test]
fn inches_show_four_decimals() {
assert_eq!(format_measure(12.0, Unit::Inches), "0.1667 in");
assert_eq!(format_measure(210.0 * PT_PER_MM, Unit::Inches), "8.2677 in");
assert_eq!(format_measure(612.0, Unit::Inches), "8.5 in");
assert_eq!(format_measure(9.0, Unit::Inches), "0.125 in");
assert_eq!(format_measure(10.0, Unit::Millimeters), "3.528 mm");
assert_eq!(format_measure(10.0, Unit::Points), "10 pt");
}
#[test]
fn plain_and_units() {
assert!(close(p("12"), 12.0));
+2 -2
View File
@@ -5,7 +5,7 @@
//! section headers and 1.5 pt section rules.
use designcraft_geom::Unit;
use designcraft_geom::units::{format_measure_prec, parse_measure};
use designcraft_geom::units::{format_measure, parse_measure};
use egui::{Color32, Rect, Response, Sense, Stroke, StrokeKind, Ui, pos2, vec2};
use crate::theme::Tokens;
@@ -35,7 +35,7 @@ pub enum NumKind<'a> {
impl NumKind<'_> {
pub fn format(&self, v: f64) -> String {
match *self {
NumKind::Measure(u) => format_measure_prec(v, u, 3),
NumKind::Measure(u) => format_measure(v, u),
NumKind::Number { suffix, decimals } => {
let s = format!("{v:.decimals$}");
let s = if s.contains('.') { s.trim_end_matches('0').trim_end_matches('.').to_string() } else { s };