Bug 702696 - Path length scale factor should not be affected by the 'transform' attribute. r=dholbert.

This commit is contained in:
Jonathan Watt 2011-11-21 21:22:19 +00:00
parent a5615e40a2
commit efb9f8f776
7 changed files with 62 additions and 12 deletions

View File

@ -427,16 +427,24 @@ nsSVGPathElement::ConstructPath(gfxContext *aCtx)
} }
gfxFloat gfxFloat
nsSVGPathElement::GetPathLengthScale() nsSVGPathElement::GetPathLengthScale(PathLengthScaleForType aFor)
{ {
NS_ABORT_IF_FALSE(aFor == eForTextPath || aFor == eForStroking,
"Unknown enum");
if (mPathLength.IsExplicitlySet()) { if (mPathLength.IsExplicitlySet()) {
float authorsPathLengthEstimate = mPathLength.GetAnimValue();
nsRefPtr<gfxFlattenedPath> flat = if (authorsPathLengthEstimate > 0) {
GetFlattenedPath(PrependLocalTransformTo(gfxMatrix())); gfxMatrix matrix;
float pathLength = mPathLength.GetAnimValue(); if (aFor == eForTextPath) {
// For textPath, a transform on the referenced path affects the
if (flat && pathLength != 0) { // textPath layout, so when calculating the actual path length
return flat->GetLength() / pathLength; // we need to take that into account.
matrix = PrependLocalTransformTo(gfxMatrix());
}
nsRefPtr<gfxFlattenedPath> path = GetFlattenedPath(matrix);
if (path) {
return path->GetLength() / authorsPathLengthEstimate;
}
} }
} }
return 1.0; return 1.0;

View File

@ -98,12 +98,17 @@ public:
return nsGkAtoms::d; return nsGkAtoms::d;
} }
enum PathLengthScaleForType {
eForTextPath,
eForStroking
};
/** /**
* Gets the ratio of the actual path length to the content author's estimated * Gets the ratio of the actual path length to the content author's estimated
* length (as provided by the <path> element's 'pathLength' attribute). This * length (as provided by the <path> element's 'pathLength' attribute). This
* is used to scale stroke dashing, and to scale offsets along a textPath. * is used to scale stroke dashing, and to scale offsets along a textPath.
*/ */
gfxFloat GetPathLengthScale(); gfxFloat GetPathLengthScale(PathLengthScaleForType aFor);
protected: protected:

View File

@ -226,9 +226,11 @@ fails-if(Android) random-if(gtk2Widget) != text-language-01.xhtml text-language-
== text-layout-05.svg text-layout-05-ref.svg == text-layout-05.svg text-layout-05-ref.svg
== text-scale-01.svg text-scale-01-ref.svg == text-scale-01.svg text-scale-01-ref.svg
== text-stroke-scaling-01.svg text-stroke-scaling-01-ref.svg == text-stroke-scaling-01.svg text-stroke-scaling-01-ref.svg
== stroke-dasharray-and-pathLength-01.svg pass.svg
== stroke-linecap-square-w-zero-length-segs-01.svg pass.svg == stroke-linecap-square-w-zero-length-segs-01.svg pass.svg
== stroke-linecap-square-w-zero-length-segs-02.svg pass.svg == stroke-linecap-square-w-zero-length-segs-02.svg pass.svg
== textPath-01.svg textPath-01-ref.svg == textPath-01.svg textPath-01-ref.svg
== textPath-02.svg pass.svg
== text-style-01a.svg text-style-01-ref.svg == text-style-01a.svg text-style-01-ref.svg
== text-style-01b.svg text-style-01-ref.svg == text-style-01b.svg text-style-01-ref.svg
== text-style-01c.svg text-style-01-ref.svg == text-style-01c.svg text-style-01-ref.svg

View File

@ -0,0 +1,20 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg">
<title>Test stroke-dasharray with pathLength and scaling</title>
<rect width="100%" height="100%" fill="lime"/>
<!--
Here we set the 'pathLength' to twice the actual length of the path,
which should cause the stroke-dasharray values to be scaled down by one
half. Visually, this should effectively cancel out the 2x scaling along
the x-axis introduced by the 'transform' attribute.
-->
<path d="M0.5,10 L100.5,10" stroke="red" stroke-width="18" stroke-dasharray="18 22" pathLength="200" transform="scale(2,1)"/>
<rect x="1" y="1" width="18" height="18" fill="lime"/>
<rect x="41" y="1" width="18" height="18" fill="lime"/>
<rect x="81" y="1" width="18" height="18" fill="lime"/>
<rect x="121" y="1" width="18" height="18" fill="lime"/>
<rect x="161" y="1" width="18" height="18" fill="lime"/>
</svg>

After

Width:  |  Height:  |  Size: 995 B

View File

@ -0,0 +1,15 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Test effect on startOffset of a scale transform on a textPath's path</title>
<defs>
<path id="path" d="M20,20 C20,150 150,150 150,20" pathLength="100" transform="scale(2,1)" fill="none" stroke="black"/>
</defs>
<rect width="100%" height="100%" fill="lime"/>
<text y="50">
<textPath xlink:href="#path" font-size="20" fill="red" startOffset="50">FAIL</textPath>
</text>
<rect x="160" y="80" width="100" height="60" fill="lime"/>
</svg>

After

Width:  |  Height:  |  Size: 679 B

View File

@ -120,8 +120,8 @@ nsSVGGeometryFrame::GetStrokeDashArray(gfxFloat **aDashes, PRUint32 *aCount)
gfxFloat pathScale = 1.0; gfxFloat pathScale = 1.0;
if (mContent->Tag() == nsGkAtoms::path) { if (mContent->Tag() == nsGkAtoms::path) {
pathScale = pathScale = static_cast<nsSVGPathElement*>(mContent)->
static_cast<nsSVGPathElement*>(mContent)->GetPathLengthScale(); GetPathLengthScale(nsSVGPathElement::eForStroking);
if (pathScale <= 0) { if (pathScale <= 0) {
return NS_OK; return NS_OK;
} }

View File

@ -177,7 +177,7 @@ nsSVGTextPathFrame::GetOffsetScale()
return 1.0; return 1.0;
return static_cast<nsSVGPathElement*>(pathFrame->GetContent())-> return static_cast<nsSVGPathElement*>(pathFrame->GetContent())->
GetPathLengthScale(); GetPathLengthScale(nsSVGPathElement::eForTextPath);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------