Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions | Variables
pathkit_wasm_bindings.cpp File Reference
#include "include/core/SkCubicMap.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPathEffect.h"
#include "include/core/SkPathUtils.h"
#include "include/core/SkRect.h"
#include "include/core/SkString.h"
#include "include/core/SkStrokeRec.h"
#include "include/effects/SkDashPathEffect.h"
#include "include/effects/SkTrimPathEffect.h"
#include "include/pathops/SkPathOps.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/utils/SkParsePath.h"
#include "src/base/SkFloatBits.h"
#include "src/core/SkPaintDefaults.h"
#include "src/core/SkPathPriv.h"
#include <emscripten.h>
#include <emscripten/bind.h>

Go to the source code of this file.

Classes

struct  StrokeOpts
 
struct  SimpleMatrix
 

Macros

#define CHECK_NUM_ARGS(n)
 

Typedefs

using SkPathOrNull = emscripten::val
 
using JSString = emscripten::val
 
using JSArray = emscripten::val
 

Functions

JSArray EMSCRIPTEN_KEEPALIVE ToCmds (const SkPath &path)
 
SkPathOrNull EMSCRIPTEN_KEEPALIVE FromCmds (uintptr_t cptr, int numCmds)
 
SkPath EMSCRIPTEN_KEEPALIVE NewPath ()
 
SkPath EMSCRIPTEN_KEEPALIVE CopyPath (const SkPath &a)
 
bool EMSCRIPTEN_KEEPALIVE Equals (const SkPath &a, const SkPath &b)
 
void ApplyArcTo (SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius)
 
void ApplyClose (SkPath &p)
 
void ApplyConicTo (SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar w)
 
