Skip to content

[libimpeller] x and y glyph coordinates are swapped #196827

Closed

Description

@loic-sharma

Background

The standalone Impeller SDK (aka libimpeller) lets you use Impeller outside of Flutter. It has a public ImpellerGlyphInfoGetGraphemeClusterBounds C API that lets you look up the position of a character in text. Currently, the returned x and y coordinates are incorrectly swapped.

Steps to reproduce

  1. Build and lay out a paragraph of text using ImpellerParagraphBuilderBuildParagraphNew.
  2. Get a character's glyph info using ImpellerParagraphCreateGlyphInfoAtCodeUnitIndexNew.
  3. Get glyph's bounds using ImpellerGlyphInfoGetGraphemeClusterBounds.

Expected results

The returned ImpellerRect.x contains the x coordinate, and ImpellerRect.y contains the y coordinate.

Actual results

The returned ImpellerRect.x contains the y coordinate, the ImpellerRect.y contains the x coordinate.

Code sample

  • Option 1: This project contains a self-contained minimal repro: https://github.com/loic-sharma/impeller_cmake_demo/tree/glyph_bounds_bug

    It lays out the paragraph "Hello\nWorld" and checks that e is to the right of H and W is below H. This fails on master today.

  • Option 2: Apply this patch to the Flutter engine. It updates Impeller's unit tests to check that the x coordinate increases for characters on the same line, and that the y coordinate increases for characters on the next line. This test fails on master today.

    Code sample
    diff --git a/engine/src/flutter/impeller/toolkit/interop/impeller_unittests.cc b/engine/src/flutter/impeller/toolkit/interop/impeller_unittests.cc
    index 2c16960f13a50..ee419a7cb2c5e 100644
    --- a/engine/src/flutter/impeller/toolkit/interop/impeller_unittests.cc
    +++ b/engine/src/flutter/impeller/toolkit/interop/impeller_unittests.cc
    @@ -587,8 +587,24 @@ TEST_P(InteropPlaygroundTest, CanMeasureText) {
     
         ImpellerRect bounds2 = {};
         ImpellerGlyphInfoGetGraphemeClusterBounds(glyph.Get(), &bounds2);
    +    ASSERT_EQ(bounds.x, bounds2.x);
    +    ASSERT_EQ(bounds.y, bounds2.y);
         ASSERT_EQ(bounds.width, bounds2.width);
         ASSERT_EQ(bounds.height, bounds2.height);
    +
    +    // The next glyph on the same line is to the right.
    +    auto next_glyph = paragraph.GlyphInfoAtCodeUnitIndex(
    +        glyph.GetGraphemeClusterCodeUnitRangeEnd());
    +    ASSERT_TRUE(next_glyph);
    +    ASSERT_GE(next_glyph.GetGraphemeClusterBounds().x, bounds.x + bounds.width);
    +
    +    // The first glyph on the next line is below the first line's baseline.
    +    auto line_metrics = paragraph.GetLineMetrics();
    +    auto next_line_glyph = paragraph.GlyphInfoAtCodeUnitIndex(
    +        line_metrics.GetCodeUnitStartIndex(1));
    +    ASSERT_TRUE(next_line_glyph);
    +    ASSERT_GT(next_line_glyph.GetGraphemeClusterBounds().y,
    +              line_metrics.GetBaseline(0));
       }
     
       // Glyph info by coordinates.

Screenshots or Video

N/A

Logs

N/A

Flutter Doctor output

N/A

Activity

  1. added
    team-engine
    e: libimpeller
    on Nov 17, 2026
  2. changed the title [-][libimpeller] x and y are swapped in ImpellerGlyphInfoGetGraphemeClusterBounds[/-] [+][libimpeller] x and y glyph coordinates are swapped[/+] on Nov 17, 2026
  3. moved this from In Triage to Done in libImpelleron Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    e: libimpellerteam-enginewaiting for PR to land (fixed)

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions