2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkOTUtils_DEFINED
9 #define SkOTUtils_DEFINED
11 #include "SkOTTableTypes.h"
12 #include "SkOTTable_name.h"
13 #include "SkTypeface.h"
20 * Calculates the OpenType checksum for data.
22 static uint32_t CalcTableChecksum(SK_OT_ULONG *data, size_t length);
25 * Renames an sfnt font. On failure (invalid data or not an sfnt font)
28 * Essentially, this removes any existing 'name' table and replaces it
29 * with a new one in which FontFamilyName, FontSubfamilyName,
30 * UniqueFontIdentifier, FullFontName, and PostscriptName are fontName.
32 * The new 'name' table records will be written with the Windows,
33 * UnicodeBMPUCS2, and English_UnitedStates settings.
35 * fontName and fontNameLen must be specified in terms of ASCII chars.
37 * Does not affect fontData's ownership.
39 static SkData* RenameFont(SkStreamAsset* fontData, const char* fontName, int fontNameLen);
41 /** An implementation of LocalizedStrings which obtains it's data from a 'name' table. */
42 class LocalizedStrings_NameTable : public SkTypeface::LocalizedStrings {
44 /** Takes ownership of the nameTableData and will free it with SK_DELETE. */
45 LocalizedStrings_NameTable(SkOTTableName* nameTableData,
46 SkOTTableName::Record::NameID::Predefined::Value types[],
48 : fTypes(types), fTypesCount(typesCount), fTypesIndex(0)
49 , fNameTableData(nameTableData), fFamilyNameIter(*nameTableData, fTypes[fTypesIndex])
52 /** Creates an iterator over all the family names in the 'name' table of a typeface.
53 * If no valid 'name' table can be found, returns NULL.
55 static LocalizedStrings_NameTable* CreateForFamilyNames(const SkTypeface& typeface);
57 bool next(SkTypeface::LocalizedString* localizedString) SK_OVERRIDE;
59 static SkOTTableName::Record::NameID::Predefined::Value familyNameTypes[3];
61 SkOTTableName::Record::NameID::Predefined::Value* fTypes;
64 SkAutoTDeleteArray<SkOTTableName> fNameTableData;
65 SkOTTableName::Iterator fFamilyNameIter;
68 /** An implementation of LocalizedStrings which has one name. */
69 class LocalizedStrings_SingleName : public SkTypeface::LocalizedStrings {
71 LocalizedStrings_SingleName(SkString name, SkString language)
72 : fName(name), fLanguage(language), fHasNext(true)
75 bool next(SkTypeface::LocalizedString* localizedString) SK_OVERRIDE {
76 localizedString->fString = fName;
77 localizedString->fLanguage = fLanguage;
79 bool hadNext = fHasNext;