From d44df16704fa63595d11c909f3897318294f7c3a Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 26 Apr 2023 08:17:40 -0400 Subject: [PATCH] Ladybird: Explicitly set the font family for CSS generic fonts We currently query Qt for system fonts using QFont::setStyleHint(). The docs from Qt have the following note regarding this API on X11: Qt does not support style hints on X11 since this information is not provided by the window system. This prevents any monospace font from working on X11 systems. For now, work around this by specifying the font-family for fonts which Qt has listed as mapping to a CSS generic font-family. --- Ladybird/FontPluginQt.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Ladybird/FontPluginQt.cpp b/Ladybird/FontPluginQt.cpp index c98440f773..11d21ba581 100644 --- a/Ladybird/FontPluginQt.cpp +++ b/Ladybird/FontPluginQt.cpp @@ -68,9 +68,19 @@ void FontPluginQt::update_generic_fonts() m_generic_font_names.resize(static_cast(Web::Platform::GenericFont::__Count)); - auto update_mapping = [&](Web::Platform::GenericFont generic_font, QFont::StyleHint qfont_style_hint, Vector fallbacks = {}) { + auto update_mapping = [&](Web::Platform::GenericFont generic_font, QFont::StyleHint qfont_style_hint, ReadonlySpan fallbacks) { QFont qt_font; qt_font.setStyleHint(qfont_style_hint); + + // NOTE: This is a workaround for setStyleHint being a no-op on X11 systems. See: + // https://doc.qt.io/qt-6/qfont.html#setStyleHint + if (generic_font == Web::Platform::GenericFont::Monospace) + qt_font.setFamily("monospace"); + else if (generic_font == Web::Platform::GenericFont::Fantasy) + qt_font.setFamily("fantasy"); + else if (generic_font == Web::Platform::GenericFont::Cursive) + qt_font.setFamily("cursive"); + QFontInfo qt_info(qt_font); auto qt_font_family = qt_info.family();