From c1b1dbcc0925ba1730fabbfbca3c8b99831c5561 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 11 Mar 2021 10:48:29 +0100 Subject: =?UTF-8?q?Better=20expansion=20behaviour=20=F0=9F=90=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes expansion behaviour inheritable by placing it into the area and passing it down during layouting instead of computing some approximation of what we want during execution. --- src/exec/context.rs | 20 +++++--------------- src/exec/mod.rs | 19 ++++++++++++------- src/exec/state.rs | 6 +----- 3 files changed, 18 insertions(+), 27 deletions(-) (limited to 'src/exec') diff --git a/src/exec/context.rs b/src/exec/context.rs index d491a251..4d2047a6 100644 --- a/src/exec/context.rs +++ b/src/exec/context.rs @@ -7,7 +7,7 @@ use super::*; use crate::diag::{Diag, DiagSet}; use crate::geom::{ChildAlign, Dir, Gen, LayoutDirs, Length, Linear, Sides, Size}; use crate::layout::{ - Expansion, Node, NodePad, NodePages, NodePar, NodeSpacing, NodeStack, NodeText, Tree, + Node, NodePad, NodePages, NodePar, NodeSpacing, NodeStack, NodeText, Tree, }; use crate::parse::is_newline; @@ -105,18 +105,18 @@ impl<'a> ExecContext<'a> { } } - /// Execute the body of a function and return the result as a stack node. - pub fn exec_body(&mut self, body: &ValueTemplate, expand: Spec) -> Node { + /// Execute a template and return the result as a stack node. + pub fn exec(&mut self, template: &ValueTemplate) -> Node { let dirs = self.state.dirs; let align = self.state.align; self.start_group(ContentGroup); self.start_par_group(); - body.exec(self); + template.exec(self); self.end_par_group(); let children = self.end_group::().1; - NodeStack { dirs, align, expand, children }.into() + NodeStack { dirs, align, children }.into() } /// Start a page group based on the active page state. @@ -128,7 +128,6 @@ impl<'a> ExecContext<'a> { pub fn start_page_group(&mut self, softness: Softness) { self.start_group(PageGroup { size: self.state.page.size, - expand: self.state.page.expand, padding: self.state.page.margins(), dirs: self.state.dirs, align: self.state.align, @@ -158,7 +157,6 @@ impl<'a> ExecContext<'a> { child: NodeStack { dirs: group.dirs, align: group.align, - expand: group.expand, children, } .into(), @@ -186,13 +184,6 @@ impl<'a> ExecContext<'a> { self.push(NodePar { dirs: group.dirs, align: group.align, - // FIXME: This is a hack and should be superseded by something - // better. - cross_expansion: if self.groups.len() <= 1 { - Expansion::Fill - } else { - Expansion::Fit - }, line_spacing: group.line_spacing, children, }); @@ -306,7 +297,6 @@ pub enum Softness { #[derive(Debug)] struct PageGroup { size: Size, - expand: Spec, padding: Sides, dirs: LayoutDirs, align: ChildAlign, diff --git a/src/exec/mod.rs b/src/exec/mod.rs index ea2c90f4..79ad81e7 100644 --- a/src/exec/mod.rs +++ b/src/exec/mod.rs @@ -11,8 +11,7 @@ use std::rc::Rc; use crate::diag::Pass; use crate::env::Env; use crate::eval::{ExprMap, TemplateFunc, TemplateNode, Value, ValueTemplate}; -use crate::geom::Spec; -use crate::layout::{self, Expansion, NodeSpacing, NodeStack}; +use crate::layout::{self, NodeFixed, NodeSpacing, NodeStack}; use crate::pretty::pretty; use crate::syntax::*; @@ -120,11 +119,17 @@ impl Exec for NodeRaw { ctx.apply_parbreak(); } - ctx.push(NodeStack { - dirs: ctx.state.dirs, - align: ctx.state.align, - expand: Spec::uniform(Expansion::Fit), - children, + // This is wrapped in a fixed node to make sure the stack fits to its + // content instead of filling the available area. + ctx.push(NodeFixed { + width: None, + height: None, + child: NodeStack { + dirs: ctx.state.dirs, + align: ctx.state.align, + children, + } + .into(), }); if self.block { diff --git a/src/exec/state.rs b/src/exec/state.rs index 416b5d08..3293662a 100644 --- a/src/exec/state.rs +++ b/src/exec/state.rs @@ -3,9 +3,8 @@ use std::rc::Rc; use fontdock::{fallback, FallbackTree, FontStretch, FontStyle, FontVariant, FontWeight}; use crate::geom::{ - Align, ChildAlign, Dir, LayoutDirs, Length, Linear, Relative, Sides, Size, Spec, + Align, ChildAlign, Dir, LayoutDirs, Length, Linear, Relative, Sides, Size, }; -use crate::layout::Expansion; use crate::paper::{Paper, PaperClass, PAPER_A4}; /// The evaluation state. @@ -42,8 +41,6 @@ pub struct PageState { pub class: PaperClass, /// The width and height of the page. pub size: Size, - /// Whether the expand the pages to the `size` or to fit the content. - pub expand: Spec, /// The amount of white space on each side of the page. If a side is set to /// `None`, the default for the paper class is used. pub margins: Sides>, @@ -55,7 +52,6 @@ impl PageState { Self { class: paper.class, size: paper.size(), - expand: Spec::uniform(Expansion::Fill), margins: Sides::uniform(None), } } -- cgit v1.2.3