Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge storytold/main into fix/1589-audit-dc-08-non-finite-idml-numb

Brandon Thomasb84f2684307a
diff --cc crates/idml/src/tests.rs
index 6999b78b2,1a9734a6b..da9d8f91f
--- a/crates/idml/src/tests.rs
+++ b/crates/idml/src/tests.rs
@@@ -4369,38 -4369,36 +4369,72 @@@ fn cell_first_baseline_comes_from_cell_
assert_eq!(s2.first_baseline, Some(FirstBaseline::CapHeight));
}
+ /// A graphic placed in a table cell is written into the cell, not dropped.
+ #[test]
+ fn exports_graphic_in_table_cell() {
+ let mut d = Document::new(&NewDocument::default());
+ let lid = d.default_layer();
+ let (_, sid) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(40.0, 40.0, 400.0, 400.0), lid, "Intro", ParaFormat::default()).unwrap();
+ let asset = designcraft_doc::AssetId(d.alloc());
+ let id = d.add_asset(designcraft_doc::Asset {
+ id: asset,
+ name: "tick.png".into(),
+ mime: "image/png".into(),
+ data: std::sync::Arc::new(vec![1, 2, 3]),
+ ..Default::default()
+ });
+ let mut t = designcraft_doc::Table::new(d.alloc(), 2, 2, 0, 0, 200.0);
+ t.cell_mut(1, 0).unwrap().graphic = Some(designcraft_doc::Graphic {
+ asset: id,
+ size: (24.0, 24.0),
+ xf: designcraft_geom::Affine::IDENTITY,
+ clip: None,
+ auto_fit: Default::default(),
+ fit_align: 4,
+ crop: [0.0; 4],
+ wrap: Default::default(),
+ fill: Default::default(),
+ });
+ d.story_mut(sid).unwrap().insert_table(5, t);
+ let story = zip_text(&export_idml(&d), "Stories/");
+ let cell = story.split("<Cell ").nth(3).unwrap_or_default();
+ let cell = cell.split("</Cell>").next().unwrap_or_default();
+ assert!(cell.contains("<Image "), "{story}");
+ assert!(cell.contains("ClipContentToCell=\"true\""), "{story}");
+ }
++
+/// Non-finite numbers in colour values, page bounds and item transforms (NaN, infinities and
+/// values like 1e300 that overflow `f32`) never reach the model: JSON would write them as null.
+#[test]
+fn non_finite_number_lists_never_reach_the_model() {
+ let graphic = GRAPHIC.replace(r#"ColorValue="255 0 0""#, r#"ColorValue="NaN 1e300 inf""#);
+ let spread = SPREAD
+ .replace(r#"Self="p2" AppliedMaster="m1" GeometricBounds="0 0 700 500""#, r#"Self="p2" AppliedMaster="m1" GeometricBounds="0 0 NaN 500""#)
+ .replace(r#"ItemTransform="1 0 0 1 50 -300""#, r#"ItemTransform="1 0 0 1 inf -300""#);
+ let bytes = zip_files(&[
+ ("designmap.xml", DESIGNMAP),
+ ("Resources/Graphic.xml", &graphic),
+ ("Resources/Styles.xml", STYLES),
+ ("Resources/Preferences.xml", PREFS),
+ ("MasterSpreads/MasterSpread_m1.xml", MASTER),
+ ("Spreads/Spread_sp1.xml", &spread),
+ ("Stories/Story_s1.xml", STORY),
+ ]);
+ let doc = import_idml(&bytes).unwrap();
+ for s in &doc.swatches {
+ if let SwatchValue::Color { color, .. } | SwatchValue::Paper { color } = &s.value {
+ let parts: Vec<f32> = match *color {
+ Color::Rgb { r, g, b } => vec![r, g, b],
+ Color::Cmyk { c, m, y, k } => vec![c, m, y, k],
+ Color::Gray { k } => vec![k],
+ };
+ assert!(parts.iter().all(|v| v.is_finite()), "swatch {} is not finite: {color:?}", s.name);
+ }
+ }
+ for sp in doc.spreads.iter().chain(&doc.parents) {
+ for p in &sp.pages {
+ assert!(p.width.is_finite() && p.height.is_finite() && p.x.is_finite(), "page {p:?}");
+ }
+ }
+ assert_eq!(doc.non_finite_item(), None);
+}