Now Reading
On fractional scales, fonts and hinting – GTK Growth Weblog

On fractional scales, fonts and hinting – GTK Growth Weblog

2024-03-07 01:01:37

GTK 4.14 will probably be launched very quickly, with new renderers that had been introduced earlier this yr.

The brand new renderers have a lot improved help for fractional scaling—on my system, I now use 125% scaling as a substitute of the ‘Massive Textual content’ setting, and I discover that works fantastic for my wants.

Magical numbers

Ever since 4.0, GTK has been advocating for linear structure.

The thought is that we simply place glyphs the place the coordinates inform us, and if that may be a fractional place someplace between pixels, so be it, we will render the define at that offset simply fantastic. This strategy works—in case your output machine has a high-enough decision (something above 240 dpi ought to be okay). Sadly, we don’t stay in a world the place most laptop computer screens have that sort of decision, so we will’t simply ignore pixels.

Consequently, we added the gtk-hint-font-metrics setting that forces textual content structure to spherical issues to integer positions. This isn’t an incredible match for fractional scaling, for the reason that rounding occurs in software pixels, and we actually want integral machine pixel positions to provide crisp outcomes.

Software vs. machine pixels

The frequent fractional scales are 125%, 150%, 175%, 200% and 225%. At these scales (apart from 200%), most software pixel boundaries don’t align with machine pixel boundaries.

What now?

The brand new renderers gave us a possibility to revisit the subject of font rendering and do some research on the mechanics of hinting choices, and the way they get handed down the stack from GTK by Pango and cairo, after which find yourself in freetype as a mixture of render goal + load flags.

Trace type and antialiasing choices translate to render mode and cargo flags

The brand new renders acknowledge that there’s two primary modes of operation relating to glyphs:

  • optimize for uniform spacing
  • optimize for crisp rendering

The previous results in subpixel positioning and unhinted rendering, the latter to hinted rendering and glyphs which can be positioned at integral pixel positions (since that’s what the autohinter expects).

We decide which case we’re in by trying on the font options. In the event that they inform us to do hinting, we around the glyph place to an integral machine pixel within the y route. Why solely y? The autohinter solely applies hinting within the vertical route and the horizontal route is the place the elevated decision of subpixel positions helps most. If we’re not hinting, then we use subpixel positions for each x and y, identical to the outdated renderer.

A comparability

Textual content rendering variations are all the time delicate and, to some extent, a matter a style and desire. So these screenshots ought to be taken with a grain of salt—it’s significantly better to attempt the brand new renderers for your self.

See Also

Textual content rendered at 125%, outdated renderer
Textual content rendered at 125%, new renderer

Each of those renderings had been executed at a scale of 125%, with hinting enabled.

Here’s a have a look at some particulars: the horizontal bars of T and e are constant throughout strains, though we nonetheless enable the glyphs to shift by subpixel positions horizontally.

Constant vertical placement
Cases of T and e, outdated renderer
Cases of T and e, new renderer

Abstract

The brand new renderers in GTK 4.14 ought to produce extra crisp font rendering, specifically with fractional scaling.

Please attempt it out and inform us what you suppose.

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top