summaryrefslogtreecommitdiff
path: root/src/layout/tree.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout/tree.rs')
-rw-r--r--src/layout/tree.rs57
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![
+ self.layouter.set_spaces(smallvec![
LayoutSpace {
dimensions: style.dimensions,
padding: margins,
@@ -137,7 +138,7 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
}
SetAlignment(alignment) => self.ctx.alignment = alignment,
SetAxes(axes) => {
- self.stack.set_axes(axes);
+ self.layouter.set_axes(axes);
self.ctx.axes = axes;
}
}
@@ -146,18 +147,6 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
}
fn finish(self) -> LayoutResult<MultiLayout> {
- self.stack.finish()
+ self.layouter.finish()
}
}
-
-fn word_spacing(style: &TextStyle) -> Size {
- style.word_spacing * style.font_size()
-}
-
-fn flex_spacing(style: &TextStyle) -> Size {
- (style.line_spacing - 1.0) * style.font_size()
-}
-
-fn paragraph_spacing(style: &TextStyle) -> Size {
- (style.paragraph_spacing - 1.0) * style.font_size()
-}