• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_CFX_FONT_H_
8 #define CORE_FXGE_CFX_FONT_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fxcrt/bytestring.h"
14 #include "core/fxcrt/fx_coordinates.h"
15 #include "core/fxcrt/unowned_ptr.h"
16 #include "core/fxge/fx_freetype.h"
17 
18 #if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_
19 #include "core/fxge/fx_font.h"
20 #endif
21 
22 class CFX_FaceCache;
23 class CFX_GlyphBitmap;
24 class CFX_PathData;
25 class CFX_SubstFont;
26 class IFX_SeekableReadStream;
27 
28 class CFX_Font {
29  public:
30   CFX_Font();
31   ~CFX_Font();
32 
33   void LoadSubst(const ByteString& face_name,
34                  bool bTrueType,
35                  uint32_t flags,
36                  int weight,
37                  int italic_angle,
38                  int CharsetCP,
39                  bool bVertical);
40 
41   bool LoadEmbedded(const uint8_t* data, uint32_t size);
GetFace()42   FXFT_Face GetFace() const { return m_Face; }
GetSubstFont()43   CFX_SubstFont* GetSubstFont() const { return m_pSubstFont.get(); }
44 
45 #ifdef PDF_ENABLE_XFA
46   bool LoadFile(const RetainPtr<IFX_SeekableReadStream>& pFile, int nFaceIndex);
47 
48   void SetFace(FXFT_Face face);
49   void SetSubstFont(std::unique_ptr<CFX_SubstFont> subst);
50 #endif  // PDF_ENABLE_XFA
51 
52   const CFX_GlyphBitmap* LoadGlyphBitmap(uint32_t glyph_index,
53                                          bool bFontStyle,
54                                          const CFX_Matrix* pMatrix,
55                                          int dest_width,
56                                          int anti_alias,
57                                          int& text_flags) const;
58   const CFX_PathData* LoadGlyphPath(uint32_t glyph_index, int dest_width) const;
59 
60 #if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_
61   CFX_TypeFace* GetDeviceCache() const;
62 #endif
63 
64   int GetGlyphWidth(uint32_t glyph_index);
65   int GetAscent() const;
66   int GetDescent() const;
67   bool GetGlyphBBox(uint32_t glyph_index, FX_RECT& bbox);
68   bool IsItalic() const;
69   bool IsBold() const;
70   bool IsFixedWidth() const;
IsVertical()71   bool IsVertical() const { return m_bVertical; }
72   ByteString GetPsName() const;
73   ByteString GetFamilyName() const;
74   ByteString GetFaceName() const;
75   bool IsTTFont() const;
76   bool GetBBox(FX_RECT& bbox);
IsEmbedded()77   bool IsEmbedded() const { return m_bEmbedded; }
GetSubData()78   uint8_t* GetSubData() const { return m_pGsubData.get(); }
SetSubData(uint8_t * data)79   void SetSubData(uint8_t* data) { m_pGsubData.reset(data); }
80 #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
GetPlatformFont()81   void* GetPlatformFont() const { return m_pPlatformFont; }
SetPlatformFont(void * font)82   void SetPlatformFont(void* font) { m_pPlatformFont = font; }
83 #endif
GetFontData()84   uint8_t* GetFontData() const { return m_pFontData; }
GetSize()85   uint32_t GetSize() const { return m_dwSize; }
86   void AdjustMMParams(int glyph_index, int width, int weight) const;
87 
88   CFX_PathData* LoadGlyphPathImpl(uint32_t glyph_index, int dest_width) const;
89 
90   static const size_t kAngleSkewArraySize = 30;
91   static const char s_AngleSkew[kAngleSkewArraySize];
92   static const size_t kWeightPowArraySize = 100;
93   static const uint8_t s_WeightPow[kWeightPowArraySize];
94   static const uint8_t s_WeightPow_11[kWeightPowArraySize];
95   static const uint8_t s_WeightPow_SHIFTJIS[kWeightPowArraySize];
96 
97 #ifdef PDF_ENABLE_XFA
98  protected:
99   std::unique_ptr<FXFT_StreamRec> m_pOwnedStream;
100 #endif  // PDF_ENABLE_XFA
101 
102  private:
103   CFX_FaceCache* GetFaceCache() const;
104 #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
105   void ReleasePlatformResource();
106 #endif  // _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
107   void DeleteFace();
108   void ClearFaceCache();
109 
110   FXFT_Face m_Face;
111   mutable UnownedPtr<CFX_FaceCache> m_FaceCache;
112   std::unique_ptr<CFX_SubstFont> m_pSubstFont;
113   std::vector<uint8_t> m_pFontDataAllocation;
114   uint8_t* m_pFontData;
115   std::unique_ptr<uint8_t, FxFreeDeleter> m_pGsubData;
116   uint32_t m_dwSize;
117 #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
118   void* m_pPlatformFont;
119 #endif
120   bool m_bEmbedded;
121   bool m_bVertical;
122 };
123 
124 #endif  // CORE_FXGE_CFX_FONT_H_
125