daa84 / neovim-gtk

gtk ui for neovim
GNU General Public License v3.0
716 stars 57 forks source link

Subpixel Font Rendering #169

Closed landersson closed 5 years ago

landersson commented 5 years ago

Hi,

I seem to have a minor issue with LCD subpixel rendering in nvim-gtk. Compared to the font rendering in gvim, using the same font, the quality is slightly better in gvim. It looks like LCD subpixel font rendering is not configured properly in nvim-gtk.

gvim:

gvim

nvim-gtk: nvim-gtk

It looks like there is some minor LCD subpixel rendering happening even when using nvim-gtk, but much less than when using gvim, and the rgb order also seem to be reversed.

Any idea how to fix this? Would it be possible to use cairo::FontOptions to enforce specific font rendering options to see it that helps?

gtk-rs.org/docs/cairo/struct.FontOptions.html

landersson commented 5 years ago

I think the issue could somehow be related to the text renderer not being aware of the current background colour. Subpixel rendering works fine with a dark background.

Could this be related to the transparency support?

daa84 commented 5 years ago

Yes it can be, rendering works with layers that combines together. So maybe white background combined with transparency rendered pixel gives this strange result.

landersson commented 5 years ago

I haven't enabled background transparency though, unless it's somehow enabled by default.

Is there an easy way to definitively disable transparency?

daa84 commented 5 years ago

This is not transparency background problem, but problem of compositing, background color composed with text with CAIRO_OPERATOR_OVER: so resulting color in case it transparent changed as (xaA + xaB·(1−aA))/aR.

daa84 commented 5 years ago

Correction: CAIRO_OPERATOR_DEST used, but that for some unknown (for me) reason do color modification of dest. Think i can try to use surface instead of group, maybe this helps

landersson commented 5 years ago

To me, it definitively looks related to subpixel antialiasing though. It's only the pixels where the text renderer attempts to do subpixel correction that look wrong.

mcepl commented 5 years ago

Just to note, it looks like a duplicate of #88. Still reproducible with build from 7cda84c. nvim-gtk-anti-aliasing

landersson commented 5 years ago

@mcepl, I don't think these are identical issues. Looking closer at your images, your font rendering doesn't seem to use LCD subpixel antialiasing at all (i.e, you don't have the blue/red fringe pixels around letters as seen in my example images). My main issue is that the subpixel correction seem to assume a dark background.

daa84 commented 5 years ago

@landersson can you check branch subpixel_render_fix? Does it fix your issue? Maybe it introduce some new :smile:

landersson commented 5 years ago

Yep, this seem to fix the issue... fonts now look as good as in gvim, and nvim-gtk is quite a bit snappier. Thanks!

nvim-fixed

I haven't looked carefully, but I haven't noticed anything else breaking.