When I use C::B in a remote desktop PC, I see that the font is not showing correctly.
The remote C::B is using the GDI render(since the Direct2D mode has some crash issue).
I just compared the C::B with another program Notepad2, which is also scintilla based.
In the setting menu of the Notepad2, there is an option, I choose the "legecy GDI", and in another font quality setting, I choose "default". you see in the screen shot, both C::B and Notepad2 show blur font. (See the first attachment image named 2022-10-22 14 51 21.png)
But when I select the "Font quality" menu to "ClearType", the font rendering shows good in Notepad2. (See the second attachment image named 2022-10-22 14 53 32.png)
I see we have an option also in our C::B editor setting(Font quality), but that option is gray out. (I see the C::B's font quality is only enabled when I choose the DirectWrite mode. )
My question is: how can I enable the "ClearType" in our C::B when we use the default legacy GDI rending mode.
I have tried to modify the "FONT_QUALITY" in C::B's config file(default.conf)
<TECHNOLOGY int="0" />
<FONT_QUALITY int="3" />
But setting the value to "3" (I guess it is the ClearType option) has no effect.
I did some search, and it looks like:
AntiAliased (https://docs.wxwidgets.org/trunk/classwx_font_info.html#afb8a34aec76cc22c1e79cb1c68e6aa3c)
This function of wxFontInfo::AntiAliased
Set anti-aliasing flag.
Force the use of anti-aliasing on or off.
Currently this is not implemented, i.e. using this method doesn't do anything.
But there are some solutions to enable at least under Windows:
Font color problem - wxWidgets Discussion Forum (https://forums.wxwidgets.org/viewtopic.php?p=162626#p162626) and Re: wxWidgets & ClearType (https://forums.wxwidgets.org/viewtopic.php?p=187440#p187440)
Call wxFont::GetNativeFontInfoDesc()
You will get a string that looks like this:
"0;-16;0;0;0;400;0;0;0;1;0;0;0;32;WebDings"
You need to change the "quality" property, with has index=12 (starting from 0).
Values are:
DEFAULT=0
NONANTIALIASED=3
ANTIALIASED=4
CLEARTYPE=5
Use wxFont::SetNativeFontInfo() to write the new string back.
This works only under Windows. The last time i used it was under XP, i'm not sure if it works under W7 or higher.
So, I think we can hack on this?
I create a code snippet to enable this option in the font wxWidgets sample program.
wxFont fontWithClearType = font;
wxString nativeDesc = fontWithClearType.GetNativeFontInfoDesc();
int index = 0;
for (size_t pos = 0, start = 0; pos <= nativeDesc.length(); )
{
pos = nativeDesc.find(";", start);
index++;
if (index == 13)
{
// enable the cleartype option of the font
nativeDesc.replace(start, pos - start, "5");
bool result = fontWithClearType.SetNativeFontInfo(nativeDesc);
break;
}
start = pos+1;
}
m_textctrl->SetFont(fontWithClearType);
This does change the description string, but has no effect. :(
EDIT:
problem solved, it should be:
OK, problem solved!!! I think I can hack our wxScintilla control to let it have the smooth font option enabled. (If you use Notepad++, you will see there is an option named: Enable smooth font, if you are using Notepad2, you will also see a similar option)
The trick is that the font description string format is changed in the wxWidgets.
wxString wxNativeFontInfo::ToString() const
{
wxString s;
s.Printf(wxS("%d;%s;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
1, // version
wxString::FromCDouble(pointSize),
lf.lfHeight,
lf.lfWidth,
lf.lfEscapement,
lf.lfOrientation,
lf.lfWeight,
lf.lfItalic,
lf.lfUnderline,
lf.lfStrikeOut,
lf.lfCharSet,
lf.lfOutPrecision,
lf.lfClipPrecision,
lf.lfQuality,
lf.lfPitchAndFamily,
lf.lfFaceName);
return s;
}
The above code is the current in wx 3.2.1(wxWidgets-3.2.1\src\msw\font.cpp), I believe in the wx forum, mentioned in Font color problem - wxWidgets Discussion Forum (https://forums.wxwidgets.org/viewtopic.php?p=162626#p162626) and Re: wxWidgets & ClearType (https://forums.wxwidgets.org/viewtopic.php?p=187440#p187440), the lf.lfQuality is in index 13(suppose we start from 1), and now, it becomes 14. ;)
EDIT
I see the font wx sample code works correctly, but I still need to find a way to enable the smooth font in our wxscintilla.
EDIT
I see the font wx sample code works correctly, but I still need to find a way to enable the smooth font in our wxscintilla.
This is the final version which enable the "smooth font" feature for the legacy GDI font render. I just tested in my remote PC, and it works OK!
From cce9ad5d95b0f2c9f0a9f8b0f12046718b508f33 Mon Sep 17 00:00:00 2001
From: asmwarrior <a@b.com>
Date: Sat, 22 Oct 2022 22:40:27 +0800
Subject: enable the font smooth feature
diff --git a/src/sdk/wxscintilla/src/PlatWX.cpp b/src/sdk/wxscintilla/src/PlatWX.cpp
index f72c8cdc..0cb0bd2b 100644
--- a/src/sdk/wxscintilla/src/PlatWX.cpp
+++ b/src/sdk/wxscintilla/src/PlatWX.cpp
@@ -201,7 +201,28 @@ void Font::Create(const FontParameters &fp) {
false,
sci2wx(fp.faceName),
encoding);
+
+ // enable the smooth font by default
+ // font rendering issue when using C::B under windows remote desktop
+ // https://forums.codeblocks.org/index.php/topic,25146.msg171484.html#msg171484
+
+ wxString nativeDesc = font.GetNativeFontInfoDesc();
+ int index = 0;
+ for (size_t pos = 0, start = 0; pos <= nativeDesc.length(); )
+ {
+ pos = nativeDesc.find(";", start);
+ index++;
+ if (index == 14)
+ {
+ // enable the cleartype option of the font
+ nativeDesc.replace(start, pos - start, "5");
+ bool result = font.SetNativeFontInfo(nativeDesc);
+ break;
+ }
+ start = pos+1;
+ }
wxFontWithAscent* newFont = new wxFontWithAscent(font);
+
fid = newFont;
#ifdef HAVE_DIRECTWRITE_TECHNOLOGY