Repository navigation
Description
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
- Build and lay out a paragraph of text using
ImpellerParagraphBuilderBuildParagraphNew. - Get a character's glyph info using
ImpellerParagraphCreateGlyphInfoAtCodeUnitIndexNew. - 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 thateis to the right ofHandWis belowH. 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
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
[-][libimpeller] x and y are swapped in ImpellerGlyphInfoGetGraphemeClusterBounds[/-][+][libimpeller] x and y glyph coordinates are swapped[/+][libimpeller] Fix swapped x and y glyph coordinates (flutter#196552)