OLD | NEW |
| (Empty) |
1 // Copyright 2014 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_FXGE_INCLUDE_FX_FONT_H_ | |
8 #define CORE_FXGE_INCLUDE_FX_FONT_H_ | |
9 | |
10 #include <memory> | |
11 #include <vector> | |
12 | |
13 #include "core/fxcrt/fx_system.h" | |
14 #include "core/fxge/include/cfx_substfont.h" | |
15 #include "core/fxge/include/fx_dib.h" | |
16 #include "core/fxge/include/fx_freetype.h" | |
17 | |
18 typedef struct FT_FaceRec_* FXFT_Face; | |
19 typedef void* FXFT_Library; | |
20 | |
21 class CFX_FaceCache; | |
22 class CFX_GlyphBitmap; | |
23 class CFX_PathData; | |
24 class CFX_SizeGlyphCache; | |
25 | |
26 #ifdef _SKIA_SUPPORT_ | |
27 class SkTypeface; | |
28 | |
29 using CFX_TypeFace = SkTypeface; | |
30 #endif | |
31 | |
32 /* Character sets for the font */ | |
33 #define FXFONT_ANSI_CHARSET 0 | |
34 #define FXFONT_DEFAULT_CHARSET 1 | |
35 #define FXFONT_SYMBOL_CHARSET 2 | |
36 #define FXFONT_SHIFTJIS_CHARSET 128 | |
37 #define FXFONT_HANGUL_CHARSET 129 | |
38 #define FXFONT_GB2312_CHARSET 134 | |
39 #define FXFONT_CHINESEBIG5_CHARSET 136 | |
40 #define FXFONT_THAI_CHARSET 222 | |
41 #define FXFONT_EASTEUROPE_CHARSET 238 | |
42 #define FXFONT_RUSSIAN_CHARSET 204 | |
43 #define FXFONT_GREEK_CHARSET 161 | |
44 #define FXFONT_TURKISH_CHARSET 162 | |
45 #define FXFONT_HEBREW_CHARSET 177 | |
46 #define FXFONT_ARABIC_CHARSET 178 | |
47 #define FXFONT_BALTIC_CHARSET 186 | |
48 #define FXFONT_JOHAB_CHARSET 130 | |
49 #define FXFONT_VIETNAMESE_CHARSET 163 | |
50 | |
51 /* Font pitch and family flags */ | |
52 #define FXFONT_FF_FIXEDPITCH 1 | |
53 #define FXFONT_FF_ROMAN (1 << 4) | |
54 #define FXFONT_FF_SCRIPT (4 << 4) | |
55 | |
56 /* Typical weight values */ | |
57 #define FXFONT_FW_NORMAL 400 | |
58 #define FXFONT_FW_BOLD 700 | |
59 | |
60 /* Font styles */ | |
61 #define FXFONT_FIXED_PITCH 0x01 | |
62 #define FXFONT_SERIF 0x02 | |
63 #define FXFONT_SYMBOLIC 0x04 | |
64 #define FXFONT_SCRIPT 0x08 | |
65 #define FXFONT_ITALIC 0x40 | |
66 #define FXFONT_BOLD 0x40000 | |
67 #define FXFONT_USEEXTERNATTR 0x80000 | |
68 #define FXFONT_CIDFONT 0x100000 | |
69 #ifdef PDF_ENABLE_XFA | |
70 #define FXFONT_EXACTMATCH 0x80000000 | |
71 #endif // PDF_ENABLE_XFA | |
72 | |
73 #define CHARSET_FLAG_ANSI 1 | |
74 #define CHARSET_FLAG_SYMBOL 2 | |
75 #define CHARSET_FLAG_SHIFTJIS 4 | |
76 #define CHARSET_FLAG_BIG5 8 | |
77 #define CHARSET_FLAG_GB 16 | |
78 #define CHARSET_FLAG_KOREAN 32 | |
79 | |
80 #define GET_TT_SHORT(w) (uint16_t)(((w)[0] << 8) | (w)[1]) | |
81 #define GET_TT_LONG(w) \ | |
82 (uint32_t)(((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3]) | |
83 | |
84 // Sets the given transform on the font, and resets it to the identity when it | |
85 // goes out of scope. | |
86 class ScopedFontTransform { | |
87 public: | |
88 ScopedFontTransform(FT_Face face, FXFT_Matrix* matrix); | |
89 ~ScopedFontTransform(); | |
90 | |
91 private: | |
92 FT_Face m_Face; | |
93 }; | |
94 | |
95 class CFX_Font { | |
96 public: | |
97 CFX_Font(); | |
98 ~CFX_Font(); | |
99 | |
100 void LoadSubst(const CFX_ByteString& face_name, | |
101 FX_BOOL bTrueType, | |
102 uint32_t flags, | |
103 int weight, | |
104 int italic_angle, | |
105 int CharsetCP, | |
106 bool bVertical); | |
107 | |
108 FX_BOOL LoadEmbedded(const uint8_t* data, uint32_t size); | |
109 FXFT_Face GetFace() const { return m_Face; } | |
110 CFX_SubstFont* GetSubstFont() const { return m_pSubstFont.get(); } | |
111 | |
112 #ifdef PDF_ENABLE_XFA | |
113 FX_BOOL LoadFile(IFX_FileRead* pFile, | |
114 int nFaceIndex = 0, | |
115 int* pFaceCount = nullptr); | |
116 | |
117 FX_BOOL LoadClone(const CFX_Font* pFont); | |
118 void SetFace(FXFT_Face face); | |
119 void SetSubstFont(std::unique_ptr<CFX_SubstFont> subst) { | |
120 m_pSubstFont = std::move(subst); | |
121 } | |
122 #endif // PDF_ENABLE_XFA | |
123 | |
124 const CFX_GlyphBitmap* LoadGlyphBitmap(uint32_t glyph_index, | |
125 FX_BOOL bFontStyle, | |
126 const CFX_Matrix* pMatrix, | |
127 int dest_width, | |
128 int anti_alias, | |
129 int& text_flags) const; | |
130 const CFX_PathData* LoadGlyphPath(uint32_t glyph_index, int dest_width) const; | |
131 | |
132 #ifdef _SKIA_SUPPORT_ | |
133 CFX_TypeFace* GetDeviceCache() const; | |
134 #endif | |
135 | |
136 int GetGlyphWidth(uint32_t glyph_index); | |
137 int GetAscent() const; | |
138 int GetDescent() const; | |
139 FX_BOOL GetGlyphBBox(uint32_t glyph_index, FX_RECT& bbox); | |
140 bool IsItalic() const; | |
141 bool IsBold() const; | |
142 bool IsFixedWidth() const; | |
143 bool IsVertical() const { return m_bVertical; } | |
144 CFX_ByteString GetPsName() const; | |
145 CFX_ByteString GetFamilyName() const; | |
146 CFX_ByteString GetFaceName() const; | |
147 bool IsTTFont() const; | |
148 FX_BOOL GetBBox(FX_RECT& bbox); | |
149 int GetHeight() const; | |
150 int GetULPos() const; | |
151 int GetULthickness() const; | |
152 int GetMaxAdvanceWidth() const; | |
153 FX_BOOL IsEmbedded() const { return m_bEmbedded; } | |
154 uint8_t* GetSubData() const { return m_pGsubData; } | |
155 void SetSubData(uint8_t* data) { m_pGsubData = data; } | |
156 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | |
157 void* GetPlatformFont() const { return m_pPlatformFont; } | |
158 void SetPlatformFont(void* font) { m_pPlatformFont = font; } | |
159 #endif | |
160 uint8_t* GetFontData() const { return m_pFontData; } | |
161 uint32_t GetSize() const { return m_dwSize; } | |
162 void AdjustMMParams(int glyph_index, int width, int weight) const; | |
163 | |
164 static const size_t kAngleSkewArraySize = 30; | |
165 static const char s_AngleSkew[kAngleSkewArraySize]; | |
166 static const size_t kWeightPowArraySize = 100; | |
167 static const uint8_t s_WeightPow[kWeightPowArraySize]; | |
168 static const uint8_t s_WeightPow_11[kWeightPowArraySize]; | |
169 static const uint8_t s_WeightPow_SHIFTJIS[kWeightPowArraySize]; | |
170 | |
171 #ifdef PDF_ENABLE_XFA | |
172 protected: | |
173 CFX_BinaryBuf m_OtfFontData; | |
174 bool m_bShallowCopy; | |
175 FXFT_StreamRec* m_pOwnedStream; | |
176 #endif // PDF_ENABLE_XFA | |
177 | |
178 private: | |
179 friend class CFX_FaceCache; | |
180 CFX_PathData* LoadGlyphPathImpl(uint32_t glyph_index, | |
181 int dest_width = 0) const; | |
182 | |
183 private: | |
184 CFX_FaceCache* GetFaceCache() const; | |
185 | |
186 void ReleasePlatformResource(); | |
187 void DeleteFace(); | |
188 | |
189 void ClearFaceCache(); | |
190 | |
191 FXFT_Face m_Face; | |
192 mutable CFX_FaceCache* m_FaceCache; // not owned. | |
193 std::unique_ptr<CFX_SubstFont> m_pSubstFont; | |
194 std::vector<uint8_t> m_pFontDataAllocation; | |
195 uint8_t* m_pFontData; | |
196 uint8_t* m_pGsubData; | |
197 uint32_t m_dwSize; | |
198 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | |
199 void* m_pPlatformFont; | |
200 #endif | |
201 bool m_bEmbedded; | |
202 bool m_bVertical; | |
203 }; | |
204 | |
205 class CFX_FontFaceInfo { | |
206 public: | |
207 CFX_FontFaceInfo(CFX_ByteString filePath, | |
208 CFX_ByteString faceName, | |
209 CFX_ByteString fontTables, | |
210 uint32_t fontOffset, | |
211 uint32_t fileSize); | |
212 | |
213 const CFX_ByteString m_FilePath; | |
214 const CFX_ByteString m_FaceName; | |
215 const CFX_ByteString m_FontTables; | |
216 const uint32_t m_FontOffset; | |
217 const uint32_t m_FileSize; | |
218 uint32_t m_Styles; | |
219 uint32_t m_Charsets; | |
220 }; | |
221 | |
222 class CFX_GlyphBitmap { | |
223 public: | |
224 int m_Top; | |
225 int m_Left; | |
226 CFX_DIBitmap m_Bitmap; | |
227 }; | |
228 | |
229 struct FXTEXT_GLYPHPOS { | |
230 const CFX_GlyphBitmap* m_pGlyph; | |
231 int m_OriginX; | |
232 int m_OriginY; | |
233 FX_FLOAT m_fOriginX; | |
234 FX_FLOAT m_fOriginY; | |
235 }; | |
236 | |
237 FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs, | |
238 int anti_alias, | |
239 FX_FLOAT retinaScaleX = 1.0f, | |
240 FX_FLOAT retinaScaleY = 1.0f); | |
241 | |
242 CFX_ByteString GetNameFromTT(const uint8_t* name_table, | |
243 uint32_t name_table_size, | |
244 uint32_t name); | |
245 | |
246 int PDF_GetStandardFontName(CFX_ByteString* name); | |
247 | |
248 #endif // CORE_FXGE_INCLUDE_FX_FONT_H_ | |
OLD | NEW |