@@ -77,9 +77,7 @@ inline static bool checkArgs(const Nan::FunctionCallbackInfo<Value> &info, doubl
77
77
double val = Nan::To<double >(info[i]).FromMaybe (0 );
78
78
79
79
if (areArgsValid) {
80
- if (val != val ||
81
- val == std::numeric_limits<double >::infinity () ||
82
- val == -std::numeric_limits<double >::infinity ()) {
80
+ if (!std::isfinite (val)) {
83
81
// We should continue the loop instead of returning immediately
84
82
// See https://html.spec.whatwg.org/multipage/canvas.html
85
83
@@ -140,6 +138,7 @@ Context2d::Initialize(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target) {
140
138
Nan::SetPrototypeMethod (ctor, " measureText" , MeasureText);
141
139
Nan::SetPrototypeMethod (ctor, " moveTo" , MoveTo);
142
140
Nan::SetPrototypeMethod (ctor, " lineTo" , LineTo);
141
+ Nan::SetPrototypeMethod (ctor, " linesTo" , LinesTo);
143
142
Nan::SetPrototypeMethod (ctor, " bezierCurveTo" , BezierCurveTo);
144
143
Nan::SetPrototypeMethod (ctor, " quadraticCurveTo" , QuadraticCurveTo);
145
144
Nan::SetPrototypeMethod (ctor, " beginPath" , BeginPath);
@@ -723,6 +722,15 @@ NAN_METHOD(Context2d::New) {
723
722
Context2d *context = new Context2d (canvas);
724
723
725
724
context->Wrap (info.This ());
725
+
726
+ Nan::Set (info.This (),
727
+ Nan::New<String>(" _ptidx" ).ToLocalChecked (),
728
+ Nan::New<Number>(0 )).Check ();
729
+ Local<Float64Array> pts = Float64Array::New (ArrayBuffer::New (Isolate::GetCurrent (), 8 * 10 * 2 ), 0 , 10 * 2 );
730
+ Nan::Set (info.This (),
731
+ Nan::New<String>(" _pts" ).ToLocalChecked (),
732
+ pts).Check ();
733
+
726
734
info.GetReturnValue ().Set (info.This ());
727
735
}
728
736
@@ -2363,6 +2371,20 @@ NAN_METHOD(Context2d::Fill) {
2363
2371
2364
2372
NAN_METHOD (Context2d::Stroke) {
2365
2373
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This ());
2374
+
2375
+ uint32_t ptidx = Nan::To<uint32_t >(Nan::Get (info.This (), Nan::New<String>(" _ptidx" ).ToLocalChecked ()).ToLocalChecked ()).FromJust ();
2376
+ if (ptidx > 0 ) {
2377
+ Local<Float64Array> pointsArray = Nan::Get (info.This (), Nan::New<String>(" _pts" ).ToLocalChecked ()).ToLocalChecked ().As <Float64Array>();
2378
+ Nan::TypedArrayContents<double > typedArrayContents (pointsArray);
2379
+ double * points = *typedArrayContents;
2380
+ for (uint32_t i = 0 ; i < ptidx; i += 2 ) {
2381
+ cairo_line_to (context->context (), points[i], points[i + 1 ]);
2382
+ }
2383
+ Nan::Set (info.This (),
2384
+ Nan::New<String>(" _ptidx" ).ToLocalChecked (),
2385
+ Nan::New<Number>(0 )).Check ();
2386
+ }
2387
+
2366
2388
context->stroke (true );
2367
2389
}
2368
2390
@@ -2511,6 +2533,17 @@ NAN_METHOD(Context2d::LineTo) {
2511
2533
cairo_line_to (context->context (), args[0 ], args[1 ]);
2512
2534
}
2513
2535
2536
+ NAN_METHOD (Context2d::LinesTo) {
2537
+ Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This ());
2538
+
2539
+ Local<Float64Array> pointsArray = info[0 ].As <Float64Array>();
2540
+ Nan::TypedArrayContents<double > typedArrayContents (pointsArray);
2541
+ double * points = *typedArrayContents;
2542
+ for (uint32_t i = 0 ; i < 20 ; i += 2 ) {
2543
+ cairo_line_to (context->context (), points[i], points[i + 1 ]);
2544
+ }
2545
+ }
2546
+
2514
2547
/*
2515
2548
* Creates a new subpath at the given point.
2516
2549
*/
@@ -2521,6 +2554,20 @@ NAN_METHOD(Context2d::MoveTo) {
2521
2554
return ;
2522
2555
2523
2556
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This ());
2557
+
2558
+ uint32_t ptidx = Nan::To<uint32_t >(Nan::Get (info.This (), Nan::New<String>(" _ptidx" ).ToLocalChecked ()).ToLocalChecked ()).FromJust ();
2559
+ if (ptidx > 0 ) {
2560
+ Local<Float64Array> pointsArray = Nan::Get (info.This (), Nan::New<String>(" _pts" ).ToLocalChecked ()).ToLocalChecked ().As <Float64Array>();
2561
+ Nan::TypedArrayContents<double > typedArrayContents (pointsArray);
2562
+ double * points = *typedArrayContents;
2563
+ for (uint32_t i = 0 ; i < ptidx; i += 2 ) {
2564
+ cairo_line_to (context->context (), points[i], points[i + 1 ]);
2565
+ }
2566
+ Nan::Set (info.This (),
2567
+ Nan::New<String>(" _ptidx" ).ToLocalChecked (),
2568
+ Nan::New<Number>(0 )).Check ();
2569
+ }
2570
+
2524
2571
cairo_move_to (context->context (), args[0 ], args[1 ]);
2525
2572
}
2526
2573
0 commit comments