1 // Copyright 2014 PDFium Authors. All rights reserved.
\r
2 // Use of this source code is governed by a BSD-style license that can be
\r
3 // found in the LICENSE file.
\r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
\r
7 #ifndef _FX_FONTMGR_IMP
\r
8 #define _FX_FONTMGR_IMP
\r
9 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
\r
10 FX_INT32 FX_GetSimilarValue(FX_LPCFONTDESCRIPTOR pFont, FX_DWORD dwFontStyles);
\r
11 FX_LPCFONTDESCRIPTOR FX_DefFontMatcher(FX_LPFONTMATCHPARAMS pParams, const CFX_FontDescriptors &fonts, FX_LPVOID pUserData);
\r
12 class CFX_StdFontMgrImp : public IFX_FontMgr, public CFX_Object
\r
15 CFX_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator, FX_LPMatchFont pMatcher, FX_LPVOID pUserData);
\r
16 ~CFX_StdFontMgrImp();
\r
17 virtual void Release()
\r
21 virtual IFX_Font* GetDefFontByCodePage(FX_WORD wCodePage, FX_DWORD dwFontStyles, FX_LPCWSTR pszFontFamily = NULL);
\r
22 virtual IFX_Font* GetDefFontByCharset(FX_BYTE nCharset, FX_DWORD dwFontStyles, FX_LPCWSTR pszFontFamily = NULL);
\r
23 virtual IFX_Font* GetDefFontByUnicode(FX_WCHAR wUnicode, FX_DWORD dwFontStyles, FX_LPCWSTR pszFontFamily = NULL);
\r
24 virtual IFX_Font* GetDefFontByLanguage(FX_WORD wLanguage, FX_DWORD dwFontStyles, FX_LPCWSTR pszFontFamily = NULL);
\r
25 virtual IFX_Font* LoadFont(FX_LPCWSTR pszFontFamily, FX_DWORD dwFontStyles, FX_WORD wCodePage = 0xFFFF);
\r
26 virtual IFX_Font* LoadFont(FX_LPCBYTE pBuffer, FX_INT32 iLength);
\r
27 virtual IFX_Font* LoadFont(FX_LPCWSTR pszFileName);
\r
28 virtual IFX_Font* LoadFont(IFX_Stream *pFontStream, FX_LPCWSTR pszFontAlias = NULL, FX_DWORD dwFontStyles = 0, FX_WORD wCodePage = 0, FX_BOOL bSaveStream = FALSE);
\r
29 virtual IFX_Font* LoadFont(IFX_Font *pSrcFont, FX_DWORD dwFontStyles, FX_WORD wCodePage = 0xFFFF);
\r
30 virtual void ClearFontCache();
\r
31 virtual void RemoveFont(IFX_Font *pFont);
\r
33 FX_LPMatchFont m_pMatcher;
\r
34 FX_LPEnumAllFonts m_pEnumerator;
\r
35 CFX_FontDescriptors m_FontFaces;
\r
36 CFX_PtrArray m_Fonts;
\r
37 CFX_MapPtrToPtr m_CPFonts;
\r
38 CFX_MapPtrToPtr m_FamilyFonts;
\r
39 CFX_MapPtrToPtr m_UnicodeFonts;
\r
40 CFX_MapPtrToPtr m_BufferFonts;
\r
41 CFX_MapPtrToPtr m_FileFonts;
\r
42 CFX_MapPtrToPtr m_StreamFonts;
\r
43 CFX_MapPtrToPtr m_DeriveFonts;
\r
44 FX_LPVOID m_pUserData;
\r
45 void RemoveFont(CFX_MapPtrToPtr &fontMap, IFX_Font *pFont);
\r
46 FX_LPCFONTDESCRIPTOR FindFont(FX_LPCWSTR pszFontFamily, FX_DWORD dwFontStyles, FX_DWORD dwMatchFlags, FX_WORD wCodePage, FX_DWORD dwUSB = 999, FX_WCHAR wUnicode = 0);
\r
47 IFX_Font* GetFont(FX_LPCFONTDESCRIPTOR pFD, FX_DWORD dwFontStyles);
\r
49 FX_DWORD FX_GetGdiFontStyles(const LOGFONTW &lf);
\r
51 class CFX_FontDescriptor : public CFX_Object
\r
54 CFX_FontDescriptor()
\r
55 : m_pFileAccess(NULL)
\r
59 m_dwUsb[0] = m_dwUsb[1] = m_dwUsb[2] = m_dwUsb[3] = 0;
\r
60 m_dwCsb[0] = m_dwCsb[1] = 0;
\r
62 ~CFX_FontDescriptor()
\r
64 if (NULL != m_pFileAccess) {
\r
65 m_pFileAccess->Release();
\r
68 IFX_FileAccess* m_pFileAccess;
\r
69 FX_INT32 m_nFaceIndex;
\r
70 CFX_WideString m_wsFaceName;
\r
71 CFX_WideStringArray m_wsFamilyNames;
\r
72 FX_DWORD m_dwFontStyles;
\r
73 FX_DWORD m_dwUsb[4];
\r
74 FX_DWORD m_dwCsb[2];
\r
76 typedef CFX_ArrayTemplate<CFX_FontDescriptor*> CFX_FontDescriptors;
\r
77 struct FX_FontDescriptorInfo {
\r
79 CFX_FontDescriptor* pFont;
\r
81 FX_BOOL operator > (const FX_FontDescriptorInfo& x)
\r
83 return this->nPenalty > x.nPenalty;
\r
85 FX_BOOL operator < (const FX_FontDescriptorInfo& x)
\r
87 return this->nPenalty < x.nPenalty;
\r
89 FX_BOOL operator == (const FX_FontDescriptorInfo& x)
\r
91 return this->nPenalty == x.nPenalty;
\r
94 typedef CFX_ArrayTemplate<FX_FontDescriptorInfo> CFX_FontDescriptorInfos;
\r
95 struct FX_HandleParentPath : public CFX_Object {
\r
96 FX_HandleParentPath()
\r
99 FX_HandleParentPath(const FX_HandleParentPath& x)
\r
101 pFileHandle = x.pFileHandle;
\r
102 bsParentPath = x.bsParentPath;
\r
105 CFX_ByteString bsParentPath;
\r
107 class CFX_FontSourceEnum_File : public IFX_FontSourceEnum, public CFX_Object
\r
110 CFX_FontSourceEnum_File();
\r
111 virtual void Release()
\r
115 virtual FX_POSITION GetStartPosition(FX_LPVOID pUserData = NULL);
\r
116 virtual IFX_FileAccess* GetNext(FX_POSITION& pos, FX_LPVOID pUserData = NULL);
\r
118 CFX_ByteString GetNextFile();
\r
119 CFX_WideString m_wsNext;
\r
120 CFX_ObjectArray<FX_HandleParentPath> m_FolderQueue;
\r
121 CFX_ByteStringArray m_FolderPaths;
\r
123 typedef CFX_MapPtrTemplate<FX_DWORD, IFX_FileAccess*> CFX_HashFileMap;
\r
124 typedef CFX_MapPtrTemplate<FX_DWORD, IFX_Font*> CFX_HashFontMap;
\r
125 typedef CFX_MapPtrTemplate<FX_DWORD, CFX_FontDescriptorInfos*> CFX_HashFontDescsMap;
\r
126 typedef CFX_MapPtrTemplate<FX_DWORD, CFX_ArrayTemplate<IFX_Font*>* > CFX_HashFontsMap;
\r
127 typedef CFX_MapPtrTemplate<FX_WCHAR, IFX_Font*> CFX_UnicodeFontMap;
\r
128 typedef CFX_MapPtrTemplate<IFX_FileAccess*, CFX_ArrayTemplate<IFX_Font*>* > CFX_FileFontMap;
\r
129 typedef CFX_MapPtrTemplate<IFX_Font*, IFX_FileRead*> CFX_FonStreamtMap;
\r
130 class CFX_FontMgrImp : public IFX_FontMgr, public CFX_Object
\r
133 CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum, IFX_FontMgrDelegate* pDelegate = NULL, FX_LPVOID pUserData = NULL);
\r
134 virtual void Release();
\r
135 virtual IFX_Font* GetDefFontByCodePage(FX_WORD wCodePage, FX_DWORD dwFontStyles, FX_LPCWSTR pszFontFamily = NULL);
\r
136 virtual IFX_Font* GetDefFontByCharset(FX_BYTE nCharset, FX_DWORD dwFontStyles, FX_LPCWSTR pszFontFamily = NULL);
\r
137 virtual IFX_Font* GetDefFontByUnicode(FX_WCHAR wUnicode, FX_DWORD dwFontStyles, FX_LPCWSTR pszFontFamily = NULL);
\r
138 virtual IFX_Font* GetDefFontByLanguage(FX_WORD wLanguage, FX_DWORD dwFontStyles, FX_LPCWSTR pszFontFamily = NULL);
\r
139 virtual IFX_Font* GetFontByCodePage(FX_WORD wCodePage, FX_DWORD dwFontStyles, FX_LPCWSTR pszFontFamily = NULL);
\r
140 virtual IFX_Font* GetFontByCharset(FX_BYTE nCharset, FX_DWORD dwFontStyles, FX_LPCWSTR pszFontFamily = NULL);
\r
141 virtual IFX_Font* GetFontByUnicode(FX_WCHAR wUnicode, FX_DWORD dwFontStyles, FX_LPCWSTR pszFontFamily = NULL);
\r
142 virtual IFX_Font* GetFontByLanguage(FX_WORD wLanguage, FX_DWORD dwFontStyles, FX_LPCWSTR pszFontFamily = NULL);
\r
143 virtual IFX_Font* LoadFont(FX_LPCBYTE pBuffer, FX_INT32 iLength, FX_INT32 iFaceIndex, FX_INT32* pFaceCount);
\r
144 virtual IFX_Font* LoadFont(FX_LPCWSTR pszFileName, FX_INT32 iFaceIndex, FX_INT32* pFaceCount);
\r
145 virtual IFX_Font* LoadFont(IFX_Stream* pFontStream, FX_INT32 iFaceIndex, FX_INT32* pFaceCount, FX_BOOL bSaveStream = FALSE);
\r
146 virtual void ClearFontCache();
\r
147 virtual void RemoveFont(IFX_Font* pFont);
\r
148 FX_BOOL EnumFonts();
\r
150 void ReportFace(FXFT_Face pFace, CFX_FontDescriptors& Fonts, IFX_FileAccess* pFontAccess);
\r
151 void GetNames(FX_LPCBYTE name_table, CFX_WideStringArray& Names);
\r
152 void GetCharsets(FXFT_Face pFace, CFX_WordArray& Charsets);
\r
153 void GetUSBCSB(FXFT_Face pFace, FX_DWORD* USB, FX_DWORD* CSB);
\r
154 FX_DWORD GetFlags(FXFT_Face pFace);
\r
155 CFX_FontDescriptors m_InstalledFonts;
\r
156 FX_BOOL VerifyUnicode(CFX_FontDescriptor* pDesc, FX_WCHAR wcUnicode);
\r
157 FX_BOOL VerifyUnicode(IFX_Font* pFont, FX_WCHAR wcUnicode);
\r
158 void NormalizeFontName( CFX_WideString& FontName );
\r
159 FX_INT32 IsPartName(const CFX_WideString& Name1, const CFX_WideString& Name2);
\r
160 FX_INT32 MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, FX_WORD wCodePage, FX_DWORD dwFontStyles, const CFX_WideString& FontName, FX_WCHAR wcUnicode = 0xFFFE);
\r
161 FX_INT32 CalcPenalty(CFX_FontDescriptor* pInstalled, FX_WORD wCodePage, FX_DWORD dwFontStyles, const CFX_WideString& FontName, FX_WCHAR wcUnicode = 0xFFFE);
\r
162 IFX_Font* LoadFont(IFX_FileAccess* pFontAccess, FX_INT32 iFaceIndex, FX_INT32* pFaceCount, FX_BOOL bWantCache = FALSE);
\r
163 FXFT_Face LoadFace(IFX_FileRead* pFontStream, FX_INT32 iFaceIndex);
\r
164 CFX_HashFontDescsMap m_Hash2CandidateList;
\r
165 CFX_HashFontsMap m_Hash2Fonts;
\r
166 CFX_HashFileMap m_Hash2FileAccess;
\r
167 CFX_HashFontMap m_FileAccess2IFXFont;
\r
168 CFX_FonStreamtMap m_IFXFont2FileRead;
\r
169 CFX_UnicodeFontMap m_FailedUnicodes2NULL;
\r
170 IFX_FontSourceEnum* m_pFontSource;
\r
171 IFX_FontMgrDelegate* m_pDelegate;
\r
172 FX_LPVOID m_pUserData;
\r