Merge pull request #9307 from dotCooCoo/fix/style-percent-comma

Fields: Character Style Options refuses 1,000% as it refuses 1,000
This commit is contained in:
BFlat
2026-11-26 00:31:07 +07:00
committed by GitHub
2 changed files with 17 additions and 4 deletions
@@ -437,16 +437,17 @@ fn case_from_attrs(attrs: &Map<String, Value>) -> Option<&'static str> {
/// 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);
return vectorcraft_doc::Unit::Points.parse(&vectorcraft_doc::decimal_point(&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))
// The suffix comes off before the comma is read, so `1,000%` is refused as `1,000` is.
let number = mark.and_then(|m| text.strip_suffix(m)).unwrap_or(&text);
vectorcraft_doc::parse_number(&vectorcraft_doc::decimal_point(number))
}
fn optional_number(d: &Values, key: &str) -> Result<Option<Value>, String> {
@@ -529,13 +529,25 @@ fn number_fields_take_field_arithmetic() {
("leading", "1 in", 72.0),
("baseline_shift", "\u{2212}2", -2.0),
("kerning", "12,5", 12.5),
("h_scale", "12,5%", 12.5),
("rotation", "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")] {
for (key, text) in [
("size", "12°"),
("leading", "50%"),
("tracking", "10%"),
("rotation", "45%"),
("h_scale", "1%2"),
("size", "1e3"),
("h_scale", "1,000"),
("h_scale", "1,000%"),
("rotation", "1,000°"),
] {
let (mut d, _) = dialog_for(json!({}));
put(&mut d, key, json!(text));
assert!(optional_number(&Values::new(&d), key).is_err(), "{key} {text}");