Skip to content

Commit 57f4c60

Browse files
committed
Added harmony lcd rendering support so that now we can work with pentile or LCDs with any pixel arrangement.
1 parent 628faa7 commit 57f4c60

File tree

4 files changed

+77
-38
lines changed

4 files changed

+77
-38
lines changed

ft.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,32 +3339,6 @@ BOOL FontLInit(void) {
33393339
return FALSE;
33403340
}
33413341

3342-
const int nLcdFilter = pSettings->LcdFilter();
3343-
if ((int)FT_LCD_FILTER_NONE < nLcdFilter && nLcdFilter < (int)FT_LCD_FILTER_MAX) {
3344-
FT_Library_SetLcdFilter(freetype_library, (FT_LcdFilter)nLcdFilter);
3345-
if (pSettings->UseCustomLcdFilter())
3346-
{
3347-
unsigned char buff[5];
3348-
memcpy(buff, pSettings->LcdFilterWeights(), sizeof(buff));
3349-
FT_Library_SetLcdFilterWeights(freetype_library, buff);
3350-
}
3351-
else
3352-
switch (nLcdFilter)
3353-
{
3354-
case FT_LCD_FILTER_NONE:
3355-
case FT_LCD_FILTER_DEFAULT:
3356-
case FT_LCD_FILTER_LEGACY:
3357-
{
3358-
FT_Library_SetLcdFilterWeights(freetype_library,
3359-
(unsigned char*)"\x00\x55\x56\x55\x00");
3360-
break;
3361-
}
3362-
case FT_LCD_FILTER_LIGHT:
3363-
default:
3364-
FT_Library_SetLcdFilterWeights(freetype_library,
3365-
(unsigned char*)"\x10\x40\x70\x40\x10");
3366-
}
3367-
}
33683342
//s_AlphaBlendTable.init();
33693343
s_AlphaBlendTable.initRGB();
33703344

gdidll.rc

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
// Microsoft Visual C++ generated resource script.
22
//
3-
#pragma code_page(65001)
4-
3+
#pragma code_page(65001)
4+
55
#include "resource."
66

77
#define APSTUDIO_READONLY_SYMBOLS
88
/////////////////////////////////////////////////////////////////////////////
99
//
1010
// Generated from the TEXTINCLUDE 2 resource.
1111
//
12-
//#include "afxres.h"/////////////////////////////////////////////////////////////////////////////
12+
13+
/////////////////////////////////////////////////////////////////////////////
1314
#undef APSTUDIO_READONLY_SYMBOLS
1415

1516
/////////////////////////////////////////////////////////////////////////////
@@ -24,8 +25,8 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_SYS_DEFAULT
2425
//
2526

2627
VS_VERSION_INFO VERSIONINFO
27-
FILEVERSION 1,2021,507,1
28-
PRODUCTVERSION 1,2021,5,7
28+
FILEVERSION 1,2022,720,1
29+
PRODUCTVERSION 1,2022,720,1
2930
FILEFLAGSMASK 0x8L
3031
#ifdef _DEBUG
3132
FILEFLAGS 0xbL
@@ -43,12 +44,12 @@ BEGIN
4344
VALUE "Comments", "Portions of this software are copyright (c) 2005-2021 The FreeType Project (www.freetype.org). All rights reserved."
4445
VALUE "CompanyName", "2ch & THEMEX & everyone"
4546
VALUE "FileDescription", "The Ultimate Font Rasterizer"
46-
VALUE "FileVersion", "1.2021.507.1"
47+
VALUE "FileVersion", "1.2022.720.1"
4748
VALUE "InternalName", "MacType"
4849
VALUE "LegalCopyright", "(C) 460, 168, Higambana, 555 and sy567. All rights reserved. FlyingSnow republished"
4950
VALUE "OriginalFilename", "MacType.dll"
5051
VALUE "ProductName", "The Ultimate Font Rasterizer"
51-
VALUE "ProductVersion", "1.2021.5.7"
52+
VALUE "ProductVersion", "1.2022.720.1"
5253
VALUE "URL", "http://www.mactype.net http://drwatson.nobody.jp/gdi++/"
5354
END
5455
END
@@ -63,7 +64,7 @@ END
6364

6465

6566
/////////////////////////////////////////////////////////////////////////////
66-
// Chinese (Simplified, PRC) resources
67+
// Chinese (Simplified, China) resources
6768

6869
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
6970
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
@@ -91,7 +92,7 @@ END
9192

9293
#endif // APSTUDIO_INVOKED
9394

94-
#endif // Chinese (Simplified, PRC) resources
95+
#endif // Chinese (Simplified, China) resources
9596
/////////////////////////////////////////////////////////////////////////////
9697

9798

@@ -101,6 +102,7 @@ END
101102
//
102103
// Generated from the TEXTINCLUDE 3 resource.
103104
//
104-
/////////////////////////////////////////////////////////////////////////////
105+
106+
/////////////////////////////////////////////////////////////////////////////
105107
#endif // not APSTUDIO_INVOKED
106108

settings.cpp

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static const TCHAR c_szDirectWrite[] = _T("DirectWrite");
4343
#define HINTING_MIN 0
4444
#define HINTING_MAX 2
4545
#define AAMODE_MIN -1
46-
#define AAMODE_MAX 5
46+
#define AAMODE_MAX 6
4747
#define GAMMAVALUE_MIN 0.0625f
4848
#define GAMMAVALUE_MAX 20.0f
4949
#define CONTRAST_MIN 0.0625f
@@ -174,6 +174,62 @@ void CGdippSettings::DelayedInit()
174174
m_fontlinkinfo.init();
175175
}
176176

