[skottie] Optional path control points

Make parsing the in/out Bezier control points optional (default [0,0]).

Change-Id: Id1ef43cea133fab3a112e653d4ce2ab21b91effb
Reviewed-on: https://skia-review.googlesource.com/c/159980
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Florin Malita 2018-10-05 11:24:45 -04:00 committed by Skia Commit-Bot
parent ba651682ae
commit 2c06e14697

View File

@ -133,19 +133,28 @@ bool ValueTraits<ShapeValue>::FromJSON(const skjson::Value& jv,
return false;
const auto& ov = jv.as<skjson::ObjectValue>();
std::vector<SkPoint> inPts, // Cubic Bezier "in" control points, relative to vertices.
outPts, // Cubic Bezier "out" control points, relative to vertices.
verts; // Cubic Bezier vertices.
if (!ParsePointVec(ov["i"], &inPts) ||
!ParsePointVec(ov["o"], &outPts) ||
!ParsePointVec(ov["v"], &verts) ||
inPts.size() != outPts.size() ||
inPts.size() != verts.size()) {
std::vector<SkPoint> verts, // Cubic Bezier vertices.
inPts, // Cubic Bezier "in" control points, relative to vertices.
outPts; // Cubic Bezier "out" control points, relative to vertices.
if (!ParsePointVec(ov["v"], &verts)) {
// Vertices are required.
return false;
}
// In/out points are optional.
ParsePointVec(ov["i"], &inPts);
if (!inPts.empty() && inPts.size() != verts.size()) {
return false;
}
inPts.resize(verts.size(), { 0, 0 });
ParsePointVec(ov["o"], &outPts);
if (!outPts.empty() && outPts.size() != verts.size()) {
return false;
}
outPts.resize(verts.size(), { 0, 0 });
v->fVertices.reserve(inPts.size());
for (size_t i = 0; i < inPts.size(); ++i) {
v->fVertices.push_back(BezierVertex({inPts[i], outPts[i], verts[i]}));