diff --git a/include/core/SkFontHost.h b/include/core/SkFontHost.h index b48c565352..30852f22f6 100644 --- a/include/core/SkFontHost.h +++ b/include/core/SkFontHost.h @@ -91,16 +91,6 @@ public: /** @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 54566c9242..9f72faa3de 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -132,21 +132,8 @@ SkStream* SkTypeface::openStream(int* ttcIndex) const { } 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 @@ int SkTypeface::getUnitsPerEm() const { #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 6a36f4407a..4aaf31ba0c 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -698,8 +698,7 @@ void SkTypeface_FreeType::onFilterRec(SkScalerContextRec* rec) const { #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 @@ uint32_t SkFontHost::GetUnitsPerEm(SkFontID fontID) { libInit = gFTLibrary; } SkAutoTCallIProc 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 a9b6be5f66..00b3bd6a7a 100644 --- a/src/ports/SkFontHost_FreeType_common.h +++ b/src/ports/SkFontHost_FreeType_common.h @@ -56,6 +56,8 @@ protected: virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( SkAdvancedTypefaceMetrics::PerGlyphInfo, const uint32_t*, uint32_t) const SK_OVERRIDE; + virtual int onGetUPEM() const SK_OVERRIDE; + private: typedef SkTypeface INHERITED; };