Skip to content

Fractional kerning and advance #108

@stg

Description

@stg

For systems that render bitmap text with subpixel accuracy, it would be very useful to have kerning and advance values with subpixel accuracy.

I would like to be able to export files with a configurable number of fractional bits for these values (typically called Qn fixed-point format, where n is the number of fractional bits).

This essentially means that all stored values have a factor of 2**n.

For example:
Q0 - exactly as it is today: 1 equals 1 pixel
Q1 - 1 fractional bit: 1 equals 1/2 pixel, 2 equals 1 pixel
Q4 - 4 fractional bits: 1 means 1/16 pixel, 16 means 1 pixel
etcetera.

Typically, for subpixel accuracy, no more than 8 bits are ever wanted, so Q0 to Q8 would be a suitable range.

Reserved bits in Block 2, bitField (where bit 7 is "packed") can be used to indicate the number of fractional bits, which would not break compatibility unless the feature is used. And if it is used, and a parser is unaware, it would lead only to instantly obvious character distance errors.

This would also yield more kerning pairs, as pairs that previously rounded to 0 are now included.

Today, the only way to get this information is to use the following painful process:

  • Export 4x (for example) required font size
  • Extract kerning and advance information
  • Export required final font size
  • Inject kerning and advance information back, now with 1/4 subpixel accuracy

I am currently using Q2 (1/4 subpixel accuracy) with very good results, and even though my internal advance and kerning fields are only 8 bits wide, they never overflow with any tested 32px font. These fields are 16 bits in the BMF binary format, so there is plenty of headroom, given that subpixel accuracy is mostly useful with small font sizes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions