Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

font hintstyle/antialias in editor differ from settings font #3610

Closed
poluyan opened this issue Oct 17, 2023 · 21 comments
Closed

font hintstyle/antialias in editor differ from settings font #3610

poluyan opened this issue Oct 17, 2023 · 21 comments

Comments

@poluyan
Copy link

poluyan commented Oct 17, 2023

I use arch with xfce4. After last update of geany-git (git >= 1b06889) I have blurry text inside editor. Only in editor, fonts in menu/settings are good. Check out font view from editor settings and inside editor.
geany_screen1
Can I change hintstyle/antialias with custom font settings at the start? Is it geany or purely GTK issue? removing .config/geany didn't change anything.

@techee
Copy link
Member

techee commented Oct 17, 2023

Can you bisect the exact commit where you started getting the blurry text? (I don't see anything too bad myself.)

@elextr
Copy link
Member

elextr commented Oct 18, 2023

You need to find out what font is "Monospace Regular", that name is an alias for another font, not a font itself. Without knowing the actual font we have no way of replicating the problem as @techee said.

@elextr
Copy link
Member

elextr commented Oct 18, 2023

Here it looks as identical as my olde eyes can tell no matter how far I zoom.

Screenshot from 2023-10-18 10-56-11

@andrej-herceg
Copy link
Contributor

That looks like Gtk2 vs Gtk3 difference

Geany / Gtk2
geany-gtk2

Geany / Gtk3
geany-gtk3

@elextr
Copy link
Member

elextr commented Oct 18, 2023

Comparing GTK2 and GTK3 was not your initial issue.

Possibilities:

  1. GTK2 and GTK3 do not render the same, quite likely, they are different and likely have different versions of Pango and harfbuzz the two libraries that actually convert font info to pixels.
  2. The fonts are not the same, or not the same version with the same hints
  3. The Scintilla rendering has changed in the versions between Geany for GTK2 (limited to Scintilla 3.5) and current git GTK3 (Scintilla 5.3.7)

As we don't have access to your system you will have to do the research, 1. and 2. you will need to check dependency versions for the libraries mentioned and versions of the fonts.

To see if there have been any changes in Scintilla operation you can check its changelog on its website.

Quite frankly the GTK3 looks right, having aliasing only on one side of the verticals as the GTK2 shows is "unusual".

@poluyan
Copy link
Author

poluyan commented Oct 18, 2023

Thanks everyone for the detailed answers! I just tested geany 1.38 (2022-05-01) from the official arch repo. The font there looks "sharp" as I wanted. It uses GTK+ v3.24.38, the same one I used building latest commit version from source. I tested geany with gtk2 too, font is sharp. I have to do some research and find out on which commit it starts blurry. It will take some time then I will write the results here.

@eht16
Copy link
Member

eht16 commented Oct 18, 2023

I didn't understand the issue completely yet but anyway maybe it's worth to try SciTE (https://archlinux.org/packages/extra/x86_64/scite/) to check whether it has the same problem.
If so, it is very likely related to Scintilla. If not, it may or may not be related to Scintilla.

@poluyan when you are bisecting, maybe check with a commit before 19336d2, this was the latest Scintilla update.

@elextr
Copy link
Member

elextr commented Oct 18, 2023

Try the merges that change Scintilla versions first.

@elextr
Copy link
Member

elextr commented Oct 18, 2023

Heh, overlapping comments

Great minds think alike :-)

@nyamatongwe
Copy link
Contributor

Possibly https://sourceforge.net/p/scintilla/code/ci/c692633b18bff53ea43e0f0a81cf56b6ebc83836/ which was to fix https://sourceforge.net/p/scintilla/bugs/2310/.

@elextr
Copy link
Member

elextr commented Oct 18, 2023

Thanks Neil, that could explain the difference between GTK2 (Scintilla 3.5) Geany and GTK3 current git (Scintilla 5.3.7) Geany.

As I said above, the images posted by the OP show the current aliasing to be more correct than the GTK2 version which never seems to alias both sides of the verticals.

The OP has not identified the font used, I compared my system Monospace (DejaVu sans mono) and Hack and the aliasing does change between them, with Hack having less, maybe slightly different character positioning in the glyph space, differing hinting?

@poluyan Aliasing is always going to have the chance of looking fuzzy on some resolutions with some fonts, so not sure what we can say except try different fonts to find one that suits your eyes (like the one on Arch you found).

@poluyan
Copy link
Author

poluyan commented Oct 18, 2023

@eht16 Thank you, I have checked, this is exactly the place where font starts to be blurry. I tried SciTE with scite "-font.base=font:Monospace Regular,size:12" and compared Geany, SciTE, Gedit.
geany22
Just for my eyes the I character in SciTE looks awful.
@elextr, @nyamatongwe thank you for explanations! I have to play with some fonts, maybe found good one for Geany.

Thanks for the quick replies. This issue can be closed.

@elextr
Copy link
Member

elextr commented Oct 18, 2023

@poluyan just to remind you, "Monospace" is not a font, it is an alias for one. Use fc-match monospace to find out which one so you can avoid it.

@elextr elextr closed this as completed Oct 18, 2023
@techee
Copy link
Member

techee commented Oct 19, 2023

elextr closed this as completed 9 hours ago

Is it fixed though and is this a problem of the used font? I'm not really familiar with pango and what exact implications the commit Neil mentioned had in Scintilla but it appears it triggered this problem.

@elextr
Copy link
Member

elextr commented Oct 19, 2023

it triggered this problem

IIUC it "triggered" the problem by doing it (more) correctly :-)

