bug 1384701 get system font name and size from widget style context instead of GtkSettings r?manishearth
gtk_widget_get_settings() returns the same settings for all widgets [1] but
GTK actually uses specific fonts for each widget [2].
[1] https://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?h=3.22.19#n11637
[2] https://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?h=3.22.19#n10334
Changing to GtkStyleContext* will also make this easier to use from code where
the GtkStyleContext exists but not the GtkWidget, such as EnsureInit() in a
future patch.
MozReview-Commit-ID: 3NuTL5wRzm5
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -706,30 +706,27 @@ nsLookAndFeel::GetFloatImpl(FloatID aID,
return res;
}
static void
GetSystemFontInfo(GtkWidget *aWidget,
nsString *aFontName,
gfxFontStyle *aFontStyle)
{
- GtkSettings *settings = gtk_widget_get_settings(aWidget);
-
aFontStyle->style = NS_FONT_STYLE_NORMAL;
- gchar *fontname;
- g_object_get(settings, "gtk-font-name", &fontname, nullptr);
-
+ // As in
+ // https://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?h=3.22.19#n10333
+ GtkStyleContext *style = gtk_widget_get_style_context(aWidget);
PangoFontDescription *desc;
- desc = pango_font_description_from_string(fontname);
+ gtk_style_context_get(style, gtk_style_context_get_state(style),
+ "font", &desc, nullptr);
aFontStyle->systemFont = true;
- g_free(fontname);
-
NS_NAMED_LITERAL_STRING(quote, "\"");
NS_ConvertUTF8toUTF16 family(pango_font_description_get_family(desc));
*aFontName = quote + family + quote;
aFontStyle->weight = pango_font_description_get_weight(desc);
// FIXME: Set aFontStyle->stretch correctly!
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;