Author Topic: CodeBlocks and Fira Code issues  (Read 5924 times)

Offline sodev

  • Regular
  • ***
  • Posts: 405
CodeBlocks and Fira Code issues
« on: May 22, 2019, 09:13:39 pm »
I am using the latest CodeBlocks revision 11703 together with wxWidgets f668f5b36f to play around with Fira Code and it doesn't work correctly, neither on Windows (Windows 10 1809) nor Linux (CentOS 7.6.1810 with MATE Desktop). The effects are slightly different though.

The good news: ligatures are working (when using Direct2D), the bad news: only the regular variant of Fira Code is working. All other variants (light, medium, bold, italic and its combinations) are not working in the editor. But they are working in the preview of the editor settings page (im not talking about the font selection dialog but the text left to the button to open it) and get applied to the line numbers.

In the editor however, something else happens, and for me this is different on Windows and Linux. If i select another variant on Linux it seems it is still using the regular variant, on Windows however for most variants it seems like a replacement font is used instead, only a few seem to use the regular variant.

For reference, on Linux in Eclipse all variants do work for me.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12897
    • Travis build status
Re: CodeBlocks and Fira Code issues
« Reply #1 on: May 22, 2019, 10:55:32 pm »
Check if it works in scite or some other scintilla based editor. If it works there then it is a problem of C::B else it is in wx/scintilla/direct2d.

What wx version are you using?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline sodev

  • Regular
  • ***
  • Posts: 405
Re: CodeBlocks and Fira Code issues
« Reply #2 on: May 23, 2019, 10:14:18 pm »
Did some tests with quite some surprising effects.

First some interesting aspect about how you select a font, each application (CodeBlocks, Notepad++, SciTE) does it different:
  • In CodeBlocks you select the font face name and select weight and italics from a combined list of selections (e.g. light, bold italics)
  • In Notepad++ you have multiple font entries with the font face name and the weight attached except bold (e.g. Fira Code, Fira Code Light) and a boolean for bold and italics
  • In SciTE you select the font face name and have to specify italics as boolean and the weight as integer

In SciTE everything works as excepted on Windows and Linux, using the proper weight values selects the proper variant, applying italics works as well.

Now Notepad++, this is really strange, every combination works (yes, you can apply bold to everything) in plain text mode. If you turn on the c++ lexer (didn't try others) it breaks. The regular text is shown in the selected variant, BUT the bold and italics property gets only applied to the invisible characters (you need to turn them on). And ligatures don't work at all.

What wx version are you using?
wxWidgets f668f5b36f
That git revision, in 32 bit if that matters, with all compatibility options disabled.

Offline sodev

  • Regular
  • ***
  • Posts: 405
Re: CodeBlocks and Fira Code issues
« Reply #3 on: May 24, 2019, 06:30:56 am »
Ok, this happens if you are lazy and do the tests in a hurry, the strange things with enabled c++ lexer in Notepad++ stop to happen if you actually do not set the Default Style but the Global Override.

I took some more time and applied the workaround to enable SC_TECHNOLOGY_DIRECTWRITE in Notepad++ and discovered something interesting. In contrast to my previous test now certain fonts do also fail, but i get ligatures instead :). I get a replacement font for every selection except plain Fira Code and Fira Code Retina, so all font names with attached weight in the name do not work. This sounds quite similar to my CodeBlocks experience. So apparently only the SciTE way to select font weight and italics works in Direct2D mode correctly.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2848
Re: CodeBlocks and Fira Code issues
« Reply #4 on: May 27, 2019, 12:11:15 am »
I tested this today with latest codebocks on windows and wx3.1.2 and codeblocks crashes after typing
Code: [Select]
...
Have to recompile all with debug symbols to get a backtrace...

Offline Miguel Gimenez

  • Lives here!
  • ****
  • Posts: 570
Re: CodeBlocks and Fira Code issues
« Reply #5 on: May 27, 2019, 10:16:43 am »
With wx3.1.2 you will get crashes with Code Completion if you don't backport New Pagodi's changes in wx trunk to wx3.1.2

I published a patch with this backport in the forum, see http://forums.codeblocks.org/index.php/topic,22974.msg156992.html#msg156992
« Last Edit: May 27, 2019, 10:23:36 am by Miguel Gimenez »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2848
Re: CodeBlocks and Fira Code issues
« Reply #6 on: May 27, 2019, 01:03:07 pm »
But with wx trunk it should work? I will recompile and test...

Offline sodev

  • Regular
  • ***
  • Posts: 405
Re: CodeBlocks and Fira Code issues
« Reply #7 on: May 27, 2019, 01:21:44 pm »
I get no crashes with the revision that im using

