26#include <emscripten.h>
27#include <emscripten/bind.h>
52 JSArray cmds = emscripten::val::array();
57 cmd.call<
void>(
"push",
MOVE, pts[0].x(), pts[0].y());
60 cmd.call<
void>(
"push",
LINE, pts[1].x(), pts[1].y());
63 cmd.call<
void>(
"push",
QUAD, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
67 pts[1].x(), pts[1].y(),
68 pts[2].x(), pts[2].y(), *
w);
72 pts[1].x(), pts[1].y(),
73 pts[2].x(), pts[2].y(),
74 pts[3].x(), pts[3].y());
80 cmds.call<
void>(
"push",
cmd);
96 const auto* cmds =
reinterpret_cast<const float*
>(cptr);
98 float x1, y1, x2, y2, x3, y3;
101 #define CHECK_NUM_ARGS(n) \
102 if ((i + n) > numCmds) { \
103 SkDebugf("Not enough args to match the verbs. Saw %d commands\n", numCmds); \
104 return emscripten::val::null(); \
107 for(
int i = 0;
i < numCmds;){
111 x1 = cmds[
i++]; y1 = cmds[
i++];
116 x1 = cmds[
i++]; y1 = cmds[
i++];
121 x1 = cmds[
i++]; y1 = cmds[
i++];
122 x2 = cmds[
i++]; y2 = cmds[
i++];
123 path.quadTo(x1, y1, x2, y2);
127 x1 = cmds[
i++]; y1 = cmds[
i++];
128 x2 = cmds[
i++]; y2 = cmds[
i++];
130 path.conicTo(x1, y1, x2, y2, x3);
134 x1 = cmds[
i++]; y1 = cmds[
i++];
135 x2 = cmds[
i++]; y2 = cmds[
i++];
136 x3 = cmds[
i++]; y3 = cmds[
i++];
137 path.cubicTo(x1, y1, x2, y2, x3, y3);
143 SkDebugf(
" path: UNKNOWN command %f, aborting dump...\n", cmds[
i-1]);
144 return emscripten::val::null();
148 #undef CHECK_NUM_ARGS
150 return emscripten::val(
path);
178 p.arcTo(x1, y1, x2, y2, radius);
187 p.conicTo(x1, y1, x2, y2,
w);
192 p.cubicTo(x1, y1, x2, y2, x3, y3);
204 p.quadTo(x1, y1, x2, y2);
208 return path.isEmpty();
229 return emscripten::val(
path);
231 return emscripten::val::null();
247 return Op(pathOne, pathTwo, op, &pathOne);
252 if (
Op(pathOne, pathTwo, op, &
out)) {
253 return emscripten::val(
out);
255 return emscripten::val::null();
261 return emscripten::val(
path);
263 return emscripten::val::null();
277 ctx.call<
void>(
"moveTo", pts[0].
x(), pts[0].
y());
280 ctx.call<
void>(
"lineTo", pts[1].
x(), pts[1].
y());
283 ctx.call<
void>(
"quadraticCurveTo", pts[1].
x(), pts[1].
y(), pts[2].
x(), pts[2].
y());
289 ctx.call<
void>(
"quadraticCurveTo", quads[1].
x(), quads[1].
y(), quads[2].
x(), quads[2].
y());
290 ctx.call<
void>(
"quadraticCurveTo", quads[3].
x(), quads[3].
y(), quads[4].
x(), quads[4].
y());
293 ctx.call<
void>(
"bezierCurveTo", pts[1].
x(), pts[1].
y(), pts[2].
x(), pts[2].
y(),
294 pts[3].
x(), pts[3].
y());
297 ctx.call<
void>(
"closePath");
305emscripten::val
JSPath2D = emscripten::val::global(
"Path2D");
308 emscripten::val retVal =
JSPath2D.new_();
349 skewY , scaleY, transY,
350 pers0 , pers1 , pers2);
361 return emscripten::val(
"nonzero");
363 return emscripten::val(
"evenodd");
365 SkDebugf(
"warning: can't translate inverted filltype to HTML Canvas\n");
366 return emscripten::val(
"nonzero");
378 SkDebugf(
"Invalid args to dash()\n");
381 SkStrokeRec rec(SkStrokeRec::InitStyle::kHairline_InitStyle);
382 if (pe->filterPath(&
path,
path, &rec,
nullptr)) {
385 SkDebugf(
"Could not make dashed path\n");
393 SkDebugf(
"Invalid args to trim(): startT and stopT must be in [0,1]\n");
396 SkStrokeRec rec(SkStrokeRec::InitStyle::kHairline_InitStyle);
397 if (pe->filterPath(&
path,
path, &rec,
nullptr)) {
418 p.setStrokeCap(opts.
cap);
419 p.setStrokeJoin(opts.
join);
420 p.setStrokeWidth(opts.
width);
454 skewY , scaleY, transY,
455 pers0 , pers1 , pers2);
488 class_<SkPath>(
"SkPath")
490 .constructor<const SkPath&>()
510 .function(
"_isEmpty", &
IsEmpty)
518 .function(
"equals", &
Equals)
528 .function(
"_transform", select_overload<
void(
SkPath& orig,
SkScalar,
SkScalar,
SkScalar,
SkScalar,
SkScalar,
SkScalar,
SkScalar,
SkScalar,
SkScalar)>(&
ApplyTransform))
536 .function(
"toCmds", &
ToCmds)
541#ifdef PATHKIT_TESTING
542 .function(
"dump", select_overload<
void()
const>(&
SkPath::dump))
547 class_<SkOpBuilder>(
"SkOpBuilder")
568 enum_<SkPathOp>(
"PathOp")
575 enum_<SkPathFillType>(
"FillType")
581 constant(
"MOVE_VERB",
MOVE);
582 constant(
"LINE_VERB",
LINE);
583 constant(
"QUAD_VERB",
QUAD);
584 constant(
"CONIC_VERB",
CONIC);
585 constant(
"CUBIC_VERB",
CUBIC);
586 constant(
"CLOSE_VERB",
CLOSE);
591 value_object<SkRect>(
"SkRect")
600 enum_<SkPaint::Join>(
"StrokeJoin")
601 .value(
"MITER", SkPaint::Join::kMiter_Join)
602 .value(
"ROUND", SkPaint::Join::kRound_Join)
603 .value(
"BEVEL", SkPaint::Join::kBevel_Join);
605 enum_<SkPaint::Cap>(
"StrokeCap")
606 .value(
"BUTT", SkPaint::Cap::kButt_Cap)
607 .value(
"ROUND", SkPaint::Cap::kRound_Cap)
608 .value(
"SQUARE", SkPaint::Cap::kSquare_Cap);
610 value_object<StrokeOpts>(
"StrokeOpts")
623 value_array<SimpleMatrix>(
"SkMatrix")
636 value_array<SkPoint>(
"SkPoint")
642 class_<SkCubicMap>(
"_SkCubicMap")
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static float SkBits2Float(uint32_t bits)
#define sk_float_floor2int(x)
bool SK_API AsWinding(const SkPath &path, SkPath *result)
@ kReverseDifference_SkPathOp
subtract the first path from the op path
@ kDifference_SkPathOp
subtract the op path from the first path
@ kIntersect_SkPathOp
intersect the two paths
@ kUnion_SkPathOp
union (inclusive-or) the two paths
@ kXOR_SkPathOp
exclusive-or the two paths
bool SK_API Simplify(const SkPath &path, SkPath *result)
@ kClose
SkPath::RawIter returns 0 points.
@ kCubic
SkPath::RawIter returns 4 points.
@ kConic
SkPath::RawIter returns 3 points + 1 weight.
@ kQuad
SkPath::RawIter returns 3 points.
@ kMove
SkPath::RawIter returns 1 point.
@ kLine
SkPath::RawIter returns 2 points.
#define SkRadiansToDegrees(radians)
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
emscripten::val SkPathOrNull
float computeYFromX(float x) const
SkPoint computeFromT(float t) const
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
void add(const SkPath &path, SkPathOp _operator)
@ kStroke_Style
set to stroke geometry
static SkString ToSVGString(const SkPath &, PathEncoding=PathEncoding::Absolute)
static bool FromSVGString(const char str[], SkPath *)
Verb next(SkPoint pts[4])
SkScalar conicWeight() const
SkPath & reverseAddPath(const SkPath &src)
SkPathFillType getFillType() const
void setFillType(SkPathFillType ft)
SkPath & addPath(const SkPath &src, SkScalar dx, SkScalar dy, AddPathMode mode=kAppend_AddPathMode)
SkRect computeTightBounds() const
SkPath & addArc(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle)
static int ConvertConicToQuads(const SkPoint &p0, const SkPoint &p1, const SkPoint &p2, SkScalar w, SkPoint pts[], int pow2)
const SkRect & getBounds() const
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
static sk_sp< SkPathEffect > Make(SkScalar startT, SkScalar stopT, Mode=Mode::kNormal)
Dart_NativeFunction function
Optional< SkRect > bounds
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)
SkPathOrNull EMSCRIPTEN_KEEPALIVE FromSVGString(std::string str)
bool EMSCRIPTEN_KEEPALIVE ApplySimplify(SkPath &path)
bool ApplyStroke(SkPath &path, StrokeOpts opts)
bool EMSCRIPTEN_KEEPALIVE ApplyAsWinding(SkPath &path)
JSString EMSCRIPTEN_KEEPALIVE ToSVGString(const SkPath &path)
void ApplyReverseAddPath(SkPath &orig, const SkPath &newPath)
void ApplyClose(SkPath &p)
float SkBits2FloatUnsigned(uint32_t floatAsBits)
bool EMSCRIPTEN_KEEPALIVE ApplyPathOp(SkPath &pathOne, const SkPath &pathTwo, SkPathOp op)
SkPath EMSCRIPTEN_KEEPALIVE CopyPath(const SkPath &a)
JSArray EMSCRIPTEN_KEEPALIVE ToCmds(const SkPath &path)
void ApplyCubicTo(SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
void ApplyMoveTo(SkPath &p, SkScalar x, SkScalar y)
void ApplyArcTo(SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius)
void ApplyEllipse(SkPath &path, SkScalar x, SkScalar y, SkScalar radiusX, SkScalar radiusY, SkScalar rotation, SkScalar startAngle, SkScalar endAngle, bool ccw)
SkMatrix toSkMatrix(const SimpleMatrix &sm)
void ApplyConicTo(SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar w)
bool EMSCRIPTEN_KEEPALIVE IsEmpty(const SkPath &path)
SkPathOrNull EMSCRIPTEN_KEEPALIVE MakeFromOp(const SkPath &pathOne, const SkPath &pathTwo, SkPathOp op)
bool ApplyDash(SkPath &path, SkScalar on, SkScalar off, SkScalar phase)
JSString GetFillTypeString(const SkPath &path)
void ApplyTransform(SkPath &orig, const SimpleMatrix &sm)
bool EMSCRIPTEN_KEEPALIVE Equals(const SkPath &a, const SkPath &b)
#define CHECK_NUM_ARGS(n)
emscripten::val EMSCRIPTEN_KEEPALIVE ToPath2D(const SkPath &path)
SkPathOrNull EMSCRIPTEN_KEEPALIVE ResolveBuilder(SkOpBuilder &builder)
void EMSCRIPTEN_KEEPALIVE ToCanvas(const SkPath &path, emscripten::val ctx)
SkPathOrNull EMSCRIPTEN_KEEPALIVE FromCmds(uintptr_t cptr, int numCmds)
void ApplyQuadTo(SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
EMSCRIPTEN_BINDINGS(skia)
void ApplyAddArc(SkPath &path, SkScalar x, SkScalar y, SkScalar radius, SkScalar startAngle, SkScalar endAngle, bool ccw)
bool ApplyTrim(SkPath &path, SkScalar startT, SkScalar stopT, bool isComplement)
void ApplyAddRect(SkPath &path, SkScalar x, SkScalar y, SkScalar width, SkScalar height)
void ApplyAddPath(SkPath &orig, const SkPath &newPath, SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
SkPath EMSCRIPTEN_KEEPALIVE NewPath()
void ApplyLineTo(SkPath &p, SkScalar x, SkScalar y)
constexpr float y() const
constexpr float x() const
SkScalar fBottom
larger y-axis bounds
SkScalar fLeft
smaller x-axis bounds
SkScalar fRight
larger x-axis bounds
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
SkScalar fTop
smaller y-axis bounds