Skip to content

Commit

Permalink
Bug 1178159 - Ignore stroke-linecap:"square" on circle and ellipse. r…
Browse files Browse the repository at this point in the history
…=longsonr
  • Loading branch information
kleintom committed Jun 29, 2015
1 parent ad1cf4a commit 4989c72
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 12 deletions.
29 changes: 20 additions & 9 deletions dom/svg/SVGContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,21 @@ SVGContentUtils::GetStrokeOptions(AutoStrokeOptions* aStrokeOptions,
break;
}

switch (styleSVG->mStrokeLinecap) {
case NS_STYLE_STROKE_LINECAP_BUTT:
if (ShapeTypeHasNoCorners(aElement)) {
aStrokeOptions->mLineCap = CapStyle::BUTT;
break;
case NS_STYLE_STROKE_LINECAP_ROUND:
aStrokeOptions->mLineCap = CapStyle::ROUND;
break;
case NS_STYLE_STROKE_LINECAP_SQUARE:
aStrokeOptions->mLineCap = CapStyle::SQUARE;
break;
}
else {
switch (styleSVG->mStrokeLinecap) {
case NS_STYLE_STROKE_LINECAP_BUTT:
aStrokeOptions->mLineCap = CapStyle::BUTT;
break;
case NS_STYLE_STROKE_LINECAP_ROUND:
aStrokeOptions->mLineCap = CapStyle::ROUND;
break;
case NS_STYLE_STROKE_LINECAP_SQUARE:
aStrokeOptions->mLineCap = CapStyle::SQUARE;
break;
}
}
}

Expand Down Expand Up @@ -808,3 +813,9 @@ SVGContentUtils::GetPath(const nsAString& aPathString)

return pathData.BuildPath(builder, NS_STYLE_STROKE_LINECAP_BUTT, 1);
}

bool
SVGContentUtils::ShapeTypeHasNoCorners(const nsIContent* aContent) {
return aContent && aContent->IsAnyOfSVGElements(nsGkAtoms::circle,
nsGkAtoms::ellipse);
}
6 changes: 6 additions & 0 deletions dom/svg/SVGContentUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ class SVGContentUtils
*/
static mozilla::TemporaryRef<mozilla::gfx::Path>
GetPath(const nsAString& aPathString);

/**
* Returns true if aContent is one of the elements whose stroke is guaranteed
* to have no corners: circle or ellipse
*/
static bool ShapeTypeHasNoCorners(const nsIContent* aContent);
};

#endif
1 change: 1 addition & 0 deletions layout/reftests/svg/reftest.list
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ fuzzy-if(cocoaWidget,4,15982) fuzzy-if(winWidget,4,92) == radialGradient-basic-0
== rootElement-null-01.svg pass.svg
== script-empty-01.svg pass.svg
== selector-01.svg pass.svg
== stroke-linecap-circle-ellipse-01.svg stroke-linecap-circle-ellipse-01-ref.svg
== stroke-width-percentage-01.svg pass.svg
== stroke-width-percentage-02a.svg stroke-width-percentage-02-ref.svg
== stroke-width-percentage-02b.svg stroke-width-percentage-02-ref.svg
Expand Down
14 changes: 14 additions & 0 deletions layout/reftests/svg/stroke-linecap-circle-ellipse-01-ref.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions layout/reftests/svg/stroke-linecap-circle-ellipse-01.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion layout/svg/nsSVGPathGeometryFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ nsSVGPathGeometryFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
nsSVGPathGeometryElement* element =
static_cast<nsSVGPathGeometryElement*>(mContent);

if (aOldStyleContext->PeekStyleSVG()) {
if (aOldStyleContext->PeekStyleSVG() &&
!SVGContentUtils::ShapeTypeHasNoCorners(mContent)) {
if ((StyleSVG()->mStrokeLinecap !=
aOldStyleContext->PeekStyleSVG()->mStrokeLinecap) &&
element->IsSVGElement(nsGkAtoms::path)) {
Expand Down
3 changes: 1 addition & 2 deletions layout/svg/nsSVGUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,8 +1197,7 @@ nsSVGUtils::PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
const gfxMatrix& aMatrix)
{
bool strokeMayHaveCorners =
!aFrame->GetContent()->IsAnyOfSVGElements(nsGkAtoms::circle,
nsGkAtoms::ellipse);
!SVGContentUtils::ShapeTypeHasNoCorners(aFrame->GetContent());

// For a shape without corners the stroke can only extend half the stroke
// width from the path in the x/y-axis directions. For shapes with corners
Expand Down

0 comments on commit 4989c72

Please sign in to comment.