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

Side by Side Diff: core/fxge/ge/fx_ge_font.cpp

Issue 2260533002: Refactor fx_font part 2 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 4 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/fxge/include/fx_font.h" 7 #include "core/fxge/include/fx_font.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/fxge/ge/fx_text_int.h"
10 #include "core/fxge/include/cfx_fontmgr.h" 11 #include "core/fxge/include/cfx_fontmgr.h"
11 #include "core/fxge/ge/fx_text_int.h"
12 #include "core/fxge/include/cfx_gemodule.h" 12 #include "core/fxge/include/cfx_gemodule.h"
13 #include "core/fxge/include/fx_freetype.h" 13 #include "core/fxge/include/fx_freetype.h"
14 14
15 #define EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em) 15 #define EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em)
16 16
17 namespace { 17 namespace {
18 18
19 #ifdef PDF_ENABLE_XFA 19 #ifdef PDF_ENABLE_XFA
20 const uint32_t g_EncodingID[] = {
21 FXFM_ENCODING_MS_SYMBOL, FXFM_ENCODING_UNICODE,
22 FXFM_ENCODING_MS_SJIS, FXFM_ENCODING_MS_GB2312,
23 FXFM_ENCODING_MS_BIG5, FXFM_ENCODING_MS_WANSUNG,
24 FXFM_ENCODING_MS_JOHAB, FXFM_ENCODING_ADOBE_STANDARD,
25 FXFM_ENCODING_ADOBE_EXPERT, FXFM_ENCODING_ADOBE_CUSTOM,
26 FXFM_ENCODING_ADOBE_LATIN_1, FXFM_ENCODING_OLD_LATIN_2,
27 FXFM_ENCODING_APPLE_ROMAN,
28 };
29
30 CFX_UnicodeEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont,
31 uint32_t nEncodingID) {
32 if (FXFT_Select_Charmap(pFont->GetFace(), nEncodingID))
33 return nullptr;
34 return new CFX_UnicodeEncodingEx(pFont, nEncodingID);
35 }
36 20
37 unsigned long FTStreamRead(FXFT_Stream stream, 21 unsigned long FTStreamRead(FXFT_Stream stream,
38 unsigned long offset, 22 unsigned long offset,
39 unsigned char* buffer, 23 unsigned char* buffer,
40 unsigned long count) { 24 unsigned long count) {
41 if (count == 0) 25 if (count == 0)
42 return 0; 26 return 0;
43 27
44 IFX_FileRead* pFile = static_cast<IFX_FileRead*>(stream->descriptor.pointer); 28 IFX_FileRead* pFile = static_cast<IFX_FileRead*>(stream->descriptor.pointer);
45 return pFile->ReadBlock(buffer, offset, count) ? count : 0; 29 return pFile->ReadBlock(buffer, offset, count) ? count : 0;
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 FXFT_Get_Face_UnderLinePosition(m_Face)); 406 FXFT_Get_Face_UnderLinePosition(m_Face));
423 } 407 }
424 408
425 int CFX_Font::GetULthickness() const { 409 int CFX_Font::GetULthickness() const {
426 if (!m_Face) 410 if (!m_Face)
427 return 0; 411 return 0;
428 412
429 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), 413 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
430 FXFT_Get_Face_UnderLineThickness(m_Face)); 414 FXFT_Get_Face_UnderLineThickness(m_Face));
431 } 415 }
432
433 CFX_UnicodeEncoding::CFX_UnicodeEncoding(CFX_Font* pFont) : m_pFont(pFont) {}
434
435 CFX_UnicodeEncoding::~CFX_UnicodeEncoding() {}
436
437 uint32_t CFX_UnicodeEncoding::GlyphFromCharCode(uint32_t charcode) {
438 FXFT_Face face = m_pFont->GetFace();
439 if (!face)
440 return charcode;
441
442 if (FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE) == 0)
443 return FXFT_Get_Char_Index(face, charcode);
444
445 if (m_pFont->GetSubstFont() &&
446 m_pFont->GetSubstFont()->m_Charset == FXFONT_SYMBOL_CHARSET) {
447 uint32_t index = 0;
448 if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0)
449 index = FXFT_Get_Char_Index(face, charcode);
450 if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN))
451 return FXFT_Get_Char_Index(face, charcode);
452 }
453 return charcode;
454 }
455
456 #ifdef PDF_ENABLE_XFA
457 CFX_UnicodeEncodingEx::CFX_UnicodeEncodingEx(CFX_Font* pFont,
458 uint32_t EncodingID)
459 : CFX_UnicodeEncoding(pFont), m_nEncodingID(EncodingID) {}
460
461 CFX_UnicodeEncodingEx::~CFX_UnicodeEncodingEx() {}
462
463 uint32_t CFX_UnicodeEncodingEx::GlyphFromCharCode(uint32_t charcode) {
464 FXFT_Face face = m_pFont->GetFace();
465 FT_UInt nIndex = FXFT_Get_Char_Index(face, charcode);
466 if (nIndex > 0) {
467 return nIndex;
468 }
469 int nmaps = FXFT_Get_Face_CharmapCount(face);
470 int m = 0;
471 while (m < nmaps) {
472 uint32_t nEncodingID =
473 FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[m++]);
474 if (m_nEncodingID == nEncodingID) {
475 continue;
476 }
477 int error = FXFT_Select_Charmap(face, nEncodingID);
478 if (error) {
479 continue;
480 }
481 nIndex = FXFT_Get_Char_Index(face, charcode);
482 if (nIndex > 0) {
483 m_nEncodingID = nEncodingID;
484 return nIndex;
485 }
486 }
487 FXFT_Select_Charmap(face, m_nEncodingID);
488 return 0;
489 }
490
491 uint32_t CFX_UnicodeEncodingEx::CharCodeFromUnicode(FX_WCHAR Unicode) const {
492 if (m_nEncodingID == FXFM_ENCODING_UNICODE ||
493 m_nEncodingID == FXFM_ENCODING_MS_SYMBOL) {
494 return Unicode;
495 }
496 FXFT_Face face = m_pFont->GetFace();
497 int nmaps = FXFT_Get_Face_CharmapCount(face);
498 for (int i = 0; i < nmaps; i++) {
499 int nEncodingID =
500 FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[i]);
501 if (nEncodingID == FXFM_ENCODING_UNICODE ||
502 nEncodingID == FXFM_ENCODING_MS_SYMBOL) {
503 return Unicode;
504 }
505 }
506 return CPDF_Font::kInvalidCharCode;
507 }
508
509 CFX_UnicodeEncodingEx* FX_CreateFontEncodingEx(CFX_Font* pFont,
510 uint32_t nEncodingID) {
511 if (!pFont || !pFont->GetFace())
512 return nullptr;
513
514 if (nEncodingID != FXFM_ENCODING_NONE)
515 return _FXFM_CreateFontEncoding(pFont, nEncodingID);
516
517 for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) {
518 CFX_UnicodeEncodingEx* pFontEncoding =
519 _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]);
520 if (pFontEncoding) {
521 return pFontEncoding;
522 }
523 }
524 return nullptr;
525 }
526 #endif // PDF_ENABLE_XFA
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698