From 97184fe85da8495f08eea5ef367a9262168717a7 Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Wed, 18 Jan 2017 10:53:24 -0500 Subject: [PATCH] Stop processing multiline text after maxLines. (flutter/engine#3342) Added a Paragraph.didExceedMaxLines property to query when this occurs. Needed for https://github.com/flutter/flutter/issues/7271 --- engine/src/flutter/lib/ui/text.dart | 6 +++++- engine/src/flutter/lib/ui/text/paragraph.cc | 9 +++++++++ engine/src/flutter/lib/ui/text/paragraph.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/lib/ui/text.dart b/engine/src/flutter/lib/ui/text.dart index 66761bf23f..70f391bd78 100644 --- a/engine/src/flutter/lib/ui/text.dart +++ b/engine/src/flutter/lib/ui/text.dart @@ -693,9 +693,13 @@ abstract class Paragraph extends NativeFieldWrapperClass2 { double get alphabeticBaseline native "Paragraph_alphabeticBaseline"; /// The distance from the top of the paragraph to the ideographic - /// baseline of the first line, in logical pixels. + /// baseline of the first line, in logical pixels. double get ideographicBaseline native "Paragraph_ideographicBaseline"; + /// True if there is more vertical content, but the text was truncated + /// because we reached [ParagraphStyle.maxLines] lines of text. + bool get didExceedMaxLines native "Paragraph_didExceedMaxLines"; + /// Computes the size and position of each glyph in the paragraph. void layout(ParagraphConstraints constraints) => _layout(constraints.width); void _layout(double width) native "Paragraph_layout"; diff --git a/engine/src/flutter/lib/ui/text/paragraph.cc b/engine/src/flutter/lib/ui/text/paragraph.cc index c7fc683385..9f29d3d089 100644 --- a/engine/src/flutter/lib/ui/text/paragraph.cc +++ b/engine/src/flutter/lib/ui/text/paragraph.cc @@ -7,6 +7,7 @@ #include "flutter/common/threads.h" #include "flutter/sky/engine/core/rendering/PaintInfo.h" #include "flutter/sky/engine/core/rendering/RenderText.h" +#include "flutter/sky/engine/core/rendering/RenderParagraph.h" #include "flutter/sky/engine/core/rendering/style/RenderStyle.h" #include "flutter/sky/engine/platform/fonts/FontCache.h" #include "flutter/sky/engine/platform/graphics/GraphicsContext.h" @@ -30,6 +31,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Paragraph); V(Paragraph, maxIntrinsicWidth) \ V(Paragraph, alphabeticBaseline) \ V(Paragraph, ideographicBaseline) \ + V(Paragraph, didExceedMaxLines) \ V(Paragraph, layout) \ V(Paragraph, paint) \ V(Paragraph, getWordBoundary) \ @@ -75,6 +77,13 @@ double Paragraph::ideographicBaseline() { FontBaselineOrAuto(IdeographicBaseline)); } +bool Paragraph::didExceedMaxLines() { + RenderBox* box = firstChildBox(); + ASSERT(box->isRenderParagraph()); + RenderParagraph* paragraph = static_cast(box); + return paragraph->didExceedMaxLines(); +} + void Paragraph::layout(double width) { FontCachePurgePreventer fontCachePurgePreventer; diff --git a/engine/src/flutter/lib/ui/text/paragraph.h b/engine/src/flutter/lib/ui/text/paragraph.h index be4e555ec8..e75025b07a 100644 --- a/engine/src/flutter/lib/ui/text/paragraph.h +++ b/engine/src/flutter/lib/ui/text/paragraph.h @@ -34,6 +34,7 @@ class Paragraph : public ftl::RefCountedThreadSafe, double maxIntrinsicWidth(); double alphabeticBaseline(); double ideographicBaseline(); + bool didExceedMaxLines(); void layout(double width); void paint(Canvas* canvas, double x, double y);