2ff6c0f38c058f77fc6a214bce98be2ad78a290b
[pdfium.git] / fpdfsdk / include / pdfwindow / PWL_FontMap.h
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 _PWL_FONTMAP_H_
8 #define _PWL_FONTMAP_H_
9
10 #include "../../../public/fpdf_sysfontinfo.h"
11 #include "../fxedit/fx_edit.h"
12
13 class CPDF_Document;
14 class IFX_SystemHandler;
15
16 struct CPWL_FontMap_Data
17 {
18         CPDF_Font*                      pFont;
19         FX_INT32                        nCharset;
20         CFX_ByteString          sFontName;
21 };
22
23 struct CPWL_FontMap_Native
24 {
25         FX_INT32                        nCharset;
26         CFX_ByteString          sFontName;
27 };
28
29 #ifndef ANSI_CHARSET
30
31 #define ANSI_CHARSET            0
32 #define DEFAULT_CHARSET         1
33 #define SYMBOL_CHARSET          2
34 #define SHIFTJIS_CHARSET        128
35 #define HANGEUL_CHARSET         129
36 #define HANGUL_CHARSET          129
37 #define GB2312_CHARSET          134
38 #define CHINESEBIG5_CHARSET     136
39 #define OEM_CHARSET             255
40 #define JOHAB_CHARSET           130
41 #define HEBREW_CHARSET          177
42 #define ARABIC_CHARSET          178
43 #define GREEK_CHARSET           161
44 #define TURKISH_CHARSET         162
45 #define VIETNAMESE_CHARSET      163
46 #define THAI_CHARSET            222
47 #define EASTEUROPE_CHARSET      238
48 #define RUSSIAN_CHARSET         204
49 #define BALTIC_CHARSET          186
50
51 #endif
52
53 #ifndef PWL_CLASS
54
55         #ifdef FX_READER_DLL
56                 #define PWL_CLASS               __declspec(dllexport)
57         #else
58                 #define PWL_CLASS
59         #endif
60 #endif
61
62 class PWL_CLASS CPWL_FontMap : public IFX_Edit_FontMap
63 {
64 public:
65         CPWL_FontMap(IFX_SystemHandler* pSystemHandler);
66         virtual ~CPWL_FontMap();
67
68         virtual CPDF_Font*                                                      GetPDFFont(FX_INT32 nFontIndex);
69         virtual CFX_ByteString                                          GetPDFFontAlias(FX_INT32 nFontIndex);
70         virtual FX_INT32                                                        GetWordFontIndex(FX_WORD word, FX_INT32 nCharset, FX_INT32 nFontIndex);
71         virtual FX_INT32                                                        CharCodeFromUnicode(FX_INT32 nFontIndex, FX_WORD word);
72         virtual FX_INT32                                                        CharSetFromUnicode(FX_WORD word, FX_INT32 nOldCharset);
73
74 public:
75         virtual void                                                            Initial(FX_LPCSTR fontname = NULL);
76         void                                                                            SetSystemHandler(IFX_SystemHandler* pSystemHandler);
77
78         FX_INT32                                                                        GetFontMapCount() const;
79         const CPWL_FontMap_Data*                                        GetFontMapData(FX_INT32 nIndex) const;
80
81 public:
82         static FX_INT32                                                         GetNativeCharset();
83         CFX_ByteString                                                          GetNativeFontName(FX_INT32 nCharset);
84
85         static CFX_ByteString                                           GetDefaultFontByCharset(FX_INT32 nCharset);
86
87         CPDF_Font*                                                                      AddFontToDocument(CPDF_Document* pDoc, CFX_ByteString& sFontName, FX_BYTE nCharset);
88         static FX_BOOL                                                          IsStandardFont(const CFX_ByteString& sFontName);                                                        
89         CPDF_Font*                                                                      AddStandardFont(CPDF_Document* pDoc, CFX_ByteString& sFontName);
90         CPDF_Font*                                                                      AddSystemFont(CPDF_Document* pDoc, CFX_ByteString& sFontName, 
91                                                                                                         FX_BYTE nCharset);
92
93 protected:
94         virtual CPDF_Font*                                                      FindFontSameCharset(CFX_ByteString& sFontAlias, FX_INT32 nCharset);
95         virtual void                                                            AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias);
96         FX_BOOL                                                                         KnowWord(FX_INT32 nFontIndex, FX_WORD word);
97
98         virtual CPDF_Document*                                          GetDocument();
99
100         void                                                                            Empty();
101         FX_INT32                                                                        GetFontIndex(const CFX_ByteString& sFontName, FX_INT32 nCharset, FX_BOOL bFind);
102         FX_INT32                                                                        GetPWLFontIndex(FX_WORD word, FX_INT32 nCharset);
103         FX_INT32                                                                        AddFontData(CPDF_Font* pFont, const CFX_ByteString& sFontAlias, FX_INT32 nCharset = DEFAULT_CHARSET);
104
105         CFX_ByteString                                                          EncodeFontAlias(const CFX_ByteString& sFontName, FX_INT32 nCharset);
106         CFX_ByteString                                                          EncodeFontAlias(const CFX_ByteString& sFontName);
107
108 private:
109         CFX_ByteString                                                          GetFontName(FX_INT32 nFontIndex);
110         FX_INT32                                                                        FindFont(const CFX_ByteString& sFontName, FX_INT32 nCharset = DEFAULT_CHARSET);
111
112         CFX_ByteString                                                          GetNativeFont(FX_INT32 nCharset);
113
114 public:
115     using CharsetFontMap = FPDF_CharsetFontMap;
116         static const CharsetFontMap                                     defaultTTFMap[];
117
118 protected:
119         CFX_ArrayTemplate<CPWL_FontMap_Data*>           m_aData;
120         CFX_ArrayTemplate<CPWL_FontMap_Native*>         m_aNativeFont;
121
122 private:
123         CPDF_Document*                                                          m_pPDFDoc;
124         IFX_SystemHandler*                                                      m_pSystemHandler;
125 };
126
127 class PWL_CLASS CPWL_DocFontMap : public CPWL_FontMap
128 {
129 public:
130         CPWL_DocFontMap(IFX_SystemHandler* pSystemHandler, CPDF_Document* pAttachedDoc);
131         virtual ~CPWL_DocFontMap();
132
133         virtual CPDF_Document*                                          GetDocument();
134
135 private:
136         CPDF_Document*                                                          m_pAttachedDoc;
137 };
138
139 #endif