Issue #2737 - Part 1: Base implementation of SVGGeometryElement.

Mostly mechanical changes to generalize path geometry for all SVG draw
elements. No user-exposed changes.
This commit is contained in:
Moonchild 2025-04-27 18:03:48 +02:00 committed by roytam1
commit fd4a224d1d
45 changed files with 368 additions and 319 deletions

View file

@ -9,7 +9,6 @@
#include "DOMSVGPathSeg.h"
#include "DOMSVGPathSegList.h"
#include "DOMSVGPoint.h"
#include "gfx2DGlue.h"
#include "gfxPlatform.h"
#include "mozilla/dom/SVGPathElementBinding.h"
@ -35,9 +34,6 @@ SVGPathElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
return SVGPathElementBinding::Wrap(aCx, this, aGivenProto);
}
nsSVGElement::NumberInfo SVGPathElement::sNumberInfo =
{ &nsGkAtoms::pathLength, 0, false };
//----------------------------------------------------------------------
// Implementation
@ -61,45 +57,6 @@ SVGPathElement::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGPathElement)
already_AddRefed<SVGAnimatedNumber>
SVGPathElement::PathLength()
{
return mPathLength.ToDOMAnimatedNumber(this);
}
float
SVGPathElement::GetTotalLength()
{
RefPtr<Path> flat = GetOrBuildPathForMeasuring();
return flat ? flat->ComputeLength() : 0.f;
}
already_AddRefed<nsISVGPoint>
SVGPathElement::GetPointAtLength(float distance, ErrorResult& rv)
{
RefPtr<Path> path = GetOrBuildPathForMeasuring();
if (!path) {
rv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
float totalLength = path->ComputeLength();
if (mPathLength.IsExplicitlySet()) {
float pathLength = mPathLength.GetAnimValue();
if (pathLength <= 0) {
rv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
distance *= totalLength / pathLength;
}
distance = std::max(0.f, distance);
distance = std::min(totalLength, distance);
nsCOMPtr<nsISVGPoint> point =
new DOMSVGPoint(path->ComputePointAtLength(distance));
return point.forget();
}
uint32_t
SVGPathElement::GetPathSegAtLength(float distance)
{
@ -284,12 +241,6 @@ SVGPathElement::HasValidDimensions() const
return !mD.GetAnimValue().IsEmpty();
}
nsSVGElement::NumberAttributesInfo
SVGPathElement::GetNumberInfo()
{
return NumberAttributesInfo(&mPathLength, &sNumberInfo, 1);
}
//----------------------------------------------------------------------
// nsIContent methods
@ -311,7 +262,7 @@ SVGPathElement::GetOrBuildPathForMeasuring()
}
//----------------------------------------------------------------------
// nsSVGPathGeometryElement methods
// SVGGeometryElement methods
bool
SVGPathElement::AttributeDefinesGeometry(const nsIAtom *aName)