From f1daa1e629411676f5ca84387372330e9454998e Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Mon, 7 Aug 2017 16:25:18 -0700 Subject: [PATCH] Hardcode no-ligature flags for performance boost, minor bugfix on trailing space. Change-Id: Ic61b7fba6ded25790f78b5040e4eb5ba3d1376a5 --- engine/src/flutter/src/paragraph.cc | 19 ++++++------------- engine/src/flutter/src/paragraph.h | 2 -- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 5bb0a41f0e..54d5e8a7ca 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -109,17 +109,6 @@ void GetFontAndMinikinPaint(const TextStyle& style, // also produces more accurate layouts. paint->paintFlags |= style.round_char_advances ? 0x00 : minikin::LinearTextFlag; - // Disable ligatures - // TODO(garyq): Re-enable ligatures. - std::vector features; - hb_feature_t no_liga = {HB_TAG('l', 'i', 'g', 'a'), 0, 0, ~0u}; - hb_feature_t no_clig = {HB_TAG('c', 'l', 'i', 'g'), 0, 0, ~0u}; - char buff[HB_FEATURE_BUFFER_SIZE * 2]; - hb_feature_to_string(&no_liga, buff, HB_FEATURE_BUFFER_SIZE); - hb_feature_to_string(&no_clig, buff + HB_FEATURE_BUFFER_SIZE, - HB_FEATURE_BUFFER_SIZE); - paint->fontFeatureSettings = - std::string(buff) + "," + std::string(buff + HB_FEATURE_BUFFER_SIZE); } void GetPaint(const TextStyle& style, SkPaint* paint) { @@ -220,6 +209,10 @@ void Paragraph::Layout(double width, bool force) { minikin::MinikinPaint minikin_paint; minikin::Layout layout; + // Disable ligatures + // TODO(garyq): Re-enable ligatures. + minikin_paint.fontFeatureSettings += "-liga,-clig,"; + SkTextBlobBuilder builder; // Reset member variables so Layout still works when called more than once @@ -370,7 +363,6 @@ void Paragraph::Layout(double width, bool force) { layout_end == next_break) { ++trailing_length; } - trailing_length = 0; buffers.push_back( &builder.allocRunPos(paint, blob_length - trailing_length)); @@ -385,6 +377,7 @@ void Paragraph::Layout(double width, bool force) { buffers.back()->glyphs[blob_index] = layout.getGlyphId(glyph_index); const size_t pos_index = 2 * blob_index; + // Extract the letter spacing by itself out of the minikin layout. letter_spacing = run.style.letter_spacing == 0 ? 0 : layout.getX(glyph_index) - current_x_position; @@ -625,9 +618,9 @@ void Paragraph::SetFontCollection(FontCollection* font_collection) { void Paragraph::Paint(SkCanvas* canvas, double x, double y) { SkAutoCanvasRestore canvas_restore(canvas, true); canvas->translate(x, y); + SkPaint paint; for (size_t index = 0; index < records_.size(); ++index) { PaintRecord& record = records_[index]; - SkPaint paint; paint.setColor(record.style().color); SkPoint offset = record.offset(); canvas->drawTextBlob(record.text(), offset.x(), offset.y(), paint); diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index d4b7a491b3..9fb8865056 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -31,8 +31,6 @@ #include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/include/core/SkTextBlob.h" -#define HB_FEATURE_BUFFER_SIZE 128 - class SkCanvas; namespace txt {