mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 08:26:04 +00:00
Merge pull request #8796 from dotCooCoo/fix/value-fields-arithmetic
Fields: number fields outside the shared widgets read field arithmetic
This commit is contained in:
@@ -429,6 +429,23 @@ fn case_from_attrs(attrs: &Map<String, Value>) -> Option<&'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The number the text typed into number field `key` reads as, with the arithmetic of the app's number
|
||||
/// fields (`6x2`, `10+4`, `200/2`) and a decimal comma: a length in points in the length fields (`1 in`),
|
||||
/// and a final `%` in the percent fields or `°` in Character Rotation.
|
||||
fn typed_number(key: &str, text: &str) -> Option<f64> {
|
||||
let text = text.trim().replace('\u{2212}', "-");
|
||||
let text = vectorcraft_doc::decimal_point(&text);
|
||||
let mark = match key {
|
||||
"size" | "leading" | "baseline_shift" | "tcyUpDown" | "tcyLeftRight" | "stroke_width" => {
|
||||
return vectorcraft_doc::Unit::Points.parse(&text);
|
||||
}
|
||||
"h_scale" | "v_scale" | "tsume" | "fill_tint" | "stroke_tint" => Some('%'),
|
||||
"rotation" => Some('°'),
|
||||
_ => None,
|
||||
};
|
||||
vectorcraft_doc::parse_number(mark.and_then(|m| text.strip_suffix(m)).unwrap_or(&text))
|
||||
}
|
||||
|
||||
fn optional_number(d: &Values, key: &str) -> Result<Option<Value>, String> {
|
||||
let label = match key {
|
||||
"size" => tl!("Size"),
|
||||
@@ -458,7 +475,7 @@ fn optional_number(d: &Values, key: &str) -> Result<Option<Value>, String> {
|
||||
Some(v) => {
|
||||
let n = v
|
||||
.as_f64()
|
||||
.or_else(|| v.as_str().and_then(|s| s.trim().parse::<f64>().ok()))
|
||||
.or_else(|| v.as_str().and_then(|s| typed_number(key, s)))
|
||||
.filter(|n| n.is_finite())
|
||||
.ok_or_else(|| format!("{label} must be a number"))?;
|
||||
// Character Style fields use the Character panel's visible ranges.
|
||||
|
||||
@@ -515,6 +515,33 @@ fn diacritic_position_fields_show_set_reset_and_commit() {
|
||||
assert!(t.runs.iter().all(|r| (r.style.diacritic_horizontal, r.style.diacritic_vertical) == (-120.0, 1000.0)));
|
||||
}
|
||||
|
||||
/// The number fields read typed text as the app's other number fields do: `6x2`, `10+4`, `200/2%`,
|
||||
/// `45°`, a decimal comma, and a length with its unit. `%` and `°` only where the field takes them,
|
||||
/// and an exponent is not read.
|
||||
#[test]
|
||||
fn number_fields_take_field_arithmetic() {
|
||||
let typed = [
|
||||
("size", "6x2", 12.0),
|
||||
("tracking", "10+4", 14.0),
|
||||
("h_scale", "200/2%", 100.0),
|
||||
("rotation", "45°", 45.0),
|
||||
("fill_tint", "25*2", 50.0),
|
||||
("leading", "1 in", 72.0),
|
||||
("baseline_shift", "\u{2212}2", -2.0),
|
||||
("kerning", "12,5", 12.5),
|
||||
];
|
||||
for (key, text, want) in typed {
|
||||
let (mut d, _) = dialog_for(json!({}));
|
||||
put(&mut d, key, json!(text));
|
||||
assert_eq!(optional_number(&Values::new(&d), key), Ok(Some(json!(want))), "{key} {text}");
|
||||
}
|
||||
for (key, text) in [("size", "12°"), ("leading", "50%"), ("tracking", "10%"), ("rotation", "45%"), ("h_scale", "1%2"), ("size", "1e3")] {
|
||||
let (mut d, _) = dialog_for(json!({}));
|
||||
put(&mut d, key, json!(text));
|
||||
assert!(optional_number(&Values::new(&d), key).is_err(), "{key} {text}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Tsume: empty is unset, an explicit 0 stays set, a typed value stops at 0 and 100, Reset Panel
|
||||
/// unsets it, and it commits to the style and the text set in it.
|
||||
#[test]
|
||||
@@ -523,7 +550,7 @@ fn tsume_field_shows_sets_resets_and_commits() {
|
||||
assert_eq!(val(&d, "tsume"), json!(""));
|
||||
let (mut d, o) = dialog_for(json!({"tsume": 50.0}));
|
||||
assert_eq!(val(&d, "tsume"), json!("50.0"));
|
||||
for (typed, kept) in [("0", 0.0), ("25.5", 25.5), ("150", 100.0), ("-5", 0.0)] {
|
||||
for (typed, kept) in [("0", 0.0), ("25.5", 25.5), ("25%", 25.0), ("50/2%", 25.0), ("150", 100.0), ("-5", 0.0)] {
|
||||
put(&mut d, "tsume", json!(typed));
|
||||
assert_eq!(edited_attrs(&d, &o).unwrap(), attrs(json!({"tsume": kept})), "{typed}");
|
||||
}
|
||||
|
||||
+4
-1
@@ -13360,7 +13360,10 @@ dialog exposes `name`, `font_family`, `font_style`, `size`, `leading`, `kerning`
|
||||
`tcyLeftRight`, `rotation`, `akiLeft`, `akiRight`, `tsume`, `diacriticHorizontal`, `diacriticVertical`, `language`, `fill`, `fill_tint`, `stroke`, `stroke_tint`, `stroke_width`, `overprint_fill`, `overprint_stroke`,
|
||||
`ot_figure`, `ot_position`, `ot_liga`, `ot_calt`, `ot_dlig`, `ot_swsh`, `ot_salt`, `ot_titl`, `ot_ordn`, `ot_frac`,
|
||||
`ot_sets`, `section` (`general`, `basic`, `advanced`, `color` or `opentype`), and `preview`. An empty field leaves its
|
||||
attribute unset. `leading` and `kerning` also accept `Auto` to store an explicit automatic value.
|
||||
attribute unset. `leading` and `kerning` also accept `Auto` to store an explicit automatic value. A number field
|
||||
given as text takes the arithmetic of the app's number fields (`"6x2"`, `"10+4"`) and a decimal comma; `size`, `leading`,
|
||||
`baseline_shift`, `tcyUpDown`, `tcyLeftRight` and `stroke_width` also read a unit (`"1 in"`), a final `%` is read only
|
||||
in `h_scale`, `v_scale`, `tsume`, `fill_tint` and `stroke_tint`, and a final `°` only in `rotation`.
|
||||
Advanced Character Formats holds `h_scale` and `v_scale` (percent, 1 to 10000),
|
||||
`baseline_shift` (points, -1296 to 1296), the Tate-chu-yoko Settings `tcyUpDown` and `tcyLeftRight` (points,
|
||||
-1296 to 1296, as `text.setRangeStyle` takes them; an explicit 0 stays distinct from unset), `rotation` (degrees, stored from -180 to 180), Insert Aki Left and Right `akiLeft` and `akiRight` (thousandths of
|
||||
|
||||
@@ -1105,6 +1105,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- 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 number fields of Character Style Options read typed text with the same arithmetic and a decimal comma (`6x2` is 12, `200/2%` is 100%); the length fields also read a unit (`1 in` is 72 pt). A final `%` is read only in the percent fields and a final `°` only in Character Rotation, and an exponent (`1e3`) is not read. Tests: `number_fields_take_field_arithmetic` and `tsume_field_shows_sets_resets_and_commits` in `crates/ui-egui/src/dialogs/char_style_options/tests.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.
|
||||
|
||||
Reference in New Issue
Block a user