move impl of AdvancedTypefaceMetrics into typeface (3)
Review URL: https://codereview.chromium.org/12807004
git-svn-id: http://skia.googlecode.com/svn/trunk@8274 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index a009fc9..b08aa8e 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -447,12 +447,10 @@
}
}
-// static
-SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
- uint32_t fontID,
+SkAdvancedTypefaceMetrics* SkTypeface_FreeType::onGetAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
const uint32_t* glyphIDs,
- uint32_t glyphIDsCount) {
+ uint32_t glyphIDsCount) const {
#if defined(SK_BUILD_FOR_MAC)
return NULL;
#else
@@ -464,7 +462,7 @@
libInit = gFTLibrary;
}
SkAutoTCallIProc<struct FT_LibraryRec_, FT_Done_FreeType> ftLib(libInit);
- SkFaceRec* rec = ref_ft_face(fontID);
+ SkFaceRec* rec = ref_ft_face(this->uniqueID());
if (NULL == rec)
return NULL;
FT_Face face = rec->fFace;
diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h
index fb8271c..a9b6be5 100644
--- a/src/ports/SkFontHost_FreeType_common.h
+++ b/src/ports/SkFontHost_FreeType_common.h
@@ -53,7 +53,9 @@
virtual SkScalerContext* onCreateScalerContext(
const SkDescriptor*) const SK_OVERRIDE;
virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
-
+ virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ SkAdvancedTypefaceMetrics::PerGlyphInfo,
+ const uint32_t*, uint32_t) const SK_OVERRIDE;
private:
typedef SkTypeface INHERITED;
};
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 674f1fd..ea2d30c 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -418,7 +418,10 @@
virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE;
virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
virtual void onGetFontDescriptor(SkFontDescriptor*) const SK_OVERRIDE;
-
+ virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ SkAdvancedTypefaceMetrics::PerGlyphInfo,
+ const uint32_t*, uint32_t) const SK_OVERRIDE;
+
private:
typedef SkTypeface INHERITED;
};
@@ -657,7 +660,7 @@
, fFBoundingBoxesGlyphOffset(0)
, fGeneratedFBoundingBoxes(false)
{
- CTFontRef ctFont = GetFontRefFromFontID(fRec.fFontID);
+ CTFontRef ctFont = typeface->fFontRef.get();
CFIndex numGlyphs = CTFontGetGlyphCount(ctFont);
// Get the state we need
@@ -1472,13 +1475,12 @@
dst->resize(strlen(dst->c_str()));
}
-// static
-SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
- uint32_t fontID,
+SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
const uint32_t* glyphIDs,
- uint32_t glyphIDsCount) {
- CTFontRef originalCTFont = GetFontRefFromFontID(fontID);
+ uint32_t glyphIDsCount) const {
+
+ CTFontRef originalCTFont = fFontRef.get();
AutoCFRelease<CTFontRef> ctFont(CTFontCreateCopyWithAttributes(
originalCTFont, CTFontGetUnitsPerEm(originalCTFont), NULL, NULL));
SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics;
@@ -1503,7 +1505,7 @@
// fonts always have both glyf and loca tables. At the least, this is what
// sfntly needs to subset the font. CTFontCopyAttribute() does not always
// succeed in determining this directly.
- if (!GetTableSize(fontID, 'glyf') || !GetTableSize(fontID, 'loca')) {
+ if (!this->getTableSize('glyf') || !this->getTableSize('loca')) {
info->fType = SkAdvancedTypefaceMetrics::kOther_Font;
info->fItalicAngle = 0;
info->fAscent = 0;
diff --git a/src/ports/SkFontHost_none.cpp b/src/ports/SkFontHost_none.cpp
index a0aedba..f41951a 100644
--- a/src/ports/SkFontHost_none.cpp
+++ b/src/ports/SkFontHost_none.cpp
@@ -27,16 +27,6 @@
return NULL;
}
-// static
-SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
- uint32_t fontID,
- SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
- const uint32_t* glyphIDs,
- uint32_t glyphIDsCount) {
- SkDEBUGFAIL("SkFontHost::GetAdvancedTypefaceMetrics unimplemented");
- return NULL;
-}
-
///////////////////////////////////////////////////////////////////////////////
SkStream* SkFontHost::OpenStream(uint32_t uniqueID) {
diff --git a/src/ports/SkFontHost_simple.cpp b/src/ports/SkFontHost_simple.cpp
index 7d9cf6d..0a9695c 100644
--- a/src/ports/SkFontHost_simple.cpp
+++ b/src/ports/SkFontHost_simple.cpp
@@ -260,6 +260,14 @@
virtual const char* getUniqueString() const = 0;
virtual const char* getFilePath() const = 0;
+protected:
+ virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ SkAdvancedTypefaceMetrics::PerGlyphInfo,
+ const uint32_t*,
+ uint32_t) const SK_OVERRIDE {
+ return NULL;
+ }
+
private:
bool fIsSysFont;
@@ -552,17 +560,6 @@
return stream;
}
-#if 0
-SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
- uint32_t fontID,
- SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
- const uint32_t* glyphIDs,
- uint32_t glyphIDsCount) {
- SkDEBUGFAIL("SkFontHost::GetAdvancedTypefaceMetrics unimplemented");
- return NULL;
-}
-#endif
-
size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
int32_t* index) {
SkAutoMutexAcquire ac(gFamilyMutex);
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index b430a04..d58ba6a 100755
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -200,6 +200,9 @@
protected:
virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE;
virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
+ virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ SkAdvancedTypefaceMetrics::PerGlyphInfo,
+ const uint32_t*, uint32_t) const SK_OVERRIDE;
};
class FontMemResourceTypeface : public LogFontTypeface {
@@ -1347,14 +1350,11 @@
return true;
}
-// static
-SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
- uint32_t fontID,
+SkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
const uint32_t* glyphIDs,
- uint32_t glyphIDsCount) {
- LOGFONT lf;
- GetLogFontByID(fontID, &lf);
+ uint32_t glyphIDsCount) const {
+ LOGFONT lf = fLogFont;
SkAdvancedTypefaceMetrics* info = NULL;
HDC hdc = CreateCompatibleDC(NULL);
@@ -1371,7 +1371,7 @@
OUTLINETEXTMETRIC otm;
unsigned int otmRet = GetOutlineTextMetrics(hdc, sizeof(otm), &otm);
if (0 == otmRet) {
- ensure_typeface_accessible(fontID);
+ ensure_typeface_accessible(this->uniqueID());
otmRet = GetOutlineTextMetrics(hdc, sizeof(otm), &otm);
}
if (!otmRet || !GetTextFace(hdc, LF_FACESIZE, lf.lfFaceName)) {
diff --git a/src/ports/SkFontHost_win_dw.cpp b/src/ports/SkFontHost_win_dw.cpp
index 1e06e38..0e4ace1 100644
--- a/src/ports/SkFontHost_win_dw.cpp
+++ b/src/ports/SkFontHost_win_dw.cpp
@@ -481,6 +481,9 @@
protected:
virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE;
virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
+ virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ SkAdvancedTypefaceMetrics::PerGlyphInfo,
+ const uint32_t*, uint32_t) const SK_OVERRIDE;
};
class SkScalerContext_Windows : public SkScalerContext {
@@ -1397,23 +1400,19 @@
void* fLock;
};
-// static
-SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
- uint32_t fontID,
+SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
const uint32_t* glyphIDs,
- uint32_t glyphIDsCount) {
+ uint32_t glyphIDsCount) const {
SkAdvancedTypefaceMetrics* info = NULL;
HRESULT hr = S_OK;
- DWriteFontTypeface* typeface = GetDWriteFontByID(fontID);
-
- const unsigned glyphCount = typeface->fDWriteFontFace->GetGlyphCount();
+ const unsigned glyphCount = fDWriteFontFace->GetGlyphCount();
DWRITE_FONT_METRICS dwfm;
- typeface->fDWriteFontFace->GetMetrics(&dwfm);
+ fDWriteFontFace->GetMetrics(&dwfm);
info = new SkAdvancedTypefaceMetrics;
info->fEmSize = dwfm.designUnitsPerEm;
@@ -1424,8 +1423,8 @@
SkTScopedComPtr<IDWriteLocalizedStrings> familyNames;
SkTScopedComPtr<IDWriteLocalizedStrings> faceNames;
- hr = typeface->fDWriteFontFamily->GetFamilyNames(&familyNames);
- hr = typeface->fDWriteFont->GetFaceNames(&faceNames);
+ hr = fDWriteFontFamily->GetFamilyNames(&familyNames);
+ hr = fDWriteFont->GetFaceNames(&faceNames);
UINT32 familyNameLength;
hr = familyNames->GetStringLength(0, &familyNameLength);
@@ -1451,10 +1450,10 @@
info->fFontName.set(familyName.begin(), str_len);
if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) {
- populate_glyph_to_unicode(typeface->fDWriteFontFace.get(), glyphCount, &(info->fGlyphToUnicode));
+ populate_glyph_to_unicode(fDWriteFontFace.get(), glyphCount, &(info->fGlyphToUnicode));
}
- DWRITE_FONT_FACE_TYPE fontType = typeface->fDWriteFontFace->GetType();
+ DWRITE_FONT_FACE_TYPE fontType = fDWriteFontFace->GetType();
if (fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE ||
fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION) {
info->fType = SkAdvancedTypefaceMetrics::kTrueType_Font;
@@ -1469,10 +1468,10 @@
return info;
}
- AutoDWriteTable<SkOTTableHead> headTable(typeface->fDWriteFontFace.get());
- AutoDWriteTable<SkOTTablePostScript> postTable(typeface->fDWriteFontFace.get());
- AutoDWriteTable<SkOTTableHorizontalHeader> hheaTable(typeface->fDWriteFontFace.get());
- AutoDWriteTable<SkOTTableOS2> os2Table(typeface->fDWriteFontFace.get());
+ AutoDWriteTable<SkOTTableHead> headTable(fDWriteFontFace.get());
+ AutoDWriteTable<SkOTTablePostScript> postTable(fDWriteFontFace.get());
+ AutoDWriteTable<SkOTTableHorizontalHeader> hheaTable(fDWriteFontFace.get());
+ AutoDWriteTable<SkOTTableOS2> os2Table(fDWriteFontFace.get());
if (!headTable.fExists || !postTable.fExists || !hheaTable.fExists || !os2Table.fExists) {
info->fItalicAngle = 0;
info->fAscent = dwfm.ascent;;
@@ -1546,13 +1545,13 @@
if (fixedWidth) {
appendRange(&info->fGlyphWidths, 0);
int16_t advance;
- getWidthAdvance(typeface->fDWriteFontFace.get(), 1, &advance);
+ getWidthAdvance(fDWriteFontFace.get(), 1, &advance);
info->fGlyphWidths->fAdvance.append(1, &advance);
finishRange(info->fGlyphWidths.get(), 0,
SkAdvancedTypefaceMetrics::WidthRange::kDefault);
} else {
info->fGlyphWidths.reset(
- getAdvanceData(typeface->fDWriteFontFace.get(),
+ getAdvanceData(fDWriteFontFace.get(),
glyphCount,
glyphIDs,
glyphIDsCount,