nanovg icon indicating copy to clipboard operation
nanovg copied to clipboard

turning off text pixel-snapping

Open wtholliday opened this issue 8 years ago • 3 comments

As I understand it, nanovg's font rendering snaps in order to improve anti-aliasing.

In my app, the user can zoom in and out, so the text jumps around as it snaps. So I get fairly frequent feedback from users, who think this is a bug.

Since retina screens have such good resolution, I'd rather just turn off the snapping, but there doesn't seem to be API to do so.

Where in nanovg (or fontstash) does the pixel snapping occur and how can I disable it?

thanks!

wtholliday avatar Feb 08 '16 17:02 wtholliday

This would be a useful feature, I use the app mentioned above and the text snapping is very notable and causes all sorts of little artifacts, even sometimes causing the lines to wrap at a different word at odd/even intervals so you wind up with the text jiggling all over the place when you do otherwise very smooth two finger pinch zooms

MacroMachines avatar Feb 08 '16 17:02 MacroMachines

Yes, this would be a good feature to have. I don't currently have time to implement it, but I can walk you help you out to make a PR for it.

The first thing to to would be to just remove the rounding. It is done here: https://github.com/memononen/nanovg/blob/master/src/fontstash.h#L1134 https://github.com/memononen/nanovg/blob/master/src/fontstash.h#L1147

It could be controlled by something like this:

void fonsSetPixelSnap(FONScontext* s, int state);

And in nanovg:

void nvgTextPixelSnap(NVGcontext* ctx, int state);

This will lead to blurry text most of the time. In oder to solve that we could improve the font stash to include 2x2 oversampling as per: https://github.com/nothings/stb/tree/master/tests/oversample I think that would be a better default too than pixel snapping.

memononen avatar Feb 08 '16 20:02 memononen

It as been a few years since the bug is open and I am also interested in disabling the snapping. It the suggestion from @memononen still the correct way to go about it?

guillaumechereau avatar Jan 14 '19 14:01 guillaumechereau