call onGetUPEM to subclasses can optimize it, and place default behavior
(calling getAdvancedTypefaceMetrics) in base impl.

This allows us to remove SkFontHost::GetUnitsPerEm entirely
Review URL: https://codereview.chromium.org/12915003

git-svn-id: http://skia.googlecode.com/svn/trunk@8295 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkFontHost.h b/include/core/SkFontHost.h
index b48c565..30852f2 100644
--- a/include/core/SkFontHost.h
+++ b/include/core/SkFontHost.h
@@ -91,16 +91,6 @@
     /** @deprecated get from Device. */
     static LCDOrder GetSubpixelOrder();
 
-#ifdef SK_BUILD_FOR_ANDROID
-    /**
-     * Return the number of font units per em.
-     *
-     * @param fontID the font to query.
-     * @return the number of font units per em or 0 on error.
-     */
-    static uint32_t GetUnitsPerEm(SkFontID fontID);
-#endif
-
     /** If Skia is running in a constrained environment and the typeface
      implementation is handle based, the typeface data may become
      unavailable asynchronously. If a font host or scaler context method is
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 54566c9..9f72faa 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -132,21 +132,8 @@
 }
 
 int SkTypeface::getUnitsPerEm() const {
-    int upem = 0;
-
-#ifdef SK_BUILD_FOR_ANDROID
-    upem = SkFontHost::GetUnitsPerEm(fUniqueID);
-#else
-    SkAdvancedTypefaceMetrics* metrics;
-    metrics = this->getAdvancedTypefaceMetrics(
-                                 SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo,
-                                 NULL, 0);
-    if (metrics) {
-        upem = metrics->fEmSize;
-        metrics->unref();
-    }
-#endif
-    return upem;
+    // should we try to cache this in the base-class?
+    return this->onGetUPEM();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -154,10 +141,24 @@
 
 #include "SkFontDescriptor.h"
 
-int SkTypeface::onGetUPEM() const { return 0; }
+int SkTypeface::onGetUPEM() const {
+    int upem = 0;
+
+    SkAdvancedTypefaceMetrics* metrics;
+    metrics = this->getAdvancedTypefaceMetrics(
+                             SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo,
+                             NULL, 0);
+    if (metrics) {
+        upem = metrics->fEmSize;
+        metrics->unref();
+    }
+    return upem;
+}
+
 int SkTypeface::onGetTableTags(SkFontTableTag tags[]) const { return 0; }
 size_t SkTypeface::onGetTableData(SkFontTableTag, size_t offset,
                                   size_t length, void* data) const { return 0; }
 void SkTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const {
     desc->setStyle(this->style());
 }
+
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 6a36f44..4aaf31b 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -698,8 +698,7 @@
 #endif
 }
 
-#ifdef SK_BUILD_FOR_ANDROID
-uint32_t SkFontHost::GetUnitsPerEm(SkFontID fontID) {
+int SkTypeface_FreeType::onGetUPEM() const {
     SkAutoMutexAcquire ac(gFTMutex);
     FT_Library libInit = NULL;
     if (gFTCount == 0) {
@@ -708,17 +707,16 @@
         libInit = gFTLibrary;
     }
     SkAutoTCallIProc<struct FT_LibraryRec_, FT_Done_FreeType> ftLib(libInit);
-    SkFaceRec *rec = ref_ft_face(fontID);
-    uint16_t unitsPerEm = 0;
+    SkFaceRec *rec = ref_ft_face(this->uniqueID());
+    int unitsPerEm = 0;
 
     if (rec != NULL && rec->fFace != NULL) {
         unitsPerEm = rec->fFace->units_per_EM;
         unref_ft_face(rec->fFace);
     }
 
-    return (uint32_t)unitsPerEm;
+    return unitsPerEm;
 }
-#endif
 
 SkScalerContext_FreeType::SkScalerContext_FreeType(SkTypeface* typeface,
                                                    const SkDescriptor* desc)
diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h
index a9b6be5..00b3bd6 100644
--- a/src/ports/SkFontHost_FreeType_common.h
+++ b/src/ports/SkFontHost_FreeType_common.h
@@ -56,6 +56,8 @@
     virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
                                 SkAdvancedTypefaceMetrics::PerGlyphInfo,
                                 const uint32_t*, uint32_t) const SK_OVERRIDE;
+    virtual int onGetUPEM() const SK_OVERRIDE;
+
 private:
     typedef SkTypeface INHERITED;
 };