diff options
author | jvanverth@google.com <jvanverth@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-08-06 23:31:44 +0000 |
---|---|---|
committer | jvanverth@google.com <jvanverth@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-08-06 23:31:44 +0000 |
commit | 7ca6d2f0709d844f6afc601738b9453b3543d38b (patch) | |
tree | 272ed793ffbbb0294d80da2bc361ba3a3eb25935 | |
parent | 990d85f02ba6efaf6f3d75262d7ed650edc8afd5 (diff) |
Reverting r10589: Add getFamilyNames to SkTypeface
git-svn-id: http://skia.googlecode.com/svn/trunk@10590 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/core/SkTypeface.h | 17 | ||||
-rw-r--r-- | src/core/SkTypeface.cpp | 4 | ||||
-rw-r--r-- | src/fonts/SkGScalerContext.cpp | 4 | ||||
-rw-r--r-- | src/fonts/SkGScalerContext.h | 2 | ||||
-rw-r--r-- | src/ports/SkFontHost_FreeType.cpp | 13 | ||||
-rw-r--r-- | src/ports/SkFontHost_FreeType_common.h | 2 | ||||
-rwxr-xr-x | src/ports/SkFontHost_mac.cpp | 26 | ||||
-rwxr-xr-x | src/ports/SkFontHost_win.cpp | 129 | ||||
-rw-r--r-- | src/ports/SkFontHost_win_dw.cpp | 50 | ||||
-rw-r--r-- | src/sfnt/SkOTTable_name.cpp | 27 | ||||
-rw-r--r-- | src/sfnt/SkOTTable_name.h | 6 | ||||
-rw-r--r-- | src/sfnt/SkOTUtils.cpp | 42 | ||||
-rw-r--r-- | src/sfnt/SkOTUtils.h | 52 | ||||
-rw-r--r-- | tests/FontNamesTest.cpp | 115 |
14 files changed, 108 insertions, 381 deletions
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index a0ca182154..3cfa6ac3c6 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -225,21 +225,6 @@ public: */ int getUnitsPerEm() const; - struct LocalizedString { - SkString fString; - SkString fLanguage; - }; - class LocalizedStrings : ::SkNoncopyable { - public: - virtual bool next(LocalizedString* localizedString) = 0; - }; - /** - * Returns an iterator which will attempt to enumerate all of the - * family names specified by the font. - * It is the caller's responsibility to SK_DELETE the returned pointer. - */ - LocalizedStrings* getFamilyNames() const; - /** * Return the family name for this typeface. It will always be returned * encoded as UTF8, but the language of the name is whatever the host @@ -310,8 +295,6 @@ protected: virtual int onGetUPEM() const = 0; - virtual LocalizedStrings* onGetFamilyNames() const = 0; - virtual int onGetTableTags(SkFontTableTag tags[]) const = 0; virtual size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const = 0; diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp index 507c1bf2a6..34ff853c5c 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -194,10 +194,6 @@ int SkTypeface::getUnitsPerEm() const { return this->onGetUPEM(); } -SkTypeface::LocalizedStrings* SkTypeface::getFamilyNames() const { - return this->onGetFamilyNames(); -} - void SkTypeface::getFamilyName(SkString* name) const { bool isLocal = false; SkFontDescriptor desc(this->style()); diff --git a/src/fonts/SkGScalerContext.cpp b/src/fonts/SkGScalerContext.cpp index 34a55e6d31..882c70b121 100644 --- a/src/fonts/SkGScalerContext.cpp +++ b/src/fonts/SkGScalerContext.cpp @@ -202,10 +202,6 @@ int SkGTypeface::onGetUPEM() const { return fProxy->getUnitsPerEm(); } -SkTypeface::LocalizedStrings* SkGTypeface::onGetFamilyNames() const { - return fProxy->getFamilyNames(); -} - int SkGTypeface::onGetTableTags(SkFontTableTag tags[]) const { return fProxy->getTableTags(tags); } diff --git a/src/fonts/SkGScalerContext.h b/src/fonts/SkGScalerContext.h index 0a06b7c12b..1aa1df369e 100644 --- a/src/fonts/SkGScalerContext.h +++ b/src/fonts/SkGScalerContext.h @@ -32,8 +32,6 @@ protected: virtual int onCountGlyphs() const SK_OVERRIDE; virtual int onGetUPEM() const SK_OVERRIDE; - virtual SkTypeface::LocalizedStrings* onGetFamilyNames() const SK_OVERRIDE; - virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; virtual size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const SK_OVERRIDE; diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp index c5542a9ddf..3a32ea40c4 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -17,7 +17,6 @@ #include "SkGlyph.h" #include "SkMask.h" #include "SkMaskGamma.h" -#include "SkOTUtils.h" #include "SkAdvancedTypefaceMetrics.h" #include "SkScalerContext.h" #include "SkStream.h" @@ -1403,18 +1402,6 @@ int SkTypeface_FreeType::onCountGlyphs() const { return fGlyphCount; } -SkTypeface::LocalizedStrings* SkTypeface_FreeType::onGetFamilyNames() const { - SkTypeface::LocalizedStrings* nameIter = - SkOTUtils::LocalizedStrings_NameTable::CreateForFamilyNames(*this); - if (NULL == nameIter) { - SkString familyName; - this->getFamilyName(&familyName); - SkString language("und"); //undetermined - nameIter = new SkOTUtils::LocalizedStrings_SingleName(familyName, language); - } - return nameIter; -} - int SkTypeface_FreeType::onGetTableTags(SkFontTableTag tags[]) const { AutoFTAccess fta(this); FT_Face face = fta.face(); diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h index 5c069d042d..d3df9ce85b 100644 --- a/src/ports/SkFontHost_FreeType_common.h +++ b/src/ports/SkFontHost_FreeType_common.h @@ -64,8 +64,6 @@ protected: int glyphCount) const SK_OVERRIDE; virtual int onCountGlyphs() const SK_OVERRIDE; - virtual LocalizedStrings* onGetFamilyNames() const SK_OVERRIDE; - virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; virtual size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const SK_OVERRIDE; diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index 9600730f67..71fa5ebdb0 100755 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -95,7 +95,6 @@ public: operator CFRef() const { return fCFRef; } CFRef get() const { return fCFRef; } - CFRef* operator&() { SkASSERT(fCFRef == NULL); return &fCFRef; } private: CFRef fCFRef; }; @@ -454,7 +453,6 @@ protected: virtual int onGetUPEM() const SK_OVERRIDE; virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; - virtual SkTypeface::LocalizedStrings* onGetFamilyNames() const SK_OVERRIDE; virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; virtual size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const SK_OVERRIDE; @@ -1750,30 +1748,6 @@ int SkTypeface_Mac::onGetUPEM() const { return CGFontGetUnitsPerEm(cgFont); } -SkTypeface::LocalizedStrings* SkTypeface_Mac::onGetFamilyNames() const { - SkTypeface::LocalizedStrings* nameIter = - SkOTUtils::LocalizedStrings_NameTable::CreateForFamilyNames(*this); - if (NULL == nameIter) { - AutoCFRelease<CFStringRef> cfLanguage; - AutoCFRelease<CFStringRef> cfFamilyName( - CTFontCopyLocalizedName(fFontRef, kCTFontFamilyNameKey, &cfLanguage)); - - SkString skLanguage; - SkString skFamilyName; - if (cfLanguage.get()) { - CFStringToSkString(cfLanguage.get(), &skLanguage); - } else { - skLanguage = "und"; //undetermined - } - if (cfFamilyName.get()) { - CFStringToSkString(cfFamilyName.get(), &skFamilyName); - } - - nameIter = new SkOTUtils::LocalizedStrings_SingleName(skFamilyName, skLanguage); - } - return nameIter; -} - // If, as is the case with web fonts, the CTFont data isn't available, // the CGFont data may work. While the CGFont may always provide the // right result, leave the CTFont code path to minimize disruption. diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index d52774ca6d..fe646d74b9 100755 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -16,7 +16,6 @@ #include "SkGlyph.h" #include "SkMaskGamma.h" #include "SkOTTable_maxp.h" -#include "SkOTTable_name.h" #include "SkOTUtils.h" #include "SkPath.h" #include "SkSFNTHeader.h" @@ -97,26 +96,6 @@ static void tchar_to_skstring(const TCHAR t[], SkString* s) { #endif } -static void dcfontname_to_skstring(HDC deviceContext, const LOGFONT& lf, SkString* familyName) { - int fontNameLen; //length of fontName in TCHARS. - if (0 == (fontNameLen = GetTextFace(deviceContext, 0, NULL))) { - call_ensure_accessible(lf); - if (0 == (fontNameLen = GetTextFace(deviceContext, 0, NULL))) { - fontNameLen = 0; - } - } - - SkAutoSTArray<LF_FULLFACESIZE, TCHAR> fontName(fontNameLen+1); - if (0 == GetTextFace(deviceContext, fontNameLen, fontName.get())) { - call_ensure_accessible(lf); - if (0 == GetTextFace(deviceContext, fontNameLen, fontName.get())) { - fontName[0] = 0; - } - } - - tchar_to_skstring(fontName.get(), familyName); -} - static void make_canonical(LOGFONT* lf) { lf->lfHeight = -2048; lf->lfQuality = CLEARTYPE_QUALITY;//PROOF_QUALITY; @@ -244,6 +223,10 @@ public: (textMetric.tmPitchAndFamily & TMPF_DEVICE)); } + void getFamilyName(SkString* name) const { + tchar_to_skstring(fLogFont.lfFaceName, name); + } + LOGFONT fLogFont; bool fSerializeAsStream; bool fCanBeLCD; @@ -268,7 +251,6 @@ protected: virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE; virtual int onCountGlyphs() const SK_OVERRIDE; virtual int onGetUPEM() const SK_OVERRIDE; - virtual SkTypeface::LocalizedStrings* onGetFamilyNames() const SK_OVERRIDE; virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; virtual size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const SK_OVERRIDE; @@ -1733,8 +1715,21 @@ void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, HDC deviceContext = ::CreateCompatibleDC(NULL); HFONT savefont = (HFONT)SelectObject(deviceContext, font); - SkString familyName; - dcfontname_to_skstring(deviceContext, fLogFont, &familyName); + int fontNameLen; //length of fontName in TCHARS. + if (0 == (fontNameLen = GetTextFace(deviceContext, 0, NULL))) { + call_ensure_accessible(fLogFont); + if (0 == (fontNameLen = GetTextFace(deviceContext, 0, NULL))) { + fontNameLen = 0; + } + } + + SkAutoSTArray<LF_FULLFACESIZE, TCHAR> fontName(fontNameLen+1); + if (0 == GetTextFace(deviceContext, fontNameLen, fontName.get())) { + call_ensure_accessible(fLogFont); + if (0 == GetTextFace(deviceContext, fontNameLen, fontName.get())) { + fontName[0] = 0; + } + } if (deviceContext) { ::SelectObject(deviceContext, savefont); @@ -1744,6 +1739,9 @@ void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, ::DeleteObject(font); } + SkString familyName; + tchar_to_skstring(fontName.get(), &familyName); + desc->setFamilyName(familyName.c_str()); *isLocalStream = this->fSerializeAsStream; } @@ -2056,18 +2054,6 @@ int LogFontTypeface::onGetUPEM() const { return upem; } -SkTypeface::LocalizedStrings* LogFontTypeface::onGetFamilyNames() const { - SkTypeface::LocalizedStrings* nameIter = - SkOTUtils::LocalizedStrings_NameTable::CreateForFamilyNames(*this); - if (NULL == nameIter) { - SkString familyName; - this->getFamilyName(&familyName); - SkString language("und"); //undetermined - nameIter = new SkOTUtils::LocalizedStrings_SingleName(familyName, language); - } - return nameIter; -} - int LogFontTypeface::onGetTableTags(SkFontTableTag tags[]) const { SkSFNTHeader header; if (sizeof(header) != this->onGetTableData(0, 0, sizeof(header), &header)) { @@ -2205,25 +2191,21 @@ SkTypeface* LogFontTypeface::onRefMatchingStyle(Style style) const { #include "SkFontMgr.h" #include "SkDataTable.h" -static bool valid_logfont_for_enum(const LOGFONT& lf) { - // TODO: Vector FON is unsupported and should not be listed. - return - // Ignore implicit vertical variants. - lf.lfFaceName[0] && lf.lfFaceName[0] != '@' - - // DEFAULT_CHARSET is used to get all fonts, but also implies all - // character sets. Filter assuming all fonts support ANSI_CHARSET. - && ANSI_CHARSET == lf.lfCharSet - ; -} - -/** An EnumFontFamExProc implementation which interprets builderParam as - * an SkTDArray<ENUMLOGFONTEX>* and appends logfonts which - * pass the valid_logfont_for_enum predicate. - */ -static int CALLBACK enum_family_proc(const LOGFONT* lf, const TEXTMETRIC*, - DWORD fontType, LPARAM builderParam) { - if (valid_logfont_for_enum(*lf)) { +static bool valid_logfont_for_enum(const LOGFONT& lf, DWORD fontType) { + return TRUETYPE_FONTTYPE == fontType + && lf.lfFaceName[0] + && lf.lfFaceName[0] != '@' + && OUT_STROKE_PRECIS == lf.lfOutPrecision + // without the chraset check, we got LOTS of dups of the same font + // is there a better check (other than searching the array for + // the same name? + && 0 == lf.lfCharSet + ; +} + +static int CALLBACK enum_fonts_proc(const LOGFONT* lf, const TEXTMETRIC*, + DWORD fontType, LPARAM builderParam) { + if (valid_logfont_for_enum(*lf, fontType)) { SkTDArray<ENUMLOGFONTEX>* array = (SkTDArray<ENUMLOGFONTEX>*)builderParam; *array->append() = *(ENUMLOGFONTEX*)lf; } @@ -2239,13 +2221,8 @@ static SkFontStyle compute_fontstyle(const LOGFONT& lf) { class SkFontStyleSetGDI : public SkFontStyleSet { public: SkFontStyleSetGDI(const TCHAR familyName[]) { - LOGFONT lf; - sk_bzero(&lf, sizeof(lf)); - lf.lfCharSet = DEFAULT_CHARSET; - _tcscpy_s(lf.lfFaceName, familyName); - HDC hdc = ::CreateCompatibleDC(NULL); - ::EnumFontFamiliesEx(hdc, &lf, enum_family_proc, (LPARAM)&fArray, 0); + ::EnumFonts(hdc, familyName, enum_fonts_proc, (LPARAM)&fArray); ::DeleteDC(hdc); } @@ -2283,9 +2260,29 @@ private: SkTDArray<ENUMLOGFONTEX> fArray; }; +static int CALLBACK enum_family_proc(const LOGFONT* lf, const TEXTMETRIC* tm, + DWORD fontType, LPARAM builderParam) { + if (valid_logfont_for_enum(*lf, fontType)) { + SkTDArray<ENUMLOGFONTEX>* array = (SkTDArray<ENUMLOGFONTEX>*)builderParam; + *array->append() = *(ENUMLOGFONTEX*)lf; +#if 0 + SkString str; + tchar_to_skstring(lf->lfFaceName, &str); + SkDebugf("fam:%s height:%d width:%d esc:%d orien:%d weight:%d ital:%d char:%d clip:%d qual:%d pitch:%d\n", + str.c_str(), lf->lfHeight, lf->lfWidth, lf->lfEscapement, lf->lfOrientation, + lf->lfWeight, lf->lfItalic, lf->lfCharSet, lf->lfClipPrecision, lf->lfQuality, + lf->lfPitchAndFamily); +#endif + } + return 1; // non-zero means continue +} + class SkFontMgrGDI : public SkFontMgr { -public: - SkFontMgrGDI() { + void init() { + if (!fLogFontArray.isEmpty()) { + return; + } + LOGFONT lf; sk_bzero(&lf, sizeof(lf)); lf.lfCharSet = DEFAULT_CHARSET; @@ -2295,17 +2292,23 @@ public: ::DeleteDC(hdc); } +public: + SkFontMgrGDI() {} + protected: virtual int onCountFamilies() SK_OVERRIDE { + this->init(); return fLogFontArray.count(); } virtual void onGetFamilyName(int index, SkString* familyName) SK_OVERRIDE { + this->init(); SkASSERT((unsigned)index < (unsigned)fLogFontArray.count()); tchar_to_skstring(fLogFontArray[index].elfLogFont.lfFaceName, familyName); } virtual SkFontStyleSet* onCreateStyleSet(int index) SK_OVERRIDE { + this->init(); SkASSERT((unsigned)index < (unsigned)fLogFontArray.count()); return SkNEW_ARGS(SkFontStyleSetGDI, (fLogFontArray[index].elfLogFont.lfFaceName)); } diff --git a/src/ports/SkFontHost_win_dw.cpp b/src/ports/SkFontHost_win_dw.cpp index cee8b362b2..beec056e93 100644 --- a/src/ports/SkFontHost_win_dw.cpp +++ b/src/ports/SkFontHost_win_dw.cpp @@ -495,7 +495,6 @@ protected: virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE; virtual int onCountGlyphs() const SK_OVERRIDE; virtual int onGetUPEM() const SK_OVERRIDE; - virtual SkTypeface::LocalizedStrings* onGetFamilyNames() const SK_OVERRIDE; virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; virtual size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const SK_OVERRIDE; @@ -1089,54 +1088,6 @@ int DWriteFontTypeface::onGetUPEM() const { return metrics.designUnitsPerEm; } -class LocalizedStrings_IDWriteLocalizedStrings : public SkTypeface::LocalizedStrings { -public: - /** Takes ownership of the IDWriteLocalizedStrings. */ - explicit LocalizedStrings_IDWriteLocalizedStrings(IDWriteLocalizedStrings* strings) - : fIndex(0), fStrings(strings) - { } - - virtual bool next(SkTypeface::LocalizedString* localizedString) SK_OVERRIDE { - if (fIndex >= fStrings->GetCount()) { - return false; - } - - // String - UINT32 stringLength; - HRBM(fStrings->GetStringLength(fIndex, &stringLength), "Could not get string length."); - stringLength += 1; - - SkSMallocWCHAR wString(stringLength); - HRBM(fStrings->GetString(fIndex, wString.get(), stringLength), "Could not get string."); - - HRB(wchar_to_skstring(wString.get(), &localizedString->fString)); - - // Locale - UINT32 localeLength; - HRBM(fStrings->GetLocaleNameLength(fIndex, &localeLength), "Could not get locale length."); - localeLength += 1; - - SkSMallocWCHAR wLocale(localeLength); - HRBM(fStrings->GetLocaleName(fIndex, wLocale.get(), localeLength), "Could not get locale."); - - HRB(wchar_to_skstring(wLocale.get(), &localizedString->fLanguage)); - - ++fIndex; - return true; - } - -private: - UINT32 fIndex; - SkTScopedComPtr<IDWriteLocalizedStrings> fStrings; -}; - -SkTypeface::LocalizedStrings* DWriteFontTypeface::onGetFamilyNames() const { - SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; - HRNM(fDWriteFontFamily->GetFamilyNames(&familyNames), "Could not obtain family names."); - - return new LocalizedStrings_IDWriteLocalizedStrings(familyNames.release()); -} - int DWriteFontTypeface::onGetTableTags(SkFontTableTag tags[]) const { DWRITE_FONT_FACE_TYPE type = fDWriteFontFace->GetType(); if (type != DWRITE_FONT_FACE_TYPE_CFF && @@ -1705,7 +1656,6 @@ public: DWRITE_FONT_STRETCH width = (DWRITE_FONT_STRETCH)pattern.width(); SkTScopedComPtr<IDWriteFont> font; - // TODO: perhaps use GetMatchingFonts and get the least simulated? HRNM(fFontFamily->GetFirstMatchingFont(weight, width, slant, &font), "Could not match font in family."); diff --git a/src/sfnt/SkOTTable_name.cpp b/src/sfnt/SkOTTable_name.cpp index b536c0a115..e0440754ca 100644 --- a/src/sfnt/SkOTTable_name.cpp +++ b/src/sfnt/SkOTTable_name.cpp @@ -451,8 +451,6 @@ bool SkOTTableName::Iterator::next(SkOTTableName::Iterator::Record& record) { ++fIndex; } while (fType != -1 && nameRecord->nameID.fontSpecific != fType); - record.type = nameRecord->nameID.fontSpecific; - const uint16_t stringTableOffset = SkEndian_SwapBE16(fName.stringOffset); const char* stringTable = SkTAddOffset<const char>(&fName, stringTableOffset); @@ -462,29 +460,20 @@ bool SkOTTableName::Iterator::next(SkOTTableName::Iterator::Record& record) { const char* nameString = SkTAddOffset<const char>(stringTable, nameOffset); switch (nameRecord->platformID.value) { case SkOTTableName::Record::PlatformID::Windows: - if (SkOTTableName::Record::EncodingID::Windows::UnicodeBMPUCS2 - != nameRecord->encodingID.windows.value - && SkOTTableName::Record::EncodingID::Windows::UnicodeUCS4 - != nameRecord->encodingID.windows.value - && SkOTTableName::Record::EncodingID::Windows::Symbol - != nameRecord->encodingID.windows.value) - { - record.name.reset(); - break; - } + SkASSERT(SkOTTableName::Record::EncodingID::Windows::UnicodeBMPUCS2 + == nameRecord->encodingID.windows.value + || SkOTTableName::Record::EncodingID::Windows::UnicodeUCS4 + == nameRecord->encodingID.windows.value + || SkOTTableName::Record::EncodingID::Windows::Symbol + == nameRecord->encodingID.windows.value); case SkOTTableName::Record::PlatformID::Unicode: case SkOTTableName::Record::PlatformID::ISO: SkStringFromUTF16BE((const uint16_t*)nameString, nameLength, record.name); break; case SkOTTableName::Record::PlatformID::Macintosh: - // TODO: need better decoding, especially on Mac. - if (SkOTTableName::Record::EncodingID::Macintosh::Roman - != nameRecord->encodingID.macintosh.value) - { - record.name.reset(); - break; - } + SkASSERT(SkOTTableName::Record::EncodingID::Macintosh::Roman + == nameRecord->encodingID.macintosh.value); SkStringFromMacRoman((const uint8_t*)nameString, nameLength, record.name); break; diff --git a/src/sfnt/SkOTTable_name.h b/src/sfnt/SkOTTable_name.h index f3dae4085a..8dde1a4fc7 100644 --- a/src/sfnt/SkOTTable_name.h +++ b/src/sfnt/SkOTTable_name.h @@ -554,13 +554,7 @@ struct SkOTTableName { : fName(name), fIndex(0), fType(type) { } - void reset(SkOTTableName::Record::NameID::Predefined::Value type) { - fIndex = 0; - fType = type; - } - struct Record { - SK_OT_USHORT type; SkString name; SkString language; }; diff --git a/src/sfnt/SkOTUtils.cpp b/src/sfnt/SkOTUtils.cpp index 004a888310..c7716fffd5 100644 --- a/src/sfnt/SkOTUtils.cpp +++ b/src/sfnt/SkOTUtils.cpp @@ -159,45 +159,3 @@ SkData* SkOTUtils::RenameFont(SkStream* fontData, const char* fontName, int font return rewrittenFontData.detach(); } - - -SkOTUtils::LocalizedStrings_NameTable* -SkOTUtils::LocalizedStrings_NameTable::CreateForFamilyNames(const SkTypeface& typeface) { - static const SkFontTableTag nameTag = SkSetFourByteTag('n','a','m','e'); - size_t nameTableSize = typeface.getTableSize(nameTag); - if (0 == nameTableSize) { - return NULL; - } - SkAutoTDeleteArray<uint8_t> nameTableData(new uint8_t[nameTableSize]); - size_t copied = typeface.getTableData(nameTag, 0, nameTableSize, nameTableData.get()); - if (copied != nameTableSize) { - return NULL; - } - - return new SkOTUtils::LocalizedStrings_NameTable((SkOTTableName*)nameTableData.detach(), - SkOTUtils::LocalizedStrings_NameTable::familyNameTypes, - SK_ARRAY_COUNT(SkOTUtils::LocalizedStrings_NameTable::familyNameTypes)); -} - -bool SkOTUtils::LocalizedStrings_NameTable::next(SkTypeface::LocalizedString* localizedString) { - do { - SkOTTableName::Iterator::Record record; - if (fFamilyNameIter.next(record)) { - localizedString->fString = record.name; - localizedString->fLanguage = record.language; - return true; - } - if (fTypesCount == fTypesIndex + 1) { - return false; - } - ++fTypesIndex; - fFamilyNameIter.reset(fTypes[fTypesIndex]); - } while (true); -} - -SkOTTableName::Record::NameID::Predefined::Value -SkOTUtils::LocalizedStrings_NameTable::familyNameTypes[3] = { - SkOTTableName::Record::NameID::Predefined::FontFamilyName, - SkOTTableName::Record::NameID::Predefined::PreferredFamily, - SkOTTableName::Record::NameID::Predefined::WWSFamilyName, -}; diff --git a/src/sfnt/SkOTUtils.h b/src/sfnt/SkOTUtils.h index 4825fbeb2f..3c5ada25eb 100644 --- a/src/sfnt/SkOTUtils.h +++ b/src/sfnt/SkOTUtils.h @@ -9,9 +9,6 @@ #define SkOTUtils_DEFINED #include "SkOTTableTypes.h" -#include "SkOTTable_name.h" -#include "SkTypeface.h" - class SkData; class SkStream; @@ -35,55 +32,6 @@ struct SkOTUtils { * fontName and fontNameLen must be specified in terms of ASCII chars. */ static SkData* RenameFont(SkStream* fontData, const char* fontName, int fontNameLen); - - /** An implementation of LocalizedStrings which obtains it's data from a 'name' table. */ - class LocalizedStrings_NameTable : public SkTypeface::LocalizedStrings { - public: - /** Takes ownership of the nameTableData and will free it with SK_DELETE. */ - LocalizedStrings_NameTable(SkOTTableName* nameTableData, - SkOTTableName::Record::NameID::Predefined::Value types[], - int typesCount) - : fTypes(types), fTypesCount(typesCount), fTypesIndex(0) - , fNameTableData(nameTableData), fFamilyNameIter(*nameTableData, fTypes[fTypesIndex]) - { } - - /** Creates an iterator over all the family names in the 'name' table of a typeface. - * If no valid 'name' table can be found, returns NULL. - */ - static LocalizedStrings_NameTable* CreateForFamilyNames(const SkTypeface& typeface); - - virtual bool next(SkTypeface::LocalizedString* localizedString) SK_OVERRIDE; - private: - static SkOTTableName::Record::NameID::Predefined::Value familyNameTypes[3]; - - SkOTTableName::Record::NameID::Predefined::Value* fTypes; - int fTypesCount; - int fTypesIndex; - SkAutoTDeleteArray<SkOTTableName> fNameTableData; - SkOTTableName::Iterator fFamilyNameIter; - }; - - /** An implementation of LocalizedStrings which has one name. */ - class LocalizedStrings_SingleName : public SkTypeface::LocalizedStrings { - public: - LocalizedStrings_SingleName(SkString name, SkString language) - : fName(name), fLanguage(language), fHasNext(true) - { } - - virtual bool next(SkTypeface::LocalizedString* localizedString) SK_OVERRIDE { - localizedString->fString = fName; - localizedString->fLanguage = fLanguage; - - bool hadNext = fHasNext; - fHasNext = false; - return hadNext; - } - - private: - SkString fName; - SkString fLanguage; - bool fHasNext; - }; }; #endif diff --git a/tests/FontNamesTest.cpp b/tests/FontNamesTest.cpp index 18ba35695e..3845c3b6c5 100644 --- a/tests/FontNamesTest.cpp +++ b/tests/FontNamesTest.cpp @@ -7,8 +7,6 @@ #include "Test.h" -#include "SkCommandLineFlags.h" -#include "SkFontMgr.h" #include "SkOTTable_name.h" #include "SkTypeface.h" @@ -110,7 +108,40 @@ struct FontNamesTest { }, }; -static void test_synthetic(skiatest::Reporter* reporter, bool verbose) { +static void TestFontNames(skiatest::Reporter* reporter) { + static const char* interestingFont[] = { + "Arial", + "Times New Roman", + "MS PGothic", // Has Japanese name. + "Wingdings", // Uses 'Symbol' name encoding. + }; + static const SkFontTableTag nameTag = SkSetFourByteTag('n','a','m','e'); + + for (size_t i = 0; i < SK_ARRAY_COUNT(interestingFont); ++i) { + SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromName(interestingFont[i], + SkTypeface::kNormal)); + if (NULL == typeface.get()) { + continue; + } + size_t nameTableSize = typeface->getTableSize(nameTag); + if (0 == nameTableSize) { + continue; + } + uint8_t* nameTableData = new uint8_t[nameTableSize]; + SkAutoTDeleteArray<uint8_t> ada(nameTableData); + size_t copied = typeface->getTableData(nameTag, 0, nameTableSize, nameTableData); + if (copied != nameTableSize) { + continue; + } + + SkOTTableName::Iterator iter(*((SkOTTableName*)nameTableData), + SkOTTableName::Record::NameID::Predefined::FontFamilyName); + SkOTTableName::Iterator::Record record; + while (iter.next(record)) { + //printf("%s <%s>\n", record.name.c_str(), record.language.c_str()); + } + } + for (size_t i = 0; i < SK_ARRAY_COUNT(test); ++i) { SkOTTableName::Iterator iter(*test[i].data, test[i].nameID.predefined.value); SkOTTableName::Iterator::Record record; @@ -139,84 +170,6 @@ static void test_synthetic(skiatest::Reporter* reporter, bool verbose) { } } -#define MAX_FAMILIES 1000 -static void test_systemfonts(skiatest::Reporter* reporter, bool verbose) { - static const SkFontTableTag nameTag = SkSetFourByteTag('n','a','m','e'); - - SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); - int count = SkMin32(fm->countFamilies(), MAX_FAMILIES); - for (int i = 0; i < count; ++i) { - SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); - for (int j = 0; j < set->count(); ++j) { - SkString sname; - SkFontStyle fs; - set->getStyle(j, &fs, &sname); - - SkAutoTUnref<SkTypeface> typeface(set->createTypeface(j)); - - SkString familyName; - typeface->getFamilyName(&familyName); - if (verbose) { - printf("[%s]\n", familyName.c_str()); - } - - SkAutoTDelete<SkTypeface::LocalizedStrings> familyNamesIter(typeface->getFamilyNames()); - SkTypeface::LocalizedString familyNameLocalized; - while (familyNamesIter->next(&familyNameLocalized)) { - if (verbose) { - printf("(%s) <%s>\n", familyNameLocalized.fString.c_str(), - familyNameLocalized.fLanguage.c_str()); - } - } - - size_t nameTableSize = typeface->getTableSize(nameTag); - if (0 == nameTableSize) { - continue; - } - SkAutoTMalloc<uint8_t> nameTableData(nameTableSize); - size_t copied = typeface->getTableData(nameTag, 0, nameTableSize, nameTableData.get()); - if (copied != nameTableSize) { - continue; - } - - SkOTTableName::Iterator::Record record; - SkOTTableName::Iterator familyNameIter(*((SkOTTableName*)nameTableData.get()), - SkOTTableName::Record::NameID::Predefined::FontFamilyName); - while (familyNameIter.next(record)) { - REPORTER_ASSERT_MESSAGE(reporter, - SkOTTableName::Record::NameID::Predefined::FontFamilyName == record.type, - "Requested family name, got something else." - ); - if (verbose) { - printf("{%s} <%s>\n", record.name.c_str(), record.language.c_str()); - } - } - - SkOTTableName::Iterator styleNameIter(*((SkOTTableName*)nameTableData.get()), - SkOTTableName::Record::NameID::Predefined::FontSubfamilyName); - while (styleNameIter.next(record)) { - REPORTER_ASSERT_MESSAGE(reporter, - SkOTTableName::Record::NameID::Predefined::FontSubfamilyName == record.type, - "Requested subfamily name, got something else." - ); - if (verbose) { - printf("{{%s}} <%s>\n", record.name.c_str(), record.language.c_str()); - } - } - - if (verbose) { - printf("\n"); - } - } - } -} - -DEFINE_bool(verboseFontNames, false, "verbose FontNames test."); - -static void TestFontNames(skiatest::Reporter* reporter) { - test_synthetic(reporter, FLAGS_verboseFontNames); - test_systemfonts(reporter, FLAGS_verboseFontNames); -} #include "TestClassDef.h" DEFINE_TESTCLASS("FontNames", FontNamesTestClass, TestFontNames) |