Chromium Code Reviews| 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_FontCacheItem; |
| 23 class CFX_GlyphBitmap; | |
| 23 class CFX_PathData; | 24 class CFX_PathData; |
| 24 class CFX_SizeGlyphCache; | 25 class CFX_SizeGlyphCache; |
| 25 | 26 |
| 26 #ifdef _SKIA_SUPPORT_ | 27 #ifdef _SKIA_SUPPORT_ |
| 27 class SkTypeface; | 28 class SkTypeface; |
| 28 | 29 |
| 29 using CFX_TypeFace = SkTypeface; | 30 using CFX_TypeFace = SkTypeface; |
| 30 #endif | 31 #endif |
| 31 | 32 |
| 32 #define FXFONT_FIXED_PITCH 0x01 | 33 #define FXFONT_FIXED_PITCH 0x01 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 int nFaceIndex = 0, | 106 int nFaceIndex = 0, |
| 106 int* pFaceCount = nullptr); | 107 int* pFaceCount = nullptr); |
| 107 | 108 |
| 108 FX_BOOL LoadClone(const CFX_Font* pFont); | 109 FX_BOOL LoadClone(const CFX_Font* pFont); |
| 109 void SetFace(FXFT_Face face) { m_Face = face; } | 110 void SetFace(FXFT_Face face) { m_Face = face; } |
| 110 void SetSubstFont(std::unique_ptr<CFX_SubstFont> subst) { | 111 void SetSubstFont(std::unique_ptr<CFX_SubstFont> subst) { |
| 111 m_pSubstFont = std::move(subst); | 112 m_pSubstFont = std::move(subst); |
| 112 } | 113 } |
| 113 #endif // PDF_ENABLE_XFA | 114 #endif // PDF_ENABLE_XFA |
| 114 | 115 |
| 115 CFX_PathData* LoadGlyphPath(uint32_t glyph_index, int dest_width = 0); | |
| 116 int GetGlyphWidth(uint32_t glyph_index); | 116 int GetGlyphWidth(uint32_t glyph_index); |
| 117 int GetAscent() const; | 117 int GetAscent() const; |
| 118 int GetDescent() const; | 118 int GetDescent() const; |
| 119 FX_BOOL GetGlyphBBox(uint32_t glyph_index, FX_RECT& bbox); | 119 FX_BOOL GetGlyphBBox(uint32_t glyph_index, FX_RECT& bbox); |
| 120 bool IsItalic() const; | 120 bool IsItalic() const; |
| 121 bool IsBold() const; | 121 bool IsBold() const; |
| 122 bool IsFixedWidth() const; | 122 bool IsFixedWidth() const; |
| 123 FX_BOOL IsVertical() const { return m_bVertical; } | 123 FX_BOOL IsVertical() const { return m_bVertical; } |
| 124 CFX_ByteString GetPsName() const; | 124 CFX_ByteString GetPsName() const; |
| 125 CFX_ByteString GetFamilyName() const; | 125 CFX_ByteString GetFamilyName() const; |
| 126 CFX_ByteString GetFaceName() const; | 126 CFX_ByteString GetFaceName() const; |
| 127 FX_BOOL IsTTFont() const; | 127 FX_BOOL IsTTFont() const; |
| 128 FX_BOOL GetBBox(FX_RECT& bbox); | 128 FX_BOOL GetBBox(FX_RECT& bbox); |
| 129 int GetHeight() const; | 129 int GetHeight() const; |
| 130 int GetULPos() const; | 130 int GetULPos() const; |
| 131 int GetULthickness() const; | 131 int GetULthickness() const; |
| 132 int GetMaxAdvanceWidth() const; | 132 int GetMaxAdvanceWidth() const; |
| 133 FX_BOOL IsEmbedded() const { return m_bEmbedded; } | 133 FX_BOOL IsEmbedded() const { return m_bEmbedded; } |
| 134 uint8_t* GetSubData() const { return m_pGsubData; } | 134 uint8_t* GetSubData() const { return m_pGsubData; } |
| 135 void SetSubData(uint8_t* data) { m_pGsubData = data; } | 135 void SetSubData(uint8_t* data) { m_pGsubData = data; } |
| 136 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 136 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 137 void* GetPlatformFont() const { return m_pPlatformFont; } | 137 void* GetPlatformFont() const { return m_pPlatformFont; } |
| 138 void SetPlatformFont(void* font) { m_pPlatformFont = font; } | 138 void SetPlatformFont(void* font) { m_pPlatformFont = font; } |
| 139 #endif | 139 #endif |
| 140 uint8_t* GetFontData() const { return m_pFontData; } | 140 uint8_t* GetFontData() const { return m_pFontData; } |
| 141 uint32_t GetSize() const { return m_dwSize; } | 141 uint32_t GetSize() const { return m_dwSize; } |
| 142 void AdjustMMParams(int glyph_index, int width, int weight); | 142 void AdjustMMParams(int glyph_index, int width, int weight); |
| 143 | 143 |
| 144 const CFX_FontCacheItem* GetFontCache() const { return m_FontCache.get(); } | |
|
dsinclair
2016/09/14 17:51:51
This isn't really a cache as it's always just one
snake
2016/09/14 19:06:29
I did remove m_FontCache member, now CFX_Font tran
| |
| 145 CFX_FaceCache* GetFaceCache() const; | |
| 146 | |
| 144 static const size_t kAngleSkewArraySize = 30; | 147 static const size_t kAngleSkewArraySize = 30; |
| 145 static const char s_AngleSkew[kAngleSkewArraySize]; | 148 static const char s_AngleSkew[kAngleSkewArraySize]; |
| 146 static const size_t kWeightPowArraySize = 100; | 149 static const size_t kWeightPowArraySize = 100; |
| 147 static const uint8_t s_WeightPow[kWeightPowArraySize]; | 150 static const uint8_t s_WeightPow[kWeightPowArraySize]; |
| 148 static const uint8_t s_WeightPow_11[kWeightPowArraySize]; | 151 static const uint8_t s_WeightPow_11[kWeightPowArraySize]; |
| 149 static const uint8_t s_WeightPow_SHIFTJIS[kWeightPowArraySize]; | 152 static const uint8_t s_WeightPow_SHIFTJIS[kWeightPowArraySize]; |
| 150 | 153 |
| 151 #ifdef PDF_ENABLE_XFA | 154 #ifdef PDF_ENABLE_XFA |
| 152 protected: | 155 protected: |
| 153 CFX_BinaryBuf m_OtfFontData; | 156 CFX_BinaryBuf m_OtfFontData; |
| 154 bool m_bShallowCopy; | 157 bool m_bShallowCopy; |
| 155 FXFT_StreamRec* m_pOwnedStream; | 158 FXFT_StreamRec* m_pOwnedStream; |
| 156 #endif // PDF_ENABLE_XFA | 159 #endif // PDF_ENABLE_XFA |
| 157 | 160 |
| 158 private: | 161 private: |
| 162 friend class CFX_FaceCache; | |
| 163 CFX_PathData* LoadGlyphPath(uint32_t glyph_index, int dest_width = 0); | |
|
dsinclair
2016/09/14 17:51:51
Why not leave this public then we don't need the f
snake
2016/09/14 19:06:29
This method is not using cache, for cleanly any ca
| |
| 164 | |
| 165 private: | |
| 159 void ReleasePlatformResource(); | 166 void ReleasePlatformResource(); |
| 160 void DeleteFace(); | 167 void DeleteFace(); |
| 161 | 168 |
| 169 void ClearFaceCache(); | |
| 170 | |
| 162 FXFT_Face m_Face; | 171 FXFT_Face m_Face; |
| 172 mutable CFX_FaceCache* m_FaceCache; | |
|
dsinclair
2016/09/14 17:51:51
Why mutable?
What is the ownership of this? If it
snake
2016/09/14 19:06:29
It is initialized on demand in GetFaceCache() cons
| |
| 173 std::unique_ptr<CFX_FontCacheItem> m_FontCache; | |
| 163 std::unique_ptr<CFX_SubstFont> m_pSubstFont; | 174 std::unique_ptr<CFX_SubstFont> m_pSubstFont; |
| 164 std::vector<uint8_t> m_pFontDataAllocation; | 175 std::vector<uint8_t> m_pFontDataAllocation; |
| 165 uint8_t* m_pFontData; | 176 uint8_t* m_pFontData; |
| 166 uint8_t* m_pGsubData; | 177 uint8_t* m_pGsubData; |
| 167 uint32_t m_dwSize; | 178 uint32_t m_dwSize; |
| 168 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 179 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 169 void* m_pPlatformFont; | 180 void* m_pPlatformFont; |
| 170 #endif | 181 #endif |
| 171 FX_BOOL m_bEmbedded; | 182 FX_BOOL m_bEmbedded; |
| 172 FX_BOOL m_bVertical; | 183 FX_BOOL m_bVertical; |
| 173 }; | 184 }; |
| 174 | 185 |
| 186 class CFX_FontCacheItem { | |
| 187 public: | |
| 188 explicit CFX_FontCacheItem(CFX_Font* font); | |
| 189 ~CFX_FontCacheItem(); | |
| 190 | |
| 191 const CFX_GlyphBitmap* LoadGlyphBitmap(uint32_t glyph_index, | |
| 192 FX_BOOL bFontStyle, | |
| 193 const CFX_Matrix* pMatrix, | |
| 194 int dest_width, | |
| 195 int anti_alias, | |
| 196 int& text_flags) const; | |
| 197 const CFX_PathData* LoadGlyphPath(uint32_t glyph_index, int dest_width) const; | |
| 198 | |
| 199 #ifdef _SKIA_SUPPORT_ | |
| 200 CFX_TypeFace* GetDeviceCache() const; | |
| 201 #endif | |
| 202 | |
| 203 private: | |
| 204 CFX_Font* m_Font; | |
| 205 }; | |
| 206 | |
| 175 class CFX_FontFaceInfo { | 207 class CFX_FontFaceInfo { |
| 176 public: | 208 public: |
| 177 CFX_FontFaceInfo(CFX_ByteString filePath, | 209 CFX_FontFaceInfo(CFX_ByteString filePath, |
| 178 CFX_ByteString faceName, | 210 CFX_ByteString faceName, |
| 179 CFX_ByteString fontTables, | 211 CFX_ByteString fontTables, |
| 180 uint32_t fontOffset, | 212 uint32_t fontOffset, |
| 181 uint32_t fileSize); | 213 uint32_t fileSize); |
| 182 | 214 |
| 183 const CFX_ByteString m_FilePath; | 215 const CFX_ByteString m_FilePath; |
| 184 const CFX_ByteString m_FaceName; | 216 const CFX_ByteString m_FaceName; |
| 185 const CFX_ByteString m_FontTables; | 217 const CFX_ByteString m_FontTables; |
| 186 const uint32_t m_FontOffset; | 218 const uint32_t m_FontOffset; |
| 187 const uint32_t m_FileSize; | 219 const uint32_t m_FileSize; |
| 188 uint32_t m_Styles; | 220 uint32_t m_Styles; |
| 189 uint32_t m_Charsets; | 221 uint32_t m_Charsets; |
| 190 }; | 222 }; |
| 191 | 223 |
| 192 class CFX_CountedFaceCache { | |
| 193 public: | |
| 194 CFX_FaceCache* m_Obj; | |
| 195 uint32_t m_nCount; | |
| 196 }; | |
| 197 | |
| 198 class CFX_GlyphBitmap { | 224 class CFX_GlyphBitmap { |
| 199 public: | 225 public: |
| 200 int m_Top; | 226 int m_Top; |
| 201 int m_Left; | 227 int m_Left; |
| 202 CFX_DIBitmap m_Bitmap; | 228 CFX_DIBitmap m_Bitmap; |
| 203 }; | 229 }; |
| 204 | 230 |
| 205 struct FXTEXT_GLYPHPOS { | 231 struct FXTEXT_GLYPHPOS { |
| 206 const CFX_GlyphBitmap* m_pGlyph; | 232 const CFX_GlyphBitmap* m_pGlyph; |
| 207 int m_OriginX; | 233 int m_OriginX; |
| 208 int m_OriginY; | 234 int m_OriginY; |
| 209 FX_FLOAT m_fOriginX; | 235 FX_FLOAT m_fOriginX; |
| 210 FX_FLOAT m_fOriginY; | 236 FX_FLOAT m_fOriginY; |
| 211 }; | 237 }; |
| 212 | 238 |
| 213 FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs, | 239 FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs, |
| 214 int anti_alias, | 240 int anti_alias, |
| 215 FX_FLOAT retinaScaleX = 1.0f, | 241 FX_FLOAT retinaScaleX = 1.0f, |
| 216 FX_FLOAT retinaScaleY = 1.0f); | 242 FX_FLOAT retinaScaleY = 1.0f); |
| 217 | 243 |
| 218 CFX_ByteString GetNameFromTT(const uint8_t* name_table, | 244 CFX_ByteString GetNameFromTT(const uint8_t* name_table, |
| 219 uint32_t name_table_size, | 245 uint32_t name_table_size, |
| 220 uint32_t name); | 246 uint32_t name); |
| 221 | 247 |
| 222 int PDF_GetStandardFontName(CFX_ByteString* name); | 248 int PDF_GetStandardFontName(CFX_ByteString* name); |
| 223 | 249 |
| 224 #endif // CORE_FXGE_INCLUDE_FX_FONT_H_ | 250 #endif // CORE_FXGE_INCLUDE_FX_FONT_H_ |
| OLD | NEW |