forked from firka/flutter
Min and Max Intrinsic Widths look mostly correct now.
Change-Id: I0201c88bab4a46baf5164def8cccd51f4c5486c1
This commit is contained in:
@@ -401,11 +401,10 @@ void Paragraph::Layout(double width, bool force) {
|
||||
max_line_spacing = temp_line_spacing;
|
||||
// Record the alphabetic_baseline_:
|
||||
if (lines_ == 0) {
|
||||
alphabetic_baseline_ = metrics.fCapHeight * run.style.height;
|
||||
alphabetic_baseline_ = -metrics.fAscent * run.style.height;
|
||||
// TODO(garyq): Properly implement ideographic_baseline_.
|
||||
ideographic_baseline_ =
|
||||
(metrics.fUnderlinePosition + metrics.fCapHeight) *
|
||||
run.style.height;
|
||||
(metrics.fUnderlinePosition - metrics.fAscent) * run.style.height;
|
||||
}
|
||||
}
|
||||
temp_line_spacing = metrics.fDescent * run.style.height;
|
||||
@@ -455,6 +454,8 @@ void Paragraph::Layout(double width, bool force) {
|
||||
buffer_sizes.size() > 0) {
|
||||
JustifyLine(buffers, buffer_sizes, word_count, justify_spacing, -1);
|
||||
}
|
||||
line_widths_ =
|
||||
std::vector<double>(breaker_.getWidths(), breaker_.getWidths() + lines_);
|
||||
CalculateIntrinsicWidths();
|
||||
}
|
||||
|
||||
@@ -509,12 +510,25 @@ double Paragraph::GetIdeographicBaseline() const {
|
||||
}
|
||||
|
||||
void Paragraph::CalculateIntrinsicWidths() {
|
||||
for (size_t i = 0; i < word_widths_.size(); ++i) {
|
||||
max_intrinsic_width_ += word_widths_[i];
|
||||
// TODO(garyq): Investigate correctness of the following implementation of max
|
||||
// intrinsic width. This is currently the sum of all the widths of each line
|
||||
// after layout.
|
||||
max_intrinsic_width_ = 0;
|
||||
for (size_t i = 0; i < line_widths_.size(); ++i) {
|
||||
max_intrinsic_width_ += line_widths_[i];
|
||||
}
|
||||
|
||||
// TODO(garyq): Implement the DP algorithm version instead of this stand in!
|
||||
min_intrinsic_width_ = max_intrinsic_width_ / paragraph_style_.max_lines;
|
||||
// TODO(garyq): Investigate correctness of the following implementation of max
|
||||
// intrinsic width. This is currently the longest line in the text after
|
||||
// layout.
|
||||
min_intrinsic_width_ = 0;
|
||||
for (size_t i = 0; i < line_widths_.size(); ++i) {
|
||||
min_intrinsic_width_ = std::max(min_intrinsic_width_, line_widths_[i]);
|
||||
}
|
||||
|
||||
// Ensure that min < max widths.
|
||||
min_intrinsic_width_ = std::min(max_intrinsic_width_, min_intrinsic_width_);
|
||||
max_intrinsic_width_ = std::max(max_intrinsic_width_, min_intrinsic_width_);
|
||||
}
|
||||
|
||||
double Paragraph::GetMaxIntrinsicWidth() const {
|
||||
@@ -534,6 +548,18 @@ double Paragraph::GetHeight() const {
|
||||
return line_heights_[line_heights_.size() - 2];
|
||||
}
|
||||
|
||||
double Paragraph::GetLayoutWidth() const {
|
||||
double w = 0;
|
||||
for (size_t i = 0; i < line_widths_.size(); ++i) {
|
||||
w = std::max(w, line_widths_[i]);
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
double Paragraph::GetMaxWidth() const {
|
||||
return width_;
|
||||
}
|
||||
|
||||
void Paragraph::SetParagraphStyle(const ParagraphStyle& style) {
|
||||
needs_layout_ = true;
|
||||
paragraph_style_ = style;
|
||||
|
||||
@@ -53,6 +53,12 @@ class Paragraph {
|
||||
|
||||
double GetHeight() const;
|
||||
|
||||
// Returns the actual max width of the longest line after Layout().
|
||||
double GetLayoutWidth() const;
|
||||
|
||||
// Returns the width provided in the Layout() method.
|
||||
double GetMaxWidth() const;
|
||||
|
||||
double GetAlphabeticBaseline() const;
|
||||
|
||||
double GetIdeographicBaseline() const;
|
||||
@@ -115,8 +121,8 @@ class Paragraph {
|
||||
SkScalar height_ = 0.0f;
|
||||
double width_ = 0.0f;
|
||||
size_t lines_ = 0;
|
||||
double max_intrinsic_width_ = -1;
|
||||
double min_intrinsic_width_ = -1;
|
||||
double max_intrinsic_width_ = 0;
|
||||
double min_intrinsic_width_ = 0;
|
||||
// TODO(garyq): Instead of using whitespace to delimit "words", use the
|
||||
// results of minikin breaker.
|
||||
std::vector<double> word_widths_;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#ifndef LIB_TXT_SRC_PARAGRAPH_STYLE_H_
|
||||
#define LIB_TXT_SRC_PARAGRAPH_STYLE_H_
|
||||
|
||||
#include <climits>
|
||||
#include <string>
|
||||
|
||||
#include "lib/txt/src/font_style.h"
|
||||
@@ -32,7 +33,7 @@ class ParagraphStyle {
|
||||
FontStyle font_style = FontStyle::normal;
|
||||
std::string font_family = "";
|
||||
double font_size = 14;
|
||||
size_t max_lines = 1;
|
||||
size_t max_lines = UINT_MAX;
|
||||
double line_height = 1.0;
|
||||
std::string ellipsis = "...";
|
||||
// TODO(garyq): Implement right to left.
|
||||
|
||||
@@ -1025,7 +1025,7 @@ TEST_F(RenderTest, GetRectsForRangeParagraph) {
|
||||
// end of paragraph handling needs to be fixed in a later patch.
|
||||
EXPECT_FLOAT_EQ(rects[16].left(), 0);
|
||||
EXPECT_FLOAT_EQ(rects[16].top(), 234.375);
|
||||
EXPECT_FLOAT_EQ(rects[16].right(), 133.875);
|
||||
EXPECT_FLOAT_EQ(rects[16].right(), 140);
|
||||
EXPECT_FLOAT_EQ(rects[16].bottom(), 292.96875);
|
||||
|
||||
ASSERT_TRUE(Snapshot());
|
||||
|
||||
Reference in New Issue
Block a user