diff options
Diffstat (limited to 'src/sfnt/SkOTUtils.h')
-rw-r--r-- | src/sfnt/SkOTUtils.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/sfnt/SkOTUtils.h b/src/sfnt/SkOTUtils.h index 3c5ada25eb..4825fbeb2f 100644 --- a/src/sfnt/SkOTUtils.h +++ b/src/sfnt/SkOTUtils.h @@ -9,6 +9,9 @@ #define SkOTUtils_DEFINED #include "SkOTTableTypes.h" +#include "SkOTTable_name.h" +#include "SkTypeface.h" + class SkData; class SkStream; @@ -32,6 +35,55 @@ 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 |