@@ -52,36 +52,33 @@ class JsiSkPathFactory : public JsiSkHostObject {
5252
5353 JSI_HOST_FUNCTION (MakeFromSVGString) {
5454 auto svgString = arguments[0 ].asString (runtime).utf8 (runtime);
55- SkPath result;
56-
57- if (!SkParsePath::FromSVGString (svgString.c_str (), &result)) {
55+ auto result = SkParsePath::FromSVGString (svgString.c_str ());
56+ if (!result.has_value ()) {
5857 throw jsi::JSError (runtime, " Could not parse Svg path" );
5958 return jsi::Value (nullptr );
6059 }
61-
6260 auto hostObjectInstance =
63- std::make_shared<JsiSkPath>(getContext (), std::move (result));
61+ std::make_shared<JsiSkPath>(getContext (), std::move (result. value () ));
6462 return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE (
6563 runtime, hostObjectInstance, getContext ());
6664 }
6765
6866 JSI_HOST_FUNCTION (MakeFromOp) {
69- SkPath one = JsiSkPath::fromValue (runtime, arguments[0 ])->snapshot ();
70- SkPath two = JsiSkPath::fromValue (runtime, arguments[1 ])->snapshot ();
67+ auto one = JsiSkPath::fromValue (runtime, arguments[0 ])->snapshot ();
68+ auto two = JsiSkPath::fromValue (runtime, arguments[1 ])->snapshot ();
7169 SkPathOp op = (SkPathOp)arguments[2 ].asNumber ();
72- SkPath result;
73- bool success = Op (one, two, op, &result);
74- if (!success) {
70+ auto result = Op (one, two, op);
71+ if (!result.has_value ()) {
7572 return jsi::Value (nullptr );
7673 }
7774 auto hostObjectInstance =
78- std::make_shared<JsiSkPath>(getContext (), std::move (result));
75+ std::make_shared<JsiSkPath>(getContext (), std::move (result. value () ));
7976 return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE (
8077 runtime, hostObjectInstance, getContext ());
8178 }
8279
8380 JSI_HOST_FUNCTION (MakeFromCmds) {
84- SkPath path ;
81+ SkPathBuilder builder ;
8582 auto cmds = arguments[0 ].asObject (runtime).asArray (runtime);
8683 auto cmdCount = cmds.size (runtime);
8784 for (int i = 0 ; i < cmdCount; i++) {
@@ -100,7 +97,7 @@ class JsiSkPathFactory : public JsiSkHostObject {
10097 }
10198 auto x = cmd.getValueAtIndex (runtime, 1 ).asNumber ();
10299 auto y = cmd.getValueAtIndex (runtime, 2 ).asNumber ();
103- path .moveTo (x, y);
100+ builder .moveTo (x, y);
104101 break ;
105102 }
106103 case LINE: {
@@ -110,7 +107,7 @@ class JsiSkPathFactory : public JsiSkHostObject {
110107 }
111108 auto x = cmd.getValueAtIndex (runtime, 1 ).asNumber ();
112109 auto y = cmd.getValueAtIndex (runtime, 2 ).asNumber ();
113- path .lineTo (x, y);
110+ builder .lineTo (x, y);
114111 break ;
115112 }
116113 case QUAD: {
@@ -122,7 +119,7 @@ class JsiSkPathFactory : public JsiSkHostObject {
122119 auto y1 = cmd.getValueAtIndex (runtime, 2 ).asNumber ();
123120 auto x2 = cmd.getValueAtIndex (runtime, 3 ).asNumber ();
124121 auto y2 = cmd.getValueAtIndex (runtime, 4 ).asNumber ();
125- path .quadTo (x1, y1, x2, y2);
122+ builder .quadTo (x1, y1, x2, y2);
126123 break ;
127124 }
128125 case CONIC: {
@@ -135,7 +132,7 @@ class JsiSkPathFactory : public JsiSkHostObject {
135132 auto x2 = cmd.getValueAtIndex (runtime, 3 ).asNumber ();
136133 auto y2 = cmd.getValueAtIndex (runtime, 4 ).asNumber ();
137134 auto w = cmd.getValueAtIndex (runtime, 5 ).asNumber ();
138- path .conicTo (x1, y1, x2, y2, w);
135+ builder .conicTo (x1, y1, x2, y2, w);
139136 break ;
140137 }
141138 case CUBIC: {
@@ -149,11 +146,11 @@ class JsiSkPathFactory : public JsiSkHostObject {
149146 auto y2 = cmd.getValueAtIndex (runtime, 4 ).asNumber ();
150147 auto x3 = cmd.getValueAtIndex (runtime, 5 ).asNumber ();
151148 auto y3 = cmd.getValueAtIndex (runtime, 6 ).asNumber ();
152- path .cubicTo (x1, y1, x2, y2, x3, y3);
149+ builder .cubicTo (x1, y1, x2, y2, x3, y3);
153150 break ;
154151 }
155152 case CLOSE: {
156- path .close ();
153+ builder .close ();
157154 break ;
158155 }
159156 default : {
@@ -163,7 +160,7 @@ class JsiSkPathFactory : public JsiSkHostObject {
163160 }
164161 }
165162 auto hostObjectInstance =
166- std::make_shared<JsiSkPath>(getContext (), std::move (path ));
163+ std::make_shared<JsiSkPath>(getContext (), builder. snapshot ( ));
167164 return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE (
168165 runtime, hostObjectInstance, getContext ());
169166 }
@@ -189,10 +186,10 @@ class JsiSkPathFactory : public JsiSkHostObject {
189186 if (count >= 2 && arguments[1 ].getBool ()) {
190187 direction = SkPathDirection::kCCW ;
191188 }
192- SkPath path ;
193- path .addRect (*rect, direction);
189+ SkPathBuilder builder ;
190+ builder .addRect (*rect, direction);
194191 auto hostObjectInstance =
195- std::make_shared<JsiSkPath>(getContext (), std::move (path ));
192+ std::make_shared<JsiSkPath>(getContext (), builder. snapshot ( ));
196193 return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE (
197194 runtime, hostObjectInstance, getContext ());
198195 }
@@ -204,10 +201,10 @@ class JsiSkPathFactory : public JsiSkHostObject {
204201 direction = SkPathDirection::kCCW ;
205202 }
206203 unsigned startIndex = count < 3 ? 0 : arguments[2 ].asNumber ();
207- SkPath path ;
208- path .addOval (*rect, direction, startIndex);
204+ SkPathBuilder builder ;
205+ builder .addOval (*rect, direction, startIndex);
209206 auto hostObjectInstance =
210- std::make_shared<JsiSkPath>(getContext (), std::move (path ));
207+ std::make_shared<JsiSkPath>(getContext (), builder. snapshot ( ));
211208 return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE (
212209 runtime, hostObjectInstance, getContext ());
213210 }
@@ -216,10 +213,10 @@ class JsiSkPathFactory : public JsiSkHostObject {
216213 auto x = arguments[0 ].asNumber ();
217214 auto y = arguments[1 ].asNumber ();
218215 auto r = arguments[2 ].asNumber ();
219- SkPath path ;
220- path .addCircle (x, y, r);
216+ SkPathBuilder builder ;
217+ builder .addCircle (x, y, r);
221218 auto hostObjectInstance =
222- std::make_shared<JsiSkPath>(getContext (), std::move (path ));
219+ std::make_shared<JsiSkPath>(getContext (), builder. snapshot ( ));
223220 return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE (
224221 runtime, hostObjectInstance, getContext ());
225222 }
@@ -230,10 +227,10 @@ class JsiSkPathFactory : public JsiSkHostObject {
230227 if (count >= 2 && arguments[1 ].getBool ()) {
231228 direction = SkPathDirection::kCCW ;
232229 }
233- SkPath path ;
234- path .addRRect (*rrect, direction);
230+ SkPathBuilder builder ;
231+ builder .addRRect (*rrect, direction);
235232 auto hostObjectInstance =
236- std::make_shared<JsiSkPath>(getContext (), std::move (path ));
233+ std::make_shared<JsiSkPath>(getContext (), builder. snapshot ( ));
237234 return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE (
238235 runtime, hostObjectInstance, getContext ());
239236 }
@@ -243,11 +240,11 @@ class JsiSkPathFactory : public JsiSkHostObject {
243240 runtime, arguments[0 ].asObject (runtime));
244241 auto p2 = JsiSkPoint::fromValue (
245242 runtime, arguments[1 ].asObject (runtime));
246- SkPath path ;
247- path .moveTo (*p1);
248- path .lineTo (*p2);
243+ SkPathBuilder builder ;
244+ builder .moveTo (*p1);
245+ builder .lineTo (*p2);
249246 auto hostObjectInstance =
250- std::make_shared<JsiSkPath>(getContext (), std::move (path ));
247+ std::make_shared<JsiSkPath>(getContext (), builder. snapshot ( ));
251248 return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE (
252249 runtime, hostObjectInstance, getContext ());
253250 }
@@ -263,11 +260,10 @@ class JsiSkPathFactory : public JsiSkHostObject {
263260 runtime, jsiPoints.getValueAtIndex (runtime, i).asObject (runtime));
264261 points.push_back (*point.get ());
265262 }
266- SkPath path;
267- auto p = SkSpan (points.data (), points.size ());
268- path.addPoly (p, close);
263+ SkPathBuilder builder;
264+ builder.addPolygon (SkSpan (points), close);
269265 auto hostObjectInstance =
270- std::make_shared<JsiSkPath>(getContext (), std::move (path ));
266+ std::make_shared<JsiSkPath>(getContext (), builder. snapshot ( ));
271267 return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE (
272268 runtime, hostObjectInstance, getContext ());
273269 }
@@ -308,22 +304,23 @@ class JsiSkPathFactory : public JsiSkHostObject {
308304
309305 auto jsiPrecision = opts.getProperty (runtime, " precision" );
310306 auto precision = jsiPrecision.isUndefined () ? 1 : jsiPrecision.asNumber ();
311- SkPath result;
307+ SkPathBuilder resultBuilder;
308+ auto ctm = SkMatrix::Scale (precision, precision);
312309 auto success =
313- skpathutils::FillPathWithPaint (path, p, &result , nullptr , precision );
310+ skpathutils::FillPathWithPaint (path, p, &resultBuilder , nullptr , ctm );
314311 if (success) {
315312 auto hostObjectInstance =
316- std::make_shared<JsiSkPath>(getContext (), std::move (result ));
313+ std::make_shared<JsiSkPath>(getContext (), resultBuilder. snapshot ( ));
317314 return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE (
318315 runtime, hostObjectInstance, getContext ());
319316 }
320317 } else {
321- SkPath result ;
318+ SkPathBuilder resultBuilder ;
322319 auto success =
323- skpathutils::FillPathWithPaint (path, p, &result, nullptr , 1 );
320+ skpathutils::FillPathWithPaint (path, p, &resultBuilder );
324321 if (success) {
325322 auto hostObjectInstance =
326- std::make_shared<JsiSkPath>(getContext (), std::move (result ));
323+ std::make_shared<JsiSkPath>(getContext (), resultBuilder. snapshot ( ));
327324 return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE (
328325 runtime, hostObjectInstance, getContext ());
329326 }
0 commit comments