diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index 1a6b1888db..32374e1b12 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -230,7 +230,6 @@ class LineBreaker { icu::Locale mLocale; std::vectormTextBuf; std::vectormCharWidths; - std::vectormCharSpacing; Hyphenator* mHyphenator; std::vector mHyphBuf; diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 62dbd830bb..661a8fc30e 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -138,10 +138,6 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const std::shared_ptrsize = style.font_size; - paint->letterSpacing = style.letter_spacing; + // Divide by font size so letter spacing is pixels, not proportional to font + // size. + paint->letterSpacing = style.letter_spacing / style.font_size; paint->wordSpacing = style.word_spacing; + paint->scaleX = 1; + // Prevent spacing rounding in Minikin. + paint->paintFlags = 0xFF; } void GetPaint(const TextStyle& style, SkPaint* paint) { @@ -203,7 +208,6 @@ void Paragraph::Layout(double width, bool force) { SkScalar x = 0.0f; SkScalar y = 0.0f; size_t break_index = 0; - double letter_spacing_offset = 0.0f; double max_line_spacing = 0.0f; double max_descent = 0.0f; double prev_max_descent = 0.0f; @@ -293,9 +297,6 @@ void Paragraph::Layout(double width, bool force) { GetFontAndMinikinPaint(run.style, &font, &minikin_paint); GetPaint(run.style, &paint); - // Subtract inital offset to avoid big gap at start of run. - letter_spacing_offset -= run.style.letter_spacing; - size_t layout_start = run.start; // Layout until the end of the run or too many lines. while (layout_start < run.end && lines_ < paragraph_style_.max_lines) { @@ -325,7 +326,6 @@ void Paragraph::Layout(double width, bool force) { buffer_sizes = std::vector(); word_count = 0; double temp_line_spacing = 0; - double prev_letter_spacing_offset = letter_spacing_offset; while (blob_start < glyph_count) { const size_t blob_length = GetBlobLength(layout, blob_start); buffer_sizes.push_back(blob_length); @@ -344,8 +344,6 @@ void Paragraph::Layout(double width, bool force) { buffers.push_back( &builder.allocRunPos(paint, blob_length - trailing_length)); - letter_spacing_offset += run.style.letter_spacing; - // TODO(garyq): Implement RTL. // Each Glyph/Letter. bool whitespace_ended = true; @@ -356,8 +354,7 @@ void Paragraph::Layout(double width, bool force) { const size_t pos_index = 2 * blob_index; - buffers.back()->pos[pos_index] = - layout.getX(glyph_index) + letter_spacing_offset; + buffers.back()->pos[pos_index] = layout.getX(glyph_index); glyph_single_line_position_x.push_back( buffers.back()->pos[pos_index]); buffers.back()->pos[pos_index + 1] = layout.getY(glyph_index); @@ -369,11 +366,6 @@ void Paragraph::Layout(double width, bool force) { // whitespaces. if (whitespace_ended) { ++word_count; - word_widths_.push_back(buffers.back()->pos[pos_index] + - layout.getCharAdvance(glyph_index) - - prev_word_pos); - prev_word_pos = buffers.back()->pos[pos_index] + - layout.getCharAdvance(glyph_index); } whitespace_ended = false; } else { @@ -381,25 +373,8 @@ void Paragraph::Layout(double width, bool force) { } prev_char_advance = layout.getCharAdvance(glyph_index); - - letter_spacing_offset += run.style.letter_spacing; } blob_start += blob_length; - - // Add on the last word if the blob break was not on whitespace. - if (whitespace_ended) { - word_widths_.push_back( - layout.getX(blob_start - 1) + letter_spacing_offset - - run.style.letter_spacing + layout.getCharAdvance(blob_start - 1) - - prev_word_pos); - } - - // Subtract letter offset to avoid big gap at end of run. This my be - // removed depending on the specifications for letter spacing. - // letter_spacing_offset -= run.style.letter_spacing; - - max_intrinsic_width_ += - layout.getX(blob_start - 1) + letter_spacing_offset; } // TODO(abarth): We could keep the same SkTextBlobBuilder as long as the @@ -416,7 +391,6 @@ void Paragraph::Layout(double width, bool force) { line_width += std::abs(records_[records_.size() - 1].text()->bounds().fRight + records_[records_.size() - 1].text()->bounds().fLeft); - records_.back().SetLetterSpacingOffset(prev_letter_spacing_offset); // Must adjust each line to the largest text in the line, so cannot // directly push the offset property of PaintRecord until line is // finished. @@ -452,13 +426,10 @@ void Paragraph::Layout(double width, bool force) { line_widths_.push_back(line_width); postprocess_line(); - records_.back().SetLetterSpacingOffset(0); - // Reset Variables for next line. max_line_spacing = 0.0f; max_descent = 0.0f; x = 0.0f; - letter_spacing_offset = 0.0f; prev_word_pos = 0; prev_char_advance = 0.0f; line_width = 0.0f; @@ -644,10 +615,6 @@ void Paragraph::PaintDecorations(SkCanvas* canvas, // Filled when drawing wavy decorations. std::vector wave_coords; - x += - (record_index != 0 ? records_[record_index - 1].GetLetterSpacingOffset() - : 0); - double width = 0; if (record_index == records_.size() - 1 || record.line() < records_[record_index + 1].line()) { diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 74d5a7ba40..773cc6bb9a 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -138,9 +138,6 @@ class Paragraph { size_t lines_ = 0; 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 word_widths_; double alphabetic_baseline_ = FLT_MAX; double ideographic_baseline_ = FLT_MAX; bool needs_layout_ = true; diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 24556675d3..8067118035 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -1201,8 +1201,6 @@ TEST_F(RenderTest, SpacingParagraph) { ASSERT_EQ(paragraph->records_[5].style().word_spacing, 0); ASSERT_EQ(paragraph->records_[6].style().word_spacing, 20); - - } } // namespace txt