| 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 "../../../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 extern short TT2PDF(int m, FXFT_Face face); | 15 extern short TT2PDF(int m, FXFT_Face face); |
| 16 extern FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id)
; | 16 extern bool FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id); |
| 17 | 17 |
| 18 CPDF_CMapManager::CPDF_CMapManager() | 18 CPDF_CMapManager::CPDF_CMapManager() |
| 19 { | 19 { |
| 20 m_bPrompted = FALSE; | 20 m_bPrompted = false; |
| 21 FXSYS_memset(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps); | 21 FXSYS_memset(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps); |
| 22 } | 22 } |
| 23 CPDF_CMapManager::~CPDF_CMapManager() | 23 CPDF_CMapManager::~CPDF_CMapManager() |
| 24 { | 24 { |
| 25 DropAll(FALSE); | 25 DropAll(false); |
| 26 } | 26 } |
| 27 CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name, FX_BO
OL bPromptCJK) | 27 CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name, bool
bPromptCJK) |
| 28 { | 28 { |
| 29 CPDF_CMap* pCMap; | 29 CPDF_CMap* pCMap; |
| 30 if (m_CMaps.Lookup(name, (void*&)pCMap)) { | 30 if (m_CMaps.Lookup(name, (void*&)pCMap)) { |
| 31 return pCMap; | 31 return pCMap; |
| 32 } | 32 } |
| 33 pCMap = LoadPredefinedCMap(name, bPromptCJK); | 33 pCMap = LoadPredefinedCMap(name, bPromptCJK); |
| 34 if (name.IsEmpty()) { | 34 if (name.IsEmpty()) { |
| 35 return pCMap; | 35 return pCMap; |
| 36 } | 36 } |
| 37 m_CMaps.SetAt(name, pCMap); | 37 m_CMaps.SetAt(name, pCMap); |
| 38 return pCMap; | 38 return pCMap; |
| 39 } | 39 } |
| 40 CPDF_CMap* CPDF_CMapManager::LoadPredefinedCMap(const CFX_ByteString& name, FX_B
OOL bPromptCJK) | 40 CPDF_CMap* CPDF_CMapManager::LoadPredefinedCMap(const CFX_ByteString& name, bool
bPromptCJK) |
| 41 { | 41 { |
| 42 CPDF_CMap* pCMap = new CPDF_CMap; | 42 CPDF_CMap* pCMap = new CPDF_CMap; |
| 43 const FX_CHAR* pname = name; | 43 const FX_CHAR* pname = name; |
| 44 if (*pname == '/') { | 44 if (*pname == '/') { |
| 45 pname ++; | 45 pname ++; |
| 46 } | 46 } |
| 47 pCMap->LoadPredefined(this, pname, bPromptCJK); | 47 pCMap->LoadPredefined(this, pname, bPromptCJK); |
| 48 return pCMap; | 48 return pCMap; |
| 49 } | 49 } |
| 50 static const FX_CHAR* const g_CharsetNames[NUMBER_OF_CIDSETS] = {NULL, "GB1", "C
NS1", "Japan1", "Korea1", "UCS" }; | 50 static const FX_CHAR* const g_CharsetNames[NUMBER_OF_CIDSETS] = {NULL, "GB1", "C
NS1", "Japan1", "Korea1", "UCS" }; |
| 51 static const int g_CharsetCPs[NUMBER_OF_CIDSETS] = {0, 936, 950, 932, 949, 1200
}; | 51 static const int g_CharsetCPs[NUMBER_OF_CIDSETS] = {0, 936, 950, 932, 949, 1200
}; |
| 52 int _CharsetFromOrdering(const CFX_ByteString& Ordering) | 52 int _CharsetFromOrdering(const CFX_ByteString& Ordering) |
| 53 { | 53 { |
| 54 for (int charset = 1; charset < NUMBER_OF_CIDSETS; charset++) { | 54 for (int charset = 1; charset < NUMBER_OF_CIDSETS; charset++) { |
| 55 if (Ordering == CFX_ByteStringC(g_CharsetNames[charset])) | 55 if (Ordering == CFX_ByteStringC(g_CharsetNames[charset])) |
| 56 return charset; | 56 return charset; |
| 57 } | 57 } |
| 58 return CIDSET_UNKNOWN; | 58 return CIDSET_UNKNOWN; |
| 59 } | 59 } |
| 60 void CPDF_CMapManager::ReloadAll() | 60 void CPDF_CMapManager::ReloadAll() |
| 61 { | 61 { |
| 62 DropAll(TRUE); | 62 DropAll(true); |
| 63 } | 63 } |
| 64 void CPDF_CMapManager::DropAll(FX_BOOL bReload) | 64 void CPDF_CMapManager::DropAll(bool bReload) |
| 65 { | 65 { |
| 66 FX_POSITION pos = m_CMaps.GetStartPosition(); | 66 FX_POSITION pos = m_CMaps.GetStartPosition(); |
| 67 while (pos) { | 67 while (pos) { |
| 68 CFX_ByteString name; | 68 CFX_ByteString name; |
| 69 CPDF_CMap* pCMap; | 69 CPDF_CMap* pCMap; |
| 70 m_CMaps.GetNextAssoc(pos, name, (void*&)pCMap); | 70 m_CMaps.GetNextAssoc(pos, name, (void*&)pCMap); |
| 71 if (pCMap == NULL) { | 71 if (pCMap == NULL) { |
| 72 continue; | 72 continue; |
| 73 } | 73 } |
| 74 if (bReload) { | 74 if (bReload) { |
| 75 pCMap->LoadPredefined(this, name, FALSE); | 75 pCMap->LoadPredefined(this, name, false); |
| 76 } else { | 76 } else { |
| 77 delete pCMap; | 77 delete pCMap; |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 for (int i = 0; i < sizeof m_CID2UnicodeMaps / sizeof(CPDF_CID2UnicodeMap*);
i ++) { | 80 for (int i = 0; i < sizeof m_CID2UnicodeMaps / sizeof(CPDF_CID2UnicodeMap*);
i ++) { |
| 81 CPDF_CID2UnicodeMap* pMap = m_CID2UnicodeMaps[i]; | 81 CPDF_CID2UnicodeMap* pMap = m_CID2UnicodeMaps[i]; |
| 82 if (pMap == NULL) { | 82 if (pMap == NULL) { |
| 83 continue; | 83 continue; |
| 84 } | 84 } |
| 85 if (bReload) { | 85 if (bReload) { |
| 86 pMap->Load(this, i, FALSE); | 86 pMap->Load(this, i, false); |
| 87 } else { | 87 } else { |
| 88 delete pMap; | 88 delete pMap; |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(int charset, FX_BOOL bP
romptCJK) | 92 CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(int charset, bool bProm
ptCJK) |
| 93 { | 93 { |
| 94 if (m_CID2UnicodeMaps[charset] == NULL) { | 94 if (m_CID2UnicodeMaps[charset] == NULL) { |
| 95 m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK); | 95 m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK); |
| 96 } | 96 } |
| 97 return m_CID2UnicodeMaps[charset]; | 97 return m_CID2UnicodeMaps[charset]; |
| 98 } | 98 } |
| 99 CPDF_CID2UnicodeMap* CPDF_CMapManager::LoadCID2UnicodeMap(int charset, FX_BOOL b
PromptCJK) | 99 CPDF_CID2UnicodeMap* CPDF_CMapManager::LoadCID2UnicodeMap(int charset, bool bPro
mptCJK) |
| 100 { | 100 { |
| 101 CPDF_CID2UnicodeMap* pMap = new CPDF_CID2UnicodeMap(); | 101 CPDF_CID2UnicodeMap* pMap = new CPDF_CID2UnicodeMap(); |
| 102 if (!pMap->Initialize()) { | 102 if (!pMap->Initialize()) { |
| 103 delete pMap; | 103 delete pMap; |
| 104 return NULL; | 104 return NULL; |
| 105 } | 105 } |
| 106 pMap->Load(this, charset, bPromptCJK); | 106 pMap->Load(this, charset, bPromptCJK); |
| 107 return pMap; | 107 return pMap; |
| 108 } | 108 } |
| 109 CPDF_CMapParser::CPDF_CMapParser() | 109 CPDF_CMapParser::CPDF_CMapParser() |
| 110 { | 110 { |
| 111 m_pCMap = NULL; | 111 m_pCMap = NULL; |
| 112 m_Status = 0; | 112 m_Status = 0; |
| 113 m_CodeSeq = 0; | 113 m_CodeSeq = 0; |
| 114 } | 114 } |
| 115 FX_BOOL»CPDF_CMapParser::Initialize(CPDF_CMap* pCMap) | 115 bool» CPDF_CMapParser::Initialize(CPDF_CMap* pCMap) |
| 116 { | 116 { |
| 117 m_pCMap = pCMap; | 117 m_pCMap = pCMap; |
| 118 m_Status = 0; | 118 m_Status = 0; |
| 119 m_CodeSeq = 0; | 119 m_CodeSeq = 0; |
| 120 m_AddMaps.EstimateSize(0, 10240); | 120 m_AddMaps.EstimateSize(0, 10240); |
| 121 return TRUE; | 121 return true; |
| 122 } | 122 } |
| 123 static FX_DWORD CMap_GetCode(const CFX_ByteStringC& word) | 123 static FX_DWORD CMap_GetCode(const CFX_ByteStringC& word) |
| 124 { | 124 { |
| 125 int num = 0; | 125 int num = 0; |
| 126 if (word.GetAt(0) == '<') { | 126 if (word.GetAt(0) == '<') { |
| 127 for (int i = 1; i < word.GetLength(); i ++) { | 127 for (int i = 1; i < word.GetLength(); i ++) { |
| 128 uint8_t digit = word.GetAt(i); | 128 uint8_t digit = word.GetAt(i); |
| 129 if (digit >= '0' && digit <= '9') { | 129 if (digit >= '0' && digit <= '9') { |
| 130 digit = digit - '0'; | 130 digit = digit - '0'; |
| 131 } else if (digit >= 'a' && digit <= 'f') { | 131 } else if (digit >= 'a' && digit <= 'f') { |
| 132 digit = digit - 'a' + 10; | 132 digit = digit - 'a' + 10; |
| 133 } else if (digit >= 'A' && digit <= 'F') { | 133 } else if (digit >= 'A' && digit <= 'F') { |
| 134 digit = digit - 'A' + 10; | 134 digit = digit - 'A' + 10; |
| 135 } else { | 135 } else { |
| 136 return num; | 136 return num; |
| 137 } | 137 } |
| 138 num = num * 16 + digit; | 138 num = num * 16 + digit; |
| 139 } | 139 } |
| 140 } else { | 140 } else { |
| 141 for (int i = 0; i < word.GetLength(); i ++) { | 141 for (int i = 0; i < word.GetLength(); i ++) { |
| 142 if (word.GetAt(i) < '0' || word.GetAt(i) > '9') { | 142 if (word.GetAt(i) < '0' || word.GetAt(i) > '9') { |
| 143 return num; | 143 return num; |
| 144 } | 144 } |
| 145 num = num * 10 + word.GetAt(i) - '0'; | 145 num = num * 10 + word.GetAt(i) - '0'; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 return num; | 148 return num; |
| 149 } | 149 } |
| 150 static FX_BOOL _CMap_GetCodeRange(_CMap_CodeRange& range, const CFX_ByteStringC&
first, const CFX_ByteStringC& second) | 150 static bool _CMap_GetCodeRange(_CMap_CodeRange& range, const CFX_ByteStringC& fi
rst, const CFX_ByteStringC& second) |
| 151 { | 151 { |
| 152 if (first.GetLength() == 0 || first.GetAt(0) != '<') { | 152 if (first.GetLength() == 0 || first.GetAt(0) != '<') { |
| 153 return FALSE; | 153 return false; |
| 154 } | 154 } |
| 155 int i; | 155 int i; |
| 156 for (i = 1; i < first.GetLength(); i ++) | 156 for (i = 1; i < first.GetLength(); i ++) |
| 157 if (first.GetAt(i) == '>') { | 157 if (first.GetAt(i) == '>') { |
| 158 break; | 158 break; |
| 159 } | 159 } |
| 160 range.m_CharSize = (i - 1) / 2; | 160 range.m_CharSize = (i - 1) / 2; |
| 161 if (range.m_CharSize > 4) { | 161 if (range.m_CharSize > 4) { |
| 162 return FALSE; | 162 return false; |
| 163 } | 163 } |
| 164 for (i = 0; i < range.m_CharSize; i ++) { | 164 for (i = 0; i < range.m_CharSize; i ++) { |
| 165 uint8_t digit1 = first.GetAt(i * 2 + 1); | 165 uint8_t digit1 = first.GetAt(i * 2 + 1); |
| 166 uint8_t digit2 = first.GetAt(i * 2 + 2); | 166 uint8_t digit2 = first.GetAt(i * 2 + 2); |
| 167 uint8_t byte = (digit1 >= '0' && digit1 <= '9') ? (digit1 - '0') : ((dig
it1 & 0xdf) - 'A' + 10); | 167 uint8_t byte = (digit1 >= '0' && digit1 <= '9') ? (digit1 - '0') : ((dig
it1 & 0xdf) - 'A' + 10); |
| 168 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') ? (digit2 - '0') :
((digit2 & 0xdf) - 'A' + 10)); | 168 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') ? (digit2 - '0') :
((digit2 & 0xdf) - 'A' + 10)); |
| 169 range.m_Lower[i] = byte; | 169 range.m_Lower[i] = byte; |
| 170 } | 170 } |
| 171 FX_DWORD size = second.GetLength(); | 171 FX_DWORD size = second.GetLength(); |
| 172 for (i = 0; i < range.m_CharSize; i ++) { | 172 for (i = 0; i < range.m_CharSize; i ++) { |
| 173 uint8_t digit1 = ((FX_DWORD)i * 2 + 1 < size) ? second.GetAt((FX_STRSIZE
)i * 2 + 1) : 0; | 173 uint8_t digit1 = ((FX_DWORD)i * 2 + 1 < size) ? second.GetAt((FX_STRSIZE
)i * 2 + 1) : 0; |
| 174 uint8_t digit2 = ((FX_DWORD)i * 2 + 2 < size) ? second.GetAt((FX_STRSIZE
)i * 2 + 2) : 0; | 174 uint8_t digit2 = ((FX_DWORD)i * 2 + 2 < size) ? second.GetAt((FX_STRSIZE
)i * 2 + 2) : 0; |
| 175 uint8_t byte = (digit1 >= '0' && digit1 <= '9') ? (digit1 - '0') : ((dig
it1 & 0xdf) - 'A' + 10); | 175 uint8_t byte = (digit1 >= '0' && digit1 <= '9') ? (digit1 - '0') : ((dig
it1 & 0xdf) - 'A' + 10); |
| 176 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') ? (digit2 - '0') :
((digit2 & 0xdf) - 'A' + 10)); | 176 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') ? (digit2 - '0') :
((digit2 & 0xdf) - 'A' + 10)); |
| 177 range.m_Upper[i] = byte; | 177 range.m_Upper[i] = byte; |
| 178 } | 178 } |
| 179 return TRUE; | 179 return true; |
| 180 } | 180 } |
| 181 static CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) | 181 static CFX_ByteString CMap_GetString(const CFX_ByteStringC& word) |
| 182 { | 182 { |
| 183 return word.Mid(1, word.GetLength() - 2); | 183 return word.Mid(1, word.GetLength() - 2); |
| 184 } | 184 } |
| 185 void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) | 185 void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) |
| 186 { | 186 { |
| 187 if (word.IsEmpty()) { | 187 if (word.IsEmpty()) { |
| 188 return; | 188 return; |
| 189 } | 189 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 m_LastWord = word; | 277 m_LastWord = word; |
| 278 } | 278 } |
| 279 CPDF_CMap::CPDF_CMap() | 279 CPDF_CMap::CPDF_CMap() |
| 280 { | 280 { |
| 281 m_Charset = CIDSET_UNKNOWN; | 281 m_Charset = CIDSET_UNKNOWN; |
| 282 m_Coding = CIDCODING_UNKNOWN; | 282 m_Coding = CIDCODING_UNKNOWN; |
| 283 m_CodingScheme = TwoBytes; | 283 m_CodingScheme = TwoBytes; |
| 284 m_bVertical = 0; | 284 m_bVertical = 0; |
| 285 m_bLoaded = FALSE; | 285 m_bLoaded = false; |
| 286 m_pMapping = NULL; | 286 m_pMapping = NULL; |
| 287 m_pLeadingBytes = NULL; | 287 m_pLeadingBytes = NULL; |
| 288 m_pAddMapping = NULL; | 288 m_pAddMapping = NULL; |
| 289 m_pEmbedMap = NULL; | 289 m_pEmbedMap = NULL; |
| 290 m_pUseMap = NULL; | 290 m_pUseMap = NULL; |
| 291 m_nCodeRanges = 0; | 291 m_nCodeRanges = 0; |
| 292 } | 292 } |
| 293 CPDF_CMap::~CPDF_CMap() | 293 CPDF_CMap::~CPDF_CMap() |
| 294 { | 294 { |
| 295 if (m_pMapping) { | 295 if (m_pMapping) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 { "KSC-EUC", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1, {0
xa1, 0xfe} }, | 339 { "KSC-EUC", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1, {0
xa1, 0xfe} }, |
| 340 { "KSCms-UHC", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1,
{0x81, 0xfe} }, | 340 { "KSCms-UHC", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1,
{0x81, 0xfe} }, |
| 341 { "KSCms-UHC-HW", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes,
1, {0x81, 0xfe} }, | 341 { "KSCms-UHC-HW", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes,
1, {0x81, 0xfe} }, |
| 342 { "KSCpc-EUC", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1,
{0xa1, 0xfd} }, | 342 { "KSCpc-EUC", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1,
{0xa1, 0xfd} }, |
| 343 { "UniKS-UCS2", CIDSET_KOREA1, CIDCODING_UCS2, CPDF_CMap::TwoBytes }, | 343 { "UniKS-UCS2", CIDSET_KOREA1, CIDCODING_UCS2, CPDF_CMap::TwoBytes }, |
| 344 { "UniKS-UTF16", CIDSET_KOREA1, CIDCODING_UTF16, CPDF_CMap::TwoBytes }, | 344 { "UniKS-UTF16", CIDSET_KOREA1, CIDCODING_UTF16, CPDF_CMap::TwoBytes }, |
| 345 { NULL, 0, 0 } | 345 { NULL, 0, 0 } |
| 346 }; | 346 }; |
| 347 extern void FPDFAPI_FindEmbeddedCMap(const char* name, int charset, int coding,
const FXCMAP_CMap*& pMap); | 347 extern void FPDFAPI_FindEmbeddedCMap(const char* name, int charset, int coding,
const FXCMAP_CMap*& pMap); |
| 348 extern FX_WORD FPDFAPI_CIDFromCharCode(const FXCMAP_CMap* pMap, FX_DWORD charcod
e); | 348 extern FX_WORD FPDFAPI_CIDFromCharCode(const FXCMAP_CMap* pMap, FX_DWORD charcod
e); |
| 349 FX_BOOL CPDF_CMap::LoadPredefined(CPDF_CMapManager* pMgr, const FX_CHAR* pName,
FX_BOOL bPromptCJK) | 349 bool CPDF_CMap::LoadPredefined(CPDF_CMapManager* pMgr, const FX_CHAR* pName, boo
l bPromptCJK) |
| 350 { | 350 { |
| 351 m_PredefinedCMap = pName; | 351 m_PredefinedCMap = pName; |
| 352 if (m_PredefinedCMap == FX_BSTRC("Identity-H") || m_PredefinedCMap == FX_BST
RC("Identity-V")) { | 352 if (m_PredefinedCMap == FX_BSTRC("Identity-H") || m_PredefinedCMap == FX_BST
RC("Identity-V")) { |
| 353 m_Coding = CIDCODING_CID; | 353 m_Coding = CIDCODING_CID; |
| 354 m_bVertical = pName[9] == 'V'; | 354 m_bVertical = pName[9] == 'V'; |
| 355 m_bLoaded = TRUE; | 355 m_bLoaded = true; |
| 356 return TRUE; | 356 return true; |
| 357 } | 357 } |
| 358 CFX_ByteString cmapid = m_PredefinedCMap; | 358 CFX_ByteString cmapid = m_PredefinedCMap; |
| 359 m_bVertical = cmapid.Right(1) == FX_BSTRC("V"); | 359 m_bVertical = cmapid.Right(1) == FX_BSTRC("V"); |
| 360 if (cmapid.GetLength() > 2) { | 360 if (cmapid.GetLength() > 2) { |
| 361 cmapid = cmapid.Left(cmapid.GetLength() - 2); | 361 cmapid = cmapid.Left(cmapid.GetLength() - 2); |
| 362 } | 362 } |
| 363 int index = 0; | 363 int index = 0; |
| 364 while (1) { | 364 while (1) { |
| 365 if (g_PredefinedCMaps[index].m_pName == NULL) { | 365 if (g_PredefinedCMaps[index].m_pName == NULL) { |
| 366 return FALSE; | 366 return false; |
| 367 } | 367 } |
| 368 if (cmapid == CFX_ByteStringC(g_PredefinedCMaps[index].m_pName)) { | 368 if (cmapid == CFX_ByteStringC(g_PredefinedCMaps[index].m_pName)) { |
| 369 break; | 369 break; |
| 370 } | 370 } |
| 371 index ++; | 371 index ++; |
| 372 } | 372 } |
| 373 const CPDF_PredefinedCMap& map = g_PredefinedCMaps[index]; | 373 const CPDF_PredefinedCMap& map = g_PredefinedCMaps[index]; |
| 374 m_Charset = map.m_Charset; | 374 m_Charset = map.m_Charset; |
| 375 m_Coding = map.m_Coding; | 375 m_Coding = map.m_Coding; |
| 376 m_CodingScheme = map.m_CodingScheme; | 376 m_CodingScheme = map.m_CodingScheme; |
| 377 if (m_CodingScheme == MixedTwoBytes) { | 377 if (m_CodingScheme == MixedTwoBytes) { |
| 378 m_pLeadingBytes = FX_Alloc(uint8_t, 256); | 378 m_pLeadingBytes = FX_Alloc(uint8_t, 256); |
| 379 for (FX_DWORD i = 0; i < map.m_LeadingSegCount; i ++) { | 379 for (FX_DWORD i = 0; i < map.m_LeadingSegCount; i ++) { |
| 380 for (int b = map.m_LeadingSegs[i * 2]; b <= map.m_LeadingSegs[i * 2
+ 1]; b ++) { | 380 for (int b = map.m_LeadingSegs[i * 2]; b <= map.m_LeadingSegs[i * 2
+ 1]; b ++) { |
| 381 m_pLeadingBytes[b] = 1; | 381 m_pLeadingBytes[b] = 1; |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 FPDFAPI_FindEmbeddedCMap(pName, m_Charset, m_Coding, m_pEmbedMap); | 385 FPDFAPI_FindEmbeddedCMap(pName, m_Charset, m_Coding, m_pEmbedMap); |
| 386 if (m_pEmbedMap) { | 386 if (m_pEmbedMap) { |
| 387 m_bLoaded = TRUE; | 387 m_bLoaded = true; |
| 388 return TRUE; | 388 return true; |
| 389 } | 389 } |
| 390 return FALSE; | 390 return false; |
| 391 } | 391 } |
| 392 extern "C" { | 392 extern "C" { |
| 393 static int compare_dword(const void* data1, const void* data2) | 393 static int compare_dword(const void* data1, const void* data2) |
| 394 { | 394 { |
| 395 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2); | 395 return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2); |
| 396 } | 396 } |
| 397 }; | 397 }; |
| 398 FX_BOOL CPDF_CMap::LoadEmbedded(const uint8_t* pData, FX_DWORD size) | 398 bool CPDF_CMap::LoadEmbedded(const uint8_t* pData, FX_DWORD size) |
| 399 { | 399 { |
| 400 m_pMapping = FX_Alloc(FX_WORD, 65536); | 400 m_pMapping = FX_Alloc(FX_WORD, 65536); |
| 401 CPDF_CMapParser parser; | 401 CPDF_CMapParser parser; |
| 402 parser.Initialize(this); | 402 parser.Initialize(this); |
| 403 CPDF_SimpleParser syntax(pData, size); | 403 CPDF_SimpleParser syntax(pData, size); |
| 404 while (1) { | 404 while (1) { |
| 405 CFX_ByteStringC word = syntax.GetWord(); | 405 CFX_ByteStringC word = syntax.GetWord(); |
| 406 if (word.IsEmpty()) { | 406 if (word.IsEmpty()) { |
| 407 break; | 407 break; |
| 408 } | 408 } |
| 409 parser.ParseWord(word); | 409 parser.ParseWord(word); |
| 410 } | 410 } |
| 411 if (m_CodingScheme == MixedFourBytes && parser.m_AddMaps.GetSize()) { | 411 if (m_CodingScheme == MixedFourBytes && parser.m_AddMaps.GetSize()) { |
| 412 m_pAddMapping = FX_Alloc(uint8_t, parser.m_AddMaps.GetSize() + 4); | 412 m_pAddMapping = FX_Alloc(uint8_t, parser.m_AddMaps.GetSize() + 4); |
| 413 *(FX_DWORD*)m_pAddMapping = parser.m_AddMaps.GetSize() / 8; | 413 *(FX_DWORD*)m_pAddMapping = parser.m_AddMaps.GetSize() / 8; |
| 414 FXSYS_memcpy(m_pAddMapping + 4, parser.m_AddMaps.GetBuffer(), parser.m_A
ddMaps.GetSize()); | 414 FXSYS_memcpy(m_pAddMapping + 4, parser.m_AddMaps.GetBuffer(), parser.m_A
ddMaps.GetSize()); |
| 415 FXSYS_qsort(m_pAddMapping + 4, parser.m_AddMaps.GetSize() / 8, 8, compar
e_dword); | 415 FXSYS_qsort(m_pAddMapping + 4, parser.m_AddMaps.GetSize() / 8, 8, compar
e_dword); |
| 416 } | 416 } |
| 417 return TRUE; | 417 return true; |
| 418 } | 418 } |
| 419 extern "C" { | 419 extern "C" { |
| 420 static int compareCID(const void* key, const void* element) | 420 static int compareCID(const void* key, const void* element) |
| 421 { | 421 { |
| 422 if ((*(FX_DWORD*)key) < (*(FX_DWORD*)element)) { | 422 if ((*(FX_DWORD*)key) < (*(FX_DWORD*)element)) { |
| 423 return -1; | 423 return -1; |
| 424 } | 424 } |
| 425 if ((*(FX_DWORD*)key) > (*(FX_DWORD*)element) + ((FX_DWORD*)element)[1]
/ 65536) { | 425 if ((*(FX_DWORD*)key) > (*(FX_DWORD*)element) + ((FX_DWORD*)element)[1]
/ 65536) { |
| 426 return 1; | 426 return 1; |
| 427 } | 427 } |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 } | 661 } |
| 662 return 0; | 662 return 0; |
| 663 } | 663 } |
| 664 CPDF_CID2UnicodeMap::CPDF_CID2UnicodeMap() | 664 CPDF_CID2UnicodeMap::CPDF_CID2UnicodeMap() |
| 665 { | 665 { |
| 666 m_EmbeddedCount = 0; | 666 m_EmbeddedCount = 0; |
| 667 } | 667 } |
| 668 CPDF_CID2UnicodeMap::~CPDF_CID2UnicodeMap() | 668 CPDF_CID2UnicodeMap::~CPDF_CID2UnicodeMap() |
| 669 { | 669 { |
| 670 } | 670 } |
| 671 FX_BOOL CPDF_CID2UnicodeMap::Initialize() | 671 bool CPDF_CID2UnicodeMap::Initialize() |
| 672 { | 672 { |
| 673 return TRUE; | 673 return true; |
| 674 } | 674 } |
| 675 FX_BOOL CPDF_CID2UnicodeMap::IsLoaded() | 675 bool CPDF_CID2UnicodeMap::IsLoaded() |
| 676 { | 676 { |
| 677 return m_EmbeddedCount != 0; | 677 return m_EmbeddedCount != 0; |
| 678 } | 678 } |
| 679 FX_WCHAR CPDF_CID2UnicodeMap::UnicodeFromCID(FX_WORD CID) | 679 FX_WCHAR CPDF_CID2UnicodeMap::UnicodeFromCID(FX_WORD CID) |
| 680 { | 680 { |
| 681 if (m_Charset == CIDSET_UNICODE) { | 681 if (m_Charset == CIDSET_UNICODE) { |
| 682 return CID; | 682 return CID; |
| 683 } | 683 } |
| 684 if (CID < m_EmbeddedCount) { | 684 if (CID < m_EmbeddedCount) { |
| 685 return m_pEmbeddedMap[CID]; | 685 return m_pEmbeddedMap[CID]; |
| 686 } | 686 } |
| 687 return 0; | 687 return 0; |
| 688 } | 688 } |
| 689 void FPDFAPI_LoadCID2UnicodeMap(int charset, const FX_WORD*& pMap, FX_DWORD& cou
nt); | 689 void FPDFAPI_LoadCID2UnicodeMap(int charset, const FX_WORD*& pMap, FX_DWORD& cou
nt); |
| 690 void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, int charset, FX_BOOL bPro
mptCJK) | 690 void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, int charset, bool bPrompt
CJK) |
| 691 { | 691 { |
| 692 m_Charset = charset; | 692 m_Charset = charset; |
| 693 FPDFAPI_LoadCID2UnicodeMap(charset, m_pEmbeddedMap, m_EmbeddedCount); | 693 FPDFAPI_LoadCID2UnicodeMap(charset, m_pEmbeddedMap, m_EmbeddedCount); |
| 694 } | 694 } |
| 695 #include "ttgsubtable.h" | 695 #include "ttgsubtable.h" |
| 696 CPDF_CIDFont::CPDF_CIDFont() : CPDF_Font(PDFFONT_CIDFONT) | 696 CPDF_CIDFont::CPDF_CIDFont() : CPDF_Font(PDFFONT_CIDFONT) |
| 697 { | 697 { |
| 698 m_pCMap = NULL; | 698 m_pCMap = NULL; |
| 699 m_pAllocatedCMap = NULL; | 699 m_pAllocatedCMap = NULL; |
| 700 m_pCID2UnicodeMap = NULL; | 700 m_pCID2UnicodeMap = NULL; |
| 701 m_pAnsiWidths = NULL; | 701 m_pAnsiWidths = NULL; |
| 702 m_pCIDToGIDMap = NULL; | 702 m_pCIDToGIDMap = NULL; |
| 703 m_bCIDIsGID = FALSE; | 703 m_bCIDIsGID = false; |
| 704 m_bAdobeCourierStd = FALSE; | 704 m_bAdobeCourierStd = false; |
| 705 m_pTTGSUBTable = NULL; | 705 m_pTTGSUBTable = NULL; |
| 706 FXSYS_memset(m_CharBBox, 0xff, 256 * sizeof(FX_SMALL_RECT)); | 706 FXSYS_memset(m_CharBBox, 0xff, 256 * sizeof(FX_SMALL_RECT)); |
| 707 } | 707 } |
| 708 CPDF_CIDFont::~CPDF_CIDFont() | 708 CPDF_CIDFont::~CPDF_CIDFont() |
| 709 { | 709 { |
| 710 if (m_pAnsiWidths) { | 710 if (m_pAnsiWidths) { |
| 711 FX_Free(m_pAnsiWidths); | 711 FX_Free(m_pAnsiWidths); |
| 712 } | 712 } |
| 713 delete m_pAllocatedCMap; | 713 delete m_pAllocatedCMap; |
| 714 delete m_pCIDToGIDMap; | 714 delete m_pCIDToGIDMap; |
| 715 delete m_pTTGSUBTable; | 715 delete m_pTTGSUBTable; |
| 716 } | 716 } |
| 717 FX_WORD CPDF_CIDFont::CIDFromCharCode(FX_DWORD charcode) const | 717 FX_WORD CPDF_CIDFont::CIDFromCharCode(FX_DWORD charcode) const |
| 718 { | 718 { |
| 719 if (m_pCMap == NULL) { | 719 if (m_pCMap == NULL) { |
| 720 return (FX_WORD)charcode; | 720 return (FX_WORD)charcode; |
| 721 } | 721 } |
| 722 return m_pCMap->CIDFromCharCode(charcode); | 722 return m_pCMap->CIDFromCharCode(charcode); |
| 723 } | 723 } |
| 724 FX_BOOL CPDF_CIDFont::IsVertWriting() const | 724 bool CPDF_CIDFont::IsVertWriting() const |
| 725 { | 725 { |
| 726 return m_pCMap ? m_pCMap->IsVertWriting() : FALSE; | 726 return m_pCMap ? m_pCMap->IsVertWriting() : false; |
| 727 } | 727 } |
| 728 extern FX_DWORD FPDFAPI_CharCodeFromCID(const FXCMAP_CMap* pMap, FX_WORD cid); | 728 extern FX_DWORD FPDFAPI_CharCodeFromCID(const FXCMAP_CMap* pMap, FX_WORD cid); |
| 729 static FX_DWORD _EmbeddedCharcodeFromUnicode(const FXCMAP_CMap* pEmbedMap, int c
harset, FX_WCHAR unicode) | 729 static FX_DWORD _EmbeddedCharcodeFromUnicode(const FXCMAP_CMap* pEmbedMap, int c
harset, FX_WCHAR unicode) |
| 730 { | 730 { |
| 731 if (charset <= 0 || charset > 4) { | 731 if (charset <= 0 || charset > 4) { |
| 732 return 0; | 732 return 0; |
| 733 } | 733 } |
| 734 CPDF_FontGlobals* pFontGlobals = CPDF_ModuleMgr::Get()->GetPageModule()->Get
FontGlobals(); | 734 CPDF_FontGlobals* pFontGlobals = CPDF_ModuleMgr::Get()->GetPageModule()->Get
FontGlobals(); |
| 735 const FX_WORD* pCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap; | 735 const FX_WORD* pCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap; |
| 736 if (pCodes == NULL) { | 736 if (pCodes == NULL) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 encoding = FXFT_ENCODING_UNICODE; | 866 encoding = FXFT_ENCODING_UNICODE; |
| 867 } | 867 } |
| 868 int err = FXFT_Select_Charmap(face, encoding); | 868 int err = FXFT_Select_Charmap(face, encoding); |
| 869 if (err) { | 869 if (err) { |
| 870 err = FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE); | 870 err = FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE); |
| 871 } | 871 } |
| 872 if (err && FXFT_Get_Face_Charmaps(face)) { | 872 if (err && FXFT_Get_Face_Charmaps(face)) { |
| 873 FXFT_Set_Charmap(face, *FXFT_Get_Face_Charmaps(face)); | 873 FXFT_Set_Charmap(face, *FXFT_Get_Face_Charmaps(face)); |
| 874 } | 874 } |
| 875 } | 875 } |
| 876 FX_BOOL CPDF_CIDFont::_Load() | 876 bool CPDF_CIDFont::_Load() |
| 877 { | 877 { |
| 878 if (m_pFontDict->GetString(FX_BSTRC("Subtype")) == FX_BSTRC("TrueType")) { | 878 if (m_pFontDict->GetString(FX_BSTRC("Subtype")) == FX_BSTRC("TrueType")) { |
| 879 return LoadGB2312(); | 879 return LoadGB2312(); |
| 880 } | 880 } |
| 881 CPDF_Array* pFonts = m_pFontDict->GetArray(FX_BSTRC("DescendantFonts")); | 881 CPDF_Array* pFonts = m_pFontDict->GetArray(FX_BSTRC("DescendantFonts")); |
| 882 if (pFonts == NULL) { | 882 if (pFonts == NULL) { |
| 883 return FALSE; | 883 return false; |
| 884 } | 884 } |
| 885 if (pFonts->GetCount() != 1) { | 885 if (pFonts->GetCount() != 1) { |
| 886 return FALSE; | 886 return false; |
| 887 } | 887 } |
| 888 CPDF_Dictionary* pCIDFontDict = pFonts->GetDict(0); | 888 CPDF_Dictionary* pCIDFontDict = pFonts->GetDict(0); |
| 889 if (pCIDFontDict == NULL) { | 889 if (pCIDFontDict == NULL) { |
| 890 return FALSE; | 890 return false; |
| 891 } | 891 } |
| 892 m_BaseFont = pCIDFontDict->GetString(FX_BSTRC("BaseFont")); | 892 m_BaseFont = pCIDFontDict->GetString(FX_BSTRC("BaseFont")); |
| 893 if ((m_BaseFont.Compare("CourierStd") == 0 || m_BaseFont.Compare("CourierStd
-Bold") == 0 | 893 if ((m_BaseFont.Compare("CourierStd") == 0 || m_BaseFont.Compare("CourierStd
-Bold") == 0 |
| 894 || m_BaseFont.Compare("CourierStd-BoldOblique") == 0 || m_BaseFont.C
ompare("CourierStd-Oblique") == 0) | 894 || m_BaseFont.Compare("CourierStd-BoldOblique") == 0 || m_BaseFont.C
ompare("CourierStd-Oblique") == 0) |
| 895 && !IsEmbedded()) { | 895 && !IsEmbedded()) { |
| 896 m_bAdobeCourierStd = TRUE; | 896 m_bAdobeCourierStd = true; |
| 897 } | 897 } |
| 898 CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDict(FX_BSTRC("FontDescriptor"
)); | 898 CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDict(FX_BSTRC("FontDescriptor"
)); |
| 899 if (pFontDesc) { | 899 if (pFontDesc) { |
| 900 LoadFontDescriptor(pFontDesc); | 900 LoadFontDescriptor(pFontDesc); |
| 901 } | 901 } |
| 902 CPDF_Object* pEncoding = m_pFontDict->GetElementValue(FX_BSTRC("Encoding")); | 902 CPDF_Object* pEncoding = m_pFontDict->GetElementValue(FX_BSTRC("Encoding")); |
| 903 if (pEncoding == NULL) { | 903 if (pEncoding == NULL) { |
| 904 return FALSE; | 904 return false; |
| 905 } | 905 } |
| 906 CFX_ByteString subtype = pCIDFontDict->GetString(FX_BSTRC("Subtype")); | 906 CFX_ByteString subtype = pCIDFontDict->GetString(FX_BSTRC("Subtype")); |
| 907 m_bType1 = FALSE; | 907 m_bType1 = false; |
| 908 if (subtype == FX_BSTRC("CIDFontType0")) { | 908 if (subtype == FX_BSTRC("CIDFontType0")) { |
| 909 m_bType1 = TRUE; | 909 m_bType1 = true; |
| 910 } | 910 } |
| 911 if (pEncoding->GetType() == PDFOBJ_NAME) { | 911 if (pEncoding->GetType() == PDFOBJ_NAME) { |
| 912 CFX_ByteString cmap = pEncoding->GetString(); | 912 CFX_ByteString cmap = pEncoding->GetString(); |
| 913 m_pCMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CM
apManager.GetPredefinedCMap(cmap, | 913 m_pCMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CM
apManager.GetPredefinedCMap(cmap, |
| 914 m_pFontFile && m_bType1); | 914 m_pFontFile && m_bType1); |
| 915 } else if (pEncoding->GetType() == PDFOBJ_STREAM) { | 915 } else if (pEncoding->GetType() == PDFOBJ_STREAM) { |
| 916 m_pAllocatedCMap = m_pCMap = new CPDF_CMap; | 916 m_pAllocatedCMap = m_pCMap = new CPDF_CMap; |
| 917 CPDF_Stream* pStream = (CPDF_Stream*)pEncoding; | 917 CPDF_Stream* pStream = (CPDF_Stream*)pEncoding; |
| 918 CPDF_StreamAcc acc; | 918 CPDF_StreamAcc acc; |
| 919 acc.LoadAllData(pStream, FALSE); | 919 acc.LoadAllData(pStream, false); |
| 920 m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize()); | 920 m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize()); |
| 921 } else { | 921 } else { |
| 922 return FALSE; | 922 return false; |
| 923 } | 923 } |
| 924 if (m_pCMap == NULL) { | 924 if (m_pCMap == NULL) { |
| 925 return FALSE; | 925 return false; |
| 926 } | 926 } |
| 927 m_Charset = m_pCMap->m_Charset; | 927 m_Charset = m_pCMap->m_Charset; |
| 928 if (m_Charset == CIDSET_UNKNOWN) { | 928 if (m_Charset == CIDSET_UNKNOWN) { |
| 929 CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDict(FX_BSTRC("CIDSystemInf
o")); | 929 CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDict(FX_BSTRC("CIDSystemInf
o")); |
| 930 if (pCIDInfo) { | 930 if (pCIDInfo) { |
| 931 m_Charset = _CharsetFromOrdering(pCIDInfo->GetString(FX_BSTRC("Order
ing"))); | 931 m_Charset = _CharsetFromOrdering(pCIDInfo->GetString(FX_BSTRC("Order
ing"))); |
| 932 } | 932 } |
| 933 } | 933 } |
| 934 if (m_Charset != CIDSET_UNKNOWN) | 934 if (m_Charset != CIDSET_UNKNOWN) |
| 935 m_pCID2UnicodeMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGloba
ls()->m_CMapManager.GetCID2UnicodeMap(m_Charset, | 935 m_pCID2UnicodeMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGloba
ls()->m_CMapManager.GetCID2UnicodeMap(m_Charset, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 948 } | 948 } |
| 949 if (!IsEmbedded()) { | 949 if (!IsEmbedded()) { |
| 950 LoadSubstFont(); | 950 LoadSubstFont(); |
| 951 } | 951 } |
| 952 if (1) { | 952 if (1) { |
| 953 if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT))
{ | 953 if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT))
{ |
| 954 CPDF_Object* pmap = pCIDFontDict->GetElementValue(FX_BSTRC("CIDToGID
Map")); | 954 CPDF_Object* pmap = pCIDFontDict->GetElementValue(FX_BSTRC("CIDToGID
Map")); |
| 955 if (pmap) { | 955 if (pmap) { |
| 956 if (pmap->GetType() == PDFOBJ_STREAM) { | 956 if (pmap->GetType() == PDFOBJ_STREAM) { |
| 957 m_pCIDToGIDMap = new CPDF_StreamAcc; | 957 m_pCIDToGIDMap = new CPDF_StreamAcc; |
| 958 m_pCIDToGIDMap->LoadAllData((CPDF_Stream*)pmap, FALSE); | 958 m_pCIDToGIDMap->LoadAllData((CPDF_Stream*)pmap, false); |
| 959 } else if (pmap->GetString() == FX_BSTRC("Identity")) { | 959 } else if (pmap->GetString() == FX_BSTRC("Identity")) { |
| 960 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 960 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 961 if (m_pFontFile) { | 961 if (m_pFontFile) { |
| 962 m_bCIDIsGID = TRUE; | 962 m_bCIDIsGID = true; |
| 963 } | 963 } |
| 964 #else | 964 #else |
| 965 m_bCIDIsGID = TRUE; | 965 m_bCIDIsGID = true; |
| 966 #endif | 966 #endif |
| 967 } | 967 } |
| 968 } | 968 } |
| 969 } | 969 } |
| 970 } | 970 } |
| 971 CheckFontMetrics(); | 971 CheckFontMetrics(); |
| 972 if (IsVertWriting()) { | 972 if (IsVertWriting()) { |
| 973 pWidthArray = pCIDFontDict->GetArray(FX_BSTRC("W2")); | 973 pWidthArray = pCIDFontDict->GetArray(FX_BSTRC("W2")); |
| 974 if (pWidthArray) { | 974 if (pWidthArray) { |
| 975 LoadMetricsArray(pWidthArray, m_VertMetrics, 3); | 975 LoadMetricsArray(pWidthArray, m_VertMetrics, 3); |
| 976 } | 976 } |
| 977 CPDF_Array* pDefaultArray = pCIDFontDict->GetArray(FX_BSTRC("DW2")); | 977 CPDF_Array* pDefaultArray = pCIDFontDict->GetArray(FX_BSTRC("DW2")); |
| 978 if (pDefaultArray) { | 978 if (pDefaultArray) { |
| 979 m_DefaultVY = pDefaultArray->GetInteger(0); | 979 m_DefaultVY = pDefaultArray->GetInteger(0); |
| 980 m_DefaultW1 = pDefaultArray->GetInteger(1); | 980 m_DefaultW1 = pDefaultArray->GetInteger(1); |
| 981 } else { | 981 } else { |
| 982 m_DefaultVY = 880; | 982 m_DefaultVY = 880; |
| 983 m_DefaultW1 = -1000; | 983 m_DefaultW1 = -1000; |
| 984 } | 984 } |
| 985 } | 985 } |
| 986 return TRUE; | 986 return true; |
| 987 } | 987 } |
| 988 FX_FLOAT _CIDTransformToFloat(uint8_t ch) | 988 FX_FLOAT _CIDTransformToFloat(uint8_t ch) |
| 989 { | 989 { |
| 990 if (ch < 128) { | 990 if (ch < 128) { |
| 991 return ch * 1.0f / 127; | 991 return ch * 1.0f / 127; |
| 992 } | 992 } |
| 993 return (-255 + ch) * 1.0f / 127; | 993 return (-255 + ch) * 1.0f / 127; |
| 994 } | 994 } |
| 995 void CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) | 995 void CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) |
| 996 { | 996 { |
| 997 if (charcode < 256 && m_CharBBox[charcode].Right != -1) { | 997 if (charcode < 256 && m_CharBBox[charcode].Right != -1) { |
| 998 rect.bottom = m_CharBBox[charcode].Bottom; | 998 rect.bottom = m_CharBBox[charcode].Bottom; |
| 999 rect.left = m_CharBBox[charcode].Left; | 999 rect.left = m_CharBBox[charcode].Left; |
| 1000 rect.right = m_CharBBox[charcode].Right; | 1000 rect.right = m_CharBBox[charcode].Right; |
| 1001 rect.top = m_CharBBox[charcode].Top; | 1001 rect.top = m_CharBBox[charcode].Top; |
| 1002 return; | 1002 return; |
| 1003 } | 1003 } |
| 1004 FX_BOOL bVert = FALSE; | 1004 bool bVert = false; |
| 1005 int glyph_index = GlyphFromCharCode(charcode, &bVert); | 1005 int glyph_index = GlyphFromCharCode(charcode, &bVert); |
| 1006 if (m_Font.m_Face == NULL) { | 1006 if (m_Font.m_Face == NULL) { |
| 1007 rect = FX_RECT(0, 0, 0, 0); | 1007 rect = FX_RECT(0, 0, 0, 0); |
| 1008 } else { | 1008 } else { |
| 1009 rect.left = rect.bottom = rect.right = rect.top = 0; | 1009 rect.left = rect.bottom = rect.right = rect.top = 0; |
| 1010 FXFT_Face face = m_Font.m_Face; | 1010 FXFT_Face face = m_Font.m_Face; |
| 1011 if (FXFT_Is_Face_Tricky(face)) { | 1011 if (FXFT_Is_Face_Tricky(face)) { |
| 1012 int err = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_IGNORE_GLOBAL
_ADVANCE_WIDTH); | 1012 int err = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_IGNORE_GLOBAL
_ADVANCE_WIDTH); |
| 1013 if (!err) { | 1013 if (!err) { |
| 1014 FXFT_BBox cbox; | 1014 FXFT_BBox cbox; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 const FX_DWORD* list = m_WidthList.GetData(); | 1113 const FX_DWORD* list = m_WidthList.GetData(); |
| 1114 for (int i = 0; i < size; i += 3) { | 1114 for (int i = 0; i < size; i += 3) { |
| 1115 if (CID >= list[i] && CID <= list[i + 1]) { | 1115 if (CID >= list[i] && CID <= list[i + 1]) { |
| 1116 dwWidth = (FX_WORD)list[i + 2]; | 1116 dwWidth = (FX_WORD)list[i + 2]; |
| 1117 break; | 1117 break; |
| 1118 } | 1118 } |
| 1119 } | 1119 } |
| 1120 vx = (short)dwWidth / 2; | 1120 vx = (short)dwWidth / 2; |
| 1121 vy = (short)m_DefaultVY; | 1121 vy = (short)m_DefaultVY; |
| 1122 } | 1122 } |
| 1123 int» CPDF_CIDFont::GetGlyphIndex(FX_DWORD unicode, FX_BOOL *pVertGlyph) | 1123 int» CPDF_CIDFont::GetGlyphIndex(FX_DWORD unicode, bool *pVertGlyph) |
| 1124 { | 1124 { |
| 1125 if (pVertGlyph) { | 1125 if (pVertGlyph) { |
| 1126 *pVertGlyph = FALSE; | 1126 *pVertGlyph = false; |
| 1127 } | 1127 } |
| 1128 int index = FXFT_Get_Char_Index(m_Font.m_Face, unicode ); | 1128 int index = FXFT_Get_Char_Index(m_Font.m_Face, unicode ); |
| 1129 if (unicode == 0x2502) { | 1129 if (unicode == 0x2502) { |
| 1130 return index; | 1130 return index; |
| 1131 } | 1131 } |
| 1132 if (index && IsVertWriting()) { | 1132 if (index && IsVertWriting()) { |
| 1133 if (m_pTTGSUBTable) { | 1133 if (m_pTTGSUBTable) { |
| 1134 TT_uint32_t vindex = 0; | 1134 TT_uint32_t vindex = 0; |
| 1135 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex); | 1135 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex); |
| 1136 if (vindex) { | 1136 if (vindex) { |
| 1137 index = vindex; | 1137 index = vindex; |
| 1138 if (pVertGlyph) { | 1138 if (pVertGlyph) { |
| 1139 *pVertGlyph = TRUE; | 1139 *pVertGlyph = true; |
| 1140 } | 1140 } |
| 1141 } | 1141 } |
| 1142 return index; | 1142 return index; |
| 1143 } | 1143 } |
| 1144 if (NULL == m_Font.m_pGsubData) { | 1144 if (NULL == m_Font.m_pGsubData) { |
| 1145 unsigned long length = 0; | 1145 unsigned long length = 0; |
| 1146 int error = FXFT_Load_Sfnt_Table( m_Font.m_Face, FT_MAKE_TAG('G', 'S
', 'U', 'B'), 0, NULL, &length); | 1146 int error = FXFT_Load_Sfnt_Table( m_Font.m_Face, FT_MAKE_TAG('G', 'S
', 'U', 'B'), 0, NULL, &length); |
| 1147 if (!error) { | 1147 if (!error) { |
| 1148 m_Font.m_pGsubData = (unsigned char*)FX_Alloc(uint8_t, length); | 1148 m_Font.m_pGsubData = (unsigned char*)FX_Alloc(uint8_t, length); |
| 1149 } | 1149 } |
| 1150 } | 1150 } |
| 1151 int error = FXFT_Load_Sfnt_Table( m_Font.m_Face, FT_MAKE_TAG('G', 'S', '
U', 'B'), 0, m_Font.m_pGsubData, NULL); | 1151 int error = FXFT_Load_Sfnt_Table( m_Font.m_Face, FT_MAKE_TAG('G', 'S', '
U', 'B'), 0, m_Font.m_pGsubData, NULL); |
| 1152 if (!error && m_Font.m_pGsubData) { | 1152 if (!error && m_Font.m_pGsubData) { |
| 1153 m_pTTGSUBTable = new CFX_CTTGSUBTable; | 1153 m_pTTGSUBTable = new CFX_CTTGSUBTable; |
| 1154 m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.m_pGsubData); | 1154 m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.m_pGsubData); |
| 1155 TT_uint32_t vindex = 0; | 1155 TT_uint32_t vindex = 0; |
| 1156 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex); | 1156 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex); |
| 1157 if (vindex) { | 1157 if (vindex) { |
| 1158 index = vindex; | 1158 index = vindex; |
| 1159 if (pVertGlyph) { | 1159 if (pVertGlyph) { |
| 1160 *pVertGlyph = TRUE; | 1160 *pVertGlyph = true; |
| 1161 } | 1161 } |
| 1162 } | 1162 } |
| 1163 } | 1163 } |
| 1164 return index; | 1164 return index; |
| 1165 } | 1165 } |
| 1166 if (pVertGlyph) { | 1166 if (pVertGlyph) { |
| 1167 *pVertGlyph = FALSE; | 1167 *pVertGlyph = false; |
| 1168 } | 1168 } |
| 1169 return index; | 1169 return index; |
| 1170 } | 1170 } |
| 1171 int CPDF_CIDFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph) | 1171 int CPDF_CIDFont::GlyphFromCharCode(FX_DWORD charcode, bool *pVertGlyph) |
| 1172 { | 1172 { |
| 1173 if (pVertGlyph) { | 1173 if (pVertGlyph) { |
| 1174 *pVertGlyph = FALSE; | 1174 *pVertGlyph = false; |
| 1175 } | 1175 } |
| 1176 if (m_pFontFile == NULL && m_pCIDToGIDMap == NULL) { | 1176 if (m_pFontFile == NULL && m_pCIDToGIDMap == NULL) { |
| 1177 FX_WORD cid = CIDFromCharCode(charcode); | 1177 FX_WORD cid = CIDFromCharCode(charcode); |
| 1178 FX_WCHAR unicode = 0; | 1178 FX_WCHAR unicode = 0; |
| 1179 if (m_bCIDIsGID) { | 1179 if (m_bCIDIsGID) { |
| 1180 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ | 1180 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ |
| 1181 return cid; | 1181 return cid; |
| 1182 #else | 1182 #else |
| 1183 if (m_Flags & PDFFONT_SYMBOLIC) { | 1183 if (m_Flags & PDFFONT_SYMBOLIC) { |
| 1184 return cid; | 1184 return cid; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1199 if (unicode == 0 && !(m_Flags & PDFFONT_SYMBOLIC)) { | 1199 if (unicode == 0 && !(m_Flags & PDFFONT_SYMBOLIC)) { |
| 1200 unicode = UnicodeFromCharCode(charcode).GetAt(0); | 1200 unicode = UnicodeFromCharCode(charcode).GetAt(0); |
| 1201 } | 1201 } |
| 1202 } | 1202 } |
| 1203 if (unicode == 0) { | 1203 if (unicode == 0) { |
| 1204 if (!m_bAdobeCourierStd) { | 1204 if (!m_bAdobeCourierStd) { |
| 1205 return charcode == 0 ? -1 : (int)charcode; | 1205 return charcode == 0 ? -1 : (int)charcode; |
| 1206 } | 1206 } |
| 1207 charcode += 31; | 1207 charcode += 31; |
| 1208 int index = 0, iBaseEncoding; | 1208 int index = 0, iBaseEncoding; |
| 1209 FX_BOOL bMSUnicode = FT_UseTTCharmap(m_Font.m_Face, 3, 1); | 1209 bool bMSUnicode = FT_UseTTCharmap(m_Font.m_Face, 3, 1); |
| 1210 FX_BOOL bMacRoman = FALSE; | 1210 bool bMacRoman = false; |
| 1211 if (!bMSUnicode) { | 1211 if (!bMSUnicode) { |
| 1212 bMacRoman = FT_UseTTCharmap(m_Font.m_Face, 1, 0); | 1212 bMacRoman = FT_UseTTCharmap(m_Font.m_Face, 1, 0); |
| 1213 } | 1213 } |
| 1214 iBaseEncoding = PDFFONT_ENCODING_STANDARD; | 1214 iBaseEncoding = PDFFONT_ENCODING_STANDARD; |
| 1215 if (bMSUnicode) { | 1215 if (bMSUnicode) { |
| 1216 iBaseEncoding = PDFFONT_ENCODING_WINANSI; | 1216 iBaseEncoding = PDFFONT_ENCODING_WINANSI; |
| 1217 } else if (bMacRoman) { | 1217 } else if (bMacRoman) { |
| 1218 iBaseEncoding = PDFFONT_ENCODING_MACROMAN; | 1218 iBaseEncoding = PDFFONT_ENCODING_MACROMAN; |
| 1219 } | 1219 } |
| 1220 const FX_CHAR* name = GetAdobeCharName(iBaseEncoding, NULL, charcode
); | 1220 const FX_CHAR* name = GetAdobeCharName(iBaseEncoding, NULL, charcode
); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 return m_pCMap->GetCharSize(charcode); | 1320 return m_pCMap->GetCharSize(charcode); |
| 1321 } | 1321 } |
| 1322 int CPDF_CIDFont::CountChar(const FX_CHAR* pString, int size) const | 1322 int CPDF_CIDFont::CountChar(const FX_CHAR* pString, int size) const |
| 1323 { | 1323 { |
| 1324 return m_pCMap->CountChar(pString, size); | 1324 return m_pCMap->CountChar(pString, size); |
| 1325 } | 1325 } |
| 1326 int CPDF_CIDFont::AppendChar(FX_CHAR* str, FX_DWORD charcode) const | 1326 int CPDF_CIDFont::AppendChar(FX_CHAR* str, FX_DWORD charcode) const |
| 1327 { | 1327 { |
| 1328 return m_pCMap->AppendChar(str, charcode); | 1328 return m_pCMap->AppendChar(str, charcode); |
| 1329 } | 1329 } |
| 1330 FX_BOOL CPDF_CIDFont::IsUnicodeCompatible() const | 1330 bool CPDF_CIDFont::IsUnicodeCompatible() const |
| 1331 { | 1331 { |
| 1332 if (!m_pCMap->IsLoaded() || m_pCID2UnicodeMap == NULL || !m_pCID2UnicodeMap-
>IsLoaded()) { | 1332 if (!m_pCMap->IsLoaded() || m_pCID2UnicodeMap == NULL || !m_pCID2UnicodeMap-
>IsLoaded()) { |
| 1333 return m_pCMap->m_Coding != CIDCODING_UNKNOWN; | 1333 return m_pCMap->m_Coding != CIDCODING_UNKNOWN; |
| 1334 } | 1334 } |
| 1335 return TRUE; | 1335 return true; |
| 1336 } | 1336 } |
| 1337 FX_BOOL CPDF_CIDFont::IsFontStyleFromCharCode(FX_DWORD charcode) const | 1337 bool CPDF_CIDFont::IsFontStyleFromCharCode(FX_DWORD charcode) const |
| 1338 { | 1338 { |
| 1339 return TRUE; | 1339 return true; |
| 1340 } | 1340 } |
| 1341 void CPDF_CIDFont::LoadSubstFont() | 1341 void CPDF_CIDFont::LoadSubstFont() |
| 1342 { | 1342 { |
| 1343 m_Font.LoadSubst(m_BaseFont, !m_bType1, m_Flags, m_StemV * 5, m_ItalicAngle,
g_CharsetCPs[m_Charset], IsVertWriting()); | 1343 m_Font.LoadSubst(m_BaseFont, !m_bType1, m_Flags, m_StemV * 5, m_ItalicAngle,
g_CharsetCPs[m_Charset], IsVertWriting()); |
| 1344 } | 1344 } |
| 1345 void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, CFX_DWordArray& result,
int nElements) | 1345 void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, CFX_DWordArray& result,
int nElements) |
| 1346 { | 1346 { |
| 1347 int width_status = 0; | 1347 int width_status = 0; |
| 1348 int iCurElement = 0; | 1348 int iCurElement = 0; |
| 1349 int first_code = 0, last_code; | 1349 int first_code = 0, last_code; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1383 } | 1383 } |
| 1384 result.Add(pObj->GetInteger()); | 1384 result.Add(pObj->GetInteger()); |
| 1385 iCurElement ++; | 1385 iCurElement ++; |
| 1386 if (iCurElement == nElements) { | 1386 if (iCurElement == nElements) { |
| 1387 width_status = 0; | 1387 width_status = 0; |
| 1388 } | 1388 } |
| 1389 } | 1389 } |
| 1390 } | 1390 } |
| 1391 } | 1391 } |
| 1392 } | 1392 } |
| 1393 FX_BOOL CPDF_CIDFont::LoadGB2312() | 1393 bool CPDF_CIDFont::LoadGB2312() |
| 1394 { | 1394 { |
| 1395 m_BaseFont = m_pFontDict->GetString(FX_BSTRC("BaseFont")); | 1395 m_BaseFont = m_pFontDict->GetString(FX_BSTRC("BaseFont")); |
| 1396 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDict(FX_BSTRC("FontDescriptor")
); | 1396 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDict(FX_BSTRC("FontDescriptor")
); |
| 1397 if (pFontDesc) { | 1397 if (pFontDesc) { |
| 1398 LoadFontDescriptor(pFontDesc); | 1398 LoadFontDescriptor(pFontDesc); |
| 1399 } | 1399 } |
| 1400 m_Charset = CIDSET_GB1; | 1400 m_Charset = CIDSET_GB1; |
| 1401 m_bType1 = FALSE; | 1401 m_bType1 = false; |
| 1402 m_pCMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CMapMa
nager.GetPredefinedCMap( | 1402 m_pCMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CMapMa
nager.GetPredefinedCMap( |
| 1403 FX_BSTRC("GBK-EUC-H"), FALSE); | 1403 FX_BSTRC("GBK-EUC-H"), false); |
| 1404 m_pCID2UnicodeMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()
->m_CMapManager.GetCID2UnicodeMap(m_Charset, FALSE); | 1404 m_pCID2UnicodeMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()
->m_CMapManager.GetCID2UnicodeMap(m_Charset, false); |
| 1405 if (!IsEmbedded()) { | 1405 if (!IsEmbedded()) { |
| 1406 LoadSubstFont(); | 1406 LoadSubstFont(); |
| 1407 } | 1407 } |
| 1408 CheckFontMetrics(); | 1408 CheckFontMetrics(); |
| 1409 m_DefaultWidth = 1000; | 1409 m_DefaultWidth = 1000; |
| 1410 m_pAnsiWidths = FX_Alloc(FX_WORD, 128); | 1410 m_pAnsiWidths = FX_Alloc(FX_WORD, 128); |
| 1411 for (int i = 32; i < 127; i ++) { | 1411 for (int i = 32; i < 127; i ++) { |
| 1412 m_pAnsiWidths[i] = 500; | 1412 m_pAnsiWidths[i] = 500; |
| 1413 } | 1413 } |
| 1414 return TRUE; | 1414 return true; |
| 1415 } | 1415 } |
| 1416 const struct _CIDTransform { | 1416 const struct _CIDTransform { |
| 1417 FX_WORD CID; | 1417 FX_WORD CID; |
| 1418 uint8_t a, b, c, d, e, f; | 1418 uint8_t a, b, c, d, e, f; |
| 1419 } | 1419 } |
| 1420 Japan1_VertCIDs[] = { | 1420 Japan1_VertCIDs[] = { |
| 1421 {97, 129, 0, 0, 127, 55, 0}, | 1421 {97, 129, 0, 0, 127, 55, 0}, |
| 1422 {7887, 127, 0, 0, 127, 76, 89}, | 1422 {7887, 127, 0, 0, 127, 76, 89}, |
| 1423 {7888, 127, 0, 0, 127, 79, 94}, | 1423 {7888, 127, 0, 0, 127, 79, 94}, |
| 1424 {7889, 0, 129, 127, 0, 17, 127}, | 1424 {7889, 0, 129, 127, 0, 17, 127}, |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1586 if (middlecode > CID) { | 1586 if (middlecode > CID) { |
| 1587 end = middle - 1; | 1587 end = middle - 1; |
| 1588 } else if (middlecode < CID) { | 1588 } else if (middlecode < CID) { |
| 1589 begin = middle + 1; | 1589 begin = middle + 1; |
| 1590 } else { | 1590 } else { |
| 1591 return &Japan1_VertCIDs[middle].a; | 1591 return &Japan1_VertCIDs[middle].a; |
| 1592 } | 1592 } |
| 1593 } | 1593 } |
| 1594 return NULL; | 1594 return NULL; |
| 1595 } | 1595 } |
| OLD | NEW |