void ApplyCubicTo (SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
 
void ApplyLineTo (SkPath &p, SkScalar x, SkScalar y)
 
void ApplyMoveTo (SkPath &p, SkScalar x, SkScalar y)
 
void ApplyQuadTo (SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
 
JSString EMSCRIPTEN_KEEPALIVE ToSVGString (const SkPath &path)
 
SkPathOrNull EMSCRIPTEN_KEEPALIVE FromSVGString (std::string str)
 
bool EMSCRIPTEN_KEEPALIVE ApplySimplify (SkPath &path)
 
bool EMSCRIPTEN_KEEPALIVE ApplyPathOp (SkPath &pathOne, const SkPath &pathTwo, SkPathOp op)
 
SkPathOrNull EMSCRIPTEN_KEEPALIVE MakeFromOp (const SkPath &pathOne, const SkPath &pathTwo, SkPathOp op)
 
SkPathOrNull EMSCRIPTEN_KEEPALIVE ResolveBuilder (SkOpBuilder &builder)
 
void EMSCRIPTEN_KEEPALIVE ToCanvas (const SkPath &path, emscripten::val ctx)
 
emscripten::val EMSCRIPTEN_KEEPALIVE ToPath2D (const SkPath &path)
 
void ApplyAddRect (SkPath &path, SkScalar x, SkScalar y, SkScalar width, SkScalar height)
 
void ApplyAddArc (SkPath &path, SkScalar x, SkScalar y, SkScalar radius, SkScalar startAngle, SkScalar endAngle, bool ccw)
 
void ApplyEllipse (SkPath &path, SkScalar x, SkScalar y, SkScalar radiusX, SkScalar radiusY, SkScalar rotation, SkScalar startAngle, SkScalar endAngle, bool ccw)
 
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)
 
JSString GetFillTypeString (const SkPath &path)
 
bool ApplyDash (SkPath &path, SkScalar on, SkScalar off, SkScalar phase)
 
bool ApplyTrim (SkPath &path, SkScalar startT, SkScalar stopT, bool isComplement)
 
bool ApplyStroke (SkPath &path, StrokeOpts opts)
 
SkMatrix toSkMatrix (const SimpleMatrix &sm)
 
void ApplyTransform (SkPath &orig, const SimpleMatrix &sm)
 
void ApplyTransform (SkPath &orig, SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
 
float SkBits2FloatUnsigned (uint32_t floatAsBits)
 
 EMSCRIPTEN_BINDINGS (skia)
 

Variables

static const int MOVE = 0
 
static const int LINE = 1
 
static const int QUAD = 2
 
static const int CONIC = 3
 
static const int CUBIC = 4
 
static const int CLOSE = 5
 
emscripten::val JSPath2D = emscripten::val::global("Path2D")
 

Macro Definition Documentation

◆ CHECK_NUM_ARGS

#define CHECK_NUM_ARGS (   n)
Value:
if ((i + n) > numCmds) { \
SkDebugf("Not enough args to match the verbs. Saw %d commands\n", numCmds); \
return emscripten::val::null(); \
}

Typedef Documentation

◆ JSArray

using JSArray = emscripten::val

Definition at line 45 of file pathkit_wasm_bindings.cpp.

◆ JSString

using JSString = emscripten::val

Definition at line 44 of file pathkit_wasm_bindings.cpp.

◆ SkPathOrNull

using SkPathOrNull = emscripten::val

Definition at line 42 of file pathkit_wasm_bindings.cpp.

Function Documentation

◆ ApplyAddArc()

void ApplyAddArc ( SkPath path,
SkScalar  x,
SkScalar  y,
SkScalar  radius,
SkScalar  startAngle,
SkScalar  endAngle,
bool  ccw 
)

Definition at line 312 of file pathkit_wasm_bindings.cpp.

313 {
314 SkPath temp;
315 SkRect bounds = SkRect::MakeLTRB(x-radius, y-radius, x+radius, y+radius);
316 const auto sweep = SkRadiansToDegrees(endAngle - startAngle) - 360 * ccw;
317 temp.addArc(bounds, SkRadiansToDegrees(startAngle), sweep);
318 path.addPath(temp, SkPath::kExtend_AddPathMode);
319}
#define SkRadiansToDegrees(radians)
Definition SkScalar.h:78
SkPath & addArc(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle)
Definition SkPath.cpp:1375
@ kExtend_AddPathMode
Definition SkPath.h:1285
double y
double x
Optional< SkRect > bounds
Definition SkRecords.h:189
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
Definition switches.h:57
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646

◆ ApplyAddPath()

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 
)

Definition at line 336 of file pathkit_wasm_bindings.cpp.

339 {
340 SkMatrix m = SkMatrix::MakeAll(scaleX, skewX , transX,
341 skewY , scaleY, transY,
342 pers0 , pers1 , pers2);
343 orig.addPath(newPath, m);
344}
static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
Definition SkMatrix.h:179
SkPath & addPath(const SkPath &src, SkScalar dx, SkScalar dy, AddPathMode mode=kAppend_AddPathMode)
Definition SkPath.cpp:1442

◆ ApplyAddRect()

void ApplyAddRect ( SkPath path,
SkScalar  x,
SkScalar  y,
SkScalar  width,
SkScalar  height 
)

Definition at line 308 of file pathkit_wasm_bindings.cpp.

308 {
309 path.addRect(x, y, x+width, y+height);
310}
int32_t height
int32_t width

◆ ApplyArcTo()

void ApplyArcTo ( SkPath p,
SkScalar  x1,
SkScalar  y1,
SkScalar  x2,
SkScalar  y2,
SkScalar  radius 
)

Definition at line 176 of file pathkit_wasm_bindings.cpp.

177 {
178 p.arcTo(x1, y1, x2, y2, radius);
179}

◆ ApplyClose()

void ApplyClose ( SkPath p)

Definition at line 181 of file pathkit_wasm_bindings.cpp.

181 {
182 p.close();
183}

◆ ApplyConicTo()

void ApplyConicTo ( SkPath p,
SkScalar  x1,
SkScalar  y1,
SkScalar  x2,
SkScalar  y2,
SkScalar  w 
)

Definition at line 185 of file pathkit_wasm_bindings.cpp.

186 {
187 p.conicTo(x1, y1, x2, y2, w);
188}
SkScalar w

◆ ApplyCubicTo()

void ApplyCubicTo ( SkPath p,
SkScalar  x1,
SkScalar  y1,
SkScalar  x2,
SkScalar  y2,
SkScalar  x3,
SkScalar  y3 
)

Definition at line 190 of file pathkit_wasm_bindings.cpp.

191 {
192 p.cubicTo(x1, y1, x2, y2, x3, y3);
193}

◆ ApplyDash()

bool ApplyDash ( SkPath path,
SkScalar  on,
SkScalar  off,
SkScalar  phase 
)

Definition at line 361 of file pathkit_wasm_bindings.cpp.

361 {
362 SkScalar intervals[] = { on, off };
363 auto pe = SkDashPathEffect::Make(intervals, 2, phase);
364 if (!pe) {
365 SkDebugf("Invalid args to dash()\n");
366 return false;
367 }
369 if (pe->filterPath(&path, path, &rec, nullptr)) {
370 return true;
371 }
372 SkDebugf("Could not make dashed path\n");
373 return false;
374}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
@ kHairline_InitStyle
Definition SkStrokeRec.h:25
float SkScalar
Definition extension.cpp:12

◆ ApplyEllipse()

void ApplyEllipse ( SkPath path,
SkScalar  x,
SkScalar  y,
SkScalar  radiusX,
SkScalar  radiusY,
SkScalar  rotation,
SkScalar  startAngle,
SkScalar  endAngle,
bool  ccw 
)

Definition at line 321 of file pathkit_wasm_bindings.cpp.

322 {
323 // This is easiest to do by making a new path and then extending the current path
324 // (this properly catches the cases of if there's a moveTo before this call or not).
325 SkRect bounds = SkRect::MakeLTRB(x-radiusX, y-radiusY, x+radiusX, y+radiusY);
326 SkPath temp;
327 const auto sweep = SkRadiansToDegrees(endAngle - startAngle) - (360 * ccw);
328 temp.addArc(bounds, SkRadiansToDegrees(startAngle), sweep);
329
330 SkMatrix m;
331 m.setRotate(SkRadiansToDegrees(rotation), x, y);
332 path.addPath(temp, m, SkPath::kExtend_AddPathMode);
333}

◆ ApplyLineTo()

void ApplyLineTo ( SkPath p,
SkScalar  x,
SkScalar  y 
)

Definition at line 195 of file pathkit_wasm_bindings.cpp.

195 {
196 p.lineTo(x, y);
197}

◆ ApplyMoveTo()

void ApplyMoveTo ( SkPath p,
SkScalar  x,
SkScalar  y 
)

Definition at line 199 of file pathkit_wasm_bindings.cpp.

199 {
200 p.moveTo(x, y);
201}

◆ ApplyPathOp()

bool EMSCRIPTEN_KEEPALIVE ApplyPathOp ( SkPath pathOne,
const SkPath pathTwo,
SkPathOp  op 
)

Definition at line 238 of file pathkit_wasm_bindings.cpp.

238 {
239 return Op(pathOne, pathTwo, op, &pathOne);
240}

◆ ApplyQuadTo()

void ApplyQuadTo ( SkPath p,
SkScalar  x1,
SkScalar  y1,
SkScalar  x2,
SkScalar  y2 
)

Definition at line 203 of file pathkit_wasm_bindings.cpp.

203 {
204 p.quadTo(x1, y1, x2, y2);
205}

◆ ApplySimplify()

bool EMSCRIPTEN_KEEPALIVE ApplySimplify ( SkPath path)

Definition at line 234 of file pathkit_wasm_bindings.cpp.

234 {
235 return Simplify(path, &path);
236}
bool SK_API Simplify(const SkPath &path, SkPath *result)

◆ ApplyStroke()

bool ApplyStroke ( SkPath path,
StrokeOpts  opts 
)

Definition at line 402 of file pathkit_wasm_bindings.cpp.

402 {
403 SkPaint p;
404 p.setStyle(SkPaint::kStroke_Style);
405 p.setStrokeCap(opts.cap);
406 p.setStrokeJoin(opts.join);
407 p.setStrokeWidth(opts.width);
408 p.setStrokeMiter(opts.miter_limit);
409 // Default to 1.0 if 0 (or an invalid negative number)
410 if (opts.res_scale <= 0) {
411 opts.res_scale = 1.0;
412 }
413 return skpathutils::FillPathWithPaint(path, p, &path, nullptr, opts.res_scale);
414}
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)
SkPaint::Join join

