1 // Copyright 2014 The PDFium Authors 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 <stdint.h> 11 12 #include <map> 13 #include <memory> 14 #include <utility> 15 #include <vector> 16 17 #include "build/build_config.h" 18 #include "core/fxcrt/fx_codepage_forward.h" 19 #include "core/fxcrt/fx_coordinates.h" 20 #include "core/fxcrt/fx_string.h" 21 #include "core/fxcrt/maybe_owned.h" 22 #include "core/fxcrt/retain_ptr.h" 23 #include "third_party/abseil-cpp/absl/types/optional.h" 24 25 class CFX_Font; 26 class CFX_UnicodeEncodingEx; 27 class CPDF_Document; 28 class CPDF_Font; 29 30 class CFGAS_GEFont final : public Retainable { 31 public: 32 CONSTRUCT_VIA_MAKE_RETAIN; 33 34 static RetainPtr<CFGAS_GEFont> LoadFont(const wchar_t* pszFontFamily, 35 uint32_t dwFontStyles, 36 FX_CodePage wCodePage); 37 static RetainPtr<CFGAS_GEFont> LoadFont(RetainPtr<CPDF_Font> pFont); 38 static RetainPtr<CFGAS_GEFont> LoadFont(std::unique_ptr<CFX_Font> pFont); 39 static RetainPtr<CFGAS_GEFont> LoadStockFont(CPDF_Document* pDoc, 40 const ByteString& font_family); 41 42 uint32_t GetFontStyles() const; 43 absl::optional<uint16_t> GetCharWidth(wchar_t wUnicode); 44 int32_t GetGlyphIndex(wchar_t wUnicode); 45 int32_t GetAscent() const; 46 int32_t GetDescent() const; 47 absl::optional<FX_RECT> GetCharBBox(wchar_t wUnicode); 48 49 RetainPtr<CFGAS_GEFont> GetSubstFont(int32_t iGlyphIndex); GetDevFont()50 CFX_Font* GetDevFont() const { return m_pFont.Get(); } 51 SetLogicalFontStyle(uint32_t dwLogFontStyle)52 void SetLogicalFontStyle(uint32_t dwLogFontStyle) { 53 m_dwLogFontStyle = dwLogFontStyle; 54 } 55 56 private: 57 CFGAS_GEFont(); 58 ~CFGAS_GEFont() override; 59 60 #if BUILDFLAG(IS_WIN) 61 bool LoadFontInternal(const wchar_t* pszFontFamily, 62 uint32_t dwFontStyles, 63 FX_CodePage wCodePage); 64 #endif 65 bool LoadFontInternal(std::unique_ptr<CFX_Font> pInternalFont); 66 bool LoadFontInternal(RetainPtr<CPDF_Font> pPDFFont); 67 bool InitFont(); 68 std::pair<int32_t, RetainPtr<CFGAS_GEFont>> GetGlyphIndexAndFont( 69 wchar_t wUnicode, 70 bool bRecursive); 71 WideString GetFamilyName() const; 72 73 absl::optional<uint32_t> m_dwLogFontStyle; 74 RetainPtr<CPDF_Font> m_pPDFFont; // Must come before |m_pFont|. 75 MaybeOwned<CFX_Font> m_pFont; // Must come before |m_pFontEncoding|. 76 std::unique_ptr<CFX_UnicodeEncodingEx> m_pFontEncoding; 77 std::map<wchar_t, absl::optional<uint16_t>> m_CharWidthMap; 78 std::map<wchar_t, FX_RECT> m_BBoxMap; 79 std::vector<RetainPtr<CFGAS_GEFont>> m_SubstFonts; 80 std::map<wchar_t, RetainPtr<CFGAS_GEFont>> m_FontMapper; 81 }; 82 83 #endif // XFA_FGAS_FONT_CFGAS_GEFONT_H_ 84