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 XFA_FGAS_FONT_CFGAS_GEFONT_H_ | 7 #ifndef XFA_FGAS_FONT_CFGAS_GEFONT_H_ |
8 #define XFA_FGAS_FONT_CFGAS_GEFONT_H_ | 8 #define XFA_FGAS_FONT_CFGAS_GEFONT_H_ |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> |
12 | 13 |
| 14 #include "core/fxcrt/cfx_retain_ptr.h" |
13 #include "core/fxcrt/fx_memory.h" | 15 #include "core/fxcrt/fx_memory.h" |
14 #include "xfa/fgas/crt/fgas_utils.h" | 16 #include "xfa/fgas/crt/fgas_utils.h" |
15 #include "xfa/fgas/font/cfgas_fontmgr.h" | 17 #include "xfa/fgas/font/cfgas_fontmgr.h" |
16 | 18 |
17 #define FXFONT_SUBST_ITALIC 0x02 | 19 #define FXFONT_SUBST_ITALIC 0x02 |
18 | 20 |
| 21 class CFGAS_FontMgr; |
19 class CFX_UnicodeEncoding; | 22 class CFX_UnicodeEncoding; |
20 class CXFA_PDFFontMgr; | 23 class CXFA_PDFFontMgr; |
21 | 24 |
22 class CFGAS_GEFont { | 25 class CFGAS_GEFont : public CFX_Retainable { |
23 public: | 26 public: |
24 static CFGAS_GEFont* LoadFont(const FX_WCHAR* pszFontFamily, | 27 template <typename T, typename... Args> |
25 uint32_t dwFontStyles, | 28 friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); |
26 uint16_t wCodePage, | 29 |
27 CFGAS_FontMgr* pFontMgr); | 30 static CFX_RetainPtr<CFGAS_GEFont> LoadFont(const FX_WCHAR* pszFontFamily, |
28 static CFGAS_GEFont* LoadFont(CFX_Font* pExternalFont, | 31 uint32_t dwFontStyles, |
29 CFGAS_FontMgr* pFontMgr); | 32 uint16_t wCodePage, |
30 static CFGAS_GEFont* LoadFont(std::unique_ptr<CFX_Font> pInternalFont, | 33 CFGAS_FontMgr* pFontMgr); |
31 CFGAS_FontMgr* pFontMgr); | 34 static CFX_RetainPtr<CFGAS_GEFont> LoadFont(CFX_Font* pExternalFont, |
| 35 CFGAS_FontMgr* pFontMgr); |
| 36 static CFX_RetainPtr<CFGAS_GEFont> LoadFont( |
| 37 std::unique_ptr<CFX_Font> pInternalFont, |
| 38 CFGAS_FontMgr* pFontMgr); |
32 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 39 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
33 static CFGAS_GEFont* LoadFont(const uint8_t* pBuffer, | 40 static CFX_RetainPtr<CFGAS_GEFont> LoadFont(const uint8_t* pBuffer, |
34 int32_t iLength, | 41 int32_t iLength, |
35 CFGAS_FontMgr* pFontMgr); | 42 CFGAS_FontMgr* pFontMgr); |
36 static CFGAS_GEFont* LoadFont(const CFX_RetainPtr<IFGAS_Stream>& pFontStream, | 43 static CFX_RetainPtr<CFGAS_GEFont> LoadFont( |
37 CFGAS_FontMgr* pFontMgr, | 44 const CFX_RetainPtr<IFGAS_Stream>& pFontStream, |
38 bool bSaveStream); | 45 CFGAS_FontMgr* pFontMgr, |
| 46 bool bSaveStream); |
39 #endif | 47 #endif |
40 | 48 |
41 ~CFGAS_GEFont(); | 49 ~CFGAS_GEFont() override; |
42 | 50 |
43 void Release(); | 51 CFX_RetainPtr<CFGAS_GEFont> Derive(uint32_t dwFontStyles, |
44 CFGAS_GEFont* Retain(); | 52 uint16_t wCodePage = 0); |
45 CFGAS_GEFont* Derive(uint32_t dwFontStyles, uint16_t wCodePage = 0); | |
46 uint32_t GetFontStyles() const; | 53 uint32_t GetFontStyles() const; |
47 bool GetCharWidth(FX_WCHAR wUnicode, int32_t& iWidth, bool bCharCode); | 54 bool GetCharWidth(FX_WCHAR wUnicode, int32_t& iWidth, bool bCharCode); |
48 int32_t GetGlyphIndex(FX_WCHAR wUnicode, bool bCharCode = false); | 55 int32_t GetGlyphIndex(FX_WCHAR wUnicode, bool bCharCode = false); |
49 int32_t GetAscent() const; | 56 int32_t GetAscent() const; |
50 int32_t GetDescent() const; | 57 int32_t GetDescent() const; |
51 bool GetCharBBox(FX_WCHAR wUnicode, CFX_Rect& bbox, bool bCharCode = false); | 58 bool GetCharBBox(FX_WCHAR wUnicode, CFX_Rect& bbox, bool bCharCode = false); |
52 bool GetBBox(CFX_Rect& bbox); | 59 bool GetBBox(CFX_Rect& bbox); |
53 CFGAS_GEFont* GetSubstFont(int32_t iGlyphIndex) const; | 60 CFX_RetainPtr<CFGAS_GEFont> GetSubstFont(int32_t iGlyphIndex) const; |
54 CFX_Font* GetDevFont() const { return m_pFont; } | 61 CFX_Font* GetDevFont() const { return m_pFont; } |
55 void SetFontProvider(CXFA_PDFFontMgr* pProvider) { m_pProvider = pProvider; } | 62 void SetFontProvider(CXFA_PDFFontMgr* pProvider) { m_pProvider = pProvider; } |
56 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 63 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
57 void SetLogicalFontStyle(uint32_t dwLogFontStyle) { | 64 void SetLogicalFontStyle(uint32_t dwLogFontStyle) { |
58 m_bUseLogFontStyle = true; | 65 m_bUseLogFontStyle = true; |
59 m_dwLogFontStyle = dwLogFontStyle; | 66 m_dwLogFontStyle = dwLogFontStyle; |
60 } | 67 } |
61 #endif | 68 #endif |
62 | 69 |
63 private: | 70 private: |
64 explicit CFGAS_GEFont(CFGAS_FontMgr* pFontMgr); | 71 explicit CFGAS_GEFont(CFGAS_FontMgr* pFontMgr); |
65 CFGAS_GEFont(CFGAS_GEFont* src, uint32_t dwFontStyles); | 72 CFGAS_GEFont(const CFX_RetainPtr<CFGAS_GEFont>& src, uint32_t dwFontStyles); |
66 | 73 |
67 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 74 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
68 bool LoadFontInternal(const FX_WCHAR* pszFontFamily, | 75 bool LoadFontInternal(const FX_WCHAR* pszFontFamily, |
69 uint32_t dwFontStyles, | 76 uint32_t dwFontStyles, |
70 uint16_t wCodePage); | 77 uint16_t wCodePage); |
71 bool LoadFontInternal(const uint8_t* pBuffer, int32_t length); | 78 bool LoadFontInternal(const uint8_t* pBuffer, int32_t length); |
72 bool LoadFontInternal(const CFX_RetainPtr<IFGAS_Stream>& pFontStream, | 79 bool LoadFontInternal(const CFX_RetainPtr<IFGAS_Stream>& pFontStream, |
73 bool bSaveStream); | 80 bool bSaveStream); |
74 #endif | 81 #endif |
75 bool LoadFontInternal(CFX_Font* pExternalFont); | 82 bool LoadFontInternal(CFX_Font* pExternalFont); |
76 bool LoadFontInternal(std::unique_ptr<CFX_Font> pInternalFont); | 83 bool LoadFontInternal(std::unique_ptr<CFX_Font> pInternalFont); |
77 bool InitFont(); | 84 bool InitFont(); |
78 bool GetCharBBoxInternal(FX_WCHAR wUnicode, | 85 bool GetCharBBoxInternal(FX_WCHAR wUnicode, |
79 CFX_Rect& bbox, | 86 CFX_Rect& bbox, |
80 bool bRecursive, | 87 bool bRecursive, |
81 bool bCharCode = false); | 88 bool bCharCode = false); |
82 bool GetCharWidthInternal(FX_WCHAR wUnicode, | 89 bool GetCharWidthInternal(FX_WCHAR wUnicode, |
83 int32_t& iWidth, | 90 int32_t& iWidth, |
84 bool bRecursive, | 91 bool bRecursive, |
85 bool bCharCode); | 92 bool bCharCode); |
86 int32_t GetGlyphIndex(FX_WCHAR wUnicode, | 93 int32_t GetGlyphIndex(FX_WCHAR wUnicode, |
87 bool bRecursive, | 94 bool bRecursive, |
88 CFGAS_GEFont** ppFont, | 95 CFX_RetainPtr<CFGAS_GEFont>* ppFont, |
89 bool bCharCode = false); | 96 bool bCharCode = false); |
90 CFX_WideString GetFamilyName() const; | 97 CFX_WideString GetFamilyName() const; |
91 | 98 |
92 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 99 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
93 bool m_bUseLogFontStyle; | 100 bool m_bUseLogFontStyle; |
94 uint32_t m_dwLogFontStyle; | 101 uint32_t m_dwLogFontStyle; |
95 #endif | 102 #endif |
96 CFX_Font* m_pFont; | 103 CFX_Font* m_pFont; |
97 CFGAS_GEFont* const m_pSrcFont; | 104 CFX_RetainPtr<CFGAS_GEFont> m_pSrcFont; // Only set by ctor, so no cycles. |
98 CFGAS_FontMgr* const m_pFontMgr; | 105 CFGAS_FontMgr* const m_pFontMgr; |
99 int32_t m_iRefCount; | |
100 bool m_bExternalFont; | 106 bool m_bExternalFont; |
101 CFX_RetainPtr<IFGAS_Stream> m_pStream; | 107 CFX_RetainPtr<IFGAS_Stream> m_pStream; |
102 CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead; | 108 CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead; |
103 std::unique_ptr<CFX_UnicodeEncoding> m_pFontEncoding; | 109 std::unique_ptr<CFX_UnicodeEncoding> m_pFontEncoding; |
104 std::unique_ptr<CFX_DiscreteArrayTemplate<uint16_t>> m_pCharWidthMap; | 110 std::unique_ptr<CFX_DiscreteArrayTemplate<uint16_t>> m_pCharWidthMap; |
105 std::unique_ptr<CFX_MassArrayTemplate<CFX_Rect>> m_pRectArray; | 111 std::unique_ptr<CFX_MassArrayTemplate<CFX_Rect>> m_pRectArray; |
106 std::unique_ptr<CFX_MapPtrToPtr> m_pBBoxMap; | 112 std::unique_ptr<CFX_MapPtrToPtr> m_pBBoxMap; |
107 CXFA_PDFFontMgr* m_pProvider; // not owned. | 113 CXFA_PDFFontMgr* m_pProvider; // not owned. |
108 CFX_ArrayTemplate<CFGAS_GEFont*> m_SubstFonts; | 114 std::vector<CFX_RetainPtr<CFGAS_GEFont>> m_SubstFonts; |
109 std::map<FX_WCHAR, CFGAS_GEFont*> m_FontMapper; | 115 std::map<FX_WCHAR, CFX_RetainPtr<CFGAS_GEFont>> m_FontMapper; |
110 }; | 116 }; |
111 | 117 |
112 #endif // XFA_FGAS_FONT_CFGAS_GEFONT_H_ | 118 #endif // XFA_FGAS_FONT_CFGAS_GEFONT_H_ |
OLD | NEW |