Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: ollydbg on October 08, 2022, 01:39:46 pm

Title: Editor enable DirectWrite or not have different font width
Post by: ollydbg on October 08, 2022, 01:39:46 pm
I'm using this font: be5invis/Sarasa-Gothic: Sarasa Gothic / 更纱黑体 / 更紗黑體 / 更紗ゴシック / 사라사 고딕 (https://github.com/be5invis/Sarasa-Gothic)

Especially the mono Simplified Chinese(SC) version. That is: The width of the Chinese character is 2 times as the English character.

Now, the text shows differently when I have DirectWrite enabled or not, see the attachments. When DirectWrite is enabled, the alignment is broken.

Any ideas?





Title: Re: Editor enable DirectWrite or not have different font width
Post by: New Pagodi on October 08, 2022, 07:18:42 pm
I'm not sure about codeblocks, but in the stc source the average char width for a font is set like this:

Code
m_averageCharWidth = textmetrics.width/extentTest.length();

where extentTest is is a wxString built from " `~!@#$%^&*()-_=+\\|[]{};:\"\'<,>.?/1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

Obviously that's going to have trouble with nonlatin characters.  A better test for average char width is needed that can account for nonlatin characters, but I have no clue how to do that.
Title: Re: Editor enable DirectWrite or not have different font width
Post by: ollydbg on October 09, 2022, 04:30:05 am
Hi, New Pagodi, thanks for the reply.

I just test the wxWidgets' font sample code.

It looks like when I choose the font size = 10 or font size = 12, the alignment is correct, while if I select the font size = 11, the alignment is wrong.

I just checked this issue under Notepad++, it works correctly in all the three font sizes.

So, my guess is that this issue if from the wxWidgets' font handling, not from the stc source.

See the screen shot below:


EDIT:

Compared with Notepad++, it looks like that in wx font sample, when the mis-alignment happens, the Chinese characters width is correct, and the English character has one extra space in the horizontal direction. So, the English text line is a bit longer than the Chinese text line.


Title: Re: Editor enable DirectWrite or not have different font width
Post by: ollydbg on October 11, 2022, 02:49:50 pm
Hi, everyone, it looks like this is related to the font issue.

See this issue and discussion:

CJK characters alignment issue in some applications Issue #1 jonz94/Sarasa-Gothic-Nerd-Fonts (https://github.com/jonz94/Sarasa-Gothic-Nerd-Fonts/issues/1)

And this fork of the Sarasa-Gothic font fixed such issue.

Title: Re: Editor enable DirectWrite or not have different font width
Post by: ollydbg on October 11, 2022, 03:00:27 pm
There are mainly two issues here:
1, different font size are not aligned correctly, this issue is related to font itself, see my previous post

2, the DirectWrite/Non-DirectWrite issue still remains. The alignment is totally wrong when DirectWrite is enabled.
Title: Re: Editor enable DirectWrite or not have different font width
Post by: ollydbg on October 12, 2022, 06:30:06 am
I found another issue:

Code::Blocks' editor will be extremely slow when I use the be5invis/Sarasa-Gothic: Sarasa Gothic / 更纱黑体 / 更紗黑體 / 更紗ゴシック / 사라사 고딕 (https://github.com/be5invis/Sarasa-Gothic). The font with hinting feature cause this issue. If I use the unhinted version, the editor renders fast.

Here is the related discussion:
https://github.com/be5invis/Sarasa-Gothic/issues/218#issuecomment-757409436

Quote
Sarasa intensively uses TT hints to maximize clarity - so a badly implemented rasterizer may become slow when scaling them.

I just check the Notepad++, and it works fast in either hinted or unhinted font.

Do you know how to fix the Code::Blocks' render?