diff options
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/layout.rs | 8 | ||||
| -rw-r--r-- | src/library/text.rs | 48 |
2 files changed, 29 insertions, 27 deletions
diff --git a/src/library/layout.rs b/src/library/layout.rs index cbc5ff94..ef909bc3 100644 --- a/src/library/layout.rs +++ b/src/library/layout.rs @@ -96,7 +96,7 @@ fn spacing_impl(ctx: &mut EvalContext, args: &mut FuncArgs, axis: GenAxis) -> Va Value::template(move |ctx| { if let Some(linear) = spacing { // TODO: Should this really always be font-size relative? - let amount = linear.resolve(ctx.state.font.size); + let amount = linear.resolve(ctx.state.text.size); ctx.push_spacing(axis, amount); } }) @@ -124,7 +124,7 @@ pub fn align(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { Value::template(move |ctx| { if let Some(horizontal) = horizontal { - ctx.state.aligns.cross = horizontal.to_align(ctx.state.lang.dir); + ctx.state.aligns.cross = horizontal.to_align(ctx.state.dir); } if let Some(vertical) = vertical { @@ -260,7 +260,7 @@ pub fn stack(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { .collect(); ctx.push_into_stack(StackNode { - dirs: Gen::new(ctx.state.lang.dir, dir), + dirs: Gen::new(ctx.state.dir, dir), aspect: None, children, }); @@ -290,7 +290,7 @@ pub fn grid(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { .map(|child| ctx.exec_template_stack(child).into()) .collect(); - let cross_dir = column_dir.unwrap_or(ctx.state.lang.dir); + let cross_dir = column_dir.unwrap_or(ctx.state.dir); let main_dir = row_dir.unwrap_or(cross_dir.axis().other().dir(true)); ctx.push_into_stack(GridNode { diff --git a/src/library/text.rs b/src/library/text.rs index 14a0ee9a..5e3ce204 100644 --- a/src/library/text.rs +++ b/src/library/text.rs @@ -1,6 +1,6 @@ use std::convert::TryFrom; -use crate::exec::{FontState, LineState}; +use crate::exec::{LineState, TextState}; use crate::font::{FontStretch, FontStyle, FontWeight}; use crate::layout::Paint; @@ -28,50 +28,50 @@ pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { let body = args.expect::<Template>(ctx, "body").unwrap_or_default(); Value::template(move |ctx| { - let font = ctx.state.font_mut(); + let state = ctx.state.text_mut(); if let Some(linear) = size { - font.size = linear.resolve(font.size); + state.size = linear.resolve(state.size); } if let Some(FontDef(list)) = &list { - font.families_mut().list = list.clone(); + state.families_mut().list = list.clone(); } if let Some(style) = style { - font.variant.style = style; + state.variant.style = style; } if let Some(weight) = weight { - font.variant.weight = weight; + state.variant.weight = weight; } if let Some(stretch) = stretch { - font.variant.stretch = stretch; + state.variant.stretch = stretch; } if let Some(top_edge) = top_edge { - font.top_edge = top_edge; + state.top_edge = top_edge; } if let Some(bottom_edge) = bottom_edge { - font.bottom_edge = bottom_edge; + state.bottom_edge = bottom_edge; } if let Some(fill) = fill { - font.fill = Paint::Color(fill); + state.fill = Paint::Color(fill); } if let Some(FamilyDef(serif)) = &serif { - font.families_mut().serif = serif.clone(); + state.families_mut().serif = serif.clone(); } if let Some(FamilyDef(sans_serif)) = &sans_serif { - font.families_mut().sans_serif = sans_serif.clone(); + state.families_mut().sans_serif = sans_serif.clone(); } if let Some(FamilyDef(monospace)) = &monospace { - font.families_mut().monospace = monospace.clone(); + state.families_mut().monospace = monospace.clone(); } body.exec(ctx); @@ -131,22 +131,24 @@ dynamic! { /// `par`: Configure paragraphs. pub fn par(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { - let spacing = args.named(ctx, "spacing"); - let leading = args.named(ctx, "leading"); + let par_spacing = args.named(ctx, "spacing"); + let line_spacing = args.named(ctx, "leading"); let word_spacing = args.named(ctx, "word-spacing"); let body = args.expect::<Template>(ctx, "body").unwrap_or_default(); Value::template(move |ctx| { - if let Some(spacing) = spacing { - ctx.state.par.spacing = spacing; + let state = ctx.state.text_mut(); + + if let Some(par_spacing) = par_spacing { + state.par_spacing = par_spacing; } - if let Some(leading) = leading { - ctx.state.par.leading = leading; + if let Some(line_spacing) = line_spacing { + state.line_spacing = line_spacing; } if let Some(word_spacing) = word_spacing { - ctx.state.par.word_spacing = word_spacing; + state.word_spacing = word_spacing; } ctx.parbreak(); @@ -169,7 +171,7 @@ pub fn lang(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { Value::template(move |ctx| { if let Some(dir) = dir.or(iso) { - ctx.state.lang.dir = dir; + ctx.state.dir = dir; } ctx.parbreak(); @@ -204,7 +206,7 @@ pub fn overline(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { fn line_impl( ctx: &mut EvalContext, args: &mut FuncArgs, - substate: fn(&mut FontState) -> &mut Option<Rc<LineState>>, + substate: fn(&mut TextState) -> &mut Option<Rc<LineState>>, ) -> Value { let stroke = args.eat().or_else(|| args.named(ctx, "stroke")); let thickness = args.eat().or_else(|| args.named::<Linear>(ctx, "thickness")); @@ -223,7 +225,7 @@ fn line_impl( }); Value::template(move |ctx| { - *substate(ctx.state.font_mut()) = state.clone(); + *substate(ctx.state.text_mut()) = state.clone(); body.exec(ctx); }) } |
