Skip to content

Commit

Permalink
vaev-style: Added support for generic font names.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Nov 26, 2024
1 parent 8308479 commit 70bcb98
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/vaev-layout/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ static Attrs _parseDomAttr(Markup::Element const &el) {

// MARK: Build Inline ----------------------------------------------------------

static Opt<Strong<Karm::Text::Fontface>> _monospaceFontface = NONE;
static Opt<Strong<Karm::Text::Fontface>> _regularFontface = NONE;
static Opt<Strong<Karm::Text::Fontface>> _boldFontface = NONE;

static Strong<Karm::Text::Fontface> _lookupFontface(Style::Computed &style) {
if (style.font->style != FontStyle::NORMAL) {
if (contains(style.font->families, "monospace"s)) {
if (not _monospaceFontface)
_monospaceFontface = Karm::Text::loadFontfaceOrFallback("bundle://fonts-fira-code/fonts/FiraCode-Regular.ttf"_url).unwrap();
return *_monospaceFontface;
} else if (style.font->style != FontStyle::NORMAL) {
if (style.font->weight != FontWeight::NORMAL) {
if (not _boldFontface)
_boldFontface = Karm::Text::loadFontfaceOrFallback("bundle://fonts-inter/fonts/Inter-BoldItalic.ttf"_url).unwrap();
Expand Down
18 changes: 17 additions & 1 deletion src/vaev-style/styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,23 @@ struct FontFamilyProp {
Res<> parse(Cursor<Css::Sst> &c) {
eatWhitespace(c);
while (not c.ended()) {
value.pushBack(try$(parseValue<String>(c)));
if (c.skip(Css::Token::ident("serif")))
value.pushBack("serif"s);
else if (c.skip(Css::Token::ident("sans-serif")))
value.pushBack("sans-serif"s);
else if (c.skip(Css::Token::ident("cursive")))
value.pushBack("cursive"s);
else if (c.skip(Css::Token::ident("fantasy")))
value.pushBack("fantasy"s);
else if (c.skip(Css::Token::ident("monospace")))
value.pushBack("monospace"s);
else if (c.skip(Css::Token::ident("system-ui")))
value.pushBack("system-ui"s);
else if (c.skip(Css::Token::ident("math")))
value.pushBack("math"s);
else
value.pushBack(try$(parseValue<String>(c)));

eatWhitespace(c);
}
return Ok();
Expand Down

0 comments on commit 70bcb98

Please sign in to comment.