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

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

Issue 1729823004: refactor CPDF_Font and subclasses (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Remove types and delete unused Created 4 years, 10 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/src/fpdfapi/fpdf_font/font_int.h" 7 #include "core/src/fpdfapi/fpdf_font/font_int.h"
8 8
9 #include "core/include/fpdfapi/fpdf_module.h" 9 #include "core/include/fpdfapi/fpdf_module.h"
10 #include "core/include/fpdfapi/fpdf_page.h" 10 #include "core/include/fpdfapi/fpdf_page.h"
11 #include "core/include/fpdfapi/fpdf_pageobj.h" 11 #include "core/include/fpdfapi/fpdf_pageobj.h"
12 #include "core/include/fpdfapi/fpdf_resource.h" 12 #include "core/include/fpdfapi/fpdf_resource.h"
13 #include "core/include/fxcrt/fx_ext.h" 13 #include "core/include/fxcrt/fx_ext.h"
14 #include "core/include/fxge/fx_freetype.h" 14 #include "core/include/fxge/fx_freetype.h"
15 #include "core/src/fpdfapi/fpdf_page/pageint.h" 15 #include "core/src/fpdfapi/fpdf_page/pageint.h"
16 #include "third_party/base/stl_util.h" 16 #include "third_party/base/stl_util.h"
17 17
18 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 18 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
19 #include "core/src/fxge/apple/apple_int.h" 19 #include "core/src/fxge/apple/apple_int.h"
20 #endif 20 #endif
21 21
22 namespace {
23
24 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
25 struct _GlyphNameMap {
Lei Zhang 2016/02/25 01:54:02 No leading underscore. Ditto below.
Wei Li 2016/02/25 18:48:42 Done.
26 const FX_CHAR* m_pStrAdobe;
27 const FX_CHAR* m_pStrUnicode;
28 };
29 const _GlyphNameMap g_GlyphNameSubsts[] = {{"ff", "uniFB00"},
30 {"fi", "uniFB01"},
31 {"fl", "uniFB02"},
32 {"ffi", "uniFB03"},
33 {"ffl", "uniFB04"}};
34 extern "C" {
Lei Zhang 2016/02/25 01:54:02 not needed
Wei Li 2016/02/25 18:48:42 Done.
35 int compareString(const void* key, const void* element) {
36 return FXSYS_stricmp((const FX_CHAR*)key,
37 ((_GlyphNameMap*)element)->m_pStrAdobe);
38 }
39 }
40 const FX_CHAR* _GlyphNameRemap(const FX_CHAR* pStrAdobe) {
41 _GlyphNameMap* found = (_GlyphNameMap*)FXSYS_bsearch(
Lei Zhang 2016/02/25 01:54:02 Just do std::find() given the size of the array?
Wei Li 2016/02/25 18:48:42 For such a small array, plain linear search should
42 pStrAdobe, g_GlyphNameSubsts,
43 sizeof g_GlyphNameSubsts / sizeof(_GlyphNameMap), sizeof(_GlyphNameMap),
44 compareString);
45 if (found) {
46 return found->m_pStrUnicode;
47 }
48 return NULL;
49 }
50 #endif
51
52 const uint8_t ChineseFontNames[][5] = {{0xCB, 0xCE, 0xCC, 0xE5, 0x00},
53 {0xBF, 0xAC, 0xCC, 0xE5, 0x00},
54 {0xBA, 0xDA, 0xCC, 0xE5, 0x00},
55 {0xB7, 0xC2, 0xCB, 0xCE, 0x00},
56 {0xD0, 0xC2, 0xCB, 0xCE, 0x00}};
57
58 FX_BOOL GetPredefinedEncoding(int& basemap, const CFX_ByteString& value) {
59 if (value == "WinAnsiEncoding") {
60 basemap = PDFFONT_ENCODING_WINANSI;
61 } else if (value == "MacRomanEncoding") {
62 basemap = PDFFONT_ENCODING_MACROMAN;
63 } else if (value == "MacExpertEncoding") {
64 basemap = PDFFONT_ENCODING_MACEXPERT;
65 } else if (value == "PDFDocEncoding") {
66 basemap = PDFFONT_ENCODING_PDFDOC;
67 } else {
68 return FALSE;
69 }
70 return TRUE;
71 }
72
73 static FX_BOOL FT_UseType1Charmap(FXFT_Face face) {
Lei Zhang 2016/02/25 01:54:02 no need for static inside anonymous namespace
Wei Li 2016/02/25 18:48:42 Missed this, thanks
74 if (FXFT_Get_Face_CharmapCount(face) == 0) {
75 return FALSE;
76 }
77 if (FXFT_Get_Face_CharmapCount(face) == 1 &&
78 FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[0]) ==
79 FXFT_ENCODING_UNICODE) {
80 return FALSE;
81 }
82 if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[0]) ==
83 FXFT_ENCODING_UNICODE) {
84 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[1]);
85 } else {
86 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[0]);
87 }
88 return TRUE;
89 }
90
91 } // namespace
92
22 FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id) { 93 FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id) {
23 for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) { 94 for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) {
24 if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) == 95 if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) ==
25 platform_id && 96 platform_id &&
26 FXFT_Get_Charmap_EncodingID(FXFT_Get_Face_Charmaps(face)[i]) == 97 FXFT_Get_Charmap_EncodingID(FXFT_Get_Face_Charmaps(face)[i]) ==
27 encoding_id) { 98 encoding_id) {
28 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[i]); 99 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[i]);
29 return TRUE; 100 return TRUE;
30 } 101 }
31 } 102 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 void CPDF_FontGlobals::Set(CPDF_Document* pDoc, int index, CPDF_Font* pFont) { 145 void CPDF_FontGlobals::Set(CPDF_Document* pDoc, int index, CPDF_Font* pFont) {
75 if (!pdfium::ContainsKey(m_StockMap, pDoc)) 146 if (!pdfium::ContainsKey(m_StockMap, pDoc))
76 m_StockMap[pDoc].reset(new CFX_StockFontArray); 147 m_StockMap[pDoc].reset(new CFX_StockFontArray);
77 m_StockMap[pDoc]->SetFont(index, pFont); 148 m_StockMap[pDoc]->SetFont(index, pFont);
78 } 149 }
79 150
80 void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) { 151 void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) {
81 m_StockMap.erase(pDoc); 152 m_StockMap.erase(pDoc);
82 } 153 }
83 154
84 CPDF_Font::CPDF_Font(int fonttype) : m_FontType(fonttype) { 155 CPDF_Font::CPDF_Font()
85 m_FontBBox.left = m_FontBBox.right = m_FontBBox.top = m_FontBBox.bottom = 0; 156 : m_pFontFile(nullptr),
86 m_StemV = m_Ascent = m_Descent = m_ItalicAngle = 0; 157 m_pFontDict(nullptr),
87 m_pFontFile = NULL; 158 m_pToUnicodeMap(nullptr),
88 m_Flags = 0; 159 m_bToUnicodeLoaded(FALSE),
89 m_pToUnicodeMap = NULL; 160 m_Flags(0),
90 m_bToUnicodeLoaded = FALSE; 161 m_StemV(0),
91 } 162 m_Ascent(0),
163 m_Descent(0),
164 m_ItalicAngle(0) {}
165
92 CPDF_Font::~CPDF_Font() { 166 CPDF_Font::~CPDF_Font() {
93 delete m_pToUnicodeMap; 167 delete m_pToUnicodeMap;
94 m_pToUnicodeMap = NULL; 168 m_pToUnicodeMap = NULL;
95 169
96 if (m_pFontFile) { 170 if (m_pFontFile) {
97 m_pDocument->GetPageData()->ReleaseFontFileStreamAcc( 171 m_pDocument->GetPageData()->ReleaseFontFileStreamAcc(
98 const_cast<CPDF_Stream*>(m_pFontFile->GetStream()->AsStream())); 172 const_cast<CPDF_Stream*>(m_pFontFile->GetStream()->AsStream()));
99 } 173 }
100 } 174 }
175
101 FX_BOOL CPDF_Font::IsVertWriting() const { 176 FX_BOOL CPDF_Font::IsVertWriting() const {
102 FX_BOOL bVertWriting = FALSE; 177 FX_BOOL bVertWriting = FALSE;
103 CPDF_CIDFont* pCIDFont = GetCIDFont(); 178 const CPDF_CIDFont* pCIDFont = AsCIDFont();
104 if (pCIDFont) { 179 if (pCIDFont) {
105 bVertWriting = pCIDFont->IsVertWriting(); 180 bVertWriting = pCIDFont->IsVertWriting();
106 } else { 181 } else {
107 bVertWriting = m_Font.IsVertical(); 182 bVertWriting = m_Font.IsVertical();
108 } 183 }
109 return bVertWriting; 184 return bVertWriting;
110 } 185 }
111 CFX_ByteString CPDF_Font::GetFontTypeName() const { 186
112 switch (m_FontType) { 187 int CPDF_Font::AppendChar(FX_CHAR* buf, FX_DWORD charcode) const {
113 case PDFFONT_TYPE1: 188 *buf = (FX_CHAR)charcode;
114 return "Type1"; 189 return 1;
115 case PDFFONT_TRUETYPE:
116 return "TrueType";
117 case PDFFONT_TYPE3:
118 return "Type3";
119 case PDFFONT_CIDFONT:
120 return "Type0";
121 }
122 return CFX_ByteString();
123 } 190 }
191
124 void CPDF_Font::AppendChar(CFX_ByteString& str, FX_DWORD charcode) const { 192 void CPDF_Font::AppendChar(CFX_ByteString& str, FX_DWORD charcode) const {
125 char buf[4]; 193 char buf[4];
126 int len = AppendChar(buf, charcode); 194 int len = AppendChar(buf, charcode);
127 if (len == 1) { 195 if (len == 1) {
128 str += buf[0]; 196 str += buf[0];
129 } else { 197 } else {
130 str += CFX_ByteString(buf, len); 198 str += CFX_ByteString(buf, len);
131 } 199 }
132 } 200 }
201
133 CFX_WideString CPDF_Font::UnicodeFromCharCode(FX_DWORD charcode) const { 202 CFX_WideString CPDF_Font::UnicodeFromCharCode(FX_DWORD charcode) const {
134 if (!m_bToUnicodeLoaded) { 203 if (!m_bToUnicodeLoaded) {
135 ((CPDF_Font*)this)->LoadUnicodeMap(); 204 ((CPDF_Font*)this)->LoadUnicodeMap();
136 } 205 }
137 if (m_pToUnicodeMap) { 206 if (m_pToUnicodeMap) {
138 CFX_WideString wsRet = m_pToUnicodeMap->Lookup(charcode); 207 CFX_WideString wsRet = m_pToUnicodeMap->Lookup(charcode);
139 if (!wsRet.IsEmpty()) { 208 if (!wsRet.IsEmpty()) {
140 return wsRet; 209 return wsRet;
141 } 210 }
142 } 211 }
143 FX_WCHAR unicode = _UnicodeFromCharCode(charcode); 212 FX_WCHAR unicode = _UnicodeFromCharCode(charcode);
144 if (unicode == 0) { 213 if (unicode == 0) {
145 return CFX_WideString(); 214 return CFX_WideString();
146 } 215 }
147 return unicode; 216 return unicode;
148 } 217 }
218
149 FX_DWORD CPDF_Font::CharCodeFromUnicode(FX_WCHAR unicode) const { 219 FX_DWORD CPDF_Font::CharCodeFromUnicode(FX_WCHAR unicode) const {
150 if (!m_bToUnicodeLoaded) { 220 if (!m_bToUnicodeLoaded) {
151 ((CPDF_Font*)this)->LoadUnicodeMap(); 221 ((CPDF_Font*)this)->LoadUnicodeMap();
152 } 222 }
153 if (m_pToUnicodeMap) { 223 if (m_pToUnicodeMap) {
154 FX_DWORD charcode = m_pToUnicodeMap->ReverseLookup(unicode); 224 FX_DWORD charcode = m_pToUnicodeMap->ReverseLookup(unicode);
155 if (charcode) { 225 if (charcode) {
156 return charcode; 226 return charcode;
157 } 227 }
158 } 228 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 296 }
227 } 297 }
228 298
229 short TT2PDF(int m, FXFT_Face face) { 299 short TT2PDF(int m, FXFT_Face face) {
230 int upm = FXFT_Get_Face_UnitsPerEM(face); 300 int upm = FXFT_Get_Face_UnitsPerEM(face);
231 if (upm == 0) { 301 if (upm == 0) {
232 return (short)m; 302 return (short)m;
233 } 303 }
234 return (m * 1000 + upm / 2) / upm; 304 return (m * 1000 + upm / 2) / upm;
235 } 305 }
306
236 void CPDF_Font::CheckFontMetrics() { 307 void CPDF_Font::CheckFontMetrics() {
237 if (m_FontBBox.top == 0 && m_FontBBox.bottom == 0 && m_FontBBox.left == 0 && 308 if (m_FontBBox.top == 0 && m_FontBBox.bottom == 0 && m_FontBBox.left == 0 &&
238 m_FontBBox.right == 0) { 309 m_FontBBox.right == 0) {
239 FXFT_Face face = m_Font.GetFace(); 310 FXFT_Face face = m_Font.GetFace();
240 if (face) { 311 if (face) {
241 m_FontBBox.left = TT2PDF(FXFT_Get_Face_xMin(face), face); 312 m_FontBBox.left = TT2PDF(FXFT_Get_Face_xMin(face), face);
242 m_FontBBox.bottom = TT2PDF(FXFT_Get_Face_yMin(face), face); 313 m_FontBBox.bottom = TT2PDF(FXFT_Get_Face_yMin(face), face);
243 m_FontBBox.right = TT2PDF(FXFT_Get_Face_xMax(face), face); 314 m_FontBBox.right = TT2PDF(FXFT_Get_Face_xMax(face), face);
244 m_FontBBox.top = TT2PDF(FXFT_Get_Face_yMax(face), face); 315 m_FontBBox.top = TT2PDF(FXFT_Get_Face_yMax(face), face);
245 m_Ascent = TT2PDF(FXFT_Get_Face_Ascender(face), face); 316 m_Ascent = TT2PDF(FXFT_Get_Face_Ascender(face), face);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 m_Ascent = rect.top; 352 m_Ascent = rect.top;
282 } 353 }
283 GetCharBBox('g', rect); 354 GetCharBBox('g', rect);
284 if (rect.bottom == rect.top) { 355 if (rect.bottom == rect.top) {
285 m_Descent = m_FontBBox.bottom; 356 m_Descent = m_FontBBox.bottom;
286 } else { 357 } else {
287 m_Descent = rect.bottom; 358 m_Descent = rect.bottom;
288 } 359 }
289 } 360 }
290 } 361 }
362
291 void CPDF_Font::LoadUnicodeMap() { 363 void CPDF_Font::LoadUnicodeMap() {
292 m_bToUnicodeLoaded = TRUE; 364 m_bToUnicodeLoaded = TRUE;
293 CPDF_Stream* pStream = m_pFontDict->GetStreamBy("ToUnicode"); 365 CPDF_Stream* pStream = m_pFontDict->GetStreamBy("ToUnicode");
294 if (!pStream) { 366 if (!pStream) {
295 return; 367 return;
296 } 368 }
297 m_pToUnicodeMap = new CPDF_ToUnicodeMap; 369 m_pToUnicodeMap = new CPDF_ToUnicodeMap;
298 m_pToUnicodeMap->Load(pStream); 370 m_pToUnicodeMap->Load(pStream);
299 } 371 }
372
300 int CPDF_Font::GetStringWidth(const FX_CHAR* pString, int size) { 373 int CPDF_Font::GetStringWidth(const FX_CHAR* pString, int size) {
301 int offset = 0; 374 int offset = 0;
302 int width = 0; 375 int width = 0;
303 while (offset < size) { 376 while (offset < size) {
304 FX_DWORD charcode = GetNextChar(pString, size, offset); 377 FX_DWORD charcode = GetNextChar(pString, size, offset);
305 width += GetCharWidthF(charcode); 378 width += GetCharWidthF(charcode);
306 } 379 }
307 return width; 380 return width;
308 } 381 }
309 int CPDF_Font::GetCharTypeWidth(FX_DWORD charcode) {
310 if (!m_Font.GetFace())
311 return 0;
312
313 int glyph_index = GlyphFromCharCode(charcode);
314 if (glyph_index == 0xffff) {
315 return 0;
316 }
317 return m_Font.GetGlyphWidth(glyph_index);
318 }
319 382
320 CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc, 383 CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc,
321 const CFX_ByteStringC& name) { 384 const CFX_ByteStringC& name) {
322 CFX_ByteString fontname(name); 385 CFX_ByteString fontname(name);
323 int font_id = PDF_GetStandardFontName(&fontname); 386 int font_id = PDF_GetStandardFontName(&fontname);
324 if (font_id < 0) { 387 if (font_id < 0) {
325 return nullptr; 388 return nullptr;
326 } 389 }
327 CPDF_FontGlobals* pFontGlobals = 390 CPDF_FontGlobals* pFontGlobals =
328 CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals(); 391 CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
329 CPDF_Font* pFont = pFontGlobals->Find(pDoc, font_id); 392 CPDF_Font* pFont = pFontGlobals->Find(pDoc, font_id);
330 if (pFont) { 393 if (pFont) {
331 return pFont; 394 return pFont;
332 } 395 }
333 CPDF_Dictionary* pDict = new CPDF_Dictionary; 396 CPDF_Dictionary* pDict = new CPDF_Dictionary;
334 pDict->SetAtName("Type", "Font"); 397 pDict->SetAtName("Type", "Font");
335 pDict->SetAtName("Subtype", "Type1"); 398 pDict->SetAtName("Subtype", "Type1");
336 pDict->SetAtName("BaseFont", fontname); 399 pDict->SetAtName("BaseFont", fontname);
337 pDict->SetAtName("Encoding", "WinAnsiEncoding"); 400 pDict->SetAtName("Encoding", "WinAnsiEncoding");
338 pFont = CPDF_Font::CreateFontF(NULL, pDict); 401 pFont = CPDF_Font::CreateFontF(NULL, pDict);
339 pFontGlobals->Set(pDoc, font_id, pFont); 402 pFontGlobals->Set(pDoc, font_id, pFont);
340 return pFont; 403 return pFont;
341 } 404 }
342 const uint8_t ChineseFontNames[][5] = {{0xCB, 0xCE, 0xCC, 0xE5, 0x00}, 405
343 {0xBF, 0xAC, 0xCC, 0xE5, 0x00},
344 {0xBA, 0xDA, 0xCC, 0xE5, 0x00},
345 {0xB7, 0xC2, 0xCB, 0xCE, 0x00},
346 {0xD0, 0xC2, 0xCB, 0xCE, 0x00}};
347 CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, 406 CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc,
348 CPDF_Dictionary* pFontDict) { 407 CPDF_Dictionary* pFontDict) {
349 CFX_ByteString type = pFontDict->GetStringBy("Subtype"); 408 CFX_ByteString type = pFontDict->GetStringBy("Subtype");
350 CPDF_Font* pFont; 409 CPDF_Font* pFont;
351 if (type == "TrueType") { 410 if (type == "TrueType") {
352 { 411 {
353 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || \ 412 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || \
354 _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ 413 _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \
355 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ || \ 414 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ || \
356 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 415 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
(...skipping 30 matching lines...) Expand all
387 pFont = new CPDF_Type1Font; 446 pFont = new CPDF_Type1Font;
388 } 447 }
389 pFont->m_pFontDict = pFontDict; 448 pFont->m_pFontDict = pFontDict;
390 pFont->m_pDocument = pDoc; 449 pFont->m_pDocument = pDoc;
391 if (!pFont->Load()) { 450 if (!pFont->Load()) {
392 delete pFont; 451 delete pFont;
393 return NULL; 452 return NULL;
394 } 453 }
395 return pFont; 454 return pFont;
396 } 455 }
456
397 FX_BOOL CPDF_Font::Load() { 457 FX_BOOL CPDF_Font::Load() {
398 if (!m_pFontDict) { 458 if (!m_pFontDict) {
399 return FALSE; 459 return FALSE;
400 } 460 }
401 CFX_ByteString type = m_pFontDict->GetStringBy("Subtype"); 461 CFX_ByteString type = m_pFontDict->GetStringBy("Subtype");
402 m_BaseFont = m_pFontDict->GetStringBy("BaseFont"); 462 m_BaseFont = m_pFontDict->GetStringBy("BaseFont");
403 if (type == "MMType1") { 463 if (type == "MMType1") {
404 type = "Type1"; 464 type = "Type1";
405 } 465 }
406 return _Load(); 466 return _Load();
(...skipping 20 matching lines...) Expand all
427 if (index + len < index || index + len >= buf_len) { 487 if (index + len < index || index + len >= buf_len) {
428 return CFX_WideString(); 488 return CFX_WideString();
429 } 489 }
430 return CFX_WideString(buf + index + 1, len); 490 return CFX_WideString(buf + index + 1, len);
431 } 491 }
432 if (m_pBaseMap) { 492 if (m_pBaseMap) {
433 return m_pBaseMap->UnicodeFromCID((FX_WORD)charcode); 493 return m_pBaseMap->UnicodeFromCID((FX_WORD)charcode);
434 } 494 }
435 return CFX_WideString(); 495 return CFX_WideString();
436 } 496 }
497
437 FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) { 498 FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) {
438 for (const auto& pair : m_Map) { 499 for (const auto& pair : m_Map) {
439 if (pair.second == unicode) 500 if (pair.second == unicode)
440 return pair.first; 501 return pair.first;
441 } 502 }
442 return 0; 503 return 0;
443 } 504 }
444 505
445 // Static. 506 // Static.
446 FX_DWORD CPDF_ToUnicodeMap::StringToCode(const CFX_ByteStringC& str) { 507 FX_DWORD CPDF_ToUnicodeMap::StringToCode(const CFX_ByteStringC& str) {
447 const FX_CHAR* buf = str.GetCStr(); 508 const FX_CHAR* buf = str.GetCStr();
448 int len = str.GetLength(); 509 int len = str.GetLength();
449 if (len == 0) 510 if (len == 0)
450 return 0; 511 return 0;
451 512
452 int result = 0; 513 int result = 0;
453 if (buf[0] == '<') { 514 if (buf[0] == '<') {
454 for (int i = 1; i < len && std::isxdigit(buf[i]); ++i) 515 for (int i = 1; i < len && std::isxdigit(buf[i]); ++i)
455 result = result * 16 + FXSYS_toHexDigit(buf[i]); 516 result = result * 16 + FXSYS_toHexDigit(buf[i]);
456 return result; 517 return result;
457 } 518 }
458 519
459 for (int i = 0; i < len && std::isdigit(buf[i]); ++i) 520 for (int i = 0; i < len && std::isdigit(buf[i]); ++i)
460 result = result * 10 + FXSYS_toDecimalDigit(buf[i]); 521 result = result * 10 + FXSYS_toDecimalDigit(buf[i]);
461 522
462 return result; 523 return result;
463 } 524 }
525
464 static CFX_WideString StringDataAdd(CFX_WideString str) { 526 static CFX_WideString StringDataAdd(CFX_WideString str) {
465 CFX_WideString ret; 527 CFX_WideString ret;
466 int len = str.GetLength(); 528 int len = str.GetLength();
467 FX_WCHAR value = 1; 529 FX_WCHAR value = 1;
468 for (int i = len - 1; i >= 0; --i) { 530 for (int i = len - 1; i >= 0; --i) {
469 FX_WCHAR ch = str[i] + value; 531 FX_WCHAR ch = str[i] + value;
470 if (ch < str[i]) { 532 if (ch < str[i]) {
471 ret.Insert(0, 0); 533 ret.Insert(0, 0);
472 } else { 534 } else {
473 ret.Insert(0, ch); 535 ret.Insert(0, ch);
(...skipping 24 matching lines...) Expand all
498 if (byte_pos == 4) { 560 if (byte_pos == 4) {
499 result += ch; 561 result += ch;
500 byte_pos = 0; 562 byte_pos = 0;
501 ch = 0; 563 ch = 0;
502 } 564 }
503 } 565 }
504 return result; 566 return result;
505 } 567 }
506 return result; 568 return result;
507 } 569 }
570
508 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { 571 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) {
509 CIDSet cid_set = CIDSET_UNKNOWN; 572 CIDSet cid_set = CIDSET_UNKNOWN;
510 CPDF_StreamAcc stream; 573 CPDF_StreamAcc stream;
511 stream.LoadAllData(pStream, FALSE); 574 stream.LoadAllData(pStream, FALSE);
512 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize()); 575 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize());
513 while (1) { 576 while (1) {
514 CFX_ByteStringC word = parser.GetWord(); 577 CFX_ByteStringC word = parser.GetWord();
515 if (word.IsEmpty()) { 578 if (word.IsEmpty()) {
516 break; 579 break;
517 } 580 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 } 668 }
606 if (cid_set) { 669 if (cid_set) {
607 m_pBaseMap = CPDF_ModuleMgr::Get() 670 m_pBaseMap = CPDF_ModuleMgr::Get()
608 ->GetPageModule() 671 ->GetPageModule()
609 ->GetFontGlobals() 672 ->GetFontGlobals()
610 ->m_CMapManager.GetCID2UnicodeMap(cid_set, FALSE); 673 ->m_CMapManager.GetCID2UnicodeMap(cid_set, FALSE);
611 } else { 674 } else {
612 m_pBaseMap = NULL; 675 m_pBaseMap = NULL;
613 } 676 }
614 } 677 }
615 static FX_BOOL GetPredefinedEncoding(int& basemap, 678
616 const CFX_ByteString& value) { 679 FX_DWORD CPDF_Font::GetNextChar(const FX_CHAR* pString,
617 if (value == "WinAnsiEncoding") { 680 int nStrLen,
618 basemap = PDFFONT_ENCODING_WINANSI; 681 int& offset) const {
619 } else if (value == "MacRomanEncoding") { 682 if (offset < 0 || nStrLen < 1) {
620 basemap = PDFFONT_ENCODING_MACROMAN; 683 return 0;
621 } else if (value == "MacExpertEncoding") {
622 basemap = PDFFONT_ENCODING_MACEXPERT;
623 } else if (value == "PDFDocEncoding") {
624 basemap = PDFFONT_ENCODING_PDFDOC;
625 } else {
626 return FALSE;
627 } 684 }
628 return TRUE; 685 uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen - 1];
686 return static_cast<FX_DWORD>(ch);
629 } 687 }
688
630 void CPDF_Font::LoadPDFEncoding(CPDF_Object* pEncoding, 689 void CPDF_Font::LoadPDFEncoding(CPDF_Object* pEncoding,
631 int& iBaseEncoding, 690 int& iBaseEncoding,
632 CFX_ByteString*& pCharNames, 691 CFX_ByteString*& pCharNames,
633 FX_BOOL bEmbedded, 692 FX_BOOL bEmbedded,
634 FX_BOOL bTrueType) { 693 FX_BOOL bTrueType) {
635 if (!pEncoding) { 694 if (!pEncoding) {
636 if (m_BaseFont == "Symbol") { 695 if (m_BaseFont == "Symbol") {
637 iBaseEncoding = bTrueType ? PDFFONT_ENCODING_MS_SYMBOL 696 iBaseEncoding = bTrueType ? PDFFONT_ENCODING_MS_SYMBOL
638 : PDFFONT_ENCODING_ADOBE_SYMBOL; 697 : PDFFONT_ENCODING_ADOBE_SYMBOL;
639 } else if (!bEmbedded && iBaseEncoding == PDFFONT_ENCODING_BUILTIN) { 698 } else if (!bEmbedded && iBaseEncoding == PDFFONT_ENCODING_BUILTIN) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 if (cur_code < 256) 749 if (cur_code < 256)
691 pCharNames[cur_code] = pName->GetString(); 750 pCharNames[cur_code] = pName->GetString();
692 cur_code++; 751 cur_code++;
693 } else { 752 } else {
694 cur_code = pElement->GetInteger(); 753 cur_code = pElement->GetInteger();
695 } 754 }
696 } 755 }
697 } 756 }
698 757
699 FX_BOOL CPDF_Font::IsStandardFont() const { 758 FX_BOOL CPDF_Font::IsStandardFont() const {
700 if (m_FontType != PDFFONT_TYPE1) 759 if (!IsType1Font())
701 return FALSE; 760 return FALSE;
702 if (m_pFontFile) 761 if (m_pFontFile)
703 return FALSE; 762 return FALSE;
704 if (((CPDF_Type1Font*)this)->GetBase14Font() < 0) 763 if (this->AsType1Font()->GetBase14Font() < 0)
705 return FALSE; 764 return FALSE;
706 return TRUE; 765 return TRUE;
707 } 766 }
708 CPDF_SimpleFont::CPDF_SimpleFont(int fonttype) : CPDF_Font(fonttype) { 767
768 CPDF_SimpleFont::CPDF_SimpleFont() {
709 FXSYS_memset(m_CharBBox, 0xff, sizeof m_CharBBox); 769 FXSYS_memset(m_CharBBox, 0xff, sizeof m_CharBBox);
710 FXSYS_memset(m_CharWidth, 0xff, sizeof m_CharWidth); 770 FXSYS_memset(m_CharWidth, 0xff, sizeof m_CharWidth);
711 FXSYS_memset(m_GlyphIndex, 0xff, sizeof m_GlyphIndex); 771 FXSYS_memset(m_GlyphIndex, 0xff, sizeof m_GlyphIndex);
712 FXSYS_memset(m_ExtGID, 0xff, sizeof m_ExtGID); 772 FXSYS_memset(m_ExtGID, 0xff, sizeof m_ExtGID);
713 m_pCharNames = NULL; 773 m_pCharNames = NULL;
714 m_BaseEncoding = PDFFONT_ENCODING_BUILTIN; 774 m_BaseEncoding = PDFFONT_ENCODING_BUILTIN;
715 } 775 }
776
716 CPDF_SimpleFont::~CPDF_SimpleFont() { 777 CPDF_SimpleFont::~CPDF_SimpleFont() {
717 delete[] m_pCharNames; 778 delete[] m_pCharNames;
718 } 779 }
780
719 int CPDF_SimpleFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph) { 781 int CPDF_SimpleFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph) {
720 if (pVertGlyph) { 782 if (pVertGlyph) {
721 *pVertGlyph = FALSE; 783 *pVertGlyph = FALSE;
722 } 784 }
723 if (charcode > 0xff) { 785 if (charcode > 0xff) {
724 return -1; 786 return -1;
725 } 787 }
726 int index = m_GlyphIndex[(uint8_t)charcode]; 788 int index = m_GlyphIndex[(uint8_t)charcode];
727 if (index == 0xffff) { 789 if (index == 0xffff) {
728 return -1; 790 return -1;
729 } 791 }
730 return index; 792 return index;
731 } 793 }
794
732 void CPDF_SimpleFont::LoadCharMetrics(int charcode) { 795 void CPDF_SimpleFont::LoadCharMetrics(int charcode) {
733 if (!m_Font.GetFace()) 796 if (!m_Font.GetFace())
734 return; 797 return;
735 798
736 if (charcode < 0 || charcode > 0xff) { 799 if (charcode < 0 || charcode > 0xff) {
737 return; 800 return;
738 } 801 }
739 int glyph_index = m_GlyphIndex[charcode]; 802 int glyph_index = m_GlyphIndex[charcode];
740 if (glyph_index == 0xffff) { 803 if (glyph_index == 0xffff) {
741 if (!m_pFontFile && charcode != 32) { 804 if (!m_pFontFile && charcode != 32) {
(...skipping 23 matching lines...) Expand all
765 if (m_CharWidth[charcode] == 0xffff) { 828 if (m_CharWidth[charcode] == 0xffff) {
766 m_CharWidth[charcode] = TT_Width; 829 m_CharWidth[charcode] = TT_Width;
767 } else if (TT_Width && !IsEmbedded()) { 830 } else if (TT_Width && !IsEmbedded()) {
768 m_CharBBox[charcode].Right = 831 m_CharBBox[charcode].Right =
769 m_CharBBox[charcode].Right * m_CharWidth[charcode] / TT_Width; 832 m_CharBBox[charcode].Right * m_CharWidth[charcode] / TT_Width;
770 m_CharBBox[charcode].Left = 833 m_CharBBox[charcode].Left =
771 m_CharBBox[charcode].Left * m_CharWidth[charcode] / TT_Width; 834 m_CharBBox[charcode].Left * m_CharWidth[charcode] / TT_Width;
772 } 835 }
773 } 836 }
774 } 837 }
838
775 int CPDF_SimpleFont::GetCharWidthF(FX_DWORD charcode, int level) { 839 int CPDF_SimpleFont::GetCharWidthF(FX_DWORD charcode, int level) {
776 if (charcode > 0xff) { 840 if (charcode > 0xff) {
777 charcode = 0; 841 charcode = 0;
778 } 842 }
779 if (m_CharWidth[charcode] == 0xffff) { 843 if (m_CharWidth[charcode] == 0xffff) {
780 LoadCharMetrics(charcode); 844 LoadCharMetrics(charcode);
781 if (m_CharWidth[charcode] == 0xffff) { 845 if (m_CharWidth[charcode] == 0xffff) {
782 m_CharWidth[charcode] = 0; 846 m_CharWidth[charcode] = 0;
783 } 847 }
784 } 848 }
785 return (int16_t)m_CharWidth[charcode]; 849 return (int16_t)m_CharWidth[charcode];
786 } 850 }
851
787 void CPDF_SimpleFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) { 852 void CPDF_SimpleFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) {
788 if (charcode > 0xff) { 853 if (charcode > 0xff) {
789 charcode = 0; 854 charcode = 0;
790 } 855 }
791 if (m_CharBBox[charcode].Left == (int16_t)0xffff) { 856 if (m_CharBBox[charcode].Left == (int16_t)0xffff) {
792 LoadCharMetrics(charcode); 857 LoadCharMetrics(charcode);
793 } 858 }
794 rect.left = m_CharBBox[charcode].Left; 859 rect.left = m_CharBBox[charcode].Left;
795 rect.right = m_CharBBox[charcode].Right; 860 rect.right = m_CharBBox[charcode].Right;
796 rect.bottom = m_CharBBox[charcode].Bottom; 861 rect.bottom = m_CharBBox[charcode].Bottom;
797 rect.top = m_CharBBox[charcode].Top; 862 rect.top = m_CharBBox[charcode].Top;
798 } 863 }
864
799 const FX_CHAR* GetAdobeCharName(int iBaseEncoding, 865 const FX_CHAR* GetAdobeCharName(int iBaseEncoding,
800 const CFX_ByteString* pCharNames, 866 const CFX_ByteString* pCharNames,
801 int charcode) { 867 int charcode) {
802 ASSERT(charcode >= 0 && charcode < 256); 868 ASSERT(charcode >= 0 && charcode < 256);
803 if (charcode < 0 || charcode >= 256) { 869 if (charcode < 0 || charcode >= 256) {
804 return NULL; 870 return NULL;
805 } 871 }
806 const FX_CHAR* name = NULL; 872 const FX_CHAR* name = NULL;
807 if (pCharNames) { 873 if (pCharNames) {
808 name = pCharNames[charcode]; 874 name = pCharNames[charcode];
809 } 875 }
810 if ((!name || name[0] == 0) && iBaseEncoding) { 876 if ((!name || name[0] == 0) && iBaseEncoding) {
811 name = PDF_CharNameFromPredefinedCharSet(iBaseEncoding, charcode); 877 name = PDF_CharNameFromPredefinedCharSet(iBaseEncoding, charcode);
812 } 878 }
813 return name && name[0] ? name : nullptr; 879 return name && name[0] ? name : nullptr;
814 } 880 }
881
815 FX_BOOL CPDF_SimpleFont::LoadCommon() { 882 FX_BOOL CPDF_SimpleFont::LoadCommon() {
816 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictBy("FontDescriptor"); 883 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictBy("FontDescriptor");
817 if (pFontDesc) { 884 if (pFontDesc) {
818 LoadFontDescriptor(pFontDesc); 885 LoadFontDescriptor(pFontDesc);
819 } 886 }
820 CPDF_Array* pWidthArray = m_pFontDict->GetArrayBy("Widths"); 887 CPDF_Array* pWidthArray = m_pFontDict->GetArrayBy("Widths");
821 int width_start = 0, width_end = -1; 888 int width_start = 0, width_end = -1;
822 m_bUseFontWidth = TRUE; 889 m_bUseFontWidth = TRUE;
823 if (pWidthArray) { 890 if (pWidthArray) {
824 m_bUseFontWidth = FALSE; 891 m_bUseFontWidth = FALSE;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 if (m_CharWidth[i - 32]) { 940 if (m_CharWidth[i - 32]) {
874 m_CharWidth[i] = m_CharWidth[i - 32]; 941 m_CharWidth[i] = m_CharWidth[i - 32];
875 m_CharBBox[i] = m_CharBBox[i - 32]; 942 m_CharBBox[i] = m_CharBBox[i - 32];
876 } 943 }
877 } 944 }
878 } 945 }
879 } 946 }
880 CheckFontMetrics(); 947 CheckFontMetrics();
881 return TRUE; 948 return TRUE;
882 } 949 }
950
883 void CPDF_SimpleFont::LoadSubstFont() { 951 void CPDF_SimpleFont::LoadSubstFont() {
884 if (!m_bUseFontWidth && !(m_Flags & PDFFONT_FIXEDPITCH)) { 952 if (!m_bUseFontWidth && !(m_Flags & PDFFONT_FIXEDPITCH)) {
885 int width = 0, i; 953 int width = 0, i;
886 for (i = 0; i < 256; i++) { 954 for (i = 0; i < 256; i++) {
887 if (m_CharWidth[i] == 0 || m_CharWidth[i] == 0xffff) { 955 if (m_CharWidth[i] == 0 || m_CharWidth[i] == 0xffff) {
888 continue; 956 continue;
889 } 957 }
890 if (width == 0) { 958 if (width == 0) {
891 width = m_CharWidth[i]; 959 width = m_CharWidth[i];
892 } else if (width != m_CharWidth[i]) { 960 } else if (width != m_CharWidth[i]) {
893 break; 961 break;
894 } 962 }
895 } 963 }
896 if (i == 256 && width) { 964 if (i == 256 && width) {
897 m_Flags |= PDFFONT_FIXEDPITCH; 965 m_Flags |= PDFFONT_FIXEDPITCH;
898 } 966 }
899 } 967 }
900 int weight = m_StemV < 140 ? m_StemV * 5 : (m_StemV * 4 + 140); 968 int weight = m_StemV < 140 ? m_StemV * 5 : (m_StemV * 4 + 140);
901 m_Font.LoadSubst(m_BaseFont, IsFontType(PDFFONT_TRUETYPE), m_Flags, weight, 969 m_Font.LoadSubst(m_BaseFont, IsTrueTypeFont(), m_Flags, weight, m_ItalicAngle,
902 m_ItalicAngle, 0); 970 0);
903 if (m_Font.GetSubstFont()->m_SubstFlags & FXFONT_SUBST_NONSYMBOL) { 971 if (m_Font.GetSubstFont()->m_SubstFlags & FXFONT_SUBST_NONSYMBOL) {
904 } 972 }
905 } 973 }
974
906 FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const { 975 FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const {
907 return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN && 976 return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN &&
908 m_BaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL && 977 m_BaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL &&
909 m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS; 978 m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS;
910 } 979 }
911 CPDF_Type1Font::CPDF_Type1Font() : CPDF_SimpleFont(PDFFONT_TYPE1) { 980
912 m_Base14Font = -1; 981 FX_WCHAR CPDF_SimpleFont::_UnicodeFromCharCode(FX_DWORD charcode) const {
982 return m_Encoding.UnicodeFromCharCode((uint8_t)charcode);
913 } 983 }
984
985 FX_DWORD CPDF_SimpleFont::_CharCodeFromUnicode(FX_WCHAR Unicode) const {
986 return m_Encoding.CharCodeFromUnicode(Unicode);
987 }
988
989 CPDF_Type1Font::CPDF_Type1Font() : m_Base14Font(-1) {}
990
914 FX_BOOL CPDF_Type1Font::_Load() { 991 FX_BOOL CPDF_Type1Font::_Load() {
915 m_Base14Font = PDF_GetStandardFontName(&m_BaseFont); 992 m_Base14Font = PDF_GetStandardFontName(&m_BaseFont);
916 if (m_Base14Font >= 0) { 993 if (m_Base14Font >= 0) {
917 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictBy("FontDescriptor"); 994 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictBy("FontDescriptor");
918 if (pFontDesc && pFontDesc->KeyExist("Flags")) { 995 if (pFontDesc && pFontDesc->KeyExist("Flags")) {
919 m_Flags = pFontDesc->GetIntegerBy("Flags"); 996 m_Flags = pFontDesc->GetIntegerBy("Flags");
920 } else { 997 } else {
921 m_Flags = m_Base14Font >= 12 ? PDFFONT_SYMBOLIC : PDFFONT_NONSYMBOLIC; 998 m_Flags = m_Base14Font >= 12 ? PDFFONT_SYMBOLIC : PDFFONT_NONSYMBOLIC;
922 } 999 }
923 if (m_Base14Font < 4) 1000 if (m_Base14Font < 4)
924 for (int i = 0; i < 256; i++) { 1001 for (int i = 0; i < 256; i++) {
925 m_CharWidth[i] = 600; 1002 m_CharWidth[i] = 600;
926 } 1003 }
927 if (m_Base14Font == 12) { 1004 if (m_Base14Font == 12) {
928 m_BaseEncoding = PDFFONT_ENCODING_ADOBE_SYMBOL; 1005 m_BaseEncoding = PDFFONT_ENCODING_ADOBE_SYMBOL;
929 } else if (m_Base14Font == 13) { 1006 } else if (m_Base14Font == 13) {
930 m_BaseEncoding = PDFFONT_ENCODING_ZAPFDINGBATS; 1007 m_BaseEncoding = PDFFONT_ENCODING_ZAPFDINGBATS;
931 } else if (m_Flags & PDFFONT_NONSYMBOLIC) { 1008 } else if (m_Flags & PDFFONT_NONSYMBOLIC) {
932 m_BaseEncoding = PDFFONT_ENCODING_STANDARD; 1009 m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
933 } 1010 }
934 } 1011 }
935 return LoadCommon(); 1012 return LoadCommon();
936 } 1013 }
937 static FX_BOOL FT_UseType1Charmap(FXFT_Face face) { 1014
938 if (FXFT_Get_Face_CharmapCount(face) == 0) {
939 return FALSE;
940 }
941 if (FXFT_Get_Face_CharmapCount(face) == 1 &&
942 FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[0]) ==
943 FXFT_ENCODING_UNICODE) {
944 return FALSE;
945 }
946 if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[0]) ==
947 FXFT_ENCODING_UNICODE) {
948 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[1]);
949 } else {
950 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[0]);
951 }
952 return TRUE;
953 }
954 int CPDF_Type1Font::GlyphFromCharCodeExt(FX_DWORD charcode) {
955 if (charcode > 0xff) {
956 return -1;
957 }
958 int index = m_ExtGID[(uint8_t)charcode];
959 if (index == 0xffff) {
960 return -1;
961 }
962 return index;
963 }
964 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
965 struct _GlyphNameMap {
966 const FX_CHAR* m_pStrAdobe;
967 const FX_CHAR* m_pStrUnicode;
968 };
969 static const _GlyphNameMap g_GlyphNameSubsts[] = {{"ff", "uniFB00"},
970 {"fi", "uniFB01"},
971 {"fl", "uniFB02"},
972 {"ffi", "uniFB03"},
973 {"ffl", "uniFB04"}};
974 extern "C" {
975 static int compareString(const void* key, const void* element) {
976 return FXSYS_stricmp((const FX_CHAR*)key,
977 ((_GlyphNameMap*)element)->m_pStrAdobe);
978 }
979 }
980 static const FX_CHAR* _GlyphNameRemap(const FX_CHAR* pStrAdobe) {
981 _GlyphNameMap* found = (_GlyphNameMap*)FXSYS_bsearch(
982 pStrAdobe, g_GlyphNameSubsts,
983 sizeof g_GlyphNameSubsts / sizeof(_GlyphNameMap), sizeof(_GlyphNameMap),
984 compareString);
985 if (found) {
986 return found->m_pStrUnicode;
987 }
988 return NULL;
989 }
990 #endif
991 void CPDF_Type1Font::LoadGlyphMap() { 1015 void CPDF_Type1Font::LoadGlyphMap() {
992 if (!m_Font.GetFace()) 1016 if (!m_Font.GetFace())
993 return; 1017 return;
994 1018
995 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1019 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
996 FX_BOOL bCoreText = TRUE; 1020 FX_BOOL bCoreText = TRUE;
997 CQuartz2D& quartz2d = 1021 CQuartz2D& quartz2d =
998 ((CApplePlatform*)CFX_GEModule::Get()->GetPlatformData())->_quartz2d; 1022 ((CApplePlatform*)CFX_GEModule::Get()->GetPlatformData())->_quartz2d;
999 if (!m_Font.GetPlatformFont()) { 1023 if (!m_Font.GetPlatformFont()) {
1000 if (m_Font.GetPsName() == CFX_WideString::FromLocal("DFHeiStd-W5")) { 1024 if (m_Font.GetPsName() == CFX_WideString::FromLocal("DFHeiStd-W5")) {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1297 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
1274 if (!bCoreText) { 1298 if (!bCoreText) {
1275 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256); 1299 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256);
1276 } 1300 }
1277 #endif 1301 #endif
1278 } 1302 }
1279 1303
1280 CPDF_FontEncoding::CPDF_FontEncoding() { 1304 CPDF_FontEncoding::CPDF_FontEncoding() {
1281 FXSYS_memset(m_Unicodes, 0, sizeof(m_Unicodes)); 1305 FXSYS_memset(m_Unicodes, 0, sizeof(m_Unicodes));
1282 } 1306 }
1307
1283 int CPDF_FontEncoding::CharCodeFromUnicode(FX_WCHAR unicode) const { 1308 int CPDF_FontEncoding::CharCodeFromUnicode(FX_WCHAR unicode) const {
1284 for (int i = 0; i < 256; i++) 1309 for (int i = 0; i < 256; i++)
1285 if (m_Unicodes[i] == unicode) { 1310 if (m_Unicodes[i] == unicode) {
1286 return i; 1311 return i;
1287 } 1312 }
1288 return -1; 1313 return -1;
1289 } 1314 }
1315
1290 CPDF_FontEncoding::CPDF_FontEncoding(int PredefinedEncoding) { 1316 CPDF_FontEncoding::CPDF_FontEncoding(int PredefinedEncoding) {
1291 const FX_WORD* pSrc = PDF_UnicodesForPredefinedCharSet(PredefinedEncoding); 1317 const FX_WORD* pSrc = PDF_UnicodesForPredefinedCharSet(PredefinedEncoding);
1292 if (!pSrc) { 1318 if (!pSrc) {
1293 FXSYS_memset(m_Unicodes, 0, sizeof(m_Unicodes)); 1319 FXSYS_memset(m_Unicodes, 0, sizeof(m_Unicodes));
1294 } else 1320 } else
1295 for (int i = 0; i < 256; i++) { 1321 for (int i = 0; i < 256; i++) {
1296 m_Unicodes[i] = pSrc[i]; 1322 m_Unicodes[i] = pSrc[i];
1297 } 1323 }
1298 } 1324 }
1325
1299 FX_BOOL CPDF_FontEncoding::IsIdentical(CPDF_FontEncoding* pAnother) const { 1326 FX_BOOL CPDF_FontEncoding::IsIdentical(CPDF_FontEncoding* pAnother) const {
1300 return FXSYS_memcmp(m_Unicodes, pAnother->m_Unicodes, sizeof(m_Unicodes)) == 1327 return FXSYS_memcmp(m_Unicodes, pAnother->m_Unicodes, sizeof(m_Unicodes)) ==
1301 0; 1328 0;
1302 } 1329 }
1330
1303 CPDF_Object* CPDF_FontEncoding::Realize() { 1331 CPDF_Object* CPDF_FontEncoding::Realize() {
1304 int predefined = 0; 1332 int predefined = 0;
1305 for (int cs = PDFFONT_ENCODING_WINANSI; cs < PDFFONT_ENCODING_ZAPFDINGBATS; 1333 for (int cs = PDFFONT_ENCODING_WINANSI; cs < PDFFONT_ENCODING_ZAPFDINGBATS;
1306 cs++) { 1334 cs++) {
1307 const FX_WORD* pSrc = PDF_UnicodesForPredefinedCharSet(cs); 1335 const FX_WORD* pSrc = PDF_UnicodesForPredefinedCharSet(cs);
1308 FX_BOOL match = TRUE; 1336 FX_BOOL match = TRUE;
1309 for (int i = 0; i < 256; ++i) { 1337 for (int i = 0; i < 256; ++i) {
1310 if (m_Unicodes[i] != pSrc[i]) { 1338 if (m_Unicodes[i] != pSrc[i]) {
1311 match = FALSE; 1339 match = FALSE;
1312 break; 1340 break;
(...skipping 25 matching lines...) Expand all
1338 } 1366 }
1339 pDiff->Add(new CPDF_Number(i)); 1367 pDiff->Add(new CPDF_Number(i));
1340 pDiff->Add(new CPDF_Name(PDF_AdobeNameFromUnicode(m_Unicodes[i]))); 1368 pDiff->Add(new CPDF_Name(PDF_AdobeNameFromUnicode(m_Unicodes[i])));
1341 } 1369 }
1342 1370
1343 CPDF_Dictionary* pDict = new CPDF_Dictionary; 1371 CPDF_Dictionary* pDict = new CPDF_Dictionary;
1344 pDict->SetAtName("BaseEncoding", "WinAnsiEncoding"); 1372 pDict->SetAtName("BaseEncoding", "WinAnsiEncoding");
1345 pDict->SetAt("Differences", pDiff); 1373 pDict->SetAt("Differences", pDiff);
1346 return pDict; 1374 return pDict;
1347 } 1375 }
1348 CPDF_TrueTypeFont::CPDF_TrueTypeFont() : CPDF_SimpleFont(PDFFONT_TRUETYPE) {} 1376
1377 CPDF_TrueTypeFont::CPDF_TrueTypeFont() {}
1378
1349 FX_BOOL CPDF_TrueTypeFont::_Load() { 1379 FX_BOOL CPDF_TrueTypeFont::_Load() {
1350 return LoadCommon(); 1380 return LoadCommon();
1351 } 1381 }
1382
1352 void CPDF_TrueTypeFont::LoadGlyphMap() { 1383 void CPDF_TrueTypeFont::LoadGlyphMap() {
1353 if (!m_Font.GetFace()) 1384 if (!m_Font.GetFace())
1354 return; 1385 return;
1355 1386
1356 int baseEncoding = m_BaseEncoding; 1387 int baseEncoding = m_BaseEncoding;
1357 if (m_pFontFile && m_Font.GetFace()->num_charmaps > 0 && 1388 if (m_pFontFile && m_Font.GetFace()->num_charmaps > 0 &&
1358 (baseEncoding == PDFFONT_ENCODING_MACROMAN || 1389 (baseEncoding == PDFFONT_ENCODING_MACROMAN ||
1359 baseEncoding == PDFFONT_ENCODING_WINANSI) && 1390 baseEncoding == PDFFONT_ENCODING_WINANSI) &&
1360 (m_Flags & PDFFONT_SYMBOLIC)) { 1391 (m_Flags & PDFFONT_SYMBOLIC)) {
1361 FX_BOOL bSupportWin = FALSE; 1392 FX_BOOL bSupportWin = FALSE;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 if (bGotOne) { 1570 if (bGotOne) {
1540 return; 1571 return;
1541 } 1572 }
1542 } 1573 }
1543 for (int charcode = 0; charcode < 256; charcode++) { 1574 for (int charcode = 0; charcode < 256; charcode++) {
1544 m_GlyphIndex[charcode] = charcode; 1575 m_GlyphIndex[charcode] = charcode;
1545 } 1576 }
1546 } 1577 }
1547 1578
1548 CPDF_Type3Font::CPDF_Type3Font() 1579 CPDF_Type3Font::CPDF_Type3Font()
1549 : CPDF_SimpleFont(PDFFONT_TYPE3), 1580 : m_pCharProcs(nullptr),
1550 m_pCharProcs(nullptr),
1551 m_pPageResources(nullptr), 1581 m_pPageResources(nullptr),
1552 m_pFontResources(nullptr) { 1582 m_pFontResources(nullptr) {
1553 FXSYS_memset(m_CharWidthL, 0, sizeof(m_CharWidthL)); 1583 FXSYS_memset(m_CharWidthL, 0, sizeof(m_CharWidthL));
1554 } 1584 }
1555 1585
1556 CPDF_Type3Font::~CPDF_Type3Font() { 1586 CPDF_Type3Font::~CPDF_Type3Font() {
1557 for (auto it : m_CacheMap) 1587 for (auto it : m_CacheMap)
1558 delete it.second; 1588 delete it.second;
1559 } 1589 }
1560 1590
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 for (int i = 0; i < 256; i++) { 1627 for (int i = 0; i < 256; i++) {
1598 m_Encoding.m_Unicodes[i] = PDF_UnicodeFromAdobeName(m_pCharNames[i]); 1628 m_Encoding.m_Unicodes[i] = PDF_UnicodeFromAdobeName(m_pCharNames[i]);
1599 if (m_Encoding.m_Unicodes[i] == 0) { 1629 if (m_Encoding.m_Unicodes[i] == 0) {
1600 m_Encoding.m_Unicodes[i] = i; 1630 m_Encoding.m_Unicodes[i] = i;
1601 } 1631 }
1602 } 1632 }
1603 } 1633 }
1604 } 1634 }
1605 return TRUE; 1635 return TRUE;
1606 } 1636 }
1637
1607 void CPDF_Type3Font::CheckType3FontMetrics() { 1638 void CPDF_Type3Font::CheckType3FontMetrics() {
1608 CheckFontMetrics(); 1639 CheckFontMetrics();
1609 } 1640 }
1610 1641
1611 CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level) { 1642 CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level) {
1612 if (level >= _FPDF_MAX_TYPE3_FORM_LEVEL_) 1643 if (level >= _FPDF_MAX_TYPE3_FORM_LEVEL_)
1613 return nullptr; 1644 return nullptr;
1614 1645
1615 auto it = m_CacheMap.find(charcode); 1646 auto it = m_CacheMap.find(charcode);
1616 if (it != m_CacheMap.end()) 1647 if (it != m_CacheMap.end())
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 rect = pChar->m_BBox; 1718 rect = pChar->m_BBox;
1688 } 1719 }
1689 1720
1690 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm) 1721 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm)
1691 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {} 1722 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {}
1692 1723
1693 CPDF_Type3Char::~CPDF_Type3Char() { 1724 CPDF_Type3Char::~CPDF_Type3Char() {
1694 delete m_pForm; 1725 delete m_pForm;
1695 delete m_pBitmap; 1726 delete m_pBitmap;
1696 } 1727 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698