Offline Miguel Gimenez

  • Lives here!
  • ****
  • Posts: 570
Re: CodeBlocks and Fira Code issues
« Reply #8 on: May 30, 2019, 07:50:39 pm »
Using Fira Code Normal, size 10, the editor looks OK but Code Completion auto complete popups show a bigger than normal font, so the texts are truncated on the right side. To reproduce just move the cursor to the first column and press #.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12897
    • Travis build status
Re: CodeBlocks and Fira Code issues
« Reply #9 on: May 30, 2019, 08:17:37 pm »
Does it happen the same way in stc demo in wxWidgets' samples?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Miguel Gimenez

  • Lives here!
  • ****
  • Posts: 570
Re: CodeBlocks and Fira Code issues
« Reply #10 on: May 30, 2019, 08:47:58 pm »
Tested annotations in STC sample and more tests in C::B. The problem is not he font but the Direct Write activation:

- STC: I can't change the font, but the popup has a font slightly smaller than the main text
- C::B without Direct Write (default mode): the font size seems identical to the editor one. No text truncation
- C::B with Direct Write: the popup font is noticeably bigger that the editor one and the text is ellipsized.

I have attached three screen captures in one file.

EDIT: the two C::B tests are made with Courier New size 10.
« Last Edit: May 30, 2019, 08:50:46 pm by Miguel Gimenez »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12897
    • Travis build status
Re: CodeBlocks and Fira Code issues
« Reply #11 on: May 30, 2019, 11:56:05 pm »
- STC: I can't change the font, but the popup has a font slightly smaller than the main text
You can change the font using code. Make sure it is the same in both applications.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Miguel Gimenez

  • Lives here!
  • ****
  • Posts: 570
Re: CodeBlocks and Fira Code issues
« Reply #12 on: May 31, 2019, 10:20:42 am »
Changed the font in STC sample forcing Courier New size 10, no visual changes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12897
    • Travis build status
Re: CodeBlocks and Fira Code issues
« Reply #13 on: May 31, 2019, 08:19:41 pm »
There is an array with styles are you sure you've changed the font for all styles?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Miguel Gimenez

  • Lives here!
  • ****
  • Posts: 570
Re: CodeBlocks and Fira Code issues
« Reply #14 on: May 31, 2019, 08:47:52 pm »
I changed the font in three places, one was in a loop for all styles. Anyway the original font seems to be Courier New 10, as the aspect doesn't change (it did change when I wrote "CourierNew" for family name instead of "Courier New").

Offline New Pagodi

  • Multiple posting newcomer
  • *
  • Posts: 35
Re: CodeBlocks and Fira Code issues
« Reply #15 on: May 31, 2019, 09:38:45 pm »
This does seem to be a bug with wxSTC.  I've a standard demo application of mine for the screenshots below.  It has a wxSTC on the left and a native Scintilla window on the right.  The first is with the default GDI drawing and the second is with direct write drawing.  The font in the autocompletion window does end up larger than it should be when direct write drawing is used.  I don't know what could be going on here.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7012
    • My Best Post
Re: CodeBlocks and Fira Code issues
« Reply #16 on: June 01, 2019, 12:16:19 am »
Link to wxwidgets master branch change https://github.com/wxWidgets/wxWidgets/pull/1123
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline New Pagodi

  • Multiple posting newcomer
  • *
  • Posts: 35
Re: CodeBlocks and Fira Code issues
« Reply #17 on: June 01, 2019, 08:50:12 pm »
I'm pretty sure I know what the problem is with the font size in the list boxes.  Direct write uses DIPs for font size.  So when the technology is set to direct write, Scintilla internally scales all the fonts by 96/72 so that so drawing comes out as expected for a given font size.  So, for example, when you try to set the default font size to be 10pts, Scintilla interanlly creates a 10*96/72 = 13.333 pt font.  When drawing text in the editor, that's not a problem, but when passing that font to the list control (as is done in ListBoxImpl::SetFont), the font will be larger than expected. 

The quick fix is to check the technology in ListBoxImpl::SetFont and unscale the font if needed.  A better fix would be to measure and draw the autocompletion listbox with direct write using the SurfaceD2D methods.

Offline Miguel Gimenez

  • Lives here!
  • ****
  • Posts: 570
Re: CodeBlocks and Fira Code issues
« Reply #18 on: June 03, 2019, 06:53:50 pm »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12897
    • Travis build status
Re: CodeBlocks and Fira Code issues
« Reply #19 on: June 03, 2019, 08:10:50 pm »
Anything in STC should first be fixed in wxWidgets. I'm just backporting fixes...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Miguel Gimenez

  • Lives here!
  • ****
  • Posts: 570
