diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-10-04 18:18:55 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-10-04 18:18:55 +0200 |
| commit | 6672f8f7dfcb38bbda3ec92bdf95341c05e9a782 (patch) | |
| tree | 90ec0d7a36554f9096e5f077ac7828fb6813fca0 /src/lib.rs | |
| parent | 262a8fa36a09527b4e257c175b12c8437279cf66 (diff) | |
Remove Typesetter in favor of typeset function 🎯
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 85 |
1 files changed, 14 insertions, 71 deletions
@@ -46,78 +46,21 @@ use std::pin::Pin; use crate::diagnostic::Diagnostic; use crate::eval::{Scope, Value}; use crate::font::SharedFontLoader; -use crate::layout::{ - layout, Commands, Dir, GenAlign, LayoutAlign, LayoutContext, LayoutExpansion, - LayoutSpace, LayoutSystem, MultiLayout, -}; -use crate::style::{LayoutStyle, PageStyle, TextStyle}; -use crate::syntax::{Decoration, Offset, Pos, SpanVec, SynTree}; - -/// Transforms source code into typesetted layouts. -/// -/// A typesetter can be configured through various methods. -pub struct Typesetter { - /// The font loader shared by all typesetting processes. +use crate::layout::{Commands, MultiLayout}; +use crate::style::LayoutStyle; +use crate::syntax::{Decoration, Offset, Pos, SpanVec}; + +/// Process source code directly into a collection of layouts. +pub async fn typeset( + src: &str, + style: &LayoutStyle, + scope: &Scope, loader: SharedFontLoader, - /// A scope that contains the standard library function definitions. - std: Scope, - /// The base layouting style. - style: LayoutStyle, -} - -impl Typesetter { - /// Create a new typesetter. - pub fn new(loader: SharedFontLoader) -> Self { - Self { - loader, - std: crate::library::_std(), - style: LayoutStyle::default(), - } - } - - /// Set the base text style. - pub fn set_text_style(&mut self, style: TextStyle) { - self.style.text = style; - } - - /// Set the base page style. - pub fn set_page_style(&mut self, style: PageStyle) { - self.style.page = style; - } - - /// Parse source code into a syntax tree. - pub fn parse(&self, src: &str) -> Pass<SynTree> { - parse::parse(src) - } - - /// Layout a syntax tree and return the produced layout. - pub async fn layout(&self, tree: &SynTree) -> Pass<MultiLayout> { - let space = LayoutSpace { - size: self.style.page.size, - insets: self.style.page.insets(), - expansion: LayoutExpansion::new(true, true), - }; - layout(&tree, LayoutContext { - loader: &self.loader, - scope: &self.std, - style: &self.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 - } - - /// Process source code directly into a collection of layouts. - pub async fn typeset(&self, src: &str) -> Pass<MultiLayout> { - let parsed = self.parse(src); - let layouted = self.layout(&parsed.output).await; - let feedback = Feedback::merge(parsed.feedback, layouted.feedback); - Pass::new(layouted.output, feedback) - } +) -> Pass<MultiLayout> { + let parsed = parse::parse(src); + let layouted = layout::layout(&parsed.output, style, scope, loader).await; + let feedback = Feedback::merge(parsed.feedback, layouted.feedback); + Pass::new(layouted.output, feedback) } /// A dynamic future type which allows recursive invocation of async functions |
