summaryrefslogtreecommitdiff
path: root/xfa/src/fgas/src/font/fx_stdfontmgr.h
blob: 603a0f5d3c8d8e9c985904280d9288e59d0d5ac9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef _FX_FONTMGR_IMP
#define _FX_FONTMGR_IMP
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
int32_t FX_GetSimilarValue(FX_LPCFONTDESCRIPTOR pFont, FX_DWORD dwFontStyles);
FX_LPCFONTDESCRIPTOR FX_DefFontMatcher(FX_LPFONTMATCHPARAMS pParams,
                                       const CFX_FontDescriptors& fonts,
                                       void* pUserData);
class CFX_StdFontMgrImp : public IFX_FontMgr {
 public:
  CFX_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator,
                    FX_LPMatchFont pMatcher,
                    void* pUserData);
  ~CFX_StdFontMgrImp();
  virtual void Release() { delete this; }
  virtual IFX_Font* GetDefFontByCodePage(FX_WORD wCodePage,
                                         FX_DWORD dwFontStyles,
                                         const FX_WCHAR* pszFontFamily = NULL);
  virtual IFX_Font* GetDefFontByCharset(uint8_t nCharset,
                                        FX_DWORD dwFontStyles,
                                        const FX_WCHAR* pszFontFamily = NULL);
  virtual IFX_Font* GetDefFontByUnicode(FX_WCHAR wUnicode,
                                        FX_DWORD dwFontStyles,
                                        const FX_WCHAR* pszFontFamily = NULL);
  virtual IFX_Font* GetDefFontByLanguage(FX_WORD wLanguage,
                                         FX_DWORD dwFontStyles,
                                         const FX_WCHAR* pszFontFamily = NULL);
  virtual IFX_Font* LoadFont(const FX_WCHAR* pszFontFamily,
                             FX_DWORD dwFontStyles,
                             FX_WORD wCodePage = 0xFFFF);
  virtual IFX_Font* LoadFont(const uint8_t* pBuffer, int32_t iLength);
  virtual IFX_Font* LoadFont(const FX_WCHAR* pszFileName);
  virtual IFX_Font* LoadFont(IFX_Stream* pFontStream,
                             const FX_WCHAR* pszFontAlias = NULL,
                             FX_DWORD dwFontStyles = 0,
                             FX_WORD wCodePage = 0,
                             FX_BOOL bSaveStream = FALSE);
  virtual IFX_Font* LoadFont(IFX_Font* pSrcFont,
                             FX_DWORD dwFontStyles,
                             FX_WORD wCodePage = 0xFFFF);
  virtual void ClearFontCache();
  virtual void RemoveFont(IFX_Font* pFont);

 protected:
  FX_LPMatchFont m_pMatcher;
  FX_LPEnumAllFonts m_pEnumerator;
  CFX_FontDescriptors m_FontFaces;
  CFX_PtrArray m_Fonts;
  CFX_MapPtrToPtr m_CPFonts;
  CFX_MapPtrToPtr m_FamilyFonts;
  CFX_MapPtrToPtr m_UnicodeFonts;
  CFX_MapPtrToPtr m_BufferFonts;
  CFX_MapPtrToPtr m_FileFonts;
  CFX_MapPtrToPtr m_StreamFonts;
  CFX_MapPtrToPtr m_DeriveFonts;
  void* m_pUserData;
  void RemoveFont(CFX_MapPtrToPtr& fontMap, IFX_Font* pFont);
  FX_LPCFONTDESCRIPTOR FindFont(const FX_WCHAR* pszFontFamily,
                                FX_DWORD dwFontStyles,
                                FX_DWORD dwMatchFlags,
                                FX_WORD wCodePage,
                                FX_DWORD dwUSB = 999,
                                FX_WCHAR wUnicode = 0);
  IFX_Font* GetFont(FX_LPCFONTDESCRIPTOR pFD, FX_DWORD dwFontStyles);
};
FX_DWORD FX_GetGdiFontStyles(const LOGFONTW& lf);
#else
class CFX_FontDescriptor {
 public:
  CFX_FontDescriptor()
      : m_pFileAccess(NULL), m_nFaceIndex(0), m_dwFontStyles(0) {
    m_dwUsb[0] = m_dwUsb[1] = m_dwUsb[2] = m_dwUsb[3] = 0;
    m_dwCsb[0] = m_dwCsb[1] = 0;
  }
  ~CFX_FontDescriptor() {
    if (NULL != m_pFileAccess) {
      m_pFileAccess->Release();
    }
  }
  IFX_FileAccess* m_pFileAccess;
  int32_t m_nFaceIndex;
  CFX_WideString m_wsFaceName;
  CFX_WideStringArray m_wsFamilyNames;
  FX_DWORD m_dwFontStyles;
  FX_DWORD m_dwUsb[4];
  FX_DWORD m_dwCsb[2];
};
typedef CFX_ArrayTemplate<CFX_FontDescriptor*> CFX_FontDescriptors;
struct FX_FontDescriptorInfo {
 public:
  CFX_FontDescriptor* pFont;
  int32_t nPenalty;
  FX_BOOL operator>(const FX_FontDescriptorInfo& x) {
    return this->nPenalty > x.nPenalty;
  };
  FX_BOOL operator<(const FX_FontDescriptorInfo& x) {
    return this->nPenalty < x.nPenalty;
  };
  FX_BOOL operator==(const FX_FontDescriptorInfo& x) {
    return this->nPenalty == x.nPenalty;
  };
};
typedef CFX_ArrayTemplate<FX_FontDescriptorInfo> CFX_FontDescriptorInfos;
struct FX_HandleParentPath {
  FX_HandleParentPath() {}
  FX_HandleParentPath(const FX_HandleParentPath& x) {
    pFileHandle = x.pFileHandle;
    bsParentPath = x.bsParentPath;
  }
  void* pFileHandle;
  CFX_ByteString bsParentPath;
};
class CFX_FontSourceEnum_File : public IFX_FontSourceEnum {
 public:
  CFX_FontSourceEnum_File();
  virtual void Release() { delete this; };
  virtual FX_POSITION GetStartPosition(void* pUserData = NULL);
  virtual IFX_FileAccess* GetNext(FX_POSITION& pos, void* pUserData = NULL);

