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 #ifndef CORE_FPDFAPI_FPDF_FONT_CPDF_FONT_H_ | |
8 #define CORE_FPDFAPI_FPDF_FONT_CPDF_FONT_H_ | |
9 | |
10 #include <memory> | |
11 #include <vector> | |
12 | |
13 #include "core/fxcrt/fx_string.h" | |
14 #include "core/fxcrt/fx_system.h" | |
15 #include "core/fxge/fx_font.h" | |
16 | |
17 #define PDFFONT_FIXEDPITCH 1 | |
18 #define PDFFONT_SERIF 2 | |
19 #define PDFFONT_SYMBOLIC 4 | |
20 #define PDFFONT_SCRIPT 8 | |
21 #define PDFFONT_NONSYMBOLIC 32 | |
22 #define PDFFONT_ITALIC 64 | |
23 #define PDFFONT_ALLCAP 0x10000 | |
24 #define PDFFONT_SMALLCAP 0x20000 | |
25 #define PDFFONT_FORCEBOLD 0x40000 | |
26 #define PDFFONT_USEEXTERNATTR 0x80000 | |
27 | |
28 class CFX_SubstFont; | |
29 class CPDF_CIDFont; | |
30 class CPDF_Dictionary; | |
31 class CPDF_Document; | |
32 class CPDF_Object; | |
33 class CPDF_StreamAcc; | |
34 class CPDF_TrueTypeFont; | |
35 class CPDF_Type1Font; | |
36 class CPDF_Type3Font; | |
37 class CPDF_ToUnicodeMap; | |
38 | |
39 class CPDF_Font { | |
40 public: | |
41 static std::unique_ptr<CPDF_Font> Create(CPDF_Document* pDoc, | |
42 CPDF_Dictionary* pFontDict); | |
43 static CPDF_Font* GetStockFont(CPDF_Document* pDoc, | |
44 const CFX_ByteStringC& fontname); | |
45 static const uint32_t kInvalidCharCode = static_cast<uint32_t>(-1); | |
46 | |
47 virtual ~CPDF_Font(); | |
48 | |
49 virtual bool IsType1Font() const; | |
50 virtual bool IsTrueTypeFont() const; | |
51 virtual bool IsType3Font() const; | |
52 virtual bool IsCIDFont() const; | |
53 virtual const CPDF_Type1Font* AsType1Font() const; | |
54 virtual CPDF_Type1Font* AsType1Font(); | |
55 virtual const CPDF_TrueTypeFont* AsTrueTypeFont() const; | |
56 virtual CPDF_TrueTypeFont* AsTrueTypeFont(); | |
57 virtual const CPDF_Type3Font* AsType3Font() const; | |
58 virtual CPDF_Type3Font* AsType3Font(); | |
59 virtual const CPDF_CIDFont* AsCIDFont() const; | |
60 virtual CPDF_CIDFont* AsCIDFont(); | |
61 | |
62 virtual bool IsVertWriting() const; | |
63 virtual bool IsUnicodeCompatible() const; | |
64 virtual uint32_t GetNextChar(const FX_CHAR* pString, | |
65 int nStrLen, | |
66 int& offset) const; | |
67 virtual int CountChar(const FX_CHAR* pString, int size) const; | |
68 virtual int AppendChar(FX_CHAR* buf, uint32_t charcode) const; | |
69 virtual int GetCharSize(uint32_t charcode) const; | |
70 virtual int GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) = 0; | |
71 virtual int GlyphFromCharCodeExt(uint32_t charcode); | |
72 virtual CFX_WideString UnicodeFromCharCode(uint32_t charcode) const; | |
73 virtual uint32_t CharCodeFromUnicode(FX_WCHAR Unicode) const; | |
74 | |
75 const CFX_ByteString& GetBaseFont() const { return m_BaseFont; } | |
76 CFX_SubstFont* GetSubstFont() const { return m_Font.GetSubstFont(); } | |
77 uint32_t GetFlags() const { return m_Flags; } | |
78 bool IsEmbedded() const { return IsType3Font() || m_pFontFile != nullptr; } | |
79 CPDF_StreamAcc* GetFontFile() const { return m_pFontFile; } | |
80 CPDF_Dictionary* GetFontDict() const { return m_pFontDict; } | |
81 bool IsStandardFont() const; | |
82 FXFT_Face GetFace() const { return m_Font.GetFace(); } | |
83 void AppendChar(CFX_ByteString& str, uint32_t charcode) const; | |
84 | |
85 void GetFontBBox(FX_RECT& rect) const { rect = m_FontBBox; } | |
86 int GetTypeAscent() const { return m_Ascent; } | |
87 int GetTypeDescent() const { return m_Descent; } | |
88 int GetItalicAngle() const { return m_ItalicAngle; } | |
89 int GetStemV() const { return m_StemV; } | |
90 int GetStringWidth(const FX_CHAR* pString, int size); | |
91 uint32_t FallbackFontFromCharcode(uint32_t charcode); | |
92 int FallbackGlyphFromCharcode(int fallbackFont, uint32_t charcode); | |
93 | |
94 virtual int GetCharWidthF(uint32_t charcode) = 0; | |
95 virtual FX_RECT GetCharBBox(uint32_t charcode) = 0; | |
96 | |
97 CPDF_Document* m_pDocument; | |
98 CFX_Font m_Font; | |
99 std::vector<std::unique_ptr<CFX_Font>> m_FontFallbacks; | |
100 | |
101 protected: | |
102 CPDF_Font(); | |
103 | |
104 virtual bool Load() = 0; | |
105 | |
106 void LoadUnicodeMap() const; // logically const only. | |
107 void LoadPDFEncoding(CPDF_Object* pEncoding, | |
108 int& iBaseEncoding, | |
109 std::vector<CFX_ByteString>* pCharNames, | |
110 bool bEmbedded, | |
111 bool bTrueType); | |
112 void LoadFontDescriptor(CPDF_Dictionary* pDict); | |
113 void CheckFontMetrics(); | |
114 | |
115 const FX_CHAR* GetAdobeCharName(int iBaseEncoding, | |
116 const std::vector<CFX_ByteString>& charnames, | |
117 int charcode); | |
118 | |
119 CFX_ByteString m_BaseFont; | |
120 CPDF_StreamAcc* m_pFontFile; | |
121 CPDF_Dictionary* m_pFontDict; | |
122 mutable std::unique_ptr<CPDF_ToUnicodeMap> m_pToUnicodeMap; | |
123 mutable bool m_bToUnicodeLoaded; | |
124 int m_Flags; | |
125 FX_RECT m_FontBBox; | |
126 int m_StemV; | |
127 int m_Ascent; | |
128 int m_Descent; | |
129 int m_ItalicAngle; | |
130 }; | |
131 | |
132 #endif // CORE_FPDFAPI_FPDF_FONT_CPDF_FONT_H_ | |
OLD | NEW |