1 // Copyright 2016 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_FXGE_CFX_FONTMGR_H_ 8 #define CORE_FXGE_CFX_FONTMGR_H_ 9 10 #include <stddef.h> 11 #include <stdint.h> 12 13 #include <map> 14 #include <memory> 15 #include <tuple> 16 17 #include "core/fxcrt/bytestring.h" 18 #include "core/fxcrt/fixed_uninit_data_vector.h" 19 #include "core/fxcrt/observed_ptr.h" 20 #include "core/fxcrt/retain_ptr.h" 21 #include "core/fxge/cfx_face.h" 22 #include "core/fxge/freetype/fx_freetype.h" 23 #include "third_party/base/span.h" 24 25 class CFX_FontMapper; 26 27 class CFX_FontMgr { 28 public: 29 class FontDesc final : public Retainable, public Observable { 30 public: 31 CONSTRUCT_VIA_MAKE_RETAIN; 32 ~FontDesc() override; 33 FontData()34 pdfium::span<const uint8_t> FontData() const { return m_pFontData; } 35 void SetFace(size_t index, CFX_Face* face); 36 CFX_Face* GetFace(size_t index) const; 37 38 private: 39 explicit FontDesc(FixedUninitDataVector<uint8_t> data); 40 41 const FixedUninitDataVector<uint8_t> m_pFontData; 42 ObservedPtr<CFX_Face> m_TTCFaces[16]; 43 }; 44 45 // `index` must be less than `CFX_FontMapper::kNumStandardFonts`. 46 static pdfium::span<const uint8_t> GetStandardFont(size_t index); 47 static pdfium::span<const uint8_t> GetGenericSansFont(); 48 static pdfium::span<const uint8_t> GetGenericSerifFont(); 49 50 CFX_FontMgr(); 51 ~CFX_FontMgr(); 52 53 RetainPtr<FontDesc> GetCachedFontDesc(const ByteString& face_name, 54 int weight, 55 bool bItalic); 56 RetainPtr<FontDesc> AddCachedFontDesc(const ByteString& face_name, 57 int weight, 58 bool bItalic, 59 FixedUninitDataVector<uint8_t> data); 60 61 RetainPtr<FontDesc> GetCachedTTCFontDesc(size_t ttc_size, uint32_t checksum); 62 RetainPtr<FontDesc> AddCachedTTCFontDesc(size_t ttc_size, 63 uint32_t checksum, 64 FixedUninitDataVector<uint8_t> data); 65 66 RetainPtr<CFX_Face> NewFixedFace(RetainPtr<FontDesc> pDesc, 67 pdfium::span<const uint8_t> span, 68 size_t face_index); 69 70 // Always present. GetBuiltinMapper()71 CFX_FontMapper* GetBuiltinMapper() const { return m_pBuiltinMapper.get(); } 72 GetFTLibrary()73 FXFT_LibraryRec* GetFTLibrary() const { return m_FTLibrary.get(); } FTLibrarySupportsHinting()74 bool FTLibrarySupportsHinting() const { return m_FTLibrarySupportsHinting; } 75 76 private: 77 bool FreeTypeVersionSupportsHinting() const; 78 bool SetLcdFilterMode() const; 79 80 // Must come before |m_pBuiltinMapper| and |m_FaceMap|. 81 ScopedFXFTLibraryRec const m_FTLibrary; 82 std::unique_ptr<CFX_FontMapper> m_pBuiltinMapper; 83 std::map<std::tuple<ByteString, int, bool>, ObservedPtr<FontDesc>> m_FaceMap; 84 std::map<std::tuple<size_t, uint32_t>, ObservedPtr<FontDesc>> m_TTCFaceMap; 85 const bool m_FTLibrarySupportsHinting; 86 }; 87 88 #endif // CORE_FXGE_CFX_FONTMGR_H_ 89