From 62d761a7bc867152d7d6b73ae85c5cb09d0964ed Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Sat, 7 Nov 2026 22:06:35 -0500 Subject: [PATCH] M6: .fig import draws a scaled instance's layers at its scale factor (#2091) An instance scaled with the Scale tool in Figma stores `symbolData.uniformScaleFactor`; the importer never read it, so the layers of a 128 px instance of a 256 px component came in at 256 px with the main's radii, strokes and spacing. Layers of an instance now take the main's lengths times the factor (composed through nested instances), the same values the Scale tool scales, unless an override or derived row gives the value, which is already at the instance's scale. Eight tests: the reproducer, the round trip, a derived size row not scaled twice, override rows, auto layout gap/padding/text, nested composition, factor 1 or none, and junk factors ignored. Co-Authored-By: Claude Sonnet 5.5 Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at high --- crates/format/src/fig.rs | 2 + crates/format/src/fig/assets_tests.rs | 16 ++ crates/format/src/fig/map.rs | 89 ++++++- crates/format/src/fig/map/component.rs | 23 +- crates/format/src/fig/map/layer.rs | 45 ++-- crates/format/src/fig/map/layout.rs | 22 +- crates/format/src/fig/map/paint.rs | 30 ++- crates/format/src/fig/map/text.rs | 43 ++-- crates/format/src/fig/scale_factor_tests.rs | 256 ++++++++++++++++++++ crates/format/src/fig/tests.rs | 38 ++- docs/file-format-parity.md | 5 +- 11 files changed, 501 insertions(+), 68 deletions(-) create mode 100644 crates/format/src/fig/scale_factor_tests.rs diff --git a/crates/format/src/fig.rs b/crates/format/src/fig.rs index f6d27111f..2ac794a44 100644 --- a/crates/format/src/fig.rs +++ b/crates/format/src/fig.rs @@ -38,6 +38,8 @@ mod paste_style_tests; #[cfg(test)] mod prop_value_tests; #[cfg(test)] +mod scale_factor_tests; +#[cfg(test)] mod slot_tests; #[cfg(test)] mod source_identity_tests; diff --git a/crates/format/src/fig/assets_tests.rs b/crates/format/src/fig/assets_tests.rs index 36c70a687..a69f5ccfa 100644 --- a/crates/format/src/fig/assets_tests.rs +++ b/crates/format/src/fig/assets_tests.rs @@ -1035,3 +1035,19 @@ fn local_samples_keep_their_variables_and_styles() { assert_eq!(styles(&a), styles(&b), "{}", p.display()); } } + +/// #2091 item 1, round trip: the Scale tool's result (radius 10 -> 15) must survive export and import. +#[test] +fn a_scaled_instance_keeps_its_radius_through_a_round_trip() { + let (mut doc, insts) = sized(); + let main_box = doc.nodes().find(|n| n.name == "Box" && n.parent.is_some_and(|p| doc.node(p).unwrap().name == "Card")).unwrap().id; + doc.node_mut(main_box).unwrap().corners.radii = [10.0; 4]; + let kid = doc.node(insts[2]).unwrap().children[0]; + doc.node_mut(kid).unwrap().corners.radii = [15.0; 4]; + let (bytes, _) = export(&doc, None).unwrap(); + let (back, _) = import(&bytes, "x").unwrap(); + let inst = back.nodes().find(|n| n.name == "Scaled").unwrap(); + let b = inst.children.iter().map(|c| back.node(*c).unwrap()).find(|n| n.name == "Box").unwrap(); + eprintln!("scaled box back: {}x{} radii {:?}", b.width, b.height, b.corners.radii); + assert_eq!(b.corners.radii, [15.0; 4]); +} diff --git a/crates/format/src/fig/map.rs b/crates/format/src/fig/map.rs index 927c233a2..173439c5c 100644 --- a/crates/format/src/fig/map.rs +++ b/crates/format/src/fig/map.rs @@ -39,6 +39,10 @@ const MAX_DEPTH: usize = 256; const MAX_COMMANDS: usize = 200_000; const MAX_GRID_TRACKS: usize = 1_000; pub(super) const MAX_GRID_TRACK_VALUE: f64 = 1e6; +/// Smallest and largest scale factor of a scaled instance (`symbolData.uniformScaleFactor`, times +/// those of the instances around it) that is followed: a junk factor changes nothing. +const MIN_SCALE_FACTOR: f64 = 1e-3; +const MAX_SCALE_FACTOR: f64 = 1e3; /// Id of "no style". const NO_STYLE: &str = "4294967295:4294967295"; /// Longest asset `key` or `version` kept for resolving references given as assets. @@ -147,6 +151,22 @@ fn copy_num(o: &mut Obj, n: &View, from: &str, to: &str) { } } +/// [`copy_num`] for a length: the layers of a scaled instance give it at the instance's scale. +fn copy_len(o: &mut Obj, n: &View, from: &str, to: &str) { + if let Some(x) = n.len(from) { + o.insert(to.into(), json!(x)); + } +} + +/// `x` at scale `k`; `None` when the result is not finite. +fn scaled(x: f64, k: f64) -> Option { + if k == 1.0 { + return Some(x); + } + let r = x * k; + r.is_finite().then_some(r) +} + fn copy_str(o: &mut Obj, n: &View, from: &str, to: &str) { if let Some(s) = n.str(from) { o.insert(to.into(), json!(s)); @@ -157,26 +177,65 @@ fn copy_str(o: &mut Obj, n: &View, from: &str, to: &str) { #[derive(Clone)] struct View<'a> { layers: Vec<&'a Kv<'a>>, + /// The factor each layer's lengths take (`scales[i]` is for `layers[i]`): the layers of a main + /// inside a scaled instance have the instance's, the override and derived rows of the instance + /// 1, being at the instance's scale already (#2091). + scales: Vec, /// Size and transform worked out from the constraints, over the layers' own. fitted: Option<((f64, f64), Affine)>, } impl<'a> View<'a> { fn of(n: &'a Kv<'a>) -> Self { - Self { layers: vec![n], fitted: None } + Self::of_scaled(n, 1.0) + } + + /// A node of a main inside an instance scaled by `k`: its lengths read `k` times as long. + fn of_scaled(n: &'a Kv<'a>, k: f64) -> Self { + Self { layers: vec![n], scales: vec![k], fitted: None } + } + + /// This view with the layers of `upper` over it (`upper`'s fitted size and place). + fn over(&self, upper: &Self) -> Self { + let mut v = self.clone(); + v.layers.extend(upper.layers.iter().copied()); + v.scales.extend(upper.scales.iter().copied()); + v.fitted = upper.fitted; + v + } + + /// The factor of the lowest layer (the layer's own main), for values a style gives. + fn base_scale(&self) -> f64 { + self.scales.first().copied().unwrap_or(1.0) } fn size(&self) -> Option<(f64, f64)> { - self.fitted.map(|f| f.0).or_else(|| self.get("size").and_then(size)) + self.fitted.map(|f| f.0).or_else(|| { + let (v, k) = self.find("size")?; + let (x, y) = size(v)?; + Some((scaled(x, k)?, scaled(y, k)?)) + }) } fn transform(&self) -> Option { - self.fitted.map(|f| f.1).or_else(|| self.get("transform").and_then(matrix)) + self.fitted.map(|f| f.1).or_else(|| { + let (v, k) = self.find("transform")?; + let m = matrix(v)?; + if k == 1.0 { + return Some(m); + } + let [a, b, c, d, e, f] = m.as_coeffs(); + let m = Affine::new([a, b, c, d, scaled(e, k)?, scaled(f, k)?]); + Some(m) + }) } fn with(&self, top: impl IntoIterator>) -> Self { let mut v = self.clone(); - v.layers.extend(top); + for layer in top { + v.layers.push(layer); + v.scales.push(1.0); + } v } @@ -188,7 +247,11 @@ impl<'a> View<'a> { if let Some(s) = style { let linked_in = |k: &str| v.layers.iter().rposition(|l| l.get(k).is_some()); let at = linked_in(key).or_else(|| linked_in(legacy)).map_or(1, |i| i + 1); - v.layers.insert(at.min(v.layers.len()), s); + let at = at.min(v.layers.len()); + // The style is at the scale of the layer that links it. + let k = at.checked_sub(1).and_then(|i| v.scales.get(i)).copied().unwrap_or(1.0); + v.layers.insert(at, s); + v.scales.insert(at, k); } v } @@ -197,6 +260,22 @@ impl<'a> View<'a> { self.layers.iter().rev().find_map(|l| l.get(k)) } + /// [`Self::get`], and the factor of the layer that has it. + fn find(&self, k: &str) -> Option<(&'a Kv<'a>, f64)> { + self.layers.iter().zip(&self.scales).rev().find_map(|(l, s)| l.get(k).map(|v| (v, *s))) + } + + /// A length: the number `k` holds at the scale of the layer that has it. + fn len(&self, k: &str) -> Option { + let (v, s) = self.find(k)?; + scaled(v.f64()?, s) + } + + /// [`Self::list`], and the factor of the layer that has it. + fn list_scaled(&self, k: &str) -> (&'a [Kv<'a>], f64) { + self.find(k).map_or((&[], 1.0), |(v, s)| (v.list(), s)) + } + fn num(&self, k: &str) -> Option { self.get(k).and_then(Kv::f64) } diff --git a/crates/format/src/fig/map/component.rs b/crates/format/src/fig/map/component.rs index e17ecf8ce..9c2788ff2 100644 --- a/crates/format/src/fig/map/component.rs +++ b/crates/format/src/fig/map/component.rs @@ -1,6 +1,6 @@ use super::layer::own_text; use super::text::char_styles; -use super::{BTreeMap, BTreeSet, Kv, MAX_DEPTH, Mapper, Obj, Rc, Value, View, guid, json}; +use super::{BTreeMap, BTreeSet, Kv, MAX_DEPTH, MAX_SCALE_FACTOR, MIN_SCALE_FACTOR, Mapper, Obj, Rc, Value, View, guid, json}; /// An override row names a layer of the main by its current GUID or by the `overrideKey` the /// layer had when the row was written: the key becomes the current GUID, unless the layer is @@ -91,6 +91,10 @@ pub(super) struct Inst<'a> { pub(super) slot_content: bool, /// Mains being expanded (an instance inside its own main stops there). symbols: Vec, + /// The factor the lengths of the expanded layers take: the instance's `uniformScaleFactor` + /// times those of the instances around it (#2091). Override and derived rows are already at + /// the instance's scale and take none. + pub(super) scale: f64, } impl<'a> Mapper<'a> { @@ -278,7 +282,7 @@ impl<'a> Mapper<'a> { o.remove("_figLineStarts"); if let Some(tv) = prop_text_data(val) { let size = o.get("style").and_then(|s| s.get("fontSize")).and_then(Value::as_f64); - char_styles(o, tv, size, &mut |w| self.warn(w)); + char_styles(o, tv, 1.0, size, &mut |w| self.warn(w)); } } } @@ -353,9 +357,12 @@ impl<'a> Mapper<'a> { } // A nested instance's derived layout is for the size it has in its main: resized here, the // sizes and places in it no longer hold and its layers follow their constraints instead. - let differs = |a: f64, b: f64| (a - b).abs() > 1e-6 * a.abs().max(b.abs()).max(1.0); + // A scaled size is the factor's product, rounded to a float: a looser match. + let tolerance = if outer.is_some_and(|i| i.scale != 1.0) { 1e-4 } else { 1e-6 }; + let differs = |a: f64, b: f64| (a - b).abs() > tolerance * a.abs().max(b.abs()).max(1.0); + let outer_scale = outer.map_or(1.0, |i| i.scale); let resized = outer.is_some() - && match (self.nodes.get(id).and_then(|b| View::of(b).size()), v.size()) { + && match (self.nodes.get(id).and_then(|b| View::of_scaled(b, outer_scale).size()), v.size()) { (Some(a), Some(b)) => differs(a.0, b.0) || differs(a.1, b.1), (a, b) => a.is_some() != b.is_some(), }; @@ -431,6 +438,13 @@ impl<'a> Mapper<'a> { let mut symbols = outer.map(|i| i.symbols.clone()).unwrap_or_default(); symbols.push(sym.clone()); let root = outer.map_or_else(|| rest_id.to_string(), |i| i.root.clone()); + // The scale the Scale tool gave the instance; a junk factor changes nothing. + let factor = sd + .and_then(|s| s.get("uniformScaleFactor")) + .and_then(Kv::f64) + .filter(|k| (MIN_SCALE_FACTOR..=MAX_SCALE_FACTOR).contains(k)) + .unwrap_or(1.0); + let scale = (outer_scale * factor).clamp(MIN_SCALE_FACTOR, MAX_SCALE_FACTOR); Some(( Inst { root, @@ -440,6 +454,7 @@ impl<'a> Mapper<'a> { slot_contents: Chain::over(outer.map(|i| &i.slot_contents), slot_contents), slot_content: false, symbols, + scale, }, sym, )) diff --git a/crates/format/src/fig/map/layer.rs b/crates/format/src/fig/map/layer.rs index dd01cf0af..d15cd2478 100644 --- a/crates/format/src/fig/map/layer.rs +++ b/crates/format/src/fig/map/layer.rs @@ -3,8 +3,8 @@ use super::connector::{ConnectorShape, connector_has_saved_label}; use super::layout::{layout_grid, tracks}; use super::paint::{effect, export_setting, has_bound_variables, paint, paint_bound, stroke}; use super::{ - Affine, BTreeMap, BTreeSet, Kv, MAX_COMMANDS, MAX_DEPTH, Mapper, Obj, Value, View, copy_num, copy_str, generated_record, guid, json, matrix, - network, num, rows, size, + Affine, BTreeMap, BTreeSet, Kv, MAX_COMMANDS, MAX_DEPTH, Mapper, Obj, Value, View, copy_len, copy_num, copy_str, generated_record, guid, json, + matrix, network, num, rows, scaled, size, }; /// How the layers of a resized container follow it when the file gives no derived layout for @@ -126,14 +126,17 @@ impl<'a> Mapper<'a> { (Some(i), Some(p)) => i.overrides.get(p).map(Vec::as_slice).unwrap_or_default(), _ => &[], }; - let mut view = View::of(base).with(entries.iter().map(|e| e.row)); + // Inside a scaled instance the main's lengths are the factor times as long; the rows of + // the instance are at its scale already (#2091). + let scale = inst.map_or(1.0, |i| i.scale); + let mut view = View::of_scaled(base, scale).with(entries.iter().map(|e| e.row)); // A layer of a resized instance the file gives no derived layout for follows its // constraints from the main's geometry, then takes the size and place overridden on it // (auto layout places the others, as in the editor). let derived = entries.iter().any(|e| e.entry == Entry::Derived && (e.row.get("size").is_some() || e.row.get("transform").is_some())); let stacked = parent.and_then(|p| p.str("stackMode")).is_some_and(|m| matches!(m, "HORIZONTAL" | "VERTICAL" | "GRID")) && view.str("stackPositioning") != Some("ABSOLUTE"); - let main = View::of(base); + let main = View::of_scaled(base, scale); let set = |k: &str| entries.iter().rev().filter(|e| e.entry != Entry::Stale).find_map(|e| e.row.get(k)); if let (Some(f), false, false, Some((w, h))) = (fit, derived, stacked, main.size()) { let t = main.transform().unwrap_or_default(); @@ -280,12 +283,18 @@ impl<'a> Mapper<'a> { // The saved vector is flattened into the connector node when no child slot remains. } else if ty == "INSTANCE" { if let Some((sub, sym)) = self.instance(o, view, id, inst, rest_id) { - let main = self.nodes.get(&sym).map(|m| View::of(m)); - let fit = Fit::frame(main.as_ref().and_then(View::size), view.size()); + let main = self.nodes.get(&sym).map(|m| View::of_scaled(m, sub.scale)); + // A scaled main's size is the factor's product, rounded to a float: it matches an + // instance of that size without a fit that would round the layers again. + let near = |a: f64, b: f64| (a - b).abs() <= 1e-4 * a.abs().max(b.abs()).max(1.0); + let fit = match (main.as_ref().and_then(View::size), view.size()) { + (Some(a), Some(b)) if sub.scale != 1.0 && near(a.0, b.0) && near(a.1, b.1) => None, + (a, b) => Fit::frame(a, b), + }; // An instance that records no auto layout of its own has its main's. let view = match main { Some(m) if view.get("stackMode").is_none() && m.get("stackMode").is_some() => { - let layered = View { fitted: view.fitted, ..m.with(view.layers.iter().copied()) }; + let layered = m.over(view); self.auto_layout(o, &layered); layered } @@ -309,8 +318,8 @@ impl<'a> Mapper<'a> { // size to its own. let fit = match (inst, ty) { (None, _) => None, - (Some(_), "GROUP" | "BOOLEAN_OPERATION") => Fit::scale(View::of(base).size(), view.size()), - (Some(_), _) => Fit::frame(View::of(base).size(), view.size()), + (Some(i), "GROUP" | "BOOLEAN_OPERATION") => Fit::scale(View::of_scaled(base, i.scale).size(), view.size()), + (Some(i), _) => Fit::frame(View::of_scaled(base, i.scale).size(), view.size()), }; for c in self.children(id) { kids.extend(self.layer_filtered(&c, inst, child_space, Some(view), fit, depth + 1, included)); @@ -509,14 +518,16 @@ impl<'a> Mapper<'a> { .unwrap_or_else(|| stroke_style.map_or_else(|| v.list("strokePaints"), |s| s.get("fillPaints").map(Kv::list).unwrap_or_default())); o.insert("strokes".into(), Value::Array(strokes.iter().filter_map(|p| paint(p, &mut |w| self.warn(w))).collect())); let effect_style = self.style(v, "styleIdForEffect", "inheritEffectStyleID", "effect", &mut styles); - let effects = effect_style.map_or_else(|| v.list("effects"), |s| s.get("effects").map(Kv::list).unwrap_or_default()); + let (effects, effects_scale) = + effect_style.map_or_else(|| v.list_scaled("effects"), |s| (s.get("effects").map(Kv::list).unwrap_or_default(), v.base_scale())); if !effects.is_empty() { - o.insert("effects".into(), Value::Array(effects.iter().filter_map(effect).collect())); + o.insert("effects".into(), Value::Array(effects.iter().filter_map(|e| effect(e, effects_scale)).collect())); } let grid_style = self.style(v, "styleIdForGrid", "inheritGridStyleID", "grid", &mut styles); - let grids = grid_style.map_or_else(|| v.list("layoutGrids"), |s| s.get("layoutGrids").map(Kv::list).unwrap_or_default()); + let (grids, grids_scale) = + grid_style.map_or_else(|| v.list_scaled("layoutGrids"), |s| (s.get("layoutGrids").map(Kv::list).unwrap_or_default(), v.base_scale())); if !grids.is_empty() { - o.insert("layoutGrids".into(), Value::Array(grids.iter().map(layout_grid).collect())); + o.insert("layoutGrids".into(), Value::Array(grids.iter().map(|g| layout_grid(g, grids_scale)).collect())); } if ty == "TEXT" { self.style(v, "styleIdForText", "inheritTextStyleID", "text", &mut styles); @@ -525,10 +536,10 @@ impl<'a> Mapper<'a> { o.insert("styles".into(), Value::Object(styles)); } stroke(o, v); - copy_num(o, v, "cornerRadius", "cornerRadius"); + copy_len(o, v, "cornerRadius", "cornerRadius"); copy_num(o, v, "cornerSmoothing", "cornerSmoothing"); if v.flag("rectangleCornerRadiiIndependent") == Some(true) { - let r = |k: &str| v.num(k).unwrap_or(0.0); + let r = |k: &str| v.len(k).unwrap_or(0.0); o.insert( "rectangleCornerRadii".into(), json!([ @@ -834,9 +845,9 @@ fn child_layout(o: &mut Obj, v: &View, parent: Option<&View>) { o.insert("layoutPositioning".into(), json!("ABSOLUTE")); } for (k, w, h) in [("minSize", "minWidth", "minHeight"), ("maxSize", "maxWidth", "maxHeight")] { - if let Some(val) = v.get(k).and_then(|s| s.get("value")) { + if let Some((val, scale)) = v.find(k).and_then(|(s, scale)| Some((s.get("value")?, scale))) { for (axis, to) in [("x", w), ("y", h)] { - if let Some(x) = num(val, axis).filter(|x| *x > 0.0 && *x < 1e9) { + if let Some(x) = num(val, axis).and_then(|x| scaled(x, scale)).filter(|x| *x > 0.0 && *x < 1e9) { o.insert(to.into(), json!(x)); } } diff --git a/crates/format/src/fig/map/layout.rs b/crates/format/src/fig/map/layout.rs index 7900c4539..28fb801a2 100644 --- a/crates/format/src/fig/map/layout.rs +++ b/crates/format/src/fig/map/layout.rs @@ -1,23 +1,23 @@ use super::paint::{bound, color}; -use super::{BTreeMap, BTreeSet, Kv, MAX_GRID_TRACK_VALUE, MAX_GRID_TRACKS, Mapper, Obj, Value, View, copy_num, guid, json, num}; +use super::{BTreeMap, BTreeSet, Kv, MAX_GRID_TRACK_VALUE, MAX_GRID_TRACKS, Mapper, Obj, Value, View, copy_len, guid, json, num, scaled}; impl<'a> Mapper<'a> { pub(super) fn auto_layout(&mut self, o: &mut Obj, v: &View<'a>) { let Some(mode) = v.str("stackMode").filter(|m| matches!(*m, "HORIZONTAL" | "VERTICAL" | "GRID")) else { return }; o.insert("layoutMode".into(), json!(mode)); - copy_num(o, v, "stackSpacing", "itemSpacing"); - copy_num(o, v, "stackCounterSpacing", "counterAxisSpacing"); + copy_len(o, v, "stackSpacing", "itemSpacing"); + copy_len(o, v, "stackCounterSpacing", "counterAxisSpacing"); if v.str("stackWrap") == Some("WRAP") { o.insert("layoutWrap".into(), json!("WRAP")); } if v.str("stackCounterAlignContent") == Some("SPACE_BETWEEN") { o.insert("counterAxisAlignContent".into(), json!("SPACE_BETWEEN")); } - let (h, vert) = (v.num("stackHorizontalPadding").unwrap_or(0.0), v.num("stackVerticalPadding").unwrap_or(0.0)); + let (h, vert) = (v.len("stackHorizontalPadding").unwrap_or(0.0), v.len("stackVerticalPadding").unwrap_or(0.0)); o.insert("paddingLeft".into(), json!(h)); o.insert("paddingTop".into(), json!(vert)); - o.insert("paddingRight".into(), json!(v.num("stackPaddingRight").unwrap_or(h))); - o.insert("paddingBottom".into(), json!(v.num("stackPaddingBottom").unwrap_or(vert))); + o.insert("paddingRight".into(), json!(v.len("stackPaddingRight").unwrap_or(h))); + o.insert("paddingBottom".into(), json!(v.len("stackPaddingBottom").unwrap_or(vert))); let main = match v.str("stackPrimaryAlignItems").or_else(|| v.str("stackJustify")) { Some("CENTER") => "CENTER", Some("MAX") => "MAX", @@ -48,8 +48,8 @@ impl<'a> Mapper<'a> { o.insert("itemReverseZIndex".into(), json!(b)); } if mode == "GRID" { - copy_num(o, v, "gridColumnGap", "gridColumnGap"); - copy_num(o, v, "gridRowGap", "gridRowGap"); + copy_len(o, v, "gridColumnGap", "gridColumnGap"); + copy_len(o, v, "gridRowGap", "gridRowGap"); o.insert("gridColumnCount".into(), json!(tracks(v, "gridColumns").len())); o.insert("gridRowCount".into(), json!(tracks(v, "gridRows").len())); let track_data = [("columnTracks", "gridColumns", "gridColumnsSizing"), ("rowTracks", "gridRows", "gridRowsSizing")] @@ -162,7 +162,8 @@ fn grid_track_sizing(size: Option<&Kv<'_>>) -> Option { } } -pub(super) fn layout_grid(g: &Kv) -> Value { +/// A layout grid; `k`: the factor its lengths take (a scaled instance's layer). +pub(super) fn layout_grid(g: &Kv, k: f64) -> Value { let pattern = match (g.get("pattern").and_then(Kv::str), g.get("axis").and_then(Kv::str)) { (Some("GRID"), _) => "GRID", (_, Some("Y")) => "ROWS", @@ -170,7 +171,8 @@ pub(super) fn layout_grid(g: &Kv) -> Value { }; let mut o = json!({"pattern": pattern, "alignment": g.get("type").and_then(Kv::str).unwrap_or("STRETCH")}); for (from, to) in [("sectionSize", "sectionSize"), ("numSections", "count"), ("gutterSize", "gutterSize"), ("offset", "offset")] { - if let Some(x) = num(g, from) { + let length = from != "numSections"; + if let Some(x) = num(g, from).and_then(|x| scaled(x, if length { k } else { 1.0 })) { o[to] = json!(x); } } diff --git a/crates/format/src/fig/map/paint.rs b/crates/format/src/fig/map/paint.rs index cf96c2bf0..b563c11b0 100644 --- a/crates/format/src/fig/map/paint.rs +++ b/crates/format/src/fig/map/paint.rs @@ -1,6 +1,6 @@ use super::layer::cap_name; use super::variables::alias; -use super::{Affine, Kv, Mapper, NO_STYLE, Obj, Point, Value, View, copy_num, copy_str, guid, json, matrix, num, rows, vec2}; +use super::{Affine, Kv, Mapper, NO_STYLE, Obj, Point, Value, View, copy_len, copy_str, guid, json, matrix, num, rows, scaled, vec2}; fn filter_number(value: &Kv) -> Option { let number = match value { @@ -55,7 +55,7 @@ impl<'a> Mapper<'a> { } pub(super) fn stroke(o: &mut Obj, v: &View) { - copy_num(o, v, "strokeWeight", "strokeWeight"); + copy_len(o, v, "strokeWeight", "strokeWeight"); if let Some(a) = v.str("strokeAlign").filter(|a| *a != "OFFSET") { o.insert("strokeAlign".into(), json!(a)); } @@ -84,7 +84,8 @@ pub(super) fn stroke(o: &mut Obj, v: &View) { if !profile.is_empty() { o.insert("strokeWidthProfile".into(), Value::Array(profile)); } - let dashes: Vec = v.list("dashPattern").iter().filter_map(Kv::f64).collect(); + let (dash_list, dash_scale) = v.list_scaled("dashPattern"); + let dashes: Vec = dash_list.iter().filter_map(Kv::f64).filter_map(|d| scaled(d, dash_scale)).collect(); if !dashes.is_empty() { o.insert("strokeDashes".into(), json!(dashes)); } @@ -94,7 +95,7 @@ pub(super) fn stroke(o: &mut Obj, v: &View) { } if v.flag("borderStrokeWeightsIndependent") == Some(true) { // A side that isn't written has no border. - let side = |k: &str| v.num(k).unwrap_or(0.0); + let side = |k: &str| v.len(k).unwrap_or(0.0); o.insert( "individualStrokeWeights".into(), json!({"top": side("borderTopWeight"), "right": side("borderRightWeight"), "bottom": side("borderBottomWeight"), "left": side("borderLeftWeight")}), @@ -254,7 +255,8 @@ pub(super) fn bound(v: Option<&Kv>, fields: &[(&str, &str)]) -> Option { (!found.is_empty()).then_some(Value::Object(found)) } -pub(super) fn effect(e: &Kv) -> Option { +/// A layer effect; `k`: the factor its lengths take (a scaled instance's layer). +pub(super) fn effect(e: &Kv, k: f64) -> Option { let ty = match e.get("type").and_then(Kv::str)? { "FOREGROUND_BLUR" => "LAYER_BLUR", "GRAIN" => "TEXTURE", @@ -262,9 +264,10 @@ pub(super) fn effect(e: &Kv) -> Option { }; let mut o = Obj::new(); o.insert("type".into(), json!(ty)); - for k in ["radius", "spread", "startRadius", "density", "opacity"] { - if let Some(x) = num(e, k) { - o.insert(k.into(), json!(x)); + for key in ["radius", "spread", "startRadius", "density", "opacity"] { + let length = matches!(key, "radius" | "spread" | "startRadius"); + if let Some(x) = num(e, key).and_then(|x| scaled(x, if length { k } else { 1.0 })) { + o.insert(key.into(), json!(x)); } } for k in ["visible", "showShadowBehindNode", "clipToShape"] { @@ -284,7 +287,7 @@ pub(super) fn effect(e: &Kv) -> Option { } for (from, to) in [("offset", "offset"), ("startOffset", "startOffset"), ("endOffset", "endOffset"), ("noiseSize", "noiseSizeVector")] { if let Some(p) = e.get(from).and_then(vec2) { - o.insert(to.into(), p); + o.insert(to.into(), scale_vec2(p, k)); } } if e.get("blurOpType").and_then(Kv::str) == Some("PROGRESSIVE") { @@ -304,6 +307,15 @@ pub(super) fn effect(e: &Kv) -> Option { Some(Value::Object(o)) } +/// A `{"x", "y"}` vector at scale `k` (unchanged when that is not finite). +fn scale_vec2(p: Value, k: f64) -> Value { + let axis = |name: &str| p.get(name).and_then(Value::as_f64).and_then(|x| scaled(x, k)); + match (axis("x"), axis("y")) { + (Some(x), Some(y)) => json!({"x": x, "y": y}), + _ => p, + } +} + pub(super) fn export_setting(e: &Kv) -> Value { let c = e.get("constraint"); let ty = match c.and_then(|c| c.get("type")).and_then(Kv::str) { diff --git a/crates/format/src/fig/map/text.rs b/crates/format/src/fig/map/text.rs index 0249b1086..86d9d24bb 100644 --- a/crates/format/src/fig/map/text.rs +++ b/crates/format/src/fig/map/text.rs @@ -1,12 +1,13 @@ use super::paint::paint; -use super::{Kv, Mapper, Obj, Value, View, copy_num, copy_str, json, network, num}; +use super::{Kv, Mapper, Obj, Value, View, copy_len, copy_str, json, network, num, scaled}; /// The value from the last override layer holding a valid one for an optional text setting; invalid instance rows fall through. -fn text_num(v: &View, key: &str) -> Option { - v.layers.iter().rev().find_map(|layer| { +/// `length`: the setting is a length, at the scale of the layer that has it. +fn text_num(v: &View, key: &str, length: bool) -> Option { + v.layers.iter().zip(&v.scales).rev().find_map(|(layer, k)| { layer.get(key).and_then(|value| match value { Kv::Bool(_) => None, - _ => value.f64(), + _ => scaled(value.f64()?, if length { *k } else { 1.0 }), }) }) } @@ -16,7 +17,7 @@ fn text_flag(v: &View, key: &str) -> Option { } fn insert_text_options(style: &mut Obj, v: &View) { - if let Some(value) = text_num(v, "listSpacing") { + if let Some(value) = text_num(v, "listSpacing", true) { style.insert("listSpacing".into(), json!(value)); } for k in ["hangingList", "hangingPunctuation"] { @@ -79,7 +80,8 @@ impl<'a> Mapper<'a> { let style_node = self.style_link(v, key, legacy).and_then(|s| self.nodes.get(&s).copied()); // Overrides above the one that links the style beat it; it beats the copies below. let sv = v.styled(style_node.filter(|s| s.get("styleType").and_then(Kv::str) == Some("TEXT")), key, legacy); - let td = v.get("textData"); + let found = v.find("textData"); + let (td, td_scale) = (found.map(|f| f.0), found.map_or(1.0, |f| f.1)); let chars = td.and_then(|t| t.get("characters")).and_then(Kv::str).unwrap_or(""); o.insert("characters".into(), json!(chars)); // Where the file's own layout wrapped the lines (not a REST field). @@ -105,19 +107,19 @@ impl<'a> Mapper<'a> { } // Paragraph settings belong to the effective text layer, including explicit zero clears. for k in ["paragraphSpacing", "paragraphIndent"] { - copy_num(&mut style, v, k, k); + copy_len(&mut style, v, k, k); } insert_text_options(&mut style, v); if let Some(n) = v.num("maxLines").filter(|n| *n >= 1.0) { style.insert("maxLines".into(), json!(n)); } - let size = sv.num("fontSize"); + let size = sv.len("fontSize"); if let Some(b) = o.get_mut("style").and_then(|s| s.get_mut("boundVariables")).map(Value::take) { style.insert("boundVariables".into(), b); } o.insert("style".into(), Value::Object(style)); let Some(td) = td else { return }; - char_styles(o, td, size, &mut |w| self.warn(w)); + char_styles(o, td, td_scale, size, &mut |w| self.warn(w)); let raw = td.get("lines").map(Kv::list).unwrap_or_default(); let lines: Vec<&str> = raw .iter() @@ -238,8 +240,9 @@ impl<'a> Mapper<'a> { } /// Per-character styles of text data `td` (`characterStyleIDs` + `styleOverrideTable`) as REST -/// `characterStyleOverrides` + `styleOverrideTable`; `size`: the base font size. -pub(super) fn char_styles(o: &mut Obj, td: &Kv, size: Option, warn: &mut dyn FnMut(String)) { +/// `characterStyleOverrides` + `styleOverrideTable`; `scale`: the factor the lengths of `td` take +/// (a scaled instance's layer); `size`: the base font size. +pub(super) fn char_styles(o: &mut Obj, td: &Kv, scale: f64, size: Option, warn: &mut dyn FnMut(String)) { let ids: Vec = td.get("characterStyleIDs").map(Kv::list).unwrap_or_default().iter().filter_map(Kv::f64).map(|i| i as u64).collect(); if ids.iter().all(|i| *i == 0) { return; @@ -247,7 +250,7 @@ pub(super) fn char_styles(o: &mut Obj, td: &Kv, size: Option, warn: &mut dy let mut table = Obj::new(); for e in td.get("styleOverrideTable").map(Kv::list).unwrap_or_default() { let Some(sid) = num(e, "styleID") else { continue }; - let mut s = text_style(&View::of(e), size); + let mut s = text_style(&View::of_scaled(e, scale), size); if let Some(fills) = e.get("fillPaints") { s.insert("fills".into(), Value::Array(fills.list().iter().filter_map(|p| paint(p, warn)).collect())); } @@ -269,9 +272,9 @@ fn text_style(v: &View, size: Option) -> Obj { } } } - copy_num(&mut s, v, "fontSize", "fontSize"); - copy_num(&mut s, v, "paragraphSpacing", "paragraphSpacing"); - copy_num(&mut s, v, "paragraphIndent", "paragraphIndent"); + copy_len(&mut s, v, "fontSize", "fontSize"); + copy_len(&mut s, v, "paragraphSpacing", "paragraphSpacing"); + copy_len(&mut s, v, "paragraphIndent", "paragraphIndent"); insert_text_options(&mut s, v); copy_str(&mut s, v, "textCase", "textCase"); copy_str(&mut s, v, "textDecoration", "textDecoration"); @@ -279,11 +282,11 @@ fn text_style(v: &View, size: Option) -> Obj { s.insert("textDecorationSkipInk".into(), json!(skip_ink)); } copy_str(&mut s, v, "leadingTrim", "leadingTrim"); - let font_size = v.num("fontSize").or(size).unwrap_or(12.0); - if let Some(ls) = v.get("letterSpacing") { + let font_size = v.len("fontSize").or(size).unwrap_or(12.0); + if let Some((ls, k)) = v.find("letterSpacing") { let val = num(ls, "value").unwrap_or(0.0); let px = match ls.get("units").and_then(Kv::str) { - Some("PIXELS") => val, + Some("PIXELS") => scaled(val, k).unwrap_or(val), Some("PERCENT") => { // Private (read by `rest/text.rs`): REST spacing is in pixels; keep the percent. s.insert("_letterSpacingPercent".into(), json!(val)); @@ -293,12 +296,12 @@ fn text_style(v: &View, size: Option) -> Obj { }; s.insert("letterSpacing".into(), json!(px)); } - if let Some(lh) = v.get("lineHeight") { + if let Some((lh, k)) = v.find("lineHeight") { let val = num(lh, "value").unwrap_or(100.0); match lh.get("units").and_then(Kv::str) { Some("PIXELS") => { s.insert("lineHeightUnit".into(), json!("PIXELS")); - s.insert("lineHeightPx".into(), json!(val)); + s.insert("lineHeightPx".into(), json!(scaled(val, k).unwrap_or(val))); } // shortcut: percent units count from the font's own line height (100 % is "auto"), which // the document can only say for 100 %; other values read as % of the font size. Upgrade diff --git a/crates/format/src/fig/scale_factor_tests.rs b/crates/format/src/fig/scale_factor_tests.rs new file mode 100644 index 000000000..79aa7f949 --- /dev/null +++ b/crates/format/src/fig/scale_factor_tests.rs @@ -0,0 +1,256 @@ +//! An instance scaled with the Scale tool stores `symbolData.uniformScaleFactor` (#2091 item 1): +//! its layers draw the main's lengths times the factor (composed through nested instances), +//! unless an override or derived row gives the value, which is at the instance's scale already. +//! Fixtures built in code with the parent module's helpers. + +use figcraft_doc::{Document, EffectKind, LetterSpacing, LineHeight, Node, NodeKind}; + +use super::kiwi::{Kv, Schema}; +use super::tests::{arr, at, canvas, e, f, g, node, o, s, xy}; +use super::*; + +const SCHEMA: &str = " +enum NodeType NONE DOCUMENT CANVAS FRAME ROUNDED_RECTANGLE TEXT SYMBOL INSTANCE +enum StackMode NONE HORIZONTAL VERTICAL +enum EffectType DROP_SHADOW +enum NumberUnits RAW PIXELS PERCENT +struct GUID uint sessionID, uint localID +struct Vector float x, float y +struct Matrix float m00, float m01, float m02, float m10, float m11, float m12 +message Number float value, NumberUnits units +message ParentIndex GUID guid, string position +message FontName string family, string style, string postscript +message TextData string characters +message Effect EffectType type, float radius, float spread, Vector offset +message GUIDPath GUID[] guids +message SymbolData GUID symbolID, NodeChange[] symbolOverrides, float uniformScaleFactor +message NodeChange GUID guid, ParentIndex parentIndex, NodeType type, string name, Vector size, Matrix transform, float cornerRadius, float strokeWeight, float[] dashPattern, float fontSize, FontName fontName, TextData textData, SymbolData symbolData, StackMode stackMode, float stackSpacing, float stackHorizontalPadding, float stackVerticalPadding, float stackCounterSpacing, Effect[] effects, Number lineHeight, Number letterSpacing, NodeChange[] derivedSymbolData, GUIDPath guidPath +message Blob byte[] bytes +message Message NodeChange[] nodeChanges, Blob[] blobs +"; + +fn schema() -> Schema { + Schema::parse(SCHEMA).unwrap() +} + +fn import_nodes(nodes: Vec>) -> Document { + import(&canvas(&schema(), &o(vec![("nodeChanges", arr(nodes))])), "x").unwrap().0 +} + +fn page() -> Vec> { + vec![node(0, None, "DOCUMENT", "D", vec![]), node(1, Some((0, "!")), "CANVAS", "P", vec![])] +} + +/// A copy of `n` with field `key` set to `value`. +fn set(n: Kv<'static>, key: &'static str, value: Kv<'static>) -> Kv<'static> { + let Kv::Object(mut fields) = n else { panic!("not a node") }; + fields.retain(|(k, _)| *k != key); + fields.push((key, value)); + Kv::Object(fields) +} + +/// An instance of main `main` with `factor` (none: the field is missing) and extra fields. +fn instance( + id: u64, + parent: (u64, &str), + name: &str, + main: u64, + size: (f64, f64), + factor: Option, + mut more: Vec<(&'static str, Kv<'static>)>, +) -> Kv<'static> { + let mut symbol = vec![("symbolID", g(main))]; + if let Some(k) = factor { + symbol.push(("uniformScaleFactor", f(k))); + } + let mut fields = vec![("size", xy(size.0, size.1)), ("transform", at(300.0, 0.0)), ("symbolData", o(symbol))]; + fields.append(&mut more); + node(id, Some(parent), "INSTANCE", name, fields) +} + +/// A 256 px component "Icon" holding a 200 px rectangle at (20, 40) with radius 64 and a stroke, +/// dashes and a shadow. +fn icon() -> Vec> { + let shadow = o(vec![("type", e("DROP_SHADOW")), ("radius", f(20.0)), ("spread", f(4.0)), ("offset", xy(10.0, 6.0))]); + vec![ + node(5, Some((1, "!")), "SYMBOL", "Icon", vec![("size", xy(256.0, 256.0)), ("transform", at(0.0, 0.0))]), + node( + 6, + Some((5, "!")), + "ROUNDED_RECTANGLE", + "Mark", + vec![ + ("size", xy(200.0, 200.0)), + ("transform", at(20.0, 40.0)), + ("cornerRadius", f(64.0)), + ("strokeWeight", f(8.0)), + ("dashPattern", arr(vec![f(16.0), f(8.0)])), + ("effects", arr(vec![shadow])), + ], + ), + ] +} + +fn find<'d>(doc: &'d Document, name: &str) -> &'d Node { + doc.nodes().find(|n| n.name == name).unwrap_or_else(|| panic!("no layer {name}")) +} + +/// The first child of the layer named `name`. +fn first_child<'d>(doc: &'d Document, name: &str) -> &'d Node { + doc.node(find(doc, name).children[0]).unwrap() +} + +fn mark(doc: &Document, name: &str) -> ([f64; 2], [f64; 2], [f64; 4]) { + let m = first_child(doc, name); + let t = m.transform.translation(); + ([m.width, m.height], [t.x, t.y], m.corners.radii) +} + +#[test] +fn a_scaled_instance_scales_the_lengths_of_a_layer_it_gives_no_row_for() { + let mut nodes = page(); + nodes.extend(icon()); + nodes.push(instance(9, (1, "\""), "Half", 5, (128.0, 128.0), Some(0.5), vec![])); + let doc = import_nodes(nodes); + let (size, place, radii) = mark(&doc, "Half"); + assert_eq!((size, place, radii), ([100.0, 100.0], [10.0, 20.0], [32.0; 4])); + let m = first_child(&doc, "Half"); + assert_eq!(m.stroke.weight, 4.0); + assert_eq!(m.stroke.dashes, [8.0, 4.0]); + let EffectKind::DropShadow(sh) = &m.effects[0].kind else { panic!("not a drop shadow") }; + assert_eq!((sh.radius, sh.spread, sh.offset), (10.0, 2.0, (5.0, 3.0))); + // The instance itself is at the size the file gives it. + let inst = find(&doc, "Half"); + assert_eq!([inst.width, inst.height], [128.0, 128.0]); + // The main is untouched. + assert_eq!(first_child(&doc, "Icon").corners.radii, [64.0; 4]); +} + +#[test] +fn a_value_a_derived_row_gives_is_not_scaled_twice() { + let mut nodes = page(); + nodes.extend(icon()); + let row = o(vec![("guidPath", o(vec![("guids", arr(vec![g(6)]))])), ("size", xy(100.0, 100.0))]); + nodes.push(instance(9, (1, "\""), "Half", 5, (128.0, 128.0), Some(0.5), vec![("derivedSymbolData", arr(vec![row]))])); + let doc = import_nodes(nodes); + let (size, place, radii) = mark(&doc, "Half"); + // The derived size is taken as written; the radius and place, which no row gives, scale. + assert_eq!((size, place, radii), ([100.0, 100.0], [10.0, 20.0], [32.0; 4])); +} + +#[test] +fn an_override_row_is_not_scaled_either() { + let mut nodes = page(); + nodes.extend(icon()); + let row = o(vec![("guidPath", o(vec![("guids", arr(vec![g(6)]))])), ("cornerRadius", f(7.0)), ("strokeWeight", f(3.0))]); + let symbol = o(vec![("symbolID", g(5)), ("uniformScaleFactor", f(0.5)), ("symbolOverrides", arr(vec![row]))]); + nodes.push(node(9, Some((1, "\"")), "INSTANCE", "Half", vec![("size", xy(128.0, 128.0)), ("transform", at(300.0, 0.0)), ("symbolData", symbol)])); + let doc = import_nodes(nodes); + let m = first_child(&doc, "Half"); + assert_eq!(m.corners.radii, [7.0; 4]); + assert_eq!(m.stroke.weight, 3.0); + // What the override leaves alone still scales. + assert_eq!(m.stroke.dashes, [8.0, 4.0]); +} + +#[test] +fn a_scaled_auto_layout_instance_scales_its_gap_padding_and_text() { + let mut nodes = page(); + nodes.push(node( + 5, + Some((1, "!")), + "SYMBOL", + "Row", + vec![ + ("size", xy(200.0, 60.0)), + ("transform", at(0.0, 0.0)), + ("stackMode", e("HORIZONTAL")), + ("stackSpacing", f(20.0)), + ("stackCounterSpacing", f(6.0)), + ("stackHorizontalPadding", f(10.0)), + ("stackVerticalPadding", f(10.0)), + ], + )); + let font = o(vec![("family", s("Inter")), ("style", s("Regular")), ("postscript", s(""))]); + let px = |v: f64| o(vec![("value", f(v)), ("units", e("PIXELS"))]); + nodes.push(node( + 6, + Some((5, "!")), + "TEXT", + "Label", + vec![ + ("size", xy(40.0, 20.0)), + ("transform", at(10.0, 10.0)), + ("fontSize", f(16.0)), + ("fontName", font), + ("lineHeight", px(24.0)), + ("letterSpacing", px(2.0)), + ("textData", o(vec![("characters", s("Hi"))])), + ], + )); + nodes.push(instance(9, (1, "\""), "RowHalf", 5, (100.0, 30.0), Some(0.5), vec![])); + let doc = import_nodes(nodes); + let row = find(&doc, "RowHalf"); + let layout = row.layout.as_ref().expect("the instance has its main's auto layout"); + assert_eq!((layout.gap, layout.cross_gap, layout.padding), (10.0, 3.0, [5.0; 4])); + let NodeKind::Text(t) = &first_child(&doc, "RowHalf").kind else { panic!("not text") }; + assert_eq!(t.style.font_size, 8.0); + assert_eq!(t.style.line_height, LineHeight::Pixels(12.0)); + assert_eq!(t.style.letter_spacing, LetterSpacing::Pixels(1.0)); + // The main keeps its own. + let NodeKind::Text(main) = &first_child(&doc, "Row").kind else { panic!("not text") }; + assert_eq!(main.style.font_size, 16.0); +} + +#[test] +fn nested_scaled_instances_compose_their_factors() { + let mut nodes = page(); + // Inner: 200 px with a 200 px rectangle of radius 40. + nodes.push(node(5, Some((1, "!")), "SYMBOL", "Inner", vec![("size", xy(200.0, 200.0)), ("transform", at(0.0, 0.0))])); + nodes.push(node( + 6, + Some((5, "!")), + "ROUNDED_RECTANGLE", + "Dot", + vec![("size", xy(200.0, 200.0)), ("transform", at(0.0, 0.0)), ("cornerRadius", f(40.0))], + )); + // Outer: 200 px, holding Inner scaled to 100 px (factor 0.5) at (20, 20). + nodes.push(node(7, Some((1, "\"")), "SYMBOL", "Outer", vec![("size", xy(200.0, 200.0)), ("transform", at(300.0, 0.0))])); + nodes.push(set(instance(8, (7, "!"), "Kid", 5, (100.0, 100.0), Some(0.5), vec![]), "transform", at(20.0, 20.0))); + // The outer one scaled to 100 px (factor 0.5). + nodes.push(instance(9, (1, "#"), "Half", 7, (100.0, 100.0), Some(0.5), vec![])); + let doc = import_nodes(nodes); + let kid = first_child(&doc, "Half"); + // The nested instance itself is the outer factor times its stored size and place. + assert_eq!(([kid.width, kid.height], [kid.transform.translation().x, kid.transform.translation().y]), ([50.0, 50.0], [10.0, 10.0])); + // Its layers take both factors: 0.5 x 0.5 of the main's. + let dot = doc.node(kid.children[0]).unwrap(); + assert_eq!(([dot.width, dot.height], dot.corners.radii), ([50.0, 50.0], [10.0; 4])); +} + +#[test] +fn a_factor_of_one_or_none_changes_nothing() { + let mut nodes = page(); + nodes.extend(icon()); + nodes.push(instance(9, (1, "\""), "One", 5, (256.0, 256.0), Some(1.0), vec![])); + nodes.push(instance(10, (1, "#"), "None", 5, (256.0, 256.0), None, vec![])); + let doc = import_nodes(nodes); + for name in ["One", "None"] { + let (size, place, radii) = mark(&doc, name); + assert_eq!((size, place, radii), ([200.0, 200.0], [20.0, 40.0], [64.0; 4]), "{name}"); + assert_eq!(first_child(&doc, name).stroke.weight, 8.0, "{name}"); + } +} + +#[test] +fn a_junk_factor_is_ignored() { + // The file encoder refuses NaN and infinities; the range check turns those away too. + for factor in [-0.5, 0.0, 1e30, 3e38, 1e-30] { + let mut nodes = page(); + nodes.extend(icon()); + nodes.push(instance(9, (1, "\""), "Junk", 5, (256.0, 256.0), Some(factor), vec![])); + let doc = import_nodes(nodes); + let (size, place, radii) = mark(&doc, "Junk"); + assert_eq!((size, place, radii), ([200.0, 200.0], [20.0, 40.0], [64.0; 4]), "factor {factor}"); + } +} diff --git a/crates/format/src/fig/tests.rs b/crates/format/src/fig/tests.rs index b468093d7..a8abf56fe 100644 --- a/crates/format/src/fig/tests.rs +++ b/crates/format/src/fig/tests.rs @@ -61,7 +61,7 @@ message FontName string family, string style, string postscript message TextData string characters, uint[] characterStyleIDs, NodeChange[] styleOverrideTable message Path WindingRule windingRule, uint commandsBlob message GUIDPath GUID[] guids -message SymbolData GUID symbolID, NodeChange[] symbolOverrides +message SymbolData GUID symbolID, NodeChange[] symbolOverrides, float uniformScaleFactor message StyleId GUID guid, AssetRef assetRef message PropValue bool boolValue, TextData textValue message PropDef GUID id, string name, PropValue initialValue, PropType type @@ -1825,3 +1825,39 @@ fn same_version_library_copies_resolve_deterministically_and_leave_no_table() { } assert_eq!(picked, ["1:6", "1:6"]); } + +/// #2091 item 1: an instance scaled with the Scale tool (K) has `symbolData.uniformScaleFactor`. +#[test] +fn a_scaled_instance_draws_its_layers_at_the_factor() { + let nodes = vec![ + node(0, None, "DOCUMENT", "D", vec![]), + node(1, Some((0, "!")), "CANVAS", "P", vec![]), + node(5, Some((1, "!")), "SYMBOL", "Icon", vec![("size", xy(256.0, 256.0)), ("transform", at(0.0, 0.0))]), + node( + 6, + Some((5, "!")), + "ROUNDED_RECTANGLE", + "Mark", + vec![("size", xy(256.0, 256.0)), ("transform", at(0.0, 0.0)), ("cornerRadius", f(64.0))], + ), + node( + 9, + Some((1, "\"")), + "INSTANCE", + "Half", + vec![ + ("size", xy(128.0, 128.0)), + ("transform", at(300.0, 0.0)), + ("symbolData", o(vec![("symbolID", g(5)), ("uniformScaleFactor", f(0.5))])), + ], + ), + ]; + let (doc, _) = import(&canvas(&schema(), &o(vec![("nodeChanges", arr(nodes))])), "x").unwrap(); + let inst = named(&doc, "Half"); + let mark = doc.node(inst.children[0]).unwrap(); + let t = mark.transform.translation(); + eprintln!("instance {}x{}; child {}x{} at ({}, {}) radii {:?}", inst.width, inst.height, mark.width, mark.height, t.x, t.y, mark.corners.radii); + assert_eq!([mark.width, mark.height], [128.0, 128.0]); + assert_eq!(mark.corners.radii, [32.0; 4]); + assert_eq!([t.x, t.y], [0.0, 0.0]); +} diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index bce90b008..5a7e27d5c 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -1,6 +1,6 @@ # File format parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-04 · **Change:** minor (a color profile per PNG, JPG and WebP export setting (Same as file, sRGB or Display P3), the pixels converted; a `.jam` connector end with an `AUTO` or `CENTER` magnet leaves the side facing the other end, not the side its stale saved point named (#1909); a FigJam elbow connector saved with its path (`connectorControlPoints`) keeps it on import, as a board connector reshaped by hand does, instead of being routed again (#1910); JPG exports take a quality, 1 to 100 with 90 the default, and embed the file's colour profile when it is sRGB too (#2004); a FigJam connector without a saved snapshot took no stroke and was invisible; its line's paint, weight, cap and dashes now come from the file's generated line record (#1807); a Dash cap setting (none, round or square) on Dash and Custom strokes, drawn on both ends of every dash; pasted layers whose image the clipboard lacks are named and show a placeholder that reads as missing (#1646); paint-style colours on layers pasted from another design app keep their style instead of turning black (#1638); imported and pasted text finds an installed family under the other names its fonts give it, and with other case and spacing (#1292); `.fig` export writes colour calculations as the colour they show in each mode and leaves out, with a warning, one that resolves to nothing (#1280); `.fig` import budgets four decoded values per compressed byte instead of one, still within 20M–128M, so dense files within that budget open instead of being refused as having too many values (#574); `.fig` ZIP image reads share a total byte budget and count skipped images in the import warnings (#1076); every file a command reads whole by path is a regular file within a cap that fits it: documents 16 GiB, placed images 256 MiB, CLI scripts 1 GiB; folders, devices and pipes are refused before anything is read (#1114); files nested 256 levels deep import on the browser's 1 MB stack (#1101); SVG and PDF exports count pattern sources and the renders they embed from the layer's depth, so one cap bounds a whole export (#1082); opening a `.figcraft` file unpacks at most 6 GiB in all (2 GiB in the browser), every area together (#1079); `.fig` instance expansion no longer walks variable nodes for every instance or copies every outer override row into each nested instance (#1077); a FigJam `.jam` file opens as a board (#1342); FigJam `.jam` files open like `.fig` files: File ▸ Open, drag and drop, `file.import` and the command line (#1342); SVG import reads `color()` and `color-mix()` colours, with a note and a grey for those it can't (#1550); SVG import draws each pattern tile once per scale, within the layer budget (#1080); a file's JPEG thumbnail can't crash the home screen (#1491's progressive JPEG check, now shared); `.fig` import: library text styles linked by asset key, and override rows restating a nested level (#1234); `.fig` import keeps the file's saved line breaks while the text and its box are unedited (#1236); Download a missing free font from the Missing fonts window (`font.download`, #754); offline Penpot 2.x import/export (#1143); `.sketch` import checked against Sketch's renders: master backgrounds, symbol clipping, tints before Sketch 64, mask opacity, bitmap fills, image overrides on shapes, stretching stacks, blur radii, colour adjustments, OKLab gradients, text growth, shape group borders (#1389); FigJam outer shape outlines and sticky body fallback beside author text (#1341, #1397); image member names are checked on read, and REST image placeholders get archive-safe keys (#1086); Android Vector Drawable (XML) export; `.fig` export: files the incumbent imports, with component set properties, and grid track sizes at its field ids; Save and auto-save don't replace changes another app made to the open file (#1330); `.sketch` import, best effort, Sketch 48 and newer; the PNG row names ignore overlapping layers and where include bounding box is offered; the Fonts table's missing-font row describes the Missing fonts window; `.figcraft` carries the file kind (boards); `.fig` import: resized instances and variable modes by asset key; atomic saves; auto-save; SVG export clip of nested frames; SVG/PDF export depth refusal (#208); `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; `.fig` export: written files checked by opening them in other software; experimental `.fig` export; export and inspect behaviour suite and fixes; .fig import: editable vector networks and more layer kinds; embedded image colour profiles; `.fig` import, best effort; animated GIF fills and TIFF images; last major: created, formats from the installed Figma's Info.plist and help center, ours from source; REST import keeps slot layers and instances' slot content (#792); REST import reads grid track sizes (#465); `.fig` import fidelity from the community batches, budgets for large files, the import report, a `.fig` copy from Save as, paste from another design app; instance layers' size and resizing and Hug on import (#731, #732)) · **Target:** Figma Design (desktop app 126.10.7) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-07 · **Change:** minor (`.fig` import: the layers of an instance scaled with the Scale tool draw at its scale factor, not at their main's lengths (#2091); a color profile per PNG, JPG and WebP export setting (Same as file, sRGB or Display P3), the pixels converted; a `.jam` connector end with an `AUTO` or `CENTER` magnet leaves the side facing the other end, not the side its stale saved point named (#1909); a FigJam elbow connector saved with its path (`connectorControlPoints`) keeps it on import, as a board connector reshaped by hand does, instead of being routed again (#1910); JPG exports take a quality, 1 to 100 with 90 the default, and embed the file's colour profile when it is sRGB too (#2004); a FigJam connector without a saved snapshot took no stroke and was invisible; its line's paint, weight, cap and dashes now come from the file's generated line record (#1807); a Dash cap setting (none, round or square) on Dash and Custom strokes, drawn on both ends of every dash; pasted layers whose image the clipboard lacks are named and show a placeholder that reads as missing (#1646); paint-style colours on layers pasted from another design app keep their style instead of turning black (#1638); imported and pasted text finds an installed family under the other names its fonts give it, and with other case and spacing (#1292); `.fig` export writes colour calculations as the colour they show in each mode and leaves out, with a warning, one that resolves to nothing (#1280); `.fig` import budgets four decoded values per compressed byte instead of one, still within 20M–128M, so dense files within that budget open instead of being refused as having too many values (#574); `.fig` ZIP image reads share a total byte budget and count skipped images in the import warnings (#1076); every file a command reads whole by path is a regular file within a cap that fits it: documents 16 GiB, placed images 256 MiB, CLI scripts 1 GiB; folders, devices and pipes are refused before anything is read (#1114); files nested 256 levels deep import on the browser's 1 MB stack (#1101); SVG and PDF exports count pattern sources and the renders they embed from the layer's depth, so one cap bounds a whole export (#1082); opening a `.figcraft` file unpacks at most 6 GiB in all (2 GiB in the browser), every area together (#1079); `.fig` instance expansion no longer walks variable nodes for every instance or copies every outer override row into each nested instance (#1077); a FigJam `.jam` file opens as a board (#1342); FigJam `.jam` files open like `.fig` files: File ▸ Open, drag and drop, `file.import` and the command line (#1342); SVG import reads `color()` and `color-mix()` colours, with a note and a grey for those it can't (#1550); SVG import draws each pattern tile once per scale, within the layer budget (#1080); a file's JPEG thumbnail can't crash the home screen (#1491's progressive JPEG check, now shared); `.fig` import: library text styles linked by asset key, and override rows restating a nested level (#1234); `.fig` import keeps the file's saved line breaks while the text and its box are unedited (#1236); Download a missing free font from the Missing fonts window (`font.download`, #754); offline Penpot 2.x import/export (#1143); `.sketch` import checked against Sketch's renders: master backgrounds, symbol clipping, tints before Sketch 64, mask opacity, bitmap fills, image overrides on shapes, stretching stacks, blur radii, colour adjustments, OKLab gradients, text growth, shape group borders (#1389); FigJam outer shape outlines and sticky body fallback beside author text (#1341, #1397); image member names are checked on read, and REST image placeholders get archive-safe keys (#1086); Android Vector Drawable (XML) export; `.fig` export: files the incumbent imports, with component set properties, and grid track sizes at its field ids; Save and auto-save don't replace changes another app made to the open file (#1330); `.sketch` import, best effort, Sketch 48 and newer; the PNG row names ignore overlapping layers and where include bounding box is offered; the Fonts table's missing-font row describes the Missing fonts window; `.figcraft` carries the file kind (boards); `.fig` import: resized instances and variable modes by asset key; atomic saves; auto-save; SVG export clip of nested frames; SVG/PDF export depth refusal (#208); `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; `.fig` export: written files checked by opening them in other software; experimental `.fig` export; export and inspect behaviour suite and fixes; .fig import: editable vector networks and more layer kinds; embedded image colour profiles; `.fig` import, best effort; animated GIF fills and TIFF images; last major: created, formats from the installed Figma's Info.plist and help center, ours from source; REST import keeps slot layers and instances' slot content (#792); REST import reads grid track sizes (#465); `.fig` import fidelity from the community batches, budgets for large files, the import report, a `.fig` copy from Save as, paste from another design app; instance layers' size and resizing and Hug on import (#731, #732)) · **Target:** Figma Design (desktop app 126.10.7) Every format Figma reads or writes, with FigCraft's support. Sources: `Info.plist` of `/Applications/Figma.app` (document types only; nothing inside the bundle's code was read), Figma's @@ -17,7 +17,7 @@ and prototype interactions are still unchecked there. | Format | Figma | FigCraft read | FigCraft write | Fidelity / testing | Hours | |---|---|---|---|---|---| -| `.fig` (Figma Design, `com.figma.document`, `application/x-figma`) | native (cloud; "Save local copy") | **yes, best effort** (`file.open`, `file.import`, drop, CLI, MCP) | **experimental** ([below](#export-to-fig-experimental)) | `.fig` files open (best effort): the zip, its deflate/zstd chunks and the kiwi schema are decoded generically and mapped by field name onto the REST importer, so pages, the layer tree, geometry, paints (styles resolved), strokes, effects, text with styled runs, vectors as editable vector networks with region-specific fill paints (points, curved segments, filled areas with their winding, per-point corner radius and handle mirroring, end caps; outlines when the network is missing or damaged), auto layout (grid included; a flow that records no primary-axis sizing hugs on that axis, an instance that records no auto layout has its main's), constraints, ellipse arcs, boolean operations, components, sets (with their descriptions), instances (expanded from their main with overrides, derived layout and property values; the size and resizing their layers override stay overrides), styles, variables with modes and bindings, prototyping (set-variable, set-variable-mode and conditional actions included) and image fills from the archive come across; sticky notes and shapes with text keep their generated backgrounds, styled text, text paints, saved child bounds and sticky author lines as editable frame children, including saved vector networks without geometry paths, outer fill/stroke outlines when generated geometry is damaged, and outer body text when its generated child is unusable even if an author survives (#1341, #1397); connectors, tables, code blocks, slides and similar layers come in as the closest frames, text layers and vectors, with a warning; anything else is a warning. Since 2026-10-17 (community batches #727, #728): an instance's own identity and the cached library components a file carries, overrides applied by key and order, local text values and instance overrides over a shared text style, grid track sizes (fixed, content-sized, fill), slot content, labels of connectors saved with their drawn path (a static snapshot; the ends aren't live), skip ink, paragraph options and hanging lists, list start numbers, vertical trim, per-point stroke joins, editable text on a path, image adjustments and images carried in the message; since 2026-10-29, style links that name a library style by asset key and version (the file's own copy of it), with override rows above the linking one still winning, and override rows restating a nested level's overrides applied at that level, below the instance's own (#1234), and the line breaks the file saved with a text, followed until an edit or a resize could move one, or where a line would come out more than 3% wider than its box in the fonts at hand (#1236). Budgets come from the file's own size (four decoded values per compressed byte, 20M–128M, lower ceilings on 32-bit targets; the layer cap follows the file's size too), so a 15.4 MB synthetic file with 300,000 layers opens whole; ZIP image reads have a separate total budget of 4 GiB (1 GiB on 32-bit targets) of decompressed ZIP-member bytes containing encoded images, with the 256 MiB per-image cap kept: a member that cannot fit is skipped before its output buffer is allocated, and the import report names the budget and counts skipped images (#1076). Failed reads and invalid image contents still consume the bytes read; a reference used by several layers is read once. This is not a limit on decoded pixels or total import memory; images carried inside the message are unchanged. The file's bytes stay out of the command journal; an import report lists what was left out or changed once the file opens. Elbowed and curved connectors without a saved path are routed as FigCraft's board connectors are (right angles, or one curve, from the sides of the layers they join); an elbowed one saved with its path (`connectorControlPoints`: a point and an axis per run between the first and the last) keeps that path when it leaves and arrives by the ends' sides (#1910), and a curved one's saved `connectorBezierControlPoints` are not read; a connector routed here takes its line's paint, weight, cap and dashes from the file's generated line record, as one with a saved snapshot does (#1807). A connector's label without a saved snapshot is kept as text centred on its line, without its background. Not read: table cells beyond their own layers, live style and variable links for vector region fills, variables bound to fields the editor can't bind, video fills. Tested on fixtures generated in code (`crates/format/src/fig/tests.rs`, `tail_tests.rs` and the per-feature `*_tests.rs` beside them, fuzzed), `crates/engine/src/shapebuilder_region_paints_tests.rs`, and by reading back what the export writes; the FigJam report sample from #1341 checked locally only; no representative real-world corpus yet | read tail 5–10, write: checks against real files 5–15 | +| `.fig` (Figma Design, `com.figma.document`, `application/x-figma`) | native (cloud; "Save local copy") | **yes, best effort** (`file.open`, `file.import`, drop, CLI, MCP) | **experimental** ([below](#export-to-fig-experimental)) | `.fig` files open (best effort): the zip, its deflate/zstd chunks and the kiwi schema are decoded generically and mapped by field name onto the REST importer, so pages, the layer tree, geometry, paints (styles resolved), strokes, effects, text with styled runs, vectors as editable vector networks with region-specific fill paints (points, curved segments, filled areas with their winding, per-point corner radius and handle mirroring, end caps; outlines when the network is missing or damaged), auto layout (grid included; a flow that records no primary-axis sizing hugs on that axis, an instance that records no auto layout has its main's), constraints, ellipse arcs, boolean operations, components, sets (with their descriptions), instances (expanded from their main with overrides, derived layout and property values; the size and resizing their layers override stay overrides; an instance scaled with the Scale tool, which stores `symbolData.uniformScaleFactor`, draws its layers at the main's lengths times that factor, composed through nested instances: sizes and places, corner radii, stroke weights and dashes, effect radii, spreads and offsets, auto layout gaps and paddings, grid gaps, min and max sizes, layout grids, font sizes, pixel line heights and letter spacings, paragraph spacing and indent, except where an override or derived row gives the value, which is already at the instance's scale; the vector outline paths a layer carries (a network's points follow the layer's size), per-point corner radii, fixed grid tracks, image tile scales and glass effects are not scaled by the factor, #2091), styles, variables with modes and bindings, prototyping (set-variable, set-variable-mode and conditional actions included) and image fills from the archive come across; sticky notes and shapes with text keep their generated backgrounds, styled text, text paints, saved child bounds and sticky author lines as editable frame children, including saved vector networks without geometry paths, outer fill/stroke outlines when generated geometry is damaged, and outer body text when its generated child is unusable even if an author survives (#1341, #1397); connectors, tables, code blocks, slides and similar layers come in as the closest frames, text layers and vectors, with a warning; anything else is a warning. Since 2026-10-17 (community batches #727, #728): an instance's own identity and the cached library components a file carries, overrides applied by key and order, local text values and instance overrides over a shared text style, grid track sizes (fixed, content-sized, fill), slot content, labels of connectors saved with their drawn path (a static snapshot; the ends aren't live), skip ink, paragraph options and hanging lists, list start numbers, vertical trim, per-point stroke joins, editable text on a path, image adjustments and images carried in the message; since 2026-10-29, style links that name a library style by asset key and version (the file's own copy of it), with override rows above the linking one still winning, and override rows restating a nested level's overrides applied at that level, below the instance's own (#1234), and the line breaks the file saved with a text, followed until an edit or a resize could move one, or where a line would come out more than 3% wider than its box in the fonts at hand (#1236). Budgets come from the file's own size (four decoded values per compressed byte, 20M–128M, lower ceilings on 32-bit targets; the layer cap follows the file's size too), so a 15.4 MB synthetic file with 300,000 layers opens whole; ZIP image reads have a separate total budget of 4 GiB (1 GiB on 32-bit targets) of decompressed ZIP-member bytes containing encoded images, with the 256 MiB per-image cap kept: a member that cannot fit is skipped before its output buffer is allocated, and the import report names the budget and counts skipped images (#1076). Failed reads and invalid image contents still consume the bytes read; a reference used by several layers is read once. This is not a limit on decoded pixels or total import memory; images carried inside the message are unchanged. The file's bytes stay out of the command journal; an import report lists what was left out or changed once the file opens. Elbowed and curved connectors without a saved path are routed as FigCraft's board connectors are (right angles, or one curve, from the sides of the layers they join); an elbowed one saved with its path (`connectorControlPoints`: a point and an axis per run between the first and the last) keeps that path when it leaves and arrives by the ends' sides (#1910), and a curved one's saved `connectorBezierControlPoints` are not read; a connector routed here takes its line's paint, weight, cap and dashes from the file's generated line record, as one with a saved snapshot does (#1807). A connector's label without a saved snapshot is kept as text centred on its line, without its background. Not read: table cells beyond their own layers, live style and variable links for vector region fills, variables bound to fields the editor can't bind, video fills. Tested on fixtures generated in code (`crates/format/src/fig/tests.rs`, `tail_tests.rs` and the per-feature `*_tests.rs` beside them, fuzzed), `crates/engine/src/shapebuilder_region_paints_tests.rs`, and by reading back what the export writes; the FigJam report sample from #1341 checked locally only; no representative real-world corpus yet | read tail 5–10, write: checks against real files 5–15 | | `.penpot` (Penpot 2.x ZIP export) | — | **yes, offline** (open, import, drop, CLI, MCP) | **yes, offline** (export, CLI convert) | Editable layers, supported flex/grid layout, components, tokens and prototypes using the existing model. Unsupported layouts retain saved positions and bounded metadata; toggle-overlay and embedded font binaries are reported. Font references remain editable; no downloads. Synthetic regression coverage; live Penpot and cross-platform QA remain open. See [Penpot reference](penpot.md). | further live Penpot and cross-platform QA | | `.sketch` (Sketch 48 and newer) | import (file browser ▸ Import or drop, desktop app too; converted to a Figma file, symbols as components; per the help center) | **yes, best effort** (`file.open`, `file.import`, drop, CLI, MCP; Open With from Finder, Explorer and Linux file managers once installed; recent files show its `previews/preview.png`) | no (out of scope) | zip + JSON read from the public format description; Sketch 43–47 (text as binary property lists) and older (SQLite) files are refused with a message to resave them in a newer Sketch. Pages, artboards as frames with their background, groups; Sketch 2025 and newer: frames (clipping or not) with their style, graphics, stacks as auto layout (direction, gap, alignment, padding, wrap, hug/fill sizing, stretching filling every item across, items ignoring the stack), corners in the style (rounded, smooth with its smoothing; angled, inside square and inside arc as paths), pins and sizing, per-side borders, lists of blurs (progressive background blurs, glass), inner shadows in the shadow list, tints (a graphic's, group's or instance's fill colouring its layers, and colour overrides; from Sketch 64, before which a group's fill draws nothing), text colour and visibility overrides, text sized by its sizing; rectangles with corner radii, ovals, stars and polygons while their points are the generated ones, paths as editable vector networks, shape groups as their shape, as one compound path (children without an operation, by the group's winding rule) or as boolean operations (mixed operations nested from the left); operands' own borders ignored as Sketch does; open paths filled as if closed, edited ovals and rectangles as paths, bitmaps (their image under their style's fills; colour adjustments as image filters with Sketch's tone curve, contrast and then brightness added), slices, hotspots; transforms (rotation, flips after it), resizing constraints; fills (solid, gradients with Sketch's geometry, gradients mixed in OKLab or OKLCH as sRGB stops along the same colours, image patterns), borders (the first enabled border's width and position), shadows, inner shadows, layer, motion and background blurs (Sketch's radius is the standard deviation), opacity and blend modes; clipping masks (an outline mask that shows its own style draws a copy under itself, as Sketch does, and its opacity fades it and what it clips together; alpha masks only mask; broken mask chains wrapped), progressive opacity (Fade) as an alpha mask of its gradient; text with styled runs (UTF-16 ranges), paragraph and vertical alignment, lines placed by Sketch's line spacing behaviour, box sizing, fonts found by their PostScript names among the installed ones (else the family read from the name), variable font axes, Sketch's natural line (ascent and descent rounded, no line gap, a fifth more for classic Mac fonts) for text without a fixed line height; symbols as components (library copies on a page of their own) and instances carrying their masters' layers with overrides (text, nested swaps and hiding, images, also on shapes' image fills, layer and text styles, nested paths), clipping only where the master clips (`clippingBehavior` 1), laid out for their size the way Sketch does it (proportional sharing per pins from format 110, scaling before) and still live; master backgrounds in instances only when the master includes them in both instances and exports, as on Sketch's canvas and renders; Apple's system fonts found under the names designs use, with the platform's tracking kept as letter spacing; shared layer styles as paint (fills, border colours) and effect styles, shared text styles as text styles; Color Variables (also library ones) as colour variables with bindings; prototype links, flow starts, export options, layout and square grids (hidden, as Sketch shows them only in its layout view). Instances of a stack laid out at their size and texts an override changed measured again on open, an auto-width one growing from its aligned edge. Warnings: noise fills, OKLab and OKLCH gradients, motion and zoom blurs (drawn as plain blurs), fonts embedded with their data (not used), Smart Layout (kept as laid out), locked overrides, scaled instances. Tested on fixtures built in code (`crates/format/src/sketch/*_tests.rs`, fuzzed) and locally (`FIGCRAFT_SKETCH_SAMPLES`) on one real Sketch 50 file and the public Apache-2.0 IBM Carbon Design Kit saved by Sketch 68 and 83 (70,000 layers open in ~3 s, debug build; its edition saved by Sketch 47 is refused, as it should be); compared artboard by artboard with Sketch 2026's own renders (`FIGCRAFT_SKETCHTOOL`, black-box): the Sketch 50 file's 73 artboards differ in at most 2.3% of their pixels (0.8% on average) (text metrics, fonts FigCraft doesn't find, antialiasing), Carbon 11's 69 1.1% on average and at most 4.4% (text in IBM Plex, which the file embeds and FigCraft doesn't use yet), a Sketch 64 file's 65 artboards 2.1% on average, a Sketch 2026 showcase file's 16 frames 0.9% on average (at most 1.9%); the rules for master backgrounds, symbol clipping, mask opacity, bitmap fills, image overrides, stretching stacks, blur radii, colour adjustments, gradient interpolation and text growth checked against Sketch's renders of files built for each case (black-box, synthetic) | 5–10 (Smart Layout as auto layout, motion and zoom blurs, several borders of different widths; fonts embedded in the file once `.figcraft` documents can carry fonts: until then they would only last the session). Known limitations: a plain group (not a frame) that fills a stack keeps its layers' size where Sketch stretches them; a font Sketch can't find draws in the installed family's own weight (Sketch falls back to a regular face); text in the system SF Pro comes out a few percent narrower than Sketch's; macOS's reserved system fonts (PingFang) aren't found; brightness past about +0.4 is approximated (image filters can't add); OKLab gradients become sRGB stops (FigCraft gradients mix in sRGB) | | `.jam` (whiteboards) | native to FigJam | **yes, best effort** (`file.open`, `file.import`, File ▸ Open, drop, CLI, MCP) | no | the same archive as a `.fig` (its canvas header reads `fig-jam.`) through the same reader (#1342): it opens as a board (the file kind; a `.fig` stays a design file), with generated sticky and shape backgrounds and text kept (#1341) as ordinary layers rather than native board objects (see [boards-parity](boards-parity.md)); tables, stamps, code blocks and the like come in as frames with their text and connectors as vectors (an elbowed connector keeps the path it was saved with, #1910), with an import note; a layer type the reader doesn't know is left out with a note naming it; writing `.jam` is not supported | — | @@ -189,6 +189,7 @@ source paint coordinates. | Date | Change | Summary | |---|---|---| +| 2026-11-07 | minor | `.fig` import, #2091 item 1: an instance scaled with the Scale tool stores `symbolData.uniformScaleFactor`, which the import never read, so the layers of a 128 px instance of a 256 px component came in at 256 px with the main's radii, strokes and spacing. The layers of an instance now take the main's lengths times the factor (composed through nested instances, so 0.5 inside 0.5 is 0.25 for the inner layers), the lengths the Scale tool scales: sizes and places, corner radii, stroke weights and dashes, effect radii, spreads and offsets, auto layout gaps and paddings, grid gaps, min and max sizes, layout grids, font sizes, pixel line heights and letter spacings, paragraph spacing and indent. A value an override or derived row gives is taken as written, already at the instance's scale; the instance's own size is the file's; a missing, non-finite, non-positive or out-of-range factor (outside 0.001 to 1000) changes nothing. Not scaled: vector outline paths (a network's points follow the layer's size), per-point corner radii, fixed grid tracks, image tile scales and glass effects. Tests: `fig::tests::a_scaled_instance_draws_its_layers_at_the_factor` and `fig::scale_factor_tests`. Numbers unchanged | | 2026-11-03 | patch | M6, #1909: `.jam` import: a connector end whose magnet is `AUTO` (FigJam picks the side when it draws) or `CENTER` (the end aims at the layer's middle) left the side its stale `relativePosition` named, the left one in the reporter's file, so the connectors looped behind their shape or crossed it. It now leaves the side facing the other end, as a board connector drawn here does (`Side::Auto`), for straight, elbowed and curved connectors alike; a named magnet (`TOP`, `RIGHT`, `BOTTOM`, `LEFT`) is unchanged, and an end without a magnet still takes the edge its point lies on. The Plugin API lists the magnets (`ConnectorEndpoint.magnet`: "Which side of the node it attaches to"; NONE, AUTO, TOP, LEFT, BOTTOM, RIGHT, CENTER; "Straight connectors may use only CENTER or NONE magnets"). Test: `connectors_with_an_automatic_side_leave_the_side_facing_the_target`. Numbers unchanged. | | 2026-11-04 | minor | JPG export: `quality` (1 to 100, default 90) on `file.export`, `export.add` / `export.update` and MCP `export`, kept in the export setting; an sRGB file's JPGs embed the sRGB ICC profile, as Display P3 files' JPGs already embedded theirs, since an untagged JPG is only assumed to be sRGB (#2004). | | 2026-11-04 | minor | `.fig` and `.jam` import, #1910: an elbowed connector saved with its path keeps it. FigJam stores `connectorControlPoints`, one per run between the first and the last, each a point on its run (in the connector's parent's coordinates) with the run's axis; the first run leaves the start's side and the last arrives at the end's. They become the `ConnectorPath::Runs` a board connector reshaped by hand has (`figcraft_doc::route_along`), so a connector drawn around a layer in FigJam stays around it instead of being routed through it. Points that don't make such a path (off both axes, two runs in a row the same way, a first or last run sideways to its side or going back into its object, more runs than a hand could make) leave the connector to the router as before, and only connectors routed here count in the "follow FigCraft's own routing" note. A curved connector's `connectorBezierControlPoints` are still not read. Tests: `tail_tests::an_elbow_connector_saved_with_its_path_keeps_it`, `tail_tests::an_elbow_whose_saved_path_doesnt_fit_its_sides_is_routed_here`. |