diff --git a/crates/format/src/fig/board_import_tests.rs b/crates/format/src/fig/board_import_tests.rs index efbabde05..fb4d4ba30 100644 --- a/crates/format/src/fig/board_import_tests.rs +++ b/crates/format/src/fig/board_import_tests.rs @@ -584,6 +584,21 @@ fn a_jam_diamond_is_a_native_shape_drawn_by_figcraft() { assert_eq!(label.align_h, figcraft_doc::TextAlignH::Center); } +/// A shape past the importer's size cap is drawn at the capped size, so its outline stays inside +/// its frame. +#[test] +fn a_jam_shape_past_the_size_cap_draws_its_outline_at_the_cap() { + let mut layer = shape_node("DIAMOND"); + set(&mut layer, "size", xy(2_000_000.0, 2_000_000.0)); + let (doc, warnings) = jam(layer); + let frame = named(&doc, "Board object"); + assert_eq!(frame.board, Some(figcraft_doc::BoardItem::Shape { shape: figcraft_doc::BoardShape::Diamond }), "{warnings:?}"); + assert_eq!((frame.width, frame.height), (1e6, 1e6)); + let outline = doc.node(frame.children[0]).unwrap(); + let NodeKind::Vector { network } = &outline.kind else { panic!("{:?}", outline.kind) }; + assert_eq!(*network, figcraft_doc::VectorNetwork::from_path(&figcraft_doc::BoardShape::Diamond.path(1e6, 1e6))); +} + /// 23 of FigJam's 30 shape kinds have a FigCraft outline; the other 7 stay frames and say which. #[test] fn every_figjam_shape_kind_maps_or_stays_a_frame() { diff --git a/crates/format/src/fig/map/board.rs b/crates/format/src/fig/map/board.rs index 7ea2de801..723c490bd 100644 --- a/crates/format/src/fig/map/board.rs +++ b/crates/format/src/fig/map/board.rs @@ -135,6 +135,9 @@ impl<'a> Mapper<'a> { if !(w.is_finite() && h.is_finite() && w > 0.0 && h > 0.0) { return None; } + // The REST reader caps every size; the outline is drawn at the capped size too, so it + // stays inside its frame. + let (w, h) = (w.min(crate::rest::props::MAX_SIZE), h.min(crate::rest::props::MAX_SIZE)); // Everything is valid: build the outline from the record's paints, then the frame. let mut outline = Obj::new(); outline.insert("id".into(), json!(format!("{rest_id};generated0"))); diff --git a/crates/format/src/rest/props.rs b/crates/format/src/rest/props.rs index f5be3d279..e68af9d88 100644 --- a/crates/format/src/rest/props.rs +++ b/crates/format/src/rest/props.rs @@ -13,7 +13,7 @@ use serde_json::Value; use super::Ctx; /// Largest width/height/stroke/radius/spacing value taken from the file. -pub(super) const MAX_SIZE: f64 = 1e6; +pub(crate) const MAX_SIZE: f64 = 1e6; /// Largest coordinate taken from the file. pub(super) const MAX_COORD: f64 = 1e7; /// Most entries read from any one list (paints, effects, dashes, grids…).