In reality there will always be cases where the screen resolution being used and the way the font places characters and the way floating point calculations round to integer pixels and colours can result in text appearing "fuzzy" to a viewer.

That is actually its point of course, to "simulate" fractional pixels by shading adjacent ones and hope the viewers eyes will average it. But some viewers on some screens will see it differently. As it involves individual visual response its not an exact science, so it can never be "fixed" for everyone. So the best advice is to try a different font. Its not that one or the other font is "wrong" just that they generate differing visuals, and again, thats what fonts are for, if they were identical there would be no point in having more than one.

@b4n
Copy link
Member

b4n commented Oct 19, 2023

@elextr what you're describing is hinting ;) The trade-off between faithful glyph shape rendering versus blurry render because pixels are big.

And I agree that better hinting is better, but it's tricky. I admittedly got used to bad one because some upgrade lead to poorer hinting everywhere on my system and it's not bad enough that I spend a whole lot of time on it, but still, I'd rather have it sharp and slightly off-shape than perfectly shaped and blurry.

@elextr
Copy link
Member

elextr commented Oct 19, 2023

Yeah, hinting is the info in the font file that tells how to calculate the antialiasing.

New addition to Geany license, users may only use Geany if they sit far enough from their screen that they can't see the pixels 😁

@nyamatongwe
Copy link
Contributor

If anyone is sufficiently motivated to write a sensible patch, there could be an option to choose position rounding on/off. Probably added as a bit flag to SCI_SETFONTQUALITY.

@poluyan
Copy link
Author

poluyan commented Oct 21, 2023

@nyamatongwe can you please be more specific? I've tried to modify patch you mentioned above. I commented macros lines in SetFractionalPositions but it didn't give any affect.

There is actually more. I just now noticed that at my system Scintilla do antialiasing for same characters differently (for mono fonts). That's probably why I was annoyed with the font look. Here's comparison of geany (above) with gedit (below) with DejaVu Sans Mono and JetBrains Mono Regular. For I or l in case of Scintilla there are different "types" of antialiasing with different colors. With gedit (GtkSourceView) there is only one type of antialiasing for each character with same colors.
gg3
I expect the same characters to be displayed the same way.

Now I'm using terminus bold font and quite satisfied with it. However it is a bit "lazy" solution because there is no antialiasing involved at all. 😁

@nyamatongwe
Copy link
Contributor

nyamatongwe commented Oct 21, 2023

If removing the call or replacing it with

pango_context_set_round_glyph_positions(pcontext, TRUE);

doesn't change the appearance then this is a different issue. Your system may have different defaults.

Here's an image from my system with both choices.
SetFractional

The width of 'I' in DejaVu Sans Mono,size:12 changes from 9.632812 pixels to 10.0 pixels with FALSE/TRUE values for pango_context_set_round_glyph_positions on Ubuntu 23.10.

I expect the same characters to be displayed the same way.

Drawing is performed using a floating-point coordinate space over an visual with distinct (integral) pixels. Drawing 'I' at (0,0) will colour pixels differently than drawing 'I' at (9.632812, 0).

@poluyan
Copy link
Author

poluyan commented Oct 21, 2023

Oh, it have to be set to TRUE!! I did it and the issue was solved. Now if I'm zooming in/out using scroll all the characters is perfectly sharp at any scale as it was before Scintilla update. Thank you @nyamatongwe for providing the solution, explanation and for your time! geany community is the best! 😁

For those facing a problem in the future: in file scintilla/gtk/PlatGTK.cxx SetFractionalPositions I removed macros guard and change boolean calling argument. Just run the following commands below before building geany (e.g. for geany-git in arch I did it in prepare function in PKGBUILD).

awk '/void SetFractionalPositions/,/}/ {if ($0 !~ /#/) gsub("FALSE", "TRUE"); print; next; } 1' scintilla/gtk/PlatGTK.cxx > temp_file 
mv temp_file scintilla/gtk/PlatGTK.cxx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants