Bug 342301 - nsSVGPathGeometryElement::GetMarkPoints should take nsTArray.

r+sr=roc
This commit is contained in:
tor%cs.brown.edu 2006-06-21 19:35:59 +00:00
Родитель 2fb93b9130
Коммит 967aaf6f53
8 изменённых файлов: 44 добавлений и 60 удалений

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

@ -67,7 +67,7 @@ public:
// nsSVGPathGeometryElement methods: // nsSVGPathGeometryElement methods:
virtual PRBool IsMarkable() { return PR_TRUE; } virtual PRBool IsMarkable() { return PR_TRUE; }
virtual void GetMarkPoints(nsVoidArray *aMarks); virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks);
virtual void ConstructPath(cairo_t *aCtx); virtual void ConstructPath(cairo_t *aCtx);
protected: protected:
@ -171,23 +171,15 @@ nsSVGLineElement::GetLengthInfo()
// nsSVGPathGeometryElement methods // nsSVGPathGeometryElement methods
void void
nsSVGLineElement::GetMarkPoints(nsVoidArray *aMarks) { nsSVGLineElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks) {
float x1, y1, x2, y2; float x1, y1, x2, y2;
GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nsnull); GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nsnull);
nsSVGMark *m1, *m2; float angle = atan2(y2 - y1, x2 - x1);
m1 = new nsSVGMark();
m2 = new nsSVGMark();
m1->x = x1; aMarks->AppendElement(nsSVGMark(x1, y1, angle));
m1->y = y1; aMarks->AppendElement(nsSVGMark(x2, y2, angle));
m2->x = x2;
m2->y = y2;
m1->angle = m2->angle = atan2(y2 - y1, x2 - x1);
aMarks->AppendElement(m1);
aMarks->AppendElement(m2);
} }
void void

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

@ -433,7 +433,7 @@ CalcVectorAngle(double ux, double uy, double vx, double vy)
} }
void void
nsSVGPathElement::GetMarkPoints(nsVoidArray *aMarks) { nsSVGPathElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks) {
if (NS_FAILED(CreatePathSegList())) if (NS_FAILED(CreatePathSegList()))
return; return;
@ -841,37 +841,34 @@ nsSVGPathElement::GetMarkPoints(nsVoidArray *aMarks) {
if (newSegment && if (newSegment &&
type != nsIDOMSVGPathSeg::PATHSEG_MOVETO_ABS && type != nsIDOMSVGPathSeg::PATHSEG_MOVETO_ABS &&
type != nsIDOMSVGPathSeg::PATHSEG_MOVETO_REL) { type != nsIDOMSVGPathSeg::PATHSEG_MOVETO_REL) {
pathIndex = aMarks->Count() - 1; pathIndex = aMarks->Length() - 1;
pathAngle = startAngle; pathAngle = startAngle;
((nsSVGMark *)aMarks->ElementAt(aMarks->Count()-1))->angle = pathAngle; aMarks->ElementAt(pathIndex).angle = pathAngle;
newSegment = PR_FALSE; newSegment = PR_FALSE;
prevAngle = endAngle; prevAngle = endAngle;
} else if (type == nsIDOMSVGPathSeg::PATHSEG_MOVETO_ABS || } else if (type == nsIDOMSVGPathSeg::PATHSEG_MOVETO_ABS ||
type == nsIDOMSVGPathSeg::PATHSEG_MOVETO_REL) { type == nsIDOMSVGPathSeg::PATHSEG_MOVETO_REL) {
if (aMarks->Count()) if (aMarks->Length())
((nsSVGMark *)aMarks->ElementAt(aMarks->Count()-1))->angle = prevAngle; aMarks->ElementAt(aMarks->Length() - 1).angle = prevAngle;
} else { } else {
((nsSVGMark *)aMarks->ElementAt(aMarks->Count()-1))->angle = aMarks->ElementAt(aMarks->Length() - 1).angle =
nsSVGUtils::AngleBisect(prevAngle, startAngle); nsSVGUtils::AngleBisect(prevAngle, startAngle);
prevAngle = endAngle; prevAngle = endAngle;
} }
nsSVGMark *mark = new nsSVGMark; aMarks->AppendElement(nsSVGMark(x, y, 0));
mark->x = x;
mark->y = y;
aMarks->AppendElement(mark);
if (type == nsIDOMSVGPathSeg::PATHSEG_CLOSEPATH) { if (type == nsIDOMSVGPathSeg::PATHSEG_CLOSEPATH) {
prevAngle = nsSVGUtils::AngleBisect(endAngle, pathAngle); prevAngle = nsSVGUtils::AngleBisect(endAngle, pathAngle);
((nsSVGMark *)aMarks->ElementAt(pathIndex))->angle = prevAngle; aMarks->ElementAt(pathIndex).angle = prevAngle;
} }
cx = x; cx = x;
cy = y; cy = y;
} }
if (aMarks->Count()) if (aMarks->Length())
((nsSVGMark *)aMarks->ElementAt(aMarks->Count()-1))->angle = prevAngle; aMarks->ElementAt(aMarks->Length() - 1).angle = prevAngle;
} }

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