Re: CodeBlocks and Fira Code issues
« Reply #20 on: June 04, 2019, 08:32:09 pm »
New Pagodi, I have published a patch in the ticket zone with your first suggestion. Can you review it? Is it possible to create a PR in wxWidgets?

It is attached here too for convenience.

Offline New Pagodi

  • Multiple posting newcomer
  • *
  • Posts: 35
Re: CodeBlocks and Fira Code issues
« Reply #21 on: June 04, 2019, 09:20:31 pm »
New Pagodi, I have published a patch in the ticket zone with your first suggestion. Can you review it? Is it possible to create a PR in wxWidgets?

It is attached here too for convenience.

That seems fine.  I eventually want to try to use the SurfaceD2D functions for measuring and drawing and if I can get that to work, I'll try to submit a patch the wxWidgets, but I don't know when I'll be able to get to that.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12897
    • Travis build status
Re: CodeBlocks and Fira Code issues
« Reply #22 on: February 24, 2020, 08:18:02 pm »
@New Pagodi: Any progress with this issue?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5265
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CodeBlocks and Fira Code issues
« Reply #23 on: November 11, 2020, 06:07:13 am »
Fix size and postion of STC popups with DirectWrite by NewPagodi Pull Request #1906 wxWidgets/wxWidgets

It looks like this issue is fixed in wx's master, but not in wx 3.1.4.
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 Miguel Gimenez

  • Lives here!
  • ****
  • Posts: 570
Re: CodeBlocks and Fira Code issues
« Reply #24 on: November 11, 2020, 07:32:30 am »
It is fixed in master, but C::B uses a modified version of Scintilla, so changing to wx3.1.5 won't solve the issue.

Offline Quiss

  • Multiple posting newcomer
  • *
  • Posts: 76
Re: CodeBlocks and Fira Code issues
« Reply #25 on: November 11, 2020, 07:51:10 am »
My build is with wxmaster-1f3150b5f0d050262dbe132fc60d33a5e351d5b3 (25.09.2020), the issue (bigger font in popup window) isn't fixed (Miguel Gimenez wrote a reply while I'm writing). The thing is, I changed technology in the settings to DirectWrite just to check this.

Without DirectWrite, fonts are ok in popup but truncated. Font is Consolas-Regular-10. If I change font to Cascadia Mono-Regular-10, it doesn't truncated. I don't know if it's related to this topic or not.

Consolas, Arial, Georgia, Tahoma truncated.
Cascadia Mono, Calibri, Courier New not truncated.
« Last Edit: November 11, 2020, 07:56:44 am by Quiss »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5265
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CodeBlocks and Fira Code issues
« Reply #26 on: November 12, 2020, 10:53:28 am »
It is fixed in master, but C::B uses a modified version of Scintilla, so changing to wx3.1.5 won't solve the issue.
OK, I see, thanks.
So, currently, for C::B build against wx3.14 or wx3.13, I can use a workaround patch supplied by you in Code::Blocks / Tickets / #835 wxSTC popups' font bigger than expected when using DirectWrite, which is against our C::B code base. Am I right?

EDIT:
I'm pretty sure I know what the problem is with the font size in the list boxes.  Direct write uses DIPs for font size.  So when the technology is set to direct write, Scintilla internally scales all the fonts by 96/72 so that so drawing comes out as expected for a given font size.  So, for example, when you try to set the default font size to be 10pts, Scintilla interanlly creates a 10*96/72 = 13.333 pt font.  When drawing text in the editor, that's not a problem, but when passing that font to the list control (as is done in ListBoxImpl::SetFont), the font will be larger than expected. 

The quick fix is to check the technology in ListBoxImpl::SetFont and unscale the font if needed.  A better fix would be to measure and draw the autocompletion listbox with direct write using the SurfaceD2D methods.

So, your patch in Code::Blocks / Tickets / #835 wxSTC popups' font bigger than expected when using DirectWrite https://sourceforge.net/p/codeblocks/tickets/835/ is the "quick fix".

« Last Edit: November 12, 2020, 11:07:06 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 Miguel Gimenez

  • Lives here!
  • ****
  • Posts: 570
Re: CodeBlocks and Fira Code issues
« Reply #27 on: November 12, 2020, 11:27:43 am »
Quote
So, your patch is the "quick fix"

Yes, the patch is directwrite.patch. It works OK as long as you use 100% display scaling.

Probably it's easy to include scaling in the calculation, just include wxDisplay::GetScaleFactor() in the calculations (currently scale > 100 % makes the font bigger). If C::B is on the primary display:

Code: [Select]
GETLB(wid)->SetFont(NewFont->Scaled(72.0/(96.0*wxDisplay().GetScaleFactor())));
This line may need to be changed also:

