From 6e6bc110fd53472a8be7810bed4c7cb61302a62b Mon Sep 17 00:00:00 2001 From: Chris Dalton Date: Wed, 18 Jul 2018 16:06:22 -0600 Subject: Account for square caps in SkStrokeRec::getInflationRadius Bug: skia: Change-Id: I85b359eaa89e804218af8b2442f6c3aefa9af99a Reviewed-on: https://skia-review.googlesource.com/142271 Reviewed-by: Brian Salomon Commit-Queue: Chris Dalton --- src/core/SkStrokeRec.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'src') 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); } -- cgit v1.2.3