Add basic font family function ✏

This commit is contained in:
Laurenz 2020-01-01 19:37:55 +01:00
parent 7de9219321
commit 5dfaffc5bd

View File

@ -40,6 +40,7 @@ pub fn std() -> Scope {
std.add_with_metadata::<StyleChange>("italic", FontClass::Italic); std.add_with_metadata::<StyleChange>("italic", FontClass::Italic);
std.add_with_metadata::<StyleChange>("mono", FontClass::Monospace); std.add_with_metadata::<StyleChange>("mono", FontClass::Monospace);
std.add::<FontFamily>("font.family");
std.add::<FontSize>("font.size"); std.add::<FontSize>("font.size");
std std
@ -79,17 +80,18 @@ function! {
/// words, lines or paragraphs as a multiple of the font size. /// words, lines or paragraphs as a multiple of the font size.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct ContentSpacing { pub struct ContentSpacing {
spacing: f32, body: Option<SyntaxTree>,
content: ContentKind, content: ContentKind,
spacing: f32,
} }
type Meta = ContentKind; type Meta = ContentKind;
parse(args, body, _, meta) { parse(args, body, ctx, meta) {
parse!(forbidden: body);
ContentSpacing { ContentSpacing {
body: parse!(optional: body, ctx),
content: meta,
spacing: args.get_pos::<f64>()? as f32, spacing: args.get_pos::<f64>()? as f32,
content: meta
} }
} }
@ -100,7 +102,7 @@ function! {
ContentKind::Line => style.line_spacing_scale = self.spacing, ContentKind::Line => style.line_spacing_scale = self.spacing,
ContentKind::Paragraph => style.paragraph_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<SyntaxTree>,
family: String,
}
parse(args, body, ctx) {
FontFamily {
body: parse!(optional: body, ctx),
family: args.get_pos::<String>()?,
}
}
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! { function! {
/// `font.size`: Sets the font size. /// `font.size`: Sets the font size.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]