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 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 onGetTableTags(SkFontTableTag tags[]) const;
virtual size_t onGetTableData(SkFontTableTag, size_t offset,

View File

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

View File

@ -447,12 +447,10 @@ static void populate_glyph_to_unicode(FT_Face& face,
}
}
// 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 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
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;

View File

@ -53,7 +53,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;
private:
typedef SkTypeface INHERITED;
};

View File

@ -418,7 +418,10 @@ protected:
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 @@ SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
, 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 @@ static void CFStringToSkString(CFStringRef src, SkString* dst) {
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 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
// 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;

View File

@ -27,16 +27,6 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(char const*) {
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) {

View File

@ -260,6 +260,14 @@ public:
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 @@ SkStream* SkFontHost::OpenStream(uint32_t fontID) {
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);

View File

@ -200,6 +200,9 @@ public:
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 @@ static bool getWidthAdvance(HDC hdc, int gId, int16_t* advance) {
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 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
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)) {

View File

@ -481,6 +481,9 @@ public:
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 @@ private:
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 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
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 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
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 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
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 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
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,