OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CORE_FXGE_INCLUDE_FX_FONT_H_ | 7 #ifndef CORE_FXGE_INCLUDE_FX_FONT_H_ |
8 #define CORE_FXGE_INCLUDE_FX_FONT_H_ | 8 #define CORE_FXGE_INCLUDE_FX_FONT_H_ |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "core/fxcrt/include/fx_system.h" | 13 #include "core/fxcrt/include/fx_system.h" |
14 #include "core/fxge/include/cfx_substfont.h" | 14 #include "core/fxge/include/cfx_substfont.h" |
15 #include "core/fxge/include/fx_dib.h" | 15 #include "core/fxge/include/fx_dib.h" |
16 #include "core/fxge/include/fx_freetype.h" | 16 #include "core/fxge/include/fx_freetype.h" |
17 | 17 |
18 typedef struct FT_FaceRec_* FXFT_Face; | 18 typedef struct FT_FaceRec_* FXFT_Face; |
19 typedef void* FXFT_Library; | 19 typedef void* FXFT_Library; |
20 | 20 |
21 class CFX_FaceCache; | 21 class CFX_FaceCache; |
22 class CFX_FontCache; | 22 class CFX_GlyphBitmap; |
23 class CFX_PathData; | 23 class CFX_PathData; |
24 class CFX_SizeGlyphCache; | 24 class CFX_SizeGlyphCache; |
25 | 25 |
26 #ifdef _SKIA_SUPPORT_ | 26 #ifdef _SKIA_SUPPORT_ |
27 class SkTypeface; | 27 class SkTypeface; |
28 | 28 |
29 using CFX_TypeFace = SkTypeface; | 29 using CFX_TypeFace = SkTypeface; |
30 #endif | 30 #endif |
31 | 31 |
32 #define FXFONT_FIXED_PITCH 0x01 | 32 #define FXFONT_FIXED_PITCH 0x01 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 FX_BOOL LoadEmbedded(const uint8_t* data, uint32_t size); | 99 FX_BOOL LoadEmbedded(const uint8_t* data, uint32_t size); |
100 FXFT_Face GetFace() const { return m_Face; } | 100 FXFT_Face GetFace() const { return m_Face; } |
101 CFX_SubstFont* GetSubstFont() const { return m_pSubstFont.get(); } | 101 CFX_SubstFont* GetSubstFont() const { return m_pSubstFont.get(); } |
102 | 102 |
103 #ifdef PDF_ENABLE_XFA | 103 #ifdef PDF_ENABLE_XFA |
104 FX_BOOL LoadFile(IFX_FileRead* pFile, | 104 FX_BOOL LoadFile(IFX_FileRead* pFile, |
105 int nFaceIndex = 0, | 105 int nFaceIndex = 0, |
106 int* pFaceCount = nullptr); | 106 int* pFaceCount = nullptr); |
107 | 107 |
108 FX_BOOL LoadClone(const CFX_Font* pFont); | 108 FX_BOOL LoadClone(const CFX_Font* pFont); |
109 void SetFace(FXFT_Face face) { m_Face = face; } | 109 void SetFace(FXFT_Face face); |
110 void SetSubstFont(std::unique_ptr<CFX_SubstFont> subst) { | 110 void SetSubstFont(std::unique_ptr<CFX_SubstFont> subst) { |
111 m_pSubstFont = std::move(subst); | 111 m_pSubstFont = std::move(subst); |
112 } | 112 } |
113 #endif // PDF_ENABLE_XFA | 113 #endif // PDF_ENABLE_XFA |
114 | 114 |
115 CFX_PathData* LoadGlyphPath(uint32_t glyph_index, int dest_width = 0); | 115 const CFX_GlyphBitmap* LoadGlyphBitmap(uint32_t glyph_index, |
| 116 FX_BOOL bFontStyle, |
| 117 const CFX_Matrix* pMatrix, |
| 118 int dest_width, |
| 119 int anti_alias, |
| 120 int& text_flags) const; |
| 121 const CFX_PathData* LoadGlyphPath(uint32_t glyph_index, int dest_width) const; |
| 122 |
| 123 #ifdef _SKIA_SUPPORT_ |
| 124 CFX_TypeFace* GetDeviceCache() const; |
| 125 #endif |
| 126 |
116 int GetGlyphWidth(uint32_t glyph_index); | 127 int GetGlyphWidth(uint32_t glyph_index); |
117 int GetAscent() const; | 128 int GetAscent() const; |
118 int GetDescent() const; | 129 int GetDescent() const; |
119 FX_BOOL GetGlyphBBox(uint32_t glyph_index, FX_RECT& bbox); | 130 FX_BOOL GetGlyphBBox(uint32_t glyph_index, FX_RECT& bbox); |
120 bool IsItalic() const; | 131 bool IsItalic() const; |
121 bool IsBold() const; | 132 bool IsBold() const; |
122 bool IsFixedWidth() const; | 133 bool IsFixedWidth() const; |
123 FX_BOOL IsVertical() const { return m_bVertical; } | 134 FX_BOOL IsVertical() const { return m_bVertical; } |
124 CFX_ByteString GetPsName() const; | 135 CFX_ByteString GetPsName() const; |
125 CFX_ByteString GetFamilyName() const; | 136 CFX_ByteString GetFamilyName() const; |
126 CFX_ByteString GetFaceName() const; | 137 CFX_ByteString GetFaceName() const; |
127 FX_BOOL IsTTFont() const; | 138 FX_BOOL IsTTFont() const; |
128 FX_BOOL GetBBox(FX_RECT& bbox); | 139 FX_BOOL GetBBox(FX_RECT& bbox); |
129 int GetHeight() const; | 140 int GetHeight() const; |
130 int GetULPos() const; | 141 int GetULPos() const; |
131 int GetULthickness() const; | 142 int GetULthickness() const; |
132 int GetMaxAdvanceWidth() const; | 143 int GetMaxAdvanceWidth() const; |
133 FX_BOOL IsEmbedded() const { return m_bEmbedded; } | 144 FX_BOOL IsEmbedded() const { return m_bEmbedded; } |
134 uint8_t* GetSubData() const { return m_pGsubData; } | 145 uint8_t* GetSubData() const { return m_pGsubData; } |
135 void SetSubData(uint8_t* data) { m_pGsubData = data; } | 146 void SetSubData(uint8_t* data) { m_pGsubData = data; } |
136 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 147 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
137 void* GetPlatformFont() const { return m_pPlatformFont; } | 148 void* GetPlatformFont() const { return m_pPlatformFont; } |
138 void SetPlatformFont(void* font) { m_pPlatformFont = font; } | 149 void SetPlatformFont(void* font) { m_pPlatformFont = font; } |
139 #endif | 150 #endif |
140 uint8_t* GetFontData() const { return m_pFontData; } | 151 uint8_t* GetFontData() const { return m_pFontData; } |
141 uint32_t GetSize() const { return m_dwSize; } | 152 uint32_t GetSize() const { return m_dwSize; } |
142 void AdjustMMParams(int glyph_index, int width, int weight); | 153 void AdjustMMParams(int glyph_index, int width, int weight) const; |
143 | 154 |
144 static const size_t kAngleSkewArraySize = 30; | 155 static const size_t kAngleSkewArraySize = 30; |
145 static const char s_AngleSkew[kAngleSkewArraySize]; | 156 static const char s_AngleSkew[kAngleSkewArraySize]; |
146 static const size_t kWeightPowArraySize = 100; | 157 static const size_t kWeightPowArraySize = 100; |
147 static const uint8_t s_WeightPow[kWeightPowArraySize]; | 158 static const uint8_t s_WeightPow[kWeightPowArraySize]; |
148 static const uint8_t s_WeightPow_11[kWeightPowArraySize]; | 159 static const uint8_t s_WeightPow_11[kWeightPowArraySize]; |
149 static const uint8_t s_WeightPow_SHIFTJIS[kWeightPowArraySize]; | 160 static const uint8_t s_WeightPow_SHIFTJIS[kWeightPowArraySize]; |
150 | 161 |
151 #ifdef PDF_ENABLE_XFA | 162 #ifdef PDF_ENABLE_XFA |
152 protected: | 163 protected: |
153 CFX_BinaryBuf m_OtfFontData; | 164 CFX_BinaryBuf m_OtfFontData; |
154 bool m_bShallowCopy; | 165 bool m_bShallowCopy; |
155 FXFT_StreamRec* m_pOwnedStream; | 166 FXFT_StreamRec* m_pOwnedStream; |
156 #endif // PDF_ENABLE_XFA | 167 #endif // PDF_ENABLE_XFA |
157 | 168 |
158 private: | 169 private: |
| 170 friend class CFX_FaceCache; |
| 171 CFX_PathData* LoadGlyphPathImpl(uint32_t glyph_index, |
| 172 int dest_width = 0) const; |
| 173 |
| 174 private: |
| 175 CFX_FaceCache* GetFaceCache() const; |
| 176 |
159 void ReleasePlatformResource(); | 177 void ReleasePlatformResource(); |
160 void DeleteFace(); | 178 void DeleteFace(); |
161 | 179 |
| 180 void ClearFaceCache(); |
| 181 |
162 FXFT_Face m_Face; | 182 FXFT_Face m_Face; |
| 183 mutable CFX_FaceCache* m_FaceCache; // not owned. |
163 std::unique_ptr<CFX_SubstFont> m_pSubstFont; | 184 std::unique_ptr<CFX_SubstFont> m_pSubstFont; |
164 std::vector<uint8_t> m_pFontDataAllocation; | 185 std::vector<uint8_t> m_pFontDataAllocation; |
165 uint8_t* m_pFontData; | 186 uint8_t* m_pFontData; |
166 uint8_t* m_pGsubData; | 187 uint8_t* m_pGsubData; |
167 uint32_t m_dwSize; | 188 uint32_t m_dwSize; |
168 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 189 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
169 void* m_pPlatformFont; | 190 void* m_pPlatformFont; |
170 #endif | 191 #endif |
171 FX_BOOL m_bEmbedded; | 192 FX_BOOL m_bEmbedded; |
172 FX_BOOL m_bVertical; | 193 FX_BOOL m_bVertical; |
173 }; | 194 }; |
174 | 195 |
175 class CFX_FontFaceInfo { | 196 class CFX_FontFaceInfo { |
176 public: | 197 public: |
177 CFX_FontFaceInfo(CFX_ByteString filePath, | 198 CFX_FontFaceInfo(CFX_ByteString filePath, |
178 CFX_ByteString faceName, | 199 CFX_ByteString faceName, |
179 CFX_ByteString fontTables, | 200 CFX_ByteString fontTables, |
180 uint32_t fontOffset, | 201 uint32_t fontOffset, |
181 uint32_t fileSize); | 202 uint32_t fileSize); |
182 | 203 |
183 const CFX_ByteString m_FilePath; | 204 const CFX_ByteString m_FilePath; |
184 const CFX_ByteString m_FaceName; | 205 const CFX_ByteString m_FaceName; |
185 const CFX_ByteString m_FontTables; | 206 const CFX_ByteString m_FontTables; |
186 const uint32_t m_FontOffset; | 207 const uint32_t m_FontOffset; |
187 const uint32_t m_FileSize; | 208 const uint32_t m_FileSize; |
188 uint32_t m_Styles; | 209 uint32_t m_Styles; |
189 uint32_t m_Charsets; | 210 uint32_t m_Charsets; |
190 }; | 211 }; |
191 | 212 |
192 class CFX_CountedFaceCache { | |
193 public: | |
194 CFX_FaceCache* m_Obj; | |
195 uint32_t m_nCount; | |
196 }; | |
197 | |
198 class CFX_GlyphBitmap { | 213 class CFX_GlyphBitmap { |
199 public: | 214 public: |
200 int m_Top; | 215 int m_Top; |
201 int m_Left; | 216 int m_Left; |
202 CFX_DIBitmap m_Bitmap; | 217 CFX_DIBitmap m_Bitmap; |
203 }; | 218 }; |
204 | 219 |
205 struct FXTEXT_GLYPHPOS { | 220 struct FXTEXT_GLYPHPOS { |
206 const CFX_GlyphBitmap* m_pGlyph; | 221 const CFX_GlyphBitmap* m_pGlyph; |
207 int m_OriginX; | 222 int m_OriginX; |
208 int m_OriginY; | 223 int m_OriginY; |
209 FX_FLOAT m_fOriginX; | 224 FX_FLOAT m_fOriginX; |
210 FX_FLOAT m_fOriginY; | 225 FX_FLOAT m_fOriginY; |
211 }; | 226 }; |
212 | 227 |
213 FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs, | 228 FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs, |
214 int anti_alias, | 229 int anti_alias, |
215 FX_FLOAT retinaScaleX = 1.0f, | 230 FX_FLOAT retinaScaleX = 1.0f, |
216 FX_FLOAT retinaScaleY = 1.0f); | 231 FX_FLOAT retinaScaleY = 1.0f); |
217 | 232 |
218 CFX_ByteString GetNameFromTT(const uint8_t* name_table, | 233 CFX_ByteString GetNameFromTT(const uint8_t* name_table, |
219 uint32_t name_table_size, | 234 uint32_t name_table_size, |
220 uint32_t name); | 235 uint32_t name); |
221 | 236 |
222 int PDF_GetStandardFontName(CFX_ByteString* name); | 237 int PDF_GetStandardFontName(CFX_ByteString* name); |
223 | 238 |
224 #endif // CORE_FXGE_INCLUDE_FX_FONT_H_ | 239 #endif // CORE_FXGE_INCLUDE_FX_FONT_H_ |
OLD | NEW |