diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/common/gfx/chrome_font_gtk.cc | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/chrome/common/gfx/chrome_font_gtk.cc b/chrome/common/gfx/chrome_font_gtk.cc index 22ed799..c3044e8 100644 --- a/chrome/common/gfx/chrome_font_gtk.cc +++ b/chrome/common/gfx/chrome_font_gtk.cc @@ -11,20 +11,32 @@ ChromeFont* ChromeFont::default_font_ = NULL; // Get the default gtk system font (name and size). -// TODO(estade): is there a way to do this that does not involve making a -// temporary widget? ChromeFont::ChromeFont() { if (default_font_ == NULL) { - GtkWidget* widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); - PangoFontDescription* desc = pango_context_get_font_description( - gtk_widget_get_pango_context(widget)); + gtk_init(NULL, NULL); + GtkSettings* settings = gtk_settings_get_default(); + + GValue value = {0}; + g_value_init(&value, G_TYPE_STRING); + g_object_get_property(G_OBJECT(settings), "gtk-font-name", &value); + + // gtk-font-name may be wrapped in quotes. + gchar* font_name = g_strdup_value_contents(&value); + gchar* font_ptr = font_name; + if (font_ptr[0] == '\"') + font_ptr++; + if (font_ptr[strlen(font_ptr) - 1] == '\"') + font_ptr[strlen(font_ptr) - 1] = '\0'; + + PangoFontDescription* desc = + pango_font_description_from_string(font_ptr); gint size = pango_font_description_get_size(desc); const char* name = pango_font_description_get_family(desc); default_font_ = new ChromeFont(CreateFont(UTF8ToWide(name), size / PANGO_SCALE)); - gtk_widget_destroy(widget); + g_free(font_name); DCHECK(default_font_); } |