OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/fpdfapi/fpdf_font/cpdf_simplefont.h" | 7 #include "core/fpdfapi/fpdf_font/cpdf_simplefont.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_font/font_int.h" | 9 #include "core/fpdfapi/fpdf_font/font_int.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
12 #include "core/include/fxge/fx_freetype.h" | 12 #include "core/include/fxge/fx_freetype.h" |
13 | 13 |
14 CPDF_SimpleFont::CPDF_SimpleFont() | 14 CPDF_SimpleFont::CPDF_SimpleFont() |
15 : m_pCharNames(nullptr), m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) { | 15 : m_pCharNames(nullptr), m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) { |
16 FXSYS_memset(m_CharWidth, 0xff, sizeof m_CharWidth); | 16 FXSYS_memset(m_CharWidth, 0xff, sizeof m_CharWidth); |
17 FXSYS_memset(m_GlyphIndex, 0xff, sizeof m_GlyphIndex); | 17 FXSYS_memset(m_GlyphIndex, 0xff, sizeof m_GlyphIndex); |
18 FXSYS_memset(m_ExtGID, 0xff, sizeof m_ExtGID); | 18 FXSYS_memset(m_ExtGID, 0xff, sizeof m_ExtGID); |
19 } | 19 } |
20 | 20 |
21 CPDF_SimpleFont::~CPDF_SimpleFont() { | 21 CPDF_SimpleFont::~CPDF_SimpleFont() { |
22 delete[] m_pCharNames; | 22 delete[] m_pCharNames; |
23 } | 23 } |
24 | 24 |
25 int CPDF_SimpleFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph) { | 25 int CPDF_SimpleFont::GlyphFromCharCode(uint32_t charcode, FX_BOOL* pVertGlyph) { |
26 if (pVertGlyph) { | 26 if (pVertGlyph) { |
27 *pVertGlyph = FALSE; | 27 *pVertGlyph = FALSE; |
28 } | 28 } |
29 if (charcode > 0xff) { | 29 if (charcode > 0xff) { |
30 return -1; | 30 return -1; |
31 } | 31 } |
32 int index = m_GlyphIndex[(uint8_t)charcode]; | 32 int index = m_GlyphIndex[(uint8_t)charcode]; |
33 if (index == 0xffff) { | 33 if (index == 0xffff) { |
34 return -1; | 34 return -1; |
35 } | 35 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 m_CharWidth[charcode] = TT_Width; | 75 m_CharWidth[charcode] = TT_Width; |
76 } else if (TT_Width && !IsEmbedded()) { | 76 } else if (TT_Width && !IsEmbedded()) { |
77 m_CharBBox[charcode].right = | 77 m_CharBBox[charcode].right = |
78 m_CharBBox[charcode].right * m_CharWidth[charcode] / TT_Width; | 78 m_CharBBox[charcode].right * m_CharWidth[charcode] / TT_Width; |
79 m_CharBBox[charcode].left = | 79 m_CharBBox[charcode].left = |
80 m_CharBBox[charcode].left * m_CharWidth[charcode] / TT_Width; | 80 m_CharBBox[charcode].left * m_CharWidth[charcode] / TT_Width; |
81 } | 81 } |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 int CPDF_SimpleFont::GetCharWidthF(FX_DWORD charcode, int level) { | 85 int CPDF_SimpleFont::GetCharWidthF(uint32_t charcode, int level) { |
86 if (charcode > 0xff) { | 86 if (charcode > 0xff) { |
87 charcode = 0; | 87 charcode = 0; |
88 } | 88 } |
89 if (m_CharWidth[charcode] == 0xffff) { | 89 if (m_CharWidth[charcode] == 0xffff) { |
90 LoadCharMetrics(charcode); | 90 LoadCharMetrics(charcode); |
91 if (m_CharWidth[charcode] == 0xffff) { | 91 if (m_CharWidth[charcode] == 0xffff) { |
92 m_CharWidth[charcode] = 0; | 92 m_CharWidth[charcode] = 0; |
93 } | 93 } |
94 } | 94 } |
95 return (int16_t)m_CharWidth[charcode]; | 95 return (int16_t)m_CharWidth[charcode]; |
96 } | 96 } |
97 | 97 |
98 FX_RECT CPDF_SimpleFont::GetCharBBox(FX_DWORD charcode, int level) { | 98 FX_RECT CPDF_SimpleFont::GetCharBBox(uint32_t charcode, int level) { |
99 if (charcode > 0xff) | 99 if (charcode > 0xff) |
100 charcode = 0; | 100 charcode = 0; |
101 | 101 |
102 if (m_CharBBox[charcode].left == FX_SMALL_RECT::kInvalid) | 102 if (m_CharBBox[charcode].left == FX_SMALL_RECT::kInvalid) |
103 LoadCharMetrics(charcode); | 103 LoadCharMetrics(charcode); |
104 | 104 |
105 return FX_RECT(m_CharBBox[charcode]); | 105 return FX_RECT(m_CharBBox[charcode]); |
106 } | 106 } |
107 | 107 |
108 FX_BOOL CPDF_SimpleFont::LoadCommon() { | 108 FX_BOOL CPDF_SimpleFont::LoadCommon() { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 if (m_Font.GetSubstFont()->m_SubstFlags & FXFONT_SUBST_NONSYMBOL) { | 197 if (m_Font.GetSubstFont()->m_SubstFlags & FXFONT_SUBST_NONSYMBOL) { |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const { | 201 FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const { |
202 return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN && | 202 return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN && |
203 m_BaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL && | 203 m_BaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL && |
204 m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS; | 204 m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS; |
205 } | 205 } |
206 | 206 |
207 CFX_WideString CPDF_SimpleFont::UnicodeFromCharCode(FX_DWORD charcode) const { | 207 CFX_WideString CPDF_SimpleFont::UnicodeFromCharCode(uint32_t charcode) const { |
208 CFX_WideString unicode = CPDF_Font::UnicodeFromCharCode(charcode); | 208 CFX_WideString unicode = CPDF_Font::UnicodeFromCharCode(charcode); |
209 if (!unicode.IsEmpty()) | 209 if (!unicode.IsEmpty()) |
210 return unicode; | 210 return unicode; |
211 FX_WCHAR ret = m_Encoding.UnicodeFromCharCode((uint8_t)charcode); | 211 FX_WCHAR ret = m_Encoding.UnicodeFromCharCode((uint8_t)charcode); |
212 if (ret == 0) | 212 if (ret == 0) |
213 return CFX_WideString(); | 213 return CFX_WideString(); |
214 return ret; | 214 return ret; |
215 } | 215 } |
216 | 216 |
217 FX_DWORD CPDF_SimpleFont::CharCodeFromUnicode(FX_WCHAR unicode) const { | 217 uint32_t CPDF_SimpleFont::CharCodeFromUnicode(FX_WCHAR unicode) const { |
218 FX_DWORD ret = CPDF_Font::CharCodeFromUnicode(unicode); | 218 uint32_t ret = CPDF_Font::CharCodeFromUnicode(unicode); |
219 if (ret) | 219 if (ret) |
220 return ret; | 220 return ret; |
221 return m_Encoding.CharCodeFromUnicode(unicode); | 221 return m_Encoding.CharCodeFromUnicode(unicode); |
222 } | 222 } |
OLD | NEW |