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