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
This commit is contained in:
reed@google.com 2013-03-20 20:01:47 +00:00
parent 8366df025a
commit 2689f615e3
9 changed files with 58 additions and 68 deletions

View File

@ -208,6 +208,11 @@ protected:
virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const = 0; virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const = 0;
virtual void onFilterRec(SkScalerContextRec*) const = 0; virtual void onFilterRec(SkScalerContextRec*) const = 0;
virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const = 0;
virtual int onGetUPEM() const; virtual int onGetUPEM() const;
virtual int onGetTableTags(SkFontTableTag tags[]) const; virtual int onGetTableTags(SkFontTableTag tags[]) const;
virtual size_t onGetTableData(SkFontTableTag, size_t offset, virtual size_t onGetTableData(SkFontTableTag, size_t offset,

View File

@ -97,13 +97,10 @@ SkTypeface* SkTypeface::Deserialize(SkStream* stream) {
} }
SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics( SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, SkAdvancedTypefaceMetrics::PerGlyphInfo info,
const uint32_t* glyphIDs, const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const { uint32_t glyphIDsCount) const {
return SkFontHost::GetAdvancedTypefaceMetrics(fUniqueID, return this->onGetAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount);
perGlyphInfo,
glyphIDs,
glyphIDsCount);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -141,7 +138,7 @@ int SkTypeface::getUnitsPerEm() const {
upem = SkFontHost::GetUnitsPerEm(fUniqueID); upem = SkFontHost::GetUnitsPerEm(fUniqueID);
#else #else
SkAdvancedTypefaceMetrics* metrics; SkAdvancedTypefaceMetrics* metrics;
metrics = SkFontHost::GetAdvancedTypefaceMetrics(fUniqueID, metrics = this->getAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo, SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo,
NULL, 0); NULL, 0);
if (metrics) { if (metrics) {

View File

@ -447,12 +447,10 @@ static void populate_glyph_to_unicode(FT_Face& face,
} }
} }
// static SkAdvancedTypefaceMetrics* SkTypeface_FreeType::onGetAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
uint32_t fontID,
SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
const uint32_t* glyphIDs, const uint32_t* glyphIDs,
uint32_t glyphIDsCount) { uint32_t glyphIDsCount) const {
#if defined(SK_BUILD_FOR_MAC) #if defined(SK_BUILD_FOR_MAC)
return NULL; return NULL;
#else #else
@ -464,7 +462,7 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
libInit = gFTLibrary; libInit = gFTLibrary;
} }
SkAutoTCallIProc<struct FT_LibraryRec_, FT_Done_FreeType> ftLib(libInit); 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) if (NULL == rec)
return NULL; return NULL;
FT_Face face = rec->fFace; FT_Face face = rec->fFace;

View File

@ -53,7 +53,9 @@ protected:
virtual SkScalerContext* onCreateScalerContext( virtual SkScalerContext* onCreateScalerContext(
const SkDescriptor*) const SK_OVERRIDE; const SkDescriptor*) const SK_OVERRIDE;
virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics::PerGlyphInfo,
const uint32_t*, uint32_t) const SK_OVERRIDE;
private: private:
typedef SkTypeface INHERITED; typedef SkTypeface INHERITED;
}; };

View File

