diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-03-21 15:36:26 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-03-21 15:36:26 +0000 |
commit | 38c37ddbaf3b29cdacbc25d4aa2acca1869d276f (patch) | |
tree | 008dd8f7c1330eb96fec98b3a1f841d31cd7d55a /src | |
parent | a262eea230a69cce309191bfdc8a19fe8737a152 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkTypeface.cpp | 25 | ||||
-rw-r--r-- | src/ports/SkFontHost_FreeType.cpp | 10 | ||||
-rw-r--r-- | src/ports/SkFontHost_FreeType_common.h | 2 |
3 files changed, 19 insertions, 18 deletions
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<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 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; }; |