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

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

Issue 1824033002: Split core/include/fpdfapi/fpdf_resource.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fixing mac build Created 4 years, 9 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 "core/fpdfapi/fpdf_font/font_int.h" 7 #include "core/fpdfapi/fpdf_font/font_int.h"
8 8
9 #include "core/fpdfapi/fpdf_cmaps/cmap_int.h" 9 #include "core/fpdfapi/fpdf_cmaps/cmap_int.h"
10 #include "core/fpdfapi/fpdf_font/ttgsubtable.h" 10 #include "core/fpdfapi/fpdf_font/ttgsubtable.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h"
14 #include "core/fpdfapi/include/cpdf_modulemgr.h" 14 #include "core/fpdfapi/include/cpdf_modulemgr.h"
15 #include "core/include/fpdfapi/fpdf_resource.h"
16 #include "core/include/fxcrt/fx_ext.h" 15 #include "core/include/fxcrt/fx_ext.h"
17 #include "core/include/fxge/fx_freetype.h" 16 #include "core/include/fxge/fx_freetype.h"
18 #include "core/include/fxge/fx_ge.h" 17 #include "core/include/fxge/fx_ge.h"
19 18
20 namespace { 19 namespace {
21 20
22 const FX_CHAR* const g_CharsetNames[CIDSET_NUM_SETS] = { 21 const FX_CHAR* const g_CharsetNames[CIDSET_NUM_SETS] = {
23 nullptr, "GB1", "CNS1", "Japan1", "Korea1", "UCS"}; 22 nullptr, "GB1", "CNS1", "Japan1", "Korea1", "UCS"};
24 23
25 const uint16_t g_CharsetCPs[CIDSET_NUM_SETS] = {0, 936, 950, 932, 949, 1200};
26 24
27 class CPDF_PredefinedCMap { 25 class CPDF_PredefinedCMap {
28 public: 26 public:
29 const FX_CHAR* m_pName; 27 const FX_CHAR* m_pName;
30 CIDSet m_Charset; 28 CIDSet m_Charset;
31 CIDCoding m_Coding; 29 CIDCoding m_Coding;
32 CPDF_CMap::CodingScheme m_CodingScheme; 30 CPDF_CMap::CodingScheme m_CodingScheme;
33 uint8_t m_LeadingSegCount; 31 uint8_t m_LeadingSegCount;
34 uint8_t m_LeadingSegs[4]; 32 uint8_t m_LeadingSegs[4];
35 }; 33 };
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 }; 183 };
186 184
187 CIDSet CIDSetFromSizeT(size_t index) { 185 CIDSet CIDSetFromSizeT(size_t index) {
188 if (index >= CIDSET_NUM_SETS) { 186 if (index >= CIDSET_NUM_SETS) {
189 NOTREACHED(); 187 NOTREACHED();
190 return CIDSET_UNKNOWN; 188 return CIDSET_UNKNOWN;
191 } 189 }
192 return static_cast<CIDSet>(index); 190 return static_cast<CIDSet>(index);
193 } 191 }
194 192
195 CIDSet CharsetFromOrdering(const CFX_ByteString& ordering) {
196 for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) {
197 if (ordering == CFX_ByteStringC(g_CharsetNames[charset]))
198 return CIDSetFromSizeT(charset);
199 }
200 return CIDSET_UNKNOWN;
201 }
202
203 CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) { 193 CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) {
204 return word.Mid(1, word.GetLength() - 2); 194 return word.Mid(1, word.GetLength() - 2);
205 } 195 }
206 196
207 int CompareDWORD(const void* data1, const void* data2) { 197 int CompareDWORD(const void* data1, const void* data2) {
208 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2); 198 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2);
209 } 199 }
210 200
211 int CompareCID(const void* key, const void* element) { 201 int CompareCID(const void* key, const void* element) {
212 if ((*(FX_DWORD*)key) < (*(FX_DWORD*)element)) { 202 if ((*(FX_DWORD*)key) < (*(FX_DWORD*)element)) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 if (iChar == pRanges[iSeg].m_CharSize) 267 if (iChar == pRanges[iSeg].m_CharSize)
278 return size; 268 return size;
279 --iSeg; 269 --iSeg;
280 } 270 }
281 --size; 271 --size;
282 ++offset; 272 ++offset;
283 } 273 }
284 return 1; 274 return 1;
285 } 275 }
286 276
287 bool IsValidEmbeddedCharcodeFromUnicodeCharset(CIDSet charset) {
288 switch (charset) {
289 case CIDSET_GB1:
290 case CIDSET_CNS1:
291 case CIDSET_JAPAN1:
292 case CIDSET_KOREA1:
293 return true;
294
295 default:
296 return false;
297 }
298 }
299
300 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
301 FX_DWORD EmbeddedCharcodeFromUnicode(const FXCMAP_CMap* pEmbedMap,
302 CIDSet charset,
303 FX_WCHAR unicode) {
304 if (!IsValidEmbeddedCharcodeFromUnicodeCharset(charset))
305 return 0;
306
307 CPDF_FontGlobals* pFontGlobals =
308 CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
309 const uint16_t* pCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap;
310 if (!pCodes)
311 return 0;
312
313 int nCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count;
314 for (int i = 0; i < nCodes; ++i) {
315 if (pCodes[i] == unicode) {
316 FX_DWORD CharCode = FPDFAPI_CharCodeFromCID(pEmbedMap, i);
317 if (CharCode != 0) {
318 return CharCode;
319 }
320 }
321 }
322 return 0;
323 }
324 #endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
325
326 FX_WCHAR EmbeddedUnicodeFromCharcode(const FXCMAP_CMap* pEmbedMap,
327 CIDSet charset,
328 FX_DWORD charcode) {
329 if (!IsValidEmbeddedCharcodeFromUnicodeCharset(charset))
330 return 0;
331
332 uint16_t cid = FPDFAPI_CIDFromCharCode(pEmbedMap, charcode);
333 if (cid == 0)
334 return 0;
335
336 CPDF_FontGlobals* pFontGlobals =
337 CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
338 const uint16_t* pCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap;
339 if (!pCodes)
340 return 0;
341
342 if (cid < pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count)
343 return pCodes[cid];
344 return 0;
345 }
346
347 void FT_UseCIDCharmap(FXFT_Face face, int coding) {
348 int encoding;
349 switch (coding) {
350 case CIDCODING_GB:
351 encoding = FXFT_ENCODING_GB2312;
352 break;
353 case CIDCODING_BIG5:
354 encoding = FXFT_ENCODING_BIG5;
355 break;
356 case CIDCODING_JIS:
357 encoding = FXFT_ENCODING_SJIS;
358 break;
359 case CIDCODING_KOREA:
360 encoding = FXFT_ENCODING_JOHAB;
361 break;
362 default:
363 encoding = FXFT_ENCODING_UNICODE;
364 }
365 int err = FXFT_Select_Charmap(face, encoding);
366 if (err) {
367 err = FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE);
368 }
369 if (err && FXFT_Get_Face_Charmaps(face)) {
370 FXFT_Set_Charmap(face, *FXFT_Get_Face_Charmaps(face));
371 }
372 }
373
374 const struct CIDTransform {
375 uint16_t CID;
376 uint8_t a, b, c, d, e, f;
377 } g_Japan1_VertCIDs[] = {
378 {97, 129, 0, 0, 127, 55, 0}, {7887, 127, 0, 0, 127, 76, 89},
379 {7888, 127, 0, 0, 127, 79, 94}, {7889, 0, 129, 127, 0, 17, 127},
380 {7890, 0, 129, 127, 0, 17, 127}, {7891, 0, 129, 127, 0, 17, 127},
381 {7892, 0, 129, 127, 0, 17, 127}, {7893, 0, 129, 127, 0, 17, 127},
382 {7894, 0, 129, 127, 0, 17, 127}, {7895, 0, 129, 127, 0, 17, 127},
383 {7896, 0, 129, 127, 0, 17, 127}, {7897, 0, 129, 127, 0, 17, 127},
384 {7898, 0, 129, 127, 0, 17, 127}, {7899, 0, 129, 127, 0, 17, 104},
385 {7900, 0, 129, 127, 0, 17, 127}, {7901, 0, 129, 127, 0, 17, 104},
386 {7902, 0, 129, 127, 0, 17, 127}, {7903, 0, 129, 127, 0, 17, 127},
387 {7904, 0, 129, 127, 0, 17, 127}, {7905, 0, 129, 127, 0, 17, 114},
388 {7906, 0, 129, 127, 0, 17, 127}, {7907, 0, 129, 127, 0, 17, 127},
389 {7908, 0, 129, 127, 0, 17, 127}, {7909, 0, 129, 127, 0, 17, 127},
390 {7910, 0, 129, 127, 0, 17, 127}, {7911, 0, 129, 127, 0, 17, 127},
391 {7912, 0, 129, 127, 0, 17, 127}, {7913, 0, 129, 127, 0, 17, 127},
392 {7914, 0, 129, 127, 0, 17, 127}, {7915, 0, 129, 127, 0, 17, 114},
393 {7916, 0, 129, 127, 0, 17, 127}, {7917, 0, 129, 127, 0, 17, 127},
394 {7918, 127, 0, 0, 127, 18, 25}, {7919, 127, 0, 0, 127, 18, 25},
395 {7920, 127, 0, 0, 127, 18, 25}, {7921, 127, 0, 0, 127, 18, 25},
396 {7922, 127, 0, 0, 127, 18, 25}, {7923, 127, 0, 0, 127, 18, 25},
397 {7924, 127, 0, 0, 127, 18, 25}, {7925, 127, 0, 0, 127, 18, 25},
398 {7926, 127, 0, 0, 127, 18, 25}, {7927, 127, 0, 0, 127, 18, 25},
399 {7928, 127, 0, 0, 127, 18, 25}, {7929, 127, 0, 0, 127, 18, 25},
400 {7930, 127, 0, 0, 127, 18, 25}, {7931, 127, 0, 0, 127, 18, 25},
401 {7932, 127, 0, 0, 127, 18, 25}, {7933, 127, 0, 0, 127, 18, 25},
402 {7934, 127, 0, 0, 127, 18, 25}, {7935, 127, 0, 0, 127, 18, 25},
403 {7936, 127, 0, 0, 127, 18, 25}, {7937, 127, 0, 0, 127, 18, 25},
404 {7938, 127, 0, 0, 127, 18, 25}, {7939, 127, 0, 0, 127, 18, 25},
405 {8720, 0, 129, 127, 0, 19, 102}, {8721, 0, 129, 127, 0, 13, 127},
406 {8722, 0, 129, 127, 0, 19, 108}, {8723, 0, 129, 127, 0, 19, 102},
407 {8724, 0, 129, 127, 0, 19, 102}, {8725, 0, 129, 127, 0, 19, 102},
408 {8726, 0, 129, 127, 0, 19, 102}, {8727, 0, 129, 127, 0, 19, 102},
409 {8728, 0, 129, 127, 0, 19, 114}, {8729, 0, 129, 127, 0, 19, 114},
410 {8730, 0, 129, 127, 0, 38, 108}, {8731, 0, 129, 127, 0, 13, 108},
411 {8732, 0, 129, 127, 0, 19, 108}, {8733, 0, 129, 127, 0, 19, 108},
412 {8734, 0, 129, 127, 0, 19, 108}, {8735, 0, 129, 127, 0, 19, 108},
413 {8736, 0, 129, 127, 0, 19, 102}, {8737, 0, 129, 127, 0, 19, 102},
414 {8738, 0, 129, 127, 0, 19, 102}, {8739, 0, 129, 127, 0, 19, 102},
415 {8740, 0, 129, 127, 0, 19, 102}, {8741, 0, 129, 127, 0, 19, 102},
416 {8742, 0, 129, 127, 0, 19, 102}, {8743, 0, 129, 127, 0, 19, 102},
417 {8744, 0, 129, 127, 0, 19, 102}, {8745, 0, 129, 127, 0, 19, 102},
418 {8746, 0, 129, 127, 0, 19, 114}, {8747, 0, 129, 127, 0, 19, 114},
419 {8748, 0, 129, 127, 0, 19, 102}, {8749, 0, 129, 127, 0, 19, 102},
420 {8750, 0, 129, 127, 0, 19, 102}, {8751, 0, 129, 127, 0, 19, 102},
421 {8752, 0, 129, 127, 0, 19, 102}, {8753, 0, 129, 127, 0, 19, 102},
422 {8754, 0, 129, 127, 0, 19, 102}, {8755, 0, 129, 127, 0, 19, 102},
423 {8756, 0, 129, 127, 0, 19, 102}, {8757, 0, 129, 127, 0, 19, 102},
424 {8758, 0, 129, 127, 0, 19, 102}, {8759, 0, 129, 127, 0, 19, 102},
425 {8760, 0, 129, 127, 0, 19, 102}, {8761, 0, 129, 127, 0, 19, 102},
426 {8762, 0, 129, 127, 0, 19, 102}, {8763, 0, 129, 127, 0, 19, 102},
427 {8764, 0, 129, 127, 0, 19, 102}, {8765, 0, 129, 127, 0, 19, 102},
428 {8766, 0, 129, 127, 0, 19, 102}, {8767, 0, 129, 127, 0, 19, 102},
429 {8768, 0, 129, 127, 0, 19, 102}, {8769, 0, 129, 127, 0, 19, 102},
430 {8770, 0, 129, 127, 0, 19, 102}, {8771, 0, 129, 127, 0, 19, 102},
431 {8772, 0, 129, 127, 0, 19, 102}, {8773, 0, 129, 127, 0, 19, 102},
432 {8774, 0, 129, 127, 0, 19, 102}, {8775, 0, 129, 127, 0, 19, 102},
433 {8776, 0, 129, 127, 0, 19, 102}, {8777, 0, 129, 127, 0, 19, 102},
434 {8778, 0, 129, 127, 0, 19, 102}, {8779, 0, 129, 127, 0, 19, 114},
435 {8780, 0, 129, 127, 0, 19, 108}, {8781, 0, 129, 127, 0, 19, 114},
436 {8782, 0, 129, 127, 0, 13, 114}, {8783, 0, 129, 127, 0, 19, 108},
437 {8784, 0, 129, 127, 0, 13, 114}, {8785, 0, 129, 127, 0, 19, 108},
438 {8786, 0, 129, 127, 0, 19, 108}, {8787, 0, 129, 127, 0, 19, 108},
439 {8788, 0, 129, 127, 0, 19, 108}, {8789, 0, 129, 127, 0, 19, 108},
440 {8790, 0, 129, 127, 0, 19, 108}, {8791, 0, 129, 127, 0, 19, 108},
441 {8792, 0, 129, 127, 0, 19, 108}, {8793, 0, 129, 127, 0, 19, 108},
442 {8794, 0, 129, 127, 0, 19, 108}, {8795, 0, 129, 127, 0, 19, 108},
443 {8796, 0, 129, 127, 0, 19, 108}, {8797, 0, 129, 127, 0, 19, 108},
444 {8798, 0, 129, 127, 0, 19, 108}, {8799, 0, 129, 127, 0, 19, 108},
445 {8800, 0, 129, 127, 0, 19, 108}, {8801, 0, 129, 127, 0, 19, 108},
446 {8802, 0, 129, 127, 0, 19, 108}, {8803, 0, 129, 127, 0, 19, 108},
447 {8804, 0, 129, 127, 0, 19, 108}, {8805, 0, 129, 127, 0, 19, 108},
448 {8806, 0, 129, 127, 0, 19, 108}, {8807, 0, 129, 127, 0, 19, 108},
449 {8808, 0, 129, 127, 0, 19, 108}, {8809, 0, 129, 127, 0, 19, 108},
450 {8810, 0, 129, 127, 0, 19, 108}, {8811, 0, 129, 127, 0, 19, 114},
451 {8812, 0, 129, 127, 0, 19, 102}, {8813, 0, 129, 127, 0, 19, 114},
452 {8814, 0, 129, 127, 0, 76, 102}, {8815, 0, 129, 127, 0, 13, 121},
453 {8816, 0, 129, 127, 0, 19, 114}, {8817, 0, 129, 127, 0, 19, 127},
454 {8818, 0, 129, 127, 0, 19, 114}, {8819, 0, 129, 127, 0, 218, 108},
455 };
456
457 int CompareCIDTransform(const void* key, const void* element) {
458 uint16_t CID = *static_cast<const uint16_t*>(key);
459 return CID - static_cast<const struct CIDTransform*>(element)->CID;
460 }
461
462 } // namespace 277 } // namespace
463 278
464 CPDF_CMapManager::CPDF_CMapManager() { 279 CPDF_CMapManager::CPDF_CMapManager() {
465 m_bPrompted = FALSE; 280 m_bPrompted = FALSE;
466 FXSYS_memset(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps); 281 FXSYS_memset(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps);
467 } 282 }
468 CPDF_CMapManager::~CPDF_CMapManager() { 283 CPDF_CMapManager::~CPDF_CMapManager() {
469 for (const auto& pair : m_CMaps) { 284 for (const auto& pair : m_CMaps) {
470 delete pair.second; 285 delete pair.second;
471 } 286 }
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 return 0; 781 return 0;
967 } 782 }
968 783
969 void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, 784 void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr,
970 CIDSet charset, 785 CIDSet charset,
971 FX_BOOL bPromptCJK) { 786 FX_BOOL bPromptCJK) {
972 m_Charset = charset; 787 m_Charset = charset;
973 FPDFAPI_LoadCID2UnicodeMap(charset, m_pEmbeddedMap, m_EmbeddedCount); 788 FPDFAPI_LoadCID2UnicodeMap(charset, m_pEmbeddedMap, m_EmbeddedCount);
974 } 789 }
975 790
976 CPDF_CIDFont::CPDF_CIDFont() 791 CIDSet CharsetFromOrdering(const CFX_ByteString& ordering) {
977 : m_pCMap(nullptr), 792 for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) {
978 m_pAllocatedCMap(nullptr), 793 if (ordering == CFX_ByteStringC(g_CharsetNames[charset]))
979 m_pCID2UnicodeMap(nullptr), 794 return CIDSetFromSizeT(charset);
980 m_pCIDToGIDMap(nullptr),
981 m_bCIDIsGID(FALSE),
982 m_pAnsiWidths(nullptr),
983 m_bAdobeCourierStd(FALSE),
984 m_pTTGSUBTable(nullptr) {}
985
986 CPDF_CIDFont::~CPDF_CIDFont() {
987 if (m_pAnsiWidths) {
988 FX_Free(m_pAnsiWidths);
989 } 795 }
990 delete m_pAllocatedCMap; 796 return CIDSET_UNKNOWN;
991 delete m_pCIDToGIDMap;
992 delete m_pTTGSUBTable;
993 } 797 }
994
995 bool CPDF_CIDFont::IsCIDFont() const {
996 return true;
997 }
998
999 const CPDF_CIDFont* CPDF_CIDFont::AsCIDFont() const {
1000 return this;
1001 }
1002
1003 CPDF_CIDFont* CPDF_CIDFont::AsCIDFont() {
1004 return this;
1005 }
1006
1007 uint16_t CPDF_CIDFont::CIDFromCharCode(FX_DWORD charcode) const {
1008 if (!m_pCMap) {
1009 return (uint16_t)charcode;
1010 }
1011 return m_pCMap->CIDFromCharCode(charcode);
1012 }
1013
1014 FX_BOOL CPDF_CIDFont::IsVertWriting() const {
1015 return m_pCMap ? m_pCMap->IsVertWriting() : FALSE;
1016 }
1017
1018 CFX_WideString CPDF_CIDFont::UnicodeFromCharCode(FX_DWORD charcode) const {
1019 CFX_WideString str = CPDF_Font::UnicodeFromCharCode(charcode);
1020 if (!str.IsEmpty())
1021 return str;
1022 FX_WCHAR ret = GetUnicodeFromCharCode(charcode);
1023 if (ret == 0)
1024 return CFX_WideString();
1025 return ret;
1026 }
1027
1028 FX_WCHAR CPDF_CIDFont::GetUnicodeFromCharCode(FX_DWORD charcode) const {
1029 switch (m_pCMap->m_Coding) {
1030 case CIDCODING_UCS2:
1031 case CIDCODING_UTF16:
1032 return (FX_WCHAR)charcode;
1033 case CIDCODING_CID:
1034 if (!m_pCID2UnicodeMap || !m_pCID2UnicodeMap->IsLoaded()) {
1035 return 0;
1036 }
1037 return m_pCID2UnicodeMap->UnicodeFromCID((uint16_t)charcode);
1038 }
1039 if (!m_pCMap->IsLoaded() || !m_pCID2UnicodeMap ||
1040 !m_pCID2UnicodeMap->IsLoaded()) {
1041 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
1042 FX_WCHAR unicode;
1043 int charsize = 1;
1044 if (charcode > 255) {
1045 charcode = (charcode % 256) * 256 + (charcode / 256);
1046 charsize = 2;
1047 }
1048 int ret = FXSYS_MultiByteToWideChar(g_CharsetCPs[m_pCMap->m_Coding], 0,
1049 (const FX_CHAR*)&charcode, charsize,
1050 &unicode, 1);
1051 if (ret != 1) {
1052 return 0;
1053 }
1054 return unicode;
1055 #endif
1056 if (m_pCMap->m_pEmbedMap) {
1057 return EmbeddedUnicodeFromCharcode(m_pCMap->m_pEmbedMap,
1058 m_pCMap->m_Charset, charcode);
1059 }
1060 return 0;
1061 }
1062 return m_pCID2UnicodeMap->UnicodeFromCID(CIDFromCharCode(charcode));
1063 }
1064
1065 FX_DWORD CPDF_CIDFont::CharCodeFromUnicode(FX_WCHAR unicode) const {
1066 FX_DWORD charcode = CPDF_Font::CharCodeFromUnicode(unicode);
1067 if (charcode)
1068 return charcode;
1069 switch (m_pCMap->m_Coding) {
1070 case CIDCODING_UNKNOWN:
1071 return 0;
1072 case CIDCODING_UCS2:
1073 case CIDCODING_UTF16:
1074 return unicode;
1075 case CIDCODING_CID: {
1076 if (!m_pCID2UnicodeMap || !m_pCID2UnicodeMap->IsLoaded()) {
1077 return 0;
1078 }
1079 FX_DWORD CID = 0;
1080 while (CID < 65536) {
1081 FX_WCHAR this_unicode =
1082 m_pCID2UnicodeMap->UnicodeFromCID((uint16_t)CID);
1083 if (this_unicode == unicode) {
1084 return CID;
1085 }
1086 CID++;
1087 }
1088 break;
1089 }
1090 }
1091
1092 if (unicode < 0x80) {
1093 return static_cast<FX_DWORD>(unicode);
1094 }
1095 if (m_pCMap->m_Coding == CIDCODING_CID) {
1096 return 0;
1097 }
1098 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
1099 uint8_t buffer[32];
1100 int ret =
1101 FXSYS_WideCharToMultiByte(g_CharsetCPs[m_pCMap->m_Coding], 0, &unicode, 1,
1102 (char*)buffer, 4, NULL, NULL);
1103 if (ret == 1) {
1104 return buffer[0];
1105 }
1106 if (ret == 2) {
1107 return buffer[0] * 256 + buffer[1];
1108 }
1109 #else
1110 if (m_pCMap->m_pEmbedMap) {
1111 return EmbeddedCharcodeFromUnicode(m_pCMap->m_pEmbedMap, m_pCMap->m_Charset,
1112 unicode);
1113 }
1114 #endif
1115 return 0;
1116 }
1117
1118 FX_BOOL CPDF_CIDFont::Load() {
1119 if (m_pFontDict->GetStringBy("Subtype") == "TrueType") {
1120 return LoadGB2312();
1121 }
1122 CPDF_Array* pFonts = m_pFontDict->GetArrayBy("DescendantFonts");
1123 if (!pFonts) {
1124 return FALSE;
1125 }
1126 if (pFonts->GetCount() != 1) {
1127 return FALSE;
1128 }
1129 CPDF_Dictionary* pCIDFontDict = pFonts->GetDictAt(0);
1130 if (!pCIDFontDict) {
1131 return FALSE;
1132 }
1133 m_BaseFont = pCIDFontDict->GetStringBy("BaseFont");
1134 if ((m_BaseFont.Compare("CourierStd") == 0 ||
1135 m_BaseFont.Compare("CourierStd-Bold") == 0 ||
1136 m_BaseFont.Compare("CourierStd-BoldOblique") == 0 ||
1137 m_BaseFont.Compare("CourierStd-Oblique") == 0) &&
1138 !IsEmbedded()) {
1139 m_bAdobeCourierStd = TRUE;
1140 }
1141 CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDictBy("FontDescriptor");
1142 if (pFontDesc) {
1143 LoadFontDescriptor(pFontDesc);
1144 }
1145 CPDF_Object* pEncoding = m_pFontDict->GetElementValue("Encoding");
1146 if (!pEncoding) {
1147 return FALSE;
1148 }
1149 CFX_ByteString subtype = pCIDFontDict->GetStringBy("Subtype");
1150 m_bType1 = (subtype == "CIDFontType0");
1151
1152 if (pEncoding->IsName()) {
1153 CFX_ByteString cmap = pEncoding->GetString();
1154 m_pCMap =
1155 CPDF_ModuleMgr::Get()
1156 ->GetPageModule()
1157 ->GetFontGlobals()
1158 ->m_CMapManager.GetPredefinedCMap(cmap, m_pFontFile && m_bType1);
1159 } else if (CPDF_Stream* pStream = pEncoding->AsStream()) {
1160 m_pAllocatedCMap = m_pCMap = new CPDF_CMap;
1161 CPDF_StreamAcc acc;
1162 acc.LoadAllData(pStream, FALSE);
1163 m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize());
1164 } else {
1165 return FALSE;
1166 }
1167 if (!m_pCMap) {
1168 return FALSE;
1169 }
1170 m_Charset = m_pCMap->m_Charset;
1171 if (m_Charset == CIDSET_UNKNOWN) {
1172 CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDictBy("CIDSystemInfo");
1173 if (pCIDInfo) {
1174 m_Charset = CharsetFromOrdering(pCIDInfo->GetStringBy("Ordering"));
1175 }
1176 }
1177 if (m_Charset != CIDSET_UNKNOWN)
1178 m_pCID2UnicodeMap =
1179 CPDF_ModuleMgr::Get()
1180 ->GetPageModule()
1181 ->GetFontGlobals()
1182 ->m_CMapManager.GetCID2UnicodeMap(
1183 m_Charset,
1184 !m_pFontFile && (m_pCMap->m_Coding == CIDCODING_CID ||
1185 pCIDFontDict->KeyExist("W")));
1186 if (m_Font.GetFace()) {
1187 if (m_bType1) {
1188 FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE);
1189 } else {
1190 FT_UseCIDCharmap(m_Font.GetFace(), m_pCMap->m_Coding);
1191 }
1192 }
1193 m_DefaultWidth = pCIDFontDict->GetIntegerBy("DW", 1000);
1194 CPDF_Array* pWidthArray = pCIDFontDict->GetArrayBy("W");
1195 if (pWidthArray) {
1196 LoadMetricsArray(pWidthArray, m_WidthList, 1);
1197 }
1198 if (!IsEmbedded()) {
1199 LoadSubstFont();
1200 }
1201 if (1) {
1202 if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) {
1203 CPDF_Object* pmap = pCIDFontDict->GetElementValue("CIDToGIDMap");
1204 if (pmap) {
1205 if (CPDF_Stream* pStream = pmap->AsStream()) {
1206 m_pCIDToGIDMap = new CPDF_StreamAcc;
1207 m_pCIDToGIDMap->LoadAllData(pStream, FALSE);
1208 } else if (pmap->GetString() == "Identity") {
1209 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
1210 if (m_pFontFile) {
1211 m_bCIDIsGID = TRUE;
1212 }
1213 #else
1214 m_bCIDIsGID = TRUE;
1215 #endif
1216 }
1217 }
1218 }
1219 }
1220 CheckFontMetrics();
1221 if (IsVertWriting()) {
1222 pWidthArray = pCIDFontDict->GetArrayBy("W2");
1223 if (pWidthArray) {
1224 LoadMetricsArray(pWidthArray, m_VertMetrics, 3);
1225 }
1226 CPDF_Array* pDefaultArray = pCIDFontDict->GetArrayBy("DW2");
1227 if (pDefaultArray) {
1228 m_DefaultVY = pDefaultArray->GetIntegerAt(0);
1229 m_DefaultW1 = pDefaultArray->GetIntegerAt(1);
1230 } else {
1231 m_DefaultVY = 880;
1232 m_DefaultW1 = -1000;
1233 }
1234 }
1235 return TRUE;
1236 }
1237
1238 FX_RECT CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, int level) {
1239 if (charcode < 256 && m_CharBBox[charcode].right != FX_SMALL_RECT::kInvalid)
1240 return FX_RECT(m_CharBBox[charcode]);
1241
1242 FX_RECT rect;
1243 FX_BOOL bVert = FALSE;
1244 int glyph_index = GlyphFromCharCode(charcode, &bVert);
1245 FXFT_Face face = m_Font.GetFace();
1246 if (face) {
1247 if (FXFT_Is_Face_Tricky(face)) {
1248 int err = FXFT_Load_Glyph(face, glyph_index,
1249 FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
1250 if (!err) {
1251 FXFT_BBox cbox;
1252 FXFT_Glyph glyph;
1253 err = FXFT_Get_Glyph(((FXFT_Face)face)->glyph, &glyph);
1254 if (!err) {
1255 FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox);
1256 int pixel_size_x = ((FXFT_Face)face)->size->metrics.x_ppem;
1257 int pixel_size_y = ((FXFT_Face)face)->size->metrics.y_ppem;
1258 if (pixel_size_x == 0 || pixel_size_y == 0) {
1259 rect = FX_RECT(cbox.xMin, cbox.yMax, cbox.xMax, cbox.yMin);
1260 } else {
1261 rect = FX_RECT(cbox.xMin * 1000 / pixel_size_x,
1262 cbox.yMax * 1000 / pixel_size_y,
1263 cbox.xMax * 1000 / pixel_size_x,
1264 cbox.yMin * 1000 / pixel_size_y);
1265 }
1266 if (rect.top > FXFT_Get_Face_Ascender(face)) {
1267 rect.top = FXFT_Get_Face_Ascender(face);
1268 }
1269 if (rect.bottom < FXFT_Get_Face_Descender(face)) {
1270 rect.bottom = FXFT_Get_Face_Descender(face);
1271 }
1272 FXFT_Done_Glyph(glyph);
1273 }
1274 }
1275 } else {
1276 int err = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_NO_SCALE);
1277 if (err == 0) {
1278 rect = FX_RECT(TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face),
1279 TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face),
1280 TT2PDF(FXFT_Get_Glyph_HoriBearingX(face) +
1281 FXFT_Get_Glyph_Width(face),
1282 face),
1283 TT2PDF(FXFT_Get_Glyph_HoriBearingY(face) -
1284 FXFT_Get_Glyph_Height(face),
1285 face));
1286 rect.top += rect.top / 64;
1287 }
1288 }
1289 }
1290 if (!m_pFontFile && m_Charset == CIDSET_JAPAN1) {
1291 uint16_t CID = CIDFromCharCode(charcode);
1292 const uint8_t* pTransform = GetCIDTransform(CID);
1293 if (pTransform && !bVert) {
1294 CFX_Matrix matrix(CIDTransformToFloat(pTransform[0]),
1295 CIDTransformToFloat(pTransform[1]),
1296 CIDTransformToFloat(pTransform[2]),
1297 CIDTransformToFloat(pTransform[3]),
1298 CIDTransformToFloat(pTransform[4]) * 1000,
1299 CIDTransformToFloat(pTransform[5]) * 1000);
1300 CFX_FloatRect rect_f(rect);
1301 rect_f.Transform(&matrix);
1302 rect = rect_f.GetOutterRect();
1303 }
1304 }
1305 if (charcode < 256)
1306 m_CharBBox[charcode] = rect.ToSmallRect();
1307
1308 return rect;
1309 }
1310 int CPDF_CIDFont::GetCharWidthF(FX_DWORD charcode, int level) {
1311 if (m_pAnsiWidths && charcode < 0x80) {
1312 return m_pAnsiWidths[charcode];
1313 }
1314 uint16_t cid = CIDFromCharCode(charcode);
1315 int size = m_WidthList.GetSize();
1316 FX_DWORD* list = m_WidthList.GetData();
1317 for (int i = 0; i < size; i += 3) {
1318 if (cid >= list[i] && cid <= list[i + 1]) {
1319 return (int)list[i + 2];
1320 }
1321 }
1322 return m_DefaultWidth;
1323 }
1324 short CPDF_CIDFont::GetVertWidth(uint16_t CID) const {
1325 FX_DWORD vertsize = m_VertMetrics.GetSize() / 5;
1326 if (vertsize == 0) {
1327 return m_DefaultW1;
1328 }
1329 const FX_DWORD* pTable = m_VertMetrics.GetData();
1330 for (FX_DWORD i = 0; i < vertsize; i++)
1331 if (pTable[i * 5] <= CID && pTable[i * 5 + 1] >= CID) {
1332 return (short)(int)pTable[i * 5 + 2];
1333 }
1334 return m_DefaultW1;
1335 }
1336 void CPDF_CIDFont::GetVertOrigin(uint16_t CID, short& vx, short& vy) const {
1337 FX_DWORD vertsize = m_VertMetrics.GetSize() / 5;
1338 if (vertsize) {
1339 const FX_DWORD* pTable = m_VertMetrics.GetData();
1340 for (FX_DWORD i = 0; i < vertsize; i++)
1341 if (pTable[i * 5] <= CID && pTable[i * 5 + 1] >= CID) {
1342 vx = (short)(int)pTable[i * 5 + 3];
1343 vy = (short)(int)pTable[i * 5 + 4];
1344 return;
1345 }
1346 }
1347 FX_DWORD dwWidth = m_DefaultWidth;
1348 int size = m_WidthList.GetSize();
1349 const FX_DWORD* list = m_WidthList.GetData();
1350 for (int i = 0; i < size; i += 3) {
1351 if (CID >= list[i] && CID <= list[i + 1]) {
1352 dwWidth = (uint16_t)list[i + 2];
1353 break;
1354 }
1355 }
1356 vx = (short)dwWidth / 2;
1357 vy = (short)m_DefaultVY;
1358 }
1359 int CPDF_CIDFont::GetGlyphIndex(FX_DWORD unicode, FX_BOOL* pVertGlyph) {
1360 if (pVertGlyph) {
1361 *pVertGlyph = FALSE;
1362 }
1363 FXFT_Face face = m_Font.GetFace();
1364 int index = FXFT_Get_Char_Index(face, unicode);
1365 if (unicode == 0x2502) {
1366 return index;
1367 }
1368 if (index && IsVertWriting()) {
1369 if (m_pTTGSUBTable) {
1370 uint32_t vindex = 0;
1371 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex);
1372 if (vindex) {
1373 index = vindex;
1374 if (pVertGlyph) {
1375 *pVertGlyph = TRUE;
1376 }
1377 }
1378 return index;
1379 }
1380 if (!m_Font.GetSubData()) {
1381 unsigned long length = 0;
1382 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0,
1383 NULL, &length);
1384 if (!error) {
1385 m_Font.SetSubData(FX_Alloc(uint8_t, length));
1386 }
1387 }
1388 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0,
1389 m_Font.GetSubData(), NULL);
1390 if (!error && m_Font.GetSubData()) {
1391 m_pTTGSUBTable = new CFX_CTTGSUBTable;
1392 m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.GetSubData());
1393 uint32_t vindex = 0;
1394 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex);
1395 if (vindex) {
1396 index = vindex;
1397 if (pVertGlyph) {
1398 *pVertGlyph = TRUE;
1399 }
1400 }
1401 }
1402 return index;
1403 }
1404 if (pVertGlyph) {
1405 *pVertGlyph = FALSE;
1406 }
1407 return index;
1408 }
1409 int CPDF_CIDFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph) {
1410 if (pVertGlyph) {
1411 *pVertGlyph = FALSE;
1412 }
1413 if (!m_pFontFile && !m_pCIDToGIDMap) {
1414 uint16_t cid = CIDFromCharCode(charcode);
1415 FX_WCHAR unicode = 0;
1416 if (m_bCIDIsGID) {
1417 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
1418 return cid;
1419 #else
1420 if (m_Flags & PDFFONT_SYMBOLIC) {
1421 return cid;
1422 }
1423 CFX_WideString uni_str = UnicodeFromCharCode(charcode);
1424 if (uni_str.IsEmpty()) {
1425 return cid;
1426 }
1427 unicode = uni_str.GetAt(0);
1428 #endif
1429 } else {
1430 if (cid && m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded()) {
1431 unicode = m_pCID2UnicodeMap->UnicodeFromCID(cid);
1432 }
1433 if (unicode == 0) {
1434 unicode = GetUnicodeFromCharCode(charcode);
1435 }
1436 if (unicode == 0 && !(m_Flags & PDFFONT_SYMBOLIC)) {
1437 unicode = UnicodeFromCharCode(charcode).GetAt(0);
1438 }
1439 }
1440 FXFT_Face face = m_Font.GetFace();
1441 if (unicode == 0) {
1442 if (!m_bAdobeCourierStd) {
1443 return charcode == 0 ? -1 : (int)charcode;
1444 }
1445 charcode += 31;
1446 int index = 0, iBaseEncoding;
1447 FX_BOOL bMSUnicode = FT_UseTTCharmap(face, 3, 1);
1448 FX_BOOL bMacRoman = FALSE;
1449 if (!bMSUnicode) {
1450 bMacRoman = FT_UseTTCharmap(face, 1, 0);
1451 }
1452 iBaseEncoding = PDFFONT_ENCODING_STANDARD;
1453 if (bMSUnicode) {
1454 iBaseEncoding = PDFFONT_ENCODING_WINANSI;
1455 } else if (bMacRoman) {
1456 iBaseEncoding = PDFFONT_ENCODING_MACROMAN;
1457 }
1458 const FX_CHAR* name = GetAdobeCharName(iBaseEncoding, NULL, charcode);
1459 if (!name) {
1460 return charcode == 0 ? -1 : (int)charcode;
1461 }
1462 uint16_t unicode = PDF_UnicodeFromAdobeName(name);
1463 if (unicode) {
1464 if (bMSUnicode) {
1465 index = FXFT_Get_Char_Index(face, unicode);
1466 } else if (bMacRoman) {
1467 FX_DWORD maccode =
1468 FT_CharCodeFromUnicode(FXFT_ENCODING_APPLE_ROMAN, unicode);
1469 index = !maccode ? FXFT_Get_Name_Index(face, (char*)name)
1470 : FXFT_Get_Char_Index(face, maccode);
1471 } else {
1472 return FXFT_Get_Char_Index(face, unicode);
1473 }
1474 } else {
1475 return charcode == 0 ? -1 : (int)charcode;
1476 }
1477 if (index == 0 || index == 0xffff) {
1478 return charcode == 0 ? -1 : (int)charcode;
1479 }
1480 return index;
1481 }
1482 if (m_Charset == CIDSET_JAPAN1) {
1483 if (unicode == '\\') {
1484 unicode = '/';
1485 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
1486 } else if (unicode == 0xa5) {
1487 unicode = 0x5c;
1488 #endif
1489 }
1490 }
1491 if (!face)
1492 return unicode;
1493
1494 int err = FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE);
1495 if (err != 0) {
1496 int i;
1497 for (i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) {
1498 FX_DWORD ret = FT_CharCodeFromUnicode(
1499 FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[i]),
1500 (FX_WCHAR)charcode);
1501 if (ret == 0) {
1502 continue;
1503 }
1504 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[i]);
1505 unicode = (FX_WCHAR)ret;
1506 break;
1507 }
1508 if (i == FXFT_Get_Face_CharmapCount(face) && i) {
1509 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[0]);
1510 unicode = (FX_WCHAR)charcode;
1511 }
1512 }
1513 if (FXFT_Get_Face_Charmap(face)) {
1514 int index = GetGlyphIndex(unicode, pVertGlyph);
1515 if (index == 0)
1516 return -1;
1517 return index;
1518 }
1519 return unicode;
1520 }
1521 if (!m_Font.GetFace())
1522 return -1;
1523
1524 uint16_t cid = CIDFromCharCode(charcode);
1525 if (m_bType1) {
1526 if (!m_pCIDToGIDMap) {
1527 return cid;
1528 }
1529 } else {
1530 if (!m_pCIDToGIDMap) {
1531 if (m_pFontFile && !m_pCMap->m_pMapping)
1532 return cid;
1533 if (m_pCMap->m_Coding == CIDCODING_UNKNOWN ||
1534 !FXFT_Get_Face_Charmap(m_Font.GetFace())) {
1535 return cid;
1536 }
1537 if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmap(m_Font.GetFace())) ==
1538 FXFT_ENCODING_UNICODE) {
1539 CFX_WideString unicode_str = UnicodeFromCharCode(charcode);
1540 if (unicode_str.IsEmpty()) {
1541 return -1;
1542 }
1543 charcode = unicode_str.GetAt(0);
1544 }
1545 return GetGlyphIndex(charcode, pVertGlyph);
1546 }
1547 }
1548 FX_DWORD byte_pos = cid * 2;
1549 if (byte_pos + 2 > m_pCIDToGIDMap->GetSize())
1550 return -1;
1551
1552 const uint8_t* pdata = m_pCIDToGIDMap->GetData() + byte_pos;
1553 return pdata[0] * 256 + pdata[1];
1554 }
1555 FX_DWORD CPDF_CIDFont::GetNextChar(const FX_CHAR* pString,
1556 int nStrLen,
1557 int& offset) const {
1558 return m_pCMap->GetNextChar(pString, nStrLen, offset);
1559 }
1560 int CPDF_CIDFont::GetCharSize(FX_DWORD charcode) const {
1561 return m_pCMap->GetCharSize(charcode);
1562 }
1563 int CPDF_CIDFont::CountChar(const FX_CHAR* pString, int size) const {
1564 return m_pCMap->CountChar(pString, size);
1565 }
1566 int CPDF_CIDFont::AppendChar(FX_CHAR* str, FX_DWORD charcode) const {
1567 return m_pCMap->AppendChar(str, charcode);
1568 }
1569 FX_BOOL CPDF_CIDFont::IsUnicodeCompatible() const {
1570 if (!m_pCMap->IsLoaded() || !m_pCID2UnicodeMap ||
1571 !m_pCID2UnicodeMap->IsLoaded()) {
1572 return m_pCMap->m_Coding != CIDCODING_UNKNOWN;
1573 }
1574 return TRUE;
1575 }
1576 FX_BOOL CPDF_CIDFont::IsFontStyleFromCharCode(FX_DWORD charcode) const {
1577 return TRUE;
1578 }
1579 void CPDF_CIDFont::LoadSubstFont() {
1580 m_Font.LoadSubst(m_BaseFont, !m_bType1, m_Flags, m_StemV * 5, m_ItalicAngle,
1581 g_CharsetCPs[m_Charset], IsVertWriting());
1582 }
1583 void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray,
1584 CFX_DWordArray& result,
1585 int nElements) {
1586 int width_status = 0;
1587 int iCurElement = 0;
1588 int first_code = 0;
1589 int last_code = 0;
1590 FX_DWORD count = pArray->GetCount();
1591 for (FX_DWORD i = 0; i < count; i++) {
1592 CPDF_Object* pObj = pArray->GetElementValue(i);
1593 if (!pObj)
1594 continue;
1595
1596 if (CPDF_Array* pArray = pObj->AsArray()) {
1597 if (width_status != 1)
1598 return;
1599
1600 FX_DWORD count = pArray->GetCount();
1601 for (FX_DWORD j = 0; j < count; j += nElements) {
1602 result.Add(first_code);
1603 result.Add(first_code);
1604 for (int k = 0; k < nElements; k++) {
1605 result.Add(pArray->GetIntegerAt(j + k));
1606 }
1607 first_code++;
1608 }
1609 width_status = 0;
1610 } else {
1611 if (width_status == 0) {
1612 first_code = pObj->GetInteger();
1613 width_status = 1;
1614 } else if (width_status == 1) {
1615 last_code = pObj->GetInteger();
1616 width_status = 2;
1617 iCurElement = 0;
1618 } else {
1619 if (!iCurElement) {
1620 result.Add(first_code);
1621 result.Add(last_code);
1622 }
1623 result.Add(pObj->GetInteger());
1624 iCurElement++;
1625 if (iCurElement == nElements) {
1626 width_status = 0;
1627 }
1628 }
1629 }
1630 }
1631 }
1632
1633 // static
1634 FX_FLOAT CPDF_CIDFont::CIDTransformToFloat(uint8_t ch) {
1635 if (ch < 128) {
1636 return ch * 1.0f / 127;
1637 }
1638 return (-255 + ch) * 1.0f / 127;
1639 }
1640
1641 FX_BOOL CPDF_CIDFont::LoadGB2312() {
1642 m_BaseFont = m_pFontDict->GetStringBy("BaseFont");
1643 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictBy("FontDescriptor");
1644 if (pFontDesc) {
1645 LoadFontDescriptor(pFontDesc);
1646 }
1647 m_Charset = CIDSET_GB1;
1648 m_bType1 = FALSE;
1649 m_pCMap = CPDF_ModuleMgr::Get()
1650 ->GetPageModule()
1651 ->GetFontGlobals()
1652 ->m_CMapManager.GetPredefinedCMap("GBK-EUC-H", FALSE);
1653 m_pCID2UnicodeMap = CPDF_ModuleMgr::Get()
1654 ->GetPageModule()
1655 ->GetFontGlobals()
1656 ->m_CMapManager.GetCID2UnicodeMap(m_Charset, FALSE);
1657 if (!IsEmbedded()) {
1658 LoadSubstFont();
1659 }
1660 CheckFontMetrics();
1661 m_DefaultWidth = 1000;
1662 m_pAnsiWidths = FX_Alloc(uint16_t, 128);
1663 for (int i = 32; i < 127; i++) {
1664 m_pAnsiWidths[i] = 500;
1665 }
1666 return TRUE;
1667 }
1668
1669 const uint8_t* CPDF_CIDFont::GetCIDTransform(uint16_t CID) const {
1670 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile)
1671 return nullptr;
1672
1673 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch(
1674 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs),
1675 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform);
1676 return found ? &found->a : nullptr;
1677 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698