blend2d icon indicating copy to clipboard operation
blend2d copied to clipboard

Font hinting & font dev in general

Open ghost opened this issue 4 years ago • 5 comments

I'm thinking about implementing font hinting in blend2d. This involves a lot of work and wanted to check first what your thoughts are and/or if you already started to work on it.

I've been reading the opentype spec and looking at freetype for a reference implementation. It appears to involve writing a bytecode interpreter for opentype instructions. It's a lot of work but at first sight it looks doable.

ghost avatar Mar 19 '21 14:03 ghost

I don't know whether font hinting is something that is worth spending time on to be honest, at least at the moment.

It seems to me that the world is moving forward and font hinting is disappearing from libraries like Pango, and thus from Linux desktop, for example.

Not saying not to do that, but I'm not sure I would be able to help with the design. The whole architecture that works with text would have to account for the pixel font size - not sure what exactly would have to be changed to make it working. Imagine for example that you scale your rendering context and then want to render hinted text at size 14px, but the rendering context was transformed and rotated - I'm not sure what should be rendered in that case to be honest.

Additionally, I think interpreting the hinting bytecode is not the best idea. There is something like autohinter in FreeType and it works reasonably across all fonts, which is much better than interpreting proprietary bytecode not designed for analytic rasterizers - you would have to try whether the rasterizer is able to render hinted paths correctly.

I think, that if you have time and want to improve text support in Blend2D then finishing OpenType features like GPOS/GSUB would be much more interesting. What do you think?

kobalicek avatar Mar 20 '21 23:03 kobalicek

I'm open to improving GPOS/GSUB support.

Instead of having a theoretical discussion about hinting, maybe it's useful I made a test program which gets the outlines from freetype (with hinting) and renders it with blend2d. Then on a line below I can display the same string rendered with the native blend2d implementation.

I know I'm being nitpicky about this. I've upgraded my program from agg+freetype to blend2d. The first thing I noticed was the incredible increase in speed :). The second was that some letters were displayed fuzzy. When I went back to the agg implementation and I turned off hinting, I saw the same fuzzyness with the exact same letters.

Anyways, to return to improving GPOS/GSUB. I think if I already have this test program, I can add harfbuzz so I can test the implementation of blend2d of GPOS/GSUB. It would be easily noticable what we're missing or doing wrong.

I took a quick glance at the code and saw you already did some work on this. What parts are you missing and want to be done?

ghost avatar Mar 21 '21 04:03 ghost

(Before you read this: I agree with you that implementing GSUB/GPOS is probably more beneficial)

hinting:

I've made a simple test program: https://github.com/justnope/blend2dfont

Everything is rendered using blend2d BLPaths.

The first line I got the outline from freetype with hinting enabled. The second one also from freetype with hinting disabled. The third one is rendered using exclusively blend2d.

I think the result might be monitor dependent because when I see the result on one of my low contrast cheap monitors, I can barely tell the difference between hinting on or off. Other displays I used showed the fonts a bit blurrier. Not all glyphs were rendered blurry, but some of them were.

bl-getting-started-1

ghost avatar Mar 22 '21 04:03 ghost

I like the hinted text actually - it looks much nicer on my screen than unhinted. Maybe it's worth thinking about it.

kobalicek avatar Mar 23 '21 00:03 kobalicek

Regarding GPOS/GSUB - I have already done something, but it's far from complete. Let me check my branch where I experimented with more font features first, I don't know the exact state.

kobalicek avatar Mar 23 '21 00:03 kobalicek

I'm closing as this issue is here for a long time, but without any activity.

kobalicek avatar Feb 15 '24 23:02 kobalicek