Workaround for jittering text selection bug using LinearTextFlag.
Change-Id: I15d9b43e7d3de851c7eb40e2c4abf29adb2b4817
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <minikin/Layout.h>
|
||||
#include "lib/ftl/logging.h"
|
||||
#include "lib/txt/include/minikin/MinikinFont.h"
|
||||
#include "lib/txt/libs/minikin/HbFontCache.h"
|
||||
#include "lib/txt/libs/minikin/LayoutUtils.h"
|
||||
#include "lib/txt/src/font_collection.h"
|
||||
@@ -103,8 +104,11 @@ void GetFontAndMinikinPaint(const TextStyle& style,
|
||||
paint->letterSpacing = style.letter_spacing / style.font_size;
|
||||
paint->wordSpacing = style.word_spacing;
|
||||
paint->scaleX = 1.0f;
|
||||
// Prevent spacing rounding in Minikin.
|
||||
paint->paintFlags = 0xFF;
|
||||
// Prevent spacing rounding in Minikin. This causes jitter when switching
|
||||
// between same text content with different runs composing it, however, it
|
||||
// also produces more accurate layouts.
|
||||
paint->paintFlags |=
|
||||
style.round_char_advances ? 0x00 : minikin::LinearTextFlag;
|
||||
}
|
||||
|
||||
void GetPaint(const TextStyle& style, SkPaint* paint) {
|
||||
@@ -649,7 +653,7 @@ void Paragraph::PaintDecorations(SkCanvas* canvas,
|
||||
// Backup value if the fUnderlineThickness metric is not available:
|
||||
// Divide by 14pt as it is the default size.
|
||||
: record.style().font_size / 14.0f *
|
||||
record.style().decoration_thickness);
|
||||
record.style().decoration_thickness_multiplier);
|
||||
|
||||
// Setup the decorations.
|
||||
switch (record.style().decoration_style) {
|
||||
@@ -740,7 +744,7 @@ void Paragraph::PaintDecorations(SkCanvas* canvas,
|
||||
if (SkToBool(metrics.fFlags & SkPaint::FontMetrics::FontMetricsFlags::
|
||||
kStrikeoutThicknessIsValid_Flag))
|
||||
paint.setStrokeWidth(metrics.fStrikeoutThickness *
|
||||
record.style().decoration_thickness);
|
||||
record.style().decoration_thickness_multiplier);
|
||||
// Make sure the double line is "centered" vertically.
|
||||
y_offset += (decoration_count - 1.0) * metrics.fUnderlineThickness *
|
||||
kDoubleDecorationSpacing / -2.0;
|
||||
|
||||
@@ -30,7 +30,7 @@ bool TextStyle::equals(const TextStyle& other) const {
|
||||
return false;
|
||||
if (decoration_style != other.decoration_style)
|
||||
return false;
|
||||
if (decoration_thickness != other.decoration_thickness)
|
||||
if (decoration_thickness_multiplier != other.decoration_thickness_multiplier)
|
||||
return false;
|
||||
if (font_weight != other.font_weight)
|
||||
return false;
|
||||
@@ -44,6 +44,8 @@ bool TextStyle::equals(const TextStyle& other) const {
|
||||
return false;
|
||||
if (height != other.height)
|
||||
return false;
|
||||
if (round_char_advances != other.round_char_advances)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ class TextStyle {
|
||||
// value to indicate no decoration color was set.
|
||||
SkColor decoration_color = SK_ColorTRANSPARENT;
|
||||
TextDecorationStyle decoration_style = TextDecorationStyle::kSolid;
|
||||
double decoration_thickness = 1.0;
|
||||
// Thickness is applied as a multiplier to the default thickness of the font.
|
||||
double decoration_thickness_multiplier = 1.0;
|
||||
FontWeight font_weight = FontWeight::w400;
|
||||
FontStyle font_style = FontStyle::normal;
|
||||
TextBaseline text_baseline = TextBaseline::kAlphabetic;
|
||||
@@ -45,6 +46,16 @@ class TextStyle {
|
||||
double word_spacing = 0.0;
|
||||
double height = 1.0;
|
||||
|
||||
// When disabled, the x coordinates of glyphs will be rounded, eliminating
|
||||
// potential mismatch between one long run and mutiple shorter runs of the
|
||||
// same text.
|
||||
//
|
||||
// When set to false, there may be jitter when switching between same text
|
||||
// content with different runs composing it, however, it also produces more
|
||||
// accurate layouts. Setting to true removs this, but sacrifices layout
|
||||
// accuracy.
|
||||
bool round_char_advances = false;
|
||||
|
||||
bool equals(const TextStyle& other) const;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user