@ -418,6 +418,9 @@ protected:
virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE; virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE;
virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
virtual void onGetFontDescriptor(SkFontDescriptor*) const SK_OVERRIDE; virtual void onGetFontDescriptor(SkFontDescriptor*) const SK_OVERRIDE;
virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics::PerGlyphInfo,
const uint32_t*, uint32_t) const SK_OVERRIDE;
private: private:
typedef SkTypeface INHERITED; typedef SkTypeface INHERITED;
@ -657,7 +660,7 @@ SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
, fFBoundingBoxesGlyphOffset(0) , fFBoundingBoxesGlyphOffset(0)
, fGeneratedFBoundingBoxes(false) , fGeneratedFBoundingBoxes(false)
{ {
CTFontRef ctFont = GetFontRefFromFontID(fRec.fFontID); CTFontRef ctFont = typeface->fFontRef.get();
CFIndex numGlyphs = CTFontGetGlyphCount(ctFont); CFIndex numGlyphs = CTFontGetGlyphCount(ctFont);
// Get the state we need // Get the state we need
@ -1472,13 +1475,12 @@ static void CFStringToSkString(CFStringRef src, SkString* dst) {
dst->resize(strlen(dst->c_str())); dst->resize(strlen(dst->c_str()));
} }
// static SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
uint32_t fontID,
SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
const uint32_t* glyphIDs, const uint32_t* glyphIDs,
uint32_t glyphIDsCount) { uint32_t glyphIDsCount) const {
CTFontRef originalCTFont = GetFontRefFromFontID(fontID);
CTFontRef originalCTFont = fFontRef.get();
AutoCFRelease<CTFontRef> ctFont(CTFontCreateCopyWithAttributes( AutoCFRelease<CTFontRef> ctFont(CTFontCreateCopyWithAttributes(
originalCTFont, CTFontGetUnitsPerEm(originalCTFont), NULL, NULL)); originalCTFont, CTFontGetUnitsPerEm(originalCTFont), NULL, NULL));
SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics;
@ -1503,7 +1505,7 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
// fonts always have both glyf and loca tables. At the least, this is what // fonts always have both glyf and loca tables. At the least, this is what
// sfntly needs to subset the font. CTFontCopyAttribute() does not always // sfntly needs to subset the font. CTFontCopyAttribute() does not always
// succeed in determining this directly. // 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->fType = SkAdvancedTypefaceMetrics::kOther_Font;
info->fItalicAngle = 0; info->fItalicAngle = 0;
info->fAscent = 0; info->fAscent = 0;

View File

@ -27,16 +27,6 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(char const*) {
return NULL; 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) { SkStream* SkFontHost::OpenStream(uint32_t uniqueID) {

View File

@ -260,6 +260,14 @@ public:
virtual const char* getUniqueString() const = 0; virtual const char* getUniqueString() const = 0;
virtual const char* getFilePath() 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: private:
bool fIsSysFont; bool fIsSysFont;
@ -552,17 +560,6 @@ SkStream* SkFontHost::OpenStream(uint32_t fontID) {
return stream; 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, size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
int32_t* index) { int32_t* index) {
SkAutoMutexAcquire ac(gFamilyMutex); SkAutoMutexAcquire ac(gFamilyMutex);

View File

@ -200,6 +200,9 @@ public:
protected: protected:
virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE; virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE;
virtual void onFilterRec(SkScalerContextRec*) 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 { class FontMemResourceTypeface : public LogFontTypeface {
@ -1347,14 +1350,11 @@ static bool getWidthAdvance(HDC hdc, int gId, int16_t* advance) {
return true; return true;
} }
// static SkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
uint32_t fontID,
SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
const uint32_t* glyphIDs, const uint32_t* glyphIDs,
uint32_t glyphIDsCount) { uint32_t glyphIDsCount) const {
LOGFONT lf; LOGFONT lf = fLogFont;
GetLogFontByID(fontID, &lf);
SkAdvancedTypefaceMetrics* info = NULL; SkAdvancedTypefaceMetrics* info = NULL;
HDC hdc = CreateCompatibleDC(NULL); HDC hdc = CreateCompatibleDC(NULL);
@ -1371,7 +1371,7 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
OUTLINETEXTMETRIC otm; OUTLINETEXTMETRIC otm;
unsigned int otmRet = GetOutlineTextMetrics(hdc, sizeof(otm), &otm); unsigned int otmRet = GetOutlineTextMetrics(hdc, sizeof(otm), &otm);
if (0 == otmRet) { if (0 == otmRet) {
ensure_typeface_accessible(fontID); ensure_typeface_accessible(this->uniqueID());
otmRet = GetOutlineTextMetrics(hdc, sizeof(otm), &otm); otmRet = GetOutlineTextMetrics(hdc, sizeof(otm), &otm);
} }
if (!otmRet || !GetTextFace(hdc, LF_FACESIZE, lf.lfFaceName)) { if (!otmRet || !GetTextFace(hdc, LF_FACESIZE, lf.lfFaceName)) {

View File

@ -481,6 +481,9 @@ public:
protected: protected:
virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE; virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE;
virtual void onFilterRec(SkScalerContextRec*) 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 { class SkScalerContext_Windows : public SkScalerContext {
@ -1397,23 +1400,19 @@ private:
void* fLock; void* fLock;
}; };
// static SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics(
SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
uint32_t fontID,
SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
const uint32_t* glyphIDs, const uint32_t* glyphIDs,
uint32_t glyphIDsCount) { uint32_t glyphIDsCount) const {
SkAdvancedTypefaceMetrics* info = NULL; SkAdvancedTypefaceMetrics* info = NULL;
HRESULT hr = S_OK; HRESULT hr = S_OK;
DWriteFontTypeface* typeface = GetDWriteFontByID(fontID); const unsigned glyphCount = fDWriteFontFace->GetGlyphCount();
const unsigned glyphCount = typeface->fDWriteFontFace->GetGlyphCount();
DWRITE_FONT_METRICS dwfm; DWRITE_FONT_METRICS dwfm;
typeface->fDWriteFontFace->GetMetrics(&dwfm); fDWriteFontFace->GetMetrics(&dwfm);
info = new SkAdvancedTypefaceMetrics; info = new SkAdvancedTypefaceMetrics;
info->fEmSize = dwfm.designUnitsPerEm; info->fEmSize = dwfm.designUnitsPerEm;
@ -1424,8 +1423,8 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; SkTScopedComPtr<IDWriteLocalizedStrings> familyNames;
SkTScopedComPtr<IDWriteLocalizedStrings> faceNames; SkTScopedComPtr<IDWriteLocalizedStrings> faceNames;
hr = typeface->fDWriteFontFamily->GetFamilyNames(&familyNames); hr = fDWriteFontFamily->GetFamilyNames(&familyNames);
hr = typeface->fDWriteFont->GetFaceNames(&faceNames); hr = fDWriteFont->GetFaceNames(&faceNames);
UINT32 familyNameLength; UINT32 familyNameLength;
hr = familyNames->GetStringLength(0, &familyNameLength); hr = familyNames->GetStringLength(0, &familyNameLength);
@ -1451,10 +1450,10 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
info->fFontName.set(familyName.begin(), str_len); info->fFontName.set(familyName.begin(), str_len);
if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) { 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 || if (fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE ||
fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION) { fontType == DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION) {
info->fType = SkAdvancedTypefaceMetrics::kTrueType_Font; info->fType = SkAdvancedTypefaceMetrics::kTrueType_Font;
@ -1469,10 +1468,10 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
return info; return info;
} }
AutoDWriteTable<SkOTTableHead> headTable(typeface->fDWriteFontFace.get()); AutoDWriteTable<SkOTTableHead> headTable(fDWriteFontFace.get());
AutoDWriteTable<SkOTTablePostScript> postTable(typeface->fDWriteFontFace.get()); AutoDWriteTable<SkOTTablePostScript> postTable(fDWriteFontFace.get());
AutoDWriteTable<SkOTTableHorizontalHeader> hheaTable(typeface->fDWriteFontFace.get()); AutoDWriteTable<SkOTTableHorizontalHeader> hheaTable(fDWriteFontFace.get());
AutoDWriteTable<SkOTTableOS2> os2Table(typeface->fDWriteFontFace.get()); AutoDWriteTable<SkOTTableOS2> os2Table(fDWriteFontFace.get());
if (!headTable.fExists || !postTable.fExists || !hheaTable.fExists || !os2Table.fExists) { if (!headTable.fExists || !postTable.fExists || !hheaTable.fExists || !os2Table.fExists) {
info->fItalicAngle = 0; info->fItalicAngle = 0;
info->fAscent = dwfm.ascent;; info->fAscent = dwfm.ascent;;
@ -1546,13 +1545,13 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
if (fixedWidth) { if (fixedWidth) {
appendRange(&info->fGlyphWidths, 0); appendRange(&info->fGlyphWidths, 0);
int16_t advance; int16_t advance;
getWidthAdvance(typeface->fDWriteFontFace.get(), 1, &advance); getWidthAdvance(fDWriteFontFace.get(), 1, &advance);
info->fGlyphWidths->fAdvance.append(1, &advance); info->fGlyphWidths->fAdvance.append(1, &advance);
finishRange(info->fGlyphWidths.get(), 0, finishRange(info->fGlyphWidths.get(), 0,
SkAdvancedTypefaceMetrics::WidthRange::kDefault); SkAdvancedTypefaceMetrics::WidthRange::kDefault);
} else { } else {
info->fGlyphWidths.reset( info->fGlyphWidths.reset(
getAdvanceData(typeface->fDWriteFontFace.get(), getAdvanceData(fDWriteFontFace.get(),
glyphCount, glyphCount,
glyphIDs, glyphIDs,
glyphIDsCount, glyphIDsCount,