From e7277fec232b5bc30f7ffe49a123550d1a096cb7 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 12 Dec 2019 11:41:04 +0100 Subject: [PATCH] =?UTF-8?q?Add=20font=20size=20function=20=F0=9F=8C=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/library/mod.rs | 32 ++++++++++++++++++++++++++++++++ src/style.rs | 4 ++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/library/mod.rs b/src/library/mod.rs index 4439f1376..342b2721d 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -29,6 +29,8 @@ pub fn std() -> Scope { std.add::("par.break"); std.add::("page.break"); + std.add::("font.size"); + std.add_with_metadata::>("spacing", None); for (name, key) in &[("h", AxisKey::Horizontal), ("v", AxisKey::Vertical)] { @@ -188,3 +190,33 @@ function! { } } } + +function! { + /// `font.size`: Set the font size. + #[derive(Debug, PartialEq)] + pub struct FontSize { + body: Option, + size: Size, + } + + parse(args, body, ctx) { + FontSize { + body: parse!(optional: body, ctx), + size: args.get_pos::()?.v, + } + } + + layout(self, mut ctx) { + let mut style = ctx.style.text.clone(); + style.font_size = self.size; + + match &self.body { + Some(body) => vec![ + SetTextStyle(style), + LayoutTree(body), + SetTextStyle(ctx.style.text.clone()), + ], + None => vec![SetTextStyle(style)] + } + } +} diff --git a/src/style.rs b/src/style.rs index 3323e5763..aa6f9d6c8 100644 --- a/src/style.rs +++ b/src/style.rs @@ -72,10 +72,10 @@ impl Default for TextStyle { TextStyle { classes: vec![Regular], fallback: vec![Serif], - font_size: Size::pt(10.0), + font_size: Size::pt(11.0), word_spacing: 0.25, line_spacing: 1.2, - paragraph_spacing: 1.4, + paragraph_spacing: 1.5, } } }