From 6672f8f7dfcb38bbda3ec92bdf95341c05e9a782 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 4 Oct 2020 18:18:55 +0200 Subject: =?UTF-8?q?Remove=20Typesetter=20in=20favor=20of=20typeset=20funct?= =?UTF-8?q?ion=20=F0=9F=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/mod.rs | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'src/layout/mod.rs') diff --git a/src/layout/mod.rs b/src/layout/mod.rs index c9abb165..8156f596 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -1,13 +1,17 @@ //! Layouting of syntax trees into box layouts. -pub mod elements; -pub mod line; pub mod primitive; -pub mod stack; + +mod elements; +mod line; +mod stack; mod tree; +pub use elements::*; +pub use line::*; pub use primitive::*; -pub use tree::layout_tree as layout; +pub use stack::*; +pub use tree::*; use crate::geom::{Insets, Point, Rect, RectExt, Sides, Size, SizeExt}; @@ -15,8 +19,33 @@ use crate::eval::Scope; use crate::font::SharedFontLoader; use crate::style::{LayoutStyle, PageStyle, TextStyle}; use crate::syntax::SynTree; - -use elements::LayoutElements; +use crate::Pass; + +/// Layout a syntax tree and return the produced layout. +pub async fn layout( + tree: &SynTree, + style: &LayoutStyle, + scope: &Scope, + loader: SharedFontLoader, +) -> Pass { + let space = LayoutSpace { + size: style.page.size, + insets: style.page.insets(), + expansion: LayoutExpansion::new(true, true), + }; + tree::layout_tree(&tree, LayoutContext { + loader, + scope, + style, + base: space.usable(), + spaces: vec![space], + repeat: true, + sys: LayoutSystem::new(Dir::LTR, Dir::TTB), + align: LayoutAlign::new(GenAlign::Start, GenAlign::Start), + root: true, + }) + .await +} /// A collection of layouts. pub type MultiLayout = Vec; @@ -36,7 +65,7 @@ pub struct BoxLayout { #[derive(Debug, Clone)] pub struct LayoutContext<'a> { /// The font loader to query fonts from when typesetting text. - pub loader: &'a SharedFontLoader, + pub loader: SharedFontLoader, /// The function scope. pub scope: &'a Scope, /// The style for pages and text. -- cgit v1.2.3