From 665b4d2aca81af48b8e0eaca4e709ef2e7825844 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 13 Dec 2019 23:59:01 +0100 Subject: =?UTF-8?q?More=20consistent=20library=20code=20and=20functions=20?= =?UTF-8?q?=F0=9F=8E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/tree.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/layout/tree.rs') diff --git a/src/layout/tree.rs b/src/layout/tree.rs index e9d8850d..3c6a4274 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -7,7 +7,7 @@ use crate::style::TextStyle; use super::*; /// Layout a syntax tree into a multibox. -pub fn layout_tree(tree: &SyntaxTree, ctx: LayoutContext) -> LayoutResult { +pub fn layout(tree: &SyntaxTree, ctx: LayoutContext) -> LayoutResult { let mut layouter = TreeLayouter::new(ctx); layouter.layout(tree)?; layouter.finish() @@ -28,6 +28,7 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { spaces: ctx.spaces.clone(), axes: ctx.axes, alignment: ctx.alignment, + repeat: ctx.repeat, debug: ctx.debug, }), style: ctx.style.clone(), @@ -106,8 +107,15 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { FinishLine => {}, FinishRun => {}, - FinishSpace => self.stack.finish_space(true), + FinishSpace => self.stack.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)? + } SetTextStyle(style) => self.style.text = style, SetPageStyle(style) => { @@ -116,6 +124,7 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { } self.style.page = style; + self.ctx.base = style.dimensions.unpadded(style.margins); self.stack.set_spaces(smallvec![ LayoutSpace { dimensions: style.dimensions, @@ -135,18 +144,18 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { } fn finish(self) -> LayoutResult { - Ok(self.stack.finish()) + self.stack.finish() } } fn word_spacing(style: &TextStyle) -> Size { - style.word_spacing * style.font_size + style.word_spacing * style.font_size() } fn flex_spacing(style: &TextStyle) -> Size { - (style.line_spacing - 1.0) * style.font_size + (style.line_spacing - 1.0) * style.font_size() } fn paragraph_spacing(style: &TextStyle) -> Size { - (style.paragraph_spacing - 1.0) * style.font_size + (style.paragraph_spacing - 1.0) * style.font_size() } -- cgit v1.2.3