Bug 1099197 - Determine the bounds of unstroked polylines/polygons directly. r=jwatt

This commit is contained in:
Robert Longson 2014-11-24 14:28:58 +00:00
parent 9a5408ffa8
commit 687a879b40
3 changed files with 54 additions and 0 deletions

View File

@ -119,3 +119,38 @@ nsSVGPolyElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
aMarks->LastElement().angle = prevAngle;
aMarks->LastElement().type = nsSVGMark::eEnd;
}
bool
nsSVGPolyElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
const Matrix& aTransform)
{
const SVGPointList &points = mPoints.GetAnimValue();
if (!points.Length()) {
// Rendering of the element is disabled
aBounds->SetEmpty();
return true;
}
if (aStrokeWidth > 0) {
// We don't handle stroke-miterlimit etc. yet
return false;
}
if (aTransform.IsRectilinear()) {
// We can avoid transforming each point and just transform the result.
// Important for large point lists.
Rect bounds(points[0], Size());
for (uint32_t i = 1; i < points.Length(); ++i) {
bounds.ExpandToEnclose(points[i]);
}
*aBounds = aTransform.TransformBounds(bounds);
} else {
*aBounds = Rect(aTransform * points[0], Size());
for (uint32_t i = 1; i < points.Length(); ++i) {
aBounds->ExpandToEnclose(aTransform * points[i]);
}
}
return true;
}

View File

@ -45,6 +45,8 @@ public:
virtual bool AttributeDefinesGeometry(const nsIAtom *aName) MOZ_OVERRIDE;
virtual bool IsMarkable() MOZ_OVERRIDE { return true; }
virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks) MOZ_OVERRIDE;
virtual bool GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
const Matrix& aTransform) MOZ_OVERRIDE;
// WebIDL
already_AddRefed<mozilla::DOMSVGPointList> Points();

View File

@ -177,6 +177,23 @@ struct BaseRect {
*static_cast<Sub*>(this) = aRect1.UnionEdges(aRect2);
}
// Expands the rect to include the point
void ExpandToEnclose(const Point& aPoint)
{
if (aPoint.x < x) {
width = XMost() - aPoint.x;
x = aPoint.x;
} else if (aPoint.x > XMost()) {
width = aPoint.x - x;
}
if (aPoint.y < y) {
height = YMost() - aPoint.y;
y = aPoint.y;
} else if (aPoint.y > YMost()) {
height = aPoint.y - y;
}
}
void SetRect(T aX, T aY, T aWidth, T aHeight)
{
x = aX; y = aY; width = aWidth; height = aHeight;