mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 12:38:18 +00:00
Fields: test a product through a length param and keep upstream's doc text
- `Unit::parse` keeps main's paragraph about units after `*` and `/` as it was; the new `x` paragraph follows it, and the limit line names the signs it counts again. - `object.path.offsetPath` takes `"0.05x2 in"` (0.1 in), which it refused before; `"0x10"` reads as 0 pt. docs/mcp.md states both.
This commit is contained in:
@@ -121,6 +121,7 @@ fn x_is_a_multiplication_sign() {
|
||||
(Unit::Points, "2p×3", 72.0),
|
||||
// Text that used to be refused now reads as a product.
|
||||
(Unit::Points, "8.5x11 in", 93.5 * 72.0),
|
||||
(Unit::Points, "0x10", 0.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}");
|
||||
|
||||
@@ -151,17 +151,18 @@ impl Unit {
|
||||
/// Parse `12`, `12pt`, `1in`, `3 mm`, `2p6` (picas+points), `6q` (Q) and `6h` (Ha), simple
|
||||
/// `+ - * /` arithmetic.
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// `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). `X` and `×` after a `p` multiply (`2pX3` is 6 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 [`arithmetic_signs`] reads as nothing.
|
||||
/// Text with more than 128 `+ - * /` signs ([`arithmetic_signs`], a multiplication sign counted
|
||||
/// as `*`) reads as nothing.
|
||||
pub fn parse(self, s: &str) -> Option<f64> {
|
||||
if arithmetic_signs(s) > MAX_MEASURE_OPERATORS {
|
||||
return None;
|
||||
|
||||
@@ -1121,6 +1121,10 @@ fn path_commands_refuse_a_param_of_the_wrong_type() {
|
||||
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
|
||||
let r = ids(&s.execute("object.path.offsetPath", &json!({"offset": "0.1 in", "joins": "Bevel"})).unwrap());
|
||||
assert!(close(bounds(&s, r[0]), Rect::new(92.8, 92.8, 157.2, 147.2), 1e-2), "{:?}", bounds(&s, r[0]));
|
||||
// A product with a unit, which the offset used to refuse: 0.05x2 in is 0.1 in.
|
||||
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
|
||||
let r = ids(&s.execute("object.path.offsetPath", &json!({"offset": "0.05x2 in", "joins": "Bevel"})).unwrap());
|
||||
assert!(close(bounds(&s, r[0]), Rect::new(92.8, 92.8, 157.2, 147.2), 1e-2), "{:?}", bounds(&s, r[0]));
|
||||
// Null switches keep Clean Up's defaults, which remove the stray point.
|
||||
let r = s.execute("object.path.cleanUp", &json!({"strayPoints": null, "unpaintedObjects": null, "emptyTextPaths": null})).unwrap();
|
||||
assert_eq!(r["removed"], 1);
|
||||
|
||||
+2
-2
@@ -7593,8 +7593,8 @@ Commands take and return lengths in points (the distances of `object.path.offset
|
||||
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. `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"` and `"2pX3"`
|
||||
are 6 picas). A string such as `"8.5x11 in"` reads as one length, 93.5 in.
|
||||
A length string with more than 128 `+ - * /` signs (each multiplication sign counts) is not read as a length. The units
|
||||
are 6 picas). A string such as `"8.5x11 in"` reads as one length, 93.5 in, and `"0x10"` reads as 0 pt. 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
|
||||
|
||||
Reference in New Issue
Block a user