Locale: a text resolution uses one digit set, exponent included

`document.rasterEffectsSettings` read `"१e2"` and `"१e+2"` as 100 ppi:
`ascii_digits` treats `e` and `+` as the end of a number, so each side
could use its own digit set. The resolution now goes through
`vectorcraft_doc::ascii_digits_one_number`, which requires one digit set
for the whole value. `"१e२"` still reads as 100, and `"1e२"`, `"१e2"`
and `"१e+2"` are refused.
This commit is contained in:
dotCooCoo committed 2026-12-05 08:48:58 -08:00
1 parent 211b57e712
commit cf429ac1d8
4 files changed
+14 -5

No files matched your search

+1 -1
View File
@@ -179,7 +179,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, arithmetic_signs, ascii_digits, decimal_point, finite_in_every_unit, parse_number};
pub use units::{ColorMode, Unit, arithmetic_signs, ascii_digits, ascii_digits_one_number, decimal_point, finite_in_every_unit, parse_number};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Document {
+6
View File
@@ -436,6 +436,12 @@ pub fn ascii_digits(text: &str) -> Option<Cow<'_, str>> {
craft_i18n::ascii_digits(text, |c| matches!(c, '.' | ',')).ok()
}
/// [`ascii_digits`] for text that holds a single number, exponent and unit included: every digit
/// must come from one set, so `१e२` is `1e2` and `१e2` is `None`.
pub fn ascii_digits_one_number(text: &str) -> Option<Cow<'_, str>> {
craft_i18n::ascii_digits(text, |_| true).ok()
}
/// Does the operand contain a thousands comma? Check both parts of a compact pica value and
/// read a percentage's number without its percent sign.
fn thousands_operand(operand: &str) -> bool {
+3 -2
View File
@@ -71,8 +71,9 @@ fn resolution(v: &Value) -> Result<f64> {
"screen" => 72.0,
"medium" => 150.0,
"high" => 300.0,
// Digits of other scripts read as ASCII digits do (`"३००"` is 300), as number fields read them.
other => vectorcraft_doc::ascii_digits(other.trim_end_matches("ppi").trim())
// Digits of other scripts read as ASCII digits do (`"३००"` is 300), as number fields read them,
// with one digit set for the whole value, exponent included (`"१e2"` is refused).
other => vectorcraft_doc::ascii_digits_one_number(other.trim_end_matches("ppi").trim())
.and_then(|n| n.parse::<f64>().ok())
.ok_or_else(|| bad(C, format!("unknown resolution `{v}`")))?,
},
+4 -2
View File
@@ -97,11 +97,13 @@ fn a_resolution_given_as_text_reads_digits_of_other_scripts() {
let r = s.execute(C, &json!({"resolution": "३०० ppi"})).unwrap();
assert_eq!(r["resolution"].as_f64(), Some(300.0));
assert_eq!(s.doc().unwrap().doc.raster_effects_ppi, 300.0);
// One digit set per number, and the same 1 to 2400 ppi range as ASCII digits.
for bad in ["1५0", "५०००"] {
// One digit set per number, exponent included, and the same 1 to 2400 ppi range as ASCII digits.
for bad in ["1५0", "५०००", "१e2", "1e२", "१e+2"] {
assert!(s.execute(C, &json!({"resolution": bad})).is_err(), "{bad}");
}
assert_eq!(s.doc().unwrap().history.undo.len(), 1);
let r = s.execute(C, &json!({"resolution": "१e२"})).unwrap();
assert_eq!(r["resolution"].as_f64(), Some(100.0));
}
#[test]