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
This commit is contained in:
parent
a262eea230
commit
38c37ddbaf
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user