diff options
| -rw-r--r-- | library/src/layout/mod.rs | 17 | ||||
| -rw-r--r-- | library/src/lib.rs | 2 | ||||
| -rw-r--r-- | library/src/structure/doc.rs | 9 | ||||
| -rw-r--r-- | src/lib.rs | 8 | ||||
| -rw-r--r-- | src/model/items.rs | 7 |
5 files changed, 28 insertions, 15 deletions
diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs index b05da901..fdf02c93 100644 --- a/library/src/layout/mod.rs +++ b/library/src/layout/mod.rs @@ -49,20 +49,25 @@ use crate::text::{ #[capability] pub trait LayoutRoot { /// Layout into one frame per page. - fn layout_root(&self, world: Tracked<dyn World>) -> SourceResult<Vec<Frame>>; + fn layout_root( + &self, + world: Tracked<dyn World>, + styles: StyleChain, + ) -> SourceResult<Vec<Frame>>; } impl LayoutRoot for Content { #[comemo::memoize] - fn layout_root(&self, world: Tracked<dyn World>) -> SourceResult<Vec<Frame>> { - let styles = StyleChain::with_root(&world.config().styles); + fn layout_root( + &self, + world: Tracked<dyn World>, + styles: StyleChain, + ) -> SourceResult<Vec<Frame>> { let scratch = Scratch::default(); - let mut builder = Builder::new(world, &scratch, true); builder.accept(self, styles)?; - let (doc, shared) = builder.into_doc(styles)?; - doc.layout(world, shared) + doc.layout_root(world, shared) } } diff --git a/library/src/lib.rs b/library/src/lib.rs index 41c841f2..7a292c6d 100644 --- a/library/src/lib.rs +++ b/library/src/lib.rs @@ -154,7 +154,7 @@ pub fn styles() -> StyleMap { /// Construct the standard lang item mapping. pub fn items() -> LangItems { LangItems { - root: |world, content| content.layout_root(world), + root: |content, world, styles| content.layout_root(world, styles), em: |styles| styles.get(text::TextNode::SIZE), dir: |styles| styles.get(text::TextNode::DIR), space: || text::SpaceNode.pack(), diff --git a/library/src/structure/doc.rs b/library/src/structure/doc.rs index ac12c3ab..42ad628e 100644 --- a/library/src/structure/doc.rs +++ b/library/src/structure/doc.rs @@ -1,13 +1,16 @@ -use crate::layout::PageNode; +use crate::layout::{LayoutRoot, PageNode}; use crate::prelude::*; /// A sequence of page runs. #[derive(Hash)] pub struct DocNode(pub StyleVec<PageNode>); -impl DocNode { +#[node(LayoutRoot)] +impl DocNode {} + +impl LayoutRoot for DocNode { /// Layout the document into a sequence of frames, one per page. - pub fn layout( + fn layout_root( &self, world: Tracked<dyn World>, styles: StyleChain, @@ -49,7 +49,7 @@ use comemo::{Prehashed, Track}; use crate::diag::{FileResult, SourceResult}; use crate::font::{Font, FontBook}; use crate::frame::Frame; -use crate::model::{LangItems, Route, Scope, StyleMap}; +use crate::model::{LangItems, Route, Scope, StyleChain, StyleMap}; use crate::syntax::{Source, SourceId}; use crate::util::Buffer; @@ -62,10 +62,12 @@ pub fn typeset( world: &(dyn World + 'static), main: SourceId, ) -> SourceResult<Vec<Frame>> { - crate::model::set_lang_items(world.config().items); + let config = world.config(); + crate::model::set_lang_items(config.items); let route = Route::default(); let module = model::eval(world.track(), route.track(), main)?; - item!(root)(world.track(), &module.content) + let styles = StyleChain::with_root(&config.styles); + item!(root)(&module.content, world.track(), styles) } /// The environment in which typesetting occurs. diff --git a/src/model/items.rs b/src/model/items.rs index 21d45b67..771756fe 100644 --- a/src/model/items.rs +++ b/src/model/items.rs @@ -42,8 +42,11 @@ macro_rules! item { #[derive(Copy, Clone)] pub struct LangItems { /// The root layout function. - pub root: - fn(world: Tracked<dyn World>, document: &Content) -> SourceResult<Vec<Frame>>, + pub root: fn( + content: &Content, + world: Tracked<dyn World>, + styles: StyleChain, + ) -> SourceResult<Vec<Frame>>, /// Access the em size. pub em: fn(StyleChain) -> Abs, /// Access the text direction. |
