Add preliminary support for letter-spacing and word-spacing
Change-Id: If3f64cf0c18ff0aa087091626532bcd983f6b54c
This commit is contained in:
@@ -149,7 +149,7 @@ void Paragraph::Layout(double width,
|
||||
|
||||
// Reset member variables so Layout still works when called more than once
|
||||
max_intrinsic_width_ = 0.0f;
|
||||
lines_ = 1;
|
||||
lines_ = 0;
|
||||
|
||||
minikin::Layout layout;
|
||||
SkScalar x = x_offset;
|
||||
@@ -170,8 +170,7 @@ void Paragraph::Layout(double width,
|
||||
|
||||
size_t layout_start = run.start;
|
||||
|
||||
while (layout_start < run.end &&
|
||||
GetLineCount() <= paragraph_style_.max_lines) {
|
||||
while (layout_start < run.end && lines_ < paragraph_style_.max_lines) {
|
||||
const size_t next_break = (break_index > breaks_count - 1)
|
||||
? std::numeric_limits<size_t>::max()
|
||||
: breaks[break_index];
|
||||
@@ -194,14 +193,15 @@ void Paragraph::Layout(double width,
|
||||
const size_t glyph_index = blob_start + blob_index;
|
||||
buffer.glyphs[blob_index] = layout.getGlyphId(glyph_index);
|
||||
const size_t pos_index = 2 * blob_index;
|
||||
letter_spacing_offset += run.style.letter_spacing;
|
||||
buffer.pos[pos_index] = layout.getX(glyph_index) +
|
||||
letter_spacing_offset + word_spacing_offset;
|
||||
letter_spacing_offset += run.style.letter_spacing;
|
||||
buffer.pos[pos_index + 1] = layout.getY(glyph_index);
|
||||
}
|
||||
blob_start += blob_length;
|
||||
|
||||
// Subtract letter offset to avoid big gap at end of run.
|
||||
// Subtract letter offset to avoid big gap at end of run. This my be
|
||||
// removed depending on the specificatins for letter spacing.
|
||||
letter_spacing_offset -= run.style.letter_spacing;
|
||||
|
||||
word_spacing_offset += run.style.word_spacing;
|
||||
@@ -210,6 +210,10 @@ void Paragraph::Layout(double width,
|
||||
layout.getX(blob_start - 1) + letter_spacing_offset;
|
||||
}
|
||||
|
||||
// Subtract word offset to avoid big gap at end of run. This my be
|
||||
// removed depending on the specificatins for word spacing.
|
||||
word_spacing_offset -= run.style.word_spacing;
|
||||
|
||||
// TODO(abarth): We could keep the same SkTextBlobBuilder as long as the
|
||||
// color stayed the same.
|
||||
records_.push_back(
|
||||
@@ -224,8 +228,6 @@ void Paragraph::Layout(double width,
|
||||
y_ += run.style.font_size * run.style.height;
|
||||
break_index += 1;
|
||||
lines_++;
|
||||
if (lines_ > paragraph_style_.max_lines)
|
||||
lines_--;
|
||||
} else {
|
||||
x += layout.getAdvance();
|
||||
}
|
||||
@@ -259,8 +261,7 @@ double Paragraph::GetMinIntrinsicWidth() const {
|
||||
}
|
||||
|
||||
double Paragraph::GetHeight() const {
|
||||
return paragraph_style_.font_size * paragraph_style_.line_height *
|
||||
paragraph_style_.max_lines;
|
||||
return y_;
|
||||
}
|
||||
|
||||
void Paragraph::SetParagraphStyle(const ParagraphStyle& style) {
|
||||
@@ -277,7 +278,6 @@ void Paragraph::Paint(SkCanvas* canvas, double x, double y) {
|
||||
}
|
||||
|
||||
int Paragraph::GetLineCount() const {
|
||||
// FTL_LOG(INFO) << "Lines: " << lines_;
|
||||
return lines_;
|
||||
}
|
||||
|
||||
|
||||
@@ -92,25 +92,25 @@ TEST_F(RenderTest, SimpleRedParagraph) {
|
||||
}
|
||||
|
||||
TEST_F(RenderTest, RainbowParagraph) {
|
||||
const char* text1 = "RedRoboto ";
|
||||
const char* text1 = "Red Roboto";
|
||||
auto icu_text1 = icu::UnicodeString::fromUTF8(text1);
|
||||
std::u16string u16_text1(icu_text1.getBuffer(),
|
||||
icu_text1.getBuffer() + icu_text1.length());
|
||||
const char* text2 = "Big Green Default ";
|
||||
const char* text2 = "Big Green Default";
|
||||
auto icu_text2 = icu::UnicodeString::fromUTF8(text2);
|
||||
std::u16string u16_text2(icu_text2.getBuffer(),
|
||||
icu_text2.getBuffer() + icu_text2.length());
|
||||
const char* text3 = "DefcolorHomemadeApple ";
|
||||
const char* text3 = "Defcolor Homemade Apple";
|
||||
auto icu_text3 = icu::UnicodeString::fromUTF8(text3);
|
||||
std::u16string u16_text3(icu_text3.getBuffer(),
|
||||
icu_text3.getBuffer() + icu_text3.length());
|
||||
const char* text4 = "SmallBlueRoboto ";
|
||||
const char* text4 = "Small Blue Roboto";
|
||||
auto icu_text4 = icu::UnicodeString::fromUTF8(text4);
|
||||
std::u16string u16_text4(icu_text4.getBuffer(),
|
||||
icu_text4.getBuffer() + icu_text4.length());
|
||||
const char* text5 =
|
||||
"Continue Last Style With lots of words to check if it overlaps properly "
|
||||
"or not";
|
||||
"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());
|
||||
@@ -281,13 +281,13 @@ TEST_F(RenderTest, LinebreakParagraph) {
|
||||
icu_text.getBuffer() + icu_text.length());
|
||||
|
||||
txt::ParagraphStyle paragraph_style;
|
||||
paragraph_style.max_lines = 1000;
|
||||
paragraph_style.max_lines = 14;
|
||||
txt::ParagraphBuilder builder(paragraph_style);
|
||||
|
||||
txt::TextStyle text_style;
|
||||
text_style.font_size = 26;
|
||||
// Letter spacing not yet implemented
|
||||
text_style.letter_spacing = 10;
|
||||
text_style.letter_spacing = 0;
|
||||
text_style.color = SK_ColorBLACK;
|
||||
text_style.height = 1.15;
|
||||
builder.PushStyle(text_style);
|
||||
@@ -297,9 +297,9 @@ TEST_F(RenderTest, LinebreakParagraph) {
|
||||
builder.Pop();
|
||||
|
||||
auto paragraph = builder.Build();
|
||||
paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir());
|
||||
paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir());
|
||||
|
||||
paragraph->Paint(GetCanvas(), 5.0, 30.0);
|
||||
paragraph->Paint(GetCanvas(), 0, 30.0);
|
||||
|
||||
ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
|
||||
for (size_t i = 0; i < u16_text.length(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user