diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 8f45e9f6b6..e548f9d10b 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -147,6 +147,10 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, SkTextBlobBuilder builder; + // Reset member variables so Layout still works when called more than once + max_intrinsic_width_ = 0.0f; + lines_ = 0; + minikin::Layout layout; SkScalar x = x_offset; y_ = y_offset; @@ -187,6 +191,7 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, buffer.pos[pos_index + 1] = layout.getY(glyph_index); } blob_start += blob_length; + max_intrinsic_width_ += layout.getX(blob_start - 1); } // TODO(abarth): We could keep the same SkTextBlobBuilder as long as the @@ -222,6 +227,14 @@ double Paragraph::GetIdeographicBaseline() const { return FLT_MAX; } +double Paragraph::GetMaxIntrinsicWidth() const { + return max_intrinsic_width_; +} + +double Paragraph::GetMinIntrinsicWidth() const { + return min_intrinsic_width_; +} + double Paragraph::GetHeight() const { return paragraph_style_.font_size * paragraph_style_.line_height * paragraph_style_.max_lines; diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 513d1fb57f..ca05810209 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -53,6 +53,10 @@ class Paragraph { double GetIdeographicBaseline() const; + double GetMaxIntrinsicWidth() const; + + double GetMinIntrinsicWidth() const; + bool DidExceedMaxLines() const; private: @@ -73,6 +77,8 @@ class Paragraph { SkScalar y_ = 0.0f; // Height of the paragraph after Layout(). double width_ = 0.0f; int lines_ = 0; + double max_intrinsic_width_ = 0.0f; + double min_intrinsic_width_ = FLT_MAX; void SetText(std::vector text, StyledRuns runs); diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index e3901f02f0..88071b13bd 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -110,7 +110,9 @@ TEST_F(RenderTest, RainbowParagraph) { auto icu_text4 = icu::UnicodeString::fromUTF8(text4); std::u16string u16_text4(icu_text4.getBuffer(), icu_text4.getBuffer() + icu_text4.length()); - const char* text5 = "ContinueLastStyle"; + const char* text5 = + "Continue Last Style With lots of words to check if it overlaps properly " + "or not"; auto icu_text5 = icu::UnicodeString::fromUTF8(text5); std::u16string u16_text5(icu_text5.getBuffer(), icu_text5.getBuffer() + icu_text5.length()); @@ -284,6 +286,7 @@ TEST_F(RenderTest, LinebreakParagraph) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; + paragraph_style.max_lines = 1000; txt::ParagraphBuilder builder(paragraph_style); txt::TextStyle text_style;