14
14
#include " include/core/SkRect.h"
15
15
#include " include/core/SkString.h"
16
16
#include " include/core/SkStrokeRec.h"
17
+ #include " include/core/SkPathMeasure.h"
17
18
#include " include/effects/SkDashPathEffect.h"
18
19
#include " include/effects/SkTrimPathEffect.h"
19
20
#include " include/pathops/SkPathOps.h"
@@ -456,6 +457,41 @@ void ApplyTransform(SkPath& orig,
456
457
orig.transform (m);
457
458
}
458
459
460
+ // ========================================================================================
461
+ // SkPoint things
462
+ // ========================================================================================
463
+ void ApplySet (SkPoint& p, SkScalar x, SkScalar y) {
464
+ p.set (x, y);
465
+ }
466
+
467
+ void ApplyNormalize (SkPoint& p) {
468
+ p.normalize ();
469
+ }
470
+
471
+ void ApplyScale (SkPoint& p, SkScalar scale) {
472
+ p.scale (scale);
473
+ }
474
+
475
+ void ApplyOffset (SkPoint& p, SkScalar dx, SkScalar dy) {
476
+ p.offset (dx, dy);
477
+ }
478
+
479
+ void ApplyNegate (SkPoint& p) {
480
+ p.negate ();
481
+ }
482
+
483
+ // ========================================================================================
484
+ // SkPathMeasure things
485
+ // ========================================================================================
486
+
487
+ void ApplySetPath (SkPathMeasure& pm, const SkPath& path, bool forceClosed) {
488
+ pm.setPath (&path, forceClosed);
489
+ }
490
+
491
+ bool EMSCRIPTEN_KEEPALIVE GetPosTan (SkPathMeasure& pm, SkScalar distance, SkPoint *position, SkPoint *tangent) {
492
+ return pm.getPosTan (distance, position, tangent);
493
+ }
494
+
459
495
// ========================================================================================
460
496
// Testing things
461
497
// ========================================================================================
@@ -633,9 +669,25 @@ EMSCRIPTEN_BINDINGS(skia) {
633
669
.element (&SimpleMatrix::pers1)
634
670
.element (&SimpleMatrix::pers2);
635
671
636
- value_array<SkPoint>(" SkPoint" )
637
- .element (&SkPoint::fX )
638
- .element (&SkPoint::fY );
672
+ class_<SkPoint>(" SkPoint" )
673
+ .constructor <>()
674
+ .function (" _set" , &ApplySet)
675
+ .function (" _normalize" , &ApplyNormalize)
676
+ .function (" _scale" , &ApplyScale)
677
+ .function (" _offset" , &ApplyOffset)
678
+ .function (" _negate" , &ApplyNegate)
679
+
680
+ .function (" length" , &SkPoint::length)
681
+ .function (" dot" , &SkPoint::dot)
682
+ .function (" cross" , &SkPoint::cross)
683
+ .property (" x" , &SkPoint::fX )
684
+ .property (" y" , &SkPoint::fY )
685
+
686
+ // Static methods
687
+ .class_function (" Distance" , &SkPoint::Distance)
688
+ .class_function (" DotProduct" , &SkPoint::DotProduct)
689
+ .class_function (" CrossProduct" , &SkPoint::CrossProduct);
690
+
639
691
640
692
// Not intended for external clients to call directly.
641
693
// See helper.js for the client-facing implementation.
@@ -645,6 +697,24 @@ EMSCRIPTEN_BINDINGS(skia) {
645
697
.function (" computeYFromX" , &SkCubicMap::computeYFromX)
646
698
.function (" computePtFromT" , &SkCubicMap::computeFromT);
647
699
700
+ class_<SkPathMeasure>(" SkPathMeasure" )
701
+ .constructor <>()
702
+ .constructor <const SkPath&, bool >()
703
+ .constructor <const SkPath&, bool , SkScalar>()
704
+
705
+ .function (" _setPath" , &ApplySetPath)
706
+ .function (" _getPosTan" , &GetPosTan, allow_raw_pointer<arg<3 >>(), allow_raw_pointer<arg<4 >>())
707
+
708
+ .function (" getLength" , &SkPathMeasure::getLength)
709
+ .function (" getSegment" , &SkPathMeasure::getSegment, allow_raw_pointer<arg<3 >>())
710
+ .function (" isClosed" , &SkPathMeasure::isClosed)
711
+ .function (" nextContour" , &SkPathMeasure::nextContour)
712
+ ;
713
+
714
+ enum_<SkPathMeasure::MatrixFlags>(" MatrixFlags" )
715
+ .value (" GET_POSITION" , SkPathMeasure::kGetPosition_MatrixFlag )
716
+ .value (" GET_TANGENT" , SkPathMeasure::kGetTangent_MatrixFlag )
717
+ .value (" GET_POS_AND_TAN" , SkPathMeasure::kGetPosAndTan_MatrixFlag );
648
718
649
719
// Test Utils
650
720
function (" SkBits2FloatUnsigned" , &SkBits2FloatUnsigned);
0 commit comments