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
This commit is contained in:
Jason Simmons
2018-09-19 13:01:08 -07:00
committed by GitHub
parent c43e79d938
commit 30f7f2ea08

View File

@@ -234,6 +234,7 @@ void Paragraph::SetText(std::vector<uint16_t> text, StyledRuns runs) {
bool Paragraph::ComputeLineBreaks() {
line_ranges_.clear();
line_widths_.clear();
max_intrinsic_width_ = 0;
std::vector<size_t> 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_;