From efb9f8f776cb024cdcc77df69ad7d2c02714bdd7 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Mon, 21 Nov 2011 21:22:19 +0000 Subject: [PATCH] Bug 702696 - Path length scale factor should not be affected by the 'transform' attribute. r=dholbert. --- content/svg/content/src/nsSVGPathElement.cpp | 24 ++++++++++++------- content/svg/content/src/nsSVGPathElement.h | 7 +++++- layout/reftests/svg/reftest.list | 2 ++ .../stroke-dasharray-and-pathLength-01.svg | 20 ++++++++++++++++ layout/reftests/svg/textPath-02.svg | 15 ++++++++++++ layout/svg/base/src/nsSVGGeometryFrame.cpp | 4 ++-- layout/svg/base/src/nsSVGTextPathFrame.cpp | 2 +- 7 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 layout/reftests/svg/stroke-dasharray-and-pathLength-01.svg create mode 100644 layout/reftests/svg/textPath-02.svg diff --git a/content/svg/content/src/nsSVGPathElement.cpp b/content/svg/content/src/nsSVGPathElement.cpp index d0063d50355..9719b23ec35 100644 --- a/content/svg/content/src/nsSVGPathElement.cpp +++ b/content/svg/content/src/nsSVGPathElement.cpp @@ -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 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 path = GetFlattenedPath(matrix); + if (path) { + return path->GetLength() / authorsPathLengthEstimate; + } } } return 1.0; diff --git a/content/svg/content/src/nsSVGPathElement.h b/content/svg/content/src/nsSVGPathElement.h index e5c011d8a7a..40988e5901a 100644 --- a/content/svg/content/src/nsSVGPathElement.h +++ b/content/svg/content/src/nsSVGPathElement.h @@ -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 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: diff --git a/layout/reftests/svg/reftest.list b/layout/reftests/svg/reftest.list index 9c3610ca92e..4d10b5159ee 100644 --- a/layout/reftests/svg/reftest.list +++ b/layout/reftests/svg/reftest.list @@ -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 diff --git a/layout/reftests/svg/stroke-dasharray-and-pathLength-01.svg b/layout/reftests/svg/stroke-dasharray-and-pathLength-01.svg new file mode 100644 index 00000000000..77f5a4d1b3c --- /dev/null +++ b/layout/reftests/svg/stroke-dasharray-and-pathLength-01.svg @@ -0,0 +1,20 @@ + + + Test stroke-dasharray with pathLength and scaling + + + + + + + + + diff --git a/layout/reftests/svg/textPath-02.svg b/layout/reftests/svg/textPath-02.svg new file mode 100644 index 00000000000..c24422a2adf --- /dev/null +++ b/layout/reftests/svg/textPath-02.svg @@ -0,0 +1,15 @@ + + + Test effect on startOffset of a scale transform on a textPath's path + + + + + + FAIL + + + diff --git a/layout/svg/base/src/nsSVGGeometryFrame.cpp b/layout/svg/base/src/nsSVGGeometryFrame.cpp index c40254f66c1..33f6951b152 100644 --- a/layout/svg/base/src/nsSVGGeometryFrame.cpp +++ b/layout/svg/base/src/nsSVGGeometryFrame.cpp @@ -120,8 +120,8 @@ nsSVGGeometryFrame::GetStrokeDashArray(gfxFloat **aDashes, PRUint32 *aCount) gfxFloat pathScale = 1.0; if (mContent->Tag() == nsGkAtoms::path) { - pathScale = - static_cast(mContent)->GetPathLengthScale(); + pathScale = static_cast(mContent)-> + GetPathLengthScale(nsSVGPathElement::eForStroking); if (pathScale <= 0) { return NS_OK; } diff --git a/layout/svg/base/src/nsSVGTextPathFrame.cpp b/layout/svg/base/src/nsSVGTextPathFrame.cpp index eaf00e10841..dcfdf53b39e 100644 --- a/layout/svg/base/src/nsSVGTextPathFrame.cpp +++ b/layout/svg/base/src/nsSVGTextPathFrame.cpp @@ -177,7 +177,7 @@ nsSVGTextPathFrame::GetOffsetScale() return 1.0; return static_cast(pathFrame->GetContent())-> - GetPathLengthScale(); + GetPathLengthScale(nsSVGPathElement::eForTextPath); } //----------------------------------------------------------------------