From 7e2c217cbc3805c4cae613baf4149cc82e10d503 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 8 Jul 2021 21:42:36 +0200 Subject: Rename some library arguments - font - color -> fill - shorthands for families and size - decoration functions - color -> stroke - strength -> thickness - position -> offset - invert offsets: now positive goes downwards just like the rest of typst --- src/library/text.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src/library') diff --git a/src/library/text.rs b/src/library/text.rs index bf0d49a4..9c2863bc 100644 --- a/src/library/text.rs +++ b/src/library/text.rs @@ -6,14 +6,20 @@ use super::*; /// `font`: Configure the font. pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { - let list = args.named(ctx, "family"); - let size = args.named::(ctx, "size"); + let families = args.all(ctx); + let list = if families.is_empty() { + args.named(ctx, "family") + } else { + Some(FontDef(families)) + }; + + let size = args.eat(ctx).or_else(|| args.named::(ctx, "size")); let style = args.named(ctx, "style"); let weight = args.named(ctx, "weight"); let stretch = args.named(ctx, "stretch"); let top_edge = args.named(ctx, "top-edge"); let bottom_edge = args.named(ctx, "bottom-edge"); - let color = args.named(ctx, "color"); + let fill = args.named(ctx, "fill"); let serif = args.named(ctx, "serif"); let sans_serif = args.named(ctx, "sans-serif"); let monospace = args.named(ctx, "monospace"); @@ -50,8 +56,8 @@ pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { font.bottom_edge = bottom_edge; } - if let Some(color) = color { - font.fill = Fill::Color(color); + if let Some(fill) = fill { + font.fill = Fill::Color(fill); } if let Some(FamilyDef(serif)) = &serif { @@ -229,19 +235,19 @@ fn line_impl( args: &mut FuncArgs, substate: fn(&mut FontState) -> &mut Option>, ) -> Value { - let color = args.named(ctx, "color"); - let position = args.named(ctx, "position"); - let strength = args.named::(ctx, "strength"); + let stroke = args.eat(ctx).or_else(|| args.named(ctx, "stroke")); + let thickness = args.eat(ctx).or_else(|| args.named::(ctx, "thickness")); + let offset = args.named(ctx, "offset"); let extent = args.named(ctx, "extent").unwrap_or_default(); let body = args.expect::(ctx, "body").unwrap_or_default(); // Suppress any existing strikethrough if strength is explicitly zero. - let state = strength.map_or(true, |s| !s.is_zero()).then(|| { + let state = thickness.map_or(true, |s| !s.is_zero()).then(|| { Rc::new(LineState { - strength, - position, + stroke: stroke.map(Fill::Color), + thickness, + offset, extent, - fill: color.map(Fill::Color), }) }); -- cgit v1.2.3