* add svn ignore
[ezgdi.git] / ezgdi / settings.h
blob167cae894920dddbb77d63a6b469b5608d045ff0
1 #pragma once
3 #define MAX_FONT_SETTINGS 16
4 #define DEFINE_FS_MEMBER(name, param) \
5 int Get##name() const { return GetParam(param); } \
6 void Set##name(int n) { SetParam(param, n); }
8 class CFontSettings
10 private:
11 int m_settings[MAX_FONT_SETTINGS];
12 static const char m_bound[MAX_FONT_SETTINGS][2];
14 enum _FontSettingsParams {
15 FSP_HINTING = 0,
16 FSP_AAMODE = 1,
17 FSP_NORMAL_WEIGHT = 2,
18 FSP_BOLD_WEIGHT = 3,
19 FSP_ITALIC_SLANT = 4,
20 FSP_KERNING = 5,
23 public:
24 CFontSettings()
26 Clear();
29 DEFINE_FS_MEMBER(HintingMode, FSP_HINTING);
30 DEFINE_FS_MEMBER(AntiAliasMode, FSP_AAMODE);
31 DEFINE_FS_MEMBER(NormalWeight, FSP_NORMAL_WEIGHT);
32 DEFINE_FS_MEMBER(BoldWeight, FSP_BOLD_WEIGHT);
33 DEFINE_FS_MEMBER(ItalicSlant, FSP_ITALIC_SLANT);
34 DEFINE_FS_MEMBER(Kerning, FSP_KERNING);
36 int GetParam(int x) const
38 Assert(0 <= x && x < MAX_FONT_SETTINGS);
39 return m_settings[x];
41 void SetParam(int x, int n)
43 Assert(0 <= x && x < MAX_FONT_SETTINGS);
44 m_settings[x] = Bound<int>(n, m_bound[x][0], m_bound[x][1]);
46 void Clear()
48 ZeroMemory(m_settings, sizeof(m_settings));
51 void SetSettings(const int* p, int count)
53 count = Min(count, MAX_FONT_SETTINGS);
54 memcpy(m_settings, p, count * sizeof(int));
58 #undef DEFINE_FS_MEMBER
61 class CFontIndividual
63 CFontSettings m_set;
64 StringHashFont m_hash;
66 public:
67 CFontIndividual()
70 CFontIndividual(LPCTSTR name)
71 : m_hash(name)
75 CFontSettings& GetIndividual() { return m_set; }
76 LPCTSTR GetName() const { return m_hash.c_str(); }
77 const StringHashFont& GetHash() const { return m_hash; }
78 bool operator ==(const CFontIndividual& x) const { return (m_hash == x.m_hash); }
81 class CFontLinkInfo
83 public:
84 enum {
85 INFOMAX = 63,
86 FONTMAX = 31,
88 private:
89 LPWSTR info[INFOMAX + 1][2 * FONTMAX + 1];
90 LPCWSTR default_font;
91 CAtlMap<CString, int> index;
93 public:
94 CFontLinkInfo();
95 ~CFontLinkInfo();
96 void init();
97 void clear();
98 const LPCWSTR * lookup(LPCWSTR fontname) const;
99 const LPCWSTR sysfn() const { return default_font; }
101 #if 0 /* disable sysfn for now*/
102 LOGFONT syslf;
103 const LPCWSTR sysfn() const { return syslf.lfFaceName; }
104 #endif
107 class CFontSubstitutesInfo;
109 class CFontSubstituteData
111 friend CFontSubstitutesInfo;
112 private:
113 LOGFONT m_lf;
114 TEXTMETRIC m_tm;
115 bool m_bCharSet;
116 public:
117 bool operator == (const CFontSubstituteData& o) const;
118 private:
119 CFontSubstituteData();
120 bool init(LPCTSTR config);
121 static int CALLBACK EnumFontFamProc(const LOGFONT *lplf, const TEXTMETRIC *lptm, DWORD FontType, LPARAM lParam);
125 typedef StringHashT<LF_FACESIZE + 10,true> CFontSubstitutesHash;
126 typedef CArray<CFontSubstitutesHash> CFontSubstitutesIniArray;
128 class CFontSubstitutesInfo : public CSimpleMap<CFontSubstituteData, CFontSubstituteData>
130 private:
131 void initini(const CFontSubstitutesIniArray& iniarray);
132 void initreg();
133 public:
134 void init(int nFontSubstitutes, const CFontSubstitutesIniArray& iniarray);
135 const LOGFONT * lookup(const LOGFONT &lf) const;
138 #define SETTING_FONTSUBSTITUTE_DISABLE (0)
139 #define SETTING_FONTSUBSTITUTE_INIONLY (1)
140 #define SETTING_FONTSUBSTITUTE_ALL (2)
142 #define SETTING_WIDTHMODE_GDI32 (0)
143 #define SETTING_WIDTHMODE_FREETYPE (1)
145 #define SETTING_FONTLOADER_FREETYPE (0)
146 #define SETTING_FONTLOADER_WIN32 (1)
148 class CGdippSettings;
150 class CGdippSettings
152 friend CFontSubstituteData;
153 friend BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID);
154 private:
155 static CGdippSettings* s_pInstance;
156 //INI—p
157 CFontSettings m_FontSettings;
158 bool m_bHookChildProcesses : 1;
159 bool m_bUseMapping : 1;
160 bool m_bLoadOnDemand : 1;
161 bool m_bEnableShadow : 1;
162 bool m_bFontLink : 1;
164 bool m_bRunFromGdiExe : 1;
165 bool m_bIsInclude : 1;
166 bool m_bDelayedInit : 1;
167 // bool m_bIsHDBench : 1;
168 // bool m_bHaveNewerFreeType : 1;
169 bool : 0;
171 int m_nBolderMode;
172 int m_nGammaMode;
173 float m_fGammaValue;
174 float m_fRenderWeight;
175 float m_fContrast;
176 int m_nMaxHeight;
177 int m_nLcdFilter;
178 int m_nShadow[3];
179 int m_nFontSubstitutes;
180 int m_nWidthMode;
181 int m_nFontLoader;
183 //FTC_Manager_New‚É“n‚·ƒpƒ‰ƒ��[ƒ^
184 int m_nCacheMaxFaces;
185 int m_nCacheMaxSizes;
186 int m_nCacheMaxBytes;
188 // ƒAƒ“ƒ`ƒGƒCƒŠƒAƒX’²�®—pƒe�[ƒuƒ‹
189 int m_nTuneTable[256];
190 // LCD—p
191 int m_nTuneTableR[256];
192 int m_nTuneTableG[256];
193 int m_nTuneTableB[256];
195 typedef CArray<StringHashFont> FontHashArray;
196 typedef CArray<StringHashModule> ModuleHashArray;
197 typedef CArray<CFontIndividual> IndividualArray;
198 FontHashArray m_arrExcludeFont;
199 ModuleHashArray m_arrExcludeModule;
200 ModuleHashArray m_arrIncludeModule;
201 IndividualArray m_arrIndividual;
203 // Žw’èƒtƒHƒ“ƒg
204 LOGFONT m_lfForceFont;
205 TCHAR m_szForceChangeFont[LF_FACESIZE];
207 //INIƒtƒ@ƒCƒ‹–¼
208 TCHAR m_szFileName[MAX_PATH];
210 //INI‚©‚ç‚Ì“Ç‚Ý�ž‚Ý�ˆ—�
211 bool LoadAppSettings(LPCTSTR lpszFile);
212 static LPTSTR _GetPrivateProfileSection (LPCTSTR lpszSection, LPCTSTR lpszFile);
213 static int _GetFreeTypeProfileInt (LPCTSTR lpszKey, int nDefault, LPCTSTR lpszFile);
214 static int _GetFreeTypeProfileBoundInt (LPCTSTR lpszKey, int nDefault, int nMin, int nMax, LPCTSTR lpszFile);
215 static float _GetFreeTypeProfileFloat (LPCTSTR lpszKey, float fDefault, LPCTSTR lpszFile);
216 static float _GetFreeTypeProfileBoundFloat(LPCTSTR lpszKey, float fDefault, float fMin, float fMax, LPCTSTR lpszFile);
217 static DWORD _GetFreeTypeProfileString (LPCTSTR lpszKey, LPCTSTR lpszDefault, LPTSTR lpszRet, DWORD cch, LPCTSTR lpszFile);
218 static int CALLBACK EnumFontFamProc(const LOGFONT* lplf, const TEXTMETRIC* lptm, DWORD FontType, LPARAM lParam);
220 template <class T>
221 static bool AddListFromSection(LPCTSTR lpszSection, LPCTSTR lpszFile, CArray<T>& arr);
222 bool AddIndividualFromSection(LPCTSTR lpszSection, LPCTSTR lpszFile, IndividualArray& arr);
223 static int _StrToInt(LPCTSTR pStr, int nDefault);
224 static float _StrToFloat(LPCTSTR pStr, float fDefault);
226 void InitInitTuneTable();
227 static void InitTuneTable(int v, int* table);
228 void DelayedInit();
230 CFontLinkInfo m_fontlinkinfo;
231 CFontSubstitutesInfo m_FontSubstitutesInfo;
233 CGdippSettings()
234 : m_bHookChildProcesses(false)
235 , m_bUseMapping(false)
236 , m_bLoadOnDemand(false)
237 , m_bEnableShadow(false)
238 , m_bFontLink(false)
239 // , m_bEnableKerning(false)
240 , m_bRunFromGdiExe(false)
241 , m_bIsInclude(false)
242 , m_bDelayedInit(false)
243 // , m_bIsHDBench(false)
244 // , m_bHaveNewerFreeType(false)
245 , m_nBolderMode(0)
246 , m_nGammaMode(0)
247 , m_fGammaValue(1.0f)
248 , m_fRenderWeight(1.0f)
249 , m_fContrast(1.0f)
250 , m_nMaxHeight(0)
251 , m_nLcdFilter(0)
252 , m_nCacheMaxFaces(0)
253 , m_nCacheMaxSizes(0)
254 , m_nCacheMaxBytes(0)
256 ZeroMemory(m_nTuneTable, sizeof(m_nTuneTable));
257 ZeroMemory(m_nTuneTableR, sizeof(m_nTuneTableR));
258 ZeroMemory(m_nTuneTableG, sizeof(m_nTuneTableG));
259 ZeroMemory(m_nTuneTableB, sizeof(m_nTuneTableB));
260 ZeroMemory(&m_lfForceFont, sizeof(LOGFONT));
261 ZeroMemory(m_nShadow, sizeof(m_nShadow));
262 ZeroMemory(m_szFileName, sizeof(m_szFileName));
263 ZeroMemory(m_szForceChangeFont, sizeof(m_szForceChangeFont));
266 ~CGdippSettings()
270 static CGdippSettings* CreateInstance();
271 static void DestroyInstance();
273 public:
274 static const CGdippSettings* GetInstance();
275 static const CGdippSettings* GetInstanceNoInit(); //FreeTypeFontEngine
277 //INI—p
278 const CFontSettings& GetFontSettings() const { return m_FontSettings; }
279 bool HookChildProcesses() const { return m_bHookChildProcesses; }
280 bool UseMapping() const { return m_bUseMapping; }
281 bool LoadOnDemand() const { return m_bLoadOnDemand; }
282 bool FontLink() const { return m_bFontLink; }
283 // bool EnableKerning() const { return m_bEnableKerning; }
285 int BolderMode() const { return m_nBolderMode; }
286 int GammaMode() const { return m_nGammaMode; }
287 float GammaValue() const { return m_fGammaValue; }
288 float RenderWeight() const { return m_fRenderWeight; }
289 float Contrast() const { return m_fContrast; }
290 int MaxHeight() const { return m_nMaxHeight; }
291 int LcdFilter() const { return m_nLcdFilter; }
292 int WidthMode() const { return m_nWidthMode; }
293 int FontLoader() const { return m_nFontLoader; }
294 int CacheMaxFaces() const { return m_nCacheMaxFaces; }
295 int CacheMaxSizes() const { return m_nCacheMaxSizes; }
296 int CacheMaxBytes() const { return m_nCacheMaxBytes; }
298 bool EnableShadow() const { return m_bEnableShadow; }
299 const int* GetShadowParams() const { return m_nShadow; }
301 // ƒtƒHƒ“ƒg–¼‚æ‚Ý‚Æ‚è
302 LPCTSTR GetForceFontName() const
304 _ASSERTE(m_bDelayedInit);
305 LPCTSTR lpszFace = m_lfForceFont.lfFaceName;
306 return lpszFace[0] ? lpszFace : NULL;
309 bool CopyForceFont(LOGFONT& lf, const LOGFONT& lfOrg) const;
311 bool IsInclude() const { return m_bIsInclude; }
312 // bool IsHDBench() const { return m_bIsHDBench; }
313 bool RunFromGdiExe() const { return m_bRunFromGdiExe; }
314 // bool HaveNewerFreeType() const { return m_bHaveNewerFreeType; }
315 const int* GetTuneTable() const { return m_nTuneTable; }
316 const int* GetTuneTableR() const { return m_nTuneTableR; }
317 const int* GetTuneTableG() const { return m_nTuneTableG; }
318 const int* GetTuneTableB() const { return m_nTuneTableB; }
320 bool LoadSettings();
321 bool LoadSettings(HINSTANCE hModule);
323 bool IsFontExcluded(LPCSTR lpFaceName) const;
324 bool IsFontExcluded(LPCWSTR lpFaceName) const;
326 bool IsProcessExcluded() const;
327 bool IsProcessIncluded() const;
328 const CFontSettings& FindIndividual(LPCTSTR lpFaceName) const;
330 const CFontLinkInfo& GetFontLinkInfo() const
331 { _ASSERTE(m_bDelayedInit); return m_fontlinkinfo; }
332 const CFontSubstitutesInfo& GetFontSubstitutesInfo() const
333 { _ASSERTE(m_bDelayedInit); return m_FontSubstitutesInfo; }
336 class CFontFaceNamesEnumerator
338 private:
339 LPCWSTR m_facenames[2];
340 const LPCWSTR *p_facename;
341 int m_pos;
342 CFontFaceNamesEnumerator();
343 public:
344 CFontFaceNamesEnumerator(LPCWSTR facename);
345 operator LPCWSTR () {
346 return *p_facename;
348 void next() {
349 ++p_facename;
351 bool atend() {
352 return NULL == *p_facename;