From ffbd0273bd1705e58ed8567540d101ba436c1bad Mon Sep 17 00:00:00 2001 From: George Wright Date: Fri, 30 Mar 2012 17:36:34 -0400 Subject: [PATCH] Bug 740963 - [Skia] Handle non-multiple-of-two dash lengths in HelpersSkia::StrokeOptionsToPaint(). r=jrmuizel --- gfx/2d/HelpersSkia.h | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/gfx/2d/HelpersSkia.h b/gfx/2d/HelpersSkia.h index 0fdfee7fb9e3..23caed57035d 100644 --- a/gfx/2d/HelpersSkia.h +++ b/gfx/2d/HelpersSkia.h @@ -118,22 +118,29 @@ StrokeOptionsToPaint(SkPaint& aPaint, const StrokeOptions &aOptions) aPaint.setStrokeCap(CapStyleToSkiaCap(aOptions.mLineCap)); aPaint.setStrokeJoin(JoinStyleToSkiaJoin(aOptions.mLineJoin)); - // XXX: According to the webkit code skia seems to only - // support dash arrays that are multiples of 2. Therefor, - // We need to double the array when % 2 != 0 - MOZ_ASSERT(aOptions.mDashLength % 2 == 0); - if (aOptions.mDashLength > 1) { - std::vector pattern; - pattern.resize(aOptions.mDashLength); - for (uint32_t i = 0; i < aOptions.mDashLength; i++) { - pattern[i] = SkFloatToScalar(aOptions.mDashPattern[i]); + if (aOptions.mDashLength > 0) { + // Skia only supports dash arrays that are multiples of 2. + uint32_t dashCount; + + if (aOptions.mDashLength % 2 == 0) { + dashCount = aOptions.mDashLength; + } else { + dashCount = aOptions.mDashLength * 2; } - - SkDashPathEffect* dash = new SkDashPathEffect(&pattern.front(), - aOptions.mDashLength, + + std::vector pattern; + pattern.resize(dashCount); + + for (uint32_t i = 0; i < dashCount; i++) { + pattern[i] = SkFloatToScalar(aOptions.mDashPattern[i % aOptions.mDashLength]); + } + + SkDashPathEffect* dash = new SkDashPathEffect(&pattern.front(), + dashCount, SkFloatToScalar(aOptions.mDashOffset)); SkSafeUnref(aPaint.setPathEffect(dash)); } + aPaint.setStyle(SkPaint::kStroke_Style); return true; }