Author Topic: font rendering issue when using C::B under windows remote desktop  (Read 1925 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5736
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
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)

Code
		<TECHNOLOGY int="0" />
<FONT_QUALITY int="3" />

But setting the value to "3" (I guess it is the ClearType option) has no effect.
« Last Edit: October 23, 2022, 02:19:49 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: font rendering issue when using C::B under windows remote desktop
« Reply #1 on: October 22, 2022, 10:06:10 am »
Long shot. The following thread may be of some use:
https://forums.codeblocks.org/index.php?topic=23207.0
Update2:Another thread that could be relevant:
https://forums.codeblocks.org/index.php?topic=21788.0
« Last Edit: October 22, 2022, 10:13:36 am by AndrewCot »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5736
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: font rendering issue when using C::B under windows remote desktop
« Reply #2 on: October 22, 2022, 11:44:58 am »
Long shot. The following thread may be of some use:
https://forums.codeblocks.org/index.php?topic=23207.0
Thanks for the reply. This link is about DirectWrite feature. I think it is not related. I just see that either in Notepad++ or Notepad2, I disable the DirectWrite feature and only enable the legacy GDI, and both the two application render the font correctly.


Quote
Update2:Another thread that could be relevant:
https://forums.codeblocks.org/index.php?topic=21788.0
Oh, this is my question in year 2017, but I see this is about DPI aware issue in the manifest. I think C::B already have the DPI aware enabled, which means C::B need to handle the DPI itself. If DPI aware is not set, the Windows will scale the application for you, and which leads to the blur text.

So, I think both the above links are not related to my original issue.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5736
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: font rendering issue when using C::B under windows remote desktop
« Reply #3 on: October 22, 2022, 12:17:37 pm »
I did some search, and it looks like:

AntiAliased

This function of wxFontInfo::AntiAliased

Quote


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 and Re: wxWidgets & ClearType

Code
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?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5736
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: font rendering issue when using C::B under windows remote desktop
« Reply #4 on: October 22, 2022, 01:15:27 pm »
I create a code snippet to enable this option in the font wxWidgets sample program.

Code
    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:

Code
 if (index == 14)
« Last Edit: October 22, 2022, 04:15:23 pm by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5736
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: font rendering issue when using C::B under windows remote desktop
« Reply #5 on: October 22, 2022, 04:14:14 pm »
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.

Code
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 and Re: wxWidgets & ClearType, 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.

« Last Edit: October 22, 2022, 04:24:27 pm by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5736
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: font rendering issue when using C::B under windows remote desktop
« Reply #6 on: October 22, 2022, 04:43:38 pm »


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!

Code
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
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9661
Re: font rendering issue when using C::B under windows remote desktop
« Reply #7 on: October 23, 2022, 04:45:09 pm »
Thanks for the effort! I tried and it also works for me.

However, just a note: Scintilla is actually something that is very old in our sources meanwhile. Also, the blocking points that stopped us from updating to a newer scintilla code base are no longer present: Native scintilla now also supports line change colouring! So we should actually try once again to update scintilla in or sources. This would also solve this issue, I guess.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5736
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: font rendering issue when using C::B under windows remote desktop
« Reply #8 on: October 24, 2022, 03:59:13 am »
Thanks for the effort! I tried and it also works for me.
Hi, Morten. I think under Windows, there should be an option to let user choose whether they need to enable the "smooth font" in legacy GDI mode. Or, we can just enable this smooth font option by default under Windows. There is no smooth font support for legacy GDI in any wxWidgets port. The Direct2D version do have smooth font support, but it has other crash issue, see this report by me: wxStyledTextCtrl with DirectWrite enabled will crash when user logs in by Windows remote desktop Issue #22872 wxWidgets/wxWidgets

Quote
However, just a note: Scintilla is actually something that is very old in our sources meanwhile. Also, the blocking points that stopped us from updating to a newer scintilla code base are no longer present: Native scintilla now also supports line change colouring! So we should actually try once again to update scintilla in or sources. This would also solve this issue, I guess.
Some infor:
1, I see Scintilla 3.21.1 by MaartenBent Pull Request #1331 wxWidgets/wxWidgets, now the Scintilla 3.21.1 is merged to the wxWidgets' trunk yesterday, so I think we should first update our code base to this version.

2, in the above github pull link, you can see there are some discussion that they may create a repo for updating the the modern Scintilla 5.x.

3, We(in our C::B forum) has some discussion before, because the modern Scintilla 5.x need C++ 17 and above

Scintilla and SciTE
Quote
Current development occurs on the default branch as 5.* which requires a recent C++ compiler that supports C++17.

For Lexilla
Quote
Current development requires a recent C++ compiler that supports C++17. The testing framework uses some C++20 features but the basic library only uses C++17.

If we need to update to the modern scintilla, we at least need C++17.

4, what do you mean by:

Quote
Native scintilla now also supports line change colouring!
?
Do you mean changing the background of the text?
Can you show me a link about this feature?






If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.