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