diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs index ebc2088245..276f298ffe 100644 --- a/crates/doc/src/lib.rs +++ b/crates/doc/src/lib.rs @@ -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 { diff --git a/crates/doc/src/units.rs b/crates/doc/src/units.rs index cc4ab253de..1ef44c0413 100644 --- a/crates/doc/src/units.rs +++ b/crates/doc/src/units.rs @@ -436,6 +436,12 @@ pub fn ascii_digits(text: &str) -> Option> { 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> { + 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 { diff --git a/crates/engine/src/cmd/rasterfx.rs b/crates/engine/src/cmd/rasterfx.rs index b567c0f3a0..1447532743 100644 --- a/crates/engine/src/cmd/rasterfx.rs +++ b/crates/engine/src/cmd/rasterfx.rs @@ -71,8 +71,9 @@ fn resolution(v: &Value) -> Result { "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::().ok()) .ok_or_else(|| bad(C, format!("unknown resolution `{v}`")))?, }, diff --git a/crates/engine/src/tests/rastersettings.rs b/crates/engine/src/tests/rastersettings.rs index fd88793cc9..d918113114 100644 --- a/crates/engine/src/tests/rastersettings.rs +++ b/crates/engine/src/tests/rastersettings.rs @@ -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]