diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-12-02 15:41:39 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-12-02 15:45:18 +0100 |
| commit | 9bc90c371fb41a2d6dc08eb4673e5be15f829514 (patch) | |
| tree | 454a47ce82c2229e79a139a8bdeaed9add1e0a14 /library/src/layout | |
| parent | 5110a41de1ca2236739ace2d37a1af912bb029f1 (diff) | |
Introspection
Diffstat (limited to 'library/src/layout')
| -rw-r--r-- | library/src/layout/mod.rs | 34 | ||||
| -rw-r--r-- | library/src/layout/page.rs | 4 | ||||
| -rw-r--r-- | library/src/layout/par.rs | 16 |
3 files changed, 46 insertions, 8 deletions
diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs index e3691732..047d78f9 100644 --- a/library/src/layout/mod.rs +++ b/library/src/layout/mod.rs @@ -59,9 +59,11 @@ impl LayoutRoot for Content { fn cached( node: &Content, world: comemo::Tracked<dyn World>, + provider: TrackedMut<StabilityProvider>, + introspector: Tracked<Introspector>, styles: StyleChain, ) -> SourceResult<Document> { - let mut vt = Vt { world }; + let mut vt = Vt { world, provider, introspector }; let scratch = Scratch::default(); let (realized, styles) = realize_root(&mut vt, &scratch, node, styles)?; realized @@ -70,7 +72,13 @@ impl LayoutRoot for Content { .layout_root(&mut vt, styles) } - cached(self, vt.world, styles) + cached( + self, + vt.world, + TrackedMut::reborrow_mut(&mut vt.provider), + vt.introspector, + styles, + ) } } @@ -97,10 +105,12 @@ impl Layout for Content { fn cached( node: &Content, world: comemo::Tracked<dyn World>, + provider: TrackedMut<StabilityProvider>, + introspector: Tracked<Introspector>, styles: StyleChain, regions: &Regions, ) -> SourceResult<Fragment> { - let mut vt = Vt { world }; + let mut vt = Vt { world, provider, introspector }; let scratch = Scratch::default(); let (realized, styles) = realize_block(&mut vt, &scratch, node, styles)?; let barrier = Style::Barrier(realized.id()); @@ -111,7 +121,14 @@ impl Layout for Content { .layout(&mut vt, styles, regions) } - cached(self, vt.world, styles, regions) + cached( + self, + vt.world, + TrackedMut::reborrow_mut(&mut vt.provider), + vt.introspector, + styles, + regions, + ) } } @@ -290,6 +307,15 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> { content: &'a Content, styles: StyleChain<'a>, ) -> SourceResult<()> { + // Prepare only if this is the first application for this node. + if let Some(node) = content.with::<dyn Prepare>() { + if !content.is_prepared() { + let prepared = node.prepare(self.vt, content.clone().prepared(), styles); + let stored = self.scratch.content.alloc(prepared); + return self.accept(stored, styles); + } + } + if let Some(styled) = content.to::<StyledNode>() { return self.styled(styled, styles); } diff --git a/library/src/layout/page.rs b/library/src/layout/page.rs index 08411ad1..dee77abd 100644 --- a/library/src/layout/page.rs +++ b/library/src/layout/page.rs @@ -5,7 +5,7 @@ use crate::prelude::*; use crate::text::TextNode; /// Layouts its child onto one or multiple pages. -#[derive(PartialEq, Clone, Hash)] +#[derive(Clone, Hash)] pub struct PageNode(pub Content); #[node] @@ -157,7 +157,7 @@ impl PagebreakNode { } /// A header, footer, foreground or background definition. -#[derive(Debug, Clone, PartialEq, Hash)] +#[derive(Debug, Clone, Hash)] pub enum Marginal { /// Nothing, None, diff --git a/library/src/layout/par.rs b/library/src/layout/par.rs index e96845dd..78e9b2a3 100644 --- a/library/src/layout/par.rs +++ b/library/src/layout/par.rs @@ -57,13 +57,15 @@ impl ParNode { fn cached( par: &ParNode, world: Tracked<dyn World>, + provider: TrackedMut<StabilityProvider>, + introspector: Tracked<Introspector>, styles: StyleChain, consecutive: bool, width: Abs, base: Size, expand: bool, ) -> SourceResult<Fragment> { - let mut vt = Vt { world }; + let mut vt = Vt { world, provider, introspector }; // Collect all text into one string for BiDi analysis. let (text, segments) = collect(par, &styles, consecutive); @@ -80,7 +82,17 @@ impl ParNode { finalize(&mut vt, &p, &lines, width, base, expand) } - cached(self, vt.world, styles, consecutive, width, base, expand) + cached( + self, + vt.world, + TrackedMut::reborrow_mut(&mut vt.provider), + vt.introspector, + styles, + consecutive, + width, + base, + expand, + ) } } |
