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

Side by Side Diff: fpdfsdk/pdfwindow/PWL_FontMap.cpp

Issue 2347313002: Remove duplicated charset definitions (Closed)
Patch Set: Nits Created 4 years, 3 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
« no previous file with comments | « fpdfsdk/pdfwindow/PWL_FontMap.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "fpdfsdk/pdfwindow/PWL_FontMap.h" 7 #include "fpdfsdk/pdfwindow/PWL_FontMap.h"
8 8
9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" 10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 int32_t CPWL_FontMap::GetWordFontIndex(uint16_t word, 88 int32_t CPWL_FontMap::GetWordFontIndex(uint16_t word,
89 int32_t nCharset, 89 int32_t nCharset,
90 int32_t nFontIndex) { 90 int32_t nFontIndex) {
91 if (nFontIndex > 0) { 91 if (nFontIndex > 0) {
92 if (KnowWord(nFontIndex, word)) 92 if (KnowWord(nFontIndex, word))
93 return nFontIndex; 93 return nFontIndex;
94 } else { 94 } else {
95 if (const CPWL_FontMap_Data* pData = GetFontMapData(0)) { 95 if (const CPWL_FontMap_Data* pData = GetFontMapData(0)) {
96 if (nCharset == DEFAULT_CHARSET || pData->nCharset == SYMBOL_CHARSET || 96 if (nCharset == FXFONT_DEFAULT_CHARSET ||
97 pData->nCharset == FXFONT_SYMBOL_CHARSET ||
97 nCharset == pData->nCharset) { 98 nCharset == pData->nCharset) {
98 if (KnowWord(0, word)) 99 if (KnowWord(0, word))
99 return 0; 100 return 0;
100 } 101 }
101 } 102 }
102 } 103 }
103 104
104 int32_t nNewFontIndex = 105 int32_t nNewFontIndex =
105 GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE); 106 GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE);
106 if (nNewFontIndex >= 0) { 107 if (nNewFontIndex >= 0) {
107 if (KnowWord(nNewFontIndex, word)) 108 if (KnowWord(nNewFontIndex, word))
108 return nNewFontIndex; 109 return nNewFontIndex;
109 } 110 }
110 nNewFontIndex = GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE); 111 nNewFontIndex =
112 GetFontIndex("Arial Unicode MS", FXFONT_DEFAULT_CHARSET, FALSE);
111 if (nNewFontIndex >= 0) { 113 if (nNewFontIndex >= 0) {
112 if (KnowWord(nNewFontIndex, word)) 114 if (KnowWord(nNewFontIndex, word))
113 return nNewFontIndex; 115 return nNewFontIndex;
114 } 116 }
115 return -1; 117 return -1;
116 } 118 }
117 119
118 int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) { 120 int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) {
119 CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex); 121 CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex);
120 if (!pData) 122 if (!pData)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 162 }
161 { 163 {
162 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++) 164 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++)
163 delete m_aNativeFont.GetAt(i); 165 delete m_aNativeFont.GetAt(i);
164 166
165 m_aNativeFont.RemoveAll(); 167 m_aNativeFont.RemoveAll();
166 } 168 }
167 } 169 }
168 170
169 void CPWL_FontMap::Initialize() { 171 void CPWL_FontMap::Initialize() {
170 GetFontIndex(kDefaultFontName, ANSI_CHARSET, FALSE); 172 GetFontIndex(kDefaultFontName, FXFONT_ANSI_CHARSET, FALSE);
171 } 173 }
172 174
173 FX_BOOL CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName) { 175 FX_BOOL CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName) {
174 for (size_t i = 0; i < FX_ArraySize(g_sDEStandardFontName); ++i) { 176 for (size_t i = 0; i < FX_ArraySize(g_sDEStandardFontName); ++i) {
175 if (sFontName == g_sDEStandardFontName[i]) 177 if (sFontName == g_sDEStandardFontName[i])
176 return TRUE; 178 return TRUE;
177 } 179 }
178 180
179 return FALSE; 181 return FALSE;
180 } 182 }
181 183
182 int32_t CPWL_FontMap::FindFont(const CFX_ByteString& sFontName, 184 int32_t CPWL_FontMap::FindFont(const CFX_ByteString& sFontName,
183 int32_t nCharset) { 185 int32_t nCharset) {
184 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++) { 186 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++) {
185 if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) { 187 if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) {
186 if (nCharset == DEFAULT_CHARSET || nCharset == pData->nCharset) { 188 if (nCharset == FXFONT_DEFAULT_CHARSET || nCharset == pData->nCharset) {
187 if (sFontName.IsEmpty() || pData->sFontName == sFontName) 189 if (sFontName.IsEmpty() || pData->sFontName == sFontName)
188 return i; 190 return i;
189 } 191 }
190 } 192 }
191 } 193 }
192 194
193 return -1; 195 return -1;
194 } 196 }
195 197
196 int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName, 198 int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 231
230 m_aData.Add(pNewData); 232 m_aData.Add(pNewData);
231 233
232 return m_aData.GetSize() - 1; 234 return m_aData.GetSize() - 1;
233 } 235 }
234 236
235 void CPWL_FontMap::AddedFont(CPDF_Font* pFont, 237 void CPWL_FontMap::AddedFont(CPDF_Font* pFont,
236 const CFX_ByteString& sFontAlias) {} 238 const CFX_ByteString& sFontAlias) {}
237 239
238 CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) { 240 CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) {
239 if (nCharset == DEFAULT_CHARSET) 241 if (nCharset == FXFONT_DEFAULT_CHARSET)
240 nCharset = GetNativeCharset(); 242 nCharset = GetNativeCharset();
241 243
242 CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset); 244 CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset);
243 if (m_pSystemHandler->FindNativeTrueTypeFont(sFontName)) 245 if (m_pSystemHandler->FindNativeTrueTypeFont(sFontName))
244 return sFontName; 246 return sFontName;
245 247
246 sFontName.clear(); 248 sFontName.clear();
247 return sFontName; 249 return sFontName;
248 } 250 }
249 251
(...skipping 24 matching lines...) Expand all
274 } 276 }
275 277
276 CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc, 278 CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc,
277 CFX_ByteString& sFontName, 279 CFX_ByteString& sFontName,
278 uint8_t nCharset) { 280 uint8_t nCharset) {
279 if (!pDoc) 281 if (!pDoc)
280 return nullptr; 282 return nullptr;
281 283
282 if (sFontName.IsEmpty()) 284 if (sFontName.IsEmpty())
283 sFontName = GetNativeFont(nCharset); 285 sFontName = GetNativeFont(nCharset);
284 if (nCharset == DEFAULT_CHARSET) 286 if (nCharset == FXFONT_DEFAULT_CHARSET)
285 nCharset = GetNativeCharset(); 287 nCharset = GetNativeCharset();
286 288
287 return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName, 289 return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName,
288 nCharset); 290 nCharset);
289 } 291 }
290 292
291 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName, 293 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName,
292 int32_t nCharset) { 294 int32_t nCharset) {
293 CFX_ByteString sPostfix; 295 CFX_ByteString sPostfix;
294 sPostfix.Format("_%02X", nCharset); 296 sPostfix.Format("_%02X", nCharset);
295 return EncodeFontAlias(sFontName) + sPostfix; 297 return EncodeFontAlias(sFontName) + sPostfix;
296 } 298 }
297 299
298 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) { 300 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) {
299 CFX_ByteString sRet = sFontName; 301 CFX_ByteString sRet = sFontName;
300 sRet.Remove(' '); 302 sRet.Remove(' ');
301 return sRet; 303 return sRet;
302 } 304 }
303 305
304 const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const { 306 const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const {
305 if (nIndex >= 0 && nIndex < m_aData.GetSize()) { 307 if (nIndex >= 0 && nIndex < m_aData.GetSize()) {
306 return m_aData.GetAt(nIndex); 308 return m_aData.GetAt(nIndex);
307 } 309 }
308 310
309 return nullptr; 311 return nullptr;
310 } 312 }
311 313
312 int32_t CPWL_FontMap::GetNativeCharset() { 314 int32_t CPWL_FontMap::GetNativeCharset() {
313 uint8_t nCharset = ANSI_CHARSET; 315 uint8_t nCharset = FXFONT_ANSI_CHARSET;
314 int32_t iCodePage = FXSYS_GetACP(); 316 int32_t iCodePage = FXSYS_GetACP();
315 switch (iCodePage) { 317 switch (iCodePage) {
316 case 932: // Japan 318 case 932: // Japan
317 nCharset = SHIFTJIS_CHARSET; 319 nCharset = FXFONT_SHIFTJIS_CHARSET;
318 break; 320 break;
319 case 936: // Chinese (PRC, Singapore) 321 case 936: // Chinese (PRC, Singapore)
320 nCharset = GB2312_CHARSET; 322 nCharset = FXFONT_GB2312_CHARSET;
321 break; 323 break;
322 case 950: // Chinese (Taiwan; Hong Kong SAR, PRC) 324 case 950: // Chinese (Taiwan; Hong Kong SAR, PRC)
323 nCharset = GB2312_CHARSET; 325 nCharset = FXFONT_GB2312_CHARSET;
324 break; 326 break;
325 case 1252: // Windows 3.1 Latin 1 (US, Western Europe) 327 case 1252: // Windows 3.1 Latin 1 (US, Western Europe)
326 nCharset = ANSI_CHARSET; 328 nCharset = FXFONT_ANSI_CHARSET;
327 break; 329 break;
328 case 874: // Thai 330 case 874: // Thai
329 nCharset = THAI_CHARSET; 331 nCharset = FXFONT_THAI_CHARSET;
330 break; 332 break;
331 case 949: // Korean 333 case 949: // Korean
332 nCharset = HANGUL_CHARSET; 334 nCharset = FXFONT_HANGUL_CHARSET;
333 break; 335 break;
334 case 1200: // Unicode (BMP of ISO 10646) 336 case 1200: // Unicode (BMP of ISO 10646)
335 nCharset = ANSI_CHARSET; 337 nCharset = FXFONT_ANSI_CHARSET;
336 break; 338 break;
337 case 1250: // Windows 3.1 Eastern European 339 case 1250: // Windows 3.1 Eastern European
338 nCharset = EASTEUROPE_CHARSET; 340 nCharset = FXFONT_EASTEUROPE_CHARSET;
339 break; 341 break;
340 case 1251: // Windows 3.1 Cyrillic 342 case 1251: // Windows 3.1 Cyrillic
341 nCharset = RUSSIAN_CHARSET; 343 nCharset = FXFONT_RUSSIAN_CHARSET;
342 break; 344 break;
343 case 1253: // Windows 3.1 Greek 345 case 1253: // Windows 3.1 Greek
344 nCharset = GREEK_CHARSET; 346 nCharset = FXFONT_GREEK_CHARSET;
345 break; 347 break;
346 case 1254: // Windows 3.1 Turkish 348 case 1254: // Windows 3.1 Turkish
347 nCharset = TURKISH_CHARSET; 349 nCharset = FXFONT_TURKISH_CHARSET;
348 break; 350 break;
349 case 1255: // Hebrew 351 case 1255: // Hebrew
350 nCharset = HEBREW_CHARSET; 352 nCharset = FXFONT_HEBREW_CHARSET;
351 break; 353 break;
352 case 1256: // Arabic 354 case 1256: // Arabic
353 nCharset = ARABIC_CHARSET; 355 nCharset = FXFONT_ARABIC_CHARSET;
354 break; 356 break;
355 case 1257: // Baltic 357 case 1257: // Baltic
356 nCharset = BALTIC_CHARSET; 358 nCharset = FXFONT_BALTIC_CHARSET;
357 break; 359 break;
358 case 1258: // Vietnamese 360 case 1258: // Vietnamese
359 nCharset = VIETNAMESE_CHARSET; 361 nCharset = FXFONT_VIETNAMESE_CHARSET;
360 break; 362 break;
361 case 1361: // Korean(Johab) 363 case 1361: // Korean(Johab)
362 nCharset = JOHAB_CHARSET; 364 nCharset = FXFONT_JOHAB_CHARSET;
363 break; 365 break;
364 } 366 }
365 return nCharset; 367 return nCharset;
366 } 368 }
367 369
368 const FPDF_CharsetFontMap CPWL_FontMap::defaultTTFMap[] = { 370 const FPDF_CharsetFontMap CPWL_FontMap::defaultTTFMap[] = {
369 {ANSI_CHARSET, "Helvetica"}, {GB2312_CHARSET, "SimSun"}, 371 {FXFONT_ANSI_CHARSET, "Helvetica"},
370 {CHINESEBIG5_CHARSET, "MingLiU"}, {SHIFTJIS_CHARSET, "MS Gothic"}, 372 {FXFONT_GB2312_CHARSET, "SimSun"},
371 {HANGUL_CHARSET, "Batang"}, {RUSSIAN_CHARSET, "Arial"}, 373 {FXFONT_CHINESEBIG5_CHARSET, "MingLiU"},
374 {FXFONT_SHIFTJIS_CHARSET, "MS Gothic"},
375 {FXFONT_HANGUL_CHARSET, "Batang"},
376 {FXFONT_RUSSIAN_CHARSET, "Arial"},
372 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ 377 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \
373 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 378 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
374 {EASTEUROPE_CHARSET, "Arial"}, 379 {FXFONT_EASTEUROPE_CHARSET, "Arial"},
375 #else 380 #else
376 {EASTEUROPE_CHARSET, "Tahoma"}, 381 {FXFONT_EASTEUROPE_CHARSET, "Tahoma"},
377 #endif 382 #endif
378 {ARABIC_CHARSET, "Arial"}, {-1, nullptr}}; 383 {FXFONT_ARABIC_CHARSET, "Arial"},
384 {-1, nullptr}};
379 385
380 CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) { 386 CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) {
381 int i = 0; 387 int i = 0;
382 while (defaultTTFMap[i].charset != -1) { 388 while (defaultTTFMap[i].charset != -1) {
383 if (nCharset == defaultTTFMap[i].charset) 389 if (nCharset == defaultTTFMap[i].charset)
384 return defaultTTFMap[i].fontname; 390 return defaultTTFMap[i].fontname;
385 ++i; 391 ++i;
386 } 392 }
387 return ""; 393 return "";
388 } 394 }
389 395
390 int32_t CPWL_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) { 396 int32_t CPWL_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) {
391 // to avoid CJK Font to show ASCII 397 // to avoid CJK Font to show ASCII
392 if (word < 0x7F) 398 if (word < 0x7F)
393 return ANSI_CHARSET; 399 return FXFONT_ANSI_CHARSET;
394 // follow the old charset 400 // follow the old charset
395 if (nOldCharset != DEFAULT_CHARSET) 401 if (nOldCharset != FXFONT_DEFAULT_CHARSET)
396 return nOldCharset; 402 return nOldCharset;
397 403
398 // find new charset 404 // find new charset
399 if ((word >= 0x4E00 && word <= 0x9FA5) || 405 if ((word >= 0x4E00 && word <= 0x9FA5) ||
400 (word >= 0xE7C7 && word <= 0xE7F3) || 406 (word >= 0xE7C7 && word <= 0xE7F3) ||
401 (word >= 0x3000 && word <= 0x303F) || 407 (word >= 0x3000 && word <= 0x303F) ||
402 (word >= 0x2000 && word <= 0x206F)) { 408 (word >= 0x2000 && word <= 0x206F)) {
403 return GB2312_CHARSET; 409 return FXFONT_GB2312_CHARSET;
404 } 410 }
405 411
406 if (((word >= 0x3040) && (word <= 0x309F)) || 412 if (((word >= 0x3040) && (word <= 0x309F)) ||
407 ((word >= 0x30A0) && (word <= 0x30FF)) || 413 ((word >= 0x30A0) && (word <= 0x30FF)) ||
408 ((word >= 0x31F0) && (word <= 0x31FF)) || 414 ((word >= 0x31F0) && (word <= 0x31FF)) ||
409 ((word >= 0xFF00) && (word <= 0xFFEF))) { 415 ((word >= 0xFF00) && (word <= 0xFFEF))) {
410 return SHIFTJIS_CHARSET; 416 return FXFONT_SHIFTJIS_CHARSET;
411 } 417 }
412 418
413 if (((word >= 0xAC00) && (word <= 0xD7AF)) || 419 if (((word >= 0xAC00) && (word <= 0xD7AF)) ||
414 ((word >= 0x1100) && (word <= 0x11FF)) || 420 ((word >= 0x1100) && (word <= 0x11FF)) ||
415 ((word >= 0x3130) && (word <= 0x318F))) { 421 ((word >= 0x3130) && (word <= 0x318F))) {
416 return HANGUL_CHARSET; 422 return FXFONT_HANGUL_CHARSET;
417 } 423 }
418 424
419 if (word >= 0x0E00 && word <= 0x0E7F) 425 if (word >= 0x0E00 && word <= 0x0E7F)
420 return THAI_CHARSET; 426 return FXFONT_THAI_CHARSET;
421 427
422 if ((word >= 0x0370 && word <= 0x03FF) || (word >= 0x1F00 && word <= 0x1FFF)) 428 if ((word >= 0x0370 && word <= 0x03FF) || (word >= 0x1F00 && word <= 0x1FFF))
423 return GREEK_CHARSET; 429 return FXFONT_GREEK_CHARSET;
424 430
425 if ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC)) 431 if ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
426 return ARABIC_CHARSET; 432 return FXFONT_ARABIC_CHARSET;
427 433
428 if (word >= 0x0590 && word <= 0x05FF) 434 if (word >= 0x0590 && word <= 0x05FF)
429 return HEBREW_CHARSET; 435 return FXFONT_HEBREW_CHARSET;
430 436
431 if (word >= 0x0400 && word <= 0x04FF) 437 if (word >= 0x0400 && word <= 0x04FF)
432 return RUSSIAN_CHARSET; 438 return FXFONT_RUSSIAN_CHARSET;
433 439
434 if (word >= 0x0100 && word <= 0x024F) 440 if (word >= 0x0100 && word <= 0x024F)
435 return EASTEUROPE_CHARSET; 441 return FXFONT_EASTEUROPE_CHARSET;
436 442
437 if (word >= 0x1E00 && word <= 0x1EFF) 443 if (word >= 0x1E00 && word <= 0x1EFF)
438 return VIETNAMESE_CHARSET; 444 return FXFONT_VIETNAMESE_CHARSET;
439 445
440 return ANSI_CHARSET; 446 return FXFONT_ANSI_CHARSET;
441 } 447 }
OLDNEW
« no previous file with comments | « fpdfsdk/pdfwindow/PWL_FontMap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698