Skip to content

Remove Y-axis rounding for lines in LibTxt and floating point hack rounding in framework #31707

@GaryQian

Description

@GaryQian

Text is currently being rounded in two places:

  • LibTxt rounds as a legacy feature (from blink) to better align vertical layouts with pixel boundaries to produce sharper text on low-DPI devices. This is no longer necessary as device DPI has increased significantly in recent years, and we now prefer more accurate layout.

  • TextPainter applies a rounding we call _applyFloatingPointHack to metrics. The reasoning is probably best explained by the todo:

    // Unfortunately, using full precision floating point here causes bad layouts
    // because floating point math isn't associative. If we add and subtract
    // padding, for example, we'll get different values when we estimate sizes and
    // when we actually compute layout because the operations will end up associated
    // differently. To work around this problem for now, we round fractional pixel
    // values up to the nearest whole pixel value. The right long-term fix is to do
    // layout using fixed precision arithmetic.

We should remove such rounding sooner rather than later, as it will result in < 0.5px (logical) shifts across almost all text in Flutter. Such a change should eventually be made, and the earlier, the less disruption it can cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: qualityA truly polished experiencea: typographyText rendering, possibly libtxtc: API breakBackwards-incompatible API changesc: contributor-productivityTeam-specific productivity, code health, technical debt.engineflutter/engine related. See also e: labels.frameworkflutter/packages/flutter repository. See also f: 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