mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibWeb: Add very basic handling of "font-family" font stacks
This commit is contained in:
parent
d20e26c690
commit
5142acd13e
Notes:
sideshowbarker
2024-07-19 06:43:43 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/5142acd13ea Pull-request: https://github.com/SerenityOS/serenity/pull/2189 Reviewed-by: https://github.com/awesomekling
1 changed files with 21 additions and 13 deletions
|
@ -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";
|
||||
|
||||
if (file_name.is_null()) {
|
||||
dbg() << "Failed to find a font for family " << font_family << " weight " << font_weight;
|
||||
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 (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
|
||||
|
|
Loading…
Add table
Reference in a new issue