Skip to content

Replace the font renderer with one without the issues of anti-aliasing/hinting/subpixel/baseline #2404

@dasifefe

Description

@dasifefe

Bevy version

Bevy 0.5.0.

What you did

Comparison between the font rendered by Bevy (ab_glyph) and Firefox (with subpixel disabled and subpixel enabled).

What you expected to happen

The font rendered with anti-aliasing in Bevy should be as rendered as close as possible as in Firefox (readable in small sizes, sharp, and correct positioning of glyphs).

What actually happened

Issue 1: aliasing

Font in Bevy is "bulkier". It is possible to notice that the anti-aliasing in Bevy generates a pixel with higher lightness than in the other implementations, that it is possible to notice single pixels without zooming-in (look at the letter e, for example).

The line on the top is Bevy, the line in the middle is Firefox with subpixel disabled, and the line bellow is Firefox with subpixel enabled:
f
f2

The values indicated are the values of LCh lightness (using the color picker from GIMP). The lightness of the anti-alias in the Bevy implementation is 3-5 times than in the other implementations.

Issue 2: vertical positioning

Another issue is the positioning of the glyphs on the baseline. In Bevy, with certain fonts at certain font sizes, the glyphs will be rendered on the incorrect vertical position:

image

It only happens with certain sizes, but not others. The examples above (showing the aliasing issues) are rendered in the correct vertical position, but not at size 15.

Possible issue 3: sizing

The size defined in TextStyle does not match the size in other implementations. On the first image (showing the aliasing issues), for example, I had to use the size 14.5 to match the font size 12 in Firefox.

Additional information

I did this experiment using the font "Fredoka One" on Google Fonts for comparison.

Proposal

Replace the Bevy implementation with one of two existing solutions: fontdue or swash. It seems that these two libraries are the best options for font rendering in pure Rust. We should evaluate which features that both have or don't have that are important for Bevy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenA-TextRendering and layout for charactersC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions