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