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 XFA_FGAS_FONT_CFGAS_GEFONT_H_ 8 #define XFA_FGAS_FONT_CFGAS_GEFONT_H_ 9 10 #include <map> 11 #include <memory> 12 #include <utility> 13 #include <vector> 14 15 #include "core/fxcrt/fx_memory.h" 16 #include "core/fxcrt/retain_ptr.h" 17 #include "core/fxcrt/unowned_ptr.h" 18 #include "xfa/fgas/font/cfgas_fontmgr.h" 19 #include "xfa/fgas/font/cfgas_pdffontmgr.h" 20 21 class CFX_UnicodeEncoding; 22 23 class CFGAS_GEFont : public Retainable { 24 public: 25 template <typename T> 26 friend class RetainPtr; 27 template <typename T, typename... Args> 28 friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); 29 30 static RetainPtr<CFGAS_GEFont> LoadFont(const wchar_t* pszFontFamily, 31 uint32_t dwFontStyles, 32 uint16_t wCodePage, 33 CFGAS_FontMgr* pFontMgr); 34 static RetainPtr<CFGAS_GEFont> LoadFont(CFX_Font* pExternalFont, 35 CFGAS_FontMgr* pFontMgr); 36 static RetainPtr<CFGAS_GEFont> LoadFont( 37 std::unique_ptr<CFX_Font> pInternalFont, 38 CFGAS_FontMgr* pFontMgr); 39 40 uint32_t GetFontStyles() const; 41 bool GetCharWidth(wchar_t wUnicode, int32_t& iWidth); 42 int32_t GetGlyphIndex(wchar_t wUnicode); 43 int32_t GetAscent() const; 44 int32_t GetDescent() const; 45 46 bool GetCharBBox(wchar_t wUnicode, CFX_Rect* bbox); 47 bool GetBBox(CFX_Rect* bbox); 48 49 RetainPtr<CFGAS_GEFont> GetSubstFont(int32_t iGlyphIndex); GetDevFont()50 CFX_Font* GetDevFont() const { return m_pFont; } 51 SetFontProvider(CFGAS_PDFFontMgr * pProvider)52 void SetFontProvider(CFGAS_PDFFontMgr* pProvider) { 53 m_pProvider.Reset(pProvider); 54 } 55 SetLogicalFontStyle(uint32_t dwLogFontStyle)56 void SetLogicalFontStyle(uint32_t dwLogFontStyle) { 57 m_bUseLogFontStyle = true; 58 m_dwLogFontStyle = dwLogFontStyle; 59 } 60 61 private: 62 explicit CFGAS_GEFont(CFGAS_FontMgr* pFontMgr); 63 ~CFGAS_GEFont() override; 64 65 #if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ 66 bool LoadFontInternal(const wchar_t* pszFontFamily, 67 uint32_t dwFontStyles, 68 uint16_t wCodePage); 69 bool LoadFontInternal(const uint8_t* pBuffer, int32_t length); 70 bool LoadFontInternal(const RetainPtr<CFX_SeekableStreamProxy>& pFontStream, 71 bool bSaveStream); 72 #endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ 73 bool LoadFontInternal(std::unique_ptr<CFX_Font> pInternalFont); 74 bool LoadFontInternal(CFX_Font* pExternalFont); 75 bool InitFont(); 76 std::pair<int32_t, RetainPtr<CFGAS_GEFont>> GetGlyphIndexAndFont( 77 wchar_t wUnicode, 78 bool bRecursive); 79 WideString GetFamilyName() const; 80 81 bool m_bUseLogFontStyle; 82 uint32_t m_dwLogFontStyle; 83 CFX_Font* m_pFont; 84 bool m_bExternalFont; 85 RetainPtr<CFGAS_GEFont> m_pSrcFont; // Only set by ctor, so no cycles. 86 CFGAS_FontMgr::ObservedPtr m_pFontMgr; 87 CFGAS_PDFFontMgr::ObservedPtr m_pProvider; 88 RetainPtr<CFX_SeekableStreamProxy> m_pStream; 89 RetainPtr<IFX_SeekableReadStream> m_pFileRead; 90 std::unique_ptr<CFX_UnicodeEncoding> m_pFontEncoding; 91 std::map<wchar_t, int32_t> m_CharWidthMap; 92 std::map<wchar_t, CFX_Rect> m_BBoxMap; 93 std::vector<RetainPtr<CFGAS_GEFont>> m_SubstFonts; 94 std::map<wchar_t, RetainPtr<CFGAS_GEFont>> m_FontMapper; 95 }; 96 97 #endif // XFA_FGAS_FONT_CFGAS_GEFONT_H_ 98