summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-31 17:10:18 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-31 17:10:18 +0000
commit519cba1ec680a7eae764727aaaa7edca181b7d56 (patch)
tree516803561e5099a1d0addb628540edbcc75afe25 /chrome
parenta9419b41faab206d0edcba7a667963eb6947611d (diff)
downloadchromium_src-519cba1ec680a7eae764727aaaa7edca181b7d56.zip
chromium_src-519cba1ec680a7eae764727aaaa7edca181b7d56.tar.gz
chromium_src-519cba1ec680a7eae764727aaaa7edca181b7d56.tar.bz2
Read the default gtk font from GtkSettings instead of getting the font from a temporary widget.
Review URL: http://codereview.chromium.org/56083 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12866 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/common/gfx/chrome_font_gtk.cc24
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_);
}