Add font size function 🌱
This commit is contained in:
parent
a791ef1628
commit
e7277fec23
@ -29,6 +29,8 @@ pub fn std() -> Scope {
|
||||
std.add::<ParBreak>("par.break");
|
||||
std.add::<PageBreak>("page.break");
|
||||
|
||||
std.add::<FontSize>("font.size");
|
||||
|
||||
std.add_with_metadata::<Spacing, Option<AxisKey>>("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<SyntaxTree>,
|
||||
size: Size,
|
||||
}
|
||||
|
||||
parse(args, body, ctx) {
|
||||
FontSize {
|
||||
body: parse!(optional: body, ctx),
|
||||
size: args.get_pos::<Size>()?.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)]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user