From 38c37ddbaf3b29cdacbc25d4aa2acca1869d276f Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Thu, 21 Mar 2013 15:36:26 +0000 Subject: 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 --- include/core/SkFontHost.h | 10 ---------- src/core/SkTypeface.cpp | 25 +++++++++++++------------ src/ports/SkFontHost_FreeType.cpp | 10 ++++------ src/ports/SkFontHost_FreeType_common.h | 2 ++ 4 files changed, 19 insertions(+), 28 deletions(-) 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,32 +132,33 @@ SkStream* SkTypeface::openStream(int* ttcIndex) const { } int SkTypeface::getUnitsPerEm() const { + // should we try to cache this in the base-class? + return this->onGetUPEM(); +} + +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +#include "SkFontDescriptor.h" + +int SkTypeface::onGetUPEM() const { int upem = 0; -#ifdef SK_BUILD_FOR_ANDROID - upem = SkFontHost::GetUnitsPerEm(fUniqueID); -#else SkAdvancedTypefaceMetrics* metrics; metrics = this->getAdvancedTypefaceMetrics( - SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo, - NULL, 0); + SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo, + NULL, 0); if (metrics) { upem = metrics->fEmSize; metrics->unref(); } -#endif return upem; } -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - -#include "SkFontDescriptor.h" - -int SkTypeface::onGetUPEM() const { return 0; } 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; }; -- cgit v1.2.3