diff --git a/gm/strokes.cpp b/gm/strokes.cpp index 7bd31c23f4..ed13d090ff 100644 --- a/gm/strokes.cpp +++ b/gm/strokes.cpp @@ -518,3 +518,18 @@ DEF_GM( return new Strokes5GM; ) DEF_GM( return new ZeroLenStrokesGM; ) DEF_GM( return new TeenyStrokesGM; ) + +DEF_SIMPLE_GM(zerolinedash, canvas, 256, 256) { + canvas->clear(SK_ColorWHITE); + + SkPaint paint; + paint.setColor(SkColorSetARGB(255, 0, 0, 0)); + paint.setStrokeWidth(11); + paint.setStrokeCap(SkPaint::kRound_Cap); + paint.setStrokeJoin(SkPaint::kBevel_Join); + + SkScalar dash_pattern[] = {1, 5}; + paint.setPathEffect(SkDashPathEffect::Make(dash_pattern, 2, 0)); + + canvas->drawLine(100, 100, 100, 100, paint); +} diff --git a/src/utils/SkDashPath.cpp b/src/utils/SkDashPath.cpp index d3c52daee2..cbfc8f2168 100644 --- a/src/utils/SkDashPath.cpp +++ b/src/utils/SkDashPath.cpp @@ -140,6 +140,12 @@ static bool cull_path(const SkPath& srcPath, const SkStrokeRec& rec, pts[0].fX = minX; pts[1].fX = maxX; + // If line is zero-length, bump out the end by a tiny amount + // to draw endcaps. The bump factor is sized so that + // SkPoint::Distance() computes a non-zero length. + if (minX == maxX) { + pts[1].fX += maxX * FLT_EPSILON * 32; // 16 instead of 32 does not draw; length stays zero + } dstPath->moveTo(pts[0]); dstPath->lineTo(pts[1]); return true;