Bug 740963 - [Skia] Handle non-multiple-of-two dash lengths in HelpersSkia::StrokeOptionsToPaint(). r=jrmuizel

This commit is contained in:
George Wright 2012-03-30 17:36:34 -04:00
parent 3fb5bf234f
commit b8f758f5bc

View File

@ -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) {
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;
}
std::vector<SkScalar> pattern;
pattern.resize(aOptions.mDashLength);
for (uint32_t i = 0; i < aOptions.mDashLength; i++) {
pattern[i] = SkFloatToScalar(aOptions.mDashPattern[i]);
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(),
aOptions.mDashLength,
dashCount,
SkFloatToScalar(aOptions.mDashOffset));
SkSafeUnref(aPaint.setPathEffect(dash));
}
aPaint.setStyle(SkPaint::kStroke_Style);
return true;
}