diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-12-30 22:28:56 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-12-30 22:28:56 +0100 |
| commit | 269f069a4d721a986807293ef71be1348bfae3d4 (patch) | |
| tree | 31b737c4ff2aead3eb5e2673828595bb26622032 /src/layout/tree.rs | |
| parent | b8620121a692df6313eeb5ccf7baf89c1e364116 (diff) | |
Simple line layouter 🧾
Diffstat (limited to 'src/layout/tree.rs')
| -rw-r--r-- | src/layout/tree.rs | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 7910fdd3..db59ca8d 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -16,7 +16,7 @@ pub fn layout(tree: &SyntaxTree, ctx: LayoutContext) -> LayoutResult<MultiLayout #[derive(Debug, Clone)] struct TreeLayouter<'a, 'p> { ctx: LayoutContext<'a, 'p>, - stack: StackLayouter, + layouter: LineLayouter, style: LayoutStyle, } @@ -24,12 +24,13 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { /// Create a new syntax tree layouter. fn new(ctx: LayoutContext<'a, 'p>) -> TreeLayouter<'a, 'p> { TreeLayouter { - stack: StackLayouter::new(StackContext { + layouter: LineLayouter::new(LineContext { spaces: ctx.spaces.clone(), axes: ctx.axes, alignment: ctx.alignment, repeat: ctx.repeat, debug: ctx.debug, + line_spacing: ctx.style.text.line_spacing(), }), style: ctx.style.clone(), ctx, @@ -59,29 +60,27 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { let layout = layout_text(text, TextContext { loader: &self.ctx.loader, style: &self.style.text, + axes: self.ctx.axes, alignment: self.ctx.alignment, })?; - self.stack.add(layout) + self.layouter.add(layout) } fn layout_space(&mut self) { - + self.layouter.add_primary_spacing(self.style.text.word_spacing(), WORD_KIND); } fn layout_paragraph(&mut self) -> LayoutResult<()> { - Ok(self.stack.add_spacing( - paragraph_spacing(&self.style.text), - PARAGRAPH_KIND, - )) + self.layouter.add_secondary_spacing(self.style.text.paragraph_spacing(), PARAGRAPH_KIND) } fn layout_func(&mut self, func: &FuncCall) -> LayoutResult<()> { let commands = func.0.layout(LayoutContext { style: &self.style, - spaces: self.stack.remaining(), + spaces: self.layouter.remaining(), nested: true, - debug: true, + debug: false, .. self.ctx })?; @@ -98,26 +97,28 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { match command { LayoutTree(tree) => self.layout(tree)?, - Add(layout) => self.stack.add(layout)?, - AddMultiple(layouts) => self.stack.add_multiple(layouts)?, + Add(layout) => self.layouter.add(layout)?, + AddMultiple(layouts) => self.layouter.add_multiple(layouts)?, AddSpacing(space, kind, axis) => match axis { - Primary => {}, - Secondary => self.stack.add_spacing(space, kind), + Primary => self.layouter.add_primary_spacing(space, kind), + Secondary => self.layouter.add_secondary_spacing(space, kind)?, } - FinishLine => {}, - FinishRun => {}, - FinishSpace => self.stack.finish_space(true)?, + FinishLine => self.layouter.finish_line()?, + FinishSpace => self.layouter.finish_space(true)?, BreakParagraph => self.layout_paragraph()?, BreakPage => { if self.ctx.nested { error!("page break cannot be issued from nested context"); } - self.stack.finish_space(true)? + self.layouter.finish_space(true)? } - SetTextStyle(style) => self.style.text = style, + SetTextStyle(style) => { + self.layouter.set_line_spacing(style.line_spacing()); + self.style.text = style; + } SetPageStyle(style) => { if self.ctx.nested { error!("page style cannot be altered in nested context"); @@ -127,7 +128,7 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { let margins = style.margins(); self.ctx.base = style.dimensions.unpadded(margins); - self.stack.set_spaces(smallvec