From 5dfaffc5bdfa811c135f0140c0a0ba917eb8c70f Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 1 Jan 2020 19:37:55 +0100 Subject: [PATCH] =?UTF-8?q?Add=20basic=20font=20family=20function=20?= =?UTF-8?q?=E2=9C=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/library/mod.rs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/library/mod.rs b/src/library/mod.rs index 9c7cc7ceb..7f7a0411a 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -40,6 +40,7 @@ pub fn std() -> Scope { std.add_with_metadata::("italic", FontClass::Italic); std.add_with_metadata::("mono", FontClass::Monospace); + std.add::("font.family"); std.add::("font.size"); std @@ -79,17 +80,18 @@ function! { /// words, lines or paragraphs as a multiple of the font size. #[derive(Debug, PartialEq)] pub struct ContentSpacing { - spacing: f32, + body: Option, content: ContentKind, + spacing: f32, } type Meta = ContentKind; - parse(args, body, _, meta) { - parse!(forbidden: body); + parse(args, body, ctx, meta) { ContentSpacing { + body: parse!(optional: body, ctx), + content: meta, spacing: args.get_pos::()? as f32, - content: meta } } @@ -100,7 +102,7 @@ function! { ContentKind::Line => style.line_spacing_scale = self.spacing, ContentKind::Paragraph => style.paragraph_spacing_scale = self.spacing, } - vec![SetTextStyle(style)] + styled(&self.body, &ctx, style) } } @@ -239,6 +241,28 @@ function! { } } +function! { + /// `font.family`: Set the font family. + #[derive(Debug, PartialEq)] + pub struct FontFamily { + body: Option, + family: String, + } + + parse(args, body, ctx) { + FontFamily { + body: parse!(optional: body, ctx), + family: args.get_pos::()?, + } + } + + layout(self, ctx) { + let mut style = ctx.style.text.clone(); + style.fallback.insert(0, FontClass::Family(self.family.clone())); + styled(&self.body, &ctx, style) + } +} + function! { /// `font.size`: Sets the font size. #[derive(Debug, PartialEq)]