Bug 1667018 - minor improvements to path code r=emilio

- Use IsMoveto method where appropriate
- Avoid referencing path in animation so we can move to supporting shapes later

Differential Revision: https://phabricator.services.mozilla.com/D91242
This commit is contained in:
longsonr 2020-09-24 08:43:51 +00:00
parent b703d14d66
commit 213122103c
3 changed files with 15 additions and 14 deletions

View File

@ -211,16 +211,13 @@ void SVGMotionSMILAnimationFunction::RebuildPathAndVerticesFromMpathElem(
// Use the path that's the target of our chosen <mpath> child.
SVGPathElement* pathElem = aMpathElem->GetReferencedPath();
if (pathElem) {
const SVGPathData& path = pathElem->GetAnimPathSegList()->GetAnimValue();
// Path data must contain of at least one path segment (if the path data
// doesn't begin with a valid "M", then it's invalid).
if (path.Length()) {
bool ok =
path.GetDistancesFromOriginToEndsOfVisibleSegments(&mPathVertices);
if (ok && mPathVertices.Length()) {
mPath = pathElem->GetOrBuildPathForMeasuring();
}
// Path data must contain of at least one path segment (if the path data
// doesn't begin with a valid "M", then it's invalid).
if (pathElem && pathElem->HasValidDimensions()) {
bool ok =
pathElem->GetDistancesFromOriginToEndsOfVisibleSegments(&mPathVertices);
if (ok && mPathVertices.Length()) {
mPath = pathElem->GetOrBuildPathForMeasuring();
}
}
}

View File

@ -162,8 +162,7 @@ bool SVGPathData::GetDistancesFromOriginToEndsOfVisibleSegments(
// this case an equal amount of time is spent on each path segment,
// except on moveto segments which are jumped over immediately.
if (i == 0 ||
(segType != PATHSEG_MOVETO_ABS && segType != PATHSEG_MOVETO_REL)) {
if (i == 0 || !IsMoveto(segType)) {
if (!aOutput->AppendElement(state.length, fallible)) {
return false;
}
@ -480,8 +479,7 @@ already_AddRefed<Path> SVGPathData::BuildPath(PathBuilder* aBuilder,
// seg anyway
}
subpathContainsNonMoveTo =
segType != PATHSEG_MOVETO_ABS && segType != PATHSEG_MOVETO_REL;
subpathContainsNonMoveTo = !IsMoveto(segType);
i += argCount;
prevSegType = segType;
segStart = segEnd;

View File

@ -55,6 +55,12 @@ class SVGPathElement final : public SVGPathElementBase {
*/
virtual already_AddRefed<Path> GetOrBuildPathForMeasuring() override;
bool GetDistancesFromOriginToEndsOfVisibleSegments(
FallibleTArray<double>* aOutput) const {
return mD.GetAnimValue().GetDistancesFromOriginToEndsOfVisibleSegments(
aOutput);
}
// nsIContent interface
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;