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