diff --git a/ft.cpp b/ft.cpp index 61df7cf..de47fc6 100644 --- a/ft.cpp +++ b/ft.cpp @@ -589,8 +589,7 @@ static void FreeTypeDrawBitmapPixelModeLCD(FreeTypeGlyphInfo& FTGInfo, backColor = cachebufrowp[dx]; COLORREF last = 0xFFFFFFFF; if (AAMode == 2 || AAMode == 4) { - // これはRGBの順にサブピクセルがあるディスプレイ用 - // これはRGBの順にサブピクセルがあるディスプレイ用 + // This is for displays with subpixels in RGB order alphaR = p[i + 0] / alphatuner; alphaG = p[i + 1] / alphatuner; alphaB = p[i + 2] / alphatuner; @@ -1641,6 +1640,10 @@ BOOL ForEachGetGlyphFT(FreeTypeDrawInfo& FTInfo, LPCTSTR lpString, int cbString, FT_Render_Mode render_mode = FTInfo.render_mode; const int LinkNum = FTInfo.face_id_list_num; int AAMode = FTInfo.pfs->GetAntiAliasMode(); + // fix AAMode to LCD if harmony lcd is enabled. This is will not affect directwrite output. + if (AAMode > 2 && pSettings->HarmonyLCD()) { + AAMode = 2; + } int* AAList = FTInfo.AAModes; const LOGFONTW& lf = FTInfo.LogFont(); FreeTypeFontCache* pftCache = FTInfo.pftCache; diff --git a/override.cpp b/override.cpp index f3dc27b..9e784ac 100644 --- a/override.cpp +++ b/override.cpp @@ -1659,7 +1659,7 @@ DWORD WINAPI IMPL_GetFontData(_In_ HDC hdc, if (dwTable != 0x656d616e) // we only simulate the name table, for other tables, use the substituted font data return ORIG_GetFontData(hdc, dwTable, dwOffset, pvBuffer, cjBuffer); - DWORD ret = (DWORD)INVALID_HANDLE_VALUE; + DWORD ret = GDI_ERROR; ENUMLOGFONTEXDVW envlf = { 0 }; HFONT hCurFont = GetCurrentFont(hdc); if (GetCachedFontLocale(hCurFont) && GetObjectW(hCurFont, sizeof(LOGFONT), &envlf.elfEnumLogfontEx.elfLogFont)) {// call hooked version of GetObject to retrieve font info that the app originally want to create @@ -1673,7 +1673,7 @@ DWORD WINAPI IMPL_GetFontData(_In_ HDC hdc, } DeleteDC(memdc); } - if (ret == (DWORD)INVALID_HANDLE_VALUE) // any of the above operations failed or the font is not substituted + if (ret == GDI_ERROR) // any of the above operations failed or the font is not substituted ret = ORIG_GetFontData(hdc, dwTable, dwOffset, pvBuffer, cjBuffer); // fallback to original return ret; } diff --git a/settings.cpp b/settings.cpp index c8ffa14..12595ec 100644 --- a/settings.cpp +++ b/settings.cpp @@ -178,37 +178,39 @@ void CGdippSettings::DelayedInit() 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 + if (m_bUseCustomPixelLayout) { + FT_Vector sub[3] = { { m_arrPixelLayout[0], m_arrPixelLayout[1]}, + {m_arrPixelLayout[2], m_arrPixelLayout[3]}, + {m_arrPixelLayout[4], m_arrPixelLayout[5]}}; // custom layout 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 { + 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 }, { 21, 0 } }; + FT_Library_SetLcdGeometry(freetype_library, sub); + break; + } + case 3: //BGR + case 5: { + FT_Vector sub[3] = { { 21, 0 }, { 0, 0 }, { -21, 0 } }; + FT_Library_SetLcdGeometry(freetype_library, sub); + break; + } + case 6: { + //Pentile + FT_Vector sub[3] = { {-11, 16}, {-11, -16}, {22, 0} }; + FT_Library_SetLcdGeometry(freetype_library, sub); + break; + } + } } } else { @@ -721,6 +723,8 @@ bool CGdippSettings::LoadAppSettings(LPCTSTR lpszFile) m_bUseCustomLcdFilter = AddLcdFilterFromSection(names.c_str(), lpszFile, m_arrLcdFilterWeights); else m_bUseCustomLcdFilter = AddLcdFilterFromSection(_T("LcdFilterWeight"), lpszFile, m_arrLcdFilterWeights); + + m_bUseCustomPixelLayout = AddPixelModeFromSection(_T("PixelLayout"), lpszFile, m_arrPixelLayout); return true; } @@ -793,6 +797,30 @@ bool CGdippSettings::AddLcdFilterFromSection(LPCTSTR lpszKey, LPCTSTR lpszFile, return true; } +bool CGdippSettings::AddPixelModeFromSection(LPCTSTR lpszKey, LPCTSTR lpszFile, 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 < 6; i++) { + LPCTSTR arg = token.GetArgument(i); + if (!arg) + return false; + arr[i] = _StrToInt(arg, arr[i]); + } + + return true; +} + bool CGdippSettings::AddIndividualFromSection(LPCTSTR lpszSection, LPCTSTR lpszFile, IndividualArray& arr) { LPTSTR buffer = _GetPrivateProfileSection(lpszSection, lpszFile); @@ -1169,10 +1197,7 @@ const CFontSettings& CGdippSettings::FindIndividual(LPCTSTR lpFaceName) const for(; p != end; ++p) { if (p->GetHash() == hash) { - CFontSettings& individual = p->GetIndividual(); - if (this->m_bHarmonyLCDRendering && individual.GetAntiAliasMode() > 1) - individual.SetAntiAliasMode(2); - return individual; + return p->GetIndividual(); } } return GetFontSettings(); diff --git a/settings.h b/settings.h index 56ac716..18379d3 100644 --- a/settings.h +++ b/settings.h @@ -269,7 +269,8 @@ class CGdippSettings // bool m_bIsHDBench : 1; // bool m_bHaveNewerFreeType : 1; bool : 0; - bool m_bUseCustomLcdFilter; //使用自定义lcdfilter + bool m_bUseCustomLcdFilter; // use custom lcdfilter + bool m_bUseCustomPixelLayout; bool m_bHarmonyLCDRendering; BOOL m_bHintSmallFont; @@ -293,6 +294,7 @@ class CGdippSettings DWORD m_nShadowLightColor; DWORD m_nShadowDarkColor; unsigned char m_arrLcdFilterWeights[5]; + char m_arrPixelLayout[6]; //settings for experimental bool m_bEnableClipBoxFix; @@ -362,6 +364,7 @@ class CGdippSettings static bool AddExcludeListFromSection(LPCTSTR lpszSection, LPCTSTR lpszFile, set & arr); bool AddIndividualFromSection(LPCTSTR lpszSection, LPCTSTR lpszFile, IndividualArray& arr); bool AddLcdFilterFromSection(LPCTSTR lpszKey, LPCTSTR lpszFile, unsigned char* arr); + bool AddPixelModeFromSection(LPCTSTR lpszKey, LPCTSTR lpszFile, char* arr); static int _StrToInt(LPCTSTR pStr, int nDefault); static float _StrToFloat(LPCTSTR pStr, float fDefault); static int _httoi(const TCHAR *value); @@ -439,6 +442,7 @@ class CGdippSettings int BolderMode() const { return m_nBolderMode; } int GammaMode() const { return m_nGammaMode; } float GammaValue() const { return m_fGammaValue; } + bool HarmonyLCD() const { return m_bHarmonyLCDRendering; } //DW options float GammaValueForDW() const { return m_fGammaValueForDW; } @@ -457,7 +461,6 @@ 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; }