1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:57:35 +00:00

LibWeb: Add very basic handling of "font-family" font stacks

This commit is contained in:
Linus Groh 2020-05-11 01:44:46 +01:00 committed by Andreas Kling
parent d20e26c690
commit 5142acd13e

View file

@ -132,26 +132,34 @@ void StyleProperties::load_font() const
return {}; return {};
}; };
String file_name = look_for_file(String::format("%s%s", font_family.characters(), weight.characters())); // FIXME: Do this properly, with quote handling etc.
if (file_name.is_null() && weight == "") for (auto& font_name : font_family.split(',')) {
file_name = look_for_file(String::format("%sRegular", font_family.characters())); font_name = font_name.trim_spaces();
if (font_name == "monospace")
font_name = "Csilla";
if (file_name.is_null()) { auto file_name = look_for_file(String::format("%s%s", font_name.characters(), weight.characters()));
dbg() << "Failed to find a font for family " << font_family << " weight " << font_weight; if (file_name.is_null() && weight == "")
file_name = look_for_file(String::format("%sRegular", font_name.characters()));
if (file_name.is_null())
continue;
if (font_weight == "bold") #ifdef HTML_DEBUG
m_font = Gfx::Font::default_bold_font(); dbg() << "Found font " << file_name << " for family " << font_family << " weight " << font_weight;
else #endif
m_font = Gfx::Font::default_font(); 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; return;
} }
#ifdef HTML_DEBUG #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 #endif
if (font_weight == "bold")
m_font = Gfx::Font::load_from_file(String::format("/res/fonts/%s", file_name.characters())); m_font = Gfx::Font::default_bold_font();
FontCache::the().set({ font_family, font_weight }, *m_font); else
m_font = Gfx::Font::default_font();
return;
} }
float StyleProperties::line_height() const float StyleProperties::line_height() const