diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-09-27 15:11:56 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-09-27 22:23:26 +0200 |
| commit | ed0c80401782a6c42173f0bb123731b798a2cfe1 (patch) | |
| tree | b2069f302a2d4474a23cd69a5f0ab50ab5311643 /src/library/text.rs | |
| parent | e10b3d838a75ea351f8477e07f2e1e647f4539dc (diff) | |
Add spacing capabilities to stack function
- Named argument `spacing` controls spacing between any two template arguments
- Arbitrary linears in the list can produce arbitrary spacing
Diffstat (limited to 'src/library/text.rs')
| -rw-r--r-- | src/library/text.rs | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/src/library/text.rs b/src/library/text.rs index b8b3afcd..0deda6e4 100644 --- a/src/library/text.rs +++ b/src/library/text.rs @@ -3,6 +3,33 @@ use crate::layout::{Decoration, LineDecoration, LineKind, Paint}; /// `font`: Configure the font. pub fn font(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> { + struct FontDef(Rc<Vec<FontFamily>>); + struct FamilyDef(Rc<Vec<String>>); + + castable! { + FontDef: "font family or array of font families", + Value::Str(string) => Self(Rc::new(vec![FontFamily::Named(string.to_lowercase())])), + Value::Array(values) => Self(Rc::new( + values + .into_iter() + .filter_map(|v| v.cast().ok()) + .collect() + )), + @family: FontFamily => Self(Rc::new(vec![family.clone()])), + } + + castable! { + FamilyDef: "string or array of strings", + Value::Str(string) => Self(Rc::new(vec![string.to_lowercase()])), + Value::Array(values) => Self(Rc::new( + values + .into_iter() + .filter_map(|v| v.cast().ok()) + .map(|string: Str| string.to_lowercase()) + .collect() + )), + } + let list = args.named("family")?.or_else(|| { let families: Vec<_> = args.all().collect(); (!families.is_empty()).then(|| FontDef(Rc::new(families))) @@ -81,34 +108,6 @@ pub fn font(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> { }) } -struct FontDef(Rc<Vec<FontFamily>>); - -castable! { - FontDef: "font family or array of font families", - Value::Str(string) => Self(Rc::new(vec![FontFamily::Named(string.to_lowercase())])), - Value::Array(values) => Self(Rc::new( - values - .into_iter() - .filter_map(|v| v.cast().ok()) - .collect() - )), - @family: FontFamily => Self(Rc::new(vec![family.clone()])), -} - -struct FamilyDef(Rc<Vec<String>>); - -castable! { - FamilyDef: "string or array of strings", - Value::Str(string) => Self(Rc::new(vec![string.to_lowercase()])), - Value::Array(values) => Self(Rc::new( - values - .into_iter() - .filter_map(|v| v.cast().ok()) - .map(|string: Str| string.to_lowercase()) - .collect() - )), -} - /// `par`: Configure paragraphs. pub fn par(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> { let par_spacing = args.named("spacing")?; |
