From 51d09113f72df42fe6b2fc4ddfe912d0dd454aa2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 16:57:23 -0800 Subject: [PATCH 1/3] Fields: x multiplies in value fields, as * does MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Value fields and length strings read `x`, `X` and `×` as a multiplication sign: `10x2` is 20, `2x3 mm` is 6 mm and `3cmx50%` is 1.5 cm. A lowercase `x` right after a `p` stays the `px` unit, so `2px x 3` is 6 px and `2px3` is not read. The change is in `Unit::parse` and `parse_number`, so every field that reads its text through them takes it. Each sign counts toward the 128-sign limit, which is checked before the text is copied. Docs: docs/mcp.md, docs/ui-parity.md, docs/target-app-parity.md. --- crates/doc/src/tests/units.rs | 42 +++++++++++++++++++++- crates/doc/src/units.rs | 51 ++++++++++++++++++++++++--- crates/ui-egui/src/tests/numfields.rs | 2 ++ crates/ui-egui/src/widgets.rs | 11 ++++++ docs/mcp.md | 5 +-- docs/target-app-parity.md | 1 + docs/ui-parity.md | 2 +- 7 files changed, 105 insertions(+), 9 deletions(-) diff --git a/crates/doc/src/tests/units.rs b/crates/doc/src/tests/units.rs index c53f60a227..9696bf54d0 100644 --- a/crates/doc/src/tests/units.rs +++ b/crates/doc/src/tests/units.rs @@ -94,11 +94,51 @@ fn a_very_long_expression_reads_as_nothing() { } } +/// `x`, `X` and `×` multiply as `*` does (#8435), units and percentages included; a lowercase `x` +/// right after a `p` stays the `px` unit. +#[test] +fn x_is_a_multiplication_sign() { + let (mm, cm) = (72.0 / 25.4, 72.0 / 2.54); + for (u, s, want) in [ + (Unit::Points, "10x2", 20.0), + (Unit::Points, "10 x 2", 20.0), + (Unit::Points, "10X2", 20.0), + (Unit::Points, "10×2", 20.0), + (Unit::Points, "10x-2", -20.0), + (Unit::Points, "10/2x5", 25.0), + (Unit::Points, "1+2x3", 7.0), + (Unit::Millimeters, "2x3 mm", 6.0 * mm), + (Unit::Points, "2x3mm", 6.0 * mm), + (Unit::Points, "3mm x 2", 6.0 * mm), + (Unit::Centimeters, "3cmx50%", 1.5 * cm), + (Unit::Points, "2p x 2", 48.0), + (Unit::Points, "10px", 10.0), + (Unit::Points, "2px x 3", 6.0), + (Unit::Points, "2pxx3", 6.0), + (Unit::Millimeters, "4x3 px", 12.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}"); + } + for s in ["x", "x2", "5x", "5 x x 2", "xx", "2px3"] { + assert_eq!(Unit::Points.parse(s), None, "{s}"); + } + assert_eq!(crate::parse_number("45x2"), Some(90.0)); + assert_eq!(crate::parse_number(" 45 X 2 "), Some(90.0)); + assert_eq!(crate::parse_number("45×2"), Some(90.0)); + assert_eq!(crate::parse_number("90x-1"), Some(-90.0)); + assert_eq!(crate::parse_number("x"), None); + // Each sign counts toward the 128-sign limit as a `*` would. + assert_eq!(Unit::Points.parse(&format!("1{}", "x1".repeat(128))), Some(1.0)); + assert_eq!(Unit::Points.parse(&format!("1{}", "x1".repeat(129))), None); + assert_eq!(crate::parse_number(&format!("1{}", "×1".repeat(129))), None); +} + proptest! { /// Field text made of digits, operators, `%`, spaces and unit letters reads as a finite value /// or as nothing and does not panic. #[test] - fn arithmetic_text_reads_as_a_finite_value_or_nothing(s in "[0-9.+*/% ptxinmcfyd-]{0,24}") { + fn arithmetic_text_reads_as_a_finite_value_or_nothing(s in "[0-9.+*/% ptxXinmcfyd×-]{0,24}") { for u in Unit::ALL { if let Some(v) = u.parse(&s) { prop_assert!(v.is_finite(), "{u:?}: `{s}` → {v}"); diff --git a/crates/doc/src/units.rs b/crates/doc/src/units.rs index 5fabfece65..e3bd8520a7 100644 --- a/crates/doc/src/units.rs +++ b/crates/doc/src/units.rs @@ -151,18 +151,31 @@ impl Unit { /// Parse `12`, `12pt`, `1in`, `3 mm`, `2p6` (picas+points), `6q` (Q) and `6h` (Ha), simple /// `+ - * /` arithmetic. /// + /// `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). + /// /// 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 `+ - * /` signs reads as nothing. + /// Text with more than 128 `+ - * /` signs (a multiplication sign counts as `*`) reads as nothing. pub fn parse(self, s: &str) -> Option { - if s.chars().filter(|c| matches!(c, '+' | '-' | '*' | '/')).count() > MAX_MEASURE_OPERATORS { + let mut prev = None; + let operators = s + .chars() + .filter(|&c| { + let operator = matches!(c, '+' | '-' | '*' | '/') || is_times(c, prev); + prev = Some(c); + operator + }) + .count(); + if operators > MAX_MEASURE_OPERATORS { return None; } - parse_measure(s, self).filter(|v| v.is_finite()) + parse_measure(×_as_asterisks(s), self).filter(|v| v.is_finite()) } /// The value naming this unit in the Units preferences (`points`, `millimeters`, /// `feetInches`). @@ -215,6 +228,33 @@ impl Unit { /// The most `+ - * /` signs [`Unit::parse`] reads in one text. const MAX_MEASURE_OPERATORS: usize = 128; +/// Is `c`, after `prev`, a multiplication sign typed as `x`, `X` or `×`? A lowercase `x` right +/// after a `p` is the `px` suffix (`2px x 3`), also where a number follows it (`2px3`). +fn is_times(c: char, prev: Option) -> bool { + matches!(c, 'X' | '×') || (c == 'x' && prev != Some('p')) +} + +/// `s` with each multiplication sign ([`is_times`]) written as `*` (`10 x 2` is `10 * 2`); text +/// without one is not copied. +fn times_as_asterisks(s: &str) -> std::borrow::Cow<'_, str> { + let mut prev = None; + let any = s.chars().any(|c| { + let times = is_times(c, prev); + prev = Some(c); + times + }); + if !any { + return s.into(); + } + let mut out = String::with_capacity(s.len()); + let mut prev = None; + for c in s.chars() { + out.push(if is_times(c, prev) { '*' } else { c }); + prev = Some(c); + } + out.into() +} + fn parse_measure(s: &str, default: Unit) -> Option { let s = s.trim(); // Simple arithmetic on the right (Illustrator fields accept "10+5", "100/2", "3in*2"). @@ -317,9 +357,10 @@ fn percent(s: &str) -> Option { } /// A unitless field value (percent, degrees, counts) with the same `+ - * /` arithmetic as -/// [`Unit::parse`] (`45*2`, `100/3`); text other than digits, `.` and operators reads as nothing. +/// [`Unit::parse`] (`45*2`, `45x2`, `100/3`); text other than digits, `.` and operators reads as +/// nothing. pub fn parse_number(s: &str) -> Option { - if !s.chars().all(|c| c.is_ascii_digit() || " .+-*/".contains(c)) { + if !s.chars().all(|c| c.is_ascii_digit() || " .+-*/xX×".contains(c)) { return None; } // A leading `+` is a sign (`+5`), as a plain number read it. diff --git a/crates/ui-egui/src/tests/numfields.rs b/crates/ui-egui/src/tests/numfields.rs index 689a0e3a04..3b7c2d157e 100644 --- a/crates/ui-egui/src/tests/numfields.rs +++ b/crates/ui-egui/src/tests/numfields.rs @@ -778,6 +778,8 @@ fn bare_numbers_in_picas_fields_are_points_when_the_preference_says_so() { assert_eq!(typed(&mut f, pc, "2p6"), Some(30.0), "picas and points as typed"); assert_eq!(typed(&mut f, pc, "1in"), Some(72.0), "a typed unit wins"); assert_eq!(typed(&mut f, pc, "10+5"), Some(15.0), "arithmetic in points too"); + assert_eq!(typed(&mut f, pc, "10x2"), Some(20.0), "x multiplies (#8435)"); + assert_eq!(typed(&mut f, mm, "2 x 3"), Some(mm.to_pt(6.0)), "x multiplies in millimetres"); assert_eq!(typed(&mut f, mm, "12"), Some(mm.to_pt(12.0)), "a millimetre field keeps millimetres"); widgets::set_bare_numbers_are_points(&f.ctx, false); assert_eq!(typed(&mut f, pc, "12"), Some(pc.to_pt(12.0)), "off: picas"); diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index fb291b8525..092d3d1be5 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -664,6 +664,17 @@ mod field_number_tests { assert_eq!(field_number("(0,125)", "", true), Some(0.125)); assert_eq!(field_number("12,5%", "%", false), Some(12.5)); } + + /// `x` multiplies in a unitless field as `*` does (#8435), next to a suffix, `%` and a decimal + /// comma too. + #[test] + fn x_multiplies_in_a_unitless_field() { + assert_eq!(field_number("45x2", "", false), Some(90.0)); + assert_eq!(field_number("45x2°", "°", false), Some(90.0)); + assert_eq!(field_number("50% x 2", "%", false), Some(100.0)); + assert_eq!(field_number("1,5x2", "", false), Some(3.0)); + assert_eq!(field_number("(10x2)", "", true), Some(20.0)); + } } #[cfg(test)] diff --git a/docs/mcp.md b/docs/mcp.md index 4c1b661f42..2a3ca1cf3b 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7310,8 +7310,9 @@ report warn about it). Commands take and return lengths in points (the distances of `object.path.offsetPath`, `object.path.simplify`, `object.path.splitIntoGrid` and `text.setStyle` `size`/`leading` also take a string with a unit, `"5 mm"`). A length 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. A length string with more than 128 `+ - * /` signs is not read -as a length. The units +`"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"` is 6 picas). +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 diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index ef83de54ad..dab9b3236b 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -967,6 +967,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - With automation read roots in force, `svgInteractivity.info`, `addFile` and `removeFile`, the JavaScript Files dialog in a frame a request drives and `ui_inspect`'s selected file name a linked JavaScript file outside the roots by its file name alone, as `document.json` does; `removeFile` unlinks it by that name and refuses a name that fits more than one linked file (`tests/interactivity.rs`). - Numeric fields keep the pointer's pressed character as the text-drag start when movement exceeds the click threshold (#1326); a completed focus click selects the unit too. Pixel/point, plain and optional fields are regression-tested in both directions, before/after focus, with replacement text; keyboard focus, double-click, arrows and wheel keep their prior behavior. Native egui input confirms partial replacement gives 17 px instead of 700 px, one Undo/Redo, window captures and an exact saved-document read in a separate CLI process. A focus click released more than 1 pt from its press keeps the caret, and a tap within 1 pt still selects all (#6659; short-drag and jitter-tap regressions in `tests/numfields.rs`). - Unit fields and length strings take `%` in arithmetic: `3cm*50%` reads as 1.5 cm, and `50pt+25%` reads as 62.5 pt. + - Value fields and length strings read `x` as a multiplication sign, as they read `*` (#8435; the help's "Calculate values in a panel or dialog box" lists `x` for multiplication: [help PDF, archived](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf)). `X` and `×` also multiply; that is VectorCraft's own choice. `10x2` reads as 20 and `2x3 mm` as 6 mm. A lowercase `x` right after a `p` stays the `px` unit (`2px x 3` is 6 px, and `2px3` is not read). Tests: `x_is_a_multiplication_sign` in `crates/doc/src/tests/units.rs`. - The contextual task bar's handle drags it anywhere on the canvas (kept whole on it as the window resizes); unpinned it keeps that offset as it follows the selection, and its More Options menu hides it, pins its position across selection changes (`window.taskBar.pin`), resets it under the selection (`window.taskBar.reset`) and shows the Properties panel. As in Illustrator the position isn't kept across launches. Not done: the bar's variants for other tools (only the selection tools, the Type tools, the basic shape tools, the Smooth tool and the Artboard tool show it). - A click on another object moves the contextual task bar under it without hiding it for the press; it gives way only to a drag (#4681). - With one image selected, the contextual task bar offers Image Trace, which traces the image at once with the Default preset (the Image Trace panel is left as it was), and Crop Image; with an Image Trace object it offers Expand, which keeps only the traced paths. This follows Illustrator's bar: for a selected image it includes Image Trace, Retype and Crop Image, and traced artwork can be expanded from it ([Contextual Task Bar announcement](https://community.adobe.com/announcements-651/contextual-task-bar-in-illustrator-2025-quick-actions-when-you-need-them-1546580)). Offset Path and Simplify, which don't apply to an image, aren't offered for one. Not done: Retype, which the app doesn't have. diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 4182189c4a..6f6c9fcffa 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -308,7 +308,7 @@ tools, never checked side by side) isn't captured row by row. | Fields commit what was typed on a click away or a move to another field, as Enter does; Escape discards it | done | #1787 | | Number fields: Up/Down step, Shift ×10, Cmd/Ctrl ÷10, wheel over a hovered field without a click; steps, the wheel and label scrubs stop at the field's bounds (a stroke weight at 0, a miter limit at 1) | done | Shift+arrow in the Stroke weight field doesn't step by 10 (#991); bounds #3370. The field takes the wheel only when the pointer was moved onto it after the field last moved or was covered by a window or overlay, and the wheel stream began there; a stream that began elsewhere stays there until 0.5 s pass with no wheel input or the pointer is pressed on a field, so a panel scrolled under a still pointer keeps scrolling past the field. This rule and its 0.5 s are VectorCraft's choices. | | Numeric spinner arrows step once on a click and keep repeating while held with the mouse | done | #6307; headless test `a_held_spinner_arrow_repeats` holds past egui's click timeout and checks release. | -| Arithmetic in fields (`+ - * /`, and `%` of the value before it: `3cm*50%`, `50pt+25%`) and unit suffixes (`3 mm`, `1in`, `2p6`) | done | `Unit::parse`; mixed units in one expression not verified | +| Arithmetic in fields (`+ - * /`, `x`, `X` or `×` for `*`, and `%` of the value before it: `3cm*50%`, `50pt+25%`) and unit suffixes (`3 mm`, `1in`, `2p6`) | done | `Unit::parse`; mixed units in one expression not verified | | Numeric fields: focus click selects the whole value; dragging selects from the pressed character | partial | #1326; select-all waits for click release; px/pt/plain/optional fields, both directions and replacement text tested; native API input, 17 px partial replacement, Undo/Redo, saved-file round trip and screenshots verified; Tab, double-click, arrows and wheel preserved; a release more than 1 pt from the press keeps the caret, a tap within 1 pt selects all (#6659) | | Units: pt, pc, in, mm, cm, px, ft-in, m, yd, ft; General/Stroke/Type units | done | units preference reverting to points on SVG output reported (#864). A file that records no units (PDF, EPS or `.ai` without ruler units, raster images, metafiles, Affinity files) opens and reverts in General units; native, SVG and DXF files and a `.ai` or EPS with ruler units keep theirs, as a [Community Expert's answer](https://community.adobe.com/questions-652/change-units-from-points-to-inches-won-t-stick-765372) describes (#5820) | | Units › East Asian Type (Q and Ha) | done | #394: `unitsAsianType` offers every unit and Q and Ha, a quarter of a millimetre each ([Scripting Guide's Measurement Units](https://ai-scripting.docsforadobe.dev/scripting/measurementUnits/): 0.709 pt per Q; [InDesign's unit notation](https://helpx.adobe.com/in/indesign/desktop/layout-and-grid-tools/rulers-and-measure-tools/change-ruler-measurement-units.html): `q`, `h`); only it lists Q and Ha. The public pages do not say which fields use it, so no field uses it yet and that waits for a source. Tests `q_and_ha_are_a_quarter_millimetre`, `east_asian_type_unit_*` | From 9ffca655cddf9082059ea015ba509a4320803584 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 21:15:25 -0800 Subject: [PATCH 2/3] Fields: count x signs in the Unit Converter's limit too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit addon.units.convert reads its value through Unit::parse, so after the merge of main it takes x, X and × as multiplication signs as well. Its 128-sign limit counted only + - * /. The new vectorcraft_doc::arithmetic_signs counts each multiplication sign as a *, and both Unit::parse and the converter use it. - The converter's params text and docs/mcp.md list the signs. - Tests cover 2pX3 and 2p×3 (6 picas), 8.5x11 in (refused before, now 93.5 in) and the converter's reading and limit. - The test message says "millimeters", and the doc comments wrap at the file's width. --- crates/doc/src/lib.rs | 2 +- crates/doc/src/tests/units.rs | 7 ++++ crates/doc/src/units.rs | 38 ++++++++++++--------- crates/engine/src/cmd/addons/units.rs | 12 +++---- crates/engine/src/cmd/addons/units/tests.rs | 6 ++++ crates/ui-egui/src/tests/numfields.rs | 2 +- docs/mcp.md | 10 +++--- docs/ui-parity.md | 2 +- 8 files changed, 49 insertions(+), 30 deletions(-) diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs index 18974db32a..ddea80c5f6 100644 --- a/crates/doc/src/lib.rs +++ b/crates/doc/src/lib.rs @@ -168,7 +168,7 @@ use limits::MAX_NEXT_ID; pub use limits::{DocError, FORMAT_VERSION, MAX_COORD}; pub use records::{ImageBlob, MaskEdit, NewArtIds, SavedSelection, SavedView, SvgFilter, Symbol, SymbolEdit}; pub use stored_art::{StoredPlace, StoredRoot}; -pub use units::{ColorMode, Unit, decimal_point, finite_in_every_unit, parse_number}; +pub use units::{ColorMode, Unit, arithmetic_signs, decimal_point, finite_in_every_unit, parse_number}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Document { diff --git a/crates/doc/src/tests/units.rs b/crates/doc/src/tests/units.rs index 9696bf54d0..fd8690a8ff 100644 --- a/crates/doc/src/tests/units.rs +++ b/crates/doc/src/tests/units.rs @@ -116,6 +116,11 @@ fn x_is_a_multiplication_sign() { (Unit::Points, "2px x 3", 6.0), (Unit::Points, "2pxx3", 6.0), (Unit::Millimeters, "4x3 px", 12.0), + // Only a lowercase x after a p is the px suffix. + (Unit::Points, "2pX3", 72.0), + (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), ] { 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}"); @@ -132,6 +137,8 @@ fn x_is_a_multiplication_sign() { assert_eq!(Unit::Points.parse(&format!("1{}", "x1".repeat(128))), Some(1.0)); assert_eq!(Unit::Points.parse(&format!("1{}", "x1".repeat(129))), None); assert_eq!(crate::parse_number(&format!("1{}", "×1".repeat(129))), None); + assert_eq!(crate::arithmetic_signs("1+2x3X4×5*6/7-8"), 7); + assert_eq!(crate::arithmetic_signs("2px x 3"), 1); } proptest! { diff --git a/crates/doc/src/units.rs b/crates/doc/src/units.rs index 45af1d172b..c896ee5ee8 100644 --- a/crates/doc/src/units.rs +++ b/crates/doc/src/units.rs @@ -153,26 +153,17 @@ impl Unit { /// /// `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). + /// 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. + /// 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 `+ - * /` signs (a multiplication sign counts as `*`) reads as nothing. + /// Text with more than 128 [`arithmetic_signs`] reads as nothing. pub fn parse(self, s: &str) -> Option { - let mut prev = None; - let operators = s - .chars() - .filter(|&c| { - let operator = matches!(c, '+' | '-' | '*' | '/') || is_times(c, prev); - prev = Some(c); - operator - }) - .count(); - if operators > MAX_MEASURE_OPERATORS { + if arithmetic_signs(s) > MAX_MEASURE_OPERATORS { return None; } parse_measure(×_as_asterisks(s), self).filter(|v| v.is_finite()) @@ -228,6 +219,19 @@ impl Unit { /// The most `+ - * /` signs [`Unit::parse`] reads in one text. const MAX_MEASURE_OPERATORS: usize = 128; +/// The number of `+ - * /` signs in `s`, each multiplication sign typed as `x`, `X` or `×` +/// ([`Unit::parse`]) counted as a `*`. +pub fn arithmetic_signs(s: &str) -> usize { + let mut prev = None; + s.chars() + .filter(|&c| { + let sign = matches!(c, '+' | '-' | '*' | '/') || is_times(c, prev); + prev = Some(c); + sign + }) + .count() +} + /// Is `c`, after `prev`, a multiplication sign typed as `x`, `X` or `×`? A lowercase `x` right /// after a `p` is the `px` suffix (`2px x 3`), also where a number follows it (`2px3`). fn is_times(c: char, prev: Option) -> bool { diff --git a/crates/engine/src/cmd/addons/units.rs b/crates/engine/src/cmd/addons/units.rs index b5d844709a..4da4f68b79 100644 --- a/crates/engine/src/cmd/addons/units.rs +++ b/crates/engine/src/cmd/addons/units.rs @@ -10,7 +10,7 @@ mod tests; use serde_json::{Value, json}; -use vectorcraft_doc::{OrientedBox, Unit, decimal_point, finite_in_every_unit}; +use vectorcraft_doc::{OrientedBox, Unit, arithmetic_signs, decimal_point, finite_in_every_unit}; use vectorcraft_render::effects; use super::super::{CommandSpec, always, bad, cmd, has_selection}; @@ -22,8 +22,8 @@ const SELECTION_SIZE: &str = "addon.units.selectionSize"; const SHOWN_CHARS: usize = 64; /// The longest `value` or `unit` text `addon.units.convert` reads, in bytes. const MAX_TEXT_LEN: usize = 1024; -/// The most `+ - * /` signs `addon.units.convert` reads in one `value`: [`Unit::parse`] takes one -/// level of recursion per sign. +/// The most `+ - * /` signs `addon.units.convert` reads in one `value`, a multiplication sign +/// counted as a `*`: [`Unit::parse`] takes one level of recursion per sign. const MAX_OPERATORS: usize = 128; pub fn specs() -> Vec { @@ -33,7 +33,7 @@ pub fn specs() -> Vec { "Convert Units", [], None, - "{value: a length (a number, or text as a number field reads it, with a unit suffix and + - * / arithmetic: \"10mm\", \"1in/2\", \"2p6\", \"3cm*50%\"; a decimal comma reads as a point: \"0,5 mm\"; at most 1024 bytes and 128 operators), unit?: the unit of a number without a suffix (a unit's name, suffix or key: points, picas, inches, millimeters, centimeters, pixels, feetInches, meters, yards, feet, q, ha; default: points)} the length in every unit of Preferences › Units › East Asian Type, written as the number fields write it (rounded to 3 decimals in pt, px, picas, Q and Ha and to 4 in the others; pixels are points). Nothing in the document changes → {points, units: [{unit (its key), label, number (no suffix), text (with the suffix)}]}", + "{value: a length (a number, or text as a number field reads it, with a unit suffix and + - * / arithmetic, x, X or × multiplying as * does: \"10mm\", \"1in/2\", \"2p6\", \"3cm*50%\", \"2x3 mm\"; a decimal comma reads as a point: \"0,5 mm\"; at most 1024 bytes and 128 operators, each multiplication sign counted), unit?: the unit of a number without a suffix (a unit's name, suffix or key: points, picas, inches, millimeters, centimeters, pixels, feetInches, meters, yards, feet, q, ha; default: points)} the length in every unit of Preferences › Units › East Asian Type, written as the number fields write it (rounded to 3 decimals in pt, px, picas, Q and Ha and to 4 in the others; pixels are points). Nothing in the document changes → {points, units: [{unit (its key), label, number (no suffix), text (with the suffix)}]}", always, convert ), @@ -88,9 +88,9 @@ fn convert(_: &mut Session, p: &Value) -> Result { } /// Is `s` short enough to read: at most [`MAX_TEXT_LEN`] bytes and [`MAX_OPERATORS`] `+ - * /` -/// signs? +/// signs, a multiplication sign typed as `x`, `X` or `×` counted as a `*` ([`arithmetic_signs`])? fn readable(s: &str) -> bool { - s.len() <= MAX_TEXT_LEN && s.chars().filter(|c| matches!(c, '+' | '-' | '*' | '/')).count() <= MAX_OPERATORS + s.len() <= MAX_TEXT_LEN && arithmetic_signs(s) <= MAX_OPERATORS } /// `v` as an error message shows it: text cut at [`SHOWN_CHARS`] characters with "…", as JSON, diff --git a/crates/engine/src/cmd/addons/units/tests.rs b/crates/engine/src/cmd/addons/units/tests.rs index f914c53092..802fb5dfdf 100644 --- a/crates/engine/src/cmd/addons/units/tests.rs +++ b/crates/engine/src/cmd/addons/units/tests.rs @@ -76,6 +76,12 @@ fn values_read_as_number_fields_read_them() { assert!(near(pt(&mut s, json!({"value": "1,500+2", "unit": "mm"})), 3.5 * 72.0 / 25.4)); // A sum of 128 signs still reads. assert!(near(pt(&mut s, json!({"value": format!("1{}", "+1".repeat(128))})), 129.0)); + // x, X and × multiply as * does, and each counts toward the 128 signs. + assert!(near(pt(&mut s, json!({"value": "2x3 mm"})), 6.0 * 72.0 / 25.4)); + assert!(near(pt(&mut s, json!({"value": "10X2"})), 20.0)); + assert!(near(pt(&mut s, json!({"value": "0,5×4 in"})), 144.0)); + assert!(near(pt(&mut s, json!({"value": format!("1{}", "x1".repeat(128))})), 1.0)); + assert!(s.execute("addon.units.convert", &json!({"value": format!("1{}", "x1".repeat(129))})).is_err()); } #[test] diff --git a/crates/ui-egui/src/tests/numfields.rs b/crates/ui-egui/src/tests/numfields.rs index 3b7c2d157e..585c16ba2a 100644 --- a/crates/ui-egui/src/tests/numfields.rs +++ b/crates/ui-egui/src/tests/numfields.rs @@ -779,7 +779,7 @@ fn bare_numbers_in_picas_fields_are_points_when_the_preference_says_so() { assert_eq!(typed(&mut f, pc, "1in"), Some(72.0), "a typed unit wins"); assert_eq!(typed(&mut f, pc, "10+5"), Some(15.0), "arithmetic in points too"); assert_eq!(typed(&mut f, pc, "10x2"), Some(20.0), "x multiplies (#8435)"); - assert_eq!(typed(&mut f, mm, "2 x 3"), Some(mm.to_pt(6.0)), "x multiplies in millimetres"); + assert_eq!(typed(&mut f, mm, "2 x 3"), Some(mm.to_pt(6.0)), "x multiplies in millimeters"); assert_eq!(typed(&mut f, mm, "12"), Some(mm.to_pt(12.0)), "a millimetre field keeps millimetres"); widgets::set_bare_numbers_are_points(&f.ctx, false); assert_eq!(typed(&mut f, pc, "12"), Some(pc.to_pt(12.0)), "off: picas"); diff --git a/docs/mcp.md b/docs/mcp.md index 014636167e..13b1d089fb 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7592,7 +7592,8 @@ Commands take and return lengths in points (the distances of `object.path.offset `object.path.splitIntoGrid` and `text.setStyle` `size`/`leading` also take a string with a unit, `"5 mm"`). A length 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"` is 6 picas). +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 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 @@ -14025,9 +14026,10 @@ Unit Converter is a built-in add-on that shows one length in every unit at once Converter and in its panel (`window.panel {panel: "unitConverter"}`). Neither command changes the document. `addon.units.convert {value, unit?}` reads `value` as a number field reads it: a number, or text with a unit suffix and -`+ - * /` arithmetic (`"10mm"`, `"1in/2"`, `"2p6"`, `"1080/2 px"`, `"3cm*50%"`, `"13q"`), a decimal comma read as a point -(`"0,5 mm"`) and a single number with a thousands comma (`"1,000 mm"`) refused, in at most 1024 bytes with at most 128 `+ - * /` signs. A -number without a suffix is in `unit` (a unit's name, suffix or key: `points`, `picas`, `inches`, `millimeters`, +`+ - * /` arithmetic, where `x`, `X` and `×` multiply as `*` does (`"10mm"`, `"1in/2"`, `"2p6"`, `"1080/2 px"`, +`"3cm*50%"`, `"2x3 mm"`, `"13q"`), a decimal comma read as a point (`"0,5 mm"`) and a single number with a thousands +comma (`"1,000 mm"`) refused, in at most 1024 bytes with at most 128 `+ - * /` signs (each multiplication sign counts). +A number without a suffix is in `unit` (a unit's name, suffix or key: `points`, `picas`, `inches`, `millimeters`, `centimeters`, `pixels`, `feetInches`, `meters`, `yards`, `feet`, `q`, `ha`; default `points`); a suffix in the text takes precedence over `unit`. It works without an open document. The command fails when `value` is missing, does not read, or is not finite in every unit, and when `unit` is not a unit. Result: `{points, units: [{unit, label, number, diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 47233ebac4..c7721291c0 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -309,7 +309,7 @@ tools, never checked side by side) isn't captured row by row. | Fields commit what was typed on a click away or a move to another field, as Enter does; Escape discards it | done | #1787 | | Number fields: Up/Down step, Shift ×10, Cmd/Ctrl ÷10, wheel over a hovered field without a click; steps, the wheel and label scrubs stop at the field's bounds (a stroke weight at 0, a miter limit at 1) | done | Shift+arrow in the Stroke weight field doesn't step by 10 (#991); bounds #3370. The field takes the wheel only when the pointer was moved onto it after the field last moved or was covered by a window or overlay, and the wheel stream began there; a stream that began elsewhere stays there until 0.5 s pass with no wheel input or the pointer is pressed on a field, so a panel scrolled under a still pointer keeps scrolling past the field. This rule and its 0.5 s are VectorCraft's choices. | | Numeric spinner arrows step once on a click and keep repeating while held with the mouse | done | #6307; headless test `a_held_spinner_arrow_repeats` holds past egui's click timeout and checks release. | -| Arithmetic in fields (`+ - * /`, `x`, `X` or `×` for `*`, and `%` of the value before it: `3cm*50%`, `50pt+25%`) and unit suffixes (`3 mm`, `1in`, `2p6`) | done | `Unit::parse`; mixed units in one expression not verified | +| Arithmetic in fields (`+ - * /`, `x`, `X` or `×` for `*`, and `%` of the value before it: `3cm*50%`, `50pt+25%`) and unit suffixes (`3 mm`, `1in`, `2p6`) | done | `Unit::parse` and `parse_number`; mixed units in one expression not verified | | Numeric fields: focus click selects the whole value; dragging selects from the pressed character | partial | #1326; select-all waits for click release; px/pt/plain/optional fields, both directions and replacement text tested; native API input, 17 px partial replacement, Undo/Redo, saved-file round trip and screenshots verified; Tab, double-click, arrows and wheel preserved; a release more than 1 pt from the press keeps the caret, a tap within 1 pt selects all (#6659) | | Units: pt, pc, in, mm, cm, px, ft-in, m, yd, ft; General/Stroke/Type units | done | units preference reverting to points on SVG output reported (#864). A file that records no units (PDF, EPS or `.ai` without ruler units, raster images, metafiles, Affinity files) opens and reverts in General units; native, SVG and DXF files and a `.ai` or EPS with ruler units keep theirs, as a [Community Expert's answer](https://community.adobe.com/questions-652/change-units-from-points-to-inches-won-t-stick-765372) describes (#5820) | | Units › East Asian Type (Q and Ha) | done | #394: `unitsAsianType` offers every unit and Q and Ha, a quarter of a millimetre each ([Scripting Guide's Measurement Units](https://ai-scripting.docsforadobe.dev/scripting/measurementUnits/): 0.709 pt per Q; [InDesign's unit notation](https://helpx.adobe.com/in/indesign/desktop/layout-and-grid-tools/rulers-and-measure-tools/change-ruler-measurement-units.html): `q`, `h`); only it lists Q and Ha. The public pages do not say which fields use it, so no field uses it yet and that waits for a source. Tests `q_and_ha_are_a_quarter_millimetre`, `east_asian_type_unit_*` | From a166087f55ca50e2aaea05ddc10ab95477fac4f1 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 22:36:30 -0800 Subject: [PATCH 3/3] Fields: test a product through a length param and keep upstream's doc text - `Unit::parse` keeps main's paragraph about units after `*` and `/` as it was; the new `x` paragraph follows it, and the limit line names the signs it counts again. - `object.path.offsetPath` takes `"0.05x2 in"` (0.1 in), which it refused before; `"0x10"` reads as 0 pt. docs/mcp.md states both. --- crates/doc/src/tests/units.rs | 1 + crates/doc/src/units.rs | 15 ++++++++------- crates/engine/src/tests/pathops.rs | 4 ++++ docs/mcp.md | 4 ++-- 4 files changed, 15 insertions(+), 9 deletions(-) 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