Add Getters for intrinsic widths and implement MaxInstrinsicWidth. Update tests.

Change-Id: I210fac9d47f55f8317ca77bca64cfcfd438a246a
This commit is contained in:
Gary Qian
2017-06-15 18:13:45 -07:00
parent 4823485245
commit 1493b676ff
3 changed files with 23 additions and 1 deletions

View File

@@ -147,6 +147,10 @@ void Paragraph::Layout(const ParagraphConstraints& constraints,
SkTextBlobBuilder builder;
// Reset member variables so Layout still works when called more than once
max_intrinsic_width_ = 0.0f;
lines_ = 0;
minikin::Layout layout;
SkScalar x = x_offset;
y_ = y_offset;
@@ -187,6 +191,7 @@ void Paragraph::Layout(const ParagraphConstraints& constraints,
buffer.pos[pos_index + 1] = layout.getY(glyph_index);
}
blob_start += blob_length;
max_intrinsic_width_ += layout.getX(blob_start - 1);
}
// TODO(abarth): We could keep the same SkTextBlobBuilder as long as the
@@ -222,6 +227,14 @@ double Paragraph::GetIdeographicBaseline() const {
return FLT_MAX;
}
double Paragraph::GetMaxIntrinsicWidth() const {
return max_intrinsic_width_;
}
double Paragraph::GetMinIntrinsicWidth() const {
return min_intrinsic_width_;
}
double Paragraph::GetHeight() const {
return paragraph_style_.font_size * paragraph_style_.line_height *
paragraph_style_.max_lines;

View File

@@ -53,6 +53,10 @@ class Paragraph {
double GetIdeographicBaseline() const;
double GetMaxIntrinsicWidth() const;
double GetMinIntrinsicWidth() const;
bool DidExceedMaxLines() const;
private:
@@ -73,6 +77,8 @@ class Paragraph {
SkScalar y_ = 0.0f; // Height of the paragraph after Layout().
double width_ = 0.0f;
int lines_ = 0;
double max_intrinsic_width_ = 0.0f;
double min_intrinsic_width_ = FLT_MAX;
void SetText(std::vector<uint16_t> text, StyledRuns runs);

View File

@@ -110,7 +110,9 @@ TEST_F(RenderTest, RainbowParagraph) {
auto icu_text4 = icu::UnicodeString::fromUTF8(text4);
std::u16string u16_text4(icu_text4.getBuffer(),
icu_text4.getBuffer() + icu_text4.length());
const char* text5 = "ContinueLastStyle";
const char* text5 =
"Continue Last Style With lots of words to check if it overlaps properly "
"or not";
auto icu_text5 = icu::UnicodeString::fromUTF8(text5);
std::u16string u16_text5(icu_text5.getBuffer(),
icu_text5.getBuffer() + icu_text5.length());
@@ -284,6 +286,7 @@ TEST_F(RenderTest, LinebreakParagraph) {
icu_text.getBuffer() + icu_text.length());
txt::ParagraphStyle paragraph_style;
paragraph_style.max_lines = 1000;
txt::ParagraphBuilder builder(paragraph_style);
txt::TextStyle text_style;