mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 14:06:09 +00:00
Fields: x multiplies in value fields, as * does
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.
This commit is contained in:
@@ -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}");
|
||||
|
||||
+46
-5
@@ -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<f64> {
|
||||
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<char>) -> 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<f64> {
|
||||
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<f64> {
|
||||
}
|
||||
|
||||
/// 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<f64> {
|
||||
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.
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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)]
|
||||
|
||||
+3
-2
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
+1
-1
@@ -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_*` |
|
||||
|
||||
Reference in New Issue
Block a user