@ -116,7 +116,7 @@ public:
// nsSVGPathGeometryElement methods: // nsSVGPathGeometryElement methods:
virtual PRBool IsDependentAttribute(nsIAtom *aName); virtual PRBool IsDependentAttribute(nsIAtom *aName);
virtual PRBool IsMarkable(); virtual PRBool IsMarkable();
virtual void GetMarkPoints(nsVoidArray *aMarks); virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks);
virtual void ConstructPath(cairo_t *aCtx); virtual void ConstructPath(cairo_t *aCtx);
nsSVGFlattenedPath *GetFlattenedPath(); nsSVGFlattenedPath *GetFlattenedPath();

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

@ -62,6 +62,6 @@ nsSVGPathGeometryElement::IsMarkable()
} }
void void
nsSVGPathGeometryElement::GetMarkPoints(nsVoidArray *aMarks) nsSVGPathGeometryElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
{ {
} }

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

@ -38,10 +38,13 @@
#define __NS_SVGPATHGEOMETRYELEMENT_H__ #define __NS_SVGPATHGEOMETRYELEMENT_H__
#include "nsSVGGraphicElement.h" #include "nsSVGGraphicElement.h"
#include "nsTArray.h"
#include "cairo.h" #include "cairo.h"
struct nsSVGMark { struct nsSVGMark {
float x, y, angle; float x, y, angle;
nsSVGMark(float aX, float aY, float aAngle) :
x(aX), y(aY), angle(aAngle) {}
}; };
typedef nsSVGGraphicElement nsSVGPathGeometryElementBase; typedef nsSVGGraphicElement nsSVGPathGeometryElementBase;
@ -53,7 +56,7 @@ public:
virtual PRBool IsDependentAttribute(nsIAtom *aName); virtual PRBool IsDependentAttribute(nsIAtom *aName);
virtual PRBool IsMarkable(); virtual PRBool IsMarkable();
virtual void GetMarkPoints(nsVoidArray *aMarks); virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks);
virtual void ConstructPath(cairo_t *aCtx) = 0; virtual void ConstructPath(cairo_t *aCtx) = 0;
}; };

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

