7#include "core/fpdfapi/font/cpdf_simplefont.h"
13#include "constants/font_encodings.h"
14#include "core/fpdfapi/parser/cpdf_array.h"
15#include "core/fpdfapi/parser/cpdf_dictionary.h"
16#include "core/fpdfapi/parser/cpdf_name.h"
17#include "core/fxcrt/fx_codepage.h"
18#include "core/fxge/freetype/fx_freetype.h"
19#include "core/fxge/fx_font.h"
23void GetPredefinedEncoding(
const ByteString& value,
FontEncoding* basemap) {
39 memset(m_CharWidth, 0xff,
sizeof(m_CharWidth));
40 memset(m_GlyphIndex, 0xff,
sizeof(m_GlyphIndex));
41 for (size_t i = 0; i < std::size(m_CharBBox); ++i)
42 m_CharBBox[i] = FX_RECT(-1, -1, -1, -1);
54 int index = m_GlyphIndex[charcode];
62 if (!m_Font.GetFaceRec())
65 if (charcode < 0 || charcode > 0xff) {
68 int glyph_index = m_GlyphIndex[charcode];
69 if (glyph_index == 0xffff) {
70 if (!m_pFontFile && charcode != 32) {
72 m_CharBBox[charcode] = m_CharBBox[32];
74 m_CharWidth[charcode] = m_CharWidth[32];
79 RetainPtr<CFX_Face> face = m_Font.GetFace();
84 FXFT_FaceRec* face_rec = face->GetRec();
86 FT_Load_Glyph(face_rec, glyph_index,
87 FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
91 m_CharBBox[charcode] = GetCharBBoxForFace(face);
95 if (m_CharWidth[charcode] == 0xffff) {
96 m_CharWidth[charcode] = TT_Width;
98 m_CharBBox[charcode].right =
99 m_CharBBox[charcode].right * m_CharWidth[charcode] / TT_Width;
100 m_CharBBox[charcode].left =
101 m_CharBBox[charcode].left * m_CharWidth[charcode] / TT_Width;
107 RetainPtr<
const CPDF_Array> width_array = m_pFontDict->GetArrayFor(
"Widths");
114 std::fill(std::begin(m_CharWidth), std::end(m_CharWidth), missing_width);
117 size_t width_start = m_pFontDict->GetIntegerFor(
"FirstChar", 0);
118 size_t width_end = m_pFontDict->GetIntegerFor(
"LastChar", 0);
119 if (width_start > 255)
122 if (width_end == 0 || width_end >= width_start + width_array->size())
123 width_end = width_start + width_array->size() - 1;
126 for (size_t i = width_start; i <= width_end; i++)
127 m_CharWidth[i] = width_array->GetIntegerAt(i - width_start);
131 RetainPtr<
const CPDF_Array> diffs = encoding->GetArrayFor(
"Differences");
135 m_CharNames.resize(kInternalTableSize);
136 uint32_t cur_code = 0;
137 for (uint32_t i = 0; i < diffs->size(); i++) {
142 const CPDF_Name* name = element->AsName();
144 if (cur_code < m_CharNames.size())
145 m_CharNames[cur_code] = name->GetString();
148 cur_code = element->GetInteger();
155 m_pFontDict->GetDirectObjectFor(
"Encoding");
157 if (m_BaseFontName ==
"Symbol") {
165 if (pEncoding->IsName()) {
170 if (FontStyleIsSymbolic(m_Flags) && m_BaseFontName ==
"Symbol") {
175 ByteString bsEncoding = pEncoding->GetString();
182 const CPDF_Dictionary* pDict = pEncoding->AsDictionary();
203 if (m_CharWidth[charcode] == 0xffff) {
205 if (m_CharWidth[charcode] == 0xffff) {
206 m_CharWidth[charcode] = 0;
209 return m_CharWidth[charcode];
216 if (m_CharBBox[charcode].left == -1)
219 return m_CharBBox[charcode];
223 RetainPtr<
const CPDF_Dictionary> pFontDesc =
224 m_pFontDict->GetDictFor(
"FontDescriptor");
229 if (m_BaseFontName.GetLength() > 7 && m_BaseFontName[6] ==
'+') {
230 m_BaseFontName = m_BaseFontName.Last(m_BaseFontName.GetLength() - 7);
237 LoadPDFEncoding(!!m_pFontFile, m_Font.IsTTFont());
245 static const unsigned char kLowercases[][2] = {
246 {
'a',
'z'}, {0xe0, 0xf6}, {0xf8, 0xfd}};
247 for (size_t range = 0; range <
std::size(kLowercases); ++range) {
248 const auto& lower = kLowercases[range];
249 for (
int i = lower[0]; i <= lower[1]; ++i) {
250 if (m_GlyphIndex[i] != 0xffff && m_pFontFile)
254 m_GlyphIndex[i] = m_GlyphIndex[j];
255 if (m_CharWidth[j]) {
256 m_CharWidth[i] = m_CharWidth[j];
257 m_CharBBox[i] = m_CharBBox[j];
270 for (i = 0; i < kInternalTableSize; i++) {
271 if (m_CharWidth[i] == 0 || m_CharWidth[i] == 0xffff)
275 width = m_CharWidth[i];
276 else if (width != m_CharWidth[i])
279 if (i == kInternalTableSize && width)
282 m_Font.LoadSubst(m_BaseFontName, IsTrueTypeFont(), m_Flags, GetFontWeight(),
283 m_ItalicAngle, FX_CodePage::kDefANSI,
false);
296 wchar_t ret = m_Encoding.UnicodeFromCharCode((uint8_t)charcode);
299 return WideString
(ret
);
306 return m_Encoding.CharCodeFromUnicode(unicode);
bool KeyExist(const ByteString &key) const
int GetIntegerFor(const ByteString &key) const
ByteString GetByteStringFor(const ByteString &key) const
void LoadFontDescriptor(const CPDF_Dictionary *pFontDesc)
virtual uint32_t CharCodeFromUnicode(wchar_t Unicode) const
virtual WideString UnicodeFromCharCode(uint32_t charcode) const
CPDF_SimpleFont(CPDF_Document *pDocument, RetainPtr< CPDF_Dictionary > pFontDict)
~CPDF_SimpleFont() override
int GlyphFromCharCode(uint32_t charcode, bool *pVertGlyph) override
int GetCharWidthF(uint32_t charcode) override
void LoadCharMetrics(int charcode)
uint32_t CharCodeFromUnicode(wchar_t Unicode) const override
bool IsUnicodeCompatible() const override
void LoadCharWidths(const CPDF_Dictionary *font_desc)
FX_RECT GetCharBBox(uint32_t charcode) override
void LoadPDFEncoding(bool bEmbedded, bool bTrueType)
FontEncoding m_BaseEncoding
bool HasFontWidths() const override
void LoadDifferences(const CPDF_Dictionary *encoding)
WideString UnicodeFromCharCode(uint32_t charcode) const override
virtual void LoadGlyphMap()=0
bool operator==(const char *ptr) const
ByteString & operator=(const char *str)
bool FontStyleIsFixedPitch(uint32_t style)
bool FontStyleIsSymbolic(uint32_t style)
bool FontStyleIsAllCaps(uint32_t style)
#define FXFONT_FIXED_PITCH
#define FXFT_Get_Glyph_HoriAdvance(face)
const char kMacExpertEncoding[]
const char kPDFDocEncoding[]
const char kWinAnsiEncoding[]
const char kMacRomanEncoding[]