Skip to content

Commit

Permalink
web/core: Handle generic font families (poorly)
Browse files Browse the repository at this point in the history
Right now we just translate the family back into the
CSS identifier and attempt to lookup a system font in
the future. This is better than crashing but still bad!
  • Loading branch information
simonwuelker committed Dec 9, 2023
1 parent a44aaa2 commit d70a53a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/web/core/src/css/layout/flow/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl TextRun {
// FIXME: Consider more than just the first specified font
let family = match self.style().font_family().fonts()[0] {
FontName::Family(name) => font::Family::Specific(name.to_string()),
FontName::Generic(_name) => todo!(),
FontName::Generic(name) => font::Family::Generic(name.to_string()),
};

// let style = self.style()
Expand Down
21 changes: 21 additions & 0 deletions crates/web/core/src/css/values/font_family.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,24 @@ impl<'a> CSSParse<'a> for GenericFontFamily {
Ok(parsed_value)
}
}

impl ToString for GenericFontFamily {
fn to_string(&self) -> String {
let name = match self {
Self::Serif => "serif",
Self::SansSerif => "sans-serif",
Self::Cursive => "cursive",
Self::Fantasy => "fantasy",
Self::Monospace => "monospace",
Self::SystemUi => "system-ui",
Self::Emoji => "emoji",
Self::Math => "math",
Self::GenericFangSong => "generic(fangsong)",
Self::UiSerif => "ui-serif",
Self::UiSansSerif => "ui-sans-serif",
Self::UiMonospace => "ui-monospace",
Self::UiRounded => "ui-rounded",
};
name.to_string()
}
}

0 comments on commit d70a53a

Please sign in to comment.