summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-22 20:52:58 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-22 21:09:20 +0100
commitc2749f761591b462ceeccf4a42b9ac75d8addf85 (patch)
treea2c51175fa996f5e59666da762b2e7d9e25b43e3 /library
parentea2a1525f0fc461ec9a5dc1839aec9b66c4e1ecc (diff)
More sensible `LayoutRoot`
Diffstat (limited to 'library')
-rw-r--r--library/src/layout/mod.rs17
-rw-r--r--library/src/lib.rs2
-rw-r--r--library/src/structure/doc.rs9
3 files changed, 18 insertions, 10 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,