[PathKit] Write more complete docs and clean up API to be consistent
Breaking Changes (should be minor, as it's mostly just things
for testing):
- PathKit.ApplyPathOp should have returned a new SkPath, but didn't.
It now does and is named "MakeFromOp", which makes the convention of
"Have 'make' in name, needs delete" more consistent.
- PathKit.FromCmds(arr) now only needs to take the JS Array and
will handle the TypedArrays under the hood. If clients want to deal
with TypedArrays themselves, they can use _FromCmds(ptr, len) directly.
- PathKit.MakeLTRBRect is now just PathKit.LTRBRect. The thing
returned is a normal JS Object and doesn't need delete().
As per custom with v0 apps, we are updating the minor version
to v0.3.0 to account for breaking changes.
Docs-Preview: https://skia.org/?cl=147960
Bug: skia:8216
Change-Id: Ia3626e69f3e97698fc62a6aee876af005e29ffca
Reviewed-on: https://skia-review.googlesource.com/147960
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Heather Miller <hcm@google.com>
diff --git a/experimental/pathkit/pathkit_wasm_bindings.cpp b/experimental/pathkit/pathkit_wasm_bindings.cpp
index c680db1..40772d8 100644
--- a/experimental/pathkit/pathkit_wasm_bindings.cpp
+++ b/experimental/pathkit/pathkit_wasm_bindings.cpp
@@ -134,7 +134,7 @@
CHECK_NUM_ARGS(5);
x1 = cmds[i++], y1 = cmds[i++];
x2 = cmds[i++], y2 = cmds[i++];
- x3 = cmds[i++]; // width
+ x3 = cmds[i++]; // weight
path.conicTo(x1, y1, x2, y2, x3);
break;
case CUBIC:
@@ -249,6 +249,14 @@
return Op(pathOne, pathTwo, op, &pathOne);
}
+SkPathOrNull EMSCRIPTEN_KEEPALIVE MakeFromOp(const SkPath& pathOne, const SkPath& pathTwo, SkPathOp op) {
+ SkPath out;
+ if (Op(pathOne, pathTwo, op, &out)) {
+ return emscripten::val(out);
+ }
+ return emscripten::val::null();
+}
+
SkPathOrNull EMSCRIPTEN_KEEPALIVE ResolveBuilder(SkOpBuilder& builder) {
SkPath path;
if (builder.resolve(&path)) {
@@ -481,9 +489,9 @@
.function("_arcTo", &ApplyArcTo)
//"bezierCurveTo" alias handled in JS bindings
.function("_close", &ApplyClose)
+ //"closePath" alias handled in JS bindings
.function("_conicTo", &ApplyConicTo)
.function("_cubicTo", &ApplyCubicTo)
- //"closePath" alias handled in JS bindings
.function("_ellipse", &ApplyEllipse)
.function("_lineTo", &ApplyLineTo)
@@ -530,6 +538,7 @@
.constructor<>()
.function("add", &SkOpBuilder::add)
+ .function("make", &ResolveBuilder)
.function("resolve", &ResolveBuilder);
// Without these function() bindings, the function would be exposed but oblivious to
@@ -537,13 +546,14 @@
// Import
function("FromSVGString", &FromSVGString);
- function("FromCmds", &FromCmds);
function("NewPath", &NewPath);
function("NewPath", &CopyPath);
+ // FromCmds is defined in helper.js to make use of TypedArrays transparent.
+ function("_FromCmds", &FromCmds);
// Path2D is opaque, so we can't read in from it.
// PathOps
- function("ApplyPathOp", &ApplyPathOp);
+ function("MakeFromOp", &MakeFromOp);
enum_<SkPathOp>("PathOp")
.value("DIFFERENCE", SkPathOp::kDifference_SkPathOp)
@@ -574,7 +584,7 @@
.field("fRight", &SkRect::fRight)
.field("fBottom", &SkRect::fBottom);
- function("MakeLTRBRect", &SkRect::MakeLTRB);
+ function("LTRBRect", &SkRect::MakeLTRB);
// Stroke
enum_<SkPaint::Join>("StrokeJoin")