@@ -175,6 +175,37 @@ TEST_F(ParagraphTest, GetGlyphPositionAtCoordinateSegfault) {
175175 ASSERT_TRUE (Snapshot ());
176176}
177177
178+ // Check that GetGlyphPositionAtCoordinate computes correct text positions for
179+ // a paragraph containing multiple styled runs.
180+ TEST_F (ParagraphTest, GetGlyphPositionAtCoordinateMultiRun) {
181+ txt::ParagraphStyle paragraph_style;
182+ txt::ParagraphBuilderTxt builder (paragraph_style, GetTestFontCollection ());
183+
184+ txt::TextStyle text_style;
185+ text_style.font_families = std::vector<std::string>(1 , " Ahem" );
186+ text_style.color = SK_ColorBLACK;
187+ text_style.font_size = 10 ;
188+ builder.PushStyle (text_style);
189+ builder.AddText (u" A" );
190+ text_style.font_size = 20 ;
191+ builder.PushStyle (text_style);
192+ builder.AddText (u" B" );
193+ text_style.font_size = 30 ;
194+ builder.PushStyle (text_style);
195+ builder.AddText (u" C" );
196+
197+ auto paragraph = BuildParagraph (builder);
198+ paragraph->Layout (GetTestCanvasWidth ());
199+
200+ paragraph->Paint (GetCanvas (), 10.0 , 15.0 );
201+
202+ ASSERT_EQ (paragraph->GetGlyphPositionAtCoordinate (2.0 , 5.0 ).position , 0ull );
203+ ASSERT_EQ (paragraph->GetGlyphPositionAtCoordinate (12.0 , 5.0 ).position , 1ull );
204+ ASSERT_EQ (paragraph->GetGlyphPositionAtCoordinate (32.0 , 5.0 ).position , 2ull );
205+
206+ ASSERT_TRUE (Snapshot ());
207+ }
208+
178209TEST_F (ParagraphTest, LineMetricsParagraph1) {
179210 const char * text = " Hello! What is going on?\n Second line \n thirdline" ;
180211 auto icu_text = icu::UnicodeString::fromUTF8 (text);
0 commit comments