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