Bug 1117514 - lines with zero length dashes are not rendered. r=jwatt
--- a/dom/svg/SVGContentUtils.cpp
+++ b/dom/svg/SVGContentUtils.cpp
@@ -133,22 +133,34 @@ GetStrokeDashData(SVGContentUtils::AutoS
// When deciding whether to return eNoStroke or eContinuousStroke below we
// need to take into account that in the repeat pattern the dashes become
// gaps, and the gaps become dashes.
Float origTotalLengthOfDashes = totalLengthOfDashes;
totalLengthOfDashes += totalLengthOfGaps;
totalLengthOfGaps += origTotalLengthOfDashes;
}
- if (totalLengthOfDashes <= 0 || totalLengthOfGaps <= 0) {
- if (totalLengthOfGaps > 0 && totalLengthOfDashes <= 0) {
- return eNoStroke;
- }
+ // Stroking using dashes is much slower than stroking a continuous line
+ // (see bug 609361 comment 40), and much, much slower than not stroking the
+ // line at all. Here we check for cases when the dash pattern causes the
+ // stroke to essentially be continuous or to be nonexistent in which case
+ // we can avoid expensive stroking operations (the underlying platform
+ // graphics libraries don't seem to optimize for this).
+ if (totalLengthOfDashes <= 0 && totalLengthOfGaps <= 0) {
+ return eNoStroke;
+ }
+ if (totalLengthOfGaps <= 0) {
return eContinuousStroke;
}
+ // We can only return eNoStroke if the value of stroke-linecap isn't
+ // adding caps to zero length dashes.
+ if (totalLengthOfDashes <= 0 &&
+ aStyleSVG->mStrokeLinecap == NS_STYLE_STROKE_LINECAP_BUTT) {
+ return eNoStroke;
+ }
if (aContextPaint && aStyleSVG->mStrokeDashoffsetFromObject) {
aStrokeOptions->mDashOffset = Float(aContextPaint->GetStrokeDashOffset());
} else {
aStrokeOptions->mDashOffset =
SVGContentUtils::CoordToFloat(aElement, aStyleSVG->mStrokeDashoffset);
}
--- a/layout/reftests/svg/stroke-linecap-round-w-zero-length-segs-01.svg
+++ b/layout/reftests/svg/stroke-linecap-round-w-zero-length-segs-01.svg
@@ -139,9 +139,17 @@ path.coverer {
<!-- Column 4: test lone movetos -->
<g transform="translate(425,25)">
<path class="circles-not-expected" d="M0,0 M0,0 M20,20 L30,30 M50,50 M50,50 M70,70 L80,80 M100,100 M100,100"/>
<path class="coverer" d="M20,20 L30,30 M70,70 L80,80"/>
</g>
+ <!-- Column 5: test stroke-dasharray -->
+
+ <g transform="translate(525,25)">
+ <circle cy="0" r="8"/>
+ <circle cy="40" r="8"/>
+ <circle cy="80" r="8"/>
+ <path class="circles-expected" d="M0,0v81" stroke-dasharray="0 40" />
+ </g>
</svg>