◆ ApplyTransform() [1/2]

void ApplyTransform ( SkPath orig,
const SimpleMatrix sm 
)

Definition at line 432 of file pathkit_wasm_bindings.cpp.

432 {
433 orig.transform(toSkMatrix(sm));
434}
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition SkPath.cpp:1647
SkMatrix toSkMatrix(const SimpleMatrix &sm)

◆ ApplyTransform() [2/2]

void ApplyTransform ( SkPath orig,
SkScalar  scaleX,
SkScalar  skewX,
SkScalar  transX,
SkScalar  skewY,
SkScalar  scaleY,
SkScalar  transY,
SkScalar  pers0,
SkScalar  pers1,
SkScalar  pers2 
)

Definition at line 436 of file pathkit_wasm_bindings.cpp.

439 {
440 SkMatrix m = SkMatrix::MakeAll(scaleX, skewX , transX,
441 skewY , scaleY, transY,
442 pers0 , pers1 , pers2);
443 orig.transform(m);
444}

◆ ApplyTrim()

bool ApplyTrim ( SkPath path,
SkScalar  startT,
SkScalar  stopT,
bool  isComplement 
)

Definition at line 376 of file pathkit_wasm_bindings.cpp.

376 {
378 auto pe = SkTrimPathEffect::Make(startT, stopT, mode);
379 if (!pe) {
380 SkDebugf("Invalid args to trim(): startT and stopT must be in [0,1]\n");
381 return false;
382 }
384 if (pe->filterPath(&path, path, &rec, nullptr)) {
385 return true;
386 }
387 SkDebugf("Could not trim path\n");
388 return false;
389}
static sk_sp< SkPathEffect > Make(SkScalar startT, SkScalar stopT, Mode=Mode::kNormal)
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
Definition switches.h:228

