diff --git a/crates/doc/src/tests/units.rs b/crates/doc/src/tests/units.rs index fd8690a8ff..96fe4aab69 100644 --- a/crates/doc/src/tests/units.rs +++ b/crates/doc/src/tests/units.rs @@ -121,6 +121,7 @@ fn x_is_a_multiplication_sign() { (Unit::Points, "2p×3", 72.0), // Text that used to be refused now reads as a product. (Unit::Points, "8.5x11 in", 93.5 * 72.0), + (Unit::Points, "0x10", 0.0), ] { let got = u.parse(s).unwrap_or_else(|| panic!("{u:?} can't read `{s}`")); assert!((got - want).abs() < 1e-9, "{u:?}: `{s}` → {got}, want {want}"); diff --git a/crates/doc/src/units.rs b/crates/doc/src/units.rs index c896ee5ee8..f61319326c 100644 --- a/crates/doc/src/units.rs +++ b/crates/doc/src/units.rs @@ -151,17 +151,18 @@ impl Unit { /// Parse `12`, `12pt`, `1in`, `3 mm`, `2p6` (picas+points), `6q` (Q) and `6h` (Ha), simple /// `+ - * /` arithmetic. /// + /// A unit after a `*` or `/` operand measures the whole expression (`1080/2 px` is 540 px), so + /// math typed before a field's unit suffix works. After `*` or `/`, a percentage scales the term + /// before it (`3cm*50%` is 1.5 cm, `3cm/50%` is 6 cm). After `+` or `-`, it adds or takes away + /// that share of everything before it (`50pt+25%` is 62.5 pt, `100pt+20pt-50%` is 60 pt). A + /// percentage on its own (`50%`) reads as nothing. + /// /// `x`, `X` and `×` multiply as `*` does (`10x2` is 20, `2x3 mm` is 6 mm), except a lowercase /// `x` right after a `p`, which is the `px` suffix (`2px x 3` is 6 px, and `2px3` reads as /// nothing; write `2p x 3` for picas). `X` and `×` after a `p` multiply (`2pX3` is 6 picas). /// - /// A unit after a `*` or `/` operand measures the whole expression (`1080/2 px` is 540 px), - /// so math typed before a field's unit suffix works. After `*` or `/`, a percentage scales the - /// term before it (`3cm*50%` is 1.5 cm, `3cm/50%` is 6 cm). After `+` or `-`, it adds or takes - /// away that share of everything before it (`50pt+25%` is 62.5 pt, `100pt+20pt-50%` is 60 - /// pt). A percentage on its own (`50%`) reads as nothing. - /// - /// Text with more than 128 [`arithmetic_signs`] reads as nothing. + /// Text with more than 128 `+ - * /` signs ([`arithmetic_signs`], a multiplication sign counted + /// as `*`) reads as nothing. pub fn parse(self, s: &str) -> Option { if arithmetic_signs(s) > MAX_MEASURE_OPERATORS { return None; diff --git a/crates/engine/src/tests/pathops.rs b/crates/engine/src/tests/pathops.rs index f20af794c4..dff77c1ce4 100644 --- a/crates/engine/src/tests/pathops.rs +++ b/crates/engine/src/tests/pathops.rs @@ -1121,6 +1121,10 @@ fn path_commands_refuse_a_param_of_the_wrong_type() { s.execute("select.set", &json!({"ids": [a.0]})).unwrap(); let r = ids(&s.execute("object.path.offsetPath", &json!({"offset": "0.1 in", "joins": "Bevel"})).unwrap()); assert!(close(bounds(&s, r[0]), Rect::new(92.8, 92.8, 157.2, 147.2), 1e-2), "{:?}", bounds(&s, r[0])); + // A product with a unit, which the offset used to refuse: 0.05x2 in is 0.1 in. + s.execute("select.set", &json!({"ids": [a.0]})).unwrap(); + let r = ids(&s.execute("object.path.offsetPath", &json!({"offset": "0.05x2 in", "joins": "Bevel"})).unwrap()); + assert!(close(bounds(&s, r[0]), Rect::new(92.8, 92.8, 157.2, 147.2), 1e-2), "{:?}", bounds(&s, r[0])); // Null switches keep Clean Up's defaults, which remove the stray point. let r = s.execute("object.path.cleanUp", &json!({"strayPoints": null, "unpaintedObjects": null, "emptyTextPaths": null})).unwrap(); assert_eq!(r["removed"], 1); diff --git a/docs/mcp.md b/docs/mcp.md index 13b1d089fb..8a413a7217 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7593,8 +7593,8 @@ Commands take and return lengths in points (the distances of `object.path.offset string takes the same arithmetic as the desktop app's fields, where `%` is a share of the value before it: `"200mm*50%"` is 100 mm and `"50pt+25%"` is 62.5 pt. `x`, `X` and `×` multiply as `*` does (`"2x3 mm"` is 6 mm), except a lowercase `x` right after a `p`, which is the `px` suffix (`"2px3"` is not read; `"2p x 3"` and `"2pX3"` -are 6 picas). A string such as `"8.5x11 in"` reads as one length, 93.5 in. -A length string with more than 128 `+ - * /` signs (each multiplication sign counts) is not read as a length. The units +are 6 picas). A string such as `"8.5x11 in"` reads as one length, 93.5 in, and `"0x10"` reads as 0 pt. A length +string with more than 128 `+ - * /` signs (each multiplication sign counts) is not read as a length. The units only change what the UI shows and how it reads typed numbers. Preferences ▸ Units has four: General (rulers, positions and sizes, the Info panel, dialog distances, canvas measurement labels), Stroke (weights, dashes), Type (font size, leading, baseline shift) and East Asian Type (no field uses it yet). General is the active document's units