@ -75,7 +75,7 @@ public:
// nsSVGPathGeometryElement methods: // nsSVGPathGeometryElement methods:
virtual PRBool IsDependentAttribute(nsIAtom *aName); virtual PRBool IsDependentAttribute(nsIAtom *aName);
virtual PRBool IsMarkable() { return PR_TRUE; } virtual PRBool IsMarkable() { return PR_TRUE; }
virtual void GetMarkPoints(nsVoidArray *aMarks); virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks);
virtual void ConstructPath(cairo_t *aCtx); virtual void ConstructPath(cairo_t *aCtx);
protected: protected:
@ -181,7 +181,7 @@ nsSVGPolygonElement::IsDependentAttribute(nsIAtom *aName)
} }
void void
nsSVGPolygonElement::GetMarkPoints(nsVoidArray *aMarks) nsSVGPolygonElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
{ {
if (!mPoints) if (!mPoints)
return; return;
@ -205,14 +205,10 @@ nsSVGPolygonElement::GetMarkPoints(nsVoidArray *aMarks)
if (i == 1) if (i == 1)
startAngle = angle; startAngle = angle;
else if (i > 1) else if (i > 1)
((nsSVGMark *)aMarks->ElementAt(aMarks->Count()-1))->angle = aMarks->ElementAt(aMarks->Length() - 1).angle =
nsSVGUtils::AngleBisect(prevAngle, angle); nsSVGUtils::AngleBisect(prevAngle, angle);
nsSVGMark *mark; aMarks->AppendElement(nsSVGMark(x, y, 0));
mark = new nsSVGMark;
mark->x = x;
mark->y = y;
aMarks->AppendElement(mark);
prevAngle = angle; prevAngle = angle;
px = x; px = x;
@ -225,9 +221,9 @@ nsSVGPolygonElement::GetMarkPoints(nsVoidArray *aMarks)
point->GetY(&ny); point->GetY(&ny);
angle = atan2(ny - py, nx - px); angle = atan2(ny - py, nx - px);
((nsSVGMark *)aMarks->ElementAt(aMarks->Count()-1))->angle = aMarks->ElementAt(aMarks->Length() - 1).angle =
nsSVGUtils::AngleBisect(prevAngle, angle); nsSVGUtils::AngleBisect(prevAngle, angle);
((nsSVGMark *)aMarks->ElementAt(0))->angle = aMarks->ElementAt(0).angle =
nsSVGUtils::AngleBisect(angle, startAngle); nsSVGUtils::AngleBisect(angle, startAngle);
} }

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

@ -75,7 +75,7 @@ public:
// nsSVGPathGeometryElement methods: // nsSVGPathGeometryElement methods:
virtual PRBool IsDependentAttribute(nsIAtom *aName); virtual PRBool IsDependentAttribute(nsIAtom *aName);
virtual PRBool IsMarkable() { return PR_TRUE; } virtual PRBool IsMarkable() { return PR_TRUE; }
virtual void GetMarkPoints(nsVoidArray *aMarks); virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks);
virtual void ConstructPath(cairo_t *aCtx); virtual void ConstructPath(cairo_t *aCtx);
protected: protected:
@ -181,7 +181,7 @@ nsSVGPolylineElement::IsDependentAttribute(nsIAtom *aName)
} }
void void
nsSVGPolylineElement::GetMarkPoints(nsVoidArray *aMarks) nsSVGPolylineElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
{ {
if (!mPoints) if (!mPoints)
return; return;
@ -203,23 +203,19 @@ nsSVGPolylineElement::GetMarkPoints(nsVoidArray *aMarks)
float angle = atan2(y-py, x-px); float angle = atan2(y-py, x-px);
if (i == 1) if (i == 1)
((nsSVGMark *)aMarks->ElementAt(aMarks->Count()-1))->angle = angle; aMarks->ElementAt(aMarks->Length() - 1).angle = angle;
else if (i > 1) else if (i > 1)
((nsSVGMark *)aMarks->ElementAt(aMarks->Count()-1))->angle = aMarks->ElementAt(aMarks->Length() - 1).angle =
nsSVGUtils::AngleBisect(prevAngle, angle); nsSVGUtils::AngleBisect(prevAngle, angle);
nsSVGMark *mark; aMarks->AppendElement(nsSVGMark(x, y, 0));
mark = new nsSVGMark;
mark->x = x;
mark->y = y;
aMarks->AppendElement(mark);
prevAngle = angle; prevAngle = angle;
px = x; px = x;
py = y; py = y;
} }
((nsSVGMark *)aMarks->ElementAt(aMarks->Count()-1))->angle = prevAngle; aMarks->ElementAt(aMarks->Length() - 1).angle = prevAngle;
} }
void void

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

