Skip to content

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

Merge upstream main e862e0a6 into next

aiongg004e585e3470
diff --cc crates/engine/src/cmd/preflight.rs
index 5ec2bd47d,f5ee8dfdf..e82299cc2
--- a/crates/engine/src/cmd/preflight.rs
+++ b/crates/engine/src/cmd/preflight.rs
@@@ -63,51 -66,12 +66,51 @@@ fn missing_glyphs
}
}
for c in f.tables.iter().flat_map(|t| &t.cells) {
- missing_glyphs(&c.text, &c.source, depth + 1, out);
+ missing_glyphs(&c.text, Some(owner), depth + 1, out);
}
for n in &f.notes {
- missing_glyphs(&n.text, &n.source, depth + 1, out);
+ missing_glyphs(&n.text, Some(owner), depth + 1, out);
+ }
+ }
+}
+
+/// Locate an embedded frame at the outer page frame that actually renders it.
+fn overset_location(s: &Session, target: designcraft_doc::ItemId) -> Option<(designcraft_doc::ItemId, Option<usize>)> {
+ let d = &s.active()?.doc;
+ if let Some(loc) = d.find(target) {
- return Some((target, d.item(target).and_then(|it| page_of(d, loc.spread, it))));
++ return Some((target, d.item(target).and_then(|it| page_of(d, loc.spread, it, d.parent_xf(&loc)))));
+ }
+ fn contains(root: &designcraft_compose::FrameText, target: designcraft_doc::ItemId) -> bool {
+ let mut frames = vec![root];
+ while let Some(frame) = frames.pop() {
+ for object in &frame.objects {
+ let mut found = false;
+ object.object.item.walk(&mut |it| {
+ found |= it.id == target;
+ });
+ if found {
+ return true;
+ }
+ }
+ frames.extend(frame.notes.iter().flat_map(|n| n.text.frames.iter()));
+ frames.extend(frame.tables.iter().flat_map(|t| t.cells.iter().flat_map(|c| c.text.frames.iter())));
+ }
+ false
+ }
+ let mut current = target;
+ let mut seen = std::collections::HashSet::new();
+ let embedded = d.anchored_items();
+ while seen.insert(current) {
+ let owner = embedded.iter().find_map(|(owner, it)| (it.id == current).then_some(*owner))?;
+ let cs = s.cache.get(d, owner, None);
+ // Search each host frame separately, including objects in its notes and cells.
+ let frame = cs.frames.iter().find(|f| contains(f, current))?;
+ current = frame.frame;
+ if let Some(loc) = d.find(current) {
- return Some((current, d.item(current).and_then(|it| page_of(d, loc.spread, it))));
++ return Some((current, d.item(current).and_then(|it| page_of(d, loc.spread, it, d.parent_xf(&loc)))));
}
}
+ None
}
pub fn check(s: &Session, min_ppi: f64) -> Vec<Issue> {
@@@ -234,52 -160,56 +237,56 @@@
severity: "error",
kind: "missingGlyphs",
message: format!("Missing glyphs in {} {}: {}{more}", face.family, face.style, listed.join(" ")),
- item: None,
- page: None,
+ item: Some(item.0),
- page: d.find(item).zip(d.item(item)).and_then(|(loc, it)| page_of(d, loc.spread, it)),
++ page: d.find(item).zip(d.item(item)).and_then(|(loc, it)| page_of(d, loc.spread, it, d.parent_xf(&loc))),
});
}
- // Items.
+ // Carry the ancestor transform in the same order as rendering, retaining pre-order.
for (si, sp) in d.spreads.iter().enumerate() {
- for top in &sp.items {
- top.walk(&mut |it| {
- let page = page_of(d, SpreadRef::Doc(si), it);
- match &it.content {
- Content::Graphic(g) => match d.assets.get(&g.asset) {
- None => {
- out.push(Issue { severity: "error", kind: "missingLink", message: "Missing graphic".into(), item: Some(it.id.0), page })
- }
- Some(a) if a.data.is_empty() => out.push(Issue {
- severity: "error",
- kind: "missingLink",
- message: format!("Missing link: {}", a.link.as_deref().unwrap_or(&a.name)),
- item: Some(it.id.0),
- page,
- }),
- Some(a) => {
- // Effective ppi: pixels per inch at the placed size. Placed PDF and
- // SVG pages export as vectors; their `pixels` is only the preview's.
- let vector = designcraft_images::is_pdf(&a.data) || designcraft_images::is_svg(&a.data);
- if let Some((pw, _)) = a.pixels.filter(|_| !vector) {
- let placed_w = (g.xf * it.xf).as_coeffs()[0].hypot((g.xf * it.xf).as_coeffs()[1]) * g.size.0;
- let ppi = pw as f64 / (placed_w / 72.0).max(1e-6);
- if d.settings.intent == Intent::Print && ppi < min_ppi {
- out.push(Issue {
- severity: "warning",
- kind: "lowResolution",
- message: format!("{}: effective {ppi:.0} ppi (< {min_ppi:.0})", a.name),
- item: Some(it.id.0),
- page,
- });
- }
+ let mut pending: Vec<_> = sp.items.iter().rev().map(|it| (it.as_ref(), Affine::IDENTITY)).collect();
+ while let Some((it, parent)) = pending.pop() {
+ let xf = parent * it.xf;
+ pending.extend(it.children().iter().rev().map(|child| (child.as_ref(), xf)));
+ let page = page_of(d, SpreadRef::Doc(si), it, parent);
+ match &it.content {
+ Content::Graphic(g) => match d.assets.get(&g.asset) {
+ None => out.push(Issue { severity: "error", kind: "missingLink", message: "Missing graphic".into(), item: Some(it.id.0), page }),
+ Some(a) if a.data.is_empty() => out.push(Issue {
+ severity: "error",
+ kind: "missingLink",
+ message: format!("Missing link: {}", a.link.as_deref().unwrap_or(&a.name)),
+ item: Some(it.id.0),
+ page,
+ }),
+ Some(a) => {
+ // Placed PDF and SVG pages export as vectors; `pixels` is only the preview's.
+ let vector = designcraft_images::is_pdf(&a.data) || designcraft_images::is_svg(&a.data);
+ if let Some((pw, ph)) = a.pixels.filter(|_| !vector) {
+ // Measure each image axis in points, not its rotated bounding box or
+ // cropped frame. Either axis can fall below the minimum resolution.
+ let [xx, yx, xy, yy, _, _] = (xf * g.xf).as_coeffs();
+ let placed_w = xx.hypot(yx) * g.size.0;
+ let placed_h = xy.hypot(yy) * g.size.1;
+ let ppi_x = pw as f64 / (placed_w / 72.0).max(1e-6);
+ let ppi_y = ph as f64 / (placed_h / 72.0).max(1e-6);
+ let ppi = ppi_x.min(ppi_y);
+ if d.settings.intent == Intent::Print && ppi < min_ppi {
+ out.push(Issue {
+ severity: "warning",
+ kind: "lowResolution",
+ message: format!("{}: effective {ppi:.0} ppi (< {min_ppi:.0})", a.name),
+ item: Some(it.id.0),
+ page,
+ });
}
}
- },
- Content::Text(tf) if d.story(tf.story).is_some_and(|s| s.is_empty()) => {
- out.push(Issue { severity: "warning", kind: "emptyText", message: "Empty text frame".into(), item: Some(it.id.0), page });
}
- _ => {}
+ },
+ Content::Text(tf) if d.story(tf.story).is_some_and(|s| s.is_empty()) => {
+ out.push(Issue { severity: "warning", kind: "emptyText", message: "Empty text frame".into(), item: Some(it.id.0), page });
}
- });
+ _ => {}
+ }
}
}
// RGB swatches in use in a print document.