Scale strike width for SDFT
Allow SDFT to handle non-hairline stroked glyphs. Adjust the
stroke width and dashing for the generally larger size of the
glyph image.
Change-Id: I4aeb0b439f8ad40f1a4c8472466fedfd8b118b83
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/642337
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/core/SkStrikeSpec.cpp b/src/core/SkStrikeSpec.cpp
index cfe1f26..2a5c55c 100644
--- a/src/core/SkStrikeSpec.cpp
+++ b/src/core/SkStrikeSpec.cpp
@@ -8,6 +8,9 @@
#include "src/core/SkStrikeSpec.h"
#include "include/core/SkGraphics.h"
+#include "include/core/SkPaint.h"
+#include "include/core/SkPathEffect.h"
+#include "include/effects/SkDashPathEffect.h"
#include "src/base/SkTLazy.h"
#include "src/core/SkDraw.h"
#include "src/core/SkFontPriv.h"
@@ -163,6 +166,30 @@
auto [dfFont, strikeToSourceScale, matrixRange] = control.getSDFFont(font, deviceMatrix,
textLocation);
+ // Adjust the stroke width by the scale factor for drawing the SDFT.
+ dfPaint.setStrokeWidth(paint.getStrokeWidth() / strikeToSourceScale);
+
+ // Check for dashing and adjust the intervals.
+ if (SkPathEffect* pathEffect = paint.getPathEffect(); pathEffect != nullptr) {
+ SkPathEffect::DashInfo dashInfo;
+ if (pathEffect->asADash(&dashInfo) == SkPathEffect::kDash_DashType) {
+ if (dashInfo.fCount > 0) {
+ // Allocate the intervals.
+ std::vector<SkScalar> scaledIntervals(dashInfo.fCount);
+ dashInfo.fIntervals = scaledIntervals.data();
+ // Call again to get the interval data.
+ (void)pathEffect->asADash(&dashInfo);
+ for (SkScalar& interval : scaledIntervals) {
+ interval /= strikeToSourceScale;
+ }
+ auto scaledDashes = SkDashPathEffect::Make(scaledIntervals.data(),
+ scaledIntervals.size(),
+ dashInfo.fPhase / strikeToSourceScale);
+ dfPaint.setPathEffect(scaledDashes);
+ }
+ }
+ }
+
// Fake-gamma and subpixel antialiasing are applied in the shader, so we ignore the
// passed-in scaler context flags. (It's only used when we fall-back to bitmap text).
SkScalerContextFlags flags = SkScalerContextFlags::kNone;
diff --git a/src/text/gpu/SDFTControl.cpp b/src/text/gpu/SDFTControl.cpp
index 2eae03b..d576644 100644
--- a/src/text/gpu/SDFTControl.cpp
+++ b/src/text/gpu/SDFTControl.cpp
@@ -66,9 +66,11 @@
#if !defined(SK_DISABLE_SDF_TEXT)
bool SDFTControl::isSDFT(SkScalar approximateDeviceTextSize, const SkPaint& paint,
const SkMatrix& matrix) const {
+ const bool wideStroke = paint.getStyle() == SkPaint::kStroke_Style &&
+ paint.getStrokeWidth() > 0;
return fAbleToUseSDFT &&
paint.getMaskFilter() == nullptr &&
- paint.getStyle() == SkPaint::kFill_Style &&
+ (paint.getStyle() == SkPaint::kFill_Style || wideStroke) &&
0 < approximateDeviceTextSize &&
(fAbleToUsePerspectiveSDFT || !matrix.hasPerspective()) &&
(fMinDistanceFieldFontSize <= approximateDeviceTextSize || matrix.hasPerspective()) &&