Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: core/src/fpdfapi/fpdf_font/ttgsubtable.cpp

Issue 453133004: clang-format all code (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "../../../include/fxge/fx_ge.h" 7 #include "../../../include/fxge/fx_ge.h"
8 #include "../../../include/fxge/fx_freetype.h" 8 #include "../../../include/fxge/fx_freetype.h"
9 #include "ttgsubtable.h" 9 #include "ttgsubtable.h"
10 CFX_GlyphMap::CFX_GlyphMap() 10 CFX_GlyphMap::CFX_GlyphMap() {
11 { 11 }
12 } 12 CFX_GlyphMap::~CFX_GlyphMap() {
13 CFX_GlyphMap::~CFX_GlyphMap()
14 {
15 } 13 }
16 extern "C" { 14 extern "C" {
17 static int _CompareInt(const void* p1, const void* p2) 15 static int _CompareInt(const void* p1, const void* p2) {
18 { 16 return (*(FX_DWORD*)p1) - (*(FX_DWORD*)p2);
19 return (*(FX_DWORD*)p1) - (*(FX_DWORD*)p2); 17 }
20 }
21 }; 18 };
22 struct _IntPair { 19 struct _IntPair {
23 FX_INT32 key; 20 FX_INT32 key;
24 FX_INT32 value; 21 FX_INT32 value;
25 }; 22 };
26 void CFX_GlyphMap::SetAt(int key, int value) 23 void CFX_GlyphMap::SetAt(int key, int value) {
27 { 24 FX_DWORD count = m_Buffer.GetSize() / sizeof(_IntPair);
28 FX_DWORD count = m_Buffer.GetSize() / sizeof(_IntPair); 25 _IntPair* buf = (_IntPair*)m_Buffer.GetBuffer();
29 _IntPair* buf = (_IntPair*)m_Buffer.GetBuffer(); 26 _IntPair pair = { key, value };
30 _IntPair pair = {key, value}; 27 if (count == 0 || key > buf[count - 1].key) {
31 if (count == 0 || key > buf[count - 1].key) { 28 m_Buffer.AppendBlock(&pair, sizeof(_IntPair));
32 m_Buffer.AppendBlock(&pair, sizeof(_IntPair)); 29 return;
33 return; 30 }
34 } 31 int low = 0, high = count - 1;
35 int low = 0, high = count - 1; 32 while (low <= high) {
36 while (low <= high) { 33 int mid = (low + high) / 2;
37 int mid = (low + high) / 2; 34 if (buf[mid].key < key) {
38 if (buf[mid].key < key) { 35 low = mid + 1;
39 low = mid + 1; 36 } else if (buf[mid].key > key) {
40 } else if (buf[mid].key > key) { 37 high = mid - 1;
41 high = mid - 1; 38 } else {
42 } else { 39 buf[mid].value = value;
43 buf[mid].value = value; 40 return;
44 return; 41 }
45 } 42 }
46 } 43 m_Buffer.InsertBlock(low * sizeof(_IntPair), &pair, sizeof(_IntPair));
47 m_Buffer.InsertBlock(low * sizeof(_IntPair), &pair, sizeof(_IntPair)); 44 }
48 } 45 FX_BOOL CFX_GlyphMap::Lookup(int key, int& value) {
49 FX_BOOL CFX_GlyphMap::Lookup(int key, int &value) 46 FX_LPVOID pResult = FXSYS_bsearch(&key,
50 { 47 m_Buffer.GetBuffer(),
51 FX_LPVOID pResult = FXSYS_bsearch(&key, m_Buffer.GetBuffer(), m_Buffer.GetSi ze() / sizeof(_IntPair), 48 m_Buffer.GetSize() / sizeof(_IntPair),
52 sizeof(_IntPair), _CompareInt); 49 sizeof(_IntPair),
53 if (pResult == NULL) { 50 _CompareInt);
54 return FALSE; 51 if (pResult == NULL) {
55 } 52 return FALSE;
56 value = ((FX_DWORD*)pResult)[1]; 53 }
57 return TRUE; 54 value = ((FX_DWORD*)pResult)[1];
58 } 55 return TRUE;
59 bool CFX_CTTGSUBTable::LoadGSUBTable(FT_Bytes gsub) 56 }
60 { 57 bool CFX_CTTGSUBTable::LoadGSUBTable(FT_Bytes gsub) {
61 header.Version = gsub[0] << 24 | gsub[1] << 16 | gsub[2] << 8 | gsub[3]; 58 header.Version = gsub[0] << 24 | gsub[1] << 16 | gsub[2] << 8 | gsub[3];
62 if(header.Version != 0x00010000) { 59 if (header.Version != 0x00010000) {
63 return false; 60 return false;
64 } 61 }
65 header.ScriptList = gsub[4] << 8 | gsub[5]; 62 header.ScriptList = gsub[4] << 8 | gsub[5];
66 header.FeatureList = gsub[6] << 8 | gsub[7]; 63 header.FeatureList = gsub[6] << 8 | gsub[7];
67 header.LookupList = gsub[8] << 8 | gsub[9]; 64 header.LookupList = gsub[8] << 8 | gsub[9];
68 return Parse( 65 return Parse(&gsub[header.ScriptList],
69 &gsub[header.ScriptList],
70 &gsub[header.FeatureList], 66 &gsub[header.FeatureList],
71 &gsub[header.LookupList]); 67 &gsub[header.LookupList]);
72 } 68 }
73 bool CFX_CTTGSUBTable::GetVerticalGlyph(TT_uint32_t glyphnum, TT_uint32_t *vglyp hnum) 69 bool CFX_CTTGSUBTable::GetVerticalGlyph(TT_uint32_t glyphnum,
74 { 70 TT_uint32_t* vglyphnum) {
75 TT_uint32_t tag[] = { 71 TT_uint32_t tag[] = {
76 (TT_uint8_t)'v' << 24 | 72 (TT_uint8_t)'v' << 24 | (TT_uint8_t)'r' << 16 | (TT_uint8_t)'t' << 8 |
77 (TT_uint8_t)'r' << 16 |
78 (TT_uint8_t)'t' << 8 |
79 (TT_uint8_t)'2', 73 (TT_uint8_t)'2',
80 (TT_uint8_t)'v' << 24 | 74 (TT_uint8_t)'v' << 24 | (TT_uint8_t)'e' << 16 | (TT_uint8_t)'r' << 8 |
81 (TT_uint8_t)'e' << 16 |
82 (TT_uint8_t)'r' << 8 |
83 (TT_uint8_t)'t', 75 (TT_uint8_t)'t',
84 }; 76 };
85 if (!m_bFeautureMapLoad) { 77 if (!m_bFeautureMapLoad) {
86 for (int i = 0; i < ScriptList.ScriptCount; i++) { 78 for (int i = 0; i < ScriptList.ScriptCount; i++) {
87 for (int j = 0; j <»(ScriptList.ScriptRecord + i)->Script.LangSysCou nt; ++j) { 79 for (int j = 0; j < (ScriptList.ScriptRecord + i)->Script.LangSysCount;
88 for (int k = 0; k < ((ScriptList.ScriptRecord + i)->Script.LangS ysRecord + j)->LangSys.FeatureCount; ++k) { 80 ++j) {
89 FX_DWORD index = *(((ScriptList.ScriptRecord + i)->Script.La ngSysRecord + j)->LangSys.FeatureIndex + k); 81 for (int k = 0;
90 if (FeatureList.FeatureRecord[index].FeatureTag == tag[0] || FeatureList.FeatureRecord[index].FeatureTag == tag[1]) { 82 k < ((ScriptList.ScriptRecord + i)->Script.LangSysRecord + j)
91 FX_DWORD value; 83 ->LangSys.FeatureCount;
92 if (!m_featureMap.Lookup(index, value)) { 84 ++k) {
93 m_featureMap.SetAt(index, index); 85 FX_DWORD index =
94 } 86 *(((ScriptList.ScriptRecord + i)->Script.LangSysRecord + j)
95 } 87 ->LangSys.FeatureIndex +
96 } 88 k);
89 if (FeatureList.FeatureRecord[index].FeatureTag == tag[0] ||
90 FeatureList.FeatureRecord[index].FeatureTag == tag[1]) {
91 FX_DWORD value;
92 if (!m_featureMap.Lookup(index, value)) {
93 m_featureMap.SetAt(index, index);
97 } 94 }
98 } 95 }
99 if (!m_featureMap.GetStartPosition()) { 96 }
100 for (int i = 0; i < FeatureList.FeatureCount; i ++) { 97 }
101 if (FeatureList.FeatureRecord[i].FeatureTag == tag[0] || Feature List.FeatureRecord[i].FeatureTag == tag[1]) { 98 }
102 FX_DWORD value; 99 if (!m_featureMap.GetStartPosition()) {
103 if (!m_featureMap.Lookup(i, value)) { 100 for (int i = 0; i < FeatureList.FeatureCount; i++) {
104 m_featureMap.SetAt(i, i); 101 if (FeatureList.FeatureRecord[i].FeatureTag == tag[0] ||
105 } 102 FeatureList.FeatureRecord[i].FeatureTag == tag[1]) {
106 } 103 FX_DWORD value;
107 } 104 if (!m_featureMap.Lookup(i, value)) {
108 } 105 m_featureMap.SetAt(i, i);
109 m_bFeautureMapLoad = TRUE; 106 }
110 } 107 }
111 FX_POSITION pos = m_featureMap.GetStartPosition(); 108 }
112 while (pos) { 109 }
113 FX_DWORD index, value; 110 m_bFeautureMapLoad = TRUE;
114 m_featureMap.GetNextAssoc(pos, index, value); 111 }
115 if(GetVerticalGlyphSub(glyphnum, vglyphnum,» &FeatureList.FeatureReco rd[value].Feature)) { 112 FX_POSITION pos = m_featureMap.GetStartPosition();
116 return true; 113 while (pos) {
117 } 114 FX_DWORD index, value;
118 } 115 m_featureMap.GetNextAssoc(pos, index, value);
119 return false; 116 if (GetVerticalGlyphSub(
120 } 117 glyphnum, vglyphnum, &FeatureList.FeatureRecord[value].Feature)) {
121 bool CFX_CTTGSUBTable::GetVerticalGlyphSub( 118 return true;
122 TT_uint32_t glyphnum, 119 }
123 TT_uint32_t *vglyphnum, 120 }
124 struct TFeature *Feature) 121 return false;
125 { 122 }
126 for(int i = 0; i < Feature->LookupCount; i++) { 123 bool CFX_CTTGSUBTable::GetVerticalGlyphSub(TT_uint32_t glyphnum,
127 int index = Feature->LookupListIndex[i]; 124 TT_uint32_t* vglyphnum,
128 if(index < 0 || LookupList.LookupCount < index) { 125 struct TFeature* Feature) {
129 continue; 126 for (int i = 0; i < Feature->LookupCount; i++) {
130 } 127 int index = Feature->LookupListIndex[i];
131 if(LookupList.Lookup[index].LookupType == 1) { 128 if (index < 0 || LookupList.LookupCount < index) {
132 if(GetVerticalGlyphSub2( 129 continue;
133 glyphnum, 130 }
134 vglyphnum, 131 if (LookupList.Lookup[index].LookupType == 1) {
135 &LookupList.Lookup[index])) { 132 if (GetVerticalGlyphSub2(
136 return true; 133 glyphnum, vglyphnum, &LookupList.Lookup[index])) {
137 } 134 return true;
138 } 135 }
139 } 136 }
140 return false; 137 }
141 } 138 return false;
142 bool CFX_CTTGSUBTable::GetVerticalGlyphSub2( 139 }
143 TT_uint32_t glyphnum, 140 bool CFX_CTTGSUBTable::GetVerticalGlyphSub2(TT_uint32_t glyphnum,
144 TT_uint32_t *vglyphnum, 141 TT_uint32_t* vglyphnum,
145 struct TLookup *Lookup) 142 struct TLookup* Lookup) {
146 { 143 for (int i = 0; i < Lookup->SubTableCount; i++) {
147 for(int i = 0; i < Lookup->SubTableCount; i++) { 144 switch (Lookup->SubTable[i]->SubstFormat) {
148 switch(Lookup->SubTable[i]->SubstFormat) { 145 case 1: {
149 case 1: { 146 TSingleSubstFormat1* tbl1 = (TSingleSubstFormat1*)Lookup->SubTable[i];
150 TSingleSubstFormat1 *tbl1 = (TSingleSubstFormat1*)Lookup->Su bTable[i]; 147 if (GetCoverageIndex(tbl1->Coverage, glyphnum) >= 0) {
151 if(GetCoverageIndex(tbl1->Coverage, glyphnum) >= 0) { 148 *vglyphnum = glyphnum + tbl1->DeltaGlyphID;
152 *vglyphnum = glyphnum + tbl1->DeltaGlyphID; 149 return true;
153 return true; 150 }
154 } 151 break;
155 break; 152 }
156 } 153 case 2: {
157 case 2: { 154 TSingleSubstFormat2* tbl2 = (TSingleSubstFormat2*)Lookup->SubTable[i];
158 TSingleSubstFormat2 *tbl2 = (TSingleSubstFormat2*)Lookup->Su bTable[i]; 155 int index = -1;
159 int index = -1; 156 index = GetCoverageIndex(tbl2->Coverage, glyphnum);
160 index = GetCoverageIndex(tbl2->Coverage, glyphnum); 157 if (0 <= index && index < tbl2->GlyphCount) {
161 if(0 <= index && index < tbl2->GlyphCount) { 158 *vglyphnum = tbl2->Substitute[index];
162 *vglyphnum = tbl2->Substitute[index]; 159 return true;
163 return true; 160 }
164 } 161 break;
165 break; 162 }
166 } 163 }
167 } 164 }
168 } 165 return false;
169 return false; 166 }
170 } 167 int CFX_CTTGSUBTable::GetCoverageIndex(struct TCoverageFormatBase* Coverage,
171 int CFX_CTTGSUBTable::GetCoverageIndex(struct TCoverageFormatBase *Coverage, TT_ uint32_t g) 168 TT_uint32_t g) {
172 { 169 int i = 0;
173 int i = 0; 170 if (Coverage == NULL) {
174 if(Coverage == NULL) {
175 return -1;
176 }
177 switch(Coverage->CoverageFormat) {
178 case 1: {
179 TCoverageFormat1 *c1 = (TCoverageFormat1*)Coverage;
180 for(i = 0; i < c1->GlyphCount; i++) {
181 if((TT_uint32_t)c1->GlyphArray[i] == g) {
182 return i;
183 }
184 }
185 return -1;
186 }
187 case 2: {
188 TCoverageFormat2 *c2 = (TCoverageFormat2*)Coverage;
189 for(i = 0; i < c2->RangeCount; i++) {
190 TT_uint32_t s = c2->RangeRecord[i].Start;
191 TT_uint32_t e = c2->RangeRecord[i].End;
192 TT_uint32_t si = c2->RangeRecord[i].StartCoverageIndex;
193 if (s <= g && g <= e) {
194 return si + g - s;
195 }
196 }
197 return -1;
198 }
199 }
200 return -1; 171 return -1;
201 } 172 }
202 bool CFX_CTTGSUBTable::Parse( 173 switch (Coverage->CoverageFormat) {
203 FT_Bytes scriptlist, 174 case 1: {
204 FT_Bytes featurelist, 175 TCoverageFormat1* c1 = (TCoverageFormat1*)Coverage;
205 FT_Bytes lookuplist) 176 for (i = 0; i < c1->GlyphCount; i++) {
206 { 177 if ((TT_uint32_t)c1->GlyphArray[i] == g) {
207 ParseScriptList(scriptlist, &ScriptList); 178 return i;
208 ParseFeatureList(featurelist, &FeatureList); 179 }
209 ParseLookupList(lookuplist, &LookupList); 180 }
210 return true; 181 return -1;
211 } 182 }
212 void CFX_CTTGSUBTable::ParseScriptList(FT_Bytes raw, struct TScriptList *rec) 183 case 2: {
213 { 184 TCoverageFormat2* c2 = (TCoverageFormat2*)Coverage;
214 int i; 185 for (i = 0; i < c2->RangeCount; i++) {
215 FT_Bytes sp = raw; 186 TT_uint32_t s = c2->RangeRecord[i].Start;
216 rec->ScriptCount = GetUInt16(sp); 187 TT_uint32_t e = c2->RangeRecord[i].End;
217 if(rec->ScriptCount <= 0) { 188 TT_uint32_t si = c2->RangeRecord[i].StartCoverageIndex;
218 return; 189 if (s <= g && g <= e) {
219 } 190 return si + g - s;
220 rec->ScriptRecord = new struct TScriptRecord[rec->ScriptCount]; 191 }
221 for(i = 0; i < rec->ScriptCount; i++) { 192 }
222 rec->ScriptRecord[i].ScriptTag = GetUInt32(sp); 193 return -1;
223 TT_uint16_t offset = GetUInt16(sp); 194 }
224 ParseScript( 195 }
225 &raw[offset], 196 return -1;
226 &rec->ScriptRecord[i].Script); 197 }
227 } 198 bool CFX_CTTGSUBTable::Parse(FT_Bytes scriptlist,
228 } 199 FT_Bytes featurelist,
229 void CFX_CTTGSUBTable::ParseScript(FT_Bytes raw, struct TScript *rec) 200 FT_Bytes lookuplist) {
230 { 201 ParseScriptList(scriptlist, &ScriptList);
231 int i; 202 ParseFeatureList(featurelist, &FeatureList);
232 FT_Bytes sp = raw; 203 ParseLookupList(lookuplist, &LookupList);
233 rec->DefaultLangSys = GetUInt16(sp); 204 return true;
234 rec->LangSysCount = GetUInt16(sp); 205 }
235 if(rec->LangSysCount <= 0) { 206 void CFX_CTTGSUBTable::ParseScriptList(FT_Bytes raw, struct TScriptList* rec) {
236 return; 207 int i;
237 } 208 FT_Bytes sp = raw;
238 rec->LangSysRecord = new struct TLangSysRecord[rec->LangSysCount]; 209 rec->ScriptCount = GetUInt16(sp);
239 for(i = 0; i < rec->LangSysCount; i++) { 210 if (rec->ScriptCount <= 0) {
240 rec->LangSysRecord[i].LangSysTag = GetUInt32(sp); 211 return;
241 TT_uint16_t offset = GetUInt16(sp); 212 }
242 ParseLangSys( 213 rec->ScriptRecord = new struct TScriptRecord[rec->ScriptCount];
243 &raw[offset], 214 for (i = 0; i < rec->ScriptCount; i++) {
244 &rec->LangSysRecord[i].LangSys); 215 rec->ScriptRecord[i].ScriptTag = GetUInt32(sp);
245 }
246 }
247 void CFX_CTTGSUBTable::ParseLangSys(FT_Bytes raw, struct TLangSys *rec)
248 {
249 FT_Bytes sp = raw;
250 rec->LookupOrder = GetUInt16(sp);
251 rec->ReqFeatureIndex = GetUInt16(sp);
252 rec->FeatureCount = GetUInt16(sp);
253 if(rec->FeatureCount <= 0) {
254 return;
255 }
256 rec->FeatureIndex = new TT_uint16_t[rec->FeatureCount];
257 FXSYS_memset32(rec->FeatureIndex, 0, sizeof(TT_uint16_t) * rec->FeatureCount );
258 for (int i = 0; i < rec->FeatureCount; ++i) {
259 rec->FeatureIndex[i] = GetUInt16(sp);
260 }
261 }
262 void CFX_CTTGSUBTable::ParseFeatureList(FT_Bytes raw, TFeatureList *rec)
263 {
264 int i;
265 FT_Bytes sp = raw;
266 rec->FeatureCount = GetUInt16(sp);
267 if(rec->FeatureCount <= 0) {
268 return;
269 }
270 rec->FeatureRecord = new struct TFeatureRecord[rec->FeatureCount];
271 for(i = 0; i < rec->FeatureCount; i++) {
272 rec->FeatureRecord[i].FeatureTag = GetUInt32(sp);
273 TT_uint16_t offset = GetUInt16(sp);
274 ParseFeature(
275 &raw[offset],
276 &rec->FeatureRecord[i].Feature);
277 }
278 }
279 void CFX_CTTGSUBTable::ParseFeature(FT_Bytes raw, TFeature *rec)
280 {
281 int i;
282 FT_Bytes sp = raw;
283 rec->FeatureParams = GetUInt16(sp);
284 rec->LookupCount = GetUInt16(sp);
285 if(rec->LookupCount <= 0) {
286 return;
287 }
288 rec->LookupListIndex = new TT_uint16_t[rec->LookupCount];
289 for(i = 0; i < rec->LookupCount; i++) {
290 rec->LookupListIndex[i] = GetUInt16(sp);
291 }
292 }
293 void CFX_CTTGSUBTable::ParseLookupList(FT_Bytes raw, TLookupList *rec)
294 {
295 int i;
296 FT_Bytes sp = raw;
297 rec->LookupCount = GetUInt16(sp);
298 if(rec->LookupCount <= 0) {
299 return;
300 }
301 rec->Lookup = new struct TLookup[rec->LookupCount];
302 for(i = 0; i < rec->LookupCount; i++) {
303 TT_uint16_t offset = GetUInt16(sp);
304 ParseLookup(
305 &raw[offset],
306 &rec->Lookup[i]);
307 }
308 }
309 void CFX_CTTGSUBTable::ParseLookup(FT_Bytes raw, TLookup *rec)
310 {
311 int i;
312 FT_Bytes sp = raw;
313 rec->LookupType = GetUInt16(sp);
314 rec->LookupFlag = GetUInt16(sp);
315 rec->SubTableCount = GetUInt16(sp);
316 if(rec->SubTableCount <= 0) {
317 return;
318 }
319 rec->SubTable = new struct TSubTableBase*[rec->SubTableCount];
320 for(i = 0; i < rec->SubTableCount; i++) {
321 rec->SubTable[i] = NULL;
322 }
323 if(rec->LookupType != 1) {
324 return;
325 }
326 for(i = 0; i < rec->SubTableCount; i++) {
327 TT_uint16_t offset = GetUInt16(sp);
328 ParseSingleSubst(
329 &raw[offset],
330 &rec->SubTable[i]);
331 }
332 }
333 void CFX_CTTGSUBTable::ParseCoverage(FT_Bytes raw, TCoverageFormatBase **rec)
334 {
335 FT_Bytes sp = raw;
336 TT_uint16_t Format = GetUInt16(sp);
337 switch(Format) {
338 case 1:
339 *rec = new TCoverageFormat1();
340 ParseCoverageFormat1(raw, (TCoverageFormat1*)*rec);
341 break;
342 case 2:
343 *rec = new TCoverageFormat2();
344 ParseCoverageFormat2(raw, (TCoverageFormat2*)*rec);
345 break;
346 }
347 }
348 void CFX_CTTGSUBTable::ParseCoverageFormat1(FT_Bytes raw, TCoverageFormat1 *rec)
349 {
350 int i;
351 FT_Bytes sp = raw;
352 GetUInt16(sp);
353 rec->GlyphCount = GetUInt16(sp);
354 if(rec->GlyphCount <= 0) {
355 return;
356 }
357 rec->GlyphArray = new TT_uint16_t[rec->GlyphCount];
358 for(i = 0; i < rec->GlyphCount; i++) {
359 rec->GlyphArray[i] = GetUInt16(sp);
360 }
361 }
362 void CFX_CTTGSUBTable::ParseCoverageFormat2(FT_Bytes raw, TCoverageFormat2 *rec)
363 {
364 int i;
365 FT_Bytes sp = raw;
366 GetUInt16(sp);
367 rec->RangeCount = GetUInt16(sp);
368 if(rec->RangeCount <= 0) {
369 return;
370 }
371 rec->RangeRecord = new TRangeRecord[rec->RangeCount];
372 for(i = 0; i < rec->RangeCount; i++) {
373 rec->RangeRecord[i].Start = GetUInt16(sp);
374 rec->RangeRecord[i].End = GetUInt16(sp);
375 rec->RangeRecord[i].StartCoverageIndex = GetUInt16(sp);
376 }
377 }
378 void CFX_CTTGSUBTable::ParseSingleSubst(FT_Bytes raw, TSubTableBase **rec)
379 {
380 FT_Bytes sp = raw;
381 TT_uint16_t Format = GetUInt16(sp);
382 switch(Format) {
383 case 1:
384 *rec = new TSingleSubstFormat1();
385 ParseSingleSubstFormat1(raw, (TSingleSubstFormat1*)*rec);
386 break;
387 case 2:
388 *rec = new TSingleSubstFormat2();
389 ParseSingleSubstFormat2(raw, (TSingleSubstFormat2*)*rec);
390 break;
391 }
392 }
393 void CFX_CTTGSUBTable::ParseSingleSubstFormat1(FT_Bytes raw, TSingleSubstFormat1 *rec)
394 {
395 FT_Bytes sp = raw;
396 GetUInt16(sp);
397 TT_uint16_t offset = GetUInt16(sp); 216 TT_uint16_t offset = GetUInt16(sp);
398 ParseCoverage( 217 ParseScript(&raw[offset], &rec->ScriptRecord[i].Script);
399 &raw[offset], 218 }
400 &rec->Coverage); 219 }
401 rec->DeltaGlyphID = GetInt16(sp); 220 void CFX_CTTGSUBTable::ParseScript(FT_Bytes raw, struct TScript* rec) {
402 } 221 int i;
403 void CFX_CTTGSUBTable::ParseSingleSubstFormat2(FT_Bytes raw, TSingleSubstFormat2 *rec) 222 FT_Bytes sp = raw;
404 { 223 rec->DefaultLangSys = GetUInt16(sp);
405 int i; 224 rec->LangSysCount = GetUInt16(sp);
406 FT_Bytes sp = raw; 225 if (rec->LangSysCount <= 0) {
407 GetUInt16(sp); 226 return;
227 }
228 rec->LangSysRecord = new struct TLangSysRecord[rec->LangSysCount];
229 for (i = 0; i < rec->LangSysCount; i++) {
230 rec->LangSysRecord[i].LangSysTag = GetUInt32(sp);
408 TT_uint16_t offset = GetUInt16(sp); 231 TT_uint16_t offset = GetUInt16(sp);
409 ParseCoverage( 232 ParseLangSys(&raw[offset], &rec->LangSysRecord[i].LangSys);
410 &raw[offset], 233 }
411 &rec->Coverage); 234 }
412 rec->GlyphCount = GetUInt16(sp); 235 void CFX_CTTGSUBTable::ParseLangSys(FT_Bytes raw, struct TLangSys* rec) {
413 if(rec->GlyphCount <= 0) { 236 FT_Bytes sp = raw;
414 return; 237 rec->LookupOrder = GetUInt16(sp);
415 } 238 rec->ReqFeatureIndex = GetUInt16(sp);
416 rec->Substitute = new TT_uint16_t[rec->GlyphCount]; 239 rec->FeatureCount = GetUInt16(sp);
417 for(i = 0; i < rec->GlyphCount; i++) { 240 if (rec->FeatureCount <= 0) {
418 rec->Substitute[i] = GetUInt16(sp); 241 return;
419 } 242 }
420 } 243 rec->FeatureIndex = new TT_uint16_t[rec->FeatureCount];
421 FX_BOOL CFX_GSUBTable::GetVerticalGlyph(FX_DWORD glyphnum, FX_DWORD* vglyphnum) 244 FXSYS_memset32(rec->FeatureIndex, 0, sizeof(TT_uint16_t) * rec->FeatureCount);
422 { 245 for (int i = 0; i < rec->FeatureCount; ++i) {
423 return m_GsubImp.GetVerticalGlyph(glyphnum, vglyphnum); 246 rec->FeatureIndex[i] = GetUInt16(sp);
424 } 247 }
425 IFX_GSUBTable* FXGE_CreateGSUBTable(CFX_Font* pFont) 248 }
426 { 249 void CFX_CTTGSUBTable::ParseFeatureList(FT_Bytes raw, TFeatureList* rec) {
427 if (!pFont) { 250 int i;
428 return NULL; 251 FT_Bytes sp = raw;
429 } 252 rec->FeatureCount = GetUInt16(sp);
430 if (NULL == pFont->m_pGsubData) { 253 if (rec->FeatureCount <= 0) {
431 unsigned long length = 0; 254 return;
432 int error = FXFT_Load_Sfnt_Table(pFont->m_Face, FT_MAKE_TAG('G', 'S', 'U ', 'B'), 0, NULL, &length); 255 }
433 if (!error) { 256 rec->FeatureRecord = new struct TFeatureRecord[rec->FeatureCount];
434 pFont->m_pGsubData = (unsigned char*)FX_Alloc(FX_BYTE, length); 257 for (i = 0; i < rec->FeatureCount; i++) {
435 } 258 rec->FeatureRecord[i].FeatureTag = GetUInt32(sp);
436 if (!pFont->m_pGsubData) { 259 TT_uint16_t offset = GetUInt16(sp);
437 return NULL; 260 ParseFeature(&raw[offset], &rec->FeatureRecord[i].Feature);
438 } 261 }
439 } 262 }
440 int error = FXFT_Load_Sfnt_Table(pFont->m_Face, FT_MAKE_TAG('G', 'S', 'U', ' B'), 0, pFont->m_pGsubData, NULL); 263 void CFX_CTTGSUBTable::ParseFeature(FT_Bytes raw, TFeature* rec) {
441 if (!error && pFont->m_pGsubData) { 264 int i;
442 CFX_GSUBTable* pGsubTable = FX_NEW CFX_GSUBTable; 265 FT_Bytes sp = raw;
443 if (!pGsubTable) { 266 rec->FeatureParams = GetUInt16(sp);
444 return NULL; 267 rec->LookupCount = GetUInt16(sp);
445 } 268 if (rec->LookupCount <= 0) {
446 if (pGsubTable->m_GsubImp.LoadGSUBTable((FT_Bytes)pFont->m_pGsubData)) { 269 return;
447 return pGsubTable; 270 }
448 } 271 rec->LookupListIndex = new TT_uint16_t[rec->LookupCount];
449 delete pGsubTable; 272 for (i = 0; i < rec->LookupCount; i++) {
450 } 273 rec->LookupListIndex[i] = GetUInt16(sp);
274 }
275 }
276 void CFX_CTTGSUBTable::ParseLookupList(FT_Bytes raw, TLookupList* rec) {
277 int i;
278 FT_Bytes sp = raw;
279 rec->LookupCount = GetUInt16(sp);
280 if (rec->LookupCount <= 0) {
281 return;
282 }
283 rec->Lookup = new struct TLookup[rec->LookupCount];
284 for (i = 0; i < rec->LookupCount; i++) {
285 TT_uint16_t offset = GetUInt16(sp);
286 ParseLookup(&raw[offset], &rec->Lookup[i]);
287 }
288 }
289 void CFX_CTTGSUBTable::ParseLookup(FT_Bytes raw, TLookup* rec) {
290 int i;
291 FT_Bytes sp = raw;
292 rec->LookupType = GetUInt16(sp);
293 rec->LookupFlag = GetUInt16(sp);
294 rec->SubTableCount = GetUInt16(sp);
295 if (rec->SubTableCount <= 0) {
296 return;
297 }
298 rec->SubTable = new struct TSubTableBase* [rec->SubTableCount];
299 for (i = 0; i < rec->SubTableCount; i++) {
300 rec->SubTable[i] = NULL;
301 }
302 if (rec->LookupType != 1) {
303 return;
304 }
305 for (i = 0; i < rec->SubTableCount; i++) {
306 TT_uint16_t offset = GetUInt16(sp);
307 ParseSingleSubst(&raw[offset], &rec->SubTable[i]);
308 }
309 }
310 void CFX_CTTGSUBTable::ParseCoverage(FT_Bytes raw, TCoverageFormatBase** rec) {
311 FT_Bytes sp = raw;
312 TT_uint16_t Format = GetUInt16(sp);
313 switch (Format) {
314 case 1:
315 *rec = new TCoverageFormat1();
316 ParseCoverageFormat1(raw, (TCoverageFormat1*)*rec);
317 break;
318 case 2:
319 *rec = new TCoverageFormat2();
320 ParseCoverageFormat2(raw, (TCoverageFormat2*)*rec);
321 break;
322 }
323 }
324 void CFX_CTTGSUBTable::ParseCoverageFormat1(FT_Bytes raw,
325 TCoverageFormat1* rec) {
326 int i;
327 FT_Bytes sp = raw;
328 GetUInt16(sp);
329 rec->GlyphCount = GetUInt16(sp);
330 if (rec->GlyphCount <= 0) {
331 return;
332 }
333 rec->GlyphArray = new TT_uint16_t[rec->GlyphCount];
334 for (i = 0; i < rec->GlyphCount; i++) {
335 rec->GlyphArray[i] = GetUInt16(sp);
336 }
337 }
338 void CFX_CTTGSUBTable::ParseCoverageFormat2(FT_Bytes raw,
339 TCoverageFormat2* rec) {
340 int i;
341 FT_Bytes sp = raw;
342 GetUInt16(sp);
343 rec->RangeCount = GetUInt16(sp);
344 if (rec->RangeCount <= 0) {
345 return;
346 }
347 rec->RangeRecord = new TRangeRecord[rec->RangeCount];
348 for (i = 0; i < rec->RangeCount; i++) {
349 rec->RangeRecord[i].Start = GetUInt16(sp);
350 rec->RangeRecord[i].End = GetUInt16(sp);
351 rec->RangeRecord[i].StartCoverageIndex = GetUInt16(sp);
352 }
353 }
354 void CFX_CTTGSUBTable::ParseSingleSubst(FT_Bytes raw, TSubTableBase** rec) {
355 FT_Bytes sp = raw;
356 TT_uint16_t Format = GetUInt16(sp);
357 switch (Format) {
358 case 1:
359 *rec = new TSingleSubstFormat1();
360 ParseSingleSubstFormat1(raw, (TSingleSubstFormat1*)*rec);
361 break;
362 case 2:
363 *rec = new TSingleSubstFormat2();
364 ParseSingleSubstFormat2(raw, (TSingleSubstFormat2*)*rec);
365 break;
366 }
367 }
368 void CFX_CTTGSUBTable::ParseSingleSubstFormat1(FT_Bytes raw,
369 TSingleSubstFormat1* rec) {
370 FT_Bytes sp = raw;
371 GetUInt16(sp);
372 TT_uint16_t offset = GetUInt16(sp);
373 ParseCoverage(&raw[offset], &rec->Coverage);
374 rec->DeltaGlyphID = GetInt16(sp);
375 }
376 void CFX_CTTGSUBTable::ParseSingleSubstFormat2(FT_Bytes raw,
377 TSingleSubstFormat2* rec) {
378 int i;
379 FT_Bytes sp = raw;
380 GetUInt16(sp);
381 TT_uint16_t offset = GetUInt16(sp);
382 ParseCoverage(&raw[offset], &rec->Coverage);
383 rec->GlyphCount = GetUInt16(sp);
384 if (rec->GlyphCount <= 0) {
385 return;
386 }
387 rec->Substitute = new TT_uint16_t[rec->GlyphCount];
388 for (i = 0; i < rec->GlyphCount; i++) {
389 rec->Substitute[i] = GetUInt16(sp);
390 }
391 }
392 FX_BOOL CFX_GSUBTable::GetVerticalGlyph(FX_DWORD glyphnum,
393 FX_DWORD* vglyphnum) {
394 return m_GsubImp.GetVerticalGlyph(glyphnum, vglyphnum);
395 }
396 IFX_GSUBTable* FXGE_CreateGSUBTable(CFX_Font* pFont) {
397 if (!pFont) {
451 return NULL; 398 return NULL;
452 } 399 }
400 if (NULL == pFont->m_pGsubData) {
401 unsigned long length = 0;
402 int error = FXFT_Load_Sfnt_Table(
403 pFont->m_Face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, NULL, &length);
404 if (!error) {
405 pFont->m_pGsubData = (unsigned char*)FX_Alloc(FX_BYTE, length);
406 }
407 if (!pFont->m_pGsubData) {
408 return NULL;
409 }
410 }
411 int error = FXFT_Load_Sfnt_Table(pFont->m_Face,
412 FT_MAKE_TAG('G', 'S', 'U', 'B'),
413 0,
414 pFont->m_pGsubData,
415 NULL);
416 if (!error && pFont->m_pGsubData) {
417 CFX_GSUBTable* pGsubTable = FX_NEW CFX_GSUBTable;
418 if (!pGsubTable) {
419 return NULL;
420 }
421 if (pGsubTable->m_GsubImp.LoadGSUBTable((FT_Bytes)pFont->m_pGsubData)) {
422 return pGsubTable;
423 }
424 delete pGsubTable;
425 }
426 return NULL;
427 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698