◆ CopyPath()

SkPath EMSCRIPTEN_KEEPALIVE CopyPath ( const SkPath a)

Definition at line 157 of file pathkit_wasm_bindings.cpp.

157 {
158 SkPath copy(a);
159 return copy;
160}
struct MyStruct a[10]
Definition copy.py:1

◆ EMSCRIPTEN_BINDINGS()

EMSCRIPTEN_BINDINGS ( skia  )

Definition at line 474 of file pathkit_wasm_bindings.cpp.

474 {
475 class_<SkPath>("SkPath")
476 .constructor<>()
477 .constructor<const SkPath&>()
478
479 // Path2D API
480 .function("_addPath", &ApplyAddPath)
481 // 3 additional overloads of addPath are handled in JS bindings
482 .function("_arc", &ApplyAddArc)
483 .function("_arcTo", &ApplyArcTo)
484 //"bezierCurveTo" alias handled in JS bindings
485 .function("_close", &ApplyClose)
486 //"closePath" alias handled in JS bindings
487 .function("_conicTo", &ApplyConicTo)
488 .function("_cubicTo", &ApplyCubicTo)
489
490 .function("_ellipse", &ApplyEllipse)
491 .function("_lineTo", &ApplyLineTo)
492 .function("_moveTo", &ApplyMoveTo)
493 // "quadraticCurveTo" alias handled in JS bindings
494 .function("_quadTo", &ApplyQuadTo)
495 .function("_rect", &ApplyAddRect)
496
497 // Extra features
498 .function("setFillType", select_overload<void(SkPathFillType)>(&SkPath::setFillType))
499 .function("getFillType", &SkPath::getFillType)
500 .function("getFillTypeString", &GetFillTypeString)
501 .function("getBounds", &SkPath::getBounds)
502 .function("computeTightBounds", &SkPath::computeTightBounds)
503 .function("equals", &Equals)
504 .function("copy", &CopyPath)
505
506 // PathEffects
507 .function("_dash", &ApplyDash)
508 .function("_trim", &ApplyTrim)
509 .function("_stroke", &ApplyStroke)
510
511 // Matrix
512 .function("_transform", select_overload<void(SkPath& orig, const SimpleMatrix& sm)>(&ApplyTransform))
513 .function("_transform", select_overload<void(SkPath& orig, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar)>(&ApplyTransform))
514
515 // PathOps
516 .function("_simplify", &ApplySimplify)
517 .function("_op", &ApplyPathOp)
518
519 // Exporting
520 .function("toCmds", &ToCmds)
521 .function("toPath2D", &ToPath2D)
522 .function("toCanvas", &ToCanvas)
523 .function("toSVGString", &ToSVGString)
524
525#ifdef PATHKIT_TESTING
526 .function("dump", select_overload<void() const>(&SkPath::dump))
527 .function("dumpHex", select_overload<void() const>(&SkPath::dumpHex))
528#endif
529 ;
530
531 class_<SkOpBuilder>("SkOpBuilder")
532 .constructor<>()
533
534 .function("add", &SkOpBuilder::add)
535 .function("make", &ResolveBuilder)
536 .function("resolve", &ResolveBuilder);
537
538 // Without these function() bindings, the function would be exposed but oblivious to
539 // our types (e.g. SkPath)
540
541 // Import
542 function("FromSVGString", &FromSVGString);
543 function("NewPath", &NewPath);
544 function("NewPath", &CopyPath);
545 // FromCmds is defined in helper.js to make use of TypedArrays transparent.
546 function("_FromCmds", &FromCmds);
547 // Path2D is opaque, so we can't read in from it.
548
549 // PathOps
550 function("MakeFromOp", &MakeFromOp);
551
552 enum_<SkPathOp>("PathOp")
553 .value("DIFFERENCE", SkPathOp::kDifference_SkPathOp)
554 .value("INTERSECT", SkPathOp::kIntersect_SkPathOp)
555 .value("UNION", SkPathOp::kUnion_SkPathOp)
556 .value("XOR", SkPathOp::kXOR_SkPathOp)
557 .value("REVERSE_DIFFERENCE", SkPathOp::kReverseDifference_SkPathOp);
558
559 enum_<SkPathFillType>("FillType")
560 .value("WINDING", SkPathFillType::kWinding)
561 .value("EVENODD", SkPathFillType::kEvenOdd)
562 .value("INVERSE_WINDING", SkPathFillType::kInverseWinding)
563 .value("INVERSE_EVENODD", SkPathFillType::kInverseEvenOdd);
564
565 constant("MOVE_VERB", MOVE);
566 constant("LINE_VERB", LINE);
567 constant("QUAD_VERB", QUAD);
568 constant("CONIC_VERB", CONIC);
569 constant("CUBIC_VERB", CUBIC);
570 constant("CLOSE_VERB", CLOSE);
571
572 // A value object is much simpler than a class - it is returned as a JS
573 // object and does not require delete().
574 // https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/embind.html#value-types
575 value_object<SkRect>("SkRect")
576 .field("fLeft", &SkRect::fLeft)
577 .field("fTop", &SkRect::fTop)
578 .field("fRight", &SkRect::fRight)
579 .field("fBottom", &SkRect::fBottom);
580
581 function("LTRBRect", &SkRect::MakeLTRB);
582
583 // Stroke
584 enum_<SkPaint::Join>("StrokeJoin")
585 .value("MITER", SkPaint::Join::kMiter_Join)
586 .value("ROUND", SkPaint::Join::kRound_Join)
587 .value("BEVEL", SkPaint::Join::kBevel_Join);
588
589 enum_<SkPaint::Cap>("StrokeCap")
590 .value("BUTT", SkPaint::Cap::kButt_Cap)
591 .value("ROUND", SkPaint::Cap::kRound_Cap)
592 .value("SQUARE", SkPaint::Cap::kSquare_Cap);
593
594 value_object<StrokeOpts>("StrokeOpts")
595 .field("width", &StrokeOpts::width)
596 .field("miter_limit", &StrokeOpts::miter_limit)
597 .field("res_scale", &StrokeOpts::res_scale)
598 .field("join", &StrokeOpts::join)
599 .field("cap", &StrokeOpts::cap);
600
601 // Matrix
602 // Allows clients to supply a 1D array of 9 elements and the bindings
603 // will automatically turn it into a 3x3 2D matrix.
604 // e.g. path.transform([0,1,2,3,4,5,6,7,8])
605 // This is likely simpler for the client than exposing SkMatrix
606 // directly and requiring them to do a lot of .delete().
607 value_array<SimpleMatrix>("SkMatrix")
608 .element(&SimpleMatrix::scaleX)
609 .element(&SimpleMatrix::skewX)
610 .element(&SimpleMatrix::transX)
611
612 .element(&SimpleMatrix::skewY)
613 .element(&SimpleMatrix::scaleY)
614 .element(&SimpleMatrix::transY)
615
616 .element(&SimpleMatrix::pers0)
617 .element(&SimpleMatrix::pers1)
618 .element(&SimpleMatrix::pers2);
619
620 value_array<SkPoint>("SkPoint")
621 .element(&SkPoint::fX)
622 .element(&SkPoint::fY);
623
624 // Not intended for external clients to call directly.
625 // See helper.js for the client-facing implementation.
626 class_<SkCubicMap>("_SkCubicMap")
627 .constructor<SkPoint, SkPoint>()
628
629 .function("computeYFromX", &SkCubicMap::computeYFromX)
630 .function("computePtFromT", &SkCubicMap::computeFromT);
631
632
633 // Test Utils
634 function("SkBits2FloatUnsigned", &SkBits2FloatUnsigned);
635}
@ kReverseDifference_SkPathOp
subtract the first path from the op path
Definition SkPathOps.h:27
@ kDifference_SkPathOp
subtract the op path from the first path
Definition SkPathOps.h:23
@ kIntersect_SkPathOp
intersect the two paths
Definition SkPathOps.h:24
@ kUnion_SkPathOp
union (inclusive-or) the two paths
Definition SkPathOps.h:25
@ kXOR_SkPathOp
exclusive-or the two paths
Definition SkPathOps.h:26
SkPathFillType
Definition SkPathTypes.h:11
float computeYFromX(float x) const
SkPoint computeFromT(float t) const
void add(const SkPath &path, SkPathOp _operator)
@ kRound_Cap
adds circle
Definition SkPaint.h:335
@ kButt_Cap
no stroke extension
Definition SkPaint.h:334
@ kSquare_Cap
adds square
Definition SkPaint.h:336
@ kRound_Join
adds circle
Definition SkPaint.h:360
@ kMiter_Join
extends to miter limit
Definition SkPaint.h:359
@ kBevel_Join
connects outside edges
Definition SkPaint.h:361
SkPathFillType getFillType() const
Definition SkPath.h:230
void setFillType(SkPathFillType ft)
Definition SkPath.h:235
SkRect computeTightBounds() const
Definition SkPath.cpp:3378
void dump() const
Definition SkPath.h:1726
const SkRect & getBounds() const
Definition SkPath.cpp:420
void dumpHex() const
Definition SkPath.h:1727
Dart_NativeFunction function
Definition fuchsia.cc:51
SkPathOrNull EMSCRIPTEN_KEEPALIVE FromSVGString(std::string str)
bool EMSCRIPTEN_KEEPALIVE ApplySimplify(SkPath &path)
bool ApplyStroke(SkPath &path, StrokeOpts opts)
static const int CLOSE
JSString EMSCRIPTEN_KEEPALIVE ToSVGString(const SkPath &path)
void ApplyClose(SkPath &p)
float SkBits2FloatUnsigned(uint32_t floatAsBits)
bool EMSCRIPTEN_KEEPALIVE ApplyPathOp(SkPath &pathOne, const SkPath &pathTwo, SkPathOp op)
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)
static const int QUAD
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)
void ApplyConicTo(SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar w)
static const int CUBIC
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)
static const int MOVE
static const int LINE
void ApplyTransform(SkPath &orig, const SimpleMatrix &sm)
bool EMSCRIPTEN_KEEPALIVE Equals(const SkPath &a, const SkPath &b)
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)
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)
static const int CONIC
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)
float fX
x-axis value
float fY
y-axis value
SkScalar fBottom
larger y-axis bounds
Definition extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition extension.cpp:16
SkScalar fTop
smaller y-axis bounds
Definition extension.cpp:15

