diff options
author | Linus Groh <mail@linusgroh.de> | 2020-05-11 01:44:46 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-11 10:48:54 +0200 |
commit | 5142acd13eaaa88adb02a297cb2d005b9b87b1f4 (patch) | |
tree | 8a19b8c7b9833440d39f021decd2dcc149208f68 /Libraries | |
parent | d20e26c69029e9ee80362e7eb08d848541ecb02a (diff) | |
download | serenity-5142acd13eaaa88adb02a297cb2d005b9b87b1f4.zip |
LibWeb: Add very basic handling of "font-family" font stacks
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibWeb/CSS/StyleProperties.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/Libraries/LibWeb/CSS/StyleProperties.cpp b/Libraries/LibWeb/CSS/StyleProperties.cpp index 364c27b6c0..466f99b4fc 100644 --- a/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -132,26 +132,34 @@ void StyleProperties::load_font() const return {}; }; - String file_name = look_for_file(String::format("%s%s", font_family.characters(), weight.characters())); - if (file_name.is_null() && weight == "") - file_name = look_for_file(String::format("%sRegular", font_family.characters())); + // FIXME: Do this properly, with quote handling etc. + for (auto& font_name : font_family.split(',')) { + font_name = font_name.trim_spaces(); + if (font_name == "monospace") + font_name = "Csilla"; + + auto file_name = look_for_file(String::format("%s%s", font_name.characters(), weight.characters())); + if (file_name.is_null() && weight == "") + file_name = look_for_file(String::format("%sRegular", font_name.characters())); + if (file_name.is_null()) + continue; - if (file_name.is_null()) { - dbg() << "Failed to find a font for family " << font_family << " weight " << font_weight; - - if (font_weight == "bold") - m_font = Gfx::Font::default_bold_font(); - else - m_font = Gfx::Font::default_font(); +#ifdef HTML_DEBUG + dbg() << "Found font " << file_name << " for family " << font_family << " weight " << font_weight; +#endif + m_font = Gfx::Font::load_from_file(String::format("/res/fonts/%s", file_name.characters())); + FontCache::the().set({ font_name, font_weight }, *m_font); return; } #ifdef HTML_DEBUG - dbg() << "Found font " << file_name << " for family " << font_family << " weight " << font_weight; + dbg() << "Failed to find a font for family " << font_family << " weight " << font_weight; #endif - - m_font = Gfx::Font::load_from_file(String::format("/res/fonts/%s", file_name.characters())); - FontCache::the().set({ font_family, font_weight }, *m_font); + if (font_weight == "bold") + m_font = Gfx::Font::default_bold_font(); + else + m_font = Gfx::Font::default_font(); + return; } float StyleProperties::line_height() const |