2222#include " SkDiscretePathEffect.h"
2323#include " SkEncodedImageFormat.h"
2424#include " SkFontMgr.h"
25+ #include " SkBlurTypes.h"
2526#include " SkFontMgrPriv.h"
2627#include " SkGradientShader.h"
2728#include " SkImageShader.h"
29+ #include " SkMaskFilter.h"
2830#include " SkPaint.h"
2931#include " SkParsePath.h"
3032#include " SkPath.h"
3133#include " SkPathEffect.h"
3234#include " SkPathOps.h"
3335#include " SkScalar.h"
3436#include " SkShader.h"
37+ #include " SkShadowUtils.h"
3538#include " SkString.h"
3639#include " SkStrokeRec.h"
3740#include " SkSurface.h"
@@ -349,6 +352,10 @@ EMSCRIPTEN_BINDINGS(Skia) {
349352 function (" getSkDataBytes" , &getSkDataBytes, allow_raw_pointers ());
350353 function (" MakeSkCornerPathEffect" , &SkCornerPathEffect::Make, allow_raw_pointers ());
351354 function (" MakeSkDiscretePathEffect" , &SkDiscretePathEffect::Make, allow_raw_pointers ());
355+ function (" MakeBlurMaskFilter" , optional_override ([](SkBlurStyle style, SkScalar sigma, bool respectCTM)->sk_sp <SkMaskFilter> {
356+ // Adds a little helper because emscripten doesn't expose default params.
357+ return SkMaskFilter::MakeBlur (style, sigma, respectCTM);
358+ }), allow_raw_pointers ());
352359 function (" MakePathFromOp" , &MakePathFromOp);
353360
354361 // These won't be called directly, there's a JS helper to deal with typed arrays.
@@ -445,7 +452,16 @@ EMSCRIPTEN_BINDINGS(Skia) {
445452 .function (" drawPaint" , &SkCanvas::drawPaint)
446453 .function (" drawPath" , &SkCanvas::drawPath)
447454 .function (" drawRect" , &SkCanvas::drawRect)
448- .function (" drawText" , optional_override ([](SkCanvas& self, std::string text, SkScalar x, SkScalar y, const SkPaint& p) {
455+ .function (" drawShadow" , optional_override ([](SkCanvas& self, const SkPath& path,
456+ const SkPoint3& zPlaneParams,
457+ const SkPoint3& lightPos, SkScalar lightRadius,
458+ JSColor ambientColor, JSColor spotColor,
459+ uint32_t flags) {
460+ SkShadowUtils::DrawShadow (&self, path, zPlaneParams, lightPos, lightRadius,
461+ SkColor (ambientColor), SkColor (spotColor), flags);
462+ }))
463+ .function (" drawText" , optional_override ([](SkCanvas& self, std::string text, SkScalar x,
464+ SkScalar y, const SkPaint& p) {
449465 // TODO(kjlubick): This does not work well for non-ascii
450466 // Need to maybe add a helper in interface.js that supports UTF-8
451467 // Otherwise, go with std::wstring and set UTF-32 encoding.
@@ -471,12 +487,20 @@ EMSCRIPTEN_BINDINGS(Skia) {
471487 .function (" _encodeToData" , select_overload<sk_sp<SkData>()const >(&SkImage::encodeToData))
472488 .function (" _encodeToDataWithFormat" , select_overload<sk_sp<SkData>(SkEncodedImageFormat encodedImageFormat, int quality)const >(&SkImage::encodeToData));
473489
490+ class_<SkMaskFilter>(" SkMaskFilter" )
491+ .smart_ptr <sk_sp<SkMaskFilter>>(" sk_sp<SkMaskFilter>" );
492+
474493 class_<SkPaint>(" SkPaint" )
475494 .constructor <>()
476495 .function (" copy" , optional_override ([](const SkPaint& self)->SkPaint {
477496 SkPaint p (self);
478497 return p;
479498 }))
499+ .function (" getColor" , optional_override ([](SkPaint& self)->JSColor {
500+ // JS side gives us a signed int instead of an unsigned int for color
501+ // Add a optional_override to change it out.
502+ return JSColor (self.getColor ());
503+ }))
480504 .function (" getStrokeWidth" , &SkPaint::getStrokeWidth)
481505 .function (" getStrokeMiter" , &SkPaint::getStrokeMiter)
482506 .function (" getStrokeCap" , &SkPaint::getStrokeCap)
@@ -494,6 +518,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
494518 // Add a optional_override to change it out.
495519 self.setColor (SkColor (color));
496520 }))
521+ .function (" setMaskFilter" , &SkPaint::setMaskFilter)
497522 .function (" setPathEffect" , &SkPaint::setPathEffect)
498523 .function (" setShader" , &SkPaint::setShader)
499524 .function (" setStrokeWidth" , &SkPaint::setStrokeWidth)
@@ -616,17 +641,27 @@ EMSCRIPTEN_BINDINGS(Skia) {
616641 .value (" Color" , SkBlendMode::kColor )
617642 .value (" Luminosity" , SkBlendMode::kLuminosity );
618643
619- enum_<SkPaint::Style>(" PaintStyle" )
620- .value (" Fill" , SkPaint::Style::kFill_Style )
621- .value (" Stroke" , SkPaint::Style::kStroke_Style )
622- .value (" StrokeAndFill" , SkPaint::Style::kStrokeAndFill_Style );
644+ enum_<SkBlurStyle>(" BlurStyle" )
645+ .value (" Normal" , SkBlurStyle::kNormal_SkBlurStyle )
646+ .value (" Solid" , SkBlurStyle::kSolid_SkBlurStyle )
647+ .value (" Outer" , SkBlurStyle::kOuter_SkBlurStyle )
648+ .value (" Inner" , SkBlurStyle::kInner_SkBlurStyle );
623649
624650 enum_<SkPath::FillType>(" FillType" )
625651 .value (" Winding" , SkPath::FillType::kWinding_FillType )
626652 .value (" EvenOdd" , SkPath::FillType::kEvenOdd_FillType )
627653 .value (" InverseWinding" , SkPath::FillType::kInverseWinding_FillType )
628654 .value (" InverseEvenOdd" , SkPath::FillType::kInverseEvenOdd_FillType );
629655
656+ enum_<SkEncodedImageFormat>(" ImageFormat" )
657+ .value (" PNG" , SkEncodedImageFormat::kPNG )
658+ .value (" JPEG" , SkEncodedImageFormat::kJPEG );
659+
660+ enum_<SkPaint::Style>(" PaintStyle" )
661+ .value (" Fill" , SkPaint::Style::kFill_Style )
662+ .value (" Stroke" , SkPaint::Style::kStroke_Style )
663+ .value (" StrokeAndFill" , SkPaint::Style::kStrokeAndFill_Style );
664+
630665 enum_<SkPathOp>(" PathOp" )
631666 .value (" Difference" , SkPathOp::kDifference_SkPathOp )
632667 .value (" Intersect" , SkPathOp::kIntersect_SkPathOp )
@@ -660,10 +695,6 @@ EMSCRIPTEN_BINDINGS(Skia) {
660695 .value (" TrianglesStrip" , SkVertices::VertexMode::kTriangleStrip_VertexMode )
661696 .value (" TriangleFan" , SkVertices::VertexMode::kTriangleFan_VertexMode );
662697
663- enum_<SkEncodedImageFormat>(" ImageFormat" )
664- .value (" PNG" , SkEncodedImageFormat::kPNG )
665- .value (" JPEG" , SkEncodedImageFormat::kJPEG );
666-
667698
668699 // A value object is much simpler than a class - it is returned as a JS
669700 // object and does not require delete().
@@ -685,6 +716,12 @@ EMSCRIPTEN_BINDINGS(Skia) {
685716 .element (&SkPoint::fX )
686717 .element (&SkPoint::fY );
687718
719+ // SkPoint3s can be represented by [x, y, z]
720+ value_array<SkPoint3>(" SkPoint3" )
721+ .element (&SkPoint3::fX )
722+ .element (&SkPoint3::fY )
723+ .element (&SkPoint3::fZ );
724+
688725 // {"w": Number, "h", Number}
689726 value_object<SkSize>(" SkSize" )
690727 .field (" w" , &SkSize::fWidth )
@@ -717,6 +754,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
717754 constant (" BLUE" , (JSColor) SK_ColorBLUE);
718755 constant (" YELLOW" , (JSColor) SK_ColorYELLOW);
719756 constant (" CYAN" , (JSColor) SK_ColorCYAN);
757+ constant (" BLACK" , (JSColor) SK_ColorBLACK);
720758 // TODO(?)
721759
722760#if SK_INCLUDE_SKOTTIE
0 commit comments