Skip to content

Commit abcc5bc

Browse files
socram8888AtkinsSJ
authored andcommitted
LibWeb: Support multiple emoji/symbol fonts
1 parent 01ad180 commit abcc5bc

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

Libraries/LibWeb/CSS/StyleComputer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,8 +1927,11 @@ RefPtr<Gfx::FontCascadeList const> StyleComputer::compute_font_for_style_values(
19271927
font_list->add(*default_font);
19281928
}
19291929

1930-
if (auto emoji_font = Platform::FontPlugin::the().default_emoji_font(font_size_in_pt); emoji_font) {
1931-
font_list->add(*emoji_font);
1930+
// Add emoji and symbol fonts
1931+
for (auto font_name : Platform::FontPlugin::the().symbol_font_names()) {
1932+
if (auto other_font_list = find_font(font_name)) {
1933+
font_list->extend(*other_font_list);
1934+
}
19321935
}
19331936

19341937
// The default font is already included in the font list, but we explicitly set it

Libraries/LibWeb/Platform/FontPlugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class WEB_API FontPlugin {
3434

3535
virtual RefPtr<Gfx::Font> default_font(float point_size) = 0;
3636
virtual Gfx::Font& default_fixed_width_font() = 0;
37-
virtual RefPtr<Gfx::Font> default_emoji_font(float point_size) = 0;
3837

3938
virtual FlyString generic_font_name(GenericFont) = 0;
39+
virtual Vector<FlyString> symbol_font_names() = 0;
4040
};
4141

4242
}

Libraries/LibWebView/Plugins/FontPlugin.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ FontPlugin::FontPlugin(bool is_layout_test_mode, Gfx::SystemFontProvider* font_p
4040
auto default_fixed_width_font_name = generic_font_name(Web::Platform::GenericFont::UiMonospace);
4141
m_default_fixed_width_font = Gfx::FontDatabase::the().get(default_fixed_width_font_name, 12.0, 400, Gfx::FontWidth::Normal, 0);
4242
VERIFY(m_default_fixed_width_font);
43+
44+
if (is_layout_test_mode) {
45+
m_symbol_font_names = { "Noto Emoji"_fly_string };
46+
} else {
47+
#ifdef AK_OS_MACOS
48+
m_symbol_font_names = { "Apple Color Emoji"_fly_string, "Apple Symbols"_fly_string };
49+
#else
50+
m_symbol_font_names = { "Noto Color Emoji"_fly_string, "Noto Sans Symbols"_fly_string };
51+
#endif
52+
}
4353
}
4454

4555
FontPlugin::~FontPlugin() = default;
@@ -54,21 +64,9 @@ Gfx::Font& FontPlugin::default_fixed_width_font()
5464
return *m_default_fixed_width_font;
5565
}
5666

57-
RefPtr<Gfx::Font> FontPlugin::default_emoji_font(float point_size)
67+
Vector<FlyString> FontPlugin::symbol_font_names()
5868
{
59-
FlyString default_emoji_font_name;
60-
61-
if (m_is_layout_test_mode) {
62-
default_emoji_font_name = "Noto Emoji"_fly_string;
63-
} else {
64-
#ifdef AK_OS_MACOS
65-
default_emoji_font_name = "Apple Color Emoji"_fly_string;
66-
#else
67-
default_emoji_font_name = "Noto Color Emoji"_fly_string;
68-
#endif
69-
}
70-
71-
return Gfx::FontDatabase::the().get(default_emoji_font_name, point_size, 400, Gfx::FontWidth::Normal, 0);
69+
return m_symbol_font_names;
7270
}
7371

7472
#ifdef USE_FONTCONFIG

Libraries/LibWebView/Plugins/FontPlugin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ class WEBVIEW_API FontPlugin final : public Web::Platform::FontPlugin {
2121

2222
virtual RefPtr<Gfx::Font> default_font(float point_size) override;
2323
virtual Gfx::Font& default_fixed_width_font() override;
24-
virtual RefPtr<Gfx::Font> default_emoji_font(float point_size) override;
2524
virtual FlyString generic_font_name(Web::Platform::GenericFont) override;
25+
virtual Vector<FlyString> symbol_font_names() override;
2626

2727
void update_generic_fonts();
2828

2929
private:
3030
Vector<FlyString> m_generic_font_names;
31+
Vector<FlyString> m_symbol_font_names;
3132
FlyString m_default_font_name;
3233
RefPtr<Gfx::Font> m_default_fixed_width_font;
3334
bool m_is_layout_test_mode { false };

0 commit comments

Comments
 (0)