@@ -4042,6 +4042,123 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(EmojiParagraph)) {
40424042 EXPECT_EQ (paragraph->records_ [7 ].line (), 7ull );
40434043}
40444044
4045+ TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(EmojiMultiLineRectsParagraph)) {
4046+ // clang-format off
4047+ const char * text =
4048+ " 👩👩👦👩👩👧👧🇺🇸👩👩👦👩👩👧👧i🇺🇸👩👩👦👩👩👧👧🇺🇸👩👩👦👩👩👧👧🇺🇸"
4049+ " 👩👩👦👩👩👧👧🇺🇸👩👩👦👩👩👧👧🇺🇸👩👩👦👩👩👧👧🇺🇸👩👩👦👩👩👧👧🇺🇸"
4050+ " 👩👩👦👩👩👧👧🇺🇸👩👩👦👩👩👧👧🇺🇸👩👩👦👩👩👧👧🇺🇸👩👩👦👩👩👧👧🇺🇸"
4051+ " 👩👩👦👩👩👧👧🇺🇸👩👩👦👩👩👧👧🇺🇸👩👩👦👩👩👧👧🇺🇸👩👩👦👩👩👧👧🇺🇸"
4052+ " ❄🍕🍔🍟🥝🍱🕶🎩🏈⚽🚴♀️🎻🎼🎹🚨🚎🚐⚓🛳🚀🚁🏪🏢🖱⏰📱💾💉📉🛏🔑🔓"
4053+ " 📁🗓📊❤💯🚫🔻♠♣🕓❗🏳🏁🏳️🌈🇮🇹🇱🇷🇺🇸🇬🇧🇨🇳🇧🇴" ;
4054+ // clang-format on
4055+ auto icu_text = icu::UnicodeString::fromUTF8 (text);
4056+ std::u16string u16_text (icu_text.getBuffer (),
4057+ icu_text.getBuffer () + icu_text.length ());
4058+
4059+ txt::ParagraphStyle paragraph_style;
4060+
4061+ txt::ParagraphBuilderTxt builder (paragraph_style, GetTestFontCollection ());
4062+
4063+ txt::TextStyle text_style;
4064+ text_style.color = SK_ColorBLACK;
4065+ text_style.font_families = std::vector<std::string>(1 , " Noto Color Emoji" );
4066+ text_style.font_size = 50 ;
4067+ builder.PushStyle (text_style);
4068+ builder.AddText (u16_text);
4069+
4070+ builder.Pop ();
4071+
4072+ auto paragraph = BuildParagraph (builder);
4073+ paragraph->Layout (GetTestCanvasWidth () - 300 );
4074+
4075+ paragraph->Paint (GetCanvas (), 0 , 0 );
4076+
4077+ for (size_t i = 0 ; i < u16_text.length (); i++) {
4078+ ASSERT_EQ (paragraph->text_ [i], u16_text[i]);
4079+ }
4080+
4081+ ASSERT_EQ (paragraph->records_ .size (), 10ull );
4082+
4083+ SkPaint paint;
4084+ paint.setStyle (SkPaint::kStroke_Style );
4085+ paint.setAntiAlias (true );
4086+ paint.setStrokeWidth (1 );
4087+
4088+ // Tests for GetRectsForRange()
4089+ Paragraph::RectHeightStyle rect_height_style =
4090+ Paragraph::RectHeightStyle::kTight ;
4091+ Paragraph::RectWidthStyle rect_width_style =
4092+ Paragraph::RectWidthStyle::kTight ;
4093+ paint.setColor (SK_ColorRED);
4094+ std::vector<txt::Paragraph::TextBox> boxes =
4095+ paragraph->GetRectsForRange (0 , 0 , rect_height_style, rect_width_style);
4096+ for (size_t i = 0 ; i < boxes.size (); ++i) {
4097+ GetCanvas ()->drawRect (boxes[i].rect , paint);
4098+ }
4099+ EXPECT_EQ (boxes.size (), 0ull );
4100+
4101+ // Ligature style indexing.
4102+ boxes =
4103+ paragraph->GetRectsForRange (0 , 119 , rect_height_style, rect_width_style);
4104+ for (size_t i = 0 ; i < boxes.size (); ++i) {
4105+ GetCanvas ()->drawRect (boxes[i].rect , paint);
4106+ }
4107+ EXPECT_EQ (boxes.size (), 2ull );
4108+ EXPECT_FLOAT_EQ (boxes[1 ].rect .left (), 0 );
4109+ EXPECT_FLOAT_EQ (boxes[1 ].rect .right (), 334.61475 );
4110+
4111+ boxes = paragraph->GetRectsForRange (122 , 132 , rect_height_style,
4112+ rect_width_style);
4113+ paint.setColor (SK_ColorBLUE);
4114+ for (size_t i = 0 ; i < boxes.size (); ++i) {
4115+ GetCanvas ()->drawRect (boxes[i].rect , paint);
4116+ }
4117+ EXPECT_EQ (boxes.size (), 1ull );
4118+ EXPECT_FLOAT_EQ (boxes[0 ].rect .left (), 357.95996 );
4119+ EXPECT_FLOAT_EQ (boxes[0 ].rect .right (), 418.79901 );
4120+
4121+ // GetPositionForCoordinates should not return inter-emoji positions.
4122+ boxes = paragraph->GetRectsForRange (
4123+ 0 , paragraph->GetGlyphPositionAtCoordinate (610 , 100 ).position ,
4124+ rect_height_style, rect_width_style);
4125+ paint.setColor (SK_ColorGREEN);
4126+ for (size_t i = 0 ; i < boxes.size (); ++i) {
4127+ GetCanvas ()->drawRect (boxes[i].rect , paint);
4128+ }
4129+ EXPECT_EQ (boxes.size (), 2ull );
4130+ EXPECT_FLOAT_EQ (boxes[1 ].rect .left (), 0 );
4131+ // The following is expected to change to a higher value when
4132+ // rounding up is added to getGlyphPositionForCoordinate.
4133+ EXPECT_FLOAT_EQ (boxes[1 ].rect .right (), 560.28516 );
4134+
4135+ boxes = paragraph->GetRectsForRange (
4136+ 0 , paragraph->GetGlyphPositionAtCoordinate (580 , 100 ).position ,
4137+ rect_height_style, rect_width_style);
4138+ paint.setColor (SK_ColorGREEN);
4139+ for (size_t i = 0 ; i < boxes.size (); ++i) {
4140+ GetCanvas ()->drawRect (boxes[i].rect , paint);
4141+ }
4142+ EXPECT_EQ (boxes.size (), 2ull );
4143+ EXPECT_FLOAT_EQ (boxes[1 ].rect .left (), 0 );
4144+ EXPECT_FLOAT_EQ (boxes[1 ].rect .right (), 560.28516 );
4145+
4146+ boxes = paragraph->GetRectsForRange (
4147+ 0 , paragraph->GetGlyphPositionAtCoordinate (560 , 100 ).position ,
4148+ rect_height_style, rect_width_style);
4149+ paint.setColor (SK_ColorGREEN);
4150+ for (size_t i = 0 ; i < boxes.size (); ++i) {
4151+ GetCanvas ()->drawRect (boxes[i].rect , paint);
4152+ }
4153+ EXPECT_EQ (boxes.size (), 2ull );
4154+ EXPECT_FLOAT_EQ (boxes[1 ].rect .left (), 0 );
4155+ // The following is expected to change to the 560.28516 value when
4156+ // rounding up is added to getGlyphPositionForCoordinate.
4157+ EXPECT_FLOAT_EQ (boxes[1 ].rect .right (), 498.03125 );
4158+
4159+ ASSERT_TRUE (Snapshot ());
4160+ }
4161+
40454162TEST_F (ParagraphTest, HyphenBreakParagraph) {
40464163 const char * text =
40474164 " A "
0 commit comments