Bug 1075399, part 1 - Simulate zero length SVG subpath for stroke-linecap=round. r=longsonr
authorJonathan Watt <jwatt@jwatt.org>
Fri, 03 Oct 2014 09:50:42 +0100
changeset 208551 70d8b88af2a6fd10e2c8e0eb240dc5685a152b88
parent 208550 0ffdd0092d9b617c33d3cfeb661c863baa5112b7
child 208552 8f7fc1fdc6e42750fa16d772541425f745f4ac8a
push idunknown
push userunknown
push dateunknown
reviewerslongsonr
bugs1075399
milestone35.0a1
Bug 1075399, part 1 - Simulate zero length SVG subpath for stroke-linecap=round. r=longsonr
content/svg/content/src/SVGPathData.cpp
content/svg/content/src/SVGPathElement.cpp
layout/reftests/svg/path-01-ref.svg
layout/reftests/svg/reftest.list
--- a/content/svg/content/src/SVGPathData.cpp
+++ b/content/svg/content/src/SVGPathData.cpp
@@ -255,17 +255,17 @@ ApproximateZeroLengthSubpathSquareCaps(P
   // not to.
   MOZ_ASSERT(aStrokeWidth > 0.0f,
              "Make the caller check for this, or check it here");
 
   // The fraction of the stroke width that we choose for the length of the
   // line is rather arbitrary, other than being chosen to meet the requirements
   // described in the comment above.
 
-  Float tinyLength = aStrokeWidth / 32;
+  Float tinyLength = aStrokeWidth / 512;
 
   aPB->MoveTo(aPoint);
   aPB->LineTo(aPoint + Point(tinyLength, 0));
   aPB->MoveTo(aPoint);
 }
 
 static void
 ApproximateZeroLengthSubpathSquareCaps(const gfxPoint &aPoint, gfxContext *aCtx)
@@ -279,17 +279,17 @@ ApproximateZeroLengthSubpathSquareCaps(c
 
   aCtx->MoveTo(aPoint);
   aCtx->LineTo(aPoint + gfxPoint(tinyAdvance.width, tinyAdvance.height));
   aCtx->MoveTo(aPoint);
 }
 
 #define MAYBE_APPROXIMATE_ZERO_LENGTH_SUBPATH_SQUARE_CAPS_TO_DT               \
   do {                                                                        \
-    if (capsAreSquare && !subpathHasLength && aStrokeWidth > 0 &&             \
+    if (!subpathHasLength && hasLineCaps && aStrokeWidth > 0 &&               \
         subpathContainsNonArc && SVGPathSegUtils::IsValidType(prevSegType) && \
         (!IsMoveto(prevSegType) || segType == PATHSEG_CLOSEPATH)) {           \
       ApproximateZeroLengthSubpathSquareCaps(builder, segStart, aStrokeWidth);\
     }                                                                         \
   } while(0)
 
 #define MAYBE_APPROXIMATE_ZERO_LENGTH_SUBPATH_SQUARE_CAPS                     \
   do {                                                                        \
@@ -305,17 +305,17 @@ TemporaryRef<Path>
 SVGPathData::BuildPath(PathBuilder* builder,
                        uint8_t aStrokeLineCap,
                        Float aStrokeWidth) const
 {
   if (mData.IsEmpty() || !IsMoveto(SVGPathSegUtils::DecodeType(mData[0]))) {
     return nullptr; // paths without an initial moveto are invalid
   }
 
-  bool capsAreSquare = aStrokeLineCap == NS_STYLE_STROKE_LINECAP_SQUARE;
+  bool hasLineCaps = aStrokeLineCap != NS_STYLE_STROKE_LINECAP_BUTT;
   bool subpathHasLength = false;  // visual length
   bool subpathContainsNonArc = false;
 
   uint32_t segType     = PATHSEG_UNKNOWN;
   uint32_t prevSegType = PATHSEG_UNKNOWN;
   Point pathStart(0.0, 0.0); // start point of [sub]path
   Point segStart(0.0, 0.0);
   Point segEnd;
--- a/content/svg/content/src/SVGPathElement.cpp
+++ b/content/svg/content/src/SVGPathElement.cpp
@@ -387,17 +387,17 @@ SVGPathElement::BuildPath(PathBuilder* a
   nsRefPtr<nsStyleContext> styleContext =
     nsComputedDOMStyle::GetStyleContextForElementNoFlush(this, nullptr, nullptr);
   if (styleContext) {
     const nsStyleSVG* style = styleContext->StyleSVG();
     // Note: the path that we return may be used for hit-testing, and SVG
     // exposes hit-testing of strokes that are not actually painted. For that
     // reason we do not check for eStyleSVGPaintType_None or check the stroke
     // opacity here.
-    if (style->mStrokeLinecap == NS_STYLE_STROKE_LINECAP_SQUARE) {
+    if (style->mStrokeLinecap != NS_STYLE_STROKE_LINECAP_BUTT) {
       strokeLineCap = style->mStrokeLinecap;
       strokeWidth = SVGContentUtils::GetStrokeWidth(this, styleContext, nullptr);
     }
   }
 
   RefPtr<PathBuilder> builder;
   if (aBuilder) {
     builder = aBuilder;
--- a/layout/reftests/svg/path-01-ref.svg
+++ b/layout/reftests/svg/path-01-ref.svg
@@ -2,10 +2,10 @@
      Any copyright is dedicated to the Public Domain.
      http://creativecommons.org/publicdomain/zero/1.0/
 -->
 <svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">
   <title>Reference for path consisting of a single point</title>
 
   <!-- From https://bugzilla.mozilla.org/show_bug.cgi?id=510177 -->
 
-  <circle cx="100" cy="100" r="0.00001" stroke="black" stroke-width="20" stroke-linecap="round"/>
+  <circle cx="100" cy="100" r="10" fill="black"/>
 </svg>
--- a/layout/reftests/svg/reftest.list
+++ b/layout/reftests/svg/reftest.list
@@ -236,17 +236,17 @@ fuzzy-if(Android&&AndroidVersion>=15,8,2
 == overflow-on-outer-svg-02b.xhtml overflow-on-outer-svg-02-ref.xhtml
 == overflow-on-outer-svg-02c.xhtml overflow-on-outer-svg-02-ref.xhtml
 == overflow-on-outer-svg-02d.xhtml overflow-on-outer-svg-02-ref.xhtml
 == overflow-on-outer-svg-03a.xhtml overflow-on-outer-svg-03-ref.xhtml
 == overflow-on-outer-svg-03b.xhtml overflow-on-outer-svg-03-ref.xhtml
 pref(svg.paint-order.enabled,true) == paint-order-01.svg paint-order-01-ref.svg
 pref(svg.paint-order.enabled,true) == paint-order-02.svg paint-order-02-ref.svg
 pref(svg.paint-order.enabled,true) == paint-order-03.svg paint-order-03-ref.svg
-fuzzy-if(azureQuartz,6,47) == path-01.svg path-01-ref.svg
+fuzzy(23,60) fails-if(d2d) == path-01.svg path-01-ref.svg
 == path-02.svg pass.svg
 == path-03.svg pass.svg
 == path-04.svg pass.svg
 == path-05.svg pass.svg
 == path-06.svg path-06-ref.svg
 == path-07.svg path-07-ref.svg
 == path-08.svg pass.svg
 == pathLength-01.svg pass.svg