summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-08-02 22:05:49 +0200
committerLaurenz <laurmaedje@gmail.com>2020-08-02 22:05:49 +0200
commit266d457292e7461d448f9141030028ea68b573d1 (patch)
treeff3ff3cc289d34040db421b6a7faa1f2aa402b05 /src/library
parentcbbc46215fe0a0ad8a50e991ec442890b8eadc0a (diff)
Refactor model into tree 🛒
Diffstat (limited to 'src/library')
-rw-r--r--src/library/font.rs4
-rw-r--r--src/library/layout.rs14
-rw-r--r--src/library/mod.rs26
-rw-r--r--src/library/page.rs10
-rw-r--r--src/library/spacing.rs2
5 files changed, 33 insertions, 23 deletions
diff --git a/src/library/font.rs b/src/library/font.rs
index a5ee7d9c..efcbb86f 100644
--- a/src/library/font.rs
+++ b/src/library/font.rs
@@ -1,3 +1,5 @@
+//! Font configuration.
+
use fontdock::{FontStyle, FontWeight, FontWidth};
use crate::length::ScaleLength;
use super::*;
@@ -6,7 +8,7 @@ function! {
/// `font`: Configure the font.
#[derive(Debug, Clone, PartialEq)]
pub struct FontFunc {
- body: Option<SyntaxModel>,
+ body: Option<SyntaxTree>,
size: Option<ScaleLength>,
style: Option<FontStyle>,
weight: Option<FontWeight>,
diff --git a/src/library/layout.rs b/src/library/layout.rs
index 5dd754bb..d46265a4 100644
--- a/src/library/layout.rs
+++ b/src/library/layout.rs
@@ -1,3 +1,5 @@
+//! Layout building blocks.
+
use crate::length::ScaleLength;
use super::*;
@@ -5,14 +7,14 @@ function! {
/// `box`: Layouts content into a box.
#[derive(Debug, Clone, PartialEq)]
pub struct BoxFunc {
- body: SyntaxModel,
+ body: SyntaxTree,
width: Option<ScaleLength>,
height: Option<ScaleLength>,
}
parse(header, body, ctx, f) {
BoxFunc {
- body: body!(opt: body, ctx, f).unwrap_or(SyntaxModel::new()),
+ body: body!(opt: body, ctx, f).unwrap_or(SyntaxTree::new()),
width: header.args.key.get::<ScaleLength>("width", f),
height: header.args.key.get::<ScaleLength>("height", f),
}
@@ -25,14 +27,14 @@ function! {
self.width.with(|v| {
let length = v.raw_scaled(ctx.base.x);
ctx.base.x = length;
- ctx.spaces[0].dimensions.x = length;
+ ctx.spaces[0].size.x = length;
ctx.spaces[0].expansion.horizontal = true;
});
self.height.with(|v| {
let length = v.raw_scaled(ctx.base.y);
ctx.base.y = length;
- ctx.spaces[0].dimensions.y = length;
+ ctx.spaces[0].size.y = length;
ctx.spaces[0].expansion.vertical = true;
});
@@ -48,7 +50,7 @@ function! {
/// `align`: Aligns content along the layouting axes.
#[derive(Debug, Clone, PartialEq)]
pub struct AlignFunc {
- body: Option<SyntaxModel>,
+ body: Option<SyntaxTree>,
aligns: Vec<Spanned<SpecAlign>>,
h: Option<Spanned<SpecAlign>>,
v: Option<Spanned<SpecAlign>>,
@@ -64,7 +66,7 @@ function! {
}
layout(self, ctx, f) {
- ctx.base = ctx.spaces[0].dimensions;
+ ctx.base = ctx.spaces[0].size;
let axes = ctx.axes;
let all = self.aligns.iter()
diff --git a/src/library/mod.rs b/src/library/mod.rs
index 7b7034a0..7a664257 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -1,12 +1,14 @@
//! The _Typst_ standard library.
-use crate::syntax::scope::Scope;
use crate::func::prelude::*;
+use crate::layout::{LayoutContext, Commands};
+use crate::syntax::scope::Scope;
-pub_use_mod!(font);
-pub_use_mod!(layout);
-pub_use_mod!(page);
-pub_use_mod!(spacing);
+macro_rules! lib { ($name:ident) => { mod $name; pub use $name::*; }}
+lib!(font);
+lib!(layout);
+lib!(page);
+lib!(spacing);
/// Create a scope with all standard functions.
pub fn std() -> Scope {
@@ -17,10 +19,10 @@ pub fn std() -> Scope {
std.add::<PageFunc>("page");
std.add::<AlignFunc>("align");
std.add::<BoxFunc>("box");
- std.add_with_meta::<SpacingFunc>("h", Horizontal);
- std.add_with_meta::<SpacingFunc>("v", Vertical);
std.add::<ParBreakFunc>("parbreak");
std.add::<PageBreakFunc>("pagebreak");
+ std.add_with_meta::<SpacingFunc>("h", Horizontal);
+ std.add_with_meta::<SpacingFunc>("v", Vertical);
std
}
@@ -29,7 +31,7 @@ function! {
/// `val`: Layouts the body with no special effect.
#[derive(Debug, Clone, PartialEq)]
pub struct ValFunc {
- body: Option<SyntaxModel>,
+ body: Option<SyntaxTree>,
}
parse(header, body, state, f) {
@@ -40,7 +42,7 @@ function! {
layout(self, ctx, f) {
match &self.body {
- Some(model) => vec![LayoutSyntaxModel(model)],
+ Some(tree) => vec![LayoutSyntaxTree(tree)],
None => vec![],
}
}
@@ -48,7 +50,7 @@ function! {
/// Layout an optional body with a change of the text style.
fn styled<'a, T, F>(
- body: &'a Option<SyntaxModel>,
+ body: &'a Option<SyntaxTree>,
ctx: LayoutContext<'_>,
data: Option<T>,
f: F,
@@ -58,9 +60,9 @@ fn styled<'a, T, F>(
f(&mut style, data);
match body {
- Some(model) => vec![
+ Some(tree) => vec![
SetTextStyle(style),
- LayoutSyntaxModel(model),
+ LayoutSyntaxTree(tree),
SetTextStyle(ctx.style.text.clone()),
],
None => vec![SetTextStyle(style)],
diff --git a/src/library/page.rs b/src/library/page.rs
index f1dcc9bc..d1964fd2 100644
--- a/src/library/page.rs
+++ b/src/library/page.rs
@@ -1,3 +1,5 @@
+//! Page setup.
+
use crate::length::{Length, ScaleLength};
use crate::paper::{Paper, PaperClass};
use super::*;
@@ -37,13 +39,13 @@ function! {
if let Some(paper) = self.paper {
style.class = paper.class;
- style.dimensions = paper.size();
+ style.size = paper.size();
} else if self.width.is_some() || self.height.is_some() {
style.class = PaperClass::Custom;
}
- self.width.with(|v| style.dimensions.x = v.as_raw());
- self.height.with(|v| style.dimensions.y = v.as_raw());
+ self.width.with(|v| style.size.x = v.as_raw());
+ self.height.with(|v| style.size.y = v.as_raw());
self.margins.with(|v| style.margins.set_all(Some(v)));
self.left.with(|v| style.margins.left = Some(v));
self.right.with(|v| style.margins.right = Some(v));
@@ -51,7 +53,7 @@ function! {
self.bottom.with(|v| style.margins.bottom = Some(v));
if self.flip {
- style.dimensions.swap();
+ style.size.swap();
}
vec![SetPageStyle(style)]
diff --git a/src/library/spacing.rs b/src/library/spacing.rs
index 68ef27f2..22c4669e 100644
--- a/src/library/spacing.rs
+++ b/src/library/spacing.rs
@@ -1,3 +1,5 @@
+//! Spacing.
+
use crate::length::ScaleLength;
use crate::layout::SpacingKind;
use super::*;