// Copyright 2014 PDFium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #ifndef XFA_FGAS_FONT_CFGAS_GEFONT_H_ #define XFA_FGAS_FONT_CFGAS_GEFONT_H_ #include #include #include #include #include "core/fxcrt/fx_memory.h" #include "core/fxcrt/retain_ptr.h" #include "core/fxcrt/unowned_ptr.h" #include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fgas/font/cfgas_pdffontmgr.h" class CFX_UnicodeEncoding; class CFGAS_GEFont : public Retainable { public: template friend class RetainPtr; template friend RetainPtr pdfium::MakeRetain(Args&&... args); static RetainPtr LoadFont(const wchar_t* pszFontFamily, uint32_t dwFontStyles, uint16_t wCodePage, CFGAS_FontMgr* pFontMgr); static RetainPtr LoadFont(CFX_Font* pExternalFont, CFGAS_FontMgr* pFontMgr); static RetainPtr LoadFont( std::unique_ptr pInternalFont, CFGAS_FontMgr* pFontMgr); uint32_t GetFontStyles() const; bool GetCharWidth(wchar_t wUnicode, int32_t& iWidth); int32_t GetGlyphIndex(wchar_t wUnicode); int32_t GetAscent() const; int32_t GetDescent() const; bool GetCharBBox(wchar_t wUnicode, CFX_Rect* bbox); bool GetBBox(CFX_Rect* bbox); RetainPtr GetSubstFont(int32_t iGlyphIndex); CFX_Font* GetDevFont() const { return m_pFont; } void SetFontProvider(CFGAS_PDFFontMgr* pProvider) { m_pProvider.Reset(pProvider); } void SetLogicalFontStyle(uint32_t dwLogFontStyle) { m_bUseLogFontStyle = true; m_dwLogFontStyle = dwLogFontStyle; } private: explicit CFGAS_GEFont(CFGAS_FontMgr* pFontMgr); ~CFGAS_GEFont() override; #if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ bool LoadFontInternal(const wchar_t* pszFontFamily, uint32_t dwFontStyles, uint16_t wCodePage); bool LoadFontInternal(const uint8_t* pBuffer, int32_t length); bool LoadFontInternal(const RetainPtr& pFontStream, bool bSaveStream); #endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ bool LoadFontInternal(std::unique_ptr pInternalFont); bool LoadFontInternal(CFX_Font* pExternalFont); bool InitFont(); std::pair> GetGlyphIndexAndFont( wchar_t wUnicode, bool bRecursive); WideString GetFamilyName() const; bool m_bUseLogFontStyle; uint32_t m_dwLogFontStyle; CFX_Font* m_pFont; bool m_bExternalFont; RetainPtr m_pSrcFont; // Only set by ctor, so no cycles. CFGAS_FontMgr::ObservedPtr m_pFontMgr; CFGAS_PDFFontMgr::ObservedPtr m_pProvider; RetainPtr m_pStream; RetainPtr m_pFileRead; std::unique_ptr m_pFontEncoding; std::map m_CharWidthMap; std::map m_BBoxMap; std::vector> m_SubstFonts; std::map> m_FontMapper; }; #endif // XFA_FGAS_FONT_CFGAS_GEFONT_H_