OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../../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 "font_int.h" | 9 #include "font_int.h" |
10 #include "../fpdf_cmaps/cmap_int.h" | 10 #include "../fpdf_cmaps/cmap_int.h" |
11 #include "../../../include/fxge/fx_ge.h" | 11 #include "../../../include/fxge/fx_ge.h" |
12 #include "../../../include/fxge/fx_freetype.h" | 12 #include "../../../include/fxge/fx_freetype.h" |
13 extern FX_DWORD FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode); | 13 extern FX_DWORD FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode); |
14 extern FX_LPVOID FXFC_LoadPackage(FX_LPCSTR name); | 14 extern FX_LPVOID FXFC_LoadPackage(FX_LPCSTR name); |
15 extern FX_BOOL FXFC_LoadFile(FX_LPVOID pPackage, FX_LPCSTR name, FX_LPBYTE& pBuf
fer, FX_DWORD& size); | 15 extern FX_BOOL FXFC_LoadFile(FX_LPVOID pPackage, FX_LPCSTR name, FX_LPBYTE& pBuf
fer, FX_DWORD& size); |
16 extern void FXFC_ClosePackage(FX_LPVOID pPackage); | 16 extern void FXFC_ClosePackage(FX_LPVOID pPackage); |
17 extern short TT2PDF(int m, FXFT_Face face); | 17 extern short TT2PDF(int m, FXFT_Face face); |
18 extern FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id)
; | 18 extern FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id)
; |
19 extern FX_LPCSTR GetAdobeCharName(int iBaseEncoding, const CFX_ByteString* pChar
Names, int charcode); | 19 extern FX_LPCSTR GetAdobeCharName(int iBaseEncoding, const CFX_ByteString* pChar
Names, int charcode); |
20 CPDF_CMapManager::CPDF_CMapManager() | 20 CPDF_CMapManager::CPDF_CMapManager() |
21 { | 21 { |
22 #ifndef _FPDFAPI_MINI_ | |
23 m_bPrompted = FALSE; | 22 m_bPrompted = FALSE; |
24 m_pPackage = NULL; | 23 m_pPackage = NULL; |
25 #endif | |
26 FXSYS_memset32(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps); | 24 FXSYS_memset32(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps); |
27 } | 25 } |
28 CPDF_CMapManager::~CPDF_CMapManager() | 26 CPDF_CMapManager::~CPDF_CMapManager() |
29 { | 27 { |
30 DropAll(FALSE); | 28 DropAll(FALSE); |
31 #ifndef _FPDFAPI_MINI_ | |
32 if (m_pPackage) { | 29 if (m_pPackage) { |
33 FXFC_ClosePackage(m_pPackage); | 30 FXFC_ClosePackage(m_pPackage); |
34 } | 31 } |
35 #endif | |
36 } | 32 } |
37 #ifndef _FPDFAPI_MINI_ | |
38 FX_LPVOID CPDF_CMapManager::GetPackage(FX_BOOL bPrompt) | 33 FX_LPVOID CPDF_CMapManager::GetPackage(FX_BOOL bPrompt) |
39 { | 34 { |
40 #ifndef FOXIT_CHROME_BUILD | |
41 if (m_pPackage == NULL) { | |
42 CFX_ByteString filename = CPDF_ModuleMgr::Get()->GetModuleFilePath(ADDIN
_NAME_CJK, "FPDFCJK.BIN"); | |
43 m_pPackage = FXFC_LoadPackage(filename); | |
44 if (bPrompt && m_pPackage == NULL && !m_bPrompted) { | |
45 m_bPrompted = TRUE; | |
46 if (!CPDF_ModuleMgr::Get()->DownloadModule(ADDIN_NAME_CJK)) { | |
47 return NULL; | |
48 } | |
49 m_pPackage = FXFC_LoadPackage(filename); | |
50 } | |
51 } | |
52 #endif | |
53 return m_pPackage; | 35 return m_pPackage; |
54 } | 36 } |
55 #endif | |
56 CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name, FX_BO
OL bPromptCJK) | 37 CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name, FX_BO
OL bPromptCJK) |
57 { | 38 { |
58 CPDF_CMap* pCMap; | 39 CPDF_CMap* pCMap; |
59 if (m_CMaps.Lookup(name, (FX_LPVOID&)pCMap)) { | 40 if (m_CMaps.Lookup(name, (FX_LPVOID&)pCMap)) { |
60 return pCMap; | 41 return pCMap; |
61 } | 42 } |
62 pCMap = LoadPredefinedCMap(name, bPromptCJK); | 43 pCMap = LoadPredefinedCMap(name, bPromptCJK); |
63 if (name.IsEmpty()) { | 44 if (name.IsEmpty()) { |
64 return pCMap; | 45 return pCMap; |
65 } | 46 } |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 for (int b = map.m_LeadingSegs[i * 2]; b <= map.m_LeadingSegs[i * 2
+ 1]; b ++) { | 392 for (int b = map.m_LeadingSegs[i * 2]; b <= map.m_LeadingSegs[i * 2
+ 1]; b ++) { |
412 m_pLeadingBytes[b] = 1; | 393 m_pLeadingBytes[b] = 1; |
413 } | 394 } |
414 } | 395 } |
415 } | 396 } |
416 FPDFAPI_FindEmbeddedCMap(pName, m_Charset, m_Coding, m_pEmbedMap); | 397 FPDFAPI_FindEmbeddedCMap(pName, m_Charset, m_Coding, m_pEmbedMap); |
417 if (m_pEmbedMap) { | 398 if (m_pEmbedMap) { |
418 m_bLoaded = TRUE; | 399 m_bLoaded = TRUE; |
419 return TRUE; | 400 return TRUE; |
420 } | 401 } |
421 #ifndef _FPDFAPI_MINI_ | |
422 FX_LPVOID pPackage = pMgr->GetPackage(bPromptCJK); | 402 FX_LPVOID pPackage = pMgr->GetPackage(bPromptCJK); |
423 FX_LPBYTE pBuffer; | 403 FX_LPBYTE pBuffer; |
424 FX_DWORD size; | 404 FX_DWORD size; |
425 if (pPackage == NULL || !FXFC_LoadFile(pPackage, m_PredefinedCMap, pBuffer,
size)) { | 405 if (pPackage == NULL || !FXFC_LoadFile(pPackage, m_PredefinedCMap, pBuffer,
size)) { |
426 return FALSE; | 406 return FALSE; |
427 } | 407 } |
428 m_pMapping = FX_Alloc(FX_WORD, 65536); | 408 m_pMapping = FX_Alloc(FX_WORD, 65536); |
429 FX_DWORD dwRecodeEndPos = 0; | 409 FX_DWORD dwRecodeEndPos = 0; |
430 if (pBuffer[5] == 0) { | 410 if (pBuffer[5] == 0) { |
431 FX_DWORD dwStartIndex = *(FX_DWORD*)(pBuffer + 8); | 411 FX_DWORD dwStartIndex = *(FX_DWORD*)(pBuffer + 8); |
(...skipping 23 matching lines...) Expand all Loading... |
455 if (dwMapLen) { | 435 if (dwMapLen) { |
456 m_pUseMap = FX_NEW CPDF_CMap; | 436 m_pUseMap = FX_NEW CPDF_CMap; |
457 CFX_ByteString bsName(pBuffer + dwRecodeEndPos + 4 , dwMapLen); | 437 CFX_ByteString bsName(pBuffer + dwRecodeEndPos + 4 , dwMapLen); |
458 if (m_pUseMap) { | 438 if (m_pUseMap) { |
459 m_pUseMap->LoadPredefined(pMgr, bsName, bPromptCJK); | 439 m_pUseMap->LoadPredefined(pMgr, bsName, bPromptCJK); |
460 } | 440 } |
461 } | 441 } |
462 } | 442 } |
463 FX_Free(pBuffer); | 443 FX_Free(pBuffer); |
464 m_bLoaded = TRUE; | 444 m_bLoaded = TRUE; |
465 #endif | |
466 return TRUE; | 445 return TRUE; |
467 } | 446 } |
468 extern "C" { | 447 extern "C" { |
469 static int compare_dword(const void* data1, const void* data2) | 448 static int compare_dword(const void* data1, const void* data2) |
470 { | 449 { |
471 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2); | 450 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2); |
472 } | 451 } |
473 }; | 452 }; |
474 FX_BOOL CPDF_CMap::LoadEmbedded(FX_LPCBYTE pData, FX_DWORD size) | 453 FX_BOOL CPDF_CMap::LoadEmbedded(FX_LPCBYTE pData, FX_DWORD size) |
475 { | 454 { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 str[2] = (FX_BYTE)(charcode >> 8); | 711 str[2] = (FX_BYTE)(charcode >> 8); |
733 str[3] = (FX_BYTE)charcode; | 712 str[3] = (FX_BYTE)charcode; |
734 return 4; | 713 return 4; |
735 } | 714 } |
736 } | 715 } |
737 return 0; | 716 return 0; |
738 } | 717 } |
739 CPDF_CID2UnicodeMap::CPDF_CID2UnicodeMap() | 718 CPDF_CID2UnicodeMap::CPDF_CID2UnicodeMap() |
740 { | 719 { |
741 m_EmbeddedCount = 0; | 720 m_EmbeddedCount = 0; |
742 #ifndef _FPDFAPI_MINI_ | |
743 m_pExternalMap = NULL; | 721 m_pExternalMap = NULL; |
744 #endif | |
745 } | 722 } |
746 CPDF_CID2UnicodeMap::~CPDF_CID2UnicodeMap() | 723 CPDF_CID2UnicodeMap::~CPDF_CID2UnicodeMap() |
747 { | 724 { |
748 #ifndef _FPDFAPI_MINI_ | |
749 if (m_pExternalMap) { | 725 if (m_pExternalMap) { |
750 delete m_pExternalMap; | 726 delete m_pExternalMap; |
751 } | 727 } |
752 #endif | |
753 } | 728 } |
754 FX_BOOL CPDF_CID2UnicodeMap::Initialize() | 729 FX_BOOL CPDF_CID2UnicodeMap::Initialize() |
755 { | 730 { |
756 #ifndef _FPDFAPI_MINI_ | |
757 m_pExternalMap = FX_NEW CPDF_FXMP; | 731 m_pExternalMap = FX_NEW CPDF_FXMP; |
758 #endif | |
759 return TRUE; | 732 return TRUE; |
760 } | 733 } |
761 FX_BOOL CPDF_CID2UnicodeMap::IsLoaded() | 734 FX_BOOL CPDF_CID2UnicodeMap::IsLoaded() |
762 { | 735 { |
763 #ifdef _FPDFAPI_MINI_ | |
764 return m_EmbeddedCount != 0; | |
765 #else | |
766 return m_EmbeddedCount != 0 || (m_pExternalMap != NULL && m_pExternalMap->Is
Loaded()); | 736 return m_EmbeddedCount != 0 || (m_pExternalMap != NULL && m_pExternalMap->Is
Loaded()); |
767 #endif | |
768 } | 737 } |
769 FX_WCHAR CPDF_CID2UnicodeMap::UnicodeFromCID(FX_WORD CID) | 738 FX_WCHAR CPDF_CID2UnicodeMap::UnicodeFromCID(FX_WORD CID) |
770 { | 739 { |
771 if (m_Charset == CIDSET_UNICODE) { | 740 if (m_Charset == CIDSET_UNICODE) { |
772 return CID; | 741 return CID; |
773 } | 742 } |
774 if (CID < m_EmbeddedCount) { | 743 if (CID < m_EmbeddedCount) { |
775 return m_pEmbeddedMap[CID]; | 744 return m_pEmbeddedMap[CID]; |
776 } | 745 } |
777 #ifdef _FPDFAPI_MINI_ | |
778 return 0; | |
779 #else | |
780 FX_LPCBYTE record = m_pExternalMap->GetRecord(CID); | 746 FX_LPCBYTE record = m_pExternalMap->GetRecord(CID); |
781 if (record == NULL) { | 747 if (record == NULL) { |
782 return 0; | 748 return 0; |
783 } | 749 } |
784 return *(FX_WORD*)record; | 750 return *(FX_WORD*)record; |
785 #endif | |
786 } | 751 } |
787 void FPDFAPI_LoadCID2UnicodeMap(int charset, const FX_WORD*& pMap, FX_DWORD& cou
nt); | 752 void FPDFAPI_LoadCID2UnicodeMap(int charset, const FX_WORD*& pMap, FX_DWORD& cou
nt); |
788 void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, int charset, FX_BOOL bPro
mptCJK) | 753 void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, int charset, FX_BOOL bPro
mptCJK) |
789 { | 754 { |
790 m_Charset = charset; | 755 m_Charset = charset; |
791 FPDFAPI_LoadCID2UnicodeMap(charset, m_pEmbeddedMap, m_EmbeddedCount); | 756 FPDFAPI_LoadCID2UnicodeMap(charset, m_pEmbeddedMap, m_EmbeddedCount); |
792 if (m_EmbeddedCount) { | 757 if (m_EmbeddedCount) { |
793 return; | 758 return; |
794 } | 759 } |
795 #ifndef _FPDFAPI_MINI_ | |
796 FX_LPVOID pPackage = pMgr->GetPackage(bPromptCJK); | 760 FX_LPVOID pPackage = pMgr->GetPackage(bPromptCJK); |
797 if (pPackage == NULL) { | 761 if (pPackage == NULL) { |
798 return; | 762 return; |
799 } | 763 } |
800 m_pExternalMap->LoadFile(pPackage, FX_BSTRC("CIDInfo_") + g_CharsetNames[cha
rset]); | 764 m_pExternalMap->LoadFile(pPackage, FX_BSTRC("CIDInfo_") + g_CharsetNames[cha
rset]); |
801 #endif | |
802 } | 765 } |
803 #include "ttgsubtable.h" | 766 #include "ttgsubtable.h" |
804 CPDF_CIDFont::CPDF_CIDFont() | 767 CPDF_CIDFont::CPDF_CIDFont() |
805 { | 768 { |
806 m_pCMap = NULL; | 769 m_pCMap = NULL; |
807 m_pAllocatedCMap = NULL; | 770 m_pAllocatedCMap = NULL; |
808 m_pCID2UnicodeMap = NULL; | 771 m_pCID2UnicodeMap = NULL; |
809 m_pAnsiWidths = NULL; | 772 m_pAnsiWidths = NULL; |
810 m_pCIDToGIDMap = NULL; | 773 m_pCIDToGIDMap = NULL; |
811 m_bCIDIsGID = FALSE; | 774 m_bCIDIsGID = FALSE; |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 if (index == 0 || index == 0xffff) { | 1312 if (index == 0 || index == 0xffff) { |
1350 return charcode == 0 ? -1 : (int)charcode; | 1313 return charcode == 0 ? -1 : (int)charcode; |
1351 } else { | 1314 } else { |
1352 return index; | 1315 return index; |
1353 } | 1316 } |
1354 } | 1317 } |
1355 if (m_Charset == CIDSET_JAPAN1) { | 1318 if (m_Charset == CIDSET_JAPAN1) { |
1356 if (unicode == '\\') { | 1319 if (unicode == '\\') { |
1357 unicode = '/'; | 1320 unicode = '/'; |
1358 } | 1321 } |
1359 #if !defined(_FPDFAPI_MINI_) && _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ | 1322 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ |
1360 else if (unicode == 0xa5) { | 1323 else if (unicode == 0xa5) { |
1361 unicode = 0x5c; | 1324 unicode = 0x5c; |
1362 } | 1325 } |
1363 #endif | 1326 #endif |
1364 } | 1327 } |
1365 if (m_Font.m_Face == NULL) { | 1328 if (m_Font.m_Face == NULL) { |
1366 return unicode; | 1329 return unicode; |
1367 } | 1330 } |
1368 int err = FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE); | 1331 int err = FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE); |
1369 if (err != 0) { | 1332 if (err != 0) { |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1699 if (middlecode > CID) { | 1662 if (middlecode > CID) { |
1700 end = middle - 1; | 1663 end = middle - 1; |
1701 } else if (middlecode < CID) { | 1664 } else if (middlecode < CID) { |
1702 begin = middle + 1; | 1665 begin = middle + 1; |
1703 } else { | 1666 } else { |
1704 return &Japan1_VertCIDs[middle].a; | 1667 return &Japan1_VertCIDs[middle].a; |
1705 } | 1668 } |
1706 } | 1669 } |
1707 return NULL; | 1670 return NULL; |
1708 } | 1671 } |
OLD | NEW |