Skip to content

Glyph Atlas Padding Not Correctly Handled in typographer_context_stb.cc. #145421

@johnoneil

Description

@johnoneil

Steps to reproduce

This is more of an analytical code issue, but the issue is visible in generated glyph atlases using the stb implementation.

To reproduce:

  1. Use the stb text atlas implementation.
  2. In come situations characters will appear like they have their bottoms cut off.

Using renderdoc on the subsequent binary, one can see the Glyphs in the atlas are not laid out correctly in relation to the padding between glyphs.

Expected results

Glyphs shouldn't be cut off along the bottom.

Actual results

Glyphs sometimes cut off along their bottom.

Code sample

I believe the issue is in the following section of code:

Code sample
   if (!has_color || DISABLE_COLOR_FONT_SUPPORT) {
     stbtt_MakeGlyphBitmap(typeface_stb->GetFontInfo(), output,
                          location.size.width - kPadding,
                          location.size.height - kPadding,
                           bitmap->GetRowBytes(), scale_x, scale_y, glyph.index);

Note the - kPadding.

At this point, the location used is the entry describing the glyph in the atlas, but it does not include padding, so the subtraction of kPadding is not necessary.

Screenshots or Video

Screenshots / Video demonstration

Here's a screenshot of some text rendered with the incorrect code:
Screenshot from 2024-03-19 11-16-01

And a screenshot of some glyphs in the atlas via renderdoc. Note there is double the paddng between characters and some characters (like the "i") are clipped along one side.

Screenshot from 2024-03-19 11-17-09

Correcting the code the text is improved (though in our case still not strictly correct)

Screenshot from 2024-03-19 11-19-44

And lastly, examining the glyph atlas using renderdoc with a fix in place, the layout of glyphs is improved:

Screenshot from 2024-03-19 11-10-54

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[Paste your output here]

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work liste: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.r: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions