From 3871c9a943cb9e64abd6efa4d9743d867c3e8142 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Tue, 15 Nov 2011 13:11:43 +0000 Subject: [PATCH] Bug 702477 - Change the names of nsSVGPathElement::GetScale and nsSVGTextPathFrame::GetPathScale, and add documenting comments. r=longsonr. --- content/svg/content/src/nsSVGPathElement.cpp | 2 +- content/svg/content/src/nsSVGPathElement.h | 7 ++++++- layout/svg/base/src/nsSVGGeometryFrame.cpp | 3 ++- layout/svg/base/src/nsSVGGlyphFrame.cpp | 6 +++--- layout/svg/base/src/nsSVGTextPathFrame.cpp | 7 ++++--- layout/svg/base/src/nsSVGTextPathFrame.h | 14 +++++++++++++- 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/content/svg/content/src/nsSVGPathElement.cpp b/content/svg/content/src/nsSVGPathElement.cpp index 8b1e258d173..d0063d50355 100644 --- a/content/svg/content/src/nsSVGPathElement.cpp +++ b/content/svg/content/src/nsSVGPathElement.cpp @@ -427,7 +427,7 @@ nsSVGPathElement::ConstructPath(gfxContext *aCtx) } gfxFloat -nsSVGPathElement::GetScale() +nsSVGPathElement::GetPathLengthScale() { if (mPathLength.IsExplicitlySet()) { diff --git a/content/svg/content/src/nsSVGPathElement.h b/content/svg/content/src/nsSVGPathElement.h index 742f6206000..e5c011d8a7a 100644 --- a/content/svg/content/src/nsSVGPathElement.h +++ b/content/svg/content/src/nsSVGPathElement.h @@ -98,7 +98,12 @@ public: return nsGkAtoms::d; } - gfxFloat GetScale(); + /** + * 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(); protected: diff --git a/layout/svg/base/src/nsSVGGeometryFrame.cpp b/layout/svg/base/src/nsSVGGeometryFrame.cpp index 53d130335b6..c40254f66c1 100644 --- a/layout/svg/base/src/nsSVGGeometryFrame.cpp +++ b/layout/svg/base/src/nsSVGGeometryFrame.cpp @@ -120,7 +120,8 @@ nsSVGGeometryFrame::GetStrokeDashArray(gfxFloat **aDashes, PRUint32 *aCount) gfxFloat pathScale = 1.0; if (mContent->Tag() == nsGkAtoms::path) { - pathScale = static_cast(mContent)->GetScale(); + pathScale = + static_cast(mContent)->GetPathLengthScale(); if (pathScale <= 0) { return NS_OK; } diff --git a/layout/svg/base/src/nsSVGGlyphFrame.cpp b/layout/svg/base/src/nsSVGGlyphFrame.cpp index f661a3c16a6..bc75a44b90f 100644 --- a/layout/svg/base/src/nsSVGGlyphFrame.cpp +++ b/layout/svg/base/src/nsSVGGlyphFrame.cpp @@ -751,7 +751,7 @@ nsSVGGlyphFrame::GetCharacterPositions(nsTArray* aCharacterPo if (!aCharacterPositions->SetLength(strLength)) return false; - gfxFloat pathScale = textPath->GetPathScale(); + gfxFloat pathScale = textPath->GetOffsetScale(); CharacterPosition *cp = aCharacterPositions->Elements(); @@ -877,7 +877,7 @@ nsSVGGlyphFrame::GetSubStringAdvance(PRUint32 aCharnum, gfxFloat pathScale = 1.0; nsSVGTextPathFrame *textPath = FindTextPathParent(); if (textPath) - pathScale = textPath->GetPathScale(); + pathScale = textPath->GetOffsetScale(); if (dxcount > aFragmentChars) dxcount = aFragmentChars; for (PRUint32 i = aCharnum; i < dxcount; i++) { @@ -1101,7 +1101,7 @@ nsSVGGlyphFrame::SetGlyphPosition(gfxPoint *aPosition, bool aForceGlobalTransfor gfxFloat pathScale = 1.0; if (textPath) - pathScale = textPath->GetPathScale(); + pathScale = textPath->GetOffsetScale(); nsTArray dxList, dyList; GetEffectiveDxDy(strLength, dxList, dyList); diff --git a/layout/svg/base/src/nsSVGTextPathFrame.cpp b/layout/svg/base/src/nsSVGTextPathFrame.cpp index e5649d8b7eb..eaf00e10841 100644 --- a/layout/svg/base/src/nsSVGTextPathFrame.cpp +++ b/layout/svg/base/src/nsSVGTextPathFrame.cpp @@ -166,17 +166,18 @@ nsSVGTextPathFrame::GetStartOffset() nsRefPtr data = GetFlattenedPath(); return data ? (val * data->GetLength() / 100.0) : 0.0; } - return val * GetPathScale(); + return val * GetOffsetScale(); } gfxFloat -nsSVGTextPathFrame::GetPathScale() +nsSVGTextPathFrame::GetOffsetScale() { nsIFrame *pathFrame = GetPathFrame(); if (!pathFrame) return 1.0; - return static_cast(pathFrame->GetContent())->GetScale(); + return static_cast(pathFrame->GetContent())-> + GetPathLengthScale(); } //---------------------------------------------------------------------- diff --git a/layout/svg/base/src/nsSVGTextPathFrame.h b/layout/svg/base/src/nsSVGTextPathFrame.h index 992817aebe1..94ce2ae51e7 100644 --- a/layout/svg/base/src/nsSVGTextPathFrame.h +++ b/layout/svg/base/src/nsSVGTextPathFrame.h @@ -84,8 +84,20 @@ public: already_AddRefed GetFlattenedPath(); nsIFrame *GetPathFrame(); + /** + * Gets the scale by which offsets along this textPath must be scaled. This + * scaling is due to the user provided 'pathLength' attribute on the + * element, which is a user provided estimate of the path length. + */ + gfxFloat GetOffsetScale(); + + /** + * Gets the offset from the start of the path at which the first character + * should be positioned. The value returned already takes GetOffsetScale + * into account. + */ gfxFloat GetStartOffset(); - gfxFloat GetPathScale(); + protected: virtual void GetXY(SVGUserUnitList *aX, SVGUserUnitList *aY);