◆ Equals()

bool EMSCRIPTEN_KEEPALIVE Equals ( const SkPath a,
const SkPath b 
)

Definition at line 162 of file pathkit_wasm_bindings.cpp.

162 {
163 return a == b;
164}
static bool b

◆ FromCmds()

SkPathOrNull EMSCRIPTEN_KEEPALIVE FromCmds ( uintptr_t  cptr,
int  numCmds 
)

Definition at line 95 of file pathkit_wasm_bindings.cpp.

95 {
96 const auto* cmds = reinterpret_cast<const float*>(cptr);
98 float x1, y1, x2, y2, x3, y3;
99
100 // if there are not enough arguments, bail with the path we've constructed so far.
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(); \
105 }
106
107 for(int i = 0; i < numCmds;){
108 switch (sk_float_floor2int(cmds[i++])) {
109 case MOVE:
111 x1 = cmds[i++]; y1 = cmds[i++];
112 path.moveTo(x1, y1);
113 break;
114 case LINE:
116 x1 = cmds[i++]; y1 = cmds[i++];
117 path.lineTo(x1, y1);
118 break;
119 case QUAD:
121 x1 = cmds[i++]; y1 = cmds[i++];
122 x2 = cmds[i++]; y2 = cmds[i++];
123 path.quadTo(x1, y1, x2, y2);
124 break;
125 case CONIC:
127 x1 = cmds[i++]; y1 = cmds[i++];
128 x2 = cmds[i++]; y2 = cmds[i++];
129 x3 = cmds[i++]; // weight
130 path.conicTo(x1, y1, x2, y2, x3);
131 break;
132 case CUBIC:
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);
138 break;
139 case CLOSE:
140 path.close();
141 break;
142 default:
143 SkDebugf(" path: UNKNOWN command %f, aborting dump...\n", cmds[i-1]);
144 return emscripten::val::null();
145 }
146 }
147
148 #undef CHECK_NUM_ARGS
149
150 return emscripten::val(path);
151}
#define sk_float_floor2int(x)
static void dump(const float m[20], SkYUVColorSpace cs, bool rgb2yuv)
#define CHECK_NUM_ARGS(n)

