summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-28 21:40:30 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-28 21:40:30 +0000
commitdd888ede8c242474babf1f20844ba88a0b2bf16d (patch)
tree014f6a4f61a0235fdc511822e19ad12566183bfc /app
parent5429cb56f50b1d099db25daa7c4482fddfc676fc (diff)
downloadchromium_src-dd888ede8c242474babf1f20844ba88a0b2bf16d.zip
chromium_src-dd888ede8c242474babf1f20844ba88a0b2bf16d.tar.gz
chromium_src-dd888ede8c242474babf1f20844ba88a0b2bf16d.tar.bz2
linux: simplify gfx::Font constructor logic and add CHECK()s.
Trying to track down a bug that a user is seeing. The getter we were using to extract the value before was for a debugger-compatible string. Perhaps it was the quote-removal code that was getting us before; if not, these CHECKs will track it down. BUG=12530 Review URL: http://codereview.chromium.org/115877 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17118 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r--app/gfx/font_gtk.cc81
-rw-r--r--app/gfx/font_skia.cc4
2 files changed, 41 insertions, 44 deletions
diff --git a/app/gfx/font_gtk.cc b/app/gfx/font_gtk.cc
index 3b78d02..6c5f367 100644
--- a/app/gfx/font_gtk.cc
+++ b/app/gfx/font_gtk.cc
@@ -14,63 +14,59 @@ namespace gfx {
Font* Font::default_font_ = NULL;
// Find the best match font for |family_name| in the same way as Skia
-// to make sure CreateFont() successfully creates default font.
-// In Skia, it only checks the best match font. If it failed to find,
-// SkTypeface will be NULL for that font family. It eventually causes segfault.
-// For example, family_name = "Sans" and system may have various fonts.
-// The first font family in FcPattern will be "DejaVu Sans" but a font family
-// returned by FcFontMatch will be "VL PGothic".
-// In this case, SkTypeface for "Sans" returns NULL even if system has font
-// for "Sans" font family.
-// See FontMatch() in skia/ports/SkFontHost_fontconfig.cpp for more detail.
+// to make sure CreateFont() successfully creates a default font. In
+// Skia, it only checks the best match font. If it failed to find
+// one, SkTypeface will be NULL for that font family. It eventually
+// causes a segfault. For example, family_name = "Sans" and system
+// may have various fonts. The first font family in FcPattern will be
+// "DejaVu Sans" but a font family returned by FcFontMatch will be "VL
+// PGothic". In this case, SkTypeface for "Sans" returns NULL even if
+// the system has a font for "Sans" font family. See FontMatch() in
+// skia/ports/SkFontHost_fontconfig.cpp for more detail.
static std::wstring FindBestMatchFontFamilyName(const char* family_name) {
- FcPattern* pattern = FcPatternCreate();
- FcValue fcvalue;
- fcvalue.type = FcTypeString;
- char* family_name_copy = strdup(family_name);
- fcvalue.u.s = reinterpret_cast<FcChar8*>(family_name_copy);
- FcPatternAdd(pattern, FC_FAMILY, fcvalue, 0);
- FcConfigSubstitute(0, pattern, FcMatchPattern);
- FcDefaultSubstitute(pattern);
- FcResult result;
- FcPattern* match = FcFontMatch(0, pattern, &result);
- DCHECK(match) << "Could not find font: " << family_name;
- FcChar8* match_family;
- FcPatternGetString(match, FC_FAMILY, 0, &match_family);
-
- std::wstring font_family = UTF8ToWide(
- reinterpret_cast<char*>(match_family));
- FcPatternDestroy(match);
- FcPatternDestroy(pattern);
- free(family_name_copy);
- return font_family;
+ FcPattern* pattern = FcPatternCreate();
+ FcValue fcvalue;
+ fcvalue.type = FcTypeString;
+ char* family_name_copy = strdup(family_name);
+ fcvalue.u.s = reinterpret_cast<FcChar8*>(family_name_copy);
+ FcPatternAdd(pattern, FC_FAMILY, fcvalue, 0);
+ FcConfigSubstitute(0, pattern, FcMatchPattern);
+ FcDefaultSubstitute(pattern);
+ FcResult result;
+ FcPattern* match = FcFontMatch(0, pattern, &result);
+ DCHECK(match) << "Could not find font: " << family_name;
+ FcChar8* match_family;
+ FcPatternGetString(match, FC_FAMILY, 0, &match_family);
+
+ std::wstring font_family = UTF8ToWide(
+ reinterpret_cast<char*>(match_family));
+ FcPatternDestroy(match);
+ FcPatternDestroy(pattern);
+ free(family_name_copy);
+ return font_family;
}
// Get the default gtk system font (name and size).
Font::Font() {
if (default_font_ == NULL) {
- 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);
+ gchar* font_name = NULL;
+ g_object_get(G_OBJECT(settings),
+ "gtk-font-name", &font_name,
+ NULL);
- // 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';
+ // Temporary CHECK for helping track down
+ // http://code.google.com/p/chromium/issues/detail?id=12530
+ CHECK(font_name) << " Unable to get gtk-font-name for default font.";
PangoFontDescription* desc =
- pango_font_description_from_string(font_ptr);
+ pango_font_description_from_string(font_name);
gint size = pango_font_description_get_size(desc);
const char* family_name = pango_font_description_get_family(desc);
// Find best match font for |family_name| to make sure we can get
- // SkTypeface for default font.
+ // a SkTypeface for the default font.
// TODO(agl): remove this.
std::wstring font_family = FindBestMatchFontFamilyName(family_name);
@@ -78,7 +74,6 @@ Font::Font() {
pango_font_description_free(desc);
g_free(font_name);
- g_value_unset(&value);
DCHECK(default_font_);
}
diff --git a/app/gfx/font_skia.cc b/app/gfx/font_skia.cc
index 0443ace..4308bf6 100644
--- a/app/gfx/font_skia.cc
+++ b/app/gfx/font_skia.cc
@@ -85,7 +85,9 @@ Font Font::CreateFont(const std::wstring& font_family, int font_size) {
SkTypeface* tf = SkTypeface::CreateFromName(
base::SysWideToUTF8(font_family).c_str(), SkTypeface::kNormal);
- DCHECK(tf) << "Could not find font: " << base::SysWideToUTF8(font_family);
+ // Temporary CHECK for tracking down
+ // http://code.google.com/p/chromium/issues/detail?id=12530
+ CHECK(tf) << "Could not find font: " << base::SysWideToUTF8(font_family);
SkAutoUnref tf_helper(tf);
return Font(tf, font_family, font_size, NORMAL);