mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
fix(type): keep a non-finite layer size out of the mask's create params
`mask_style_from_active_layer` built the size with `json!` and only then asked
`finite_style_value` about it. `json!` turns a non-finite f32 into `null` and
`finite_style_value` accepts `null`, so `type.create` received `"size": null`,
its `check_size_tracking` refused the whole parameter set, and the
`if let Ok(v)` in `create_text` passed the error over: a Horizontal Type Mask
click over a document whose active text layer carries a NaN or an infinite size
did nothing at all.
Gate the f32 product with `is_finite()` and only then make it JSON, so such a
layer keeps the tool's own size and the mask still starts. Pinned by
`a_non_finite_layer_size_keeps_the_tool_size`, red before this commit
("a new mask session at (60.0, 300.0)").
This commit is contained in:
1 parent
b84775b5f4
commit
d890b19ece
2 files changed
+35
-5
No files matched your search
@@ -117,11 +117,12 @@ pub(super) fn mask_style_from_active_layer(app: &PhotocraftApp) -> Option<serde_
|
||||
if !c.font_style.is_empty() {
|
||||
p["fontStyle"] = json!(c.font_style);
|
||||
}
|
||||
let size = json!(c.size_pt * shown_scale(app));
|
||||
// A size the document carries that is not a finite number stays out, so the tool's own size
|
||||
// applies, as it does today.
|
||||
if finite_style_value(&size) {
|
||||
p["size"] = size;
|
||||
let size = c.size_pt * shown_scale(app);
|
||||
// Gate the f32 itself: `json!` turns a non-finite size into `null`, `finite_style_value`
|
||||
// accepts `null`, and `type.create` then refuses the whole click. A document carrying such a
|
||||
// size keeps the tool's own, as it does for a family or style the layer does not name.
|
||||
if size.is_finite() {
|
||||
p["size"] = json!(size);
|
||||
}
|
||||
Some(p)
|
||||
}
|
||||
|
||||
@@ -270,6 +270,35 @@ fn a_layer_that_names_no_family_or_style_gives_only_its_size() {
|
||||
assert_eq!(mask_style(&app), ("Tool Font".into(), "Regular".into(), 80.0), "the size is taken, the empty names are not");
|
||||
}
|
||||
|
||||
/// A document as a corrupt file can leave it: the active layer's runs carry `bad` as their size, a
|
||||
/// value no `type` command writes (the commands keep the size within 0.1-1296 pt).
|
||||
fn corrupt_layer_size(app: &mut PhotocraftApp, id: LayerId, bad: f32) {
|
||||
let st = app.session.active_mut().unwrap();
|
||||
let mut doc = (*st.doc).clone();
|
||||
if let Some(photocraft_doc::LayerContent::Text(t)) = doc.layer_mut(id).map(|l| &mut l.content) {
|
||||
t.size_pt = bad;
|
||||
for r in &mut t.runs {
|
||||
r.style.size_pt = bad;
|
||||
}
|
||||
}
|
||||
st.doc = std::sync::Arc::new(doc);
|
||||
st.revision += 1;
|
||||
}
|
||||
|
||||
/// The corrupt-document case: a layer size that is not a finite number. It stays out of the create
|
||||
/// parameters, so the mask still starts - at the tool's own size, with the layer's font and style
|
||||
/// taken as measured. Red without the gate on the finite product: the size becomes JSON `null`,
|
||||
/// `type.create` refuses it, and the click does nothing at all.
|
||||
#[test]
|
||||
fn a_non_finite_layer_size_keeps_the_tool_size() {
|
||||
for bad in [f32::NAN, f32::INFINITY] {
|
||||
let (mut app, id) = txt_active(80.0);
|
||||
corrupt_layer_size(&mut app, id, bad);
|
||||
mask(&mut app, (60.0, 300.0), "MASK");
|
||||
assert_eq!(mask_style(&app), ("Inter".into(), "Bold".into(), 48.0), "the tool's size, not a null the engine rejects ({bad})");
|
||||
}
|
||||
}
|
||||
|
||||
/// Not measured: whether the tool options themselves change afterwards. Today they do not, and
|
||||
/// they still do not. Guard test: passes before and after the change.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user