◆ FromSVGString()

SkPathOrNull EMSCRIPTEN_KEEPALIVE FromSVGString ( std::string  str)

Definition at line 222 of file pathkit_wasm_bindings.cpp.

222 {
223 SkPath path;
224 if (SkParsePath::FromSVGString(str.c_str(), &path)) {
225 return emscripten::val(path);
226 }
227 return emscripten::val::null();
228}
static bool FromSVGString(const char str[], SkPath *)

◆ GetFillTypeString()

JSString GetFillTypeString ( const SkPath path)

Definition at line 346 of file pathkit_wasm_bindings.cpp.

346 {
347 if (path.getFillType() == SkPathFillType::kWinding) {
348 return emscripten::val("nonzero");
349 } else if (path.getFillType() == SkPathFillType::kEvenOdd) {
350 return emscripten::val("evenodd");
351 } else {
352 SkDebugf("warning: can't translate inverted filltype to HTML Canvas\n");
353 return emscripten::val("nonzero"); //Use default
354 }
355}

◆ MakeFromOp()

SkPathOrNull EMSCRIPTEN_KEEPALIVE MakeFromOp ( const SkPath pathOne,
const SkPath pathTwo,
SkPathOp  op 
)

Definition at line 242 of file pathkit_wasm_bindings.cpp.

