Skip to content

Commit

Permalink
Added harmony lcd rendering support so that now we can work with pent…
Browse files Browse the repository at this point in the history
…ile or LCDs with any pixel arrangement.
  • Loading branch information
snowie2000 committed Jul 20, 2022
1 parent 628faa7 commit 57f4c60
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 38 deletions.
26 changes: 0 additions & 26 deletions ft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3339,32 +3339,6 @@ BOOL FontLInit(void) {
return FALSE;
}

const int nLcdFilter = pSettings->LcdFilter();
if ((int)FT_LCD_FILTER_NONE < nLcdFilter && nLcdFilter < (int)FT_LCD_FILTER_MAX) {
FT_Library_SetLcdFilter(freetype_library, (FT_LcdFilter)nLcdFilter);
if (pSettings->UseCustomLcdFilter())
{
unsigned char buff[5];
memcpy(buff, pSettings->LcdFilterWeights(), sizeof(buff));
FT_Library_SetLcdFilterWeights(freetype_library, buff);
}
else
switch (nLcdFilter)
{
case FT_LCD_FILTER_NONE:
case FT_LCD_FILTER_DEFAULT:
case FT_LCD_FILTER_LEGACY:
{
FT_Library_SetLcdFilterWeights(freetype_library,
(unsigned char*)"\x00\x55\x56\x55\x00");
break;
}
case FT_LCD_FILTER_LIGHT:
default:
FT_Library_SetLcdFilterWeights(freetype_library,
(unsigned char*)"\x10\x40\x70\x40\x10");
}
}
//s_AlphaBlendTable.init();
s_AlphaBlendTable.initRGB();

Expand Down
22 changes: 12 additions & 10 deletions gdidll.rc
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Microsoft Visual C++ generated resource script.
//
#pragma code_page(65001)

#pragma code_page(65001)
#include "resource."

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
//#include "afxres.h"/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
Expand All @@ -24,8 +25,8 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_SYS_DEFAULT
//

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


/////////////////////////////////////////////////////////////////////////////
// Chinese (Simplified, PRC) resources
// Chinese (Simplified, China) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
Expand Down Expand Up @@ -91,7 +92,7 @@ END

#endif // APSTUDIO_INVOKED

#endif // Chinese (Simplified, PRC) resources
#endif // Chinese (Simplified, China) resources
/////////////////////////////////////////////////////////////////////////////


Expand All @@ -101,6 +102,7 @@ END
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

Expand Down
63 changes: 61 additions & 2 deletions settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static const TCHAR c_szDirectWrite[] = _T("DirectWrite");
#define HINTING_MIN 0
#define HINTING_MAX 2
#define AAMODE_MIN -1
#define AAMODE_MAX 5
#define AAMODE_MAX 6
#define GAMMAVALUE_MIN 0.0625f
#define GAMMAVALUE_MAX 20.0f
#define CONTRAST_MIN 0.0625f
Expand Down Expand Up @@ -174,6 +174,62 @@ void CGdippSettings::DelayedInit()
m_fontlinkinfo.init();
}

// Init LCD settings
this->m_bHarmonyLCDRendering = FT_Library_SetLcdFilter(NULL, FT_LCD_FILTER_NONE) == FT_Err_Unimplemented_Feature;
if (this->m_bHarmonyLCDRendering) {
// Harmony LCD rendering
switch (this->m_FontSettings.GetAntiAliasMode()) {
case 0:
case 1: {
FT_Vector sub[3] = { { 0, 0 }, { 0, 0 }, { 0, 0 } }; // gray scale
FT_Library_SetLcdGeometry(freetype_library, sub);
break;
}
case 2: //RGB
case 4: {
FT_Vector sub[3] = { { -21, 0 }, { 0, 0 }, { 0, 21 } };
FT_Library_SetLcdGeometry(freetype_library, sub);
break;
}
case 3: //BGR
case 5: {
FT_Vector sub[3] = { { 21, 0 }, { 0, 0 }, { 0, -21 } };
FT_Library_SetLcdGeometry(freetype_library, sub);
this->m_FontSettings.SetAntiAliasMode(2);
break;
}
case 6: {
//Pentile
FT_Vector sub[3] = { {-11, 16}, {-11, -16}, {22, 0} };
FT_Library_SetLcdGeometry(freetype_library, sub);
this->m_FontSettings.SetAntiAliasMode(2);
break;
}
case 7: {
// TODO: custom pixel arrangement support
this->m_FontSettings.SetAntiAliasMode(2);
}
}
}
else {
int nLcdFilter = LcdFilter();
if ((int)FT_LCD_FILTER_NONE < nLcdFilter && nLcdFilter < (int)FT_LCD_FILTER_MAX) {
switch (GetFontSettings().GetAntiAliasMode()) {
case 1:
case 4:
case 5:
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.
}
FT_Library_SetLcdFilter(freetype_library, (FT_LcdFilter)nLcdFilter);
if (UseCustomLcdFilter())
{
unsigned char buff[5];
memcpy(buff, LcdFilterWeights(), sizeof(buff));
FT_Library_SetLcdFilterWeights(freetype_library, buff);
}
}
}


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

for(; p != end; ++p) {
if (p->GetHash() == hash) {
return p->GetIndividual();
CFontSettings& individual = p->GetIndividual();
if (this->m_bHarmonyLCDRendering && individual.GetAntiAliasMode() > 1)
individual.SetAntiAliasMode(2);
return individual;
}
}
return GetFontSettings();
Expand Down
4 changes: 4 additions & 0 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class CGdippSettings
// bool m_bHaveNewerFreeType : 1;
bool : 0;
bool m_bUseCustomLcdFilter; //使用自定义lcdfilter
bool m_bHarmonyLCDRendering;

BOOL m_bHintSmallFont;
BOOL m_bDirectWrite;
Expand All @@ -286,6 +287,7 @@ class CGdippSettings
int m_nFontSubstitutes;
int m_bFontLink; //改为可以使用多种参数
int m_nWidthMode;

int m_nFontLoader;
int m_nScreenDpi; // screen dpi
DWORD m_nShadowLightColor;
Expand Down Expand Up @@ -400,6 +402,7 @@ class CGdippSettings
, m_bHintSmallFont(true)
, m_bDirectWrite(true)
, m_nScreenDpi(96)
, m_bHarmonyLCDRendering(false)
{
ZeroMemory(m_nTuneTable, sizeof(m_nTuneTable));
ZeroMemory(m_nTuneTableR, sizeof(m_nTuneTableR));
Expand Down Expand Up @@ -454,6 +457,7 @@ class CGdippSettings
int LcdFilter() const { return m_nLcdFilter; }
const unsigned char* LcdFilterWeights() const { return m_arrLcdFilterWeights; }
bool UseCustomLcdFilter() const { return m_bUseCustomLcdFilter; }
int PixelMode() const { return m_nPixelMode; }
int WidthMode() const { return m_nWidthMode; }
int FontLoader() const { return m_nFontLoader; }
bool EnableClipBoxFix() const { return m_bEnableClipBoxFix; }
Expand Down

0 comments on commit 57f4c60

Please sign in to comment.