Skip to content

Commit

Permalink
libtxt: make minIntrinsicWidth match maxIntrinsicWidth if constraints…
Browse files Browse the repository at this point in the history
… prevent line wrapping (flutter#4468)
  • Loading branch information
jason-simmons authored Dec 19, 2017
1 parent 1cc9abb commit 1c6eef1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
11 changes: 8 additions & 3 deletions third_party/txt/src/txt/paragraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ void Paragraph::Layout(double width, bool force) {
std::vector<uint16_t> ellipsized_text;
if (ellipsis.length() && !isinf(width_) && !line_range.hard_break &&
(line_number == line_limit - 1 ||
paragraph_style_.max_lines == std::numeric_limits<size_t>::max())) {
paragraph_style_.unlimited_lines())) {
float ellipsis_width = layout.measureText(
reinterpret_cast<const uint16_t*>(ellipsis.data()), 0,
ellipsis.length(), ellipsis.length(), bidiFlags, font,
Expand Down Expand Up @@ -471,7 +471,7 @@ void Paragraph::Layout(double width, bool force) {

// If there is no line limit, then skip all lines after the ellipsized
// line.
if (paragraph_style_.max_lines == std::numeric_limits<size_t>::max()) {
if (paragraph_style_.unlimited_lines()) {
line_limit = line_number + 1;
did_exceed_max_lines_ = true;
}
Expand Down Expand Up @@ -666,7 +666,12 @@ void Paragraph::Layout(double width, bool force) {
for (double line_width : line_widths_) {
max_intrinsic_width_ += line_width;
}
min_intrinsic_width_ = std::min(max_word_width, max_intrinsic_width_);
if (paragraph_style_.max_lines == 1 ||
(paragraph_style_.unlimited_lines() && paragraph_style_.ellipsized())) {
min_intrinsic_width_ = max_intrinsic_width_;
} else {
min_intrinsic_width_ = std::min(max_word_width, max_intrinsic_width_);
}

std::sort(code_unit_runs_.begin(), code_unit_runs_.end(),
[](const CodeUnitRun& a, const CodeUnitRun& b) {
Expand Down
8 changes: 8 additions & 0 deletions third_party/txt/src/txt/paragraph_style.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ TextStyle ParagraphStyle::GetTextStyle() const {
return result;
}

bool ParagraphStyle::unlimited_lines() const {
return max_lines == std::numeric_limits<size_t>::max();
};

bool ParagraphStyle::ellipsized() const {
return !ellipsis.empty();
}

} // namespace txt
3 changes: 3 additions & 0 deletions third_party/txt/src/txt/paragraph_style.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class ParagraphStyle {
minikin::BreakStrategy::kBreakStrategy_Greedy;

TextStyle GetTextStyle() const;

bool unlimited_lines() const;
bool ellipsized() const;
};

} // namespace txt
Expand Down

0 comments on commit 1c6eef1

Please sign in to comment.