diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-08-01 00:01:17 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-08-01 00:10:54 +0200 |
| commit | 06dbac6efd98be5a015023c88ed3dbd9a35a4594 (patch) | |
| tree | bb3c75230098bf71d1ac23bbe7184e4ae7a6cef2 /src/library/font.rs | |
| parent | 064954cf9edbb0201b6184e69978f86e93741008 (diff) | |
Port font handling to fontdock and ttf-parser 🛳
- Use fontdock for indexing fonts and querying
- Typst binary now automatically indexes and uses system fonts in addition to a fixed font folder!
- Removes subsetting support for now (was half-finished anyways, plan is to use harfbuzz for subsetting in the future)
- Adds font width configuration support
Diffstat (limited to 'src/library/font.rs')
| -rw-r--r-- | src/library/font.rs | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/library/font.rs b/src/library/font.rs index 28b79115..5696cf4a 100644 --- a/src/library/font.rs +++ b/src/library/font.rs @@ -1,4 +1,4 @@ -use toddle::query::{FontWeight, FontStyle}; +use fontdock::{FontStyle, FontWeight, FontWidth}; use crate::length::ScaleLength; use super::*; @@ -40,7 +40,7 @@ function! { styled(&self.body, ctx, Some(()), |s, _| { if !self.list.is_empty() { - s.fallback.list = self.list.clone(); + *s.fallback.list_mut() = self.list.clone(); } for (class, fallback) in &self.classes { @@ -105,6 +105,39 @@ function! { } } + +function! { + /// `font.width`: Set text with a given width. + #[derive(Debug, Clone, PartialEq)] + pub struct FontWidthFunc { + body: Option<SyntaxModel>, + width: Option<FontWidth>, + } + + parse(header, body, ctx, f) { + let body = body!(opt: body, ctx, f); + let width = header.args.pos.get::<Spanned<(FontWidth, bool)>>(&mut f.diagnostics) + .map(|Spanned { v: (width, is_clamped), span }| { + if is_clamped { + warning!( + @f, span, + "width should be between 1 and 9, clamped to {}", + width.to_number(), + ); + } + + width + }) + .or_missing(&mut f.diagnostics, header.name.span, "width"); + + FontWidthFunc { body, width } + } + + layout(self, ctx, f) { + styled(&self.body, ctx, self.width, |t, w| t.variant.width = w) + } +} + function! { /// `font.size`: Sets the font size. #[derive(Debug, Clone, PartialEq)] |
