• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 FPDFSDK_PWL_CPWL_FONT_MAP_H_
8 #define FPDFSDK_PWL_CPWL_FONT_MAP_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fpdfdoc/ipvt_fontmap.h"
14 #include "core/fxcrt/fx_codepage.h"
15 #include "public/fpdf_sysfontinfo.h"
16 
17 class CPDF_Document;
18 class CFX_SystemHandler;
19 
20 struct CPWL_FontMap_Data {
21   CPDF_Font* pFont;
22   int32_t nCharset;
23   ByteString sFontName;
24 };
25 
26 struct CPWL_FontMap_Native {
27   int32_t nCharset;
28   ByteString sFontName;
29 };
30 
31 class CPWL_FontMap : public IPVT_FontMap {
32  public:
33   explicit CPWL_FontMap(CFX_SystemHandler* pSystemHandler);
34   ~CPWL_FontMap() override;
35 
36   // IPVT_FontMap
37   CPDF_Font* GetPDFFont(int32_t nFontIndex) override;
38   ByteString GetPDFFontAlias(int32_t nFontIndex) override;
39   int32_t GetWordFontIndex(uint16_t word,
40                            int32_t nCharset,
41                            int32_t nFontIndex) override;
42   int32_t CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) override;
43   int32_t CharSetFromUnicode(uint16_t word, int32_t nOldCharset) override;
44 
45   const CPWL_FontMap_Data* GetFontMapData(int32_t nIndex) const;
46   static int32_t GetNativeCharset();
47   ByteString GetNativeFontName(int32_t nCharset);
48 
49   static ByteString GetDefaultFontByCharset(int32_t nCharset);
50   static const FPDF_CharsetFontMap defaultTTFMap[];
51 
52  protected:
53   virtual void Initialize();
54   virtual CPDF_Document* GetDocument();
55   virtual CPDF_Font* FindFontSameCharset(ByteString* sFontAlias,
56                                          int32_t nCharset);
57   virtual void AddedFont(CPDF_Font* pFont, const ByteString& sFontAlias);
58 
59   bool KnowWord(int32_t nFontIndex, uint16_t word);
60 
61   void Empty();
62   int32_t GetFontIndex(const ByteString& sFontName,
63                        int32_t nCharset,
64                        bool bFind);
65   int32_t AddFontData(CPDF_Font* pFont,
66                       const ByteString& sFontAlias,
67                       int32_t nCharset = FX_CHARSET_Default);
68 
69   ByteString EncodeFontAlias(const ByteString& sFontName, int32_t nCharset);
70   ByteString EncodeFontAlias(const ByteString& sFontName);
71 
72   std::vector<std::unique_ptr<CPWL_FontMap_Data>> m_Data;
73   std::vector<std::unique_ptr<CPWL_FontMap_Native>> m_NativeFont;
74 
75  private:
76   int32_t FindFont(const ByteString& sFontName,
77                    int32_t nCharset = FX_CHARSET_Default);
78 
79   ByteString GetNativeFont(int32_t nCharset);
80   CPDF_Font* AddFontToDocument(CPDF_Document* pDoc,
81                                ByteString& sFontName,
82                                uint8_t nCharset);
83   bool IsStandardFont(const ByteString& sFontName);
84   CPDF_Font* AddStandardFont(CPDF_Document* pDoc, ByteString& sFontName);
85   CPDF_Font* AddSystemFont(CPDF_Document* pDoc,
86                            ByteString& sFontName,
87                            uint8_t nCharset);
88 
89   std::unique_ptr<CPDF_Document> m_pPDFDoc;
90   UnownedPtr<CFX_SystemHandler> const m_pSystemHandler;
91 };
92 
93 #endif  // FPDFSDK_PWL_CPWL_FONT_MAP_H_
94