diff options
author | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-19 06:26:56 +0000 |
---|---|---|
committer | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-19 06:26:56 +0000 |
commit | 2291d04b0d127ca1b31c4326f9297253e4399d2b (patch) | |
tree | 0557b9ea97d2d36fabc0088ed4378468e17e3c31 /app/gfx/font_skia.cc | |
parent | 31814a80483a091ec3730c8a09b3b74d4f87fd1c (diff) | |
download | chromium_src-2291d04b0d127ca1b31c4326f9297253e4399d2b.zip chromium_src-2291d04b0d127ca1b31c4326f9297253e4399d2b.tar.gz chromium_src-2291d04b0d127ca1b31c4326f9297253e4399d2b.tar.bz2 |
Workaround for Issue 15949: cannot use the "WenQuanYi Bitmap Song" (chinese Fonts) as the system fonts with chrome
- Adding a font fallback code to Font::CreateFont() in font_skia.cc so that Chromium can startup even when a non-scalable font is selected as an application font. If the application font is non-scalable, Font::CreateFont() loads a _scalable_ "sans" font as a fallback.
(Note: The function still never load non-scalable fonts.)
- Removed a comment for issue 12530 since the issue has been fixed.
BUG=12530
BUG=15949
TEST=Download the snap.pcf font from http://artwizaleczapka.sourceforge.net/ and put it to ~/.fonts/. Remove temporarily /etc/fonts/conf.d/70-no-bitmaps.conf and run "fc-cache -f". Start /ust/bin/gnome-appearance-properties and select "snap" as your application font. Then start chromium and verify that it does not crash (by the CHECK failure) on startup.
Review URL: http://codereview.chromium.org/207009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26652 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/gfx/font_skia.cc')
-rw-r--r-- | app/gfx/font_skia.cc | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/app/gfx/font_skia.cc b/app/gfx/font_skia.cc index 1779635..56851e0 100644 --- a/app/gfx/font_skia.cc +++ b/app/gfx/font_skia.cc @@ -6,10 +6,20 @@ #include "app/gfx/canvas.h" #include "base/logging.h" +#include "base/string_piece.h" #include "base/sys_string_conversions.h" #include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/core/SkPaint.h" +namespace { + +// The font family name which is used when a user's application font for +// GNOME/KDE is a non-scalable one. The name should be listed in the +// IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp. +const char* kFallbackFontFamilyName = "sans"; + +} // namespace + namespace gfx { Font::Font(const Font& other) { @@ -89,15 +99,24 @@ int Font::ave_char_width() const { Font Font::CreateFont(const std::wstring& font_family, int font_size) { DCHECK_GT(font_size, 0); + std::wstring fallback; SkTypeface* tf = SkTypeface::CreateFromName( base::SysWideToUTF8(font_family).c_str(), SkTypeface::kNormal); - // 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); + if (!tf) { + // A non-scalable font such as .pcf is specified. Falls back to a default + // scalable font. + tf = SkTypeface::CreateFromName( + kFallbackFontFamilyName, SkTypeface::kNormal); + CHECK(tf) << "Could not find any font: " + << base::SysWideToUTF8(font_family) + << ", " << kFallbackFontFamilyName; + fallback = base::SysUTF8ToWide(kFallbackFontFamilyName); + } SkAutoUnref tf_helper(tf); - return Font(tf, font_family, font_size, NORMAL); + return Font( + tf, fallback.empty() ? font_family : fallback, font_size, NORMAL); } Font Font::DeriveFont(int size_delta, int style) const { |