@@ -7045,4 +7045,64 @@ TEST_F(ParagraphTest, TextHeightBehaviorRectsParagraph) {
70457045 ASSERT_TRUE (Snapshot ());
70467046}
70477047
7048+ TEST_F (ParagraphTest, MixedTextHeightBehaviorRectsParagraph) {
7049+ const char * text = " 0123456789" ;
7050+ auto icu_text = icu::UnicodeString::fromUTF8 (text);
7051+ std::u16string u16_text (icu_text.getBuffer (),
7052+ icu_text.getBuffer () + icu_text.length ());
7053+
7054+ txt::ParagraphStyle paragraph_style;
7055+ // paragraph_style.text_height_behavior will be overridden later.
7056+ paragraph_style.text_height_behavior =
7057+ txt::TextHeightBehavior::kDisableFirstAscent |
7058+ txt::TextHeightBehavior::kDisableLastDescent ;
7059+
7060+ txt::ParagraphBuilderTxt builder (paragraph_style, GetTestFontCollection ());
7061+
7062+ txt::TextStyle text_style;
7063+ text_style.color = SK_ColorBLACK;
7064+ text_style.font_families = std::vector<std::string>(1 , " Roboto" );
7065+ text_style.font_size = 30 ;
7066+ text_style.height = 5 ;
7067+ text_style.has_height_override = true ;
7068+ text_style.has_text_height_behavior_override = true ;
7069+ text_style.text_height_behavior = txt::TextHeightBehavior::kDisableAll |
7070+ txt::TextHeightBehavior::kHalfLeading ;
7071+ builder.PushStyle (text_style);
7072+ builder.AddText (u16_text);
7073+
7074+ text_style.text_height_behavior = txt::TextHeightBehavior::kHalfLeading ;
7075+ builder.PushStyle (text_style);
7076+ builder.AddText (u16_text);
7077+
7078+ builder.Pop ();
7079+
7080+ auto paragraph = BuildParagraph (builder);
7081+ paragraph->Layout (GetTestCanvasWidth () - 300 );
7082+
7083+ paragraph->Paint (GetCanvas (), 0 , 0 );
7084+
7085+ SkPaint paint;
7086+ paint.setStyle (SkPaint::kStroke_Style );
7087+ paint.setAntiAlias (true );
7088+ paint.setStrokeWidth (1 );
7089+
7090+ // Tests for GetRectsForRange()
7091+ Paragraph::RectHeightStyle rect_height_style =
7092+ Paragraph::RectHeightStyle::kMax ;
7093+ Paragraph::RectWidthStyle rect_width_style =
7094+ Paragraph::RectWidthStyle::kTight ;
7095+ paint.setColor (SK_ColorRED);
7096+ std::vector<txt::Paragraph::TextBox> boxes =
7097+ paragraph->GetRectsForRange (0 , 20 , rect_height_style, rect_width_style);
7098+
7099+ for (size_t i = 0 ; i < boxes.size (); ++i) {
7100+ GetCanvas ()->drawRect (boxes[i].rect , paint);
7101+ }
7102+ // The line-height is the same as not having the kDisableAll flag.
7103+ EXPECT_GT (boxes.size (), 1ull );
7104+ EXPECT_FLOAT_EQ (boxes[0 ].rect .bottom () - boxes[0 ].rect .top (), 150.0 );
7105+
7106+ ASSERT_TRUE (Snapshot ());
7107+ }
70487108} // namespace txt
0 commit comments