Renames an sfnt font. On failure (invalid data or not an sfnt font) returns nullptr.
Essentially, this removes any existing 'name' table and replaces it with a new one in which FontFamilyName, FontSubfamilyName, UniqueFontIdentifier, FullFontName, and PostscriptName are fontName.
The new 'name' table records will be written with the Windows, UnicodeBMPUCS2, and English_UnitedStates settings.
fontName and fontNameLen must be specified in terms of ASCII chars.
Does not affect fontData's ownership.
31 {
32
33
35 if (fontData->
read(&sfntHeader,
sizeof(sfntHeader)) <
sizeof(sfntHeader)) {
36 return nullptr;
37 }
38
39
40 int tableIndex;
43 for (tableIndex = 0; tableIndex < numTables; ++tableIndex) {
44 if (fontData->
read(&tableEntry,
sizeof(tableEntry)) <
sizeof(tableEntry)) {
45 return nullptr;
46 }
48 break;
49 }
50 }
51 if (tableIndex == numTables) {
52 return nullptr;
53 }
54
56 return nullptr;
57 }
58
59
60 static constexpr std::array<SkOTTableName::Record::NameID::Predefined::Value, 5>
names{{
66 }};
67
68
69 static constexpr std::array<SkOTTableName::Record::EncodingID::Windows::Value, 2> encodings{{
72 }};
73
74
75
79 size_t nameTablePhysicalSize = (nameTableLogicalSize + 3) & ~3;
80
83
84
85 size_t originalDataSize = fontData->
getLength() - oldNameTablePhysicalSize;
86 size_t newDataSize = originalDataSize + nameTablePhysicalSize;
87
90
91 if (fontData->
read(
data, oldNameTableOffset) < oldNameTableOffset) {
92 return nullptr;
93 }
94 if (fontData->
skip(oldNameTablePhysicalSize) < oldNameTablePhysicalSize) {
95 return nullptr;
96 }
97 if (fontData->
read(
data + oldNameTableOffset, originalDataSize - oldNameTableOffset) < originalDataSize - oldNameTableOffset) {
98 return nullptr;
99 }
100
101
105 for (; currentEntry < endEntry; ++currentEntry) {
107 if (oldOffset > oldNameTableOffset) {
109 }
110
112 headTableEntry = currentEntry;
113 }
114 }
115
116
120
121
127
129 for (const auto& encoding : encodings) {
137 ++nameRecord;
138 }
139 }
140
142 for (
int i = 0;
i < fontNameLen; ++
i) {
144 }
145
146 unsigned char* logical =
data + originalDataSize + nameTableLogicalSize;
147 unsigned char* physical =
data + originalDataSize + nameTablePhysicalSize;
148 for (; logical < physical; ++logical) {
149 *logical = 0;
150 }
151
152
154
155
156 if (headTableEntry) {
158 if (headTableOffset +
sizeof(
SkOTTableHead) < originalDataSize) {
163 }
164 }
165
166 return rewrittenFontData.release();
167}
#define SkEndian_SwapBE16(n)
constexpr uint16_t SkToU16(S x)
constexpr uint32_t SkToU32(S x)
static sk_sp< SkData > MakeUninitialized(size_t length)
size_t getLength() const override=0
virtual size_t read(void *buffer, size_t size)=0
static const char *const names[]
DEF_SWITCHES_START aot vmservice shared library name
SK_OT_ULONG checksumAdjustment
static const SK_OT_ULONG TAG
static const uint32_t fontChecksum
enum SkOTTableName::Record::EncodingID::Windows::Value value
enum SkOTTableName::Record::LanguageID::Windows::Value value
enum SkOTTableName::Record::NameID::Predefined::Value value
struct SkOTTableName::Record::PlatformID platformID
union SkOTTableName::Record::NameID nameID
union SkOTTableName::Record::LanguageID languageID
union SkOTTableName::Record::EncodingID encodingID
static const SK_OT_USHORT format_0
SK_OT_USHORT stringOffset
static const SK_OT_ULONG TAG
static uint32_t CalcTableChecksum(SK_OT_ULONG *data, size_t length)
struct SkOTTableName::Record::EncodingID::Windows windows
struct SkOTTableName::Record::LanguageID::Windows windows
struct SkOTTableName::Record::NameID::Predefined predefined