mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-24 10:16:59 -06:00
Units: inches show four decimals, as InDesign's fields
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a930276fd7
commit
a8388df9e8
@@ -347,6 +347,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.m
|
||||
|
||||
Newest first.
|
||||
|
||||
- 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.
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user