1 // Copyright 2016 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 CORE_FXGE_CFX_FOLDERFONTINFO_H_
8 #define CORE_FXGE_CFX_FOLDERFONTINFO_H_
9 
10 #include <map>
11 #include <memory>
12 #include <vector>
13 
14 #include "core/fxcrt/unowned_ptr.h"
15 #include "core/fxge/cfx_fontmapper.h"
16 #include "core/fxge/systemfontinfo_iface.h"
17 
18 class CFX_FolderFontInfo : public SystemFontInfoIface {
19  public:
20   CFX_FolderFontInfo();
21   ~CFX_FolderFontInfo() override;
22 
23   void AddPath(const ByteString& path);
24 
25   // IFX_SytemFontInfo:
26   bool EnumFontList(CFX_FontMapper* pMapper) override;
27   void* MapFont(int weight,
28                 bool bItalic,
29                 int charset,
30                 int pitch_family,
31                 const char* family) override;
32   void* GetFont(const char* face) override;
33   uint32_t GetFontData(void* hFont,
34                        uint32_t table,
35                        pdfium::span<uint8_t> buffer) override;
36   void DeleteFont(void* hFont) override;
37   bool GetFaceName(void* hFont, ByteString* name) override;
38   bool GetFontCharset(void* hFont, int* charset) override;
39 
40  protected:
41   class FontFaceInfo {
42    public:
43     FontFaceInfo(ByteString filePath,
44                  ByteString faceName,
45                  ByteString fontTables,
46                  uint32_t fontOffset,
47                  uint32_t fileSize);
48 
49     const ByteString m_FilePath;
50     const ByteString m_FaceName;
51     const ByteString m_FontTables;
52     const uint32_t m_FontOffset;
53     const uint32_t m_FileSize;
54     uint32_t m_Styles;
55     uint32_t m_Charsets;
56   };
57 
58   void ScanPath(const ByteString& path);
59   void ScanFile(const ByteString& path);
60   void ReportFace(const ByteString& path,
61                   FILE* pFile,
62                   uint32_t filesize,
63                   uint32_t offset);
64   void* GetSubstFont(const ByteString& face);
65   void* FindFont(int weight,
66                  bool bItalic,
67                  int charset,
68                  int pitch_family,
69                  const char* family,
70                  bool bMatchName);
71 
72   std::map<ByteString, std::unique_ptr<FontFaceInfo>> m_FontList;
73   std::vector<ByteString> m_PathList;
74   UnownedPtr<CFX_FontMapper> m_pMapper;
75 };
76 
77 #endif  // CORE_FXGE_CFX_FOLDERFONTINFO_H_
78