OLD | NEW |
---|---|
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/fpdf_font/ttgsubtable.h" | 7 #include "core/fpdfapi/fpdf_font/ttgsubtable.h" |
8 | 8 |
9 #include <memory> | |
10 | |
11 #include "core/fxge/include/fx_freetype.h" | 9 #include "core/fxge/include/fx_freetype.h" |
12 #include "core/fxge/include/fx_ge.h" | 10 #include "core/fxge/include/fx_ge.h" |
13 #include "third_party/base/stl_util.h" | 11 #include "third_party/base/stl_util.h" |
14 | 12 |
15 CFX_GlyphMap::CFX_GlyphMap() {} | 13 CFX_GlyphMap::CFX_GlyphMap() {} |
16 | 14 |
17 CFX_GlyphMap::~CFX_GlyphMap() {} | 15 CFX_GlyphMap::~CFX_GlyphMap() {} |
18 | 16 |
19 extern "C" { | 17 extern "C" { |
20 static int _CompareInt(const void* p1, const void* p2) { | 18 static int _CompareInt(const void* p1, const void* p2) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 bool CFX_CTTGSUBTable::GetVerticalGlyph(uint32_t glyphnum, | 88 bool CFX_CTTGSUBTable::GetVerticalGlyph(uint32_t glyphnum, |
91 uint32_t* vglyphnum) { | 89 uint32_t* vglyphnum) { |
92 uint32_t tag[] = { | 90 uint32_t tag[] = { |
93 (uint8_t)'v' << 24 | (uint8_t)'r' << 16 | (uint8_t)'t' << 8 | | 91 (uint8_t)'v' << 24 | (uint8_t)'r' << 16 | (uint8_t)'t' << 8 | |
94 (uint8_t)'2', | 92 (uint8_t)'2', |
95 (uint8_t)'v' << 24 | (uint8_t)'e' << 16 | (uint8_t)'r' << 8 | | 93 (uint8_t)'v' << 24 | (uint8_t)'e' << 16 | (uint8_t)'r' << 8 | |
96 (uint8_t)'t', | 94 (uint8_t)'t', |
97 }; | 95 }; |
98 if (!m_bFeautureMapLoad) { | 96 if (!m_bFeautureMapLoad) { |
99 for (int i = 0; i < ScriptList.ScriptCount; i++) { | 97 for (int i = 0; i < ScriptList.ScriptCount; i++) { |
100 for (int j = 0; j < (ScriptList.ScriptRecord + i)->Script.LangSysCount; | 98 for (int j = 0; j < ScriptList.ScriptRecord[i].Script.LangSysCount; ++j) { |
101 ++j) { | 99 for (int k = 0; k < ScriptList.ScriptRecord[i] |
102 for (int k = 0; | 100 .Script.LangSysRecord[j] |
103 k < ((ScriptList.ScriptRecord + i)->Script.LangSysRecord + j) | 101 .LangSys.FeatureCount; |
104 ->LangSys.FeatureCount; | |
105 ++k) { | 102 ++k) { |
106 uint32_t index = | 103 uint32_t index = ScriptList.ScriptRecord[i] |
107 *(((ScriptList.ScriptRecord + i)->Script.LangSysRecord + j) | 104 .Script.LangSysRecord[j] |
108 ->LangSys.FeatureIndex + | 105 .LangSys.FeatureIndex[k]; |
Lei Zhang
2016/07/06 23:19:56
If we have a reference variable at each level of t
Wei Li
2016/07/07 00:03:35
Done.
| |
109 k); | |
110 if (FeatureList.FeatureRecord[index].FeatureTag == tag[0] || | 106 if (FeatureList.FeatureRecord[index].FeatureTag == tag[0] || |
111 FeatureList.FeatureRecord[index].FeatureTag == tag[1]) { | 107 FeatureList.FeatureRecord[index].FeatureTag == tag[1]) { |
112 if (!pdfium::ContainsKey(m_featureMap, index)) { | 108 if (!pdfium::ContainsKey(m_featureMap, index)) { |
113 m_featureMap[index] = index; | 109 m_featureMap[index] = index; |
114 } | 110 } |
115 } | 111 } |
116 } | 112 } |
117 } | 113 } |
118 } | 114 } |
119 if (m_featureMap.empty()) { | 115 if (m_featureMap.empty()) { |
(...skipping 10 matching lines...) Expand all Loading... | |
130 if (GetVerticalGlyphSub(glyphnum, vglyphnum, | 126 if (GetVerticalGlyphSub(glyphnum, vglyphnum, |
131 &FeatureList.FeatureRecord[pair.second].Feature)) { | 127 &FeatureList.FeatureRecord[pair.second].Feature)) { |
132 return true; | 128 return true; |
133 } | 129 } |
134 } | 130 } |
135 return false; | 131 return false; |
136 } | 132 } |
137 | 133 |
138 bool CFX_CTTGSUBTable::GetVerticalGlyphSub(uint32_t glyphnum, | 134 bool CFX_CTTGSUBTable::GetVerticalGlyphSub(uint32_t glyphnum, |
139 uint32_t* vglyphnum, | 135 uint32_t* vglyphnum, |
140 struct TFeature* Feature) const { | 136 TFeature* Feature) const { |
141 for (int i = 0; i < Feature->LookupCount; i++) { | 137 for (int i = 0; i < Feature->LookupCount; i++) { |
142 int index = Feature->LookupListIndex[i]; | 138 int index = Feature->LookupListIndex[i]; |
143 if (index < 0 || LookupList.LookupCount < index) { | 139 if (index < 0 || LookupList.LookupCount < index) { |
144 continue; | 140 continue; |
145 } | 141 } |
146 if (LookupList.Lookup[index].LookupType == 1) { | 142 if (LookupList.Lookup[index].LookupType == 1) { |
147 if (GetVerticalGlyphSub2(glyphnum, vglyphnum, | 143 if (GetVerticalGlyphSub2(glyphnum, vglyphnum, |
148 &LookupList.Lookup[index])) { | 144 &LookupList.Lookup[index])) { |
149 return true; | 145 return true; |
150 } | 146 } |
151 } | 147 } |
152 } | 148 } |
153 return false; | 149 return false; |
154 } | 150 } |
155 | 151 |
156 bool CFX_CTTGSUBTable::GetVerticalGlyphSub2(uint32_t glyphnum, | 152 bool CFX_CTTGSUBTable::GetVerticalGlyphSub2(uint32_t glyphnum, |
157 uint32_t* vglyphnum, | 153 uint32_t* vglyphnum, |
158 struct TLookup* Lookup) const { | 154 TLookup* Lookup) const { |
159 for (int i = 0; i < Lookup->SubTableCount; i++) { | 155 for (int i = 0; i < Lookup->SubTableCount; i++) { |
160 switch (Lookup->SubTable[i]->SubstFormat) { | 156 switch (Lookup->SubTable[i]->SubstFormat) { |
161 case 1: { | 157 case 1: { |
162 TSingleSubstFormat1* tbl1 = (TSingleSubstFormat1*)Lookup->SubTable[i]; | 158 TSingleSubstFormat1* tbl1 = (TSingleSubstFormat1*)Lookup->SubTable[i]; |
163 if (GetCoverageIndex(tbl1->Coverage, glyphnum) >= 0) { | 159 if (GetCoverageIndex(tbl1->Coverage.get(), glyphnum) >= 0) { |
164 *vglyphnum = glyphnum + tbl1->DeltaGlyphID; | 160 *vglyphnum = glyphnum + tbl1->DeltaGlyphID; |
165 return true; | 161 return true; |
166 } | 162 } |
167 break; | 163 break; |
168 } | 164 } |
169 case 2: { | 165 case 2: { |
170 TSingleSubstFormat2* tbl2 = (TSingleSubstFormat2*)Lookup->SubTable[i]; | 166 TSingleSubstFormat2* tbl2 = (TSingleSubstFormat2*)Lookup->SubTable[i]; |
171 int index = -1; | 167 int index = -1; |
172 index = GetCoverageIndex(tbl2->Coverage, glyphnum); | 168 index = GetCoverageIndex(tbl2->Coverage.get(), glyphnum); |
173 if (0 <= index && index < tbl2->GlyphCount) { | 169 if (0 <= index && index < tbl2->GlyphCount) { |
174 *vglyphnum = tbl2->Substitute[index]; | 170 *vglyphnum = tbl2->Substitute[index]; |
175 return true; | 171 return true; |
176 } | 172 } |
177 break; | 173 break; |
178 } | 174 } |
179 } | 175 } |
180 } | 176 } |
181 return false; | 177 return false; |
182 } | 178 } |
183 | 179 |
184 int CFX_CTTGSUBTable::GetCoverageIndex(struct TCoverageFormatBase* Coverage, | 180 int CFX_CTTGSUBTable::GetCoverageIndex(TCoverageFormatBase* Coverage, |
185 uint32_t g) const { | 181 uint32_t g) const { |
186 int i = 0; | 182 int i = 0; |
187 if (!Coverage) { | 183 if (!Coverage) { |
188 return -1; | 184 return -1; |
189 } | 185 } |
190 switch (Coverage->CoverageFormat) { | 186 switch (Coverage->CoverageFormat) { |
191 case 1: { | 187 case 1: { |
192 TCoverageFormat1* c1 = (TCoverageFormat1*)Coverage; | 188 TCoverageFormat1* c1 = (TCoverageFormat1*)Coverage; |
193 for (i = 0; i < c1->GlyphCount; i++) { | 189 for (i = 0; i < c1->GlyphCount; i++) { |
194 if ((uint32_t)c1->GlyphArray[i] == g) { | 190 if ((uint32_t)c1->GlyphArray[i] == g) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 | 241 |
246 bool CFX_CTTGSUBTable::Parse(FT_Bytes scriptlist, | 242 bool CFX_CTTGSUBTable::Parse(FT_Bytes scriptlist, |
247 FT_Bytes featurelist, | 243 FT_Bytes featurelist, |
248 FT_Bytes lookuplist) { | 244 FT_Bytes lookuplist) { |
249 ParseScriptList(scriptlist, &ScriptList); | 245 ParseScriptList(scriptlist, &ScriptList); |
250 ParseFeatureList(featurelist, &FeatureList); | 246 ParseFeatureList(featurelist, &FeatureList); |
251 ParseLookupList(lookuplist, &LookupList); | 247 ParseLookupList(lookuplist, &LookupList); |
252 return true; | 248 return true; |
253 } | 249 } |
254 | 250 |
255 void CFX_CTTGSUBTable::ParseScriptList(FT_Bytes raw, struct TScriptList* rec) { | 251 void CFX_CTTGSUBTable::ParseScriptList(FT_Bytes raw, TScriptList* rec) { |
256 int i; | 252 int i; |
257 FT_Bytes sp = raw; | 253 FT_Bytes sp = raw; |
258 rec->ScriptCount = GetUInt16(sp); | 254 rec->ScriptCount = GetUInt16(sp); |
259 if (rec->ScriptCount <= 0) { | 255 if (rec->ScriptCount <= 0) { |
260 return; | 256 return; |
261 } | 257 } |
262 rec->ScriptRecord = new struct TScriptRecord[rec->ScriptCount]; | 258 rec->ScriptRecord.reset(new TScriptRecord[rec->ScriptCount]); |
263 for (i = 0; i < rec->ScriptCount; i++) { | 259 for (i = 0; i < rec->ScriptCount; i++) { |
264 rec->ScriptRecord[i].ScriptTag = GetUInt32(sp); | 260 rec->ScriptRecord[i].ScriptTag = GetUInt32(sp); |
265 uint16_t offset = GetUInt16(sp); | 261 uint16_t offset = GetUInt16(sp); |
266 ParseScript(&raw[offset], &rec->ScriptRecord[i].Script); | 262 ParseScript(&raw[offset], &rec->ScriptRecord[i].Script); |
267 } | 263 } |
268 } | 264 } |
269 | 265 |
270 void CFX_CTTGSUBTable::ParseScript(FT_Bytes raw, struct TScript* rec) { | 266 void CFX_CTTGSUBTable::ParseScript(FT_Bytes raw, TScript* rec) { |
271 int i; | 267 int i; |
272 FT_Bytes sp = raw; | 268 FT_Bytes sp = raw; |
273 rec->DefaultLangSys = GetUInt16(sp); | 269 rec->DefaultLangSys = GetUInt16(sp); |
274 rec->LangSysCount = GetUInt16(sp); | 270 rec->LangSysCount = GetUInt16(sp); |
275 if (rec->LangSysCount <= 0) { | 271 if (rec->LangSysCount <= 0) { |
276 return; | 272 return; |
277 } | 273 } |
278 rec->LangSysRecord = new struct TLangSysRecord[rec->LangSysCount]; | 274 rec->LangSysRecord.reset(new TLangSysRecord[rec->LangSysCount]); |
279 for (i = 0; i < rec->LangSysCount; i++) { | 275 for (i = 0; i < rec->LangSysCount; i++) { |
280 rec->LangSysRecord[i].LangSysTag = GetUInt32(sp); | 276 rec->LangSysRecord[i].LangSysTag = GetUInt32(sp); |
281 uint16_t offset = GetUInt16(sp); | 277 uint16_t offset = GetUInt16(sp); |
282 ParseLangSys(&raw[offset], &rec->LangSysRecord[i].LangSys); | 278 ParseLangSys(&raw[offset], &rec->LangSysRecord[i].LangSys); |
283 } | 279 } |
284 } | 280 } |
285 | 281 |
286 void CFX_CTTGSUBTable::ParseLangSys(FT_Bytes raw, struct TLangSys* rec) { | 282 void CFX_CTTGSUBTable::ParseLangSys(FT_Bytes raw, TLangSys* rec) { |
287 FT_Bytes sp = raw; | 283 FT_Bytes sp = raw; |
288 rec->LookupOrder = GetUInt16(sp); | 284 rec->LookupOrder = GetUInt16(sp); |
289 rec->ReqFeatureIndex = GetUInt16(sp); | 285 rec->ReqFeatureIndex = GetUInt16(sp); |
290 rec->FeatureCount = GetUInt16(sp); | 286 rec->FeatureCount = GetUInt16(sp); |
291 if (rec->FeatureCount <= 0) { | 287 if (rec->FeatureCount <= 0) { |
292 return; | 288 return; |
293 } | 289 } |
294 rec->FeatureIndex = new uint16_t[rec->FeatureCount]; | 290 rec->FeatureIndex.reset(new uint16_t[rec->FeatureCount]); |
295 FXSYS_memset(rec->FeatureIndex, 0, sizeof(uint16_t) * rec->FeatureCount); | 291 FXSYS_memset(rec->FeatureIndex.get(), 0, |
292 sizeof(uint16_t) * rec->FeatureCount); | |
296 for (int i = 0; i < rec->FeatureCount; ++i) { | 293 for (int i = 0; i < rec->FeatureCount; ++i) { |
297 rec->FeatureIndex[i] = GetUInt16(sp); | 294 rec->FeatureIndex[i] = GetUInt16(sp); |
298 } | 295 } |
299 } | 296 } |
300 | 297 |
301 void CFX_CTTGSUBTable::ParseFeatureList(FT_Bytes raw, TFeatureList* rec) { | 298 void CFX_CTTGSUBTable::ParseFeatureList(FT_Bytes raw, TFeatureList* rec) { |
302 int i; | 299 int i; |
303 FT_Bytes sp = raw; | 300 FT_Bytes sp = raw; |
304 rec->FeatureCount = GetUInt16(sp); | 301 rec->FeatureCount = GetUInt16(sp); |
305 if (rec->FeatureCount <= 0) { | 302 if (rec->FeatureCount <= 0) { |
306 return; | 303 return; |
307 } | 304 } |
308 rec->FeatureRecord = new struct TFeatureRecord[rec->FeatureCount]; | 305 rec->FeatureRecord.reset(new TFeatureRecord[rec->FeatureCount]); |
309 for (i = 0; i < rec->FeatureCount; i++) { | 306 for (i = 0; i < rec->FeatureCount; i++) { |
310 rec->FeatureRecord[i].FeatureTag = GetUInt32(sp); | 307 rec->FeatureRecord[i].FeatureTag = GetUInt32(sp); |
311 uint16_t offset = GetUInt16(sp); | 308 uint16_t offset = GetUInt16(sp); |
312 ParseFeature(&raw[offset], &rec->FeatureRecord[i].Feature); | 309 ParseFeature(&raw[offset], &rec->FeatureRecord[i].Feature); |
313 } | 310 } |
314 } | 311 } |
315 | 312 |
316 void CFX_CTTGSUBTable::ParseFeature(FT_Bytes raw, TFeature* rec) { | 313 void CFX_CTTGSUBTable::ParseFeature(FT_Bytes raw, TFeature* rec) { |
317 int i; | 314 int i; |
318 FT_Bytes sp = raw; | 315 FT_Bytes sp = raw; |
319 rec->FeatureParams = GetUInt16(sp); | 316 rec->FeatureParams = GetUInt16(sp); |
320 rec->LookupCount = GetUInt16(sp); | 317 rec->LookupCount = GetUInt16(sp); |
321 if (rec->LookupCount <= 0) { | 318 if (rec->LookupCount <= 0) { |
322 return; | 319 return; |
323 } | 320 } |
324 rec->LookupListIndex = new uint16_t[rec->LookupCount]; | 321 rec->LookupListIndex.reset(new uint16_t[rec->LookupCount]); |
325 for (i = 0; i < rec->LookupCount; i++) { | 322 for (i = 0; i < rec->LookupCount; i++) { |
326 rec->LookupListIndex[i] = GetUInt16(sp); | 323 rec->LookupListIndex[i] = GetUInt16(sp); |
327 } | 324 } |
328 } | 325 } |
329 | 326 |
330 void CFX_CTTGSUBTable::ParseLookupList(FT_Bytes raw, TLookupList* rec) { | 327 void CFX_CTTGSUBTable::ParseLookupList(FT_Bytes raw, TLookupList* rec) { |
331 int i; | 328 int i; |
332 FT_Bytes sp = raw; | 329 FT_Bytes sp = raw; |
333 rec->LookupCount = GetUInt16(sp); | 330 rec->LookupCount = GetUInt16(sp); |
334 if (rec->LookupCount <= 0) { | 331 if (rec->LookupCount <= 0) { |
335 return; | 332 return; |
336 } | 333 } |
337 rec->Lookup = new struct TLookup[rec->LookupCount]; | 334 rec->Lookup.reset(new TLookup[rec->LookupCount]); |
338 for (i = 0; i < rec->LookupCount; i++) { | 335 for (i = 0; i < rec->LookupCount; i++) { |
339 uint16_t offset = GetUInt16(sp); | 336 uint16_t offset = GetUInt16(sp); |
340 ParseLookup(&raw[offset], &rec->Lookup[i]); | 337 ParseLookup(&raw[offset], &rec->Lookup[i]); |
341 } | 338 } |
342 } | 339 } |
343 | 340 |
344 void CFX_CTTGSUBTable::ParseLookup(FT_Bytes raw, TLookup* rec) { | 341 void CFX_CTTGSUBTable::ParseLookup(FT_Bytes raw, TLookup* rec) { |
345 int i; | 342 int i; |
346 FT_Bytes sp = raw; | 343 FT_Bytes sp = raw; |
347 rec->LookupType = GetUInt16(sp); | 344 rec->LookupType = GetUInt16(sp); |
348 rec->LookupFlag = GetUInt16(sp); | 345 rec->LookupFlag = GetUInt16(sp); |
349 rec->SubTableCount = GetUInt16(sp); | 346 rec->SubTableCount = GetUInt16(sp); |
350 if (rec->SubTableCount <= 0) { | 347 if (rec->SubTableCount <= 0) { |
351 return; | 348 return; |
352 } | 349 } |
353 rec->SubTable = new struct TSubTableBase*[rec->SubTableCount]; | 350 rec->SubTable.reset(new TSubTableBase*[rec->SubTableCount]); |
354 for (i = 0; i < rec->SubTableCount; i++) { | 351 for (i = 0; i < rec->SubTableCount; i++) { |
355 rec->SubTable[i] = nullptr; | 352 rec->SubTable[i] = nullptr; |
356 } | 353 } |
357 if (rec->LookupType != 1) { | 354 if (rec->LookupType != 1) { |
358 return; | 355 return; |
359 } | 356 } |
360 for (i = 0; i < rec->SubTableCount; i++) { | 357 for (i = 0; i < rec->SubTableCount; i++) { |
361 uint16_t offset = GetUInt16(sp); | 358 uint16_t offset = GetUInt16(sp); |
362 ParseSingleSubst(&raw[offset], &rec->SubTable[i]); | 359 ParseSingleSubst(&raw[offset], &rec->SubTable[i]); |
363 } | 360 } |
364 } | 361 } |
365 | 362 |
366 void CFX_CTTGSUBTable::ParseCoverage(FT_Bytes raw, TCoverageFormatBase** rec) { | 363 CFX_CTTGSUBTable::TCoverageFormatBase* CFX_CTTGSUBTable::ParseCoverage( |
364 FT_Bytes raw) { | |
367 FT_Bytes sp = raw; | 365 FT_Bytes sp = raw; |
368 uint16_t Format = GetUInt16(sp); | 366 uint16_t format = GetUInt16(sp); |
369 switch (Format) { | 367 TCoverageFormatBase* rec = nullptr; |
370 case 1: | 368 if (format == 1) { |
371 *rec = new TCoverageFormat1(); | 369 rec = new TCoverageFormat1(); |
372 ParseCoverageFormat1(raw, (TCoverageFormat1*)*rec); | 370 ParseCoverageFormat1(raw, static_cast<TCoverageFormat1*>(rec)); |
373 break; | 371 } else if (format == 2) { |
374 case 2: | 372 rec = new TCoverageFormat2(); |
375 *rec = new TCoverageFormat2(); | 373 ParseCoverageFormat2(raw, static_cast<TCoverageFormat2*>(rec)); |
376 ParseCoverageFormat2(raw, (TCoverageFormat2*)*rec); | |
377 break; | |
378 } | 374 } |
375 return rec; | |
379 } | 376 } |
380 | 377 |
381 void CFX_CTTGSUBTable::ParseCoverageFormat1(FT_Bytes raw, | 378 void CFX_CTTGSUBTable::ParseCoverageFormat1(FT_Bytes raw, |
382 TCoverageFormat1* rec) { | 379 TCoverageFormat1* rec) { |
383 int i; | 380 int i; |
384 FT_Bytes sp = raw; | 381 FT_Bytes sp = raw; |
385 GetUInt16(sp); | 382 GetUInt16(sp); |
386 rec->GlyphCount = GetUInt16(sp); | 383 rec->GlyphCount = GetUInt16(sp); |
387 if (rec->GlyphCount <= 0) { | 384 if (rec->GlyphCount <= 0) { |
388 return; | 385 return; |
389 } | 386 } |
390 rec->GlyphArray = new uint16_t[rec->GlyphCount]; | 387 rec->GlyphArray.reset(new uint16_t[rec->GlyphCount]); |
391 for (i = 0; i < rec->GlyphCount; i++) { | 388 for (i = 0; i < rec->GlyphCount; i++) { |
392 rec->GlyphArray[i] = GetUInt16(sp); | 389 rec->GlyphArray[i] = GetUInt16(sp); |
393 } | 390 } |
394 } | 391 } |
395 | 392 |
396 void CFX_CTTGSUBTable::ParseCoverageFormat2(FT_Bytes raw, | 393 void CFX_CTTGSUBTable::ParseCoverageFormat2(FT_Bytes raw, |
397 TCoverageFormat2* rec) { | 394 TCoverageFormat2* rec) { |
398 int i; | 395 int i; |
399 FT_Bytes sp = raw; | 396 FT_Bytes sp = raw; |
400 GetUInt16(sp); | 397 GetUInt16(sp); |
401 rec->RangeCount = GetUInt16(sp); | 398 rec->RangeCount = GetUInt16(sp); |
402 if (rec->RangeCount <= 0) { | 399 if (rec->RangeCount <= 0) { |
403 return; | 400 return; |
404 } | 401 } |
405 rec->RangeRecord = new TRangeRecord[rec->RangeCount]; | 402 rec->RangeRecord.reset(new TRangeRecord[rec->RangeCount]); |
406 for (i = 0; i < rec->RangeCount; i++) { | 403 for (i = 0; i < rec->RangeCount; i++) { |
407 rec->RangeRecord[i].Start = GetUInt16(sp); | 404 rec->RangeRecord[i].Start = GetUInt16(sp); |
408 rec->RangeRecord[i].End = GetUInt16(sp); | 405 rec->RangeRecord[i].End = GetUInt16(sp); |
409 rec->RangeRecord[i].StartCoverageIndex = GetUInt16(sp); | 406 rec->RangeRecord[i].StartCoverageIndex = GetUInt16(sp); |
410 } | 407 } |
411 } | 408 } |
412 | 409 |
413 void CFX_CTTGSUBTable::ParseSingleSubst(FT_Bytes raw, TSubTableBase** rec) { | 410 void CFX_CTTGSUBTable::ParseSingleSubst(FT_Bytes raw, TSubTableBase** rec) { |
414 FT_Bytes sp = raw; | 411 FT_Bytes sp = raw; |
415 uint16_t Format = GetUInt16(sp); | 412 uint16_t Format = GetUInt16(sp); |
416 switch (Format) { | 413 switch (Format) { |
417 case 1: | 414 case 1: |
418 *rec = new TSingleSubstFormat1(); | 415 *rec = new TSingleSubstFormat1(); |
419 ParseSingleSubstFormat1(raw, (TSingleSubstFormat1*)*rec); | 416 ParseSingleSubstFormat1(raw, (TSingleSubstFormat1*)*rec); |
420 break; | 417 break; |
421 case 2: | 418 case 2: |
422 *rec = new TSingleSubstFormat2(); | 419 *rec = new TSingleSubstFormat2(); |
423 ParseSingleSubstFormat2(raw, (TSingleSubstFormat2*)*rec); | 420 ParseSingleSubstFormat2(raw, (TSingleSubstFormat2*)*rec); |
424 break; | 421 break; |
425 } | 422 } |
426 } | 423 } |
427 | 424 |
428 void CFX_CTTGSUBTable::ParseSingleSubstFormat1(FT_Bytes raw, | 425 void CFX_CTTGSUBTable::ParseSingleSubstFormat1(FT_Bytes raw, |
429 TSingleSubstFormat1* rec) { | 426 TSingleSubstFormat1* rec) { |
430 FT_Bytes sp = raw; | 427 FT_Bytes sp = raw; |
431 GetUInt16(sp); | 428 GetUInt16(sp); |
432 uint16_t offset = GetUInt16(sp); | 429 uint16_t offset = GetUInt16(sp); |
433 ParseCoverage(&raw[offset], &rec->Coverage); | 430 rec->Coverage.reset(ParseCoverage(&raw[offset])); |
434 rec->DeltaGlyphID = GetInt16(sp); | 431 rec->DeltaGlyphID = GetInt16(sp); |
435 } | 432 } |
436 | 433 |
437 void CFX_CTTGSUBTable::ParseSingleSubstFormat2(FT_Bytes raw, | 434 void CFX_CTTGSUBTable::ParseSingleSubstFormat2(FT_Bytes raw, |
438 TSingleSubstFormat2* rec) { | 435 TSingleSubstFormat2* rec) { |
439 int i; | 436 int i; |
440 FT_Bytes sp = raw; | 437 FT_Bytes sp = raw; |
441 GetUInt16(sp); | 438 GetUInt16(sp); |
442 uint16_t offset = GetUInt16(sp); | 439 uint16_t offset = GetUInt16(sp); |
443 ParseCoverage(&raw[offset], &rec->Coverage); | 440 rec->Coverage.reset(ParseCoverage(&raw[offset])); |
444 rec->GlyphCount = GetUInt16(sp); | 441 rec->GlyphCount = GetUInt16(sp); |
445 if (rec->GlyphCount <= 0) { | 442 if (rec->GlyphCount <= 0) { |
446 return; | 443 return; |
447 } | 444 } |
448 rec->Substitute = new uint16_t[rec->GlyphCount]; | 445 rec->Substitute.reset(new uint16_t[rec->GlyphCount]); |
449 for (i = 0; i < rec->GlyphCount; i++) { | 446 for (i = 0; i < rec->GlyphCount; i++) { |
450 rec->Substitute[i] = GetUInt16(sp); | 447 rec->Substitute[i] = GetUInt16(sp); |
451 } | 448 } |
452 } | 449 } |
453 | 450 |
454 CFX_CTTGSUBTable::TCoverageFormat1::TCoverageFormat1() | 451 CFX_CTTGSUBTable::TCoverageFormat1::TCoverageFormat1() |
455 : GlyphCount(0), GlyphArray(nullptr) { | 452 : TCoverageFormatBase(1), GlyphCount(0) {} |
456 CoverageFormat = 1; | |
457 } | |
458 | 453 |
459 CFX_CTTGSUBTable::TCoverageFormat1::~TCoverageFormat1() { | 454 CFX_CTTGSUBTable::TCoverageFormat1::~TCoverageFormat1() {} |
460 delete[] GlyphArray; | |
461 } | |
462 | 455 |
463 CFX_CTTGSUBTable::TRangeRecord::TRangeRecord() | 456 CFX_CTTGSUBTable::TRangeRecord::TRangeRecord() |
464 : Start(0), End(0), StartCoverageIndex(0) {} | 457 : Start(0), End(0), StartCoverageIndex(0) {} |
465 | 458 |
466 CFX_CTTGSUBTable::TCoverageFormat2::TCoverageFormat2() | 459 CFX_CTTGSUBTable::TCoverageFormat2::TCoverageFormat2() |
467 : RangeCount(0), RangeRecord(nullptr) { | 460 : TCoverageFormatBase(2), RangeCount(0) {} |
468 CoverageFormat = 2; | |
469 } | |
470 | 461 |
471 CFX_CTTGSUBTable::TCoverageFormat2::~TCoverageFormat2() { | 462 CFX_CTTGSUBTable::TCoverageFormat2::~TCoverageFormat2() {} |
472 delete[] RangeRecord; | |
473 } | |
474 | |
475 CFX_CTTGSUBTable::TClassDefFormat1::TClassDefFormat1() | |
476 : StartGlyph(0), GlyphCount(0), ClassValueArray(nullptr) { | |
477 ClassFormat = 1; | |
478 } | |
479 | |
480 CFX_CTTGSUBTable::TClassDefFormat1::~TClassDefFormat1() { | |
481 delete[] ClassValueArray; | |
482 } | |
483 | |
484 CFX_CTTGSUBTable::TClassDefFormat2::TClassDefFormat2() | |
485 : ClassRangeCount(0), ClassRangeRecord(nullptr) { | |
486 ClassFormat = 2; | |
487 } | |
488 | |
489 CFX_CTTGSUBTable::TClassDefFormat2::~TClassDefFormat2() { | |
490 delete[] ClassRangeRecord; | |
491 } | |
492 | 463 |
493 CFX_CTTGSUBTable::TSingleSubstFormat1::TSingleSubstFormat1() | 464 CFX_CTTGSUBTable::TSingleSubstFormat1::TSingleSubstFormat1() |
494 : Coverage(nullptr), DeltaGlyphID(0) { | 465 : TSubTableBase(1), DeltaGlyphID(0) {} |
495 SubstFormat = 1; | |
496 } | |
497 | 466 |
498 CFX_CTTGSUBTable::TSingleSubstFormat1::~TSingleSubstFormat1() { | 467 CFX_CTTGSUBTable::TSingleSubstFormat1::~TSingleSubstFormat1() {} |
499 delete Coverage; | |
500 } | |
501 | 468 |
502 CFX_CTTGSUBTable::TSingleSubstFormat2::TSingleSubstFormat2() | 469 CFX_CTTGSUBTable::TSingleSubstFormat2::TSingleSubstFormat2() |
503 : Coverage(nullptr), GlyphCount(0), Substitute(nullptr) { | 470 : TSubTableBase(2), GlyphCount(0) {} |
504 SubstFormat = 2; | |
505 } | |
506 | 471 |
507 CFX_CTTGSUBTable::TSingleSubstFormat2::~TSingleSubstFormat2() { | 472 CFX_CTTGSUBTable::TSingleSubstFormat2::~TSingleSubstFormat2() {} |
508 delete Coverage; | |
509 delete[] Substitute; | |
510 } | |
511 | 473 |
512 CFX_CTTGSUBTable::TLookup::TLookup() | 474 CFX_CTTGSUBTable::TLookup::TLookup() |
513 : LookupType(0), LookupFlag(0), SubTableCount(0), SubTable(nullptr) {} | 475 : LookupType(0), LookupFlag(0), SubTableCount(0) {} |
514 | 476 |
515 CFX_CTTGSUBTable::TLookup::~TLookup() { | 477 CFX_CTTGSUBTable::TLookup::~TLookup() { |
516 if (SubTable) { | 478 if (SubTable) { |
517 for (int i = 0; i < SubTableCount; ++i) | 479 for (int i = 0; i < SubTableCount; ++i) |
518 delete SubTable[i]; | 480 delete SubTable[i]; |
519 delete[] SubTable; | |
520 } | 481 } |
521 } | 482 } |
483 | |
484 CFX_CTTGSUBTable::TScript::TScript() : DefaultLangSys(0), LangSysCount(0) {} | |
485 | |
486 CFX_CTTGSUBTable::TScript::~TScript() {} | |
487 | |
488 CFX_CTTGSUBTable::TScriptList::TScriptList() : ScriptCount(0) {} | |
489 | |
490 CFX_CTTGSUBTable::TScriptList::~TScriptList() {} | |
491 | |
492 CFX_CTTGSUBTable::TFeature::TFeature() : FeatureParams(0), LookupCount(0) {} | |
493 | |
494 CFX_CTTGSUBTable::TFeature::~TFeature() {} | |
495 | |
496 CFX_CTTGSUBTable::TFeatureList::TFeatureList() : FeatureCount(0) {} | |
497 | |
498 CFX_CTTGSUBTable::TFeatureList::~TFeatureList() {} | |
499 | |
500 CFX_CTTGSUBTable::TLookupList::TLookupList() : LookupCount(0) {} | |
501 | |
502 CFX_CTTGSUBTable::TLookupList::~TLookupList() {} | |
503 | |
504 CFX_CTTGSUBTable::TLangSys::TLangSys() | |
505 : LookupOrder(0), ReqFeatureIndex(0), FeatureCount(0) {} | |
506 | |
507 CFX_CTTGSUBTable::TLangSys::~TLangSys() {} | |
OLD | NEW |