aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Chris Dalton <csmartdalton@google.com>2018-07-18 16:06:22 -0600
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-20 15:40:26 +0000
commit6e6bc110fd53472a8be7810bed4c7cb61302a62b (patch)
treec78e3db26f1a8112909e8ab27df0900204c2539f /src
parent681691ed18072565f75b5f1f36ac9682bf5f0a4c (diff)
Account for square caps in SkStrokeRec::getInflationRadius
Bug: skia: Change-Id: I85b359eaa89e804218af8b2442f6c3aefa9af99a Reviewed-on: https://skia-review.googlesource.com/142271 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkStrokeRec.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/core/SkStrokeRec.cpp b/src/core/SkStrokeRec.cpp
index 1b4007cd83..41a3c30e41 100644
--- a/src/core/SkStrokeRec.cpp
+++ b/src/core/SkStrokeRec.cpp
@@ -136,29 +136,36 @@ void SkStrokeRec::applyToPaint(SkPaint* paint) const {
}
static inline SkScalar get_inflation_bounds(SkPaint::Join join,
- SkScalar strokeWidth,
- SkScalar miterLimit) {
+ SkScalar miterLimit,
+ SkPaint::Cap cap,
+ SkScalar strokeWidth) {
if (strokeWidth < 0) { // fill
return 0;
} else if (0 == strokeWidth) {
+ // FIXME: We need a "matrixScale" parameter here in order to properly handle hairlines.
+ // Their with is determined in device space, unlike other strokes.
+ // http://skbug.com/8157
return SK_Scalar1;
}
- // since we're stroked, outset the rect by the radius (and join type)
- SkScalar radius = SkScalarHalf(strokeWidth);
+
+ // since we're stroked, outset the rect by the radius (and join type, caps)
+ SkScalar multiplier = SK_Scalar1;
if (SkPaint::kMiter_Join == join) {
- if (miterLimit > SK_Scalar1) {
- radius *= miterLimit;
- }
+ multiplier = SkTMax(multiplier, miterLimit);
+ }
+ if (SkPaint::kSquare_Cap == cap) {
+ multiplier = SkTMax(multiplier, SK_ScalarSqrt2);
}
- return radius;
+ return strokeWidth/2 * multiplier;
}
SkScalar SkStrokeRec::getInflationRadius() const {
- return get_inflation_bounds((SkPaint::Join)fJoin, fWidth, fMiterLimit);
+ return get_inflation_bounds((SkPaint::Join)fJoin, fMiterLimit, (SkPaint::Cap)fCap, fWidth);
}
SkScalar SkStrokeRec::GetInflationRadius(const SkPaint& paint, SkPaint::Style style) {
SkScalar width = SkPaint::kFill_Style == style ? -SK_Scalar1 : paint.getStrokeWidth();
- return get_inflation_bounds(paint.getStrokeJoin(), width, paint.getStrokeMiter());
+ return get_inflation_bounds(paint.getStrokeJoin(), paint.getStrokeMiter(), paint.getStrokeCap(),
+ width);
}