Skip to content

Use of stbtt_ScaleForPixelHeight Incorrect in typographer_context_stb.cc #146080

@johnoneil

Description

@johnoneil

Steps to reproduce

  1. Run a test case which uses the stb based glyph atlas implementation.
  2. Examine the contents of the Glyph Atlas at runtime using renderdoc or other

Expected results

The size of the glyphs in the atlas should be correct for a given typeface size in Points.

That is, for a typeface of size 12pt, the difference between the highest ascender and lowest descender should be 16 pixels (12pt == 16px @ 160 dpi).

Actual results

Currently, the resultant glyphs are (for a 12pt font) about 12px` high. This is despite correct scaling calculations.

See the screenshots below.

Code sample

Code sample
[Paste your code here]

Screenshots or Video

Screenshots / Video demonstration

Here's an analysis of the issue.

Baseline behavior for the Noto Sans typeface (normal, weight 400) can be gathered here.

This looks like:
noto-sans-regular-400-12pt-16px

Note that the vertical bar character (linux "pipe" symbol) covers the range from the highest ascender to the lowest descender. Thus it is 16px high for a 12pt font.

Looking at the current glyph atlas for an example using the same typeface at the same size (using renderdoc):

glyph-atlas-scale-for-pixel-height-1 0

The vertical bar is 12 pixels high. This is plainly incorrect.

Debugging a little, we find the scaling calculations are correct. We scale the desired 12pt to 16px at runtime.

I've debugged this further and find that the function call stbtt_ScaleForPixelHeight is returning incorrect scale values for correct inputs.

Using the function stbtt_ScaleForMappingEmToPixels with identical inputs results in correctly sized glyphs.

I'll try to present a PR to change this function call ASAP.

CC @bdero and @chinmaygarde

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 requeststeam-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