242 {
243 SkPath out;
244 if (Op(pathOne, pathTwo, op, &out)) {
245 return emscripten::val(out);
246 }
247 return emscripten::val::null();
248}

◆ NewPath()

SkPath EMSCRIPTEN_KEEPALIVE NewPath ( )

Definition at line 153 of file pathkit_wasm_bindings.cpp.

153 {
154 return SkPath();
155}

◆ ResolveBuilder()

SkPathOrNull EMSCRIPTEN_KEEPALIVE ResolveBuilder ( SkOpBuilder builder)

Definition at line 250 of file pathkit_wasm_bindings.cpp.

250 {
251 SkPath path;
252 if (builder.resolve(&path)) {
253 return emscripten::val(path);
254 }
255 return emscripten::val::null();
256}

◆ SkBits2FloatUnsigned()

float SkBits2FloatUnsigned ( uint32_t  floatAsBits)

Definition at line 455 of file pathkit_wasm_bindings.cpp.

455 {
456 return SkBits2Float((int32_t) floatAsBits);
457}
static float SkBits2Float(uint32_t bits)
Definition SkFloatBits.h:48

◆ ToCanvas()

void EMSCRIPTEN_KEEPALIVE ToCanvas ( const SkPath path,
emscripten::val  ctx 
)

Definition at line 262 of file pathkit_wasm_bindings.cpp.

262 {
263 SkPath::Iter iter(path, false);
264 SkPoint pts[4];
265 SkPath::Verb verb;
266 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
267 switch (verb) {
269 ctx.call<void>("moveTo", pts[0].x(), pts[0].y());
270 break;
272 ctx.call<void>("lineTo", pts[1].x(), pts[1].y());
273 break;
275 ctx.call<void>("quadraticCurveTo", pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
276 break;
278 SkPoint quads[5];
279 // approximate with 2^1=2 quads.
280 SkPath::ConvertConicToQuads(pts[0], pts[1], pts[2], iter.conicWeight(), quads, 1);
281 ctx.call<void>("quadraticCurveTo", quads[1].x(), quads[1].y(), quads[2].x(), quads[2].y());
282 ctx.call<void>("quadraticCurveTo", quads[3].x(), quads[3].y(), quads[4].x(), quads[4].y());
283 break;
285 ctx.call<void>("bezierCurveTo", pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y(),
286 pts[3].x(), pts[3].y());
287 break;
289 ctx.call<void>("closePath");
290 break;
292 break;
293 }
294 }
295}
static int ConvertConicToQuads(const SkPoint &p0, const SkPoint &p1, const SkPoint &p2, SkScalar w, SkPoint pts[], int pow2)
Definition SkPath.cpp:3174
@ kClose_Verb
Definition SkPath.h:1463
@ kMove_Verb
Definition SkPath.h:1458
@ kConic_Verb
Definition SkPath.h:1461
@ kDone_Verb
Definition SkPath.h:1464
@ kCubic_Verb
Definition SkPath.h:1462
@ kQuad_Verb
Definition SkPath.h:1460
@ kLine_Verb
Definition SkPath.h:1459
constexpr float y() const
constexpr float x() const

