Page MenuHome

BLF: sub-pixel positioning support
AbandonedPublic

Authored by Campbell Barton (campbellbarton) on Apr 7 2022, 4:08 AM.

Details

Summary

Support sub-pixel kerning and hinting for future support for improved character placement.
No user visible changes have been made.

  • Calculate sub-pixel offsets, using integer maths.
  • Use convenience functions to perform the conversions and hide the underlying values.
  • Use ft_pix type to distinguish values that use sub-pixel integer values from freetype and values rounded to pixels.

This was originally based on D12999 by @Harley Acheson (harley) with the user visible changes removed so they can be applied separately.


Even though it requires cumbersome conversion I think it's more reliable not to introduce floating point values for positioning text as it means positioning text may be less predictable, potentially run into float precision issues (this patch already has an assertion drawing widgets at certain zoom-levels because of a font-width calculation discrepancy).

Diff Detail

Repository
rB Blender
Branch
TEMP-BLF-64x-OFS (branched from master)
Build Status
Buildable 21502
Build 21502: arc lint + arc unit

Event Timeline

Campbell Barton (campbellbarton) requested review of this revision.Apr 7 2022, 4:08 AM
Campbell Barton (campbellbarton) created this revision.
  • Don't ft_pix_to_int in the loop the assigns pixels

Cleanup inline utilities, cast before bit-shifting

Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)

Remove _i suffix from advanced as it's no longer meaningful.

  • Remove duplicate define

Nice! This is definitely more understandable than any of my attempts at directly using FreeType integer types like FT_F26Dot6 or FT_Pos.

Slight hinting is working correctly here. The best way to see that it is working right is to crank up Resolution Scale to 2, then when you change between None and Slight hinting you will see no horizontal change at all. This is correct in that Slight only aligns to the pixel grid vertically. Doing that with master you see lots of horizontal change. There is some movement at lower scales though that might be odd, but I'll look into that tomorrow.

  • Add comment describing the purpose of ft_pix
  • Use int32_t instead of int64_t - for our purpose int32_t is easily big enough.
  • Use a doxygen section for the ft_pix API
  • Reference the file the macros originate.
  • Use rounding that matches 3.1 behavior (functional changes can be applied separately).
  • Improve commens, rename advance to advance_x
Campbell Barton (campbellbarton) retitled this revision from BLF: Sub-pixel positioning & fix hinting to BLF: sub-pixel positioning support.Apr 13 2022, 3:46 AM
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)

Minor cleanup to comments & calculaiton for advance in blf_font_boundbox_foreach_glyph_ex.

From discussing this with @Harley Acheson (harley), he's fine to apply this patch and make further hinting changes ontop of it.