map canonical css names to real fonts
authormike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 22 Mar 2011 01:32:34 +0000 (01:32 +0000)
committermike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 22 Mar 2011 01:32:34 +0000 (01:32 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@975 2bbb7eff-a529-9590-31e7-b0007b416f81

src/ports/SkFontHost_mac_coretext.cpp

index ae393619856dd1531ee8e3a0379b8ddf83e3bdc6..1a6bf435d3d494226e0ea79c85603230603c9ca7 100644 (file)
@@ -616,8 +616,23 @@ void SkScalerContext_Mac::CTPathElement(void *info, const CGPathElement *element
 }
 
 
-
-
+static const char* map_css_names(const char* name) {
+    static const struct {
+        const char* fFrom;
+        const char* fTo;
+    } gPairs[] = {
+        { "sans-serif", FONT_DEFAULT_NAME },
+        { "serif",      "Times"           },
+        { "monospace",  "Courier"         }
+    };
+
+    for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {
+        if (strcmp(name, gPairs[i].fFrom) == 0) {
+            return gPairs[i].fTo;
+        }
+    }
+    return name;    // no change
+}
 
 ///////////////////////////////////////////////////////////////////////////
 #pragma mark -
@@ -631,6 +646,9 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
     SkNativeFontInfo        fontInfo;
     SkString                fontName;
 
+    if (familyName) {
+        familyName = map_css_names(familyName);
+    }
 
     // Get the state we need
     fontName  = SkString(familyName);
@@ -645,7 +663,6 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
         return(const_cast<SkTypeface*>(familyFace));
         }
 
-
     if (fontName.isEmpty()) {
         fontName.set(FONT_DEFAULT_NAME);
     }