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 CORE_FPDFDOC_CPDF_BAFONTMAP_H_ 8 #define CORE_FPDFDOC_CPDF_BAFONTMAP_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "core/fpdfdoc/ipvt_fontmap.h" 14 #include "core/fxcrt/fx_codepage.h" 15 #include "core/fxcrt/retain_ptr.h" 16 #include "core/fxcrt/unowned_ptr.h" 17 18 class CPDF_Dictionary; 19 class CPDF_Document; 20 21 class CPDF_BAFontMap final : public IPVT_FontMap { 22 public: 23 static FX_Charset GetNativeCharset(); 24 25 CPDF_BAFontMap(CPDF_Document* pDocument, 26 RetainPtr<CPDF_Dictionary> pAnnotDict, 27 const ByteString& sAPType); 28 ~CPDF_BAFontMap() override; 29 30 // IPVT_FontMap: 31 RetainPtr<CPDF_Font> GetPDFFont(int32_t nFontIndex) override; 32 ByteString GetPDFFontAlias(int32_t nFontIndex) override; 33 int32_t GetWordFontIndex(uint16_t word, 34 FX_Charset nCharset, 35 int32_t nFontIndex) override; 36 int32_t CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) override; 37 FX_Charset CharSetFromUnicode(uint16_t word, FX_Charset nOldCharset) override; 38 39 private: 40 struct Data { 41 Data(); 42 ~Data(); 43 44 FX_Charset nCharset = FX_Charset::kANSI; 45 RetainPtr<CPDF_Font> pFont; 46 ByteString sFontName; 47 }; 48 49 struct Native { 50 FX_Charset nCharset; 51 ByteString sFontName; 52 }; 53 54 RetainPtr<CPDF_Font> FindFontSameCharset(ByteString* sFontAlias, 55 FX_Charset nCharset); 56 RetainPtr<CPDF_Font> FindResFontSameCharset(const CPDF_Dictionary* pResDict, 57 ByteString* sFontAlias, 58 FX_Charset nCharset); 59 RetainPtr<CPDF_Font> GetAnnotDefaultFont(ByteString* sAlias); 60 void AddFontToAnnotDict(const RetainPtr<CPDF_Font>& pFont, 61 const ByteString& sAlias); 62 63 bool KnowWord(int32_t nFontIndex, uint16_t word); 64 65 int32_t GetFontIndex(const ByteString& sFontName, 66 FX_Charset nCharset, 67 bool bFind); 68 int32_t AddFontData(const RetainPtr<CPDF_Font>& pFont, 69 const ByteString& sFontAlias, 70 FX_Charset nCharset); 71 72 int32_t FindFont(const ByteString& sFontName, FX_Charset nCharset); 73 ByteString GetNativeFontName(FX_Charset nCharset); 74 ByteString GetCachedNativeFontName(FX_Charset nCharset); 75 RetainPtr<CPDF_Font> AddFontToDocument(ByteString sFontName, 76 FX_Charset nCharset); 77 RetainPtr<CPDF_Font> AddStandardFont(ByteString sFontName); 78 RetainPtr<CPDF_Font> AddSystemFont(ByteString sFontName, FX_Charset nCharset); 79 80 std::vector<std::unique_ptr<Data>> m_Data; 81 std::vector<std::unique_ptr<Native>> m_NativeFont; 82 UnownedPtr<CPDF_Document> const m_pDocument; 83 RetainPtr<CPDF_Dictionary> const m_pAnnotDict; 84 RetainPtr<CPDF_Font> m_pDefaultFont; 85 ByteString m_sDefaultFontName; 86 const ByteString m_sAPType; 87 }; 88 89 #endif // CORE_FPDFDOC_CPDF_BAFONTMAP_H_ 90