Code: [Select]
maxw = (maxw*96)/72;
I can test this tonight.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5265
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CodeBlocks and Fira Code issues
« Reply #28 on: November 12, 2020, 11:40:47 am »
I can test this tonight.
OK, thanks.
I have one PC which use 100% scale, and another use 125% scale. :)
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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12897
    • Travis build status
Re: CodeBlocks and Fira Code issues
« Reply #29 on: November 12, 2020, 03:56:40 pm »
It is better to use the scaling factor of the window and not the display.
If you want to use a display you'll have to use something like wxDisplay::FromWindow(myWindow).
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5265
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CodeBlocks and Fira Code issues
« Reply #30 on: November 14, 2020, 04:31:40 am »
Code: [Select]
src/sdk/wxscintilla/src/PlatWX.cpp | 30 ++++++++++++++++++++++++++++--
 src/sdk/wxscintilla/src/PlatWX.h   |  3 +++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/src/sdk/wxscintilla/src/PlatWX.cpp b/src/sdk/wxscintilla/src/PlatWX.cpp
index 8919929b..871d513b 100644
--- a/src/sdk/wxscintilla/src/PlatWX.cpp
+++ b/src/sdk/wxscintilla/src/PlatWX.cpp
@@ -2415,6 +2415,9 @@ ListBoxImpl::ListBoxImpl()
     : lineHeight(10), unicodeMode(false),
       desiredVisibleRows(5), aveCharWidth(8), maxStrWidth(0),
       imgList(NULL), imgTypeMap(NULL)
+/* C::B begin */
+      , technology(wxSCI_TECHNOLOGY_DEFAULT)
+/* C::B end */
 {
 }
 
@@ -2425,14 +2428,28 @@ ListBoxImpl::~ListBoxImpl() {
 
 
 void ListBoxImpl::SetFont(Font &font) {
-    GETLB(wid)->SetFont(*((wxFont*)font.GetID()));
+/* C::B begin */
+    // GETLB(wid)->SetFont(*((wxFont*)font.GetID()));
+    wxFont *NewFont = (wxFont*)font.GetID();
+    if (technology == wxSCI_TECHNOLOGY_DEFAULT)
+        GETLB(wid)->SetFont(*NewFont);
+    else
+    {
+        double scale = GETLB(wid)->GetDPIScaleFactor();
+        GETLB(wid)->SetFont(NewFont->Scaled(72.0/(96.0*scale)));
+    }
+
+/* C::B end */
 }
 
 
-void ListBoxImpl::Create(Window &parent, int ctrlID, Point location_, int lineHeight_, bool unicodeMode_, int WXUNUSED(technology_)) {
+void ListBoxImpl::Create(Window &parent, int ctrlID, Point location_, int lineHeight_, bool unicodeMode_, int technology_) {
     location = location_;
     lineHeight =  lineHeight_;
     unicodeMode = unicodeMode_;
+/* C::B begin */
+    technology = technology_;
+/* C::B end */
     maxStrWidth = 0;
     wid = new wxSCIListBoxWin(GETWIN(parent.GetID()), ctrlID, location);
     if (imgList != NULL)
@@ -2463,6 +2480,14 @@ PRectangle ListBoxImpl::GetDesiredRect() {
     // wxListCtrl doesn't have a DoGetBestSize, so instead we kept track of
     // the max size in Append and calculate it here...
     int maxw = maxStrWidth * aveCharWidth;
+/* C::B begin */
+    if (technology == wxSCI_TECHNOLOGY_DIRECTWRITE)
+    {
+        double scale = GETLB(wid)->GetDPIScaleFactor();
+        maxw = (maxw*96*scale)/72;
+    }
+
+/* C::B end */
     int maxh ;
 
     // give it a default if there are no lines, and/or add a bit more
@@ -2497,6 +2522,7 @@ PRectangle ListBoxImpl::GetDesiredRect() {
     rc.left = 0;
     rc.right = maxw;
     rc.bottom = maxh;
+
     return rc;
 }
 
diff --git a/src/sdk/wxscintilla/src/PlatWX.h b/src/sdk/wxscintilla/src/PlatWX.h
index 44538ea1..7fe41e9d 100644
--- a/src/sdk/wxscintilla/src/PlatWX.h
+++ b/src/sdk/wxscintilla/src/PlatWX.h
@@ -26,6 +26,9 @@ private:
     Point               location;       // Caret location at which the list is opened
     wxImageList*        imgList;
     wxArrayInt*         imgTypeMap;
+/* C::B begin */
+    int                 technology;
+/* C::B end */
 
 public:
     ListBoxImpl();


This is the patch I use. I tested it under with scale 100% and scale 125, and it works OK.
« Last Edit: November 14, 2020, 04:40: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.