mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 702696 - Path length scale factor should not be affected by the 'transform' attribute. r=dholbert.
This commit is contained in:
parent
544968ce20
commit
a0715110cb
@ -427,16 +427,24 @@ nsSVGPathElement::ConstructPath(gfxContext *aCtx)
|
||||
}
|
||||
|
||||
gfxFloat
|
||||
nsSVGPathElement::GetPathLengthScale()
|
||||
nsSVGPathElement::GetPathLengthScale(PathLengthScaleForType aFor)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(aFor == eForTextPath || aFor == eForStroking,
|
||||
"Unknown enum");
|
||||
if (mPathLength.IsExplicitlySet()) {
|
||||
|
||||
nsRefPtr<gfxFlattenedPath> flat =
|
||||
GetFlattenedPath(PrependLocalTransformTo(gfxMatrix()));
|
||||
float pathLength = mPathLength.GetAnimValue();
|
||||
|
||||
if (flat && pathLength != 0) {
|
||||
return flat->GetLength() / pathLength;
|
||||
float authorsPathLengthEstimate = mPathLength.GetAnimValue();
|
||||
if (authorsPathLengthEstimate > 0) {
|
||||
gfxMatrix matrix;
|
||||
if (aFor == eForTextPath) {
|
||||
// For textPath, a transform on the referenced path affects the
|
||||
// textPath layout, so when calculating the actual path length
|
||||
// we need to take that into account.
|
||||
matrix = PrependLocalTransformTo(gfxMatrix());
|
||||
}
|
||||
nsRefPtr<gfxFlattenedPath> path = GetFlattenedPath(matrix);
|
||||
if (path) {
|
||||
return path->GetLength() / authorsPathLengthEstimate;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1.0;
|
||||
|
@ -98,12 +98,17 @@ public:
|
||||
return nsGkAtoms::d;
|
||||
}
|
||||
|
||||
enum PathLengthScaleForType {
|
||||
eForTextPath,
|
||||
eForStroking
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
* is used to scale stroke dashing, and to scale offsets along a textPath.
|
||||
*/
|
||||
gfxFloat GetPathLengthScale();
|
||||
gfxFloat GetPathLengthScale(PathLengthScaleForType aFor);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -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-scale-01.svg text-scale-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-02.svg pass.svg
|
||||
== textPath-01.svg textPath-01-ref.svg
|
||||
== textPath-02.svg pass.svg
|
||||
== text-style-01a.svg text-style-01-ref.svg
|
||||
== text-style-01b.svg text-style-01-ref.svg
|
||||
== text-style-01c.svg text-style-01-ref.svg
|
||||
|
20
layout/reftests/svg/stroke-dasharray-and-pathLength-01.svg
Normal file
20
layout/reftests/svg/stroke-dasharray-and-pathLength-01.svg
Normal 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 |
15
layout/reftests/svg/textPath-02.svg
Normal file
15
layout/reftests/svg/textPath-02.svg
Normal 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 |
@ -120,8 +120,8 @@ nsSVGGeometryFrame::GetStrokeDashArray(gfxFloat **aDashes, PRUint32 *aCount)
|
||||
gfxFloat pathScale = 1.0;
|
||||
|
||||
if (mContent->Tag() == nsGkAtoms::path) {
|
||||
pathScale =
|
||||
static_cast<nsSVGPathElement*>(mContent)->GetPathLengthScale();
|
||||
pathScale = static_cast<nsSVGPathElement*>(mContent)->
|
||||
GetPathLengthScale(nsSVGPathElement::eForStroking);
|
||||
if (pathScale <= 0) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ nsSVGTextPathFrame::GetOffsetScale()
|
||||
return 1.0;
|
||||
|
||||
return static_cast<nsSVGPathElement*>(pathFrame->GetContent())->
|
||||
GetPathLengthScale();
|
||||
GetPathLengthScale(nsSVGPathElement::eForTextPath);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user