177+
// Init LCD settings
178+
this->m_bHarmonyLCDRendering = FT_Library_SetLcdFilter(NULL, FT_LCD_FILTER_NONE) == FT_Err_Unimplemented_Feature;
179+
if (this->m_bHarmonyLCDRendering) {
180+
// Harmony LCD rendering
181+
switch (this->m_FontSettings.GetAntiAliasMode()) {
182+
case 0:
183+
case 1: {
184+
FT_Vector sub[3] = { { 0, 0 }, { 0, 0 }, { 0, 0 } }; // gray scale
185+
FT_Library_SetLcdGeometry(freetype_library, sub);
186+
break;
187+
}
188+
case 2: //RGB
189+
case 4: {
190+
FT_Vector sub[3] = { { -21, 0 }, { 0, 0 }, { 0, 21 } };
191+
FT_Library_SetLcdGeometry(freetype_library, sub);
192+
break;
193+
}
194+
case 3: //BGR
195+
case 5: {
196+
FT_Vector sub[3] = { { 21, 0 }, { 0, 0 }, { 0, -21 } };
197+
FT_Library_SetLcdGeometry(freetype_library, sub);
198+
this->m_FontSettings.SetAntiAliasMode(2);
199+
break;
200+
}
201+
case 6: {
202+
//Pentile
203+
FT_Vector sub[3] = { {-11, 16}, {-11, -16}, {22, 0} };
204+
FT_Library_SetLcdGeometry(freetype_library, sub);
205+
this->m_FontSettings.SetAntiAliasMode(2);
206+
break;
207+
}
208+
case 7: {
209+
// TODO: custom pixel arrangement support
210+
this->m_FontSettings.SetAntiAliasMode(2);
211+
}
212+
}
213+
}
214+
else {
215+
int nLcdFilter = LcdFilter();
216+
if ((int)FT_LCD_FILTER_NONE < nLcdFilter && nLcdFilter < (int)FT_LCD_FILTER_MAX) {
217+
switch (GetFontSettings().GetAntiAliasMode()) {
218+
case 1:
219+
case 4:
220+
case 5:
221+
nLcdFilter = FT_LCD_FILTER_LIGHT; // now we apply a light filter to lcd based on AA mode automatically, unless a custom lcd filter is defined.
222+
}
223+
FT_Library_SetLcdFilter(freetype_library, (FT_LcdFilter)nLcdFilter);
224+
if (UseCustomLcdFilter())
225+
{
226+
unsigned char buff[5];
227+
memcpy(buff, LcdFilterWeights(), sizeof(buff));
228+
FT_Library_SetLcdFilterWeights(freetype_library, buff);
229+
}
230+
}
231+
}
232+
177233

178234
//強制フォント
179235
/*
@@ -1113,7 +1169,10 @@ const CFontSettings& CGdippSettings::FindIndividual(LPCTSTR lpFaceName) const
11131169

11141170
for(; p != end; ++p) {
11151171
if (p->GetHash() == hash) {
1116-
return p->GetIndividual();
1172+
CFontSettings& individual = p->GetIndividual();
1173+
if (this->m_bHarmonyLCDRendering && individual.GetAntiAliasMode() > 1)
1174+
individual.SetAntiAliasMode(2);
1175+
return individual;
11171176
}
11181177
}
11191178
return GetFontSettings();

settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ class CGdippSettings
270270
// bool m_bHaveNewerFreeType : 1;
271271
bool : 0;
272272
bool m_bUseCustomLcdFilter; //使用自定义lcdfilter
273+
bool m_bHarmonyLCDRendering;
273274

274275
BOOL m_bHintSmallFont;
275276
BOOL m_bDirectWrite;
@@ -286,6 +287,7 @@ class CGdippSettings
286287
int m_nFontSubstitutes;
287288
int m_bFontLink; //改为可以使用多种参数
288289
int m_nWidthMode;
290+
289291
int m_nFontLoader;
290292
int m_nScreenDpi; // screen dpi
291293
DWORD m_nShadowLightColor;
@@ -400,6 +402,7 @@ class CGdippSettings
400402
, m_bHintSmallFont(true)
401403
, m_bDirectWrite(true)
402404
, m_nScreenDpi(96)
405+
, m_bHarmonyLCDRendering(false)
403406
{
404407
ZeroMemory(m_nTuneTable, sizeof(m_nTuneTable));
405408
ZeroMemory(m_nTuneTableR, sizeof(m_nTuneTableR));
@@ -454,6 +457,7 @@ class CGdippSettings
454457
int LcdFilter() const { return m_nLcdFilter; }
455458
const unsigned char* LcdFilterWeights() const { return m_arrLcdFilterWeights; }
456459
bool UseCustomLcdFilter() const { return m_bUseCustomLcdFilter; }
460+
int PixelMode() const { return m_nPixelMode; }
457461
int WidthMode() const { return m_nWidthMode; }
458462
int FontLoader() const { return m_nFontLoader; }
459463
bool EnableClipBoxFix() const { return m_bEnableClipBoxFix; }

0 commit comments

Comments
 (0)