forked from snowie2000/mactype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.cpp
1706 lines (1538 loc) · 52.3 KB
/
settings.cpp
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "settings.h"
#include "strtoken.h"
#include <math.h> //pow
#include "supinfo.h"
#include "fteng.h"
#include <stdlib.h>
#ifdef INFINALITY
#include <freetype/ftenv.h>
#endif
inline BOOL IsFolder(LPCTSTR pszPath) {
return pszPath && *pszPath && *(pszPath + wcslen(pszPath) - 1) == '\\';
}
wstring LowerCase(wstring str) {
transform(str.begin(), str.end(), str.begin(), ::tolower);
return str;
}
const wstring GetAppDir() {
static wstring AppDir;
if (AppDir.length()) {
return AppDir;
}
WCHAR name[MAX_PATH] = { 0 };
int nSize = GetModuleFileName(NULL, name, MAX_PATH + 1);
PathRemoveFileSpec(name);
AppDir = wstring(name) + L"\\"; // path should always end with a "\"
AppDir = LowerCase(AppDir);
return AppDir;
}
CGdippSettings* CGdippSettings::s_pInstance;
CParseIni CGdippSettings::m_Config;
CHashedStringList FontNameCache;
static const TCHAR c_szGeneral[] = _T("General");
static const TCHAR c_szFreeType[] = _T("FreeType");
static const TCHAR c_szDirectWrite[] = _T("DirectWrite");
#define HINTING_MIN 0
#define HINTING_MAX 2
#define AAMODE_MIN -1
#define AAMODE_MAX 5
#define GAMMAVALUE_MIN 0.0625f
#define GAMMAVALUE_MAX 20.0f
#define CONTRAST_MIN 0.0625f
#define CONTRAST_MAX 10.0f
#define RENDERWEIGHT_MIN 0.0625f
#define RENDERWEIGHT_MAX 10.0f
#define NWEIGHT_MIN -64
#define NWEIGHT_MAX +64
#define BWEIGHT_MIN -32
#define BWEIGHT_MAX +32
#define SLANT_MIN -32
#define SLANT_MAX +32
CGdippSettings* CGdippSettings::CreateInstance()
{
CCriticalSectionLock __lock(CCriticalSectionLock::CS_SETTING);
CGdippSettings* pSettings = new CGdippSettings;
CGdippSettings* pOldSettings = reinterpret_cast<CGdippSettings*>(InterlockedExchangePointer(reinterpret_cast<void**>(&s_pInstance), pSettings));
_ASSERTE(pOldSettings == NULL);
int nSize = GetModuleFileName(NULL, pSettings->m_szexeName, MAX_PATH);
for (int i = nSize; i > 0; --i) {
if (pSettings->m_szexeName[i] == _T('\\')) {
StringCchCopy(pSettings->m_szexeName, nSize - i, pSettings->m_szexeName + i + 1);
break;
}
}
return pSettings;
}
void CGdippSettings::DestroyInstance()
{
CCriticalSectionLock __lock(CCriticalSectionLock::CS_SETTING);
CGdippSettings* pSettings = reinterpret_cast<CGdippSettings*>(InterlockedExchangePointer(reinterpret_cast<void**>(&s_pInstance), NULL));
if (pSettings) {
delete pSettings;
}
}
CGdippSettings* CGdippSettings::GetInstance()
{
CCriticalSectionLock __lock(CCriticalSectionLock::CS_SETTING);
CGdippSettings* pSettings = s_pInstance;
_ASSERTE(pSettings != NULL);
if (!pSettings->m_bDelayedInit) {
pSettings->DelayedInit();
}
return pSettings;
}
const CGdippSettings* CGdippSettings::GetInstanceNoInit()
{
CCriticalSectionLock __lock(CCriticalSectionLock::CS_SETTING);
CGdippSettings* pSettings = s_pInstance;
_ASSERTE(pSettings != NULL);
return pSettings;
}
void CGdippSettings::DelayedInit()
{
if (!g_pFTEngine) {
return;
}
if (IsBadCodePtr((FARPROC)RegOpenKeyExW) || *(DWORD_PTR*)RegOpenKeyExW==0)
return;
/*
In Windows 8, this call will fail in restricted environment
if GetDC failed, we are in a restricted environment where features like font subsitutations doesn't work properly.
Because these features requires DC to get the real font name and we don't have access to any DC, even CreateCompatibleDC(null) fails (it will succeed, but DeleteDC will fail)
So it is better exit than doing initialization.
*/
m_bDelayedInit = true;
HDC hdcScreen = GetDC(NULL);
if (!hdcScreen) {
return;
}
//ForceChangeFont
if (m_szForceChangeFont[0]) {
EnumFontFamilies(hdcScreen, m_szForceChangeFont, EnumFontFamProc, reinterpret_cast<LPARAM>(this));
}
//fetch screen dpi
m_nScreenDpi = GetDeviceCaps(hdcScreen, LOGPIXELSX);
ReleaseDC(NULL, hdcScreen);
// //FontLink
// if (FontLink()) {
// m_fontlinkinfo.init();
// }
const int nTextTuning = _GetFreeTypeProfileInt(_T("TextTuning"), 0, NULL),
nTextTuningR = _GetFreeTypeProfileInt(_T("TextTuningR"), 0, NULL),
nTextTuningG = _GetFreeTypeProfileInt(_T("TextTuningG"), 0, NULL),
nTextTuningB = _GetFreeTypeProfileInt(_T("TextTuningB"), 0, NULL);
InitInitTuneTable();
InitTuneTable(nTextTuning, m_nTuneTable);
InitTuneTable(nTextTuningR, m_nTuneTableR);
InitTuneTable(nTextTuningG, m_nTuneTableG);
InitTuneTable(nTextTuningB, m_nTuneTableB);
RefreshAlphaTable();
//FontSubstitutes
CFontSubstitutesIniArray arrFontSubstitutes;
wstring names = _T("FontSubstitutes@") + wstring(m_szexeName);
if (_IsFreeTypeProfileSectionExists(names.c_str(), m_szFileName))
AddListFromSection(names.c_str(), m_szFileName, arrFontSubstitutes);
else
AddListFromSection(_T("FontSubstitutes"), m_szFileName, arrFontSubstitutes);
m_FontSubstitutesInfo.init(m_nFontSubstitutes, arrFontSubstitutes);
names = _T("Individual@") + wstring(m_szexeName);
if (_IsFreeTypeProfileSectionExists(names.c_str(), NULL))
AddIndividualFromSection(names.c_str(), NULL, m_arrIndividual);
else
AddIndividualFromSection(_T("Individual"), NULL, m_arrIndividual);
AddExcludeListFromSection(_T("Exclude"), NULL, m_arrExcludeFont);
AddExcludeListFromSection(_T("Include"), NULL, m_arrIncludeFont); //I know it's include not exclude, but they share the same logic.
//WritePrivateProfileString(NULL, NULL, NULL, m_szFileName);
//m_bDelayedInit = true;
//FontLink
if (FontLink()) {
m_fontlinkinfo.init();
}
//強制フォント
/*
LPCTSTR lpszFace = GetForceFontName();
if (lpszFace)
g_pFTEngine->AddFont(lpszFace, FW_NORMAL, false);*/
/* DWORD dwVersion = GetVersion();
if (m_bDirectWrite && (DWORD)(LOBYTE(LOWORD(dwVersion)))>5) //vista or later
{
if (GetModuleHandle(_T("d2d1.dll"))) //directwrite support
HookD2D1();
}*/
}
bool CGdippSettings::LoadSettings(HINSTANCE hModule)
{
CCriticalSectionLock __lock(CCriticalSectionLock::CS_SETTING);
int nSize = ::GetModuleFileName(hModule, m_szFileName, MAX_PATH - sizeof(".ini") + 1);
if (!nSize) {
return false;
}
ChangeFileName(m_szFileName, nSize, L"MacType.ini");
return LoadAppSettings(m_szFileName);
}
int CGdippSettings::_GetFreeTypeProfileIntFromSection(LPCTSTR lpszSection, LPCTSTR lpszKey, int nDefault, LPCTSTR lpszFile)
{
wstring names = wstring((LPTSTR)lpszSection) + _T("@") + wstring((LPTSTR)m_szexeName);
if (m_Config.IsPartExists(names.c_str()) && m_Config[names.c_str()].IsValueExists(lpszKey))
return m_Config[names.c_str()][lpszKey].ToInt();
else
if (m_Config[lpszSection].IsValueExists(lpszKey))
return m_Config[lpszSection][lpszKey].ToInt();
else
return nDefault;
}
bool CGdippSettings::_GetFreeTypeProfileBoolFromSection(LPCTSTR lpszSection, LPCTSTR lpszKey, bool nDefault, LPCTSTR lpszFile)
{
wstring names = wstring((LPTSTR)lpszSection) + _T("@") + wstring((LPTSTR)m_szexeName);
if (m_Config.IsPartExists(names.c_str()) && m_Config[names.c_str()].IsValueExists(lpszKey))
return m_Config[names.c_str()][lpszKey].ToBool();
else
if (m_Config[lpszSection].IsValueExists(lpszKey))
return m_Config[lpszSection][lpszKey].ToBool();
else
return nDefault;
}
wstring CGdippSettings::_GetFreeTypeProfileStrFromSection(LPCTSTR lpszSection, LPCTSTR lpszKey, const TCHAR* nDefault, LPCTSTR lpszFile)
{
wstring names = wstring((LPTSTR)lpszSection) + _T("@") + wstring((LPTSTR)m_szexeName);
if (m_Config.IsPartExists(names.c_str()) && m_Config[names.c_str()].IsValueExists(lpszKey))
return m_Config[names.c_str()][lpszKey].ToString();
else
if (m_Config[lpszSection].IsValueExists(lpszKey))
return m_Config[lpszSection][lpszKey].ToString();
else
return nDefault;
}
int CGdippSettings::_GetFreeTypeProfileInt(LPCTSTR lpszKey, int nDefault, LPCTSTR lpszFile)
{
int ret = _GetFreeTypeProfileIntFromSection(c_szFreeType, lpszKey, nDefault, lpszFile);
if (ret == nDefault)
return _GetFreeTypeProfileIntFromSection(c_szGeneral, lpszKey, nDefault, lpszFile);
else
return ret;
}
int CGdippSettings::_GetFreeTypeProfileBoundInt(LPCTSTR lpszKey, int nDefault, int nMin, int nMax, LPCTSTR lpszFile)
{
const int ret = _GetFreeTypeProfileInt(lpszKey, nDefault, lpszFile);
return Bound(ret, nMin, nMax);
}
bool CGdippSettings::_IsFreeTypeProfileSectionExists(LPCTSTR lpszKey, LPCTSTR lpszFile)
{
return m_Config.IsPartExists(lpszKey);
}
float CGdippSettings::FastGetProfileFloat(LPCTSTR lpszSection, LPCTSTR lpszKey, float fDefault)
{
wstring names = wstring((LPTSTR)lpszSection) + _T("@") + wstring((LPTSTR)m_szexeName);
if (m_Config.IsPartExists(names.c_str()) && m_Config[names.c_str()].IsValueExists(lpszKey))
return m_Config[names.c_str()][lpszKey].ToDouble();
else
if (m_Config[lpszSection].IsValueExists(lpszKey))
return m_Config[lpszSection][lpszKey].ToDouble();
else
return fDefault;
}
int CGdippSettings::FastGetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszKey, int nDefault)
{
wstring names = wstring((LPTSTR)lpszSection) + _T("@") + wstring((LPTSTR)m_szexeName);
if (m_Config.IsPartExists(names.c_str()) && m_Config[names.c_str()].IsValueExists(lpszKey))
return m_Config[names.c_str()][lpszKey].ToInt();
else
if (m_Config[lpszSection].IsValueExists(lpszKey))
return m_Config[lpszSection][lpszKey].ToInt();
else
return nDefault;
}
float CGdippSettings::_GetFreeTypeProfileFloat(LPCTSTR lpszKey, float fDefault, LPCTSTR lpszFile)
{
wstring names = wstring((LPTSTR)c_szFreeType) + _T("@") + wstring((LPTSTR)m_szexeName);
if (m_Config.IsPartExists(names.c_str()) && m_Config[names.c_str()].IsValueExists(lpszKey))
return m_Config[names.c_str()][lpszKey].ToInt();
else
{
names = wstring((LPTSTR)c_szGeneral) + _T("@") + wstring((LPTSTR)m_szexeName);
if (m_Config.IsPartExists(names.c_str()) && m_Config[names.c_str()].IsValueExists(lpszKey))
return m_Config[names.c_str()][lpszKey].ToDouble();
else
if (m_Config[c_szFreeType].IsValueExists(lpszKey))
return m_Config[c_szFreeType][lpszKey].ToDouble();
if (m_Config[c_szGeneral].IsValueExists(lpszKey))
return m_Config[c_szGeneral][lpszKey].ToDouble();
else
return fDefault;
}
}
float CGdippSettings::_GetFreeTypeProfileBoundFloat(LPCTSTR lpszKey, float fDefault, float fMin, float fMax, LPCTSTR lpszFile)
{
const float ret = _GetFreeTypeProfileFloat(lpszKey, fDefault, lpszFile);
return Bound(ret, fMin, fMax);
}
DWORD CGdippSettings::FastGetProfileString(LPCTSTR lpszSection, LPCTSTR lpszKey, LPCTSTR lpszDefault, LPTSTR lpszRet, DWORD cch)
{
wstring names = wstring((LPTSTR)lpszSection) + _T("@") + wstring((LPTSTR)m_szexeName);
if (m_Config.IsPartExists(names.c_str()) && m_Config[names.c_str()].IsValueExists(lpszKey))
{
LPCTSTR p = m_Config[names.c_str()][lpszKey];
StringCchCopy(lpszRet, cch, p);
return wcslen(p);
}
else
if (m_Config[lpszSection].IsValueExists(lpszKey))
{
LPCTSTR p = m_Config[lpszSection][lpszKey];
StringCchCopy(lpszRet, cch, p);
return wcslen(p);
}
else
{
if (lpszDefault) {
StringCchCopy(lpszRet, cch, lpszDefault);
return wcslen(lpszDefault);
}
else {
lpszRet = NULL;
return 0;
}
}
}
DWORD CGdippSettings::_GetFreeTypeProfileString(LPCTSTR lpszKey, LPCTSTR lpszDefault, LPTSTR lpszRet, DWORD cch, LPCTSTR lpszFile)
{
wstring names = wstring((LPTSTR)c_szFreeType) + _T("@") + wstring((LPTSTR)m_szexeName);
if (m_Config.IsPartExists(names.c_str()) && m_Config[names.c_str()].IsValueExists(lpszKey))
{
LPCTSTR p = m_Config[names.c_str()][lpszKey];
StringCchCopy(lpszRet, cch, p);
return wcslen(p);
}
else
{
names = wstring((LPTSTR)c_szGeneral) + _T("@") + wstring((LPTSTR)m_szexeName);
if (m_Config.IsPartExists(names.c_str()) && m_Config[names.c_str()].IsValueExists(lpszKey))
{
LPCTSTR p = m_Config[names.c_str()][lpszKey];
StringCchCopy(lpszRet, cch, p);
return wcslen(p);
}
else
if (m_Config[c_szFreeType].IsValueExists(lpszKey))
{
LPCTSTR p = m_Config[c_szFreeType][lpszKey];
StringCchCopy(lpszRet, cch, p);
return wcslen(p);
}
else
if (m_Config[c_szGeneral].IsValueExists(lpszKey))
{
LPCTSTR p = m_Config[c_szGeneral][lpszKey];
StringCchCopy(lpszRet, cch, p);
return wcslen(p);
}
else
{
StringCchCopy(lpszRet, cch, lpszDefault);
return wcslen(lpszDefault);
}
}
}
void CGdippSettings::GetOSVersion() {
OSVERSIONINFO info;
memset(&info, 0, sizeof(OSVERSIONINFO));
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&info);
m_dwOSMajorVer = info.dwMajorVersion;
m_dwOSMinorVer = info.dwMinorVersion;
}
bool CGdippSettings::LoadAppSettings(LPCTSTR lpszFile)
{
// 各種設定読み込み
// INIファイルの例:
// [General]
// HookChildProcesses=0
// HintingMode=0
// AntiAliasMode=0
// NormalWeight=0
// BoldWeight=0
// ItalicSlant=0
// EnableKerning=0
// MaxHeight=0
// ForceChangeFont=MS Pゴシック
// TextTuning=0
// TextTuningR=0
// TextTuningG=0
// TextTuningB=0
// CacheMaxFaces=0
// CacheMaxSizes=0
// CacheMaxBytes=0
// AlternativeFile=
// LoadOnDemand=0
// UseMapping=0
// LcdFilter=0
// Shadow=1,1,4
// [Individual]
// MS Pゴシック=0,1,2,3,4,5
GetOSVersion();
WritePrivateProfileString(NULL, NULL, NULL, lpszFile);
m_Config.Clear();
m_Config.LoadFromFile(lpszFile);
TCHAR szAlternative[MAX_PATH], szMainFile[MAX_PATH];
if (FastGetProfileString(c_szGeneral, _T("AlternativeFile"), _T(""), szAlternative, MAX_PATH)) {
if (PathIsRelative(szAlternative)) {
TCHAR szDir[MAX_PATH];
StringCchCopy(szDir, MAX_PATH, lpszFile);
PathRemoveFileSpec(szDir);
PathCombine(szAlternative, szDir, szAlternative);
}
StringCchCopy(szMainFile, MAX_PATH, lpszFile); //ームヤュハシホトシテ﨣」エ賺ツタエ
StringCchCopy(m_szFileName, MAX_PATH, szAlternative);
lpszFile = m_szFileName;
m_Config.Clear();
m_Config.LoadFromFile(lpszFile);
}
_GetAlternativeProfileName(m_szexeName, lpszFile);
CFontSettings& fs = m_FontSettings;
fs.Clear();
fs.SetHintingMode(_GetFreeTypeProfileBoundInt(_T("HintingMode"), 0, HINTING_MIN, HINTING_MAX, lpszFile));
fs.SetAntiAliasMode(_GetFreeTypeProfileBoundInt(_T("AntiAliasMode"), 0, AAMODE_MIN, AAMODE_MAX, lpszFile));
fs.SetNormalWeight(_GetFreeTypeProfileBoundInt(_T("NormalWeight"), 0, NWEIGHT_MIN, NWEIGHT_MAX, lpszFile));
fs.SetBoldWeight(_GetFreeTypeProfileBoundInt(_T("BoldWeight"), 0, BWEIGHT_MIN, BWEIGHT_MAX, lpszFile));
fs.SetItalicSlant(_GetFreeTypeProfileBoundInt(_T("ItalicSlant"), 0, SLANT_MIN, SLANT_MAX, lpszFile));
fs.SetKerning(!!_GetFreeTypeProfileInt(_T("EnableKerning"), 0, lpszFile));
{
TCHAR szShadow[256];
CStringTokenizer token;
m_bEnableShadow = false;
if (!_GetFreeTypeProfileString(_T("Shadow"), _T(""), szShadow, countof(szShadow), lpszFile)
|| token.Parse(szShadow) < 3) {
goto SKIP;
}
for (int i=0; i<3; i++) {
m_nShadow[i] = _StrToInt(token.GetArgument(i), 0);
/*if (m_nShadow[i] <= 0) {
goto SKIP;
}*/
}
m_bEnableShadow = true;
if (token.GetCount()>=4) //ネ郢鋓クカィチヒヌウノォメー
m_nShadowDarkColor = _httoi(token.GetArgument(3)); //カチネ。メー
else
m_nShadowDarkColor = 0; //キェコレノォ
if (token.GetCount()>=6) //ネ郢鋓クカィチヒノ鐱ォメー
{
m_nShadowLightColor = _httoi(token.GetArgument(5)); //カチネ。メー
m_nShadow[3] = _StrToInt(token.GetArgument(4), m_nShadow[2]); //カチネ。ノ鋐ネ
}
else
{
m_nShadowLightColor = m_nShadowDarkColor; //キヘヌウノォメーマ猩ャ
m_nShadow[3] = m_nShadow[2]; //ノ鋐ネメイマ猩ャ
}
SKIP:
;
}
m_bHookChildProcesses = !!_GetFreeTypeProfileInt(_T("HookChildProcesses"), false, lpszFile);
m_bUseMapping = !!_GetFreeTypeProfileInt(_T("UseMapping"), false, lpszFile);
m_nBolderMode = _GetFreeTypeProfileInt(_T("BolderMode"), 0, lpszFile);
m_nGammaMode = _GetFreeTypeProfileInt(_T("GammaMode"), -1, lpszFile);
m_fGammaValue = _GetFreeTypeProfileBoundFloat(_T("GammaValue"), 1.0f, GAMMAVALUE_MIN, GAMMAVALUE_MAX, lpszFile);
m_fRenderWeight = _GetFreeTypeProfileBoundFloat(_T("RenderWeight"), 1.0f, RENDERWEIGHT_MIN, RENDERWEIGHT_MAX, lpszFile);
m_fContrast = _GetFreeTypeProfileBoundFloat(_T("Contrast"), 1.0f, CONTRAST_MIN, CONTRAST_MAX, lpszFile);
//DirectWrite/Direct2D exclusive settings
float fCalculatedDWGamma = m_fGammaValue*m_fGammaValue > 1.3 ? m_fGammaValue * m_fGammaValue / 2 : 0.7f;
// if not set, use calculated gamma as DW gamma
m_fGammaValueForDW = Bound(FastGetProfileFloat(c_szDirectWrite, _T("GammaValue"), fCalculatedDWGamma), 0.0f, GAMMAVALUE_MAX);
m_fContrastForDW = Bound(FastGetProfileFloat(c_szDirectWrite, _T("Contrast"), 1.0f), CONTRAST_MIN, CONTRAST_MAX);
m_nRenderingModeForDW = Bound(FastGetProfileInt(c_szDirectWrite, _T("RenderingMode"), 5), 0, 6);
m_fClearTypeLevelForDW = Bound(FastGetProfileFloat(c_szDirectWrite, _T("ClearTypeLevel"), 1.0f), 0.0f, 1.0f);
#ifdef _DEBUG
// GammaValue検証用
//CHAR GammaValueTest[1025];
//sprintf(GammaValueTest, "GammaValue=%.6f\nContrast=%.6f\n", m_fGammaValue, m_fContrast);
//MessageBoxA(NULL, GammaValueTest, "GammaValueテスト", 0);
#endif
m_bLoadOnDemand = !!_GetFreeTypeProfileInt(_T("LoadOnDemand"), false, lpszFile);
m_bFontLink = _GetFreeTypeProfileInt(_T("FontLink"), 0, lpszFile);
m_bIsInclude = !!_GetFreeTypeProfileInt(_T("UseInclude"), false, lpszFile);
m_nMaxHeight = _GetFreeTypeProfileBoundInt(_T("MaxHeight"), 0, 0, 0xfff, lpszFile); //ラ鋕゚ヨサトワオス65535」ャcacheオトマ゙ヨニ」ャカメエヨフ衾゙ハオシハシロヨオ
m_nMinHeight = _GetFreeTypeProfileBoundInt(_T("MinHeight"), 0, 0,
(m_nMaxHeight) ? m_nMaxHeight : 0xfff, // shouldn't be greater than MaxHeight unless it is undefined
lpszFile); //Minimum size of rendered font. DPI aware alternative.
//patched by krrr https://github.com/krrr/mactype/commit/146a213e2304208cb3c1a3e6fa941a386d908761
m_nBitmapHeight = _GetFreeTypeProfileBoundInt(_T("MaxBitmap"), 0, 0, 255, lpszFile);
m_bHintSmallFont = _GetFreeTypeProfileInt(_T("HintSmallFont"), 0, lpszFile);
m_bDirectWrite = _GetFreeTypeProfileInt(_T("DirectWrite"), 0, lpszFile);
m_nLcdFilter = _GetFreeTypeProfileInt(_T("LcdFilter"), 0, lpszFile);
m_nFontSubstitutes = _GetFreeTypeProfileBoundInt(_T("FontSubstitutes"),
SETTING_FONTSUBSTITUTE_DISABLE,
SETTING_FONTSUBSTITUTE_DISABLE,
SETTING_FONTSUBSTITUTE_ALL,
lpszFile);
m_nWidthMode = SETTING_WIDTHMODE_GDI32;
/*
_GetFreeTypeProfileBoundInt(_T("WidthMode"),
SETTING_WIDTHMODE_GDI32,
SETTING_WIDTHMODE_GDI32,
SETTING_WIDTHMODE_FREETYPE,
lpszFile);*/
m_nFontLoader = _GetFreeTypeProfileBoundInt(_T("FontLoader"),
SETTING_FONTLOADER_FREETYPE,
SETTING_FONTLOADER_FREETYPE,
SETTING_FONTLOADER_WIN32,
lpszFile);
m_nCacheMaxFaces = _GetFreeTypeProfileInt(_T("CacheMaxFaces"), 64, lpszFile);
m_nCacheMaxFaces = m_nCacheMaxFaces > 64 ? m_nCacheMaxFaces : 64;
m_nCacheMaxSizes = _GetFreeTypeProfileInt(_T("CacheMaxSizes"), 1200, lpszFile);
m_nCacheMaxBytes = _GetFreeTypeProfileInt(_T("CacheMaxBytes"), 10485760, lpszFile);
//experimental settings:
m_bEnableClipBoxFix = !!_GetFreeTypeProfileIntFromSection(_T("Experimental"), _T("ClipBoxFix"), 1, lpszFile);
m_bColorFont = !!_GetFreeTypeProfileIntFromSection(_T("Experimental"), _T("ColorFont"), 0, lpszFile);
m_bInvertColor = !!_GetFreeTypeProfileIntFromSection(_T("Experimental"), _T("InvertColor"), 0, lpszFile);
#ifdef INFINALITY
// define some macros
#define INF_INT_ENV(y, def) \
nTemp = _GetFreeTypeProfileIntFromSection(_T("Infinality"), _T(y), def, lpszFile); \
FT_PutEnv(y, _ltoa(nTemp, buff, 10));
#define INF_BOOL_ENV(y, def) \
bTemp = _GetFreeTypeProfileBoolFromSection(_T("Infinality"), _T(y), def, lpszFile); \
FT_PutEnv(y, bTemp?"true":"false");
#define INF_STR_ENV(y, def) \
sTemp = _GetFreeTypeProfileStrFromSection(_T("Infinality"), _T(y), def, lpszFile); \
FT_PutEnv(y, WstringToString(sTemp).c_str());
char* buff = (char*)malloc(256);
int nTemp; bool bTemp; wstring sTemp;
// INFINALITY settings:
INF_INT_ENV( "INFINALITY_FT_CHROMEOS_STYLE_SHARPENING_STRENGTH", 0);
INF_INT_ENV( "INFINALITY_FT_CONTRAST", 0);
INF_INT_ENV( "INFINALITY_FT_STEM_FITTING_STRENGTH", 25);
INF_INT_ENV( "INFINALITY_FT_AUTOHINT_SNAP_STEM_HEIGHT", 100);
INF_INT_ENV( "INFINALITY_FT_GRAYSCALE_FILTER_STRENGTH", 0);
INF_INT_ENV( "INFINALITY_FT_WINDOWS_STYLE_SHARPENING_STRENGTH", 20);
INF_INT_ENV( "INFINALITY_FT_BRIGHTNESS", 0);
INF_INT_ENV( "INFINALITY_FT_AUTOHINT_HORIZONTAL_STEM_DARKEN_STRENGTH", 10);
INF_INT_ENV( "INFINALITY_FT_STEM_ALIGNMENT_STRENGTH", 25);
INF_INT_ENV( "INFINALITY_FT_AUTOHINT_VERTICAL_STEM_DARKEN_STRENGTH", 25);
INF_INT_ENV( "INFINALITY_FT_FRINGE_FILTER_STRENGTH", 0);
INF_INT_ENV("INFINALITY_FT_GLOBAL_EMBOLDEN_X_VALUE", 0);
INF_INT_ENV("INFINALITY_FT_GLOBAL_EMBOLDEN_Y_VALUE", 0);
INF_INT_ENV("INFINALITY_FT_BOLD_EMBOLDEN_X_VALUE", 0);
INF_INT_ENV("INFINALITY_FT_BOLD_EMBOLDEN_Y_VALUE", 0);
INF_INT_ENV("INFINALITY_FT_STEM_SNAPPING_SLIDING_SCALE", 0);
INF_BOOL_ENV("INFINALITY_FT_USE_KNOWN_SETTINGS_ON_SELECTED_FONTS", true);
INF_BOOL_ENV( "INFINALITY_FT_AUTOFIT_ADJUST_HEIGHTS", true);
INF_BOOL_ENV( "INFINALITY_FT_USE_VARIOUS_TWEAKS", true);
INF_BOOL_ENV( "INFINALITY_FT_AUTOHINT_INCREASE_GLYPH_HEIGHTS", true);
INF_BOOL_ENV( "INFINALITY_FT_STEM_DARKENING_CFF", true);
INF_BOOL_ENV( "INFINALITY_FT_STEM_DARKENING_AUTOFIT", true);
INF_STR_ENV( "INFINALITY_FT_GAMMA_CORRECTION", _T("0 100"));
INF_STR_ENV( "INFINALITY_FT_FILTER_PARAMS", _T("11 22 38 22 11"));
free(buff);
#endif
if (m_nFontLoader == SETTING_FONTLOADER_WIN32) {
// APIが処理してくれるはずなので自前処理は無効化
if (m_nFontSubstitutes == SETTING_FONTSUBSTITUTE_ALL) {
m_nFontSubstitutes = SETTING_FONTSUBSTITUTE_DISABLE;
}
m_bFontLink = 0;
}
// フォント指定
ZeroMemory(&m_lfForceFont, sizeof(LOGFONT));
m_szForceChangeFont[0] = _T('\0');
_GetFreeTypeProfileString(_T("ForceChangeFont"), _T(""), m_szForceChangeFont, LF_FACESIZE, lpszFile);
// OSのバージョンがXP以降かどうか
//OSVERSIONINFO osvi = { sizeof(OSVERSIONINFO) };
//GetVersionEx(&osvi);
m_bIsWinXPorLater = IsWindowsXPOrGreater();
STARTUPINFO si = { sizeof(STARTUPINFO) };
GetStartupInfo(&si);
m_bRunFromGdiExe = IsGdiPPStartupInfo(si);
// if (!m_bRunFromGdiExe) {
// m_bHookChildProcesses = false;
// }
/*
const int nTextTuning = _GetFreeTypeProfileInt(_T("TextTuning"), 0, lpszFile),
nTextTuningR = _GetFreeTypeProfileInt(_T("TextTuningR"), 0, lpszFile),
nTextTuningG = _GetFreeTypeProfileInt(_T("TextTuningG"), 0, lpszFile),
nTextTuningB = _GetFreeTypeProfileInt(_T("TextTuningB"), 0, lpszFile);
InitInitTuneTable();
InitTuneTable(nTextTuning, m_nTuneTable);
InitTuneTable(nTextTuningR, m_nTuneTableR);
InitTuneTable(nTextTuningG, m_nTuneTableG);
InitTuneTable(nTextTuningB, m_nTuneTableB);*/
// m_bIsHDBench = (GetModuleHandle(_T("HDBENCH.EXE")) == GetModuleHandle(NULL));
m_arrExcludeFont.clear();
m_arrIncludeFont.clear();
m_arrExcludeModule.clear();
m_arrIncludeModule.clear();
m_arrUnloadModule.clear();
m_arrUnFontSubModule.clear();
// [Exclude]セクションから除外フォントリストを読み込む
// [ExcludeModule]セクションから除外モジュールリストを読み込む
AddListFromSection(_T("ExcludeModule"), lpszFile, m_arrExcludeModule);
//AddListFromSection(_T("ExcludeModule"), szMainFile, m_arrExcludeModule);
// [IncludeModule]セクションから対象モジュールリストを読み込む
AddListFromSection(_T("IncludeModule"), lpszFile, m_arrIncludeModule);
//AddListFromSection(_T("IncludeModule"), szMainFile, m_arrIncludeModule);
// [UnloadDLL]ヘ・ォイサシモヤリオトト」ソ・
AddListFromSection(_T("UnloadDLL"), lpszFile, m_arrUnloadModule);
//AddListFromSection(_T("UnloadDLL"), szMainFile, m_arrUnloadModule);
// [ExcludeSub]イサスミラヨフ衫貊サオトト」ソ・
AddListFromSection(L"ExcludeSub", lpszFile, m_arrUnFontSubModule);
//AddListFromSection(L"ExcludeSub", szMainFile, m_arrUnFontSubModule);
//ネ郢鈹ヌナナウオトト」ソ鬟ャヤリアユラヨフ衫貊サ
if (m_nFontSubstitutes)
{
ModuleHashMap::const_iterator it=m_arrUnFontSubModule.begin();
while (it!=m_arrUnFontSubModule.end())
{
if (GetModuleHandle(it->c_str()))
{
m_nFontSubstitutes = 0; //ケリアユフ貊サ
break;
}
++it;
}
}
// [Individual]セクションからフォント別設定を読み込む
wstring names = _T("LcdFilterWeight@") + wstring(m_szexeName);
if (_IsFreeTypeProfileSectionExists(names.c_str(), lpszFile))
m_bUseCustomLcdFilter = AddLcdFilterFromSection(names.c_str(), lpszFile, m_arrLcdFilterWeights);
else
m_bUseCustomLcdFilter = AddLcdFilterFromSection(_T("LcdFilterWeight"), lpszFile, m_arrLcdFilterWeights);
return true;
}
int CALLBACK CGdippSettings::EnumFontFamProc(const LOGFONT* lplf, const TEXTMETRIC* /*lptm*/, DWORD FontType, LPARAM lParam)
{
CGdippSettings* pThis = reinterpret_cast<CGdippSettings*>(lParam);
if (pThis && FontType == TRUETYPE_FONTTYPE)
pThis->m_lfForceFont = *lplf;
return 0;
}
bool CGdippSettings::AddExcludeListFromSection(LPCTSTR lpszSection, LPCTSTR lpszFile, set<wstring> & arr)
{
LPTSTR buffer = _GetPrivateProfileSection(lpszSection, lpszFile);
if (buffer == NULL) {
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return false;
}
LPTSTR p = buffer;
TCHAR buff[LF_FACESIZE+1];
LOGFONT truefont={0};
while (*p) {
bool b = false;
GetFontLocalName(p, buff);//ラェササラヨフ蠹・
set<wstring>::const_iterator it = arr.find(buff);
if (it==arr.end())
arr.insert(buff);
for (; *p; p++); //タエオスマツメサミミ
p++;
}
return false;
}
//template <typename T>
bool CGdippSettings::AddListFromSection(LPCTSTR lpszSection, LPCTSTR lpszFile, set<wstring> & arr)
{
LPTSTR buffer = _GetPrivateProfileSection(lpszSection, lpszFile);
if (buffer == NULL) {
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return false;
}
LPTSTR p = buffer;
while (*p) {
bool b = false;
set<wstring>::const_iterator it = arr.find(p);
if (it==arr.end())
arr.insert(p);
for (; *p; p++); //タエオスマツメサミミ
p++;
}
return false;
}
bool CGdippSettings::AddLcdFilterFromSection(LPCTSTR lpszKey, LPCTSTR lpszFile, unsigned char* arr)
{
TCHAR buffer[100];
_GetFreeTypeProfileString(lpszKey, _T("\0"), buffer, sizeof(buffer), lpszFile);
if (buffer[0] == '\0') {
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return false;
}
LPTSTR p = buffer;
CStringTokenizer token;
int argc = 0;
argc = token.Parse(buffer);
for (int i = 0; i < 5; i++) {
LPCTSTR arg = token.GetArgument(i);
if (!arg)
return false; //イホハノルモレ5クモホェイサハケモテエヒイホハ
arr[i] = _StrToInt(arg, arr[i]);
}
return true;
}
bool CGdippSettings::AddIndividualFromSection(LPCTSTR lpszSection, LPCTSTR lpszFile, IndividualArray& arr)
{
LPTSTR buffer = _GetPrivateProfileSection(lpszSection, lpszFile);
if (buffer == NULL) {
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return false;
}
LPTSTR p = buffer;
TCHAR buff[LF_FACESIZE+1];
LOGFONT truefont={0};
while (*p) {
bool b = false;
LPTSTR pnext = p;
for (; *pnext; pnext++);
//"MS Pゴシック=0,0" みたいな文字列を分割
LPTSTR value = _tcschr(p, _T('='));
CStringTokenizer token;
int argc = 0;
if (value) {
*value++ = _T('\0');
argc = token.Parse(value);
}
GetFontLocalName(p, buff);//ラェササラヨフ蠹・
CFontIndividual fi(buff);
const CFontSettings& fsCommon = m_FontSettings;
CFontSettings& fs = fi.GetIndividual();
//Individualが無ければ共通設定を使う
fs = fsCommon;
for (int i = 0; i < MAX_FONT_SETTINGS; i++) {
LPCTSTR arg = token.GetArgument(i);
if (!arg)
break;
const int n = _StrToInt(arg, fsCommon.GetParam(i));
fs.SetParam(i, n);
}
for (int i = 0 ; i < arr.GetSize(); i++) {
if (arr[i] == fi) {
b = true;
break;
}
}
if (!b) {
arr.Add(fi);
#ifdef _DEBUG
TRACE(_T("Individual: %s, %d, %d, %d, %d, %d, %d\n"), fi.GetName(),
fs.GetParam(0), fs.GetParam(1), fs.GetParam(2), fs.GetParam(3), fs.GetParam(4), fs.GetParam(5));
#endif
}
p = pnext;
p++;
}
return false;
}
LPTSTR CGdippSettings::_GetPrivateProfileSection(LPCTSTR lpszSection, LPCTSTR lpszFile)
{
return const_cast<LPTSTR>((LPCTSTR)m_Config[lpszSection]);
}
//atolにデフォルト値を返せるようにしたような物
int CGdippSettings::_StrToInt(LPCTSTR pStr, int nDefault)
{
#define isspace(ch) (ch == _T('\t') || ch == _T(' '))
#define isdigit(ch) ((_TUCHAR)(ch - _T('0')) <= 9)
int ret;
bool neg = false;
LPCTSTR pStart;
for (; isspace(*pStr); pStr++);
switch (*pStr) {
case _T('-'):
neg = true;
case _T('+'):
pStr++;
break;
}
pStart = pStr;
ret = 0;
for (; isdigit(*pStr); pStr++) {
ret = 10 * ret + (*pStr - _T('0'));
}
if (pStr == pStart) {
return nDefault;
}
return neg ? -ret : ret;
#undef isspace
#undef isdigit
}
int CGdippSettings::_httoi(const TCHAR *value)
{
struct CHexMap
{
TCHAR chr;
int value;
};
const int HexMapL = 16;
CHexMap HexMap[HexMapL] =
{
{'0', 0}, {'1', 1},
{'2', 2}, {'3', 3},
{'4', 4}, {'5', 5},
{'6', 6}, {'7', 7},
{'8', 8}, {'9', 9},
{'A', 10}, {'B', 11},
{'C', 12}, {'D', 13},
{'E', 14}, {'F', 15}
};
TCHAR *mstr = _tcsupr(_tcsdup(value));
TCHAR *s = mstr;
int result = 0;
if (*s == '0' && *(s + 1) == 'X') s += 2;
bool firsttime = true;
while (*s != '\0')
{
bool found = false;
for (int i = 0; i < HexMapL; i++)
{
if (*s == HexMap[i].chr)
{
if (!firsttime) result <<= 4;
result |= HexMap[i].value;
found = true;
break;
}
}
if (!found) break;
s++;
firsttime = false;
}
free(mstr);
return result;
}
//atofにデフォルト値を返せるようにしたような物
float CGdippSettings::_StrToFloat(LPCTSTR pStr, float fDefault)
{
#define isspace(ch) (ch == _T('\t') || ch == _T(' '))
#define isdigit(ch) ((_TUCHAR)(ch - _T('0')) <= 9)
int ret_i;
int ret_d;
float ret;
bool neg = false;
LPCTSTR pStart;
for (; isspace(*pStr); pStr++);
switch (*pStr) {
case _T('-'):
neg = true;
case _T('+'):
pStr++;
break;
}
pStart = pStr;
ret = 0;
ret_i = 0;
ret_d = 1;
for (; isdigit(*pStr); pStr++) {
ret_i = 10 * ret_i + (*pStr - _T('0'));
}
if (*pStr == _T('.')) {
pStr++;
for (; isdigit(*pStr); pStr++) {
ret_i = 10 * ret_i + (*pStr - _T('0'));
ret_d *= 10;
}
}
ret = (float)ret_i / (float)ret_d;
if (pStr == pStart) {
return fDefault;
}
return neg ? -ret : ret;
#undef isspace
#undef isdigit
}
bool CGdippSettings::IsFontExcluded(LPCSTR lpFaceName) const
{
WCHAR szStack[LF_FACESIZE];
LPWSTR lpUnicode = _StrDupExAtoW(lpFaceName, -1, szStack, LF_FACESIZE, NULL);
if (!lpUnicode) {
return false;
}
bool b = IsFontExcluded(lpUnicode);
if (lpUnicode != szStack)
free(lpUnicode);
return b;
}
bool CGdippSettings::IsFontExcluded(LPCWSTR lpFaceName) const
{
FontHashMap::const_iterator it = m_arrExcludeFont.find(lpFaceName);
bool bExcluded = it != m_arrExcludeFont.end(); // if it's excluded, true
if (!bExcluded && m_arrIncludeFont.size() != 0) { // if it's not excluded, and includefont enabled
FontHashMap::const_iterator it = m_arrIncludeFont.find(lpFaceName);
bExcluded = it == m_arrIncludeFont.end(); // check if it's included
}
return bExcluded;
}
void CGdippSettings::AddFontExclude(LPCWSTR lpFaceName)
{
if (!IsFontExcluded(lpFaceName))
m_arrExcludeFont.insert(lpFaceName);
}
bool CGdippSettings::IsProcessUnload() const
{
if (m_bRunFromGdiExe) {
return false;
}
GetEnvironmentVariableW(L"MACTYPE_FORCE_LOAD", NULL, 0);
if (GetLastError()!=ERROR_ENVVAR_NOT_FOUND)
return false;
ModuleHashMap::const_iterator it = m_arrUnloadModule.begin();
for(; it != m_arrUnloadModule.end(); ++it) {
if (IsFolder(it->c_str())) {
// if the user is trying to include a folder instead of a single executable.
if (GetAppDir() == LowerCase(*it)) {
return true;
}
}
else
if (GetModuleHandleW(it->c_str())) {
return true;
}
}
return false;
}
bool CGdippSettings::IsExeUnload(LPCTSTR lpApp) const //シ・鯡ヌキレコレテ遧・チミア朗?
{
if (m_bRunFromGdiExe) {
return false;
}
GetEnvironmentVariableW(L"MACTYPE_FORCE_LOAD", NULL, 0);
if (GetLastError()!=ERROR_ENVVAR_NOT_FOUND)
return false;
ModuleHashMap::const_iterator it = m_arrUnloadModule.begin();
for(; it != m_arrUnloadModule.end(); ++it) {