@ -296,24 +296,24 @@ nsSVGPathGeometryFrame::PaintSVG(nsISVGRendererCanvas* canvas)
property->mMarkerStart)) { property->mMarkerStart)) {
float strokeWidth = GetStrokeWidth(); float strokeWidth = GetStrokeWidth();
nsVoidArray marks; nsTArray<nsSVGMark> marks;
NS_STATIC_CAST(nsSVGPathGeometryElement*, NS_STATIC_CAST(nsSVGPathGeometryElement*,
mContent)->GetMarkPoints(&marks); mContent)->GetMarkPoints(&marks);
PRUint32 num = marks.Count(); PRUint32 num = marks.Length();
if (num && property->mMarkerStart) if (num && property->mMarkerStart)
property->mMarkerStart->PaintMark(canvas, this, property->mMarkerStart->PaintMark(canvas, this,
(nsSVGMark *)marks[0], strokeWidth); &marks[0], strokeWidth);
if (num && property->mMarkerMid) if (num && property->mMarkerMid)
for (PRUint32 i = 1; i < num - 1; i++) for (PRUint32 i = 1; i < num - 1; i++)
property->mMarkerMid->PaintMark(canvas, this, property->mMarkerMid->PaintMark(canvas, this,
(nsSVGMark *)marks[i], strokeWidth); &marks[i], strokeWidth);
if (num && property->mMarkerEnd) if (num && property->mMarkerEnd)
property->mMarkerEnd->PaintMark(canvas, this, property->mMarkerEnd->PaintMark(canvas, this,
(nsSVGMark *)marks[num-1], strokeWidth); &marks[num-1], strokeWidth);
} }
} }
@ -374,15 +374,15 @@ nsSVGPathGeometryFrame::GetCoveredRegion()
float strokeWidth = GetStrokeWidth(); float strokeWidth = GetStrokeWidth();
nsVoidArray marks; nsTArray<nsSVGMark> marks;
NS_STATIC_CAST(nsSVGPathGeometryElement*, mContent)->GetMarkPoints(&marks); NS_STATIC_CAST(nsSVGPathGeometryElement*, mContent)->GetMarkPoints(&marks);
PRUint32 num = marks.Count(); PRUint32 num = marks.Length();
if (num && property->mMarkerStart) { if (num && property->mMarkerStart) {
nsRect mark; nsRect mark;
mark = property->mMarkerStart->RegionMark(this, mark = property->mMarkerStart->RegionMark(this,
(nsSVGMark *)marks[0], &marks[0],
strokeWidth); strokeWidth);
rect.UnionRect(rect, mark); rect.UnionRect(rect, mark);
} }
@ -391,7 +391,7 @@ nsSVGPathGeometryFrame::GetCoveredRegion()
for (PRUint32 i = 1; i < num - 1; i++) { for (PRUint32 i = 1; i < num - 1; i++) {
nsRect mark; nsRect mark;
mark = property->mMarkerMid->RegionMark(this, mark = property->mMarkerMid->RegionMark(this,
(nsSVGMark *)marks[i], &marks[i],
strokeWidth); strokeWidth);
rect.UnionRect(rect, mark); rect.UnionRect(rect, mark);
} }
@ -399,7 +399,7 @@ nsSVGPathGeometryFrame::GetCoveredRegion()
if (num && property->mMarkerEnd) { if (num && property->mMarkerEnd) {
nsRect mark; nsRect mark;
mark = property->mMarkerEnd->RegionMark(this, mark = property->mMarkerEnd->RegionMark(this,
(nsSVGMark *)marks[num-1], &marks[num-1],
strokeWidth); strokeWidth);
rect.UnionRect(rect, mark); rect.UnionRect(rect, mark);