From 60a92735b124e06e4a547d20c2f91b0077020c0e Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Mon, 18 Nov 2013 09:42:50 +0000 Subject: [PATCH] Bug 939534 - Convert the SVG textPath code from gfxPath to Moz2D Path. r=heycam --- layout/svg/nsSVGGlyphFrame.cpp | 24 ++++++++++++------------ layout/svg/nsSVGTextFrame2.cpp | 22 ++++++++++++---------- layout/svg/nsSVGTextFrame2.h | 1 - layout/svg/nsSVGTextPathFrame.cpp | 1 - layout/svg/nsSVGTextPathFrame.h | 1 - 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/layout/svg/nsSVGGlyphFrame.cpp b/layout/svg/nsSVGGlyphFrame.cpp index b7be64397708..f783370d8fae 100644 --- a/layout/svg/nsSVGGlyphFrame.cpp +++ b/layout/svg/nsSVGGlyphFrame.cpp @@ -9,6 +9,7 @@ // Keep others in (case-insensitive) order: #include "DOMSVGPoint.h" +#include "gfx2DGlue.h" #include "gfxContext.h" #include "gfxMatrix.h" #include "gfxPlatform.h" @@ -22,6 +23,7 @@ #include "nsSVGIntegrationUtils.h" #include "nsSVGPaintServerFrame.h" #include "mozilla/dom/SVGRect.h" +#include "mozilla/gfx/2D.h" #include "nsSVGTextPathFrame.h" #include "nsSVGUtils.h" #include "nsTextFragment.h" @@ -750,13 +752,11 @@ nsSVGGlyphFrame::GetCharacterPositions(nsTArray* aCharacterPo if (!aCharacterPositions->SetLength(strLength)) return false; - nsRefPtr data = new gfxPath(path); - gfxFloat pathScale = textPath->GetOffsetScale(); CharacterPosition *cp = aCharacterPositions->Elements(); - gfxFloat length = data->GetLength(); + Float length = path->ComputeLength(); for (uint32_t i = 0; i < strLength; i++) { gfxFloat halfAdvance = @@ -777,15 +777,15 @@ nsSVGGlyphFrame::GetCharacterPositions(nsTArray* aCharacterPo pos.x + halfAdvance <= length); if (cp[i].draw) { - - // add y (normal) - // add rotation - // move point back along tangent - gfxPoint pt = data->FindPoint(gfxPoint(pos.x + halfAdvance, pos.y), - &(cp[i].angle)); - cp[i].pos = - pt - gfxPoint(cos(cp[i].angle), sin(cp[i].angle)) * halfAdvance; - cp[i].angle += angle; + Point tangent; // Unit vector tangent to the point we find. + Point pt = path->ComputePointAtLength(Float(pos.x + halfAdvance), + &tangent); + Point normal(-tangent.y, tangent.x); // Unit vector normal to the point. + Point offsetFromPath = normal * pos.y; + cp[i].pos = ThebesPoint(pt + offsetFromPath) - + ThebesPoint(tangent) * halfAdvance; + double glyphRotation = atan2(tangent.y, tangent.x); + cp[i].angle = glyphRotation + angle; } pos.x += 2 * halfAdvance; } diff --git a/layout/svg/nsSVGTextFrame2.cpp b/layout/svg/nsSVGTextFrame2.cpp index f4e99f29cf5b..41e859f84cb1 100644 --- a/layout/svg/nsSVGTextFrame2.cpp +++ b/layout/svg/nsSVGTextFrame2.cpp @@ -4785,8 +4785,7 @@ nsSVGTextFrame2::DoTextPathLayout() // Get the path itself. RefPtr path = GetTextPath(textPathFrame); - nsRefPtr data = new gfxPath(path); - if (!data) { + if (!path) { it.AdvancePastCurrentTextPathFrame(); continue; } @@ -4794,7 +4793,7 @@ nsSVGTextFrame2::DoTextPathLayout() nsIContent* textPath = textPathFrame->GetContent(); gfxFloat offset = GetStartOffset(textPathFrame); - gfxFloat pathLength = data->GetLength(); + Float pathLength = path->ComputeLength(); // Loop for each text frame in the text path. do { @@ -4808,19 +4807,22 @@ nsSVGTextFrame2::DoTextPathLayout() mPositions[i].mHidden = midx < 0 || midx > pathLength; // Position the character on the path at the right angle. - double angle; - gfxPoint pt = - data->FindPoint(gfxPoint(midx, mPositions[i].mPosition.y), &angle); - gfxPoint direction = gfxPoint(cos(angle), sin(angle)) * sign; - mPositions[i].mPosition = pt - direction * halfAdvance; - mPositions[i].mAngle += angle; + Point tangent; // Unit vector tangent to the point we find. + Point pt = path->ComputePointAtLength(Float(midx), &tangent); + double glyphRotation = atan2(tangent.y, tangent.x); + Point normal(-tangent.y, tangent.x); // Unit vector normal to the point. + Point offsetFromPath = normal * mPositions[i].mPosition.y; + pt += offsetFromPath; + Point direction = tangent * sign; + mPositions[i].mPosition = ThebesPoint(pt) - ThebesPoint(direction) * halfAdvance; + mPositions[i].mAngle += glyphRotation; // Position any characters for a partial ligature. for (uint32_t j = i + 1; j < mPositions.Length() && mPositions[j].mClusterOrLigatureGroupMiddle; j++) { gfxPoint partialAdvance = - direction * it.GetGlyphPartialAdvance(j - i, context) / + ThebesPoint(direction) * it.GetGlyphPartialAdvance(j - i, context) / mFontSizeScaleFactor; mPositions[j].mPosition = mPositions[i].mPosition + partialAdvance; mPositions[j].mAngle = mPositions[i].mAngle; diff --git a/layout/svg/nsSVGTextFrame2.h b/layout/svg/nsSVGTextFrame2.h index 5b24b265f7c6..319bed47d59b 100644 --- a/layout/svg/nsSVGTextFrame2.h +++ b/layout/svg/nsSVGTextFrame2.h @@ -21,7 +21,6 @@ class nsDisplaySVGText; class nsRenderingContext; class nsSVGTextFrame2; class nsTextFrame; -class gfxPath; typedef nsSVGDisplayContainerFrame nsSVGTextFrame2Base; diff --git a/layout/svg/nsSVGTextPathFrame.cpp b/layout/svg/nsSVGTextPathFrame.cpp index c80f77d4c3a7..1712f068c2de 100644 --- a/layout/svg/nsSVGTextPathFrame.cpp +++ b/layout/svg/nsSVGTextPathFrame.cpp @@ -8,7 +8,6 @@ // Keep others in (case-insensitive) order: #include "gfx2DGlue.h" -#include "gfxPath.h" #include "nsContentUtils.h" #include "nsSVGEffects.h" #include "nsSVGLength2.h" diff --git a/layout/svg/nsSVGTextPathFrame.h b/layout/svg/nsSVGTextPathFrame.h index f3b9d196fe59..9876643bf844 100644 --- a/layout/svg/nsSVGTextPathFrame.h +++ b/layout/svg/nsSVGTextPathFrame.h @@ -17,7 +17,6 @@ #include "nsQueryFrame.h" #include "nsSVGTSpanFrame.h" -class gfxPath; class nsIAtom; class nsIContent; class nsIFrame;