diff options
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/elements.rs | 8 | ||||
| -rw-r--r-- | src/library/layout.rs | 54 | ||||
| -rw-r--r-- | src/library/mod.rs | 3 | ||||
| -rw-r--r-- | src/library/text.rs | 34 |
4 files changed, 51 insertions, 48 deletions
diff --git a/src/library/elements.rs b/src/library/elements.rs index 9680dfee..51f8dc98 100644 --- a/src/library/elements.rs +++ b/src/library/elements.rs @@ -61,12 +61,12 @@ fn rect_impl( fill: Option<Color>, body: Template, ) -> Value { - Value::Template(Template::from_inline(move |state| { + Value::Template(Template::from_inline(move |style| { let mut node = LayoutNode::new(FixedNode { width, height, aspect, - child: body.to_stack(state).into(), + child: body.to_stack(style).into(), }); if let Some(fill) = fill { @@ -114,7 +114,7 @@ fn ellipse_impl( fill: Option<Color>, body: Template, ) -> Value { - Value::Template(Template::from_inline(move |state| { + Value::Template(Template::from_inline(move |style| { // This padding ratio ensures that the rectangular padded region fits // perfectly into the ellipse. const PAD: f64 = 0.5 - SQRT_2 / 4.0; @@ -125,7 +125,7 @@ fn ellipse_impl( aspect, child: LayoutNode::new(PadNode { padding: Sides::splat(Relative::new(PAD).into()), - child: body.to_stack(state).into(), + child: body.to_stack(style).into(), }), }); diff --git a/src/library/layout.rs b/src/library/layout.rs index 089b80cf..c8b22f88 100644 --- a/src/library/layout.rs +++ b/src/library/layout.rs @@ -1,6 +1,6 @@ use super::*; use crate::layout::{FixedNode, GridNode, PadNode, StackChild, StackNode, TrackSizing}; -use crate::paper::{Paper, PaperClass}; +use crate::style::{Paper, PaperClass}; /// `page`: Configure pages. pub fn page(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> { @@ -21,8 +21,8 @@ pub fn page(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> { let bottom = args.named("bottom")?; let flip = args.named("flip")?; - ctx.template.modify(move |state| { - let page = state.page_mut(); + ctx.template.modify(move |style| { + let page = style.page_mut(); if let Some(paper) = paper { page.class = paper.class(); @@ -98,13 +98,13 @@ pub fn align(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> { } let realign = |template: &mut Template| { - template.modify(move |state| { + template.modify(move |style| { if let Some(horizontal) = horizontal { - state.aligns.inline = horizontal; + style.aligns.inline = horizontal; } if let Some(vertical) = vertical { - state.aligns.block = vertical; + style.aligns.block = vertical; } }); @@ -147,12 +147,12 @@ pub fn boxed(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { let width = args.named("width")?; let height = args.named("height")?; let body: Template = args.eat().unwrap_or_default(); - Ok(Value::Template(Template::from_inline(move |state| { + Ok(Value::Template(Template::from_inline(move |style| { FixedNode { width, height, aspect: None, - child: body.to_stack(state).into(), + child: body.to_stack(style).into(), } }))) } @@ -160,8 +160,8 @@ pub fn boxed(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { /// `block`: Place content in a block. pub fn block(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { let body: Template = args.expect("body")?; - Ok(Value::Template(Template::from_block(move |state| { - body.to_stack(state) + Ok(Value::Template(Template::from_block(move |style| { + body.to_stack(style) }))) } @@ -181,10 +181,10 @@ pub fn pad(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { bottom.or(all).unwrap_or_default(), ); - Ok(Value::Template(Template::from_block(move |state| { + Ok(Value::Template(Template::from_block(move |style| { PadNode { padding, - child: body.to_stack(&state).into(), + child: body.to_stack(&style).into(), } }))) } @@ -208,20 +208,20 @@ pub fn stack(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { let spacing = args.named("spacing")?; let list: Vec<Child> = args.all().collect(); - Ok(Value::Template(Template::from_block(move |state| { - let mut dirs = Gen::new(None, dir).unwrap_or(state.dirs); + Ok(Value::Template(Template::from_block(move |style| { + let mut dirs = Gen::new(style.dir, dir.unwrap_or(Dir::TTB)); // If the directions become aligned, fix up the inline direction since // that's the one that is not user-defined. - if dirs.block.axis() == dirs.inline.axis() { - dirs.inline = state.dirs.block; + if dirs.inline.axis() == dirs.block.axis() { + dirs.inline = Dir::TTB; } // Use the current alignments for all children, but take care to apply // them to the correct axes (by swapping them if the stack axes are - // different from the state axes). - let mut aligns = state.aligns; - if dirs.block.axis() == state.dirs.inline.axis() { + // different from the style axes). + let mut aligns = style.aligns; + if dirs.inline.axis() != style.dir.axis() { aligns = Gen::new(aligns.block, aligns.inline); } @@ -240,7 +240,7 @@ pub fn stack(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { children.push(StackChild::Spacing(v)); } - let node = template.to_stack(state).into(); + let node = template.to_stack(style).into(); children.push(StackChild::Any(node, aligns)); delayed = spacing; } @@ -293,10 +293,12 @@ pub fn grid(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { let children: Vec<Template> = args.all().collect(); - Ok(Value::Template(Template::from_block(move |state| { + Ok(Value::Template(Template::from_block(move |style| { // If the directions become aligned, try to fix up the direction which // is not user-defined. - let mut dirs = Gen::new(column_dir, row_dir).unwrap_or(state.dirs); + let mut dirs = + Gen::new(column_dir.unwrap_or(style.dir), row_dir.unwrap_or(Dir::TTB)); + if dirs.block.axis() == dirs.inline.axis() { let target = if column_dir.is_some() { &mut dirs.block @@ -304,15 +306,15 @@ pub fn grid(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { &mut dirs.inline }; - *target = if target.axis() == state.dirs.inline.axis() { - state.dirs.block + *target = if target.axis() == style.dir.axis() { + Dir::TTB } else { - state.dirs.inline + style.dir }; } let children = - children.iter().map(|child| child.to_stack(&state).into()).collect(); + children.iter().map(|child| child.to_stack(&style).into()).collect(); GridNode { dirs, diff --git a/src/library/mod.rs b/src/library/mod.rs index d99eb24d..7c8f4a93 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -17,10 +17,11 @@ use std::convert::TryFrom; use std::rc::Rc; use crate::diag::{At, TypResult}; -use crate::eval::{Args, Array, EvalContext, Scope, State, Str, Template, Value}; +use crate::eval::{Args, Array, EvalContext, Scope, Str, Template, Value}; use crate::font::{FontFamily, FontStretch, FontStyle, FontWeight, VerticalFontMetric}; use crate::geom::*; use crate::layout::LayoutNode; +use crate::style::Style; use crate::syntax::{Span, Spanned}; /// Construct a scope containing all standard library definitions. diff --git a/src/library/text.rs b/src/library/text.rs index b532b20b..fa334620 100644 --- a/src/library/text.rs +++ b/src/library/text.rs @@ -48,55 +48,55 @@ pub fn font(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> { let fallback = args.named("fallback")?; let body = args.eat::<Template>(); - let f = move |state: &mut State| { - let font = state.font_mut(); + let f = move |style_: &mut Style| { + let text = style_.text_mut(); if let Some(size) = size { - font.size = size.resolve(font.size); + text.size = size.resolve(text.size); } if let Some(style) = style { - font.variant.style = style; + text.variant.style = style; } if let Some(weight) = weight { - font.variant.weight = weight; + text.variant.weight = weight; } if let Some(stretch) = stretch { - font.variant.stretch = stretch; + text.variant.stretch = stretch; } if let Some(top_edge) = top_edge { - font.top_edge = top_edge; + text.top_edge = top_edge; } if let Some(bottom_edge) = bottom_edge { - font.bottom_edge = bottom_edge; + text.bottom_edge = bottom_edge; } if let Some(fill) = fill { - font.fill = Paint::Color(fill); + text.fill = Paint::Color(fill); } if let Some(FontDef(list)) = &list { - font.families_mut().list = list.clone(); + text.families_mut().list = list.clone(); } if let Some(FamilyDef(serif)) = &serif { - font.families_mut().serif = serif.clone(); + text.families_mut().serif = serif.clone(); } if let Some(FamilyDef(sans_serif)) = &sans_serif { - font.families_mut().sans_serif = sans_serif.clone(); + text.families_mut().sans_serif = sans_serif.clone(); } if let Some(FamilyDef(monospace)) = &monospace { - font.families_mut().monospace = monospace.clone(); + text.families_mut().monospace = monospace.clone(); } if let Some(fallback) = fallback { - font.fallback = fallback; + text.fallback = fallback; } }; @@ -113,8 +113,8 @@ pub fn par(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> { let par_spacing = args.named("spacing")?; let line_spacing = args.named("leading")?; - ctx.template.modify(move |state| { - let par = state.par_mut(); + ctx.template.modify(move |style| { + let par = style.par_mut(); if let Some(par_spacing) = par_spacing { par.par_spacing = par_spacing; @@ -144,7 +144,7 @@ pub fn lang(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> { }; if let Some(dir) = dir { - ctx.template.modify(move |state| state.dirs.inline = dir); + ctx.template.modify(move |style| style.dir = dir); } ctx.template.parbreak(); |
