@@ -5846,4 +5846,101 @@ TEST_F(ParagraphTest, KhmerLineBreaker) {
58465846 ASSERT_TRUE (Snapshot ());
58475847}
58485848
5849+ TEST_F (ParagraphTest, BoundingLineHeightBehaviorRectsParagraph) {
5850+ // clang-format off
5851+ const char * text =
5852+ " line1\n line2\n line3" ;
5853+ // clang-format on
5854+ auto icu_text = icu::UnicodeString::fromUTF8 (text);
5855+ std::u16string u16_text (icu_text.getBuffer (),
5856+ icu_text.getBuffer () + icu_text.length ());
5857+
5858+ txt::ParagraphStyle paragraph_style;
5859+ paragraph_style.bounding_line_height_behavior =
5860+ txt::BoundaryLineHeightBehavior::kDisableFirst &
5861+ txt::BoundaryLineHeightBehavior::kDisableLast ;
5862+
5863+ txt::ParagraphBuilderTxt builder (paragraph_style, GetTestFontCollection ());
5864+
5865+ txt::TextStyle text_style;
5866+ text_style.color = SK_ColorBLACK;
5867+ text_style.font_families = std::vector<std::string>(1 , " Roboto" );
5868+ text_style.font_size = 30 ;
5869+ text_style.height = 5 ;
5870+ text_style.has_height_override = true ;
5871+ builder.PushStyle (text_style);
5872+ builder.AddText (u16_text);
5873+
5874+ builder.Pop ();
5875+
5876+ auto paragraph = BuildParagraph (builder);
5877+ paragraph->Layout (GetTestCanvasWidth () - 300 );
5878+
5879+ paragraph->Paint (GetCanvas (), 0 , 0 );
5880+
5881+ for (size_t i = 0 ; i < u16_text.length (); i++) {
5882+ ASSERT_EQ (paragraph->text_ [i], u16_text[i]);
5883+ }
5884+
5885+ ASSERT_EQ (paragraph->records_ .size (), 3ull );
5886+
5887+ SkPaint paint;
5888+ paint.setStyle (SkPaint::kStroke_Style );
5889+ paint.setAntiAlias (true );
5890+ paint.setStrokeWidth (1 );
5891+
5892+ // Tests for GetRectsForRange()
5893+ Paragraph::RectHeightStyle rect_height_style =
5894+ Paragraph::RectHeightStyle::kMax ;
5895+ Paragraph::RectWidthStyle rect_width_style =
5896+ Paragraph::RectWidthStyle::kTight ;
5897+ paint.setColor (SK_ColorRED);
5898+ std::vector<txt::Paragraph::TextBox> boxes =
5899+ paragraph->GetRectsForRange (0 , 0 , rect_height_style, rect_width_style);
5900+ for (size_t i = 0 ; i < boxes.size (); ++i) {
5901+ GetCanvas ()->drawRect (boxes[i].rect , paint);
5902+ }
5903+ EXPECT_EQ (boxes.size (), 0ull );
5904+
5905+ // First line. Shorter due to disabled height modifications on first ascent.
5906+ boxes =
5907+ paragraph->GetRectsForRange (0 , 3 , rect_height_style, rect_width_style);
5908+ for (size_t i = 0 ; i < boxes.size (); ++i) {
5909+ GetCanvas ()->drawRect (boxes[i].rect , paint);
5910+ }
5911+ EXPECT_EQ (boxes.size (), 1ull );
5912+ EXPECT_FLOAT_EQ (boxes[0 ].rect .left (), 0 );
5913+ EXPECT_FLOAT_EQ (boxes[0 ].rect .right (), 31.117188 );
5914+ EXPECT_FLOAT_EQ (boxes[0 ].rect .top (), -0.08203125 );
5915+ EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom (), 59 );
5916+ EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom () - boxes[0 ].rect .top (), 59.082031 );
5917+
5918+ // Second line. Normal.
5919+ boxes =
5920+ paragraph->GetRectsForRange (6 , 10 , rect_height_style, rect_width_style);
5921+ for (size_t i = 0 ; i < boxes.size (); ++i) {
5922+ GetCanvas ()->drawRect (boxes[i].rect , paint);
5923+ }
5924+ EXPECT_EQ (boxes.size (), 1ull );
5925+ EXPECT_FLOAT_EQ (boxes[0 ].rect .left (), 0 );
5926+ EXPECT_FLOAT_EQ (boxes[0 ].rect .right (), 47.011719 );
5927+ EXPECT_FLOAT_EQ (boxes[0 ].rect .top (), 59 );
5928+ EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom (), 209 );
5929+ EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom () - boxes[0 ].rect .top (), 150 );
5930+
5931+ boxes =
5932+ paragraph->GetRectsForRange (12 , 17 , rect_height_style, rect_width_style);
5933+ for (size_t i = 0 ; i < boxes.size (); ++i) {
5934+ GetCanvas ()->drawRect (boxes[i].rect , paint);
5935+ }
5936+ EXPECT_EQ (boxes.size (), 1ull );
5937+ EXPECT_FLOAT_EQ (boxes[0 ].rect .left (), 0 );
5938+ EXPECT_FLOAT_EQ (boxes[0 ].rect .right (), 63.859375 );
5939+ EXPECT_FLOAT_EQ (boxes[0 ].rect .top (), 208.92578 );
5940+ EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom (), 335 );
5941+ EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom () - boxes[0 ].rect .top (), 126.07422 );
5942+
5943+ ASSERT_TRUE (Snapshot ());
5944+ }
5945+
58495946} // namespace txt
0 commit comments