OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "core/fxge/include/cfx_unicodeencodingex.h" | |
8 | |
9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | |
10 #include "core/fxge/include/fx_font.h" | |
11 #include "core/fxge/include/fx_freetype.h" | |
12 | |
13 #ifdef PDF_ENABLE_XFA | |
dsinclair
2016/08/18 15:14:52
Instead of wrapping the whole file in an ENABLE_XF
npm
2016/08/18 17:36:41
Done.
| |
14 | |
15 const uint32_t g_EncodingID[] = { | |
dsinclair
2016/08/18 15:14:52
Move into an anonymous namespace.
npm
2016/08/18 17:36:41
Done.
| |
16 FXFM_ENCODING_MS_SYMBOL, FXFM_ENCODING_UNICODE, | |
17 FXFM_ENCODING_MS_SJIS, FXFM_ENCODING_MS_GB2312, | |
18 FXFM_ENCODING_MS_BIG5, FXFM_ENCODING_MS_WANSUNG, | |
19 FXFM_ENCODING_MS_JOHAB, FXFM_ENCODING_ADOBE_STANDARD, | |
20 FXFM_ENCODING_ADOBE_EXPERT, FXFM_ENCODING_ADOBE_CUSTOM, | |
21 FXFM_ENCODING_ADOBE_LATIN_1, FXFM_ENCODING_OLD_LATIN_2, | |
22 FXFM_ENCODING_APPLE_ROMAN, | |
23 }; | |
24 | |
25 CFX_UnicodeEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont, | |
dsinclair
2016/08/18 15:14:52
Remove _ prefix as it's reserved by the compiler.
npm
2016/08/18 17:36:41
Done.
| |
26 uint32_t nEncodingID) { | |
27 if (FXFT_Select_Charmap(pFont->GetFace(), nEncodingID)) | |
28 return nullptr; | |
29 return new CFX_UnicodeEncodingEx(pFont, nEncodingID); | |
30 } | |
31 | |
32 CFX_UnicodeEncodingEx::CFX_UnicodeEncodingEx(CFX_Font* pFont, | |
33 uint32_t EncodingID) | |
34 : CFX_UnicodeEncoding(pFont), m_nEncodingID(EncodingID) {} | |
35 | |
36 CFX_UnicodeEncodingEx::~CFX_UnicodeEncodingEx() {} | |
37 | |
38 uint32_t CFX_UnicodeEncodingEx::GlyphFromCharCode(uint32_t charcode) { | |
39 FXFT_Face face = m_pFont->GetFace(); | |
40 FT_UInt nIndex = FXFT_Get_Char_Index(face, charcode); | |
41 if (nIndex > 0) { | |
42 return nIndex; | |
43 } | |
dsinclair
2016/08/18 15:14:52
nit: {}'s
npm
2016/08/18 17:36:41
Done.
| |
44 int nmaps = FXFT_Get_Face_CharmapCount(face); | |
45 int m = 0; | |
46 while (m < nmaps) { | |
47 uint32_t nEncodingID = | |
48 FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[m++]); | |
49 if (m_nEncodingID == nEncodingID) { | |
50 continue; | |
51 } | |
52 int error = FXFT_Select_Charmap(face, nEncodingID); | |
53 if (error) { | |
54 continue; | |
55 } | |
56 nIndex = FXFT_Get_Char_Index(face, charcode); | |
57 if (nIndex > 0) { | |
58 m_nEncodingID = nEncodingID; | |
59 return nIndex; | |
60 } | |
61 } | |
62 FXFT_Select_Charmap(face, m_nEncodingID); | |
63 return 0; | |
64 } | |
65 | |
66 uint32_t CFX_UnicodeEncodingEx::CharCodeFromUnicode(FX_WCHAR Unicode) const { | |
67 if (m_nEncodingID == FXFM_ENCODING_UNICODE || | |
68 m_nEncodingID == FXFM_ENCODING_MS_SYMBOL) { | |
69 return Unicode; | |
70 } | |
71 FXFT_Face face = m_pFont->GetFace(); | |
72 int nmaps = FXFT_Get_Face_CharmapCount(face); | |
73 for (int i = 0; i < nmaps; i++) { | |
74 int nEncodingID = | |
75 FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[i]); | |
76 if (nEncodingID == FXFM_ENCODING_UNICODE || | |
77 nEncodingID == FXFM_ENCODING_MS_SYMBOL) { | |
78 return Unicode; | |
79 } | |
80 } | |
81 return CPDF_Font::kInvalidCharCode; | |
82 } | |
83 | |
84 CFX_UnicodeEncodingEx* FX_CreateFontEncodingEx(CFX_Font* pFont, | |
85 uint32_t nEncodingID) { | |
86 if (!pFont || !pFont->GetFace()) | |
87 return nullptr; | |
88 | |
89 if (nEncodingID != FXFM_ENCODING_NONE) | |
90 return _FXFM_CreateFontEncoding(pFont, nEncodingID); | |
91 | |
92 for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) { | |
93 CFX_UnicodeEncodingEx* pFontEncoding = | |
94 _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]); | |
95 if (pFontEncoding) { | |
96 return pFontEncoding; | |
97 } | |
98 } | |
99 return nullptr; | |
100 } | |
101 | |
102 #endif // PDF_ENABLE_XFA | |
OLD | NEW |