Skip to content

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

Merge #523: Parent-page items are composed for their page by index, not page name

aionggd11ccad30ab7
diff --cc crates/pdf/src/export.rs
index f08be5de0,dcf8abb83..2c000b1e8
--- a/crates/pdf/src/export.rs
+++ b/crates/pdf/src/export.rs
@@@ -752,20 -750,10 +751,20 @@@ impl Exporter<'_>
tree
}
- fn item(&mut self, s: &mut Surface, it: &Item, parent: Affine, page_name: Option<&str>) {
+ fn item(&mut self, s: &mut Surface, it: &Item, parent: Affine, page: Option<usize>) {
+ if self.drawing_items.len() >= 64 || self.drawing_items.contains(&it.id) {
+ self.warnings.push(format!("Cyclic or excessively nested item {} was not rendered", it.id));
+ return;
+ }
+ self.drawing_items.push(it.id);
- self.item_guarded(s, it, parent, page_name);
++ self.item_guarded(s, it, parent, page);
+ self.drawing_items.pop();
+ }
+
- fn item_guarded(&mut self, s: &mut Surface, it: &Item, parent: Affine, page_name: Option<&str>) {
++ fn item_guarded(&mut self, s: &mut Surface, it: &Item, parent: Affine, page: Option<usize>) {
let gf = &it.effects.gradient_feather;
if !gf.on || it.hidden || it.nonprinting {
- return self.item_inner(s, it, parent, page_name);
+ return self.item_inner(s, it, parent, page);
}
// Gradient feather: a luminosity mask (white = opaque) over the object.
let xf = parent * it.xf;
@@@ -972,30 -961,16 +971,30 @@@
for _ in 0..pushes {
s.pop();
}
- // Anchored objects in the frame's text.
- if let Content::Text(tfr) = &it.content
- && let Some(st) = doc.story(tfr.story).filter(|st| !st.objects.is_empty())
- {
+ if let Content::Text(tfr) = &it.content {
- let cs = self.cache.get(doc, tfr.story, page_name);
+ let cs = self.cache.get(doc, tfr.story, page);
if let Some(ft) = cs.frame(it.id) {
- self.frame_objects(s, ft, xf * doc.text_local(it), page_name);
- for o in &ft.objects {
- if let Some(obj) = st.objects.get(o.index) {
- self.item(s, &obj.item, xf * Affine::translate(o.origin.to_vec2()), page);
- }
++ self.frame_objects(s, ft, xf * doc.text_local(it), page);
+ }
+ }
+ }
+
+ /// Draw embedded page items after restoring the surface, retaining spread-space
+ /// transforms for page culling (also for anonymous note and cell stories).
- fn frame_objects(&mut self, s: &mut Surface, ft: &designcraft_compose::FrameText, xf: Affine, page_name: Option<&str>) {
++ fn frame_objects(&mut self, s: &mut Surface, ft: &designcraft_compose::FrameText, xf: Affine, page: Option<usize>) {
+ let mut pending = vec![(ft, xf)];
+ while let Some((frame, transform)) = pending.pop() {
+ for object in &frame.objects {
- self.item(s, &object.object.item, transform * Affine::translate(object.origin.to_vec2()), page_name);
++ self.item(s, &object.object.item, transform * Affine::translate(object.origin.to_vec2()), page);
+ }
+ for note in &frame.notes {
+ if let Some(frame) = note.text.frames.first() {
+ pending.push((frame, transform * Affine::translate(note.origin.to_vec2())));
+ }
+ }
+ for cell in frame.tables.iter().flat_map(|t| &t.cells) {
+ if let Some(frame) = cell.text.frames.first() {
+ pending.push((frame, transform * Affine::translate(cell.origin.to_vec2())));
}
}
}
diff --cc crates/render/src/lib.rs
index 06b728902,0310eac35..414326ccd
--- a/crates/render/src/lib.rs
+++ b/crates/render/src/lib.rs
@@@ -223,8 -216,7 +223,8 @@@ pub struct Renderer
resources: Resources,
glyphs: text::GlyphCache,
/// Composed stories looked up during the current render.
- stories: HashMap<(StoryId, Option<String>), Arc<ComposedStory>>,
+ stories: HashMap<(StoryId, Option<usize>), Arc<ComposedStory>>,
+ drawing_items: Vec<designcraft_doc::ItemId>,
pub threads: u16,
pub stats: FrameStats,
}
@@@ -443,21 -428,9 +442,21 @@@ impl Renderer
}
}
}
+ if let Some(area) = grid_area.filter(|_| !grid.in_back) {
+ grid::draw(ctx, f, sp, grid, area);
+ }
}
- fn draw_item(&mut self, ctx: &mut RenderContext, f: &Frame, it: &Item, parent: Affine, page_name: Option<&str>) {
+ fn draw_item(&mut self, ctx: &mut RenderContext, f: &Frame, it: &Item, parent: Affine, page: Option<usize>) {
+ if self.drawing_items.len() >= 64 || self.drawing_items.contains(&it.id) {
+ return;
+ }
+ self.drawing_items.push(it.id);
- self.draw_item_inner(ctx, f, it, parent, page_name);
++ self.draw_item_inner(ctx, f, it, parent, page);
+ self.drawing_items.pop();
+ }
+
- fn draw_item_inner(&mut self, ctx: &mut RenderContext, f: &Frame, it: &Item, parent: Affine, page_name: Option<&str>) {
++ fn draw_item_inner(&mut self, ctx: &mut RenderContext, f: &Frame, it: &Item, parent: Affine, page: Option<usize>) {
if it.hidden || f.opts.hidden.contains(&it.id) || f.opts.printing_only && it.nonprinting {
return;
}