Bug 939534 - Convert the SVG textPath code from gfxPath to Moz2D Path. r=heycam

This commit is contained in:
Jonathan Watt 2013-11-18 09:42:50 +00:00
Родитель 2c9a2472e1
Коммит 60a92735b1
5 изменённых файлов: 24 добавлений и 25 удалений

Просмотреть файл

@ -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<CharacterPosition>* aCharacterPo
if (!aCharacterPositions->SetLength(strLength))
return false;
nsRefPtr<gfxPath> 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<CharacterPosition>* 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;
}

Просмотреть файл

@ -4785,8 +4785,7 @@ nsSVGTextFrame2::DoTextPathLayout()
// Get the path itself.
RefPtr<Path> path = GetTextPath(textPathFrame);
nsRefPtr<gfxPath> 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;

Просмотреть файл

@ -21,7 +21,6 @@ class nsDisplaySVGText;
class nsRenderingContext;
class nsSVGTextFrame2;
class nsTextFrame;
class gfxPath;
typedef nsSVGDisplayContainerFrame nsSVGTextFrame2Base;

Просмотреть файл

@ -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"

Просмотреть файл

@ -17,7 +17,6 @@
#include "nsQueryFrame.h"
#include "nsSVGTSpanFrame.h"
class gfxPath;
class nsIAtom;
class nsIContent;
class nsIFrame;