Hardcode no-ligature flags for performance boost, minor bugfix on trailing space.

Change-Id: Ic61b7fba6ded25790f78b5040e4eb5ba3d1376a5
This commit is contained in:
Gary Qian
2017-08-07 16:25:18 -07:00
parent 76d250550b
commit f1daa1e629
2 changed files with 6 additions and 15 deletions

View File

@@ -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<hb_feature_t> 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);

View File

@@ -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 {