OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkStrokeRec.h" | 8 #include "SkStrokeRec.h" |
9 #include "SkPaintDefaults.h" | 9 #include "SkPaintDefaults.h" |
10 | 10 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 paint->setStyle(SkPaint::kFill_Style); | 127 paint->setStyle(SkPaint::kFill_Style); |
128 return; | 128 return; |
129 } | 129 } |
130 | 130 |
131 paint->setStyle(fStrokeAndFill ? SkPaint::kStrokeAndFill_Style : SkPaint::kS
troke_Style); | 131 paint->setStyle(fStrokeAndFill ? SkPaint::kStrokeAndFill_Style : SkPaint::kS
troke_Style); |
132 paint->setStrokeWidth(fWidth); | 132 paint->setStrokeWidth(fWidth); |
133 paint->setStrokeMiter(fMiterLimit); | 133 paint->setStrokeMiter(fMiterLimit); |
134 paint->setStrokeCap((SkPaint::Cap)fCap); | 134 paint->setStrokeCap((SkPaint::Cap)fCap); |
135 paint->setStrokeJoin((SkPaint::Join)fJoin); | 135 paint->setStrokeJoin((SkPaint::Join)fJoin); |
136 } | 136 } |
| 137 |
| 138 static inline SkScalar get_inflation_bounds(SkPaint::Join join, |
| 139 SkScalar strokeWidth, |
| 140 SkScalar miterLimit) { |
| 141 if (strokeWidth < 0) { // fill |
| 142 return 0; |
| 143 } else if (0 == strokeWidth) { |
| 144 return SK_Scalar1; |
| 145 } |
| 146 // since we're stroked, outset the rect by the radius (and join type) |
| 147 SkScalar radius = SkScalarHalf(strokeWidth); |
| 148 if (SkPaint::kMiter_Join == join) { |
| 149 if (miterLimit > SK_Scalar1) { |
| 150 radius = SkScalarMul(miterLimit, radius); |
| 151 } |
| 152 } |
| 153 return radius; |
| 154 } |
| 155 |
| 156 SkScalar SkStrokeRec::getInflationRadius() const { |
| 157 return get_inflation_bounds((SkPaint::Join)fJoin, fWidth, fMiterLimit); |
| 158 } |
| 159 |
| 160 SkScalar SkStrokeRec::GetInflationRadius(const SkPaint& paint, SkPaint::Style st
yle) { |
| 161 SkScalar width = SkPaint::kFill_Style == style ? -SK_Scalar1 : paint.getStro
keWidth(); |
| 162 return get_inflation_bounds(paint.getStrokeJoin(), width, paint.getStrokeMit
er()); |
| 163 |
| 164 } |
OLD | NEW |