• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ifx_systemfontinfo.h"
17 
18 class CFX_FolderFontInfo : public IFX_SystemFontInfo {
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* face) override;
32 #ifdef PDF_ENABLE_XFA
33   void* MapFontByUnicode(uint32_t dwUnicode,
34                          int weight,
35                          bool bItalic,
36                          int pitch_family) override;
37 #endif  // PDF_ENABLE_XFA
38   void* GetFont(const char* face) override;
39   uint32_t GetFontData(void* hFont,
40                        uint32_t table,
41                        uint8_t* buffer,
42                        uint32_t size) override;
43   void DeleteFont(void* hFont) override;
44   bool GetFaceName(void* hFont, ByteString* name) override;
45   bool GetFontCharset(void* hFont, int* charset) override;
46 
47  protected:
48   class FontFaceInfo {
49    public:
50     FontFaceInfo(ByteString filePath,
51                  ByteString faceName,
52                  ByteString fontTables,
53                  uint32_t fontOffset,
54                  uint32_t fileSize);
55 
56     const ByteString m_FilePath;
57     const ByteString m_FaceName;
58     const ByteString m_FontTables;
59     const uint32_t m_FontOffset;
60     const uint32_t m_FileSize;
61     uint32_t m_Styles;
62     uint32_t m_Charsets;
63   };
64 
65   void ScanPath(const ByteString& path);
66   void ScanFile(const ByteString& path);
67   void ReportFace(const ByteString& path,
68                   FILE* pFile,
69                   uint32_t filesize,
70                   uint32_t offset);
71   void* GetSubstFont(const ByteString& face);
72   void* FindFont(int weight,
73                  bool bItalic,
74                  int charset,
75                  int pitch_family,
76                  const char* family,
77                  bool bMatchName);
78 
79   std::map<ByteString, std::unique_ptr<FontFaceInfo>> m_FontList;
80   std::vector<ByteString> m_PathList;
81   UnownedPtr<CFX_FontMapper> m_pMapper;
82 };
83 
84 #endif  // CORE_FXGE_CFX_FOLDERFONTINFO_H_
85