try drawing underline with rect instead of line/path
Change-Id: Ide265f9e5c36a5903a4726fb4fcc8d94a92678a7 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/291577 Reviewed-by: Julia Lavrova <jlavrova@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
b7518a80c5
commit
934b9996ee
@ -3,6 +3,18 @@
|
||||
#include "include/effects/SkDiscretePathEffect.h"
|
||||
#include "modules/skparagraph/src/Decorations.h"
|
||||
|
||||
static void draw_line_as_rect(SkCanvas* canvas, SkScalar x, SkScalar y, SkScalar width,
|
||||
const SkPaint& paint) {
|
||||
SkASSERT(paint.getPathEffect() == nullptr);
|
||||
SkASSERT(paint.getStrokeCap() == SkPaint::kButt_Cap);
|
||||
SkASSERT(paint.getStrokeWidth() > 0); // this trick won't work for hairlines
|
||||
|
||||
SkPaint p(paint);
|
||||
p.setStroke(false);
|
||||
float radius = paint.getStrokeWidth() * 0.5f;
|
||||
canvas->drawRect({x, y - radius, x + width, y + radius}, p);
|
||||
}
|
||||
|
||||
namespace skia {
|
||||
namespace textlayout {
|
||||
|
||||
@ -48,8 +60,8 @@ void Decorations::paint(SkCanvas* canvas, const TextStyle& textStyle, const Text
|
||||
calculateGaps(context, left, left + width, bottom, bottom + fThickness, baseline, fThickness);
|
||||
canvas->drawPath(fPath, fPaint);
|
||||
} else {
|
||||
canvas->drawLine(x, y, x + width, y, fPaint);
|
||||
canvas->drawLine(x, bottom, x + width, bottom, fPaint);
|
||||
draw_line_as_rect(canvas, x, y, width, fPaint);
|
||||
draw_line_as_rect(canvas, x, bottom, width, fPaint);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -71,7 +83,7 @@ void Decorations::paint(SkCanvas* canvas, const TextStyle& textStyle, const Text
|
||||
calculateGaps(context, left, left + width, y, y + fThickness, baseline, fThickness);
|
||||
canvas->drawPath(fPath, fPaint);
|
||||
} else {
|
||||
canvas->drawLine(x, y, x + width, y, fPaint);
|
||||
draw_line_as_rect(canvas, x, y, width, fPaint);
|
||||
}
|
||||
break;
|
||||
default:break;
|
||||
|
Loading…
Reference in New Issue
Block a user