summaryrefslogtreecommitdiffstats
path: root/skia/ext
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-23 23:27:50 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-23 23:27:50 +0000
commite35c67993153e338121eedd6413e40d39b7cb8f9 (patch)
treee9988121491c354e26677ff9963cb94038975f23 /skia/ext
parent15f49af69e1349dd4cc0ed57d422ef2398d5828e (diff)
downloadchromium_src-e35c67993153e338121eedd6413e40d39b7cb8f9.zip
chromium_src-e35c67993153e338121eedd6413e40d39b7cb8f9.tar.gz
chromium_src-e35c67993153e338121eedd6413e40d39b7cb8f9.tar.bz2
linux: be more conservative in Liberation font fallback
Rather than encoding all of the supposedly metric-compatible fonts from fontconfig, let's only whitelist fonts we know really improve the web for users. The Helvetica and Courier New substitutes don't look too great. BUB=39099 Review URL: http://codereview.chromium.org/1235001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42399 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext')
-rw-r--r--skia/ext/SkFontHost_fontconfig_direct.cpp103
-rw-r--r--skia/ext/SkFontHost_fontconfig_direct.h4
2 files changed, 41 insertions, 66 deletions
diff --git a/skia/ext/SkFontHost_fontconfig_direct.cpp b/skia/ext/SkFontHost_fontconfig_direct.cpp
index ed92387..f2cdff8 100644
--- a/skia/ext/SkFontHost_fontconfig_direct.cpp
+++ b/skia/ext/SkFontHost_fontconfig_direct.cpp
@@ -22,13 +22,21 @@
#include <fontconfig/fontconfig.h>
-FontConfigDirect::FontConfigDirect()
- : next_file_id_(0) {
- FcInit();
-}
+namespace {
-bool FontConfigDirect::IsMetricCompatibleReplacement(const char* font_a,
- const char* font_b)
+// Equivalence classes, used to match the Liberation fonts with their
+// metric-compatible replacements. See the discussion in
+// GetFontEquivClass().
+enum FontEquivClass
+{
+ OTHER,
+ SANS,
+ SERIF
+};
+
+// Match the font name against a whilelist of fonts, returning the equivalence
+// class.
+FontEquivClass GetFontEquivClass(const char* fontname)
{
// It would be nice for fontconfig to tell us whether a given suggested
// replacement is a "strong" match (that is, an equivalent font) or
@@ -36,65 +44,36 @@ bool FontConfigDirect::IsMetricCompatibleReplacement(const char* font_a,
// substitute). However, I played around with the fontconfig API for
// a good few hours and could not make it reveal this information.
//
- // So instead, we hardcode. These are from
- // /etc/fonts/conf.d/30-metric-aliases.conf on my Ubuntu Karmic
- // system.
-
- // We represent the data with a table. Two names with the same
- // id are in the same class.
- struct FontEquivClass {
- char id;
- const char name[20];
- };
- static const FontEquivClass kFontEquivClasses[] = {
- { 0, "Arial" },
- { 0, "Liberation Sans" },
- { 0, "Albany" },
- { 0, "Albany Amt" },
-
- { 1, "Times New Roman" },
- { 1, "Liberation Serif" },
- { 1, "Thorndale" },
- { 1, "Thorndale AMT" },
-
- // Note that Liberation Mono doesn't much *look* like Courier New,
- // but it's reportedly metric-compatible.
- { 2, "Courier New" },
- { 2, "Liberation Mono" },
- { 2, "Cumberland" },
- { 2, "Cumberland AMT" },
-
- { 3, "Helvetica" },
- { 3, "Nimbus Sans L" },
-
- { 4, "Times" },
- { 4, "Nimbus Roman No9 L" },
-
- { 5, "Courier" },
- { 5, "Nimbus Mono L" },
- };
- static const size_t kClassCount =
- sizeof(kFontEquivClasses)/sizeof(kFontEquivClasses[0]);
-
- int class_a = -1;
- for (size_t i = 0; i < kClassCount; ++i) {
- if (strcasecmp(kFontEquivClasses[i].name, font_a) == 0) {
- class_a = kFontEquivClasses[i].id;
- break;
- }
+ // So instead, we hardcode. Initially this function emulated
+ // /etc/fonts/conf.d/30-metric-aliases.conf
+ // from my Ubuntu system, but we're better off being very conservative.
+
+ if (strcasecmp(fontname, "Arial") == 0 ||
+ strcasecmp(fontname, "Liberation Sans") == 0) {
+ return SANS;
+ } else if (strcasecmp(fontname, "Times New Roman") == 0 ||
+ strcasecmp(fontname, "Liberation Serif") == 0) {
+ return SERIF;
}
- if (class_a == -1)
- return false;
+ return OTHER;
+}
- int class_b = -1;
- for (size_t i = 0; i < kClassCount; ++i) {
- if (strcasecmp(kFontEquivClasses[i].name, font_b) == 0) {
- class_b = kFontEquivClasses[i].id;
- break;
- }
- }
- return class_a == class_b;
+// Return true if |font_a| and |font_b| are visually and at the metrics
+// level interchangeable.
+bool IsMetricCompatibleReplacement(const char* font_a, const char* font_b)
+{
+ FontEquivClass class_a = GetFontEquivClass(font_a);
+ FontEquivClass class_b = GetFontEquivClass(font_b);
+
+ return class_a != OTHER && class_a == class_b;
+}
+
+} // anonymous namespace
+
+FontConfigDirect::FontConfigDirect()
+ : next_file_id_(0) {
+ FcInit();
}
// -----------------------------------------------------------------------------
diff --git a/skia/ext/SkFontHost_fontconfig_direct.h b/skia/ext/SkFontHost_fontconfig_direct.h
index 3f9475d..56bea34 100644
--- a/skia/ext/SkFontHost_fontconfig_direct.h
+++ b/skia/ext/SkFontHost_fontconfig_direct.h
@@ -35,10 +35,6 @@ class FontConfigDirect : public FontConfigInterface {
virtual int Open(unsigned fileid);
private:
- // Return true if font_a and font_b are completely interchangeable;
- // e.g., there exist free clones of certain well-known fonts.
- bool IsMetricCompatibleReplacement(const char* font_a, const char* font_b);
-
SkMutex mutex_;
std::map<unsigned, std::string> fileid_to_filename_;
std::map<std::string, unsigned> filename_to_fileid_;