◆ ToCmds()

JSArray EMSCRIPTEN_KEEPALIVE ToCmds ( const SkPath path)

Definition at line 51 of file pathkit_wasm_bindings.cpp.

51 {
52 JSArray cmds = emscripten::val::array();
53 for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) {
54 JSArray cmd = emscripten::val::array();
55 switch (verb) {
57 cmd.call<void>("push", MOVE, pts[0].x(), pts[0].y());
58 break;
60 cmd.call<void>("push", LINE, pts[1].x(), pts[1].y());
61 break;
63 cmd.call<void>("push", QUAD, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
64 break;
66 cmd.call<void>("push", CONIC,
67 pts[1].x(), pts[1].y(),
68 pts[2].x(), pts[2].y(), *w);
69 break;
71 cmd.call<void>("push", CUBIC,
72 pts[1].x(), pts[1].y(),
73 pts[2].x(), pts[2].y(),
74 pts[3].x(), pts[3].y());
75 break;
77 cmd.call<void>("push", CLOSE);
78 break;
79 }
80 cmds.call<void>("push", cmd);
81 }
82 return cmds;
83}
@ 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.
emscripten::val JSArray
Definition WasmCommon.h:27

◆ ToPath2D()

emscripten::val EMSCRIPTEN_KEEPALIVE ToPath2D ( const SkPath path)

Definition at line 299 of file pathkit_wasm_bindings.cpp.

299 {
300 emscripten::val retVal = JSPath2D.new_();
301 ToCanvas(path, retVal);
302 return retVal;
303}
emscripten::val JSPath2D

◆ toSkMatrix()

SkMatrix toSkMatrix ( const SimpleMatrix sm)

Definition at line 426 of file pathkit_wasm_bindings.cpp.

426 {
427 return SkMatrix::MakeAll(sm.scaleX, sm.skewX , sm.transX,
428 sm.skewY , sm.scaleY, sm.transY,
429 sm.pers0 , sm.pers1 , sm.pers2);
430}

◆ ToSVGString()

JSString EMSCRIPTEN_KEEPALIVE ToSVGString ( const SkPath path)

Definition at line 213 of file pathkit_wasm_bindings.cpp.

213 {
214 // Wrapping it in val automatically turns it into a JS string.
215 // Not too sure on performance implications, but is is simpler than
216 // returning a raw pointer to const char * and then using
217 // UTF8ToString() on the calling side.
218 return emscripten::val(SkParsePath::ToSVGString(path).c_str());
219}
static SkString ToSVGString(const SkPath &, PathEncoding=PathEncoding::Absolute)

Variable Documentation

◆ CLOSE

const int CLOSE = 5
static

Definition at line 36 of file pathkit_wasm_bindings.cpp.

◆ CONIC

const int CONIC = 3
static

Definition at line 34 of file pathkit_wasm_bindings.cpp.

◆ CUBIC

const int CUBIC = 4
static

Definition at line 35 of file pathkit_wasm_bindings.cpp.

◆ JSPath2D

emscripten::val JSPath2D = emscripten::val::global("Path2D")

Definition at line 297 of file pathkit_wasm_bindings.cpp.

◆ LINE

const int LINE = 1
static

Definition at line 32 of file pathkit_wasm_bindings.cpp.

◆ MOVE

const int MOVE = 0
static

Definition at line 31 of file pathkit_wasm_bindings.cpp.

◆ QUAD

const int QUAD = 2
static

Definition at line 33 of file pathkit_wasm_bindings.cpp.