 private:
  CFX_ByteString GetNextFile();
  CFX_WideString m_wsNext;
  CFX_ObjectArray<FX_HandleParentPath> m_FolderQueue;
  CFX_ByteStringArray m_FolderPaths;
};
typedef CFX_MapPtrTemplate<FX_DWORD, IFX_FileAccess*> CFX_HashFileMap;
typedef CFX_MapPtrTemplate<FX_DWORD, IFX_Font*> CFX_HashFontMap;
typedef CFX_MapPtrTemplate<FX_DWORD, CFX_FontDescriptorInfos*>
    CFX_HashFontDescsMap;
typedef CFX_MapPtrTemplate<FX_DWORD, CFX_ArrayTemplate<IFX_Font*>*>
    CFX_HashFontsMap;
typedef CFX_MapPtrTemplate<FX_WCHAR, IFX_Font*> CFX_UnicodeFontMap;
typedef CFX_MapPtrTemplate<IFX_FileAccess*, CFX_ArrayTemplate<IFX_Font*>*>
    CFX_FileFontMap;
typedef CFX_MapPtrTemplate<IFX_Font*, IFX_FileRead*> CFX_FonStreamtMap;
class CFX_FontMgrImp : public IFX_FontMgr {
 public:
  CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum,
                 IFX_FontMgrDelegate* pDelegate = NULL,
                 void* pUserData = NULL);
  virtual void Release();
  virtual IFX_Font* GetDefFontByCodePage(FX_WORD wCodePage,
                                         FX_DWORD dwFontStyles,
                                         const FX_WCHAR* pszFontFamily = NULL);
  virtual IFX_Font* GetDefFontByCharset(uint8_t nCharset,
                                        FX_DWORD dwFontStyles,
                                        const FX_WCHAR* pszFontFamily = NULL);
  virtual IFX_Font* GetDefFontByUnicode(FX_WCHAR wUnicode,
                                        FX_DWORD dwFontStyles,
                                        const FX_WCHAR* pszFontFamily = NULL);
  virtual IFX_Font* GetDefFontByLanguage(FX_WORD wLanguage,
                                         FX_DWORD dwFontStyles,
                                         const FX_WCHAR* pszFontFamily = NULL);
  virtual IFX_Font* GetFontByCodePage(FX_WORD wCodePage,
                                      FX_DWORD dwFontStyles,
                                      const FX_WCHAR* pszFontFamily = NULL);
  virtual IFX_Font* GetFontByCharset(uint8_t nCharset,
                                     FX_DWORD dwFontStyles,
                                     const FX_WCHAR* pszFontFamily = NULL);
  virtual IFX_Font* GetFontByUnicode(FX_WCHAR wUnicode,
                                     FX_DWORD dwFontStyles,
                                     const FX_WCHAR* pszFontFamily = NULL);
  virtual IFX_Font* GetFontByLanguage(FX_WORD wLanguage,
                                      FX_DWORD dwFontStyles,
                                      const FX_WCHAR* pszFontFamily = NULL);
  virtual IFX_Font* LoadFont(const uint8_t* pBuffer,
                             int32_t iLength,
                             int32_t iFaceIndex,
                             int32_t* pFaceCount);
  virtual IFX_Font* LoadFont(const FX_WCHAR* pszFileName,
                             int32_t iFaceIndex,
                             int32_t* pFaceCount);
  virtual IFX_Font* LoadFont(IFX_Stream* pFontStream,
                             int32_t iFaceIndex,
                             int32_t* pFaceCount,
                             FX_BOOL bSaveStream = FALSE);
  virtual IFX_Font* LoadFont(const CFX_WideString& wsFaceName,
                             int32_t iFaceIndex,
                             int32_t* pFaceCount);
  virtual void ClearFontCache();
  virtual void RemoveFont(IFX_Font* pFont);
  FX_BOOL EnumFonts();
  FX_BOOL EnumFontsFromFontMapper();
  FX_BOOL EnumFontsFromFiles();

 protected:
  void ReportFace(FXFT_Face pFace,
                  CFX_FontDescriptors& Fonts,
                  IFX_FileAccess* pFontAccess);
  void ReportFaces(IFX_FileRead* pFontStream);
  void GetNames(const uint8_t* name_table, CFX_WideStringArray& Names);
  void GetCharsets(FXFT_Face pFace, CFX_WordArray& Charsets);
  void GetUSBCSB(FXFT_Face pFace, FX_DWORD* USB, FX_DWORD* CSB);
  FX_DWORD GetFlags(FXFT_Face pFace);
  CFX_FontDescriptors m_InstalledFonts;
  FX_BOOL VerifyUnicode(CFX_FontDescriptor* pDesc, FX_WCHAR wcUnicode);
  FX_BOOL VerifyUnicode(IFX_Font* pFont, FX_WCHAR wcUnicode);
  int32_t IsPartName(const CFX_WideString& Name1, const CFX_WideString& Name2);
  int32_t MatchFonts(CFX_FontDescriptorInfos& MatchedFonts,
                     FX_WORD wCodePage,
                     FX_DWORD dwFontStyles,
                     const CFX_WideString& FontName,
                     FX_WCHAR wcUnicode = 0xFFFE);
  int32_t CalcPenalty(CFX_FontDescriptor* pInstalled,
                      FX_WORD wCodePage,
                      FX_DWORD dwFontStyles,
                      const CFX_WideString& FontName,
                      FX_WCHAR wcUnicode = 0xFFFE);
  IFX_Font* LoadFont(IFX_FileAccess* pFontAccess,
                     int32_t iFaceIndex,
                     int32_t* pFaceCount,
                     FX_BOOL bWantCache = FALSE);
  FXFT_Face LoadFace(IFX_FileRead* pFontStream, int32_t iFaceIndex);
  IFX_FileRead* CreateFontStream(CFX_FontMapper* pFontMapper,
                                 IFX_SystemFontInfo* pSystemFontInfo,
                                 FX_DWORD index);
  CFX_HashFontDescsMap m_Hash2CandidateList;
  CFX_HashFontsMap m_Hash2Fonts;
  CFX_HashFileMap m_Hash2FileAccess;
  CFX_HashFontMap m_FileAccess2IFXFont;
  CFX_FonStreamtMap m_IFXFont2FileRead;
  CFX_UnicodeFontMap m_FailedUnicodes2NULL;
  IFX_FontSourceEnum* m_pFontSource;
  IFX_FontMgrDelegate* m_pDelegate;
  void* m_pUserData;
};
#endif
#endif