From 30f7f2ea08c9cb7eff43137b6befe400ebf10a18 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 19 Sep 2018 13:01:08 -0700 Subject: [PATCH] Compute maxIntrinsicWidth based on the width of styled runs added to the line breaker (flutter/engine#6281) maxIntrinsicWidth represents the width of the paragraph if no word wrap is applied. This can be calculated by summing the width of all runs within each block of text delimited by a hard line break. maxIntrinsicWidth is the maximum width among the blocks in the paragraph. Fixes https://github.com/flutter/flutter/issues/21965 --- .../third_party/txt/src/txt/paragraph.cc | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/engine/src/flutter/third_party/txt/src/txt/paragraph.cc b/engine/src/flutter/third_party/txt/src/txt/paragraph.cc index 97a8a05fb4..fc32fcc4b8 100644 --- a/engine/src/flutter/third_party/txt/src/txt/paragraph.cc +++ b/engine/src/flutter/third_party/txt/src/txt/paragraph.cc @@ -234,6 +234,7 @@ void Paragraph::SetText(std::vector text, StyledRuns runs) { bool Paragraph::ComputeLineBreaks() { line_ranges_.clear(); line_widths_.clear(); + max_intrinsic_width_ = 0; std::vector newline_positions; for (size_t i = 0; i < text_.size(); ++i) { @@ -268,6 +269,7 @@ bool Paragraph::ComputeLineBreaks() { breaker_.setText(); // Add the runs that include this line to the LineBreaker. + double block_total_width = 0; while (run_index < runs_.size()) { StyledRuns::Run run = runs_.GetRun(run_index); if (run.start >= block_end) @@ -290,13 +292,17 @@ bool Paragraph::ComputeLineBreaks() { size_t run_start = std::max(run.start, block_start) - block_start; size_t run_end = std::min(run.end, block_end) - block_start; bool isRtl = (paragraph_style_.text_direction == TextDirection::rtl); - breaker_.addStyleRun(&paint, collection, font, run_start, run_end, isRtl); + double run_width = breaker_.addStyleRun(&paint, collection, font, + run_start, run_end, isRtl); + block_total_width += run_width; if (run.end > block_end) break; run_index++; } + max_intrinsic_width_ = std::max(max_intrinsic_width_, block_total_width); + size_t breaks_count = breaker_.computeBreaks(); const int* breaks = breaker_.getBreaks(); for (size_t i = 0; i < breaks_count; ++i) { @@ -768,17 +774,6 @@ void Paragraph::Layout(double width, bool force) { } } - max_intrinsic_width_ = 0; - double line_block_width = 0; - for (size_t i = 0; i < line_widths_.size(); ++i) { - line_block_width += line_widths_[i]; - if (line_ranges_[i].hard_break) { - max_intrinsic_width_ = std::max(line_block_width, max_intrinsic_width_); - line_block_width = 0; - } - } - max_intrinsic_width_ = std::max(line_block_width, max_intrinsic_width_); - if (paragraph_style_.max_lines == 1 || (paragraph_style_.unlimited_lines() && paragraph_style_.ellipsized())) { min_intrinsic_width_ = max_intrinsic_width_;