@@ -983,13 +983,13 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeParagraph)) {
983983 // are adjusted.
984984 paint.setColor (SK_ColorRED);
985985 std::vector<txt::Paragraph::TextBox> boxes =
986- paragraph->GetRectsForRange (0 , 0 );
986+ paragraph->GetRectsForRange (0 , 0 , Paragraph::RectStyle:: kNone );
987987 for (size_t i = 0 ; i < boxes.size (); ++i) {
988988 GetCanvas ()->drawRect (boxes[i].rect , paint);
989989 }
990990 EXPECT_EQ (boxes.size (), 0ull );
991991
992- boxes = paragraph->GetRectsForRange (0 , 1 );
992+ boxes = paragraph->GetRectsForRange (0 , 1 , Paragraph::RectStyle:: kNone );
993993 for (size_t i = 0 ; i < boxes.size (); ++i) {
994994 GetCanvas ()->drawRect (boxes[i].rect , paint);
995995 }
@@ -1000,7 +1000,7 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeParagraph)) {
10001000 EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom (), 59 );
10011001
10021002 paint.setColor (SK_ColorBLUE);
1003- boxes = paragraph->GetRectsForRange (2 , 8 );
1003+ boxes = paragraph->GetRectsForRange (2 , 8 , Paragraph::RectStyle:: kNone );
10041004 for (size_t i = 0 ; i < boxes.size (); ++i) {
10051005 GetCanvas ()->drawRect (boxes[i].rect , paint);
10061006 }
@@ -1011,7 +1011,7 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeParagraph)) {
10111011 EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom (), 59 );
10121012
10131013 paint.setColor (SK_ColorGREEN);
1014- boxes = paragraph->GetRectsForRange (8 , 21 );
1014+ boxes = paragraph->GetRectsForRange (8 , 21 , Paragraph::RectStyle:: kNone );
10151015 for (size_t i = 0 ; i < boxes.size (); ++i) {
10161016 GetCanvas ()->drawRect (boxes[i].rect , paint);
10171017 }
@@ -1022,7 +1022,7 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeParagraph)) {
10221022 EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom (), 59 );
10231023
10241024 paint.setColor (SK_ColorRED);
1025- boxes = paragraph->GetRectsForRange (30 , 100 );
1025+ boxes = paragraph->GetRectsForRange (30 , 100 , Paragraph::RectStyle:: kNone );
10261026 for (size_t i = 0 ; i < boxes.size (); ++i) {
10271027 GetCanvas ()->drawRect (boxes[i].rect , paint);
10281028 }
@@ -1040,7 +1040,7 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeParagraph)) {
10401040 EXPECT_FLOAT_EQ (boxes[3 ].rect .bottom (), 295 );
10411041
10421042 paint.setColor (SK_ColorBLUE);
1043- boxes = paragraph->GetRectsForRange (19 , 22 );
1043+ boxes = paragraph->GetRectsForRange (19 , 22 , Paragraph::RectStyle:: kNone );
10441044 for (size_t i = 0 ; i < boxes.size (); ++i) {
10451045 GetCanvas ()->drawRect (boxes[i].rect , paint);
10461046 }
@@ -1051,7 +1051,7 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeParagraph)) {
10511051 EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom (), 59 );
10521052
10531053 paint.setColor (SK_ColorRED);
1054- boxes = paragraph->GetRectsForRange (21 , 21 );
1054+ boxes = paragraph->GetRectsForRange (21 , 21 , Paragraph::RectStyle:: kNone );
10551055 for (size_t i = 0 ; i < boxes.size (); ++i) {
10561056 GetCanvas ()->drawRect (boxes[i].rect , paint);
10571057 }
@@ -1060,10 +1060,93 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeParagraph)) {
10601060 ASSERT_TRUE (Snapshot ());
10611061}
10621062
1063+ TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeTight)) {
1064+ const char * text =
1065+ " ( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)("
1066+ " ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)("
1067+ " ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)" ;
1068+ auto icu_text = icu::UnicodeString::fromUTF8 (text);
1069+ std::u16string u16_text (icu_text.getBuffer (),
1070+ icu_text.getBuffer () + icu_text.length ());
1071+
1072+ txt::ParagraphStyle paragraph_style;
1073+ paragraph_style.max_lines = 10 ;
1074+ paragraph_style.text_align = TextAlign::left;
1075+ txt::ParagraphBuilder builder (paragraph_style, GetTestFontCollection ());
1076+
1077+ txt::TextStyle text_style;
1078+ text_style.font_family = " Noto Sans CJK JP" ;
1079+ text_style.font_size = 50 ;
1080+ text_style.letter_spacing = 0 ;
1081+ text_style.font_weight = FontWeight::w500;
1082+ text_style.word_spacing = 0 ;
1083+ text_style.color = SK_ColorBLACK;
1084+ text_style.height = 1 ;
1085+ builder.PushStyle (text_style);
1086+
1087+ builder.AddText (u16_text);
1088+
1089+ builder.Pop ();
1090+
1091+ auto paragraph = builder.Build ();
1092+ paragraph->Layout (550 );
1093+
1094+ paragraph->Paint (GetCanvas (), 0 , 0 );
1095+
1096+ SkPaint paint;
1097+ paint.setStyle (SkPaint::kStroke_Style );
1098+ paint.setAntiAlias (true );
1099+ paint.setStrokeWidth (1 );
1100+
1101+ // Tests for GetRectsForRange()
1102+ // NOTE: The base truth values may still need adjustment as the specifics
1103+ // are adjusted.
1104+ paint.setColor (SK_ColorRED);
1105+ std::vector<txt::Paragraph::TextBox> boxes =
1106+ paragraph->GetRectsForRange (0 , 0 , Paragraph::RectStyle::kTight );
1107+ for (size_t i = 0 ; i < boxes.size (); ++i) {
1108+ GetCanvas ()->drawRect (boxes[i].rect , paint);
1109+ }
1110+ EXPECT_EQ (boxes.size (), 0ull );
1111+
1112+ boxes = paragraph->GetRectsForRange (0 , 1 , Paragraph::RectStyle::kTight );
1113+ for (size_t i = 0 ; i < boxes.size (); ++i) {
1114+ GetCanvas ()->drawRect (boxes[i].rect , paint);
1115+ }
1116+ EXPECT_EQ (boxes.size (), 1ull );
1117+ EXPECT_FLOAT_EQ (boxes[0 ].rect .left (), 0 );
1118+ EXPECT_FLOAT_EQ (boxes[0 ].rect .top (), 0 );
1119+ EXPECT_FLOAT_EQ (boxes[0 ].rect .right (), 16.898438 );
1120+ EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom (), 74 );
1121+
1122+ paint.setColor (SK_ColorBLUE);
1123+ boxes = paragraph->GetRectsForRange (2 , 8 , Paragraph::RectStyle::kTight );
1124+ for (size_t i = 0 ; i < boxes.size (); ++i) {
1125+ GetCanvas ()->drawRect (boxes[i].rect , paint);
1126+ }
1127+ EXPECT_EQ (boxes.size (), 1ull );
1128+ EXPECT_FLOAT_EQ (boxes[0 ].rect .top (), 0 );
1129+ EXPECT_FLOAT_EQ (boxes[0 ].rect .right (), 264.09375 );
1130+ EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom (), 74 );
1131+
1132+ paint.setColor (SK_ColorGREEN);
1133+ boxes = paragraph->GetRectsForRange (8 , 21 , Paragraph::RectStyle::kTight );
1134+ for (size_t i = 0 ; i < boxes.size (); ++i) {
1135+ GetCanvas ()->drawRect (boxes[i].rect , paint);
1136+ }
1137+ EXPECT_EQ (boxes.size (), 2ull );
1138+ EXPECT_FLOAT_EQ (boxes[0 ].rect .left (), 264.09375 );
1139+ EXPECT_FLOAT_EQ (boxes[0 ].rect .top (), 0 );
1140+ EXPECT_FLOAT_EQ (boxes[0 ].rect .right (), 595.08594 );
1141+ EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom (), 74 );
1142+
1143+ ASSERT_TRUE (Snapshot ());
1144+ }
1145+
10631146SkRect GetCoordinatesForGlyphPosition (const txt::Paragraph& paragraph,
10641147 size_t pos) {
10651148 std::vector<txt::Paragraph::TextBox> boxes =
1066- paragraph.GetRectsForRange (pos, pos + 1 );
1149+ paragraph.GetRectsForRange (pos, pos + 1 , Paragraph::RectStyle:: kNone );
10671150 return !boxes.empty () ? boxes.front ().rect : SkRect::MakeEmpty ();
10681151}
10691152
@@ -1635,8 +1718,9 @@ TEST_F(ParagraphTest, UnderlineShiftParagraph) {
16351718 paragraph->records_ [1 ].GetRunWidth (),
16361719 paragraph2->records_ [0 ].GetRunWidth ());
16371720
1638- auto rects1 = paragraph->GetRectsForRange (0 , 12 );
1639- auto rects2 = paragraph2->GetRectsForRange (0 , 12 );
1721+ auto rects1 = paragraph->GetRectsForRange (0 , 12 , Paragraph::RectStyle::kNone );
1722+ auto rects2 =
1723+ paragraph2->GetRectsForRange (0 , 12 , Paragraph::RectStyle::kNone );
16401724
16411725 for (size_t i = 0 ; i < 12 ; ++i) {
16421726 auto r1 = GetCoordinatesForGlyphPosition (*paragraph, i);
0 commit comments