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

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

Powered by Google App Engine
This is Rietveld 408576698