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

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

Issue 1356373003: Fix a bunch of sign mismatch warnings. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: fix a couple more trivial comparison warnings... maybe they got lost in the merge Created 5 years, 2 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/fpdfapi/fpdf_module.h" 7 #include "../../../include/fpdfapi/fpdf_module.h"
8 #include "../../../include/fpdfapi/fpdf_page.h" 8 #include "../../../include/fpdfapi/fpdf_page.h"
9 #include "../../../include/fpdfapi/fpdf_resource.h" 9 #include "../../../include/fpdfapi/fpdf_resource.h"
10 #include "../../../include/fxge/fx_freetype.h" 10 #include "../../../include/fxge/fx_freetype.h"
11 #include "../../../include/fxge/fx_ge.h" 11 #include "../../../include/fxge/fx_ge.h"
12 #include "../fpdf_cmaps/cmap_int.h" 12 #include "../fpdf_cmaps/cmap_int.h"
13 #include "font_int.h" 13 #include "font_int.h"
14 14
15 CPDF_CMapManager::CPDF_CMapManager() { 15 namespace {
16 m_bPrompted = FALSE; 16
17 FXSYS_memset(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps); 17 const FX_CHAR* const g_CharsetNames[CIDSET_NUM_SETS] =
18 } 18 {nullptr, "GB1", "CNS1", "Japan1", "Korea1", "UCS"};
19 CPDF_CMapManager::~CPDF_CMapManager() { 19
20 for (const auto& pair : m_CMaps) { 20 const int g_CharsetCPs[CIDSET_NUM_SETS] = {0, 936, 950, 932, 949, 1200};
21 delete pair.second; 21
22 } 22 class CPDF_PredefinedCMap {
23 m_CMaps.clear(); 23 public:
24 for (int i = 0; i < FX_ArraySize(m_CID2UnicodeMaps); ++i) { 24 const FX_CHAR* m_pName;
25 delete m_CID2UnicodeMaps[i]; 25 CIDSet m_Charset;
26 } 26 int m_Coding;
27 } 27 CPDF_CMap::CodingScheme m_CodingScheme;
28 CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name, 28 FX_DWORD m_LeadingSegCount;
29 FX_BOOL bPromptCJK) { 29 uint8_t m_LeadingSegs[4];
30 auto it = m_CMaps.find(name); 30 };
31 if (it != m_CMaps.end()) { 31
32 return it->second;
33 }
34 CPDF_CMap* pCMap = LoadPredefinedCMap(name, bPromptCJK);
35 if (!name.IsEmpty()) {
36 m_CMaps[name] = pCMap;
37 }
38 return pCMap;
39 }
40 CPDF_CMap* CPDF_CMapManager::LoadPredefinedCMap(const CFX_ByteString& name,
41 FX_BOOL bPromptCJK) {
42 CPDF_CMap* pCMap = new CPDF_CMap;
43 const FX_CHAR* pname = name;
44 if (*pname == '/') {
45 pname++;
46 }
47 pCMap->LoadPredefined(this, pname, bPromptCJK);
48 return pCMap;
49 }
50 static const FX_CHAR* const g_CharsetNames[NUMBER_OF_CIDSETS] = {
51 NULL, "GB1", "CNS1", "Japan1", "Korea1", "UCS"};
52 static const int g_CharsetCPs[NUMBER_OF_CIDSETS] = {0, 936, 950,
53 932, 949, 1200};
54 int _CharsetFromOrdering(const CFX_ByteString& Ordering) {
55 for (int charset = 1; charset < NUMBER_OF_CIDSETS; charset++) {
56 if (Ordering == CFX_ByteStringC(g_CharsetNames[charset]))
57 return charset;
58 }
59 return CIDSET_UNKNOWN;
60 }
61 void CPDF_CMapManager::ReloadAll() {
62 for (const auto& pair : m_CMaps) {
63 CPDF_CMap* pCMap = pair.second;
64 pCMap->LoadPredefined(this, pair.first, FALSE);
65 }
66 for (int i = 0; i < FX_ArraySize(m_CID2UnicodeMaps); ++i) {
67 if (CPDF_CID2UnicodeMap* pMap = m_CID2UnicodeMaps[i]) {
68 pMap->Load(this, i, FALSE);
69 }
70 }
71 }
72 CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(int charset,
73 FX_BOOL bPromptCJK) {
74 if (m_CID2UnicodeMaps[charset] == NULL) {
75 m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK);
76 }
77 return m_CID2UnicodeMaps[charset];
78 }
79 CPDF_CID2UnicodeMap* CPDF_CMapManager::LoadCID2UnicodeMap(int charset,
80 FX_BOOL bPromptCJK) {
81 CPDF_CID2UnicodeMap* pMap = new CPDF_CID2UnicodeMap();
82 if (!pMap->Initialize()) {
83 delete pMap;
84 return NULL;
85 }
86 pMap->Load(this, charset, bPromptCJK);
87 return pMap;
88 }
89 CPDF_CMapParser::CPDF_CMapParser() {
90 m_pCMap = NULL;
91 m_Status = 0;
92 m_CodeSeq = 0;
93 }
94 FX_BOOL CPDF_CMapParser::Initialize(CPDF_CMap* pCMap) {
95 m_pCMap = pCMap;
96 m_Status = 0;
97 m_CodeSeq = 0;
98 m_AddMaps.EstimateSize(0, 10240);
99 return TRUE;
100 }
101 static FX_DWORD CMap_GetCode(const CFX_ByteStringC& word) {
102 int num = 0;
103 if (word.GetAt(0) == '<') {
104 for (int i = 1; i < word.GetLength(); i++) {
105 uint8_t digit = word.GetAt(i);
106 if (digit >= '0' && digit <= '9') {
107 digit = digit - '0';
108 } else if (digit >= 'a' && digit <= 'f') {
109 digit = digit - 'a' + 10;
110 } else if (digit >= 'A' && digit <= 'F') {
111 digit = digit - 'A' + 10;
112 } else {
113 return num;
114 }
115 num = num * 16 + digit;
116 }
117 } else {
118 for (int i = 0; i < word.GetLength(); i++) {
119 if (word.GetAt(i) < '0' || word.GetAt(i) > '9') {
120 return num;
121 }
122 num = num * 10 + word.GetAt(i) - '0';
123 }
124 }
125 return num;
126 }
127 static FX_BOOL _CMap_GetCodeRange(_CMap_CodeRange& range,
128 const CFX_ByteStringC& first,
129 const CFX_ByteStringC& second) {
130 if (first.GetLength() == 0 || first.GetAt(0) != '<') {
131 return FALSE;
132 }
133 int i;
134 for (i = 1; i < first.GetLength(); i++)
135 if (first.GetAt(i) == '>') {
136 break;
137 }
138 range.m_CharSize = (i - 1) / 2;
139 if (range.m_CharSize > 4) {
140 return FALSE;
141 }
142 for (i = 0; i < range.m_CharSize; i++) {
143 uint8_t digit1 = first.GetAt(i * 2 + 1);
144 uint8_t digit2 = first.GetAt(i * 2 + 2);
145 uint8_t byte = (digit1 >= '0' && digit1 <= '9')
146 ? (digit1 - '0')
147 : ((digit1 & 0xdf) - 'A' + 10);
148 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9')
149 ? (digit2 - '0')
150 : ((digit2 & 0xdf) - 'A' + 10));
151 range.m_Lower[i] = byte;
152 }
153 FX_DWORD size = second.GetLength();
154 for (i = 0; i < range.m_CharSize; i++) {
155 uint8_t digit1 =
156 ((FX_DWORD)i * 2 + 1 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 1) : 0;
157 uint8_t digit2 =
158 ((FX_DWORD)i * 2 + 2 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 2) : 0;
159 uint8_t byte = (digit1 >= '0' && digit1 <= '9')
160 ? (digit1 - '0')
161 : ((digit1 & 0xdf) - 'A' + 10);
162 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9')
163 ? (digit2 - '0')
164 : ((digit2 & 0xdf) - 'A' + 10));
165 range.m_Upper[i] = byte;
166 }
167 return TRUE;
168 }
169 static CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) {
170 return word.Mid(1, word.GetLength() - 2);
171 }
172 void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) {
173 if (word.IsEmpty()) {
174 return;
175 }
176 if (word == FX_BSTRC("begincidchar")) {
177 m_Status = 1;
178 m_CodeSeq = 0;
179 } else if (word == FX_BSTRC("begincidrange")) {
180 m_Status = 2;
181 m_CodeSeq = 0;
182 } else if (word == FX_BSTRC("endcidrange") ||
183 word == FX_BSTRC("endcidchar")) {
184 m_Status = 0;
185 } else if (word == FX_BSTRC("/WMode")) {
186 m_Status = 6;
187 } else if (word == FX_BSTRC("/Registry")) {
188 m_Status = 3;
189 } else if (word == FX_BSTRC("/Ordering")) {
190 m_Status = 4;
191 } else if (word == FX_BSTRC("/Supplement")) {
192 m_Status = 5;
193 } else if (word == FX_BSTRC("begincodespacerange")) {
194 m_Status = 7;
195 m_CodeSeq = 0;
196 } else if (word == FX_BSTRC("usecmap")) {
197 } else if (m_Status == 1 || m_Status == 2) {
198 m_CodePoints[m_CodeSeq] = CMap_GetCode(word);
199 m_CodeSeq++;
200 FX_DWORD StartCode, EndCode;
201 FX_WORD StartCID;
202 if (m_Status == 1) {
203 if (m_CodeSeq < 2) {
204 return;
205 }
206 EndCode = StartCode = m_CodePoints[0];
207 StartCID = (FX_WORD)m_CodePoints[1];
208 } else {
209 if (m_CodeSeq < 3) {
210 return;
211 }
212 StartCode = m_CodePoints[0];
213 EndCode = m_CodePoints[1];
214 StartCID = (FX_WORD)m_CodePoints[2];
215 }
216 if (EndCode < 0x10000) {
217 for (FX_DWORD code = StartCode; code <= EndCode; code++) {
218 m_pCMap->m_pMapping[code] = (FX_WORD)(StartCID + code - StartCode);
219 }
220 } else {
221 FX_DWORD buf[2];
222 buf[0] = StartCode;
223 buf[1] = ((EndCode - StartCode) << 16) + StartCID;
224 m_AddMaps.AppendBlock(buf, sizeof buf);
225 }
226 m_CodeSeq = 0;
227 } else if (m_Status == 3) {
228 CMap_GetString(word);
229 m_Status = 0;
230 } else if (m_Status == 4) {
231 m_pCMap->m_Charset = _CharsetFromOrdering(CMap_GetString(word));
232 m_Status = 0;
233 } else if (m_Status == 5) {
234 CMap_GetCode(word);
235 m_Status = 0;
236 } else if (m_Status == 6) {
237 m_pCMap->m_bVertical = CMap_GetCode(word);
238 m_Status = 0;
239 } else if (m_Status == 7) {
240 if (word == FX_BSTRC("endcodespacerange")) {
241 int nSegs = m_CodeRanges.GetSize();
242 if (nSegs > 1) {
243 m_pCMap->m_CodingScheme = CPDF_CMap::MixedFourBytes;
244 m_pCMap->m_nCodeRanges = nSegs;
245 m_pCMap->m_pLeadingBytes =
246 FX_Alloc2D(uint8_t, nSegs, sizeof(_CMap_CodeRange));
247 FXSYS_memcpy(m_pCMap->m_pLeadingBytes, m_CodeRanges.GetData(),
248 nSegs * sizeof(_CMap_CodeRange));
249 } else if (nSegs == 1) {
250 m_pCMap->m_CodingScheme = (m_CodeRanges[0].m_CharSize == 2)
251 ? CPDF_CMap::TwoBytes
252 : CPDF_CMap::OneByte;
253 }
254 m_Status = 0;
255 } else {
256 if (word.GetLength() == 0 || word.GetAt(0) != '<') {
257 return;
258 }
259 if (m_CodeSeq % 2) {
260 _CMap_CodeRange range;
261 if (_CMap_GetCodeRange(range, m_LastWord, word)) {
262 m_CodeRanges.Add(range);
263 }
264 }
265 m_CodeSeq++;
266 }
267 }
268 m_LastWord = word;
269 }
270 CPDF_CMap::CPDF_CMap() {
271 m_Charset = CIDSET_UNKNOWN;
272 m_Coding = CIDCODING_UNKNOWN;
273 m_CodingScheme = TwoBytes;
274 m_bVertical = 0;
275 m_bLoaded = FALSE;
276 m_pMapping = NULL;
277 m_pLeadingBytes = NULL;
278 m_pAddMapping = NULL;
279 m_pEmbedMap = NULL;
280 m_pUseMap = NULL;
281 m_nCodeRanges = 0;
282 }
283 CPDF_CMap::~CPDF_CMap() {
284 FX_Free(m_pMapping);
285 FX_Free(m_pAddMapping);
286 FX_Free(m_pLeadingBytes);
287 delete m_pUseMap;
288 }
289 void CPDF_CMap::Release() {
290 if (m_PredefinedCMap.IsEmpty()) {
291 delete this;
292 }
293 }
294 const CPDF_PredefinedCMap g_PredefinedCMaps[] = { 32 const CPDF_PredefinedCMap g_PredefinedCMaps[] = {
295 {"GB-EUC", 33 {"GB-EUC",
296 CIDSET_GB1, 34 CIDSET_GB1,
297 CIDCODING_GB, 35 CIDCODING_GB,
298 CPDF_CMap::MixedTwoBytes, 36 CPDF_CMap::MixedTwoBytes,
299 1, 37 1,
300 {0xa1, 0xfe}}, 38 {0xa1, 0xfe}},
301 {"GBpc-EUC", 39 {"GBpc-EUC",
302 CIDSET_GB1, 40 CIDSET_GB1,
303 CIDCODING_GB, 41 CIDCODING_GB,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 1, 160 1,
423 {0x81, 0xfe}}, 161 {0x81, 0xfe}},
424 {"KSCpc-EUC", 162 {"KSCpc-EUC",
425 CIDSET_KOREA1, 163 CIDSET_KOREA1,
426 CIDCODING_KOREA, 164 CIDCODING_KOREA,
427 CPDF_CMap::MixedTwoBytes, 165 CPDF_CMap::MixedTwoBytes,
428 1, 166 1,
429 {0xa1, 0xfd}}, 167 {0xa1, 0xfd}},
430 {"UniKS-UCS2", CIDSET_KOREA1, CIDCODING_UCS2, CPDF_CMap::TwoBytes}, 168 {"UniKS-UCS2", CIDSET_KOREA1, CIDCODING_UCS2, CPDF_CMap::TwoBytes},
431 {"UniKS-UTF16", CIDSET_KOREA1, CIDCODING_UTF16, CPDF_CMap::TwoBytes}, 169 {"UniKS-UTF16", CIDSET_KOREA1, CIDCODING_UTF16, CPDF_CMap::TwoBytes},
432 {NULL, 0, 0}}; 170 };
171
172 CIDSet CIDSetFromSizeT(size_t index) {
173 if (index >= CIDSET_NUM_SETS) {
174 NOTREACHED();
175 return CIDSET_UNKNOWN;
176 }
177 return static_cast<CIDSet>(index);
178 }
179
180 CIDSet CharsetFromOrdering(const CFX_ByteString& ordering) {
181 for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) {
182 if (ordering == CFX_ByteStringC(g_CharsetNames[charset]))
183 return CIDSetFromSizeT(charset);
184 }
185 return CIDSET_UNKNOWN;
186 }
187
188 FX_DWORD CMap_GetCode(const CFX_ByteStringC& word) {
189 int num = 0;
190 if (word.GetAt(0) == '<') {
191 for (int i = 1; i < word.GetLength(); i++) {
192 uint8_t digit = word.GetAt(i);
193 if (digit >= '0' && digit <= '9') {
194 digit = digit - '0';
195 } else if (digit >= 'a' && digit <= 'f') {
196 digit = digit - 'a' + 10;
197 } else if (digit >= 'A' && digit <= 'F') {
198 digit = digit - 'A' + 10;
199 } else {
200 return num;
201 }
202 num = num * 16 + digit;
203 }
204 } else {
205 for (int i = 0; i < word.GetLength(); i++) {
206 if (word.GetAt(i) < '0' || word.GetAt(i) > '9') {
207 return num;
208 }
209 num = num * 10 + word.GetAt(i) - '0';
210 }
211 }
212 return num;
213 }
214
215 bool CMap_GetCodeRange(CMap_CodeRange& range,
216 const CFX_ByteStringC& first,
217 const CFX_ByteStringC& second) {
218 if (first.GetLength() == 0 || first.GetAt(0) != '<')
219 return false;
220
221 int i;
222 for (i = 1; i < first.GetLength(); ++i) {
223 if (first.GetAt(i) == '>') {
224 break;
225 }
226 }
227 range.m_CharSize = (i - 1) / 2;
228 if (range.m_CharSize > 4)
229 return false;
230
231 for (i = 0; i < range.m_CharSize; ++i) {
232 uint8_t digit1 = first.GetAt(i * 2 + 1);
233 uint8_t digit2 = first.GetAt(i * 2 + 2);
234 uint8_t byte = (digit1 >= '0' && digit1 <= '9')
235 ? (digit1 - '0')
236 : ((digit1 & 0xdf) - 'A' + 10);
237 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9')
238 ? (digit2 - '0')
239 : ((digit2 & 0xdf) - 'A' + 10));
240 range.m_Lower[i] = byte;
241 }
242
243 FX_DWORD size = second.GetLength();
244 for (i = 0; i < range.m_CharSize; ++i) {
245 uint8_t digit1 =
246 ((FX_DWORD)i * 2 + 1 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 1) : 0;
247 uint8_t digit2 =
248 ((FX_DWORD)i * 2 + 2 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 2) : 0;
249 uint8_t byte = (digit1 >= '0' && digit1 <= '9')
250 ? (digit1 - '0')
251 : ((digit1 & 0xdf) - 'A' + 10);
252 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9')
253 ? (digit2 - '0')
254 : ((digit2 & 0xdf) - 'A' + 10));
255 range.m_Upper[i] = byte;
256 }
257 return true;
258 }
259
260 CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) {
261 return word.Mid(1, word.GetLength() - 2);
262 }
263
264 int CompareDWORD(const void* data1, const void* data2) {
265 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2);
266 }
267
268 int CompareCID(const void* key, const void* element) {
269 if ((*(FX_DWORD*)key) < (*(FX_DWORD*)element)) {
270 return -1;
271 }
272 if ((*(FX_DWORD*)key) >
273 (*(FX_DWORD*)element) + ((FX_DWORD*)element)[1] / 65536) {
274 return 1;
275 }
276 return 0;
277 }
278
279 int CheckCodeRange(uint8_t* codes,
280 int size,
281 CMap_CodeRange* pRanges,
282 int nRanges) {
283 int iSeg = nRanges - 1;
284 while (iSeg >= 0) {
285 if (pRanges[iSeg].m_CharSize < size) {
286 --iSeg;
287 continue;
288 }
289 int iChar = 0;
290 while (iChar < size) {
291 if (codes[iChar] < pRanges[iSeg].m_Lower[iChar] ||
292 codes[iChar] > pRanges[iSeg].m_Upper[iChar]) {
293 break;
294 }
295 ++iChar;
296 }
297 if (iChar == pRanges[iSeg].m_CharSize)
298 return 2;
299
300 if (iChar)
301 return (size == pRanges[iSeg].m_CharSize) ? 2 : 1;
302 iSeg--;
303 }
304 return 0;
305 }
306
307 int GetCharSizeImpl(FX_DWORD charcode,
308 CMap_CodeRange* pRanges,
309 int iRangesSize) {
310 if (!iRangesSize)
311 return 1;
312
313 uint8_t codes[4];
314 codes[0] = codes[1] = 0x00;
315 codes[2] = (uint8_t)(charcode >> 8 & 0xFF);
316 codes[3] = (uint8_t)charcode;
317 int offset = 0;
318 int size = 4;
319 for (int i = 0; i < 4; ++i) {
320 int iSeg = iRangesSize - 1;
321 while (iSeg >= 0) {
322 if (pRanges[iSeg].m_CharSize < size) {
323 --iSeg;
324 continue;
325 }
326 int iChar = 0;
327 while (iChar < size) {
328 if (codes[offset + iChar] < pRanges[iSeg].m_Lower[iChar] ||
329 codes[offset + iChar] > pRanges[iSeg].m_Upper[iChar]) {
330 break;
331 }
332 ++iChar;
333 }
334 if (iChar == pRanges[iSeg].m_CharSize)
335 return size;
336 --iSeg;
337 }
338 --size;
339 ++offset;
340 }
341 return 1;
342 }
343
344 bool IsValidEmbeddedCharcodeFromUnicodeCharset(CIDSet charset) {
345 switch (charset) {
346 case CIDSET_GB1:
347 case CIDSET_CNS1:
348 case CIDSET_JAPAN1:
349 case CIDSET_KOREA1:
350 return true;
351
352 default:
353 return false;
354 }
355 }
356
357 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
358 FX_DWORD EmbeddedCharcodeFromUnicode(const FXCMAP_CMap* pEmbedMap,
359 CIDSet charset,
360 FX_WCHAR unicode) {
361 if (!IsValidEmbeddedCharcodeFromUnicodeCharset(charset))
362 return 0;
363
364 CPDF_FontGlobals* pFontGlobals =
365 CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
366 const FX_WORD* pCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap;
367 if (!pCodes)
368 return 0;
369
370 int nCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count;
371 for (int i = 0; i < nCodes; ++i) {
372 if (pCodes[i] == unicode) {
373 FX_DWORD CharCode = FPDFAPI_CharCodeFromCID(pEmbedMap, i);
374 if (CharCode != 0) {
375 return CharCode;
376 }
377 }
378 }
379 return 0;
380 }
381 #endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
382
383 FX_WCHAR EmbeddedUnicodeFromCharcode(const FXCMAP_CMap* pEmbedMap,
384 CIDSet charset,
385 FX_DWORD charcode) {
386 if (!IsValidEmbeddedCharcodeFromUnicodeCharset(charset))
387 return 0;
388
389 FX_WORD cid = FPDFAPI_CIDFromCharCode(pEmbedMap, charcode);
390 if (cid == 0)
391 return 0;
392
393 CPDF_FontGlobals* pFontGlobals =
394 CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
395 const FX_WORD* pCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap;
396 if (!pCodes)
397 return 0;
398
399 if (cid < pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count)
400 return pCodes[cid];
401 return 0;
402 }
403
404 void FT_UseCIDCharmap(FXFT_Face face, int coding) {
405 int encoding;
406 switch (coding) {
407 case CIDCODING_GB:
408 encoding = FXFT_ENCODING_GB2312;
409 break;
410 case CIDCODING_BIG5:
411 encoding = FXFT_ENCODING_BIG5;
412 break;
413 case CIDCODING_JIS:
414 encoding = FXFT_ENCODING_SJIS;
415 break;
416 case CIDCODING_KOREA:
417 encoding = FXFT_ENCODING_JOHAB;
418 break;
419 default:
420 encoding = FXFT_ENCODING_UNICODE;
421 }
422 int err = FXFT_Select_Charmap(face, encoding);
423 if (err) {
424 err = FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE);
425 }
426 if (err && FXFT_Get_Face_Charmaps(face)) {
427 FXFT_Set_Charmap(face, *FXFT_Get_Face_Charmaps(face));
428 }
429 }
430
431 const struct CIDTransform {
432 FX_WORD CID;
433 uint8_t a, b, c, d, e, f;
434 } g_Japan1_VertCIDs[] = {
435 {97, 129, 0, 0, 127, 55, 0},
436 {7887, 127, 0, 0, 127, 76, 89},
437 {7888, 127, 0, 0, 127, 79, 94},
438 {7889, 0, 129, 127, 0, 17, 127},
439 {7890, 0, 129, 127, 0, 17, 127},
440 {7891, 0, 129, 127, 0, 17, 127},
441 {7892, 0, 129, 127, 0, 17, 127},
442 {7893, 0, 129, 127, 0, 17, 127},
443 {7894, 0, 129, 127, 0, 17, 127},
444 {7895, 0, 129, 127, 0, 17, 127},
445 {7896, 0, 129, 127, 0, 17, 127},
446 {7897, 0, 129, 127, 0, 17, 127},
447 {7898, 0, 129, 127, 0, 17, 127},
448 {7899, 0, 129, 127, 0, 17, 104},
449 {7900, 0, 129, 127, 0, 17, 127},
450 {7901, 0, 129, 127, 0, 17, 104},
451 {7902, 0, 129, 127, 0, 17, 127},
452 {7903, 0, 129, 127, 0, 17, 127},
453 {7904, 0, 129, 127, 0, 17, 127},
454 {7905, 0, 129, 127, 0, 17, 114},
455 {7906, 0, 129, 127, 0, 17, 127},
456 {7907, 0, 129, 127, 0, 17, 127},
457 {7908, 0, 129, 127, 0, 17, 127},
458 {7909, 0, 129, 127, 0, 17, 127},
459 {7910, 0, 129, 127, 0, 17, 127},
460 {7911, 0, 129, 127, 0, 17, 127},
461 {7912, 0, 129, 127, 0, 17, 127},
462 {7913, 0, 129, 127, 0, 17, 127},
463 {7914, 0, 129, 127, 0, 17, 127},
464 {7915, 0, 129, 127, 0, 17, 114},
465 {7916, 0, 129, 127, 0, 17, 127},
466 {7917, 0, 129, 127, 0, 17, 127},
467 {7918, 127, 0, 0, 127, 18, 25},
468 {7919, 127, 0, 0, 127, 18, 25},
469 {7920, 127, 0, 0, 127, 18, 25},
470 {7921, 127, 0, 0, 127, 18, 25},
471 {7922, 127, 0, 0, 127, 18, 25},
472 {7923, 127, 0, 0, 127, 18, 25},
473 {7924, 127, 0, 0, 127, 18, 25},
474 {7925, 127, 0, 0, 127, 18, 25},
475 {7926, 127, 0, 0, 127, 18, 25},
476 {7927, 127, 0, 0, 127, 18, 25},
477 {7928, 127, 0, 0, 127, 18, 25},
478 {7929, 127, 0, 0, 127, 18, 25},
479 {7930, 127, 0, 0, 127, 18, 25},
480 {7931, 127, 0, 0, 127, 18, 25},
481 {7932, 127, 0, 0, 127, 18, 25},
482 {7933, 127, 0, 0, 127, 18, 25},
483 {7934, 127, 0, 0, 127, 18, 25},
484 {7935, 127, 0, 0, 127, 18, 25},
485 {7936, 127, 0, 0, 127, 18, 25},
486 {7937, 127, 0, 0, 127, 18, 25},
487 {7938, 127, 0, 0, 127, 18, 25},
488 {7939, 127, 0, 0, 127, 18, 25},
489 {8720, 0, 129, 127, 0, 19, 102},
490 {8721, 0, 129, 127, 0, 13, 127},
491 {8722, 0, 129, 127, 0, 19, 108},
492 {8723, 0, 129, 127, 0, 19, 102},
493 {8724, 0, 129, 127, 0, 19, 102},
494 {8725, 0, 129, 127, 0, 19, 102},
495 {8726, 0, 129, 127, 0, 19, 102},
496 {8727, 0, 129, 127, 0, 19, 102},
497 {8728, 0, 129, 127, 0, 19, 114},
498 {8729, 0, 129, 127, 0, 19, 114},
499 {8730, 0, 129, 127, 0, 38, 108},
500 {8731, 0, 129, 127, 0, 13, 108},
501 {8732, 0, 129, 127, 0, 19, 108},
502 {8733, 0, 129, 127, 0, 19, 108},
503 {8734, 0, 129, 127, 0, 19, 108},
504 {8735, 0, 129, 127, 0, 19, 108},
505 {8736, 0, 129, 127, 0, 19, 102},
506 {8737, 0, 129, 127, 0, 19, 102},
507 {8738, 0, 129, 127, 0, 19, 102},
508 {8739, 0, 129, 127, 0, 19, 102},
509 {8740, 0, 129, 127, 0, 19, 102},
510 {8741, 0, 129, 127, 0, 19, 102},
511 {8742, 0, 129, 127, 0, 19, 102},
512 {8743, 0, 129, 127, 0, 19, 102},
513 {8744, 0, 129, 127, 0, 19, 102},
514 {8745, 0, 129, 127, 0, 19, 102},
515 {8746, 0, 129, 127, 0, 19, 114},
516 {8747, 0, 129, 127, 0, 19, 114},
517 {8748, 0, 129, 127, 0, 19, 102},
518 {8749, 0, 129, 127, 0, 19, 102},
519 {8750, 0, 129, 127, 0, 19, 102},
520 {8751, 0, 129, 127, 0, 19, 102},
521 {8752, 0, 129, 127, 0, 19, 102},
522 {8753, 0, 129, 127, 0, 19, 102},
523 {8754, 0, 129, 127, 0, 19, 102},
524 {8755, 0, 129, 127, 0, 19, 102},
525 {8756, 0, 129, 127, 0, 19, 102},
526 {8757, 0, 129, 127, 0, 19, 102},
527 {8758, 0, 129, 127, 0, 19, 102},
528 {8759, 0, 129, 127, 0, 19, 102},
529 {8760, 0, 129, 127, 0, 19, 102},
530 {8761, 0, 129, 127, 0, 19, 102},
531 {8762, 0, 129, 127, 0, 19, 102},
532 {8763, 0, 129, 127, 0, 19, 102},
533 {8764, 0, 129, 127, 0, 19, 102},
534 {8765, 0, 129, 127, 0, 19, 102},
535 {8766, 0, 129, 127, 0, 19, 102},
536 {8767, 0, 129, 127, 0, 19, 102},
537 {8768, 0, 129, 127, 0, 19, 102},
538 {8769, 0, 129, 127, 0, 19, 102},
539 {8770, 0, 129, 127, 0, 19, 102},
540 {8771, 0, 129, 127, 0, 19, 102},
541 {8772, 0, 129, 127, 0, 19, 102},
542 {8773, 0, 129, 127, 0, 19, 102},
543 {8774, 0, 129, 127, 0, 19, 102},
544 {8775, 0, 129, 127, 0, 19, 102},
545 {8776, 0, 129, 127, 0, 19, 102},
546 {8777, 0, 129, 127, 0, 19, 102},
547 {8778, 0, 129, 127, 0, 19, 102},
548 {8779, 0, 129, 127, 0, 19, 114},
549 {8780, 0, 129, 127, 0, 19, 108},
550 {8781, 0, 129, 127, 0, 19, 114},
551 {8782, 0, 129, 127, 0, 13, 114},
552 {8783, 0, 129, 127, 0, 19, 108},
553 {8784, 0, 129, 127, 0, 13, 114},
554 {8785, 0, 129, 127, 0, 19, 108},
555 {8786, 0, 129, 127, 0, 19, 108},
556 {8787, 0, 129, 127, 0, 19, 108},
557 {8788, 0, 129, 127, 0, 19, 108},
558 {8789, 0, 129, 127, 0, 19, 108},
559 {8790, 0, 129, 127, 0, 19, 108},
560 {8791, 0, 129, 127, 0, 19, 108},
561 {8792, 0, 129, 127, 0, 19, 108},
562 {8793, 0, 129, 127, 0, 19, 108},
563 {8794, 0, 129, 127, 0, 19, 108},
564 {8795, 0, 129, 127, 0, 19, 108},
565 {8796, 0, 129, 127, 0, 19, 108},
566 {8797, 0, 129, 127, 0, 19, 108},
567 {8798, 0, 129, 127, 0, 19, 108},
568 {8799, 0, 129, 127, 0, 19, 108},
569 {8800, 0, 129, 127, 0, 19, 108},
570 {8801, 0, 129, 127, 0, 19, 108},
571 {8802, 0, 129, 127, 0, 19, 108},
572 {8803, 0, 129, 127, 0, 19, 108},
573 {8804, 0, 129, 127, 0, 19, 108},
574 {8805, 0, 129, 127, 0, 19, 108},
575 {8806, 0, 129, 127, 0, 19, 108},
576 {8807, 0, 129, 127, 0, 19, 108},
577 {8808, 0, 129, 127, 0, 19, 108},
578 {8809, 0, 129, 127, 0, 19, 108},
579 {8810, 0, 129, 127, 0, 19, 108},
580 {8811, 0, 129, 127, 0, 19, 114},
581 {8812, 0, 129, 127, 0, 19, 102},
582 {8813, 0, 129, 127, 0, 19, 114},
583 {8814, 0, 129, 127, 0, 76, 102},
584 {8815, 0, 129, 127, 0, 13, 121},
585 {8816, 0, 129, 127, 0, 19, 114},
586 {8817, 0, 129, 127, 0, 19, 127},
587 {8818, 0, 129, 127, 0, 19, 114},
588 {8819, 0, 129, 127, 0, 218, 108},
589 };
590
591 } // namespace
592
593 CPDF_CMapManager::CPDF_CMapManager() {
594 m_bPrompted = FALSE;
595 FXSYS_memset(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps);
596 }
597 CPDF_CMapManager::~CPDF_CMapManager() {
598 for (const auto& pair : m_CMaps) {
599 delete pair.second;
600 }
601 m_CMaps.clear();
602 for (size_t i = 0; i < FX_ArraySize(m_CID2UnicodeMaps); ++i) {
603 delete m_CID2UnicodeMaps[i];
604 }
605 }
606 CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name,
607 FX_BOOL bPromptCJK) {
608 auto it = m_CMaps.find(name);
609 if (it != m_CMaps.end()) {
610 return it->second;
611 }
612 CPDF_CMap* pCMap = LoadPredefinedCMap(name, bPromptCJK);
613 if (!name.IsEmpty()) {
614 m_CMaps[name] = pCMap;
615 }
616 return pCMap;
617 }
618 CPDF_CMap* CPDF_CMapManager::LoadPredefinedCMap(const CFX_ByteString& name,
619 FX_BOOL bPromptCJK) {
620 CPDF_CMap* pCMap = new CPDF_CMap;
621 const FX_CHAR* pname = name;
622 if (*pname == '/') {
623 pname++;
624 }
625 pCMap->LoadPredefined(this, pname, bPromptCJK);
626 return pCMap;
627 }
628
629 void CPDF_CMapManager::ReloadAll() {
630 for (const auto& pair : m_CMaps) {
631 CPDF_CMap* pCMap = pair.second;
632 pCMap->LoadPredefined(this, pair.first, FALSE);
633 }
634 for (size_t i = 0; i < FX_ArraySize(m_CID2UnicodeMaps); ++i) {
635 if (CPDF_CID2UnicodeMap* pMap = m_CID2UnicodeMaps[i]) {
636 pMap->Load(this, CIDSetFromSizeT(i), FALSE);
637 }
638 }
639 }
640 CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(CIDSet charset,
641 FX_BOOL bPromptCJK) {
642 if (!m_CID2UnicodeMaps[charset])
643 m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK);
644 return m_CID2UnicodeMaps[charset];
645 }
646 CPDF_CID2UnicodeMap* CPDF_CMapManager::LoadCID2UnicodeMap(CIDSet charset,
647 FX_BOOL bPromptCJK) {
648 CPDF_CID2UnicodeMap* pMap = new CPDF_CID2UnicodeMap();
649 if (!pMap->Initialize()) {
650 delete pMap;
651 return NULL;
652 }
653 pMap->Load(this, charset, bPromptCJK);
654 return pMap;
655 }
656 CPDF_CMapParser::CPDF_CMapParser() {
657 m_pCMap = NULL;
658 m_Status = 0;
659 m_CodeSeq = 0;
660 }
661 FX_BOOL CPDF_CMapParser::Initialize(CPDF_CMap* pCMap) {
662 m_pCMap = pCMap;
663 m_Status = 0;
664 m_CodeSeq = 0;
665 m_AddMaps.EstimateSize(0, 10240);
666 return TRUE;
667 }
668
669 void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) {
670 if (word.IsEmpty()) {
671 return;
672 }
673 if (word == FX_BSTRC("begincidchar")) {
674 m_Status = 1;
675 m_CodeSeq = 0;
676 } else if (word == FX_BSTRC("begincidrange")) {
677 m_Status = 2;
678 m_CodeSeq = 0;
679 } else if (word == FX_BSTRC("endcidrange") ||
680 word == FX_BSTRC("endcidchar")) {
681 m_Status = 0;
682 } else if (word == FX_BSTRC("/WMode")) {
683 m_Status = 6;
684 } else if (word == FX_BSTRC("/Registry")) {
685 m_Status = 3;
686 } else if (word == FX_BSTRC("/Ordering")) {
687 m_Status = 4;
688 } else if (word == FX_BSTRC("/Supplement")) {
689 m_Status = 5;
690 } else if (word == FX_BSTRC("begincodespacerange")) {
691 m_Status = 7;
692 m_CodeSeq = 0;
693 } else if (word == FX_BSTRC("usecmap")) {
694 } else if (m_Status == 1 || m_Status == 2) {
695 m_CodePoints[m_CodeSeq] = CMap_GetCode(word);
696 m_CodeSeq++;
697 FX_DWORD StartCode, EndCode;
698 FX_WORD StartCID;
699 if (m_Status == 1) {
700 if (m_CodeSeq < 2) {
701 return;
702 }
703 EndCode = StartCode = m_CodePoints[0];
704 StartCID = (FX_WORD)m_CodePoints[1];
705 } else {
706 if (m_CodeSeq < 3) {
707 return;
708 }
709 StartCode = m_CodePoints[0];
710 EndCode = m_CodePoints[1];
711 StartCID = (FX_WORD)m_CodePoints[2];
712 }
713 if (EndCode < 0x10000) {
714 for (FX_DWORD code = StartCode; code <= EndCode; code++) {
715 m_pCMap->m_pMapping[code] = (FX_WORD)(StartCID + code - StartCode);
716 }
717 } else {
718 FX_DWORD buf[2];
719 buf[0] = StartCode;
720 buf[1] = ((EndCode - StartCode) << 16) + StartCID;
721 m_AddMaps.AppendBlock(buf, sizeof buf);
722 }
723 m_CodeSeq = 0;
724 } else if (m_Status == 3) {
725 CMap_GetString(word);
726 m_Status = 0;
727 } else if (m_Status == 4) {
728 m_pCMap->m_Charset = CharsetFromOrdering(CMap_GetString(word));
729 m_Status = 0;
730 } else if (m_Status == 5) {
731 CMap_GetCode(word);
732 m_Status = 0;
733 } else if (m_Status == 6) {
734 m_pCMap->m_bVertical = CMap_GetCode(word);
735 m_Status = 0;
736 } else if (m_Status == 7) {
737 if (word == FX_BSTRC("endcodespacerange")) {
738 int nSegs = m_CodeRanges.GetSize();
739 if (nSegs > 1) {
740 m_pCMap->m_CodingScheme = CPDF_CMap::MixedFourBytes;
741 m_pCMap->m_nCodeRanges = nSegs;
742 m_pCMap->m_pLeadingBytes =
743 FX_Alloc2D(uint8_t, nSegs, sizeof(CMap_CodeRange));
744 FXSYS_memcpy(m_pCMap->m_pLeadingBytes, m_CodeRanges.GetData(),
745 nSegs * sizeof(CMap_CodeRange));
746 } else if (nSegs == 1) {
747 m_pCMap->m_CodingScheme = (m_CodeRanges[0].m_CharSize == 2)
748 ? CPDF_CMap::TwoBytes
749 : CPDF_CMap::OneByte;
750 }
751 m_Status = 0;
752 } else {
753 if (word.GetLength() == 0 || word.GetAt(0) != '<') {
754 return;
755 }
756 if (m_CodeSeq % 2) {
757 CMap_CodeRange range;
758 if (CMap_GetCodeRange(range, m_LastWord, word)) {
759 m_CodeRanges.Add(range);
760 }
761 }
762 m_CodeSeq++;
763 }
764 }
765 m_LastWord = word;
766 }
767 CPDF_CMap::CPDF_CMap() {
768 m_Charset = CIDSET_UNKNOWN;
769 m_Coding = CIDCODING_UNKNOWN;
770 m_CodingScheme = TwoBytes;
771 m_bVertical = 0;
772 m_bLoaded = FALSE;
773 m_pMapping = NULL;
774 m_pLeadingBytes = NULL;
775 m_pAddMapping = NULL;
776 m_pEmbedMap = NULL;
777 m_pUseMap = NULL;
778 m_nCodeRanges = 0;
779 }
780 CPDF_CMap::~CPDF_CMap() {
781 FX_Free(m_pMapping);
782 FX_Free(m_pAddMapping);
783 FX_Free(m_pLeadingBytes);
784 delete m_pUseMap;
785 }
786 void CPDF_CMap::Release() {
787 if (m_PredefinedCMap.IsEmpty()) {
788 delete this;
789 }
790 }
433 791
434 FX_BOOL CPDF_CMap::LoadPredefined(CPDF_CMapManager* pMgr, 792 FX_BOOL CPDF_CMap::LoadPredefined(CPDF_CMapManager* pMgr,
435 const FX_CHAR* pName, 793 const FX_CHAR* pName,
436 FX_BOOL bPromptCJK) { 794 FX_BOOL bPromptCJK) {
437 m_PredefinedCMap = pName; 795 m_PredefinedCMap = pName;
438 if (m_PredefinedCMap == FX_BSTRC("Identity-H") || 796 if (m_PredefinedCMap == FX_BSTRC("Identity-H") ||
439 m_PredefinedCMap == FX_BSTRC("Identity-V")) { 797 m_PredefinedCMap == FX_BSTRC("Identity-V")) {
440 m_Coding = CIDCODING_CID; 798 m_Coding = CIDCODING_CID;
441 m_bVertical = pName[9] == 'V'; 799 m_bVertical = pName[9] == 'V';
442 m_bLoaded = TRUE; 800 m_bLoaded = TRUE;
443 return TRUE; 801 return TRUE;
444 } 802 }
445 CFX_ByteString cmapid = m_PredefinedCMap; 803 CFX_ByteString cmapid = m_PredefinedCMap;
446 m_bVertical = cmapid.Right(1) == FX_BSTRC("V"); 804 m_bVertical = cmapid.Right(1) == FX_BSTRC("V");
447 if (cmapid.GetLength() > 2) { 805 if (cmapid.GetLength() > 2) {
448 cmapid = cmapid.Left(cmapid.GetLength() - 2); 806 cmapid = cmapid.Left(cmapid.GetLength() - 2);
449 } 807 }
450 int index = 0; 808 const CPDF_PredefinedCMap* map = nullptr;
451 while (1) { 809 for (size_t i = 0; i < FX_ArraySize(g_PredefinedCMaps); ++i) {
452 if (g_PredefinedCMaps[index].m_pName == NULL) { 810 if (cmapid == CFX_ByteStringC(g_PredefinedCMaps[i].m_pName)) {
453 return FALSE; 811 map = &g_PredefinedCMaps[i];
454 }
455 if (cmapid == CFX_ByteStringC(g_PredefinedCMaps[index].m_pName)) {
456 break; 812 break;
457 } 813 }
458 index++;
459 } 814 }
460 const CPDF_PredefinedCMap& map = g_PredefinedCMaps[index]; 815 if (!map)
461 m_Charset = map.m_Charset; 816 return FALSE;
462 m_Coding = map.m_Coding; 817
463 m_CodingScheme = map.m_CodingScheme; 818 m_Charset = map->m_Charset;
819 m_Coding = map->m_Coding;
820 m_CodingScheme = map->m_CodingScheme;
464 if (m_CodingScheme == MixedTwoBytes) { 821 if (m_CodingScheme == MixedTwoBytes) {
465 m_pLeadingBytes = FX_Alloc(uint8_t, 256); 822 m_pLeadingBytes = FX_Alloc(uint8_t, 256);
466 for (FX_DWORD i = 0; i < map.m_LeadingSegCount; i++) { 823 for (FX_DWORD i = 0; i < map->m_LeadingSegCount; ++i) {
467 for (int b = map.m_LeadingSegs[i * 2]; b <= map.m_LeadingSegs[i * 2 + 1]; 824 const uint8_t* segs = map->m_LeadingSegs;
468 b++) { 825 for (int b = segs[i * 2]; b <= segs[i * 2 + 1]; ++b) {
469 m_pLeadingBytes[b] = 1; 826 m_pLeadingBytes[b] = 1;
470 } 827 }
471 } 828 }
472 } 829 }
473 FPDFAPI_FindEmbeddedCMap(pName, m_Charset, m_Coding, m_pEmbedMap); 830 FPDFAPI_FindEmbeddedCMap(pName, m_Charset, m_Coding, m_pEmbedMap);
474 if (m_pEmbedMap) { 831 if (m_pEmbedMap) {
475 m_bLoaded = TRUE; 832 m_bLoaded = TRUE;
476 return TRUE; 833 return TRUE;
477 } 834 }
478 return FALSE; 835 return FALSE;
479 } 836 }
480 extern "C" {
481 static int compare_dword(const void* data1, const void* data2) {
482 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2);
483 }
484 };
485 FX_BOOL CPDF_CMap::LoadEmbedded(const uint8_t* pData, FX_DWORD size) { 837 FX_BOOL CPDF_CMap::LoadEmbedded(const uint8_t* pData, FX_DWORD size) {
486 m_pMapping = FX_Alloc(FX_WORD, 65536); 838 m_pMapping = FX_Alloc(FX_WORD, 65536);
487 CPDF_CMapParser parser; 839 CPDF_CMapParser parser;
488 parser.Initialize(this); 840 parser.Initialize(this);
489 CPDF_SimpleParser syntax(pData, size); 841 CPDF_SimpleParser syntax(pData, size);
490 while (1) { 842 while (1) {
491 CFX_ByteStringC word = syntax.GetWord(); 843 CFX_ByteStringC word = syntax.GetWord();
492 if (word.IsEmpty()) { 844 if (word.IsEmpty()) {
493 break; 845 break;
494 } 846 }
495 parser.ParseWord(word); 847 parser.ParseWord(word);
496 } 848 }
497 if (m_CodingScheme == MixedFourBytes && parser.m_AddMaps.GetSize()) { 849 if (m_CodingScheme == MixedFourBytes && parser.m_AddMaps.GetSize()) {
498 m_pAddMapping = FX_Alloc(uint8_t, parser.m_AddMaps.GetSize() + 4); 850 m_pAddMapping = FX_Alloc(uint8_t, parser.m_AddMaps.GetSize() + 4);
499 *(FX_DWORD*)m_pAddMapping = parser.m_AddMaps.GetSize() / 8; 851 *(FX_DWORD*)m_pAddMapping = parser.m_AddMaps.GetSize() / 8;
500 FXSYS_memcpy(m_pAddMapping + 4, parser.m_AddMaps.GetBuffer(), 852 FXSYS_memcpy(m_pAddMapping + 4, parser.m_AddMaps.GetBuffer(),
501 parser.m_AddMaps.GetSize()); 853 parser.m_AddMaps.GetSize());
502 FXSYS_qsort(m_pAddMapping + 4, parser.m_AddMaps.GetSize() / 8, 8, 854 FXSYS_qsort(m_pAddMapping + 4, parser.m_AddMaps.GetSize() / 8, 8,
503 compare_dword); 855 CompareDWORD);
504 } 856 }
505 return TRUE; 857 return TRUE;
506 } 858 }
507 extern "C" { 859
508 static int compareCID(const void* key, const void* element) {
509 if ((*(FX_DWORD*)key) < (*(FX_DWORD*)element)) {
510 return -1;
511 }
512 if ((*(FX_DWORD*)key) >
513 (*(FX_DWORD*)element) + ((FX_DWORD*)element)[1] / 65536) {
514 return 1;
515 }
516 return 0;
517 }
518 };
519 FX_WORD CPDF_CMap::CIDFromCharCode(FX_DWORD charcode) const { 860 FX_WORD CPDF_CMap::CIDFromCharCode(FX_DWORD charcode) const {
520 if (m_Coding == CIDCODING_CID) { 861 if (m_Coding == CIDCODING_CID) {
521 return (FX_WORD)charcode; 862 return (FX_WORD)charcode;
522 } 863 }
523 if (m_pEmbedMap) { 864 if (m_pEmbedMap) {
524 return FPDFAPI_CIDFromCharCode(m_pEmbedMap, charcode); 865 return FPDFAPI_CIDFromCharCode(m_pEmbedMap, charcode);
525 } 866 }
526 if (m_pMapping == NULL) { 867 if (m_pMapping == NULL) {
527 return (FX_WORD)charcode; 868 return (FX_WORD)charcode;
528 } 869 }
529 if (charcode >> 16) { 870 if (charcode >> 16) {
530 if (m_pAddMapping) { 871 if (m_pAddMapping) {
531 void* found = FXSYS_bsearch(&charcode, m_pAddMapping + 4, 872 void* found = FXSYS_bsearch(&charcode, m_pAddMapping + 4,
532 *(FX_DWORD*)m_pAddMapping, 8, compareCID); 873 *(FX_DWORD*)m_pAddMapping, 8, CompareCID);
533 if (found == NULL) { 874 if (found == NULL) {
534 if (m_pUseMap) { 875 if (m_pUseMap) {
535 return m_pUseMap->CIDFromCharCode(charcode); 876 return m_pUseMap->CIDFromCharCode(charcode);
536 } 877 }
537 return 0; 878 return 0;
538 } 879 }
539 return (FX_WORD)(((FX_DWORD*)found)[1] % 65536 + charcode - 880 return (FX_WORD)(((FX_DWORD*)found)[1] % 65536 + charcode -
540 *(FX_DWORD*)found); 881 *(FX_DWORD*)found);
541 } 882 }
542 if (m_pUseMap) { 883 if (m_pUseMap)
543 return m_pUseMap->CIDFromCharCode(charcode); 884 return m_pUseMap->CIDFromCharCode(charcode);
544 }
545 return 0; 885 return 0;
546 } 886 }
547 FX_DWORD CID = m_pMapping[charcode]; 887 FX_DWORD CID = m_pMapping[charcode];
548 if (!CID && m_pUseMap) { 888 if (!CID && m_pUseMap)
549 return m_pUseMap->CIDFromCharCode(charcode); 889 return m_pUseMap->CIDFromCharCode(charcode);
550 }
551 return (FX_WORD)CID; 890 return (FX_WORD)CID;
552 } 891 }
553 static int _CheckCodeRange(uint8_t* codes, 892
554 int size,
555 _CMap_CodeRange* pRanges,
556 int nRanges) {
557 int iSeg = nRanges - 1;
558 while (iSeg >= 0) {
559 if (pRanges[iSeg].m_CharSize < size) {
560 iSeg--;
561 continue;
562 }
563 int iChar = 0;
564 while (iChar < size) {
565 if (codes[iChar] < pRanges[iSeg].m_Lower[iChar] ||
566 codes[iChar] > pRanges[iSeg].m_Upper[iChar]) {
567 break;
568 }
569 iChar++;
570 }
571 if (iChar == pRanges[iSeg].m_CharSize) {
572 return 2;
573 }
574 if (iChar) {
575 if (size == pRanges[iSeg].m_CharSize) {
576 return 2;
577 }
578 return 1;
579 }
580 iSeg--;
581 }
582 return 0;
583 }
584 FX_DWORD CPDF_CMap::GetNextChar(const FX_CHAR* pString, 893 FX_DWORD CPDF_CMap::GetNextChar(const FX_CHAR* pString,
585 int nStrLen, 894 int nStrLen,
586 int& offset) const { 895 int& offset) const {
587 switch (m_CodingScheme) { 896 switch (m_CodingScheme) {
588 case OneByte: 897 case OneByte:
589 return ((uint8_t*)pString)[offset++]; 898 return ((uint8_t*)pString)[offset++];
590 case TwoBytes: 899 case TwoBytes:
591 offset += 2; 900 offset += 2;
592 return ((uint8_t*)pString)[offset - 2] * 256 + 901 return ((uint8_t*)pString)[offset - 2] * 256 +
593 ((uint8_t*)pString)[offset - 1]; 902 ((uint8_t*)pString)[offset - 1];
594 case MixedTwoBytes: { 903 case MixedTwoBytes: {
595 uint8_t byte1 = ((uint8_t*)pString)[offset++]; 904 uint8_t byte1 = ((uint8_t*)pString)[offset++];
596 if (!m_pLeadingBytes[byte1]) { 905 if (!m_pLeadingBytes[byte1]) {
597 return byte1; 906 return byte1;
598 } 907 }
599 uint8_t byte2 = ((uint8_t*)pString)[offset++]; 908 uint8_t byte2 = ((uint8_t*)pString)[offset++];
600 return byte1 * 256 + byte2; 909 return byte1 * 256 + byte2;
601 } 910 }
602 case MixedFourBytes: { 911 case MixedFourBytes: {
603 uint8_t codes[4]; 912 uint8_t codes[4];
604 int char_size = 1; 913 int char_size = 1;
605 codes[0] = ((uint8_t*)pString)[offset++]; 914 codes[0] = ((uint8_t*)pString)[offset++];
606 _CMap_CodeRange* pRanges = (_CMap_CodeRange*)m_pLeadingBytes; 915 CMap_CodeRange* pRanges = (CMap_CodeRange*)m_pLeadingBytes;
607 while (1) { 916 while (1) {
608 int ret = _CheckCodeRange(codes, char_size, pRanges, m_nCodeRanges); 917 int ret = CheckCodeRange(codes, char_size, pRanges, m_nCodeRanges);
609 if (ret == 0) { 918 if (ret == 0) {
610 return 0; 919 return 0;
611 } 920 }
612 if (ret == 2) { 921 if (ret == 2) {
613 FX_DWORD charcode = 0; 922 FX_DWORD charcode = 0;
614 for (int i = 0; i < char_size; i++) { 923 for (int i = 0; i < char_size; i++) {
615 charcode = (charcode << 8) + codes[i]; 924 charcode = (charcode << 8) + codes[i];
616 } 925 }
617 return charcode; 926 return charcode;
618 } 927 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 int count = 0, offset = 0; 976 int count = 0, offset = 0;
668 while (offset < size) { 977 while (offset < size) {
669 GetNextChar(pString, size, offset); 978 GetNextChar(pString, size, offset);
670 count++; 979 count++;
671 } 980 }
672 return count; 981 return count;
673 } 982 }
674 } 983 }
675 return size; 984 return size;
676 } 985 }
677 int _GetCharSize(FX_DWORD charcode, _CMap_CodeRange* pRanges, int iRangesSize) { 986
678 if (!iRangesSize) {
679 return 1;
680 }
681 uint8_t codes[4];
682 codes[0] = codes[1] = 0x00;
683 codes[2] = (uint8_t)(charcode >> 8 & 0xFF);
684 codes[3] = (uint8_t)charcode;
685 int offset = 0, size = 4;
686 for (int i = 0; i < 4; ++i) {
687 int iSeg = iRangesSize - 1;
688 while (iSeg >= 0) {
689 if (pRanges[iSeg].m_CharSize < size) {
690 iSeg--;
691 continue;
692 }
693 int iChar = 0;
694 while (iChar < size) {
695 if (codes[offset + iChar] < pRanges[iSeg].m_Lower[iChar] ||
696 codes[offset + iChar] > pRanges[iSeg].m_Upper[iChar]) {
697 break;
698 }
699 iChar++;
700 }
701 if (iChar == pRanges[iSeg].m_CharSize) {
702 return size;
703 }
704 iSeg--;
705 }
706 size--;
707 offset++;
708 }
709 return 1;
710 }
711 int CPDF_CMap::AppendChar(FX_CHAR* str, FX_DWORD charcode) const { 987 int CPDF_CMap::AppendChar(FX_CHAR* str, FX_DWORD charcode) const {
712 switch (m_CodingScheme) { 988 switch (m_CodingScheme) {
713 case OneByte: 989 case OneByte:
714 str[0] = (uint8_t)charcode; 990 str[0] = (uint8_t)charcode;
715 return 1; 991 return 1;
716 case TwoBytes: 992 case TwoBytes:
717 str[0] = (uint8_t)(charcode / 256); 993 str[0] = (uint8_t)(charcode / 256);
718 str[1] = (uint8_t)(charcode % 256); 994 str[1] = (uint8_t)(charcode % 256);
719 return 2; 995 return 2;
720 case MixedTwoBytes: 996 case MixedTwoBytes:
721 case MixedFourBytes: 997 case MixedFourBytes:
722 if (charcode < 0x100) { 998 if (charcode < 0x100) {
723 _CMap_CodeRange* pRanges = (_CMap_CodeRange*)m_pLeadingBytes; 999 CMap_CodeRange* pRanges = (CMap_CodeRange*)m_pLeadingBytes;
724 int iSize = _GetCharSize(charcode, pRanges, m_nCodeRanges); 1000 int iSize = GetCharSizeImpl(charcode, pRanges, m_nCodeRanges);
725 if (iSize == 0) { 1001 if (iSize == 0) {
726 iSize = 1; 1002 iSize = 1;
727 } 1003 }
728 if (iSize > 1) { 1004 if (iSize > 1) {
729 FXSYS_memset(str, 0, sizeof(uint8_t) * iSize); 1005 FXSYS_memset(str, 0, sizeof(uint8_t) * iSize);
730 } 1006 }
731 str[iSize - 1] = (uint8_t)charcode; 1007 str[iSize - 1] = (uint8_t)charcode;
732 return iSize; 1008 return iSize;
733 } 1009 }
734 if (charcode < 0x10000) { 1010 if (charcode < 0x10000) {
(...skipping 27 matching lines...) Expand all
762 } 1038 }
763 FX_WCHAR CPDF_CID2UnicodeMap::UnicodeFromCID(FX_WORD CID) { 1039 FX_WCHAR CPDF_CID2UnicodeMap::UnicodeFromCID(FX_WORD CID) {
764 if (m_Charset == CIDSET_UNICODE) { 1040 if (m_Charset == CIDSET_UNICODE) {
765 return CID; 1041 return CID;
766 } 1042 }
767 if (CID < m_EmbeddedCount) { 1043 if (CID < m_EmbeddedCount) {
768 return m_pEmbeddedMap[CID]; 1044 return m_pEmbeddedMap[CID];
769 } 1045 }
770 return 0; 1046 return 0;
771 } 1047 }
772 void FPDFAPI_LoadCID2UnicodeMap(int charset, 1048
773 const FX_WORD*& pMap,
774 FX_DWORD& count);
775 void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, 1049 void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr,
776 int charset, 1050 CIDSet charset,
777 FX_BOOL bPromptCJK) { 1051 FX_BOOL bPromptCJK) {
778 m_Charset = charset; 1052 m_Charset = charset;
779 FPDFAPI_LoadCID2UnicodeMap(charset, m_pEmbeddedMap, m_EmbeddedCount); 1053 FPDFAPI_LoadCID2UnicodeMap(charset, m_pEmbeddedMap, m_EmbeddedCount);
780 } 1054 }
1055
781 #include "ttgsubtable.h" 1056 #include "ttgsubtable.h"
782 CPDF_CIDFont::CPDF_CIDFont() : CPDF_Font(PDFFONT_CIDFONT) { 1057 CPDF_CIDFont::CPDF_CIDFont() : CPDF_Font(PDFFONT_CIDFONT) {
783 m_pCMap = NULL; 1058 m_pCMap = NULL;
784 m_pAllocatedCMap = NULL; 1059 m_pAllocatedCMap = NULL;
785 m_pCID2UnicodeMap = NULL; 1060 m_pCID2UnicodeMap = NULL;
786 m_pAnsiWidths = NULL; 1061 m_pAnsiWidths = NULL;
787 m_pCIDToGIDMap = NULL; 1062 m_pCIDToGIDMap = NULL;
788 m_bCIDIsGID = FALSE; 1063 m_bCIDIsGID = FALSE;
789 m_bAdobeCourierStd = FALSE; 1064 m_bAdobeCourierStd = FALSE;
790 m_pTTGSUBTable = NULL; 1065 m_pTTGSUBTable = NULL;
(...skipping 10 matching lines...) Expand all
801 FX_WORD CPDF_CIDFont::CIDFromCharCode(FX_DWORD charcode) const { 1076 FX_WORD CPDF_CIDFont::CIDFromCharCode(FX_DWORD charcode) const {
802 if (m_pCMap == NULL) { 1077 if (m_pCMap == NULL) {
803 return (FX_WORD)charcode; 1078 return (FX_WORD)charcode;
804 } 1079 }
805 return m_pCMap->CIDFromCharCode(charcode); 1080 return m_pCMap->CIDFromCharCode(charcode);
806 } 1081 }
807 FX_BOOL CPDF_CIDFont::IsVertWriting() const { 1082 FX_BOOL CPDF_CIDFont::IsVertWriting() const {
808 return m_pCMap ? m_pCMap->IsVertWriting() : FALSE; 1083 return m_pCMap ? m_pCMap->IsVertWriting() : FALSE;
809 } 1084 }
810 1085
811 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
812 static FX_DWORD _EmbeddedCharcodeFromUnicode(const FXCMAP_CMap* pEmbedMap,
813 int charset,
814 FX_WCHAR unicode) {
815 if (charset <= 0 || charset > 4) {
816 return 0;
817 }
818 CPDF_FontGlobals* pFontGlobals =
819 CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
820 const FX_WORD* pCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap;
821 if (pCodes == NULL) {
822 return 0;
823 }
824 int nCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count;
825 for (int i = 0; i < nCodes; i++) {
826 if (pCodes[i] == unicode) {
827 FX_DWORD CharCode = FPDFAPI_CharCodeFromCID(pEmbedMap, i);
828 if (CharCode == 0) {
829 continue;
830 }
831 return CharCode;
832 }
833 }
834 return 0;
835 }
836 #endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
837
838 static FX_WCHAR _EmbeddedUnicodeFromCharcode(const FXCMAP_CMap* pEmbedMap,
839 int charset,
840 FX_DWORD charcode) {
841 if (charset <= 0 || charset > 4) {
842 return 0;
843 }
844 FX_WORD cid = FPDFAPI_CIDFromCharCode(pEmbedMap, charcode);
845 if (cid == 0) {
846 return 0;
847 }
848 CPDF_FontGlobals* pFontGlobals =
849 CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
850 const FX_WORD* pCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap;
851 if (pCodes == NULL) {
852 return 0;
853 }
854 if (cid < pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count) {
855 return pCodes[cid];
856 }
857 return 0;
858 }
859 FX_WCHAR CPDF_CIDFont::_UnicodeFromCharCode(FX_DWORD charcode) const { 1086 FX_WCHAR CPDF_CIDFont::_UnicodeFromCharCode(FX_DWORD charcode) const {
860 switch (m_pCMap->m_Coding) { 1087 switch (m_pCMap->m_Coding) {
861 case CIDCODING_UCS2: 1088 case CIDCODING_UCS2:
862 case CIDCODING_UTF16: 1089 case CIDCODING_UTF16:
863 return (FX_WCHAR)charcode; 1090 return (FX_WCHAR)charcode;
864 case CIDCODING_CID: 1091 case CIDCODING_CID:
865 if (m_pCID2UnicodeMap == NULL || !m_pCID2UnicodeMap->IsLoaded()) { 1092 if (m_pCID2UnicodeMap == NULL || !m_pCID2UnicodeMap->IsLoaded()) {
866 return 0; 1093 return 0;
867 } 1094 }
868 return m_pCID2UnicodeMap->UnicodeFromCID((FX_WORD)charcode); 1095 return m_pCID2UnicodeMap->UnicodeFromCID((FX_WORD)charcode);
869 } 1096 }
870 if (!m_pCMap->IsLoaded() || m_pCID2UnicodeMap == NULL || 1097 if (!m_pCMap->IsLoaded() || m_pCID2UnicodeMap == NULL ||
871 !m_pCID2UnicodeMap->IsLoaded()) { 1098 !m_pCID2UnicodeMap->IsLoaded()) {
872 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 1099 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
873 FX_WCHAR unicode; 1100 FX_WCHAR unicode;
874 int charsize = 1; 1101 int charsize = 1;
875 if (charcode > 255) { 1102 if (charcode > 255) {
876 charcode = (charcode % 256) * 256 + (charcode / 256); 1103 charcode = (charcode % 256) * 256 + (charcode / 256);
877 charsize = 2; 1104 charsize = 2;
878 } 1105 }
879 int ret = FXSYS_MultiByteToWideChar(g_CharsetCPs[m_pCMap->m_Coding], 0, 1106 int ret = FXSYS_MultiByteToWideChar(g_CharsetCPs[m_pCMap->m_Coding], 0,
880 (const FX_CHAR*)&charcode, charsize, 1107 (const FX_CHAR*)&charcode, charsize,
881 &unicode, 1); 1108 &unicode, 1);
882 if (ret != 1) { 1109 if (ret != 1) {
883 return 0; 1110 return 0;
884 } 1111 }
885 return unicode; 1112 return unicode;
886 #endif 1113 #endif
887 if (m_pCMap->m_pEmbedMap) { 1114 if (m_pCMap->m_pEmbedMap) {
888 return _EmbeddedUnicodeFromCharcode(m_pCMap->m_pEmbedMap, 1115 return EmbeddedUnicodeFromCharcode(m_pCMap->m_pEmbedMap,
889 m_pCMap->m_Charset, charcode); 1116 m_pCMap->m_Charset, charcode);
890 } 1117 }
891 return 0; 1118 return 0;
892 } 1119 }
893 return m_pCID2UnicodeMap->UnicodeFromCID(CIDFromCharCode(charcode)); 1120 return m_pCID2UnicodeMap->UnicodeFromCID(CIDFromCharCode(charcode));
894 } 1121 }
895 FX_DWORD CPDF_CIDFont::_CharCodeFromUnicode(FX_WCHAR unicode) const { 1122 FX_DWORD CPDF_CIDFont::_CharCodeFromUnicode(FX_WCHAR unicode) const {
896 switch (m_pCMap->m_Coding) { 1123 switch (m_pCMap->m_Coding) {
897 case CIDCODING_UNKNOWN: 1124 case CIDCODING_UNKNOWN:
898 return 0; 1125 return 0;
899 case CIDCODING_UCS2: 1126 case CIDCODING_UCS2:
(...skipping 27 matching lines...) Expand all
927 FXSYS_WideCharToMultiByte(g_CharsetCPs[m_pCMap->m_Coding], 0, &unicode, 1, 1154 FXSYS_WideCharToMultiByte(g_CharsetCPs[m_pCMap->m_Coding], 0, &unicode, 1,
928 (char*)buffer, 4, NULL, NULL); 1155 (char*)buffer, 4, NULL, NULL);
929 if (ret == 1) { 1156 if (ret == 1) {
930 return buffer[0]; 1157 return buffer[0];
931 } 1158 }
932 if (ret == 2) { 1159 if (ret == 2) {
933 return buffer[0] * 256 + buffer[1]; 1160 return buffer[0] * 256 + buffer[1];
934 } 1161 }
935 #else 1162 #else
936 if (m_pCMap->m_pEmbedMap) { 1163 if (m_pCMap->m_pEmbedMap) {
937 return _EmbeddedCharcodeFromUnicode(m_pCMap->m_pEmbedMap, 1164 return EmbeddedCharcodeFromUnicode(m_pCMap->m_pEmbedMap, m_pCMap->m_Charset,
938 m_pCMap->m_Charset, unicode); 1165 unicode);
939 } 1166 }
940 #endif 1167 #endif
941 return 0; 1168 return 0;
942 } 1169 }
943 static void FT_UseCIDCharmap(FXFT_Face face, int coding) { 1170
944 int encoding;
945 switch (coding) {
946 case CIDCODING_GB:
947 encoding = FXFT_ENCODING_GB2312;
948 break;
949 case CIDCODING_BIG5:
950 encoding = FXFT_ENCODING_BIG5;
951 break;
952 case CIDCODING_JIS:
953 encoding = FXFT_ENCODING_SJIS;
954 break;
955 case CIDCODING_KOREA:
956 encoding = FXFT_ENCODING_JOHAB;
957 break;
958 default:
959 encoding = FXFT_ENCODING_UNICODE;
960 }
961 int err = FXFT_Select_Charmap(face, encoding);
962 if (err) {
963 err = FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE);
964 }
965 if (err && FXFT_Get_Face_Charmaps(face)) {
966 FXFT_Set_Charmap(face, *FXFT_Get_Face_Charmaps(face));
967 }
968 }
969 FX_BOOL CPDF_CIDFont::_Load() { 1171 FX_BOOL CPDF_CIDFont::_Load() {
970 if (m_pFontDict->GetString(FX_BSTRC("Subtype")) == FX_BSTRC("TrueType")) { 1172 if (m_pFontDict->GetString(FX_BSTRC("Subtype")) == FX_BSTRC("TrueType")) {
971 return LoadGB2312(); 1173 return LoadGB2312();
972 } 1174 }
973 CPDF_Array* pFonts = m_pFontDict->GetArray(FX_BSTRC("DescendantFonts")); 1175 CPDF_Array* pFonts = m_pFontDict->GetArray(FX_BSTRC("DescendantFonts"));
974 if (pFonts == NULL) { 1176 if (pFonts == NULL) {
975 return FALSE; 1177 return FALSE;
976 } 1178 }
977 if (pFonts->GetCount() != 1) { 1179 if (pFonts->GetCount() != 1) {
978 return FALSE; 1180 return FALSE;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 } 1223 }
1022 if (m_pCMap == NULL) { 1224 if (m_pCMap == NULL) {
1023 return FALSE; 1225 return FALSE;
1024 } 1226 }
1025 m_Charset = m_pCMap->m_Charset; 1227 m_Charset = m_pCMap->m_Charset;
1026 if (m_Charset == CIDSET_UNKNOWN) { 1228 if (m_Charset == CIDSET_UNKNOWN) {
1027 CPDF_Dictionary* pCIDInfo = 1229 CPDF_Dictionary* pCIDInfo =
1028 pCIDFontDict->GetDict(FX_BSTRC("CIDSystemInfo")); 1230 pCIDFontDict->GetDict(FX_BSTRC("CIDSystemInfo"));
1029 if (pCIDInfo) { 1231 if (pCIDInfo) {
1030 m_Charset = 1232 m_Charset =
1031 _CharsetFromOrdering(pCIDInfo->GetString(FX_BSTRC("Ordering"))); 1233 CharsetFromOrdering(pCIDInfo->GetString(FX_BSTRC("Ordering")));
1032 } 1234 }
1033 } 1235 }
1034 if (m_Charset != CIDSET_UNKNOWN) 1236 if (m_Charset != CIDSET_UNKNOWN)
1035 m_pCID2UnicodeMap = 1237 m_pCID2UnicodeMap =
1036 CPDF_ModuleMgr::Get() 1238 CPDF_ModuleMgr::Get()
1037 ->GetPageModule() 1239 ->GetPageModule()
1038 ->GetFontGlobals() 1240 ->GetFontGlobals()
1039 ->m_CMapManager.GetCID2UnicodeMap( 1241 ->m_CMapManager.GetCID2UnicodeMap(
1040 m_Charset, 1242 m_Charset,
1041 m_pFontFile == NULL && (m_pCMap->m_Coding == CIDCODING_CID || 1243 m_pFontFile == NULL && (m_pCMap->m_Coding == CIDCODING_CID ||
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 if (pDefaultArray) { 1287 if (pDefaultArray) {
1086 m_DefaultVY = pDefaultArray->GetInteger(0); 1288 m_DefaultVY = pDefaultArray->GetInteger(0);
1087 m_DefaultW1 = pDefaultArray->GetInteger(1); 1289 m_DefaultW1 = pDefaultArray->GetInteger(1);
1088 } else { 1290 } else {
1089 m_DefaultVY = 880; 1291 m_DefaultVY = 880;
1090 m_DefaultW1 = -1000; 1292 m_DefaultW1 = -1000;
1091 } 1293 }
1092 } 1294 }
1093 return TRUE; 1295 return TRUE;
1094 } 1296 }
1095 FX_FLOAT _CIDTransformToFloat(uint8_t ch) { 1297
1096 if (ch < 128) {
1097 return ch * 1.0f / 127;
1098 }
1099 return (-255 + ch) * 1.0f / 127;
1100 }
1101 void CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) { 1298 void CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) {
1102 if (charcode < 256 && m_CharBBox[charcode].Right != -1) { 1299 if (charcode < 256 && m_CharBBox[charcode].Right != -1) {
1103 rect.bottom = m_CharBBox[charcode].Bottom; 1300 rect.bottom = m_CharBBox[charcode].Bottom;
1104 rect.left = m_CharBBox[charcode].Left; 1301 rect.left = m_CharBBox[charcode].Left;
1105 rect.right = m_CharBBox[charcode].Right; 1302 rect.right = m_CharBBox[charcode].Right;
1106 rect.top = m_CharBBox[charcode].Top; 1303 rect.top = m_CharBBox[charcode].Top;
1107 return; 1304 return;
1108 } 1305 }
1109 FX_BOOL bVert = FALSE; 1306 FX_BOOL bVert = FALSE;
1110 int glyph_index = GlyphFromCharCode(charcode, &bVert); 1307 int glyph_index = GlyphFromCharCode(charcode, &bVert);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 face); 1353 face);
1157 } 1354 }
1158 } 1355 }
1159 } else { 1356 } else {
1160 rect = FX_RECT(0, 0, 0, 0); 1357 rect = FX_RECT(0, 0, 0, 0);
1161 } 1358 }
1162 if (m_pFontFile == NULL && m_Charset == CIDSET_JAPAN1) { 1359 if (m_pFontFile == NULL && m_Charset == CIDSET_JAPAN1) {
1163 FX_WORD CID = CIDFromCharCode(charcode); 1360 FX_WORD CID = CIDFromCharCode(charcode);
1164 const uint8_t* pTransform = GetCIDTransform(CID); 1361 const uint8_t* pTransform = GetCIDTransform(CID);
1165 if (pTransform && !bVert) { 1362 if (pTransform && !bVert) {
1166 CFX_AffineMatrix matrix(_CIDTransformToFloat(pTransform[0]), 1363 CFX_AffineMatrix matrix(CIDTransformToFloat(pTransform[0]),
1167 _CIDTransformToFloat(pTransform[1]), 1364 CIDTransformToFloat(pTransform[1]),
1168 _CIDTransformToFloat(pTransform[2]), 1365 CIDTransformToFloat(pTransform[2]),
1169 _CIDTransformToFloat(pTransform[3]), 1366 CIDTransformToFloat(pTransform[3]),
1170 _CIDTransformToFloat(pTransform[4]) * 1000, 1367 CIDTransformToFloat(pTransform[4]) * 1000,
1171 _CIDTransformToFloat(pTransform[5]) * 1000); 1368 CIDTransformToFloat(pTransform[5]) * 1000);
1172 CFX_FloatRect rect_f(rect); 1369 CFX_FloatRect rect_f(rect);
1173 rect_f.Transform(&matrix); 1370 rect_f.Transform(&matrix);
1174 rect = rect_f.GetOutterRect(); 1371 rect = rect_f.GetOutterRect();
1175 } 1372 }
1176 } 1373 }
1177 if (charcode < 256) { 1374 if (charcode < 256) {
1178 m_CharBBox[charcode].Bottom = (short)rect.bottom; 1375 m_CharBBox[charcode].Bottom = (short)rect.bottom;
1179 m_CharBBox[charcode].Left = (short)rect.left; 1376 m_CharBBox[charcode].Left = (short)rect.left;
1180 m_CharBBox[charcode].Right = (short)rect.right; 1377 m_CharBBox[charcode].Right = (short)rect.right;
1181 m_CharBBox[charcode].Top = (short)rect.top; 1378 m_CharBBox[charcode].Top = (short)rect.top;
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 } 1694 }
1498 result.Add(pObj->GetInteger()); 1695 result.Add(pObj->GetInteger());
1499 iCurElement++; 1696 iCurElement++;
1500 if (iCurElement == nElements) { 1697 if (iCurElement == nElements) {
1501 width_status = 0; 1698 width_status = 0;
1502 } 1699 }
1503 } 1700 }
1504 } 1701 }
1505 } 1702 }
1506 } 1703 }
1704
1705 // static
1706 FX_FLOAT CPDF_CIDFont::CIDTransformToFloat(uint8_t ch) {
1707 if (ch < 128) {
1708 return ch * 1.0f / 127;
1709 }
1710 return (-255 + ch) * 1.0f / 127;
1711 }
1712
1507 FX_BOOL CPDF_CIDFont::LoadGB2312() { 1713 FX_BOOL CPDF_CIDFont::LoadGB2312() {
1508 m_BaseFont = m_pFontDict->GetString(FX_BSTRC("BaseFont")); 1714 m_BaseFont = m_pFontDict->GetString(FX_BSTRC("BaseFont"));
1509 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDict(FX_BSTRC("FontDescriptor")); 1715 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDict(FX_BSTRC("FontDescriptor"));
1510 if (pFontDesc) { 1716 if (pFontDesc) {
1511 LoadFontDescriptor(pFontDesc); 1717 LoadFontDescriptor(pFontDesc);
1512 } 1718 }
1513 m_Charset = CIDSET_GB1; 1719 m_Charset = CIDSET_GB1;
1514 m_bType1 = FALSE; 1720 m_bType1 = FALSE;
1515 m_pCMap = CPDF_ModuleMgr::Get() 1721 m_pCMap = CPDF_ModuleMgr::Get()
1516 ->GetPageModule() 1722 ->GetPageModule()
1517 ->GetFontGlobals() 1723 ->GetFontGlobals()
1518 ->m_CMapManager.GetPredefinedCMap(FX_BSTRC("GBK-EUC-H"), FALSE); 1724 ->m_CMapManager.GetPredefinedCMap(FX_BSTRC("GBK-EUC-H"), FALSE);
1519 m_pCID2UnicodeMap = CPDF_ModuleMgr::Get() 1725 m_pCID2UnicodeMap = CPDF_ModuleMgr::Get()
1520 ->GetPageModule() 1726 ->GetPageModule()
1521 ->GetFontGlobals() 1727 ->GetFontGlobals()
1522 ->m_CMapManager.GetCID2UnicodeMap(m_Charset, FALSE); 1728 ->m_CMapManager.GetCID2UnicodeMap(m_Charset, FALSE);
1523 if (!IsEmbedded()) { 1729 if (!IsEmbedded()) {
1524 LoadSubstFont(); 1730 LoadSubstFont();
1525 } 1731 }
1526 CheckFontMetrics(); 1732 CheckFontMetrics();
1527 m_DefaultWidth = 1000; 1733 m_DefaultWidth = 1000;
1528 m_pAnsiWidths = FX_Alloc(FX_WORD, 128); 1734 m_pAnsiWidths = FX_Alloc(FX_WORD, 128);
1529 for (int i = 32; i < 127; i++) { 1735 for (int i = 32; i < 127; i++) {
1530 m_pAnsiWidths[i] = 500; 1736 m_pAnsiWidths[i] = 500;
1531 } 1737 }
1532 return TRUE; 1738 return TRUE;
1533 } 1739 }
1534 const struct _CIDTransform { 1740
1535 FX_WORD CID;
1536 uint8_t a, b, c, d, e, f;
1537 } Japan1_VertCIDs[] = {
1538 {97, 129, 0, 0, 127, 55, 0}, {7887, 127, 0, 0, 127, 76, 89},
1539 {7888, 127, 0, 0, 127, 79, 94}, {7889, 0, 129, 127, 0, 17, 127},
1540 {7890, 0, 129, 127, 0, 17, 127}, {7891, 0, 129, 127, 0, 17, 127},
1541 {7892, 0, 129, 127, 0, 17, 127}, {7893, 0, 129, 127, 0, 17, 127},
1542 {7894, 0, 129, 127, 0, 17, 127}, {7895, 0, 129, 127, 0, 17, 127},
1543 {7896, 0, 129, 127, 0, 17, 127}, {7897, 0, 129, 127, 0, 17, 127},
1544 {7898, 0, 129, 127, 0, 17, 127}, {7899, 0, 129, 127, 0, 17, 104},
1545 {7900, 0, 129, 127, 0, 17, 127}, {7901, 0, 129, 127, 0, 17, 104},
1546 {7902, 0, 129, 127, 0, 17, 127}, {7903, 0, 129, 127, 0, 17, 127},
1547 {7904, 0, 129, 127, 0, 17, 127}, {7905, 0, 129, 127, 0, 17, 114},
1548 {7906, 0, 129, 127, 0, 17, 127}, {7907, 0, 129, 127, 0, 17, 127},
1549 {7908, 0, 129, 127, 0, 17, 127}, {7909, 0, 129, 127, 0, 17, 127},
1550 {7910, 0, 129, 127, 0, 17, 127}, {7911, 0, 129, 127, 0, 17, 127},
1551 {7912, 0, 129, 127, 0, 17, 127}, {7913, 0, 129, 127, 0, 17, 127},
1552 {7914, 0, 129, 127, 0, 17, 127}, {7915, 0, 129, 127, 0, 17, 114},
1553 {7916, 0, 129, 127, 0, 17, 127}, {7917, 0, 129, 127, 0, 17, 127},
1554 {7918, 127, 0, 0, 127, 18, 25}, {7919, 127, 0, 0, 127, 18, 25},
1555 {7920, 127, 0, 0, 127, 18, 25}, {7921, 127, 0, 0, 127, 18, 25},
1556 {7922, 127, 0, 0, 127, 18, 25}, {7923, 127, 0, 0, 127, 18, 25},
1557 {7924, 127, 0, 0, 127, 18, 25}, {7925, 127, 0, 0, 127, 18, 25},
1558 {7926, 127, 0, 0, 127, 18, 25}, {7927, 127, 0, 0, 127, 18, 25},
1559 {7928, 127, 0, 0, 127, 18, 25}, {7929, 127, 0, 0, 127, 18, 25},
1560 {7930, 127, 0, 0, 127, 18, 25}, {7931, 127, 0, 0, 127, 18, 25},
1561 {7932, 127, 0, 0, 127, 18, 25}, {7933, 127, 0, 0, 127, 18, 25},
1562 {7934, 127, 0, 0, 127, 18, 25}, {7935, 127, 0, 0, 127, 18, 25},
1563 {7936, 127, 0, 0, 127, 18, 25}, {7937, 127, 0, 0, 127, 18, 25},
1564 {7938, 127, 0, 0, 127, 18, 25}, {7939, 127, 0, 0, 127, 18, 25},
1565 {8720, 0, 129, 127, 0, 19, 102}, {8721, 0, 129, 127, 0, 13, 127},
1566 {8722, 0, 129, 127, 0, 19, 108}, {8723, 0, 129, 127, 0, 19, 102},
1567 {8724, 0, 129, 127, 0, 19, 102}, {8725, 0, 129, 127, 0, 19, 102},
1568 {8726, 0, 129, 127, 0, 19, 102}, {8727, 0, 129, 127, 0, 19, 102},
1569 {8728, 0, 129, 127, 0, 19, 114}, {8729, 0, 129, 127, 0, 19, 114},
1570 {8730, 0, 129, 127, 0, 38, 108}, {8731, 0, 129, 127, 0, 13, 108},
1571 {8732, 0, 129, 127, 0, 19, 108}, {8733, 0, 129, 127, 0, 19, 108},
1572 {8734, 0, 129, 127, 0, 19, 108}, {8735, 0, 129, 127, 0, 19, 108},
1573 {8736, 0, 129, 127, 0, 19, 102}, {8737, 0, 129, 127, 0, 19, 102},
1574 {8738, 0, 129, 127, 0, 19, 102}, {8739, 0, 129, 127, 0, 19, 102},
1575 {8740, 0, 129, 127, 0, 19, 102}, {8741, 0, 129, 127, 0, 19, 102},
1576 {8742, 0, 129, 127, 0, 19, 102}, {8743, 0, 129, 127, 0, 19, 102},
1577 {8744, 0, 129, 127, 0, 19, 102}, {8745, 0, 129, 127, 0, 19, 102},
1578 {8746, 0, 129, 127, 0, 19, 114}, {8747, 0, 129, 127, 0, 19, 114},
1579 {8748, 0, 129, 127, 0, 19, 102}, {8749, 0, 129, 127, 0, 19, 102},
1580 {8750, 0, 129, 127, 0, 19, 102}, {8751, 0, 129, 127, 0, 19, 102},
1581 {8752, 0, 129, 127, 0, 19, 102}, {8753, 0, 129, 127, 0, 19, 102},
1582 {8754, 0, 129, 127, 0, 19, 102}, {8755, 0, 129, 127, 0, 19, 102},
1583 {8756, 0, 129, 127, 0, 19, 102}, {8757, 0, 129, 127, 0, 19, 102},
1584 {8758, 0, 129, 127, 0, 19, 102}, {8759, 0, 129, 127, 0, 19, 102},
1585 {8760, 0, 129, 127, 0, 19, 102}, {8761, 0, 129, 127, 0, 19, 102},
1586 {8762, 0, 129, 127, 0, 19, 102}, {8763, 0, 129, 127, 0, 19, 102},
1587 {8764, 0, 129, 127, 0, 19, 102}, {8765, 0, 129, 127, 0, 19, 102},
1588 {8766, 0, 129, 127, 0, 19, 102}, {8767, 0, 129, 127, 0, 19, 102},
1589 {8768, 0, 129, 127, 0, 19, 102}, {8769, 0, 129, 127, 0, 19, 102},
1590 {8770, 0, 129, 127, 0, 19, 102}, {8771, 0, 129, 127, 0, 19, 102},
1591 {8772, 0, 129, 127, 0, 19, 102}, {8773, 0, 129, 127, 0, 19, 102},
1592 {8774, 0, 129, 127, 0, 19, 102}, {8775, 0, 129, 127, 0, 19, 102},
1593 {8776, 0, 129, 127, 0, 19, 102}, {8777, 0, 129, 127, 0, 19, 102},
1594 {8778, 0, 129, 127, 0, 19, 102}, {8779, 0, 129, 127, 0, 19, 114},
1595 {8780, 0, 129, 127, 0, 19, 108}, {8781, 0, 129, 127, 0, 19, 114},
1596 {8782, 0, 129, 127, 0, 13, 114}, {8783, 0, 129, 127, 0, 19, 108},
1597 {8784, 0, 129, 127, 0, 13, 114}, {8785, 0, 129, 127, 0, 19, 108},
1598 {8786, 0, 129, 127, 0, 19, 108}, {8787, 0, 129, 127, 0, 19, 108},
1599 {8788, 0, 129, 127, 0, 19, 108}, {8789, 0, 129, 127, 0, 19, 108},
1600 {8790, 0, 129, 127, 0, 19, 108}, {8791, 0, 129, 127, 0, 19, 108},
1601 {8792, 0, 129, 127, 0, 19, 108}, {8793, 0, 129, 127, 0, 19, 108},
1602 {8794, 0, 129, 127, 0, 19, 108}, {8795, 0, 129, 127, 0, 19, 108},
1603 {8796, 0, 129, 127, 0, 19, 108}, {8797, 0, 129, 127, 0, 19, 108},
1604 {8798, 0, 129, 127, 0, 19, 108}, {8799, 0, 129, 127, 0, 19, 108},
1605 {8800, 0, 129, 127, 0, 19, 108}, {8801, 0, 129, 127, 0, 19, 108},
1606 {8802, 0, 129, 127, 0, 19, 108}, {8803, 0, 129, 127, 0, 19, 108},
1607 {8804, 0, 129, 127, 0, 19, 108}, {8805, 0, 129, 127, 0, 19, 108},
1608 {8806, 0, 129, 127, 0, 19, 108}, {8807, 0, 129, 127, 0, 19, 108},
1609 {8808, 0, 129, 127, 0, 19, 108}, {8809, 0, 129, 127, 0, 19, 108},
1610 {8810, 0, 129, 127, 0, 19, 108}, {8811, 0, 129, 127, 0, 19, 114},
1611 {8812, 0, 129, 127, 0, 19, 102}, {8813, 0, 129, 127, 0, 19, 114},
1612 {8814, 0, 129, 127, 0, 76, 102}, {8815, 0, 129, 127, 0, 13, 121},
1613 {8816, 0, 129, 127, 0, 19, 114}, {8817, 0, 129, 127, 0, 19, 127},
1614 {8818, 0, 129, 127, 0, 19, 114}, {8819, 0, 129, 127, 0, 218, 108},
1615 };
1616 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const { 1741 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const {
1617 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile != NULL) { 1742 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile)
1618 return NULL; 1743 return nullptr;
1619 } 1744
1620 int begin = 0; 1745 size_t begin = 0;
1621 int end = sizeof Japan1_VertCIDs / sizeof(struct _CIDTransform) - 1; 1746 size_t end = FX_ArraySize(g_Japan1_VertCIDs) - 1;
1622 while (begin <= end) { 1747 while (begin <= end) {
1623 int middle = (begin + end) / 2; 1748 size_t middle = (begin + end) / 2;
1624 FX_WORD middlecode = Japan1_VertCIDs[middle].CID; 1749 FX_WORD middlecode = g_Japan1_VertCIDs[middle].CID;
1625 if (middlecode > CID) { 1750 if (middlecode > CID) {
1626 end = middle - 1; 1751 end = middle - 1;
1627 } else if (middlecode < CID) { 1752 } else if (middlecode < CID) {
1628 begin = middle + 1; 1753 begin = middle + 1;
1629 } else { 1754 } else {
1630 return &Japan1_VertCIDs[middle].a; 1755 return &g_Japan1_VertCIDs[middle].a;
1631 } 1756 }
1632 } 1757 }
1633 return NULL; 1758 return nullptr;
1634 } 1759 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_font/fpdf_font.cpp ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698