@nativescript/canvas 2.0.0-alpha.20 → 2.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Canvas/common.d.ts +2 -0
- package/Canvas/common.js +6 -0
- package/Canvas/common.js.map +1 -1
- package/Canvas/index.android.d.ts +0 -2
- package/Canvas/index.android.js +8 -22
- package/Canvas/index.android.js.map +1 -1
- package/Canvas/index.d.ts +7 -0
- package/Canvas/index.ios.d.ts +0 -2
- package/Canvas/index.ios.js +7 -26
- package/Canvas/index.ios.js.map +1 -1
- package/Canvas2D/CanvasGradient/index.d.ts +1 -3
- package/Canvas2D/CanvasGradient/index.js +1 -10
- package/Canvas2D/CanvasGradient/index.js.map +1 -1
- package/Canvas2D/CanvasPattern/index.d.ts +1 -3
- package/Canvas2D/CanvasPattern/index.js +1 -10
- package/Canvas2D/CanvasPattern/index.js.map +1 -1
- package/Canvas2D/CanvasRenderingContext2D/index.d.ts +0 -2
- package/Canvas2D/CanvasRenderingContext2D/index.js +120 -138
- package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
- package/Canvas2D/DOMMatrix/index.js +3 -3
- package/Canvas2D/DOMMatrix/index.js.map +1 -1
- package/Canvas2D/ImageData/index.js +5 -5
- package/Canvas2D/ImageData/index.js.map +1 -1
- package/Canvas2D/Path2D/index.d.ts +0 -2
- package/Canvas2D/Path2D/index.js +34 -39
- package/Canvas2D/Path2D/index.js.map +1 -1
- package/ImageAsset/index.d.ts +2 -2
- package/ImageAsset/index.js +33 -37
- package/ImageAsset/index.js.map +1 -1
- package/ImageBitmap/index.d.ts +0 -2
- package/ImageBitmap/index.js +23 -29
- package/ImageBitmap/index.js.map +1 -1
- package/SVG/SVG.js +1 -1
- package/TextDecoder/index.d.ts +0 -2
- package/TextDecoder/index.js +3 -12
- package/TextDecoder/index.js.map +1 -1
- package/TextEncoder/index.d.ts +0 -2
- package/TextEncoder/index.js +4 -13
- package/TextEncoder/index.js.map +1 -1
- package/WebGL/WebGLExtensions/index.d.ts +0 -9
- package/WebGL/WebGLExtensions/index.js +17 -74
- package/WebGL/WebGLExtensions/index.js.map +1 -1
- package/WebGL/WebGLRenderingContext/common.d.ts +0 -2
- package/WebGL/WebGLRenderingContext/common.js +0 -10
- package/WebGL/WebGLRenderingContext/common.js.map +1 -1
- package/WebGL/WebGLRenderingContext/index.js +159 -298
- package/WebGL/WebGLRenderingContext/index.js.map +1 -1
- package/WebGL2/WebGL2RenderingContext/index.js +107 -195
- package/WebGL2/WebGL2RenderingContext/index.js.map +1 -1
- package/angular/esm2020/index.mjs +5 -5
- package/angular/fesm2015/nativescript-canvas-angular.mjs +4 -4
- package/angular/fesm2015/nativescript-canvas-angular.mjs.map +1 -1
- package/angular/fesm2020/nativescript-canvas-angular.mjs +4 -4
- package/angular/fesm2020/nativescript-canvas-angular.mjs.map +1 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/platforms/android/canvas-release.aar +0 -0
- package/platforms/android/include.gradle +15 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +87 -57
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h +10 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_ios.h +142 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +2589 -110
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +1174 -89
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +2 -2
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +2 -2
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +174 -114
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h +10 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_ios.h +142 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +2589 -110
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +1174 -89
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +2 -2
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +2 -2
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +1174 -89
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +2 -2
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +2 -2
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +42 -31
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/Podfile +3 -0
- package/platforms/ios/build.xcconfig +3 -3
- package/platforms/ios/src/CanvasModule.h +0 -2
- package/platforms/ios/src/CanvasModule.mm +4 -4
- package/platforms/ios/src/NSOperationQueueWrapper.h +11 -0
- package/platforms/ios/src/NSOperationQueueWrapper.mm +74 -0
- package/platforms/ios/src/cpp/Caches.cpp +35 -0
- package/platforms/ios/src/cpp/Caches.h +186 -0
- package/platforms/ios/src/cpp/CanvasJSIModule.cpp +1582 -0
- package/platforms/ios/src/cpp/CanvasJSIModule.h +7 -34
- package/platforms/ios/src/cpp/Common.h +30 -0
- package/platforms/ios/src/cpp/ConcurrentMap.h +54 -0
- package/platforms/ios/src/cpp/Helpers.h +304 -38
- package/platforms/ios/src/cpp/ImageAssetImpl.cpp +802 -0
- package/platforms/ios/src/cpp/ImageAssetImpl.h +44 -12
- package/platforms/ios/src/cpp/ImageBitmapImpl.cpp +189 -0
- package/platforms/ios/src/cpp/ImageBitmapImpl.h +22 -16
- package/platforms/ios/src/cpp/JSICallback.h +61 -5
- package/platforms/ios/src/cpp/JSIReadFileCallback.h +86 -6
- package/platforms/ios/src/cpp/JSIRuntime.cpp +21 -0
- package/platforms/ios/src/cpp/JSIRuntime.h +7 -0
- package/platforms/ios/src/cpp/OneByteStringResource.cpp +25 -0
- package/platforms/ios/src/cpp/OneByteStringResource.h +21 -0
- package/platforms/ios/src/cpp/RafImpl.cpp +8 -0
- package/platforms/ios/src/cpp/RafImpl.h +11 -8
- package/platforms/ios/src/cpp/TextDecoderImpl.cpp +188 -0
- package/platforms/ios/src/cpp/TextDecoderImpl.h +20 -14
- package/platforms/ios/src/cpp/TextEncoderImpl.cpp +139 -0
- package/platforms/ios/src/cpp/TextEncoderImpl.h +20 -11
- package/platforms/ios/src/cpp/canvas2d/CanvasGradient.cpp +71 -0
- package/platforms/ios/src/cpp/canvas2d/CanvasGradient.h +27 -13
- package/platforms/ios/src/cpp/canvas2d/CanvasPattern.cpp +89 -0
- package/platforms/ios/src/cpp/canvas2d/CanvasPattern.h +26 -13
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +2402 -0
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.h +264 -21
- package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.cpp +203 -0
- package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.h +26 -12
- package/platforms/ios/src/cpp/canvas2d/MatrixImpl.cpp +800 -0
- package/platforms/ios/src/cpp/canvas2d/MatrixImpl.h +172 -13
- package/platforms/ios/src/cpp/canvas2d/Path2D.cpp +449 -0
- package/platforms/ios/src/cpp/canvas2d/Path2D.h +41 -12
- package/platforms/ios/src/cpp/canvas2d/TextMetricsImpl.cpp +253 -0
- package/platforms/ios/src/cpp/canvas2d/TextMetricsImpl.h +50 -12
- package/platforms/ios/src/cpp/gl.h +57 -7
- package/platforms/ios/src/cpp/gl3stub.c +425 -0
- package/platforms/ios/src/cpp/gl3stub.h +665 -0
- package/platforms/ios/src/cpp/gles3jni.h +37 -0
- package/platforms/ios/src/cpp/include/robin_hood.h +2544 -0
- package/platforms/ios/src/cpp/webgl/WebGLActiveInfoImpl.cpp +93 -0
- package/platforms/ios/src/cpp/webgl/WebGLActiveInfoImpl.h +33 -13
- package/platforms/ios/src/cpp/webgl/WebGLBuffer.h +41 -6
- package/platforms/ios/src/cpp/webgl/WebGLFramebuffer.h +46 -10
- package/platforms/ios/src/cpp/webgl/WebGLProgram.h +40 -5
- package/platforms/ios/src/cpp/webgl/WebGLRenderbuffer.h +40 -6
- package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +6691 -0
- package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.h +261 -390
- package/platforms/ios/src/cpp/webgl/{WebGLRenderingContextBase.mm → WebGLRenderingContextBase.cpp} +17 -16
- package/platforms/ios/src/cpp/webgl/WebGLRenderingContextBase.h +15 -36
- package/platforms/ios/src/cpp/webgl/WebGLShader.h +40 -6
- package/platforms/ios/src/cpp/webgl/WebGLShaderPrecisionFormatImpl.cpp +50 -0
- package/platforms/ios/src/cpp/webgl/WebGLShaderPrecisionFormatImpl.h +66 -11
- package/platforms/ios/src/cpp/webgl/WebGLTexture.h +40 -6
- package/platforms/ios/src/cpp/webgl/WebGLUniformLocation.h +44 -8
- package/platforms/ios/src/cpp/webgl/extensions/ANGLE_instanced_arraysImpl.cpp +126 -0
- package/platforms/ios/src/cpp/webgl/extensions/ANGLE_instanced_arraysImpl.h +25 -12
- package/platforms/ios/src/cpp/webgl/extensions/EXT_blend_minmaxImpl.cpp +35 -0
- package/platforms/ios/src/cpp/webgl/extensions/EXT_blend_minmaxImpl.h +25 -5
- package/platforms/ios/src/cpp/webgl/extensions/EXT_color_buffer_half_floatImpl.cpp +41 -0
- package/platforms/ios/src/cpp/webgl/extensions/EXT_color_buffer_half_floatImpl.h +25 -5
- package/platforms/ios/src/cpp/webgl/extensions/EXT_disjoint_timer_queryImpl.cpp +323 -0
- package/platforms/ios/src/cpp/webgl/extensions/EXT_disjoint_timer_queryImpl.h +47 -13
- package/platforms/ios/src/cpp/webgl/extensions/EXT_sRGBImpl.h +49 -6
- package/platforms/ios/src/cpp/webgl/extensions/EXT_shader_texture_lodImpl.h +37 -15
- package/platforms/ios/src/cpp/webgl/extensions/EXT_texture_filter_anisotropicImpl.h +47 -6
- package/platforms/ios/src/cpp/webgl/extensions/OES_element_index_uintImpl.h +49 -6
- package/platforms/ios/src/cpp/webgl/extensions/OES_fbo_render_mipmap.h +36 -15
- package/platforms/ios/src/cpp/webgl/extensions/OES_standard_derivativesImpl.h +44 -6
- package/platforms/ios/src/cpp/webgl/extensions/OES_texture_floatImpl.h +38 -15
- package/platforms/ios/src/cpp/webgl/extensions/OES_texture_float_linearImpl.h +37 -16
- package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_floatImpl.h +41 -6
- package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_float_linearImpl.h +40 -16
- package/platforms/ios/src/cpp/webgl/extensions/OES_vertex_array_objectImpl.cpp +102 -0
- package/platforms/ios/src/cpp/webgl/extensions/OES_vertex_array_objectImpl.h +69 -14
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_color_buffer_floatImpl.h +51 -8
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_atcImpl.h +49 -6
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etc1Impl.h +49 -8
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etcImpl.h +76 -6
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_pvrtcImpl.h +57 -6
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tcImpl.h +53 -6
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tc_srgbImpl.h +59 -6
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_depth_textureImpl.h +46 -6
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_draw_buffersImpl.cpp +43 -0
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_draw_buffersImpl.h +126 -14
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_lose_contextImpl.cpp +32 -0
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_lose_contextImpl.h +61 -12
- package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.cpp +4517 -0
- package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.h +139 -343
- package/platforms/ios/src/cpp/webgl2/WebGLQuery.h +40 -4
- package/platforms/ios/src/cpp/webgl2/WebGLSampler.h +42 -3
- package/platforms/ios/src/cpp/webgl2/WebGLSyncImpl.h +44 -11
- package/platforms/ios/src/cpp/webgl2/WebGLTransformFeedback.h +42 -4
- package/platforms/ios/src/cpp/webgl2/WebGLVertexArrayObject.h +43 -4
- package/platforms/ios/src/module.modulemap +1 -0
- package/platforms/ios/src/cpp/CanvasJSIModule.mm +0 -1105
- package/platforms/ios/src/cpp/ImageAssetImpl.mm +0 -417
- package/platforms/ios/src/cpp/ImageBitmapImpl.mm +0 -126
- package/platforms/ios/src/cpp/RafImpl.mm +0 -10
- package/platforms/ios/src/cpp/TextDecoderImpl.mm +0 -97
- package/platforms/ios/src/cpp/TextEncoderImpl.mm +0 -60
- package/platforms/ios/src/cpp/VecMutableBuffer.h +0 -46
- package/platforms/ios/src/cpp/canvas-cxx/src/lib.rs.cc +0 -6156
- package/platforms/ios/src/cpp/canvas-cxx/src/lib.rs.h +0 -2867
- package/platforms/ios/src/cpp/canvas2d/CanvasGradient.mm +0 -42
- package/platforms/ios/src/cpp/canvas2d/CanvasPattern.mm +0 -49
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.mm +0 -1972
- package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.mm +0 -68
- package/platforms/ios/src/cpp/canvas2d/MatrixImpl.mm +0 -149
- package/platforms/ios/src/cpp/canvas2d/Path2D.mm +0 -335
- package/platforms/ios/src/cpp/canvas2d/TextMetricsImpl.mm +0 -68
- package/platforms/ios/src/cpp/rust/cxx.cc +0 -793
- package/platforms/ios/src/cpp/rust/cxx.h +0 -1111
- package/platforms/ios/src/cpp/webgl/WebGLActiveInfoImpl.mm +0 -39
- package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.mm +0 -5958
- package/platforms/ios/src/cpp/webgl/WebGLShaderPrecisionFormatImpl.mm +0 -40
- package/platforms/ios/src/cpp/webgl/extensions/ANGLE_instanced_arraysImpl.mm +0 -108
- package/platforms/ios/src/cpp/webgl/extensions/EXT_blend_minmaxImpl.mm +0 -28
- package/platforms/ios/src/cpp/webgl/extensions/EXT_color_buffer_half_floatImpl.mm +0 -42
- package/platforms/ios/src/cpp/webgl/extensions/EXT_disjoint_timer_queryImpl.mm +0 -295
- package/platforms/ios/src/cpp/webgl/extensions/EXT_sRGBImpl.mm +0 -40
- package/platforms/ios/src/cpp/webgl/extensions/EXT_texture_filter_anisotropicImpl.mm +0 -37
- package/platforms/ios/src/cpp/webgl/extensions/OES_element_index_uintImpl.mm +0 -28
- package/platforms/ios/src/cpp/webgl/extensions/OES_standard_derivativesImpl.mm +0 -31
- package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_floatImpl.mm +0 -28
- package/platforms/ios/src/cpp/webgl/extensions/OES_vertex_array_objectImpl.mm +0 -127
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_color_buffer_floatImpl.mm +0 -45
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_atcImpl.mm +0 -45
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etc1Impl.mm +0 -31
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etcImpl.mm +0 -70
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_pvrtcImpl.mm +0 -47
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tcImpl.mm +0 -46
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tc_srgbImpl.mm +0 -49
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_depth_textureImpl.mm +0 -30
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_draw_buffersImpl.mm +0 -177
- package/platforms/ios/src/cpp/webgl/extensions/WEBGL_lose_contextImpl.mm +0 -64
- package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.mm +0 -4551
- /package/platforms/ios/src/cpp/{OnRafCallback.mm → OnRafCallback.cpp} +0 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Created by Osei Fortune on 19/04/2022.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#include "TextDecoderImpl.h"
|
|
6
|
+
#include "Caches.h"
|
|
7
|
+
#include "Helpers.h"
|
|
8
|
+
#include "OneByteStringResource.h"
|
|
9
|
+
|
|
10
|
+
TextDecoderImpl::TextDecoderImpl(TextDecoder* decoder) : decoder_(decoder) {}
|
|
11
|
+
|
|
12
|
+
void TextDecoderImpl::Init(const v8::Local<v8::Object> &canvasModule, v8::Isolate *isolate) {
|
|
13
|
+
v8::Locker locker(isolate);
|
|
14
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
15
|
+
v8::HandleScope handle_scope(isolate);
|
|
16
|
+
|
|
17
|
+
auto ctor = GetCtor(isolate);
|
|
18
|
+
auto context = isolate->GetCurrentContext();
|
|
19
|
+
auto func = ctor->GetFunction(context).ToLocalChecked();
|
|
20
|
+
|
|
21
|
+
canvasModule->Set(context, ConvertToV8String(isolate, "TextDecoder"), func);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
TextDecoderImpl *TextDecoderImpl::GetPointer(v8::Local<v8::Object> object) {
|
|
25
|
+
auto ptr = object->GetInternalField(0).As<v8::External>()->Value();
|
|
26
|
+
if (ptr == nullptr) {
|
|
27
|
+
return nullptr;
|
|
28
|
+
}
|
|
29
|
+
return static_cast<TextDecoderImpl *>(ptr);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
TextDecoder* TextDecoderImpl::GetTextDecoder() {
|
|
33
|
+
return this->decoder_;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
v8::Local<v8::FunctionTemplate> TextDecoderImpl::GetCtor(v8::Isolate *isolate) {
|
|
37
|
+
auto cache = Caches::Get(isolate);
|
|
38
|
+
auto ctor = cache->TextDecoderTmpl.get();
|
|
39
|
+
if (ctor != nullptr) {
|
|
40
|
+
return ctor->Get(isolate);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
v8::Local<v8::FunctionTemplate> ctorTmpl = v8::FunctionTemplate::New(isolate, Ctor);
|
|
44
|
+
ctorTmpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
45
|
+
ctorTmpl->SetClassName(ConvertToV8String(isolate, "TextDecoder"));
|
|
46
|
+
|
|
47
|
+
auto tmpl = ctorTmpl->InstanceTemplate();
|
|
48
|
+
tmpl->SetInternalFieldCount(1);
|
|
49
|
+
tmpl->SetAccessor(
|
|
50
|
+
ConvertToV8String(isolate, "encoding"),
|
|
51
|
+
Encoding);
|
|
52
|
+
tmpl->Set(
|
|
53
|
+
ConvertToV8String(isolate, "decode"),
|
|
54
|
+
v8::FunctionTemplate::New(isolate, &Decode));
|
|
55
|
+
cache->TextDecoderTmpl =
|
|
56
|
+
std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
|
|
57
|
+
return ctorTmpl;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void TextDecoderImpl::Ctor(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
61
|
+
auto count = args.Length();
|
|
62
|
+
auto value = args[0];
|
|
63
|
+
auto isolate = args.GetIsolate();
|
|
64
|
+
if (count == 1 && !value->IsString()) {
|
|
65
|
+
auto label = value->ToString(isolate->GetCurrentContext()).ToLocalChecked();
|
|
66
|
+
auto arg = ConvertFromV8String(isolate, label);
|
|
67
|
+
auto error = "Failed to construct 'TextDecoder': The encoding label provided (" +
|
|
68
|
+
arg + "') is invalid";
|
|
69
|
+
isolate->ThrowError(ConvertToV8String(isolate, error));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
std::string encoding("utf-8");
|
|
74
|
+
if (count == 1) {
|
|
75
|
+
encoding = ConvertFromV8String(isolate, value);
|
|
76
|
+
}
|
|
77
|
+
auto encoder = canvas_native_text_decoder_create(encoding.c_str());
|
|
78
|
+
|
|
79
|
+
auto ret = args.This();
|
|
80
|
+
|
|
81
|
+
auto decoder = new TextDecoderImpl(encoder);
|
|
82
|
+
|
|
83
|
+
auto ext = v8::External::New(isolate, decoder);
|
|
84
|
+
|
|
85
|
+
ret->SetInternalField(0, ext);
|
|
86
|
+
|
|
87
|
+
args.GetReturnValue().Set(ret);
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
void
|
|
92
|
+
TextDecoderImpl::Encoding(v8::Local<v8::String> name,
|
|
93
|
+
const v8::PropertyCallbackInfo<v8::Value> &info) {
|
|
94
|
+
auto ptr = GetPointer(info.This());
|
|
95
|
+
if (ptr != nullptr) {
|
|
96
|
+
auto isolate = info.GetIsolate();
|
|
97
|
+
auto encoding = canvas_native_text_decoder_get_encoding(ptr->GetTextDecoder());
|
|
98
|
+
info.GetReturnValue().Set(ConvertToV8String(isolate, encoding));
|
|
99
|
+
canvas_native_string_destroy((char*)encoding);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
info.GetReturnValue().SetEmptyString();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
void TextDecoderImpl::Decode(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
106
|
+
TextDecoderImpl *ptr = GetPointer(args.This());
|
|
107
|
+
if (ptr == nullptr) {
|
|
108
|
+
args.GetReturnValue().SetEmptyString();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
auto isolate = args.GetIsolate();
|
|
112
|
+
auto context = isolate->GetCurrentContext();
|
|
113
|
+
|
|
114
|
+
if (args.Length() == 1) {
|
|
115
|
+
auto value = args[0];
|
|
116
|
+
if (value->IsNull() ||
|
|
117
|
+
value->IsUndefined() ||
|
|
118
|
+
!value->IsObject()) {
|
|
119
|
+
|
|
120
|
+
args.GetIsolate()->ThrowError(
|
|
121
|
+
"Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'"
|
|
122
|
+
);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
auto buf = value.As<v8::Object>();
|
|
127
|
+
|
|
128
|
+
if (buf->IsArrayBuffer()) {
|
|
129
|
+
|
|
130
|
+
auto buffer = buf.As<v8::ArrayBuffer>();
|
|
131
|
+
|
|
132
|
+
auto data = static_cast<u_int8_t *>(buffer->GetBackingStore()->Data());
|
|
133
|
+
auto size = buffer->ByteLength();
|
|
134
|
+
auto decoded = canvas_native_text_decoder_decode(
|
|
135
|
+
ptr->GetTextDecoder(),
|
|
136
|
+
data, size);
|
|
137
|
+
//args.GetReturnValue().Set(ConvertToV8String(isolate, decoded.c_str()));
|
|
138
|
+
auto returnValue = new OneByteStringResource((char *)decoded);
|
|
139
|
+
auto ret = v8::String::NewExternalOneByte(isolate, returnValue);
|
|
140
|
+
args.GetReturnValue().Set(ret.ToLocalChecked());
|
|
141
|
+
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
if (buf->IsArrayBufferView()) {
|
|
147
|
+
|
|
148
|
+
auto buffer = buf.As<v8::ArrayBufferView>();
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
auto store = buffer->Buffer()->GetBackingStore();
|
|
152
|
+
auto buffer_data = static_cast<uint8_t *>(store->Data()) + buffer->ByteOffset();
|
|
153
|
+
|
|
154
|
+
auto len = buffer->ByteLength();
|
|
155
|
+
|
|
156
|
+
// v8::Local<v8::Value> size;
|
|
157
|
+
//
|
|
158
|
+
// buf->Get(context, ConvertToV8String(isolate, "BYTES_PER_ELEMENT")).ToLocal(&size);
|
|
159
|
+
//
|
|
160
|
+
// size_t len = 0;
|
|
161
|
+
//
|
|
162
|
+
// if(!size.IsEmpty()){
|
|
163
|
+
// len = buffer->Length() * (size_t)size->NumberValue(context).FromMaybe(0);
|
|
164
|
+
// }
|
|
165
|
+
|
|
166
|
+
// auto len = buffer->ByteLength();
|
|
167
|
+
|
|
168
|
+
auto decoded = canvas_native_text_decoder_decode(
|
|
169
|
+
ptr->GetTextDecoder(),
|
|
170
|
+
buffer_data, len);
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
// args.GetReturnValue().Set(ConvertToV8String(isolate, decoded.c_str()));
|
|
174
|
+
auto returnValue = new OneByteStringResource((char*) decoded);
|
|
175
|
+
auto ret = v8::String::NewExternalOneByte(isolate, returnValue);
|
|
176
|
+
args.GetReturnValue().Set(ret.ToLocalChecked());
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
args.GetIsolate()->ThrowError(
|
|
182
|
+
"Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
args.GetReturnValue().SetEmptyString();
|
|
188
|
+
}
|
|
@@ -3,26 +3,32 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
#pragma once
|
|
6
|
-
|
|
7
|
-
#include "rust/cxx.h"
|
|
8
|
-
#include "canvas-cxx/src/lib.rs.h"
|
|
9
|
-
#include <NativeScript/JSIRuntime.h>
|
|
10
6
|
#include <vector>
|
|
11
|
-
#include "
|
|
12
|
-
|
|
13
|
-
using namespace facebook;
|
|
14
|
-
using namespace org::nativescript::canvas;
|
|
7
|
+
#include "Common.h"
|
|
15
8
|
|
|
16
|
-
class
|
|
9
|
+
class TextDecoderImpl {
|
|
17
10
|
public:
|
|
18
|
-
TextDecoderImpl(
|
|
11
|
+
TextDecoderImpl(TextDecoder* decoder);
|
|
12
|
+
|
|
13
|
+
~TextDecoderImpl(){
|
|
14
|
+
canvas_native_text_decoder_destroy(this->GetTextDecoder());
|
|
15
|
+
this->decoder_ = nullptr;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
TextDecoder* GetTextDecoder();
|
|
19
|
+
|
|
20
|
+
static void Init(const v8::Local<v8::Object>& canvasModule, v8::Isolate *isolate);
|
|
21
|
+
|
|
22
|
+
static TextDecoderImpl *GetPointer(v8::Local<v8::Object> object);
|
|
23
|
+
|
|
24
|
+
static v8::Local<v8::FunctionTemplate> GetCtor(v8::Isolate *isolate);
|
|
19
25
|
|
|
20
|
-
|
|
26
|
+
static void Ctor(const v8::FunctionCallbackInfo<v8::Value> &args);
|
|
21
27
|
|
|
22
|
-
|
|
28
|
+
static void Decode(const v8::FunctionCallbackInfo<v8::Value> &args);
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
static void Encoding(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value> &info);
|
|
25
31
|
|
|
26
32
|
private:
|
|
27
|
-
|
|
33
|
+
TextDecoder* decoder_;
|
|
28
34
|
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Created by Osei Fortune on 19/04/2022.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#include "TextEncoderImpl.h"
|
|
6
|
+
#include "Caches.h"
|
|
7
|
+
#include "Helpers.h"
|
|
8
|
+
#include "Common.h"
|
|
9
|
+
|
|
10
|
+
TextEncoderImpl::TextEncoderImpl(TextEncoder* encoder) : encoder_(encoder) {}
|
|
11
|
+
|
|
12
|
+
void TextEncoderImpl::Init(const v8::Local<v8::Object>& canvasModule, v8::Isolate *isolate) {
|
|
13
|
+
v8::Locker locker(isolate);
|
|
14
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
15
|
+
v8::HandleScope handle_scope(isolate);
|
|
16
|
+
|
|
17
|
+
auto ctor = GetCtor(isolate);
|
|
18
|
+
auto context = isolate->GetCurrentContext();
|
|
19
|
+
auto func = ctor->GetFunction(context).ToLocalChecked();
|
|
20
|
+
|
|
21
|
+
canvasModule->Set(context, ConvertToV8String(isolate, "TextEncoder"), func);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
TextEncoderImpl *TextEncoderImpl::GetPointer(v8::Local<v8::Object> object) {
|
|
26
|
+
auto ptr = object->GetInternalField(0).As<v8::External>()->Value();
|
|
27
|
+
if (ptr == nullptr) {
|
|
28
|
+
return nullptr;
|
|
29
|
+
}
|
|
30
|
+
return static_cast<TextEncoderImpl *>(ptr);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
v8::Local<v8::FunctionTemplate> TextEncoderImpl::GetCtor(v8::Isolate *isolate) {
|
|
35
|
+
auto cache = Caches::Get(isolate);
|
|
36
|
+
auto ctor = cache->TextEncoderTmpl.get();
|
|
37
|
+
if (ctor != nullptr) {
|
|
38
|
+
return ctor->Get(isolate);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
v8::Local<v8::FunctionTemplate> ctorTmpl = v8::FunctionTemplate::New(isolate, Ctor);
|
|
42
|
+
ctorTmpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
43
|
+
ctorTmpl->SetClassName(ConvertToV8String(isolate, "TextEncoder"));
|
|
44
|
+
|
|
45
|
+
auto tmpl = ctorTmpl->InstanceTemplate();
|
|
46
|
+
tmpl->SetInternalFieldCount(1);
|
|
47
|
+
tmpl->SetAccessor(
|
|
48
|
+
ConvertToV8String(isolate, "encoding"),
|
|
49
|
+
Encoding);
|
|
50
|
+
tmpl->Set(
|
|
51
|
+
ConvertToV8String(isolate, "encode"),
|
|
52
|
+
v8::FunctionTemplate::New(isolate, &Encode));
|
|
53
|
+
cache->TextEncoderTmpl =
|
|
54
|
+
std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
|
|
55
|
+
return ctorTmpl;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
void TextEncoderImpl::Ctor(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
60
|
+
auto count = args.Length();
|
|
61
|
+
auto value = args[0];
|
|
62
|
+
auto isolate = args.GetIsolate();
|
|
63
|
+
if (count == 1 && !value->IsString()) {
|
|
64
|
+
auto label = value->ToString(isolate->GetCurrentContext()).ToLocalChecked();
|
|
65
|
+
auto arg = ConvertFromV8String(isolate, label);
|
|
66
|
+
auto error = "Failed to construct 'TextEncoder': The encoding label provided (" +
|
|
67
|
+
arg + "') is invalid";
|
|
68
|
+
isolate->ThrowError(ConvertToV8String(isolate, error));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
std::string encoding("utf-8");
|
|
73
|
+
if (count == 1) {
|
|
74
|
+
encoding = ConvertFromV8String(isolate, value);
|
|
75
|
+
}
|
|
76
|
+
auto encoder = canvas_native_text_encoder_create(encoding.c_str());
|
|
77
|
+
|
|
78
|
+
auto ret = args.This();
|
|
79
|
+
|
|
80
|
+
auto txtEncoder = new TextEncoderImpl(encoder);
|
|
81
|
+
|
|
82
|
+
auto ext = v8::External::New(isolate, txtEncoder);
|
|
83
|
+
|
|
84
|
+
ret->SetInternalField(0, ext);
|
|
85
|
+
|
|
86
|
+
args.GetReturnValue().Set(ret);
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
void
|
|
92
|
+
TextEncoderImpl::Encoding(v8::Local<v8::String> name,
|
|
93
|
+
const v8::PropertyCallbackInfo<v8::Value> &info) {
|
|
94
|
+
auto ptr = GetPointer(info.This());
|
|
95
|
+
if (ptr != nullptr) {
|
|
96
|
+
auto isolate = info.GetIsolate();
|
|
97
|
+
auto encoding = canvas_native_text_encoder_get_encoding(ptr->GetTextEncoder());
|
|
98
|
+
info.GetReturnValue().Set(ConvertToV8String(isolate, encoding));
|
|
99
|
+
canvas_native_string_destroy((char*)encoding);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
info.GetReturnValue().SetEmptyString();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
void TextEncoderImpl::Encode(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
106
|
+
TextEncoderImpl *ptr = GetPointer(args.This());
|
|
107
|
+
if (ptr == nullptr) {
|
|
108
|
+
args.GetReturnValue().SetUndefined();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
auto isolate = args.GetIsolate();
|
|
112
|
+
|
|
113
|
+
auto text = args[0];
|
|
114
|
+
|
|
115
|
+
auto encoded = canvas_native_text_encoder_encode(ptr->GetTextEncoder(), ConvertFromV8String(isolate, text).c_str());
|
|
116
|
+
|
|
117
|
+
auto data = canvas_native_u8_buffer_get_bytes_mut(encoded);
|
|
118
|
+
|
|
119
|
+
auto length = canvas_native_u8_buffer_get_length(encoded);
|
|
120
|
+
|
|
121
|
+
auto store = v8::ArrayBuffer::NewBackingStore(data, length,
|
|
122
|
+
[](void *data, size_t length,
|
|
123
|
+
void *deleter_data) {
|
|
124
|
+
if (deleter_data != nullptr) {
|
|
125
|
+
canvas_native_u8_buffer_destroy((U8Buffer *)deleter_data);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
encoded);
|
|
129
|
+
|
|
130
|
+
auto buf = v8::ArrayBuffer::New(isolate, std::move(store));
|
|
131
|
+
|
|
132
|
+
auto ret = v8::Uint8ClampedArray::New(buf, 0, length);
|
|
133
|
+
|
|
134
|
+
args.GetReturnValue().Set(ret);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
TextEncoder* TextEncoderImpl::GetTextEncoder() {
|
|
138
|
+
return this->encoder_;
|
|
139
|
+
}
|
|
@@ -4,25 +4,34 @@
|
|
|
4
4
|
|
|
5
5
|
#pragma once
|
|
6
6
|
|
|
7
|
-
#include "rust/cxx.h"
|
|
8
|
-
#include "canvas-cxx/src/lib.rs.h"
|
|
9
|
-
#include "VecMutableBuffer.h"
|
|
10
7
|
#include <vector>
|
|
8
|
+
#include "Common.h"
|
|
11
9
|
|
|
12
|
-
using namespace facebook;
|
|
13
|
-
using namespace org::nativescript::canvas;
|
|
14
10
|
|
|
15
|
-
class
|
|
11
|
+
class TextEncoderImpl {
|
|
16
12
|
|
|
17
13
|
public:
|
|
18
|
-
TextEncoderImpl(
|
|
14
|
+
TextEncoderImpl(TextEncoder* encoder);
|
|
15
|
+
~TextEncoderImpl() {
|
|
16
|
+
canvas_native_text_encoder_destroy(this->GetTextEncoder());
|
|
17
|
+
this->encoder_ = nullptr;
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
TextEncoder* GetTextEncoder();
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
static void Init(const v8::Local<v8::Object>& canvasModule, v8::Isolate *isolate);
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
static TextEncoderImpl *GetPointer(v8::Local<v8::Object> object);
|
|
25
|
+
|
|
26
|
+
static v8::Local<v8::FunctionTemplate> GetCtor(v8::Isolate *isolate);
|
|
27
|
+
|
|
28
|
+
static void Ctor(const v8::FunctionCallbackInfo<v8::Value> &args);
|
|
29
|
+
|
|
30
|
+
static void Encode(const v8::FunctionCallbackInfo<v8::Value> &args);
|
|
31
|
+
|
|
32
|
+
static void
|
|
33
|
+
Encoding(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value> &info);
|
|
25
34
|
|
|
26
35
|
private:
|
|
27
|
-
|
|
36
|
+
TextEncoder* encoder_;
|
|
28
37
|
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Created by Osei Fortune on 22/03/2022.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#include "CanvasGradient.h"
|
|
6
|
+
#include "Helpers.h"
|
|
7
|
+
#include "Caches.h"
|
|
8
|
+
|
|
9
|
+
CanvasGradient::CanvasGradient(PaintStyle* style) : style_(style) {}
|
|
10
|
+
|
|
11
|
+
void CanvasGradient::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate) {
|
|
12
|
+
v8::Locker locker(isolate);
|
|
13
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
14
|
+
v8::HandleScope handle_scope(isolate);
|
|
15
|
+
|
|
16
|
+
auto ctor = GetCtor(isolate);
|
|
17
|
+
auto context = isolate->GetCurrentContext();
|
|
18
|
+
auto func = ctor->GetFunction(context).ToLocalChecked();
|
|
19
|
+
|
|
20
|
+
canvasModule->Set(context, ConvertToV8String(isolate, "CanvasGradient"), func);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
CanvasGradient *CanvasGradient::GetPointer(const v8::Local<v8::Object> &object) {
|
|
24
|
+
auto ptr = object->GetInternalField(0).As<v8::External>()->Value();
|
|
25
|
+
if (ptr == nullptr) {
|
|
26
|
+
return nullptr;
|
|
27
|
+
}
|
|
28
|
+
return static_cast<CanvasGradient *>(ptr);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
v8::Local<v8::FunctionTemplate> CanvasGradient::GetCtor(v8::Isolate *isolate) {
|
|
32
|
+
auto cache = Caches::Get(isolate);
|
|
33
|
+
auto ctor = cache->CanvasGradientTmpl.get();
|
|
34
|
+
if (ctor != nullptr) {
|
|
35
|
+
return ctor->Get(isolate);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
v8::Local<v8::FunctionTemplate> ctorTmpl = v8::FunctionTemplate::New(isolate);
|
|
39
|
+
ctorTmpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
40
|
+
ctorTmpl->SetClassName(ConvertToV8String(isolate, "CanvasGradient"));
|
|
41
|
+
|
|
42
|
+
auto tmpl = ctorTmpl->InstanceTemplate();
|
|
43
|
+
tmpl->SetInternalFieldCount(1);
|
|
44
|
+
tmpl->Set(
|
|
45
|
+
ConvertToV8String(isolate, "addColorStop"),
|
|
46
|
+
v8::FunctionTemplate::New(isolate, &AddColorStop));
|
|
47
|
+
|
|
48
|
+
cache->CanvasGradientTmpl =
|
|
49
|
+
std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
|
|
50
|
+
return ctorTmpl;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void CanvasGradient::AddColorStop(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
54
|
+
CanvasGradient *ptr = GetPointer(args.This());
|
|
55
|
+
if (ptr == nullptr) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
auto isolate = args.GetIsolate();
|
|
60
|
+
auto context = isolate->GetCurrentContext();
|
|
61
|
+
|
|
62
|
+
auto stop = (float) args[0]->NumberValue(context).ToChecked();
|
|
63
|
+
auto color = ConvertFromV8String(isolate, args[1]);
|
|
64
|
+
canvas_native_gradient_add_color_stop(
|
|
65
|
+
ptr->GetPaintStyle(), stop, color.c_str());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
PaintStyle *CanvasGradient::GetPaintStyle() {
|
|
69
|
+
return this->style_;
|
|
70
|
+
}
|
|
71
|
+
|
|
@@ -3,26 +3,40 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
#pragma once
|
|
6
|
-
|
|
7
|
-
#include "rust/cxx.h"
|
|
8
|
-
#include "canvas-cxx/src/lib.rs.h"
|
|
9
|
-
#import <NativeScript/JSIRuntime.h>
|
|
10
6
|
#include <vector>
|
|
7
|
+
#include "Common.h"
|
|
8
|
+
#include "Helpers.h"
|
|
9
|
+
class CanvasGradient {
|
|
10
|
+
public:
|
|
11
|
+
CanvasGradient(PaintStyle*style);
|
|
12
|
+
|
|
13
|
+
~CanvasGradient(){
|
|
14
|
+
canvas_native_paint_style_destroy(this->GetPaintStyle());
|
|
15
|
+
this->style_ = nullptr;
|
|
16
|
+
}
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
using namespace ::org::nativescript::canvas;
|
|
18
|
+
PaintStyle * GetPaintStyle();
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
CanvasGradient(
|
|
20
|
+
static void Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate);
|
|
21
|
+
|
|
22
|
+
static CanvasGradient *GetPointer(const v8::Local<v8::Object> &object);
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
static v8::Local<v8::FunctionTemplate> GetCtor(v8::Isolate *isolate);
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
static v8::Local<v8::Object> NewInstance(v8::Isolate *isolate, CanvasGradient *gradient) {
|
|
27
|
+
auto context = isolate->GetCurrentContext();
|
|
28
|
+
v8::EscapableHandleScope scope(isolate);
|
|
29
|
+
auto object = CanvasGradient::GetCtor(isolate)->GetFunction(
|
|
30
|
+
context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
|
|
31
|
+
SetNativeType(isolate, object, NativeType::CanvasGradient);
|
|
32
|
+
auto ext = v8::External::New(isolate, gradient);
|
|
33
|
+
object->SetInternalField(0, ext);
|
|
34
|
+
return scope.Escape(object);
|
|
35
|
+
}
|
|
22
36
|
|
|
23
|
-
|
|
37
|
+
static void AddColorStop(const v8::FunctionCallbackInfo<v8::Value> &args);
|
|
24
38
|
|
|
25
39
|
private:
|
|
26
|
-
|
|
40
|
+
PaintStyle* style_;
|
|
27
41
|
};
|
|
28
42
|
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Created by Osei Fortune on 22/03/2022.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#include "CanvasPattern.h"
|
|
6
|
+
#include "Helpers.h"
|
|
7
|
+
#include "Caches.h"
|
|
8
|
+
|
|
9
|
+
CanvasPattern::CanvasPattern(PaintStyle* style) : style_(style) {}
|
|
10
|
+
|
|
11
|
+
void CanvasPattern::Init(const v8::Local<v8::Object> &canvasModule, v8::Isolate *isolate) {
|
|
12
|
+
v8::Locker locker(isolate);
|
|
13
|
+
v8::Isolate::Scope isolate_scope(isolate);
|
|
14
|
+
v8::HandleScope handle_scope(isolate);
|
|
15
|
+
|
|
16
|
+
auto ctor = GetCtor(isolate);
|
|
17
|
+
auto context = isolate->GetCurrentContext();
|
|
18
|
+
auto func = ctor->GetFunction(context).ToLocalChecked();
|
|
19
|
+
|
|
20
|
+
canvasModule->Set(context, ConvertToV8String(isolate, "CanvasPattern"), func);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
CanvasPattern *CanvasPattern::GetPointer(const v8::Local<v8::Object> &object) {
|
|
24
|
+
auto ptr = object->GetInternalField(0).As<v8::External>()->Value();
|
|
25
|
+
if (ptr == nullptr) {
|
|
26
|
+
return nullptr;
|
|
27
|
+
}
|
|
28
|
+
return static_cast<CanvasPattern *>(ptr);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static v8::Local<v8::Object> NewInstance(v8::Isolate *isolate, CanvasPattern *pattern) {
|
|
32
|
+
auto context = isolate->GetCurrentContext();
|
|
33
|
+
v8::EscapableHandleScope scope(isolate);
|
|
34
|
+
auto object = CanvasPattern::GetCtor(isolate)->GetFunction(
|
|
35
|
+
context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
|
|
36
|
+
SetNativeType(isolate, object, NativeType::CanvasPattern);
|
|
37
|
+
auto ext = v8::External::New(isolate, pattern);
|
|
38
|
+
object->SetInternalField(0, ext);
|
|
39
|
+
return scope.Escape(object);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
v8::Local<v8::FunctionTemplate> CanvasPattern::GetCtor(v8::Isolate *isolate) {
|
|
43
|
+
auto cache = Caches::Get(isolate);
|
|
44
|
+
auto ctor = cache->CanvasPatternTmpl.get();
|
|
45
|
+
if (ctor != nullptr) {
|
|
46
|
+
return ctor->Get(isolate);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
v8::Local<v8::FunctionTemplate> ctorTmpl = v8::FunctionTemplate::New(isolate);
|
|
50
|
+
ctorTmpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
51
|
+
ctorTmpl->SetClassName(ConvertToV8String(isolate, "CanvasPattern"));
|
|
52
|
+
|
|
53
|
+
auto tmpl = ctorTmpl->InstanceTemplate();
|
|
54
|
+
tmpl->SetInternalFieldCount(1);
|
|
55
|
+
tmpl->Set(
|
|
56
|
+
ConvertToV8String(isolate, "SetTransform"),
|
|
57
|
+
v8::FunctionTemplate::New(isolate, &SetTransform));
|
|
58
|
+
|
|
59
|
+
cache->CanvasPatternTmpl =
|
|
60
|
+
std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
|
|
61
|
+
return ctorTmpl;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
void CanvasPattern::SetTransform(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
65
|
+
CanvasPattern *ptr = GetPointer(args.This());
|
|
66
|
+
if (ptr == nullptr) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
auto isolate = args.GetIsolate();
|
|
71
|
+
|
|
72
|
+
auto value = args[0];
|
|
73
|
+
auto type = GetNativeType(isolate, value);
|
|
74
|
+
|
|
75
|
+
if (type == NativeType::Matrix) {
|
|
76
|
+
|
|
77
|
+
auto matrix = MatrixImpl::GetPointer(value.As<v8::Object>());
|
|
78
|
+
if (matrix != nullptr) {
|
|
79
|
+
canvas_native_pattern_set_transform(
|
|
80
|
+
ptr->GetPaintStyle(),
|
|
81
|
+
matrix->GetMatrix());
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
PaintStyle* CanvasPattern::GetPaintStyle() {
|
|
88
|
+
return this->style_;
|
|
89
|
+
}
|
|
@@ -3,27 +3,40 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
#pragma once
|
|
6
|
-
|
|
7
|
-
#include "rust/cxx.h"
|
|
8
|
-
#include "canvas-cxx/src/lib.rs.h"
|
|
9
|
-
#import <NativeScript/JSIRuntime.h>
|
|
10
6
|
#include "MatrixImpl.h"
|
|
11
7
|
#include <vector>
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
using namespace org::nativescript::canvas;
|
|
15
|
-
|
|
16
|
-
class JSI_EXPORT CanvasPattern : public jsi::HostObject {
|
|
9
|
+
class CanvasPattern {
|
|
17
10
|
public:
|
|
18
|
-
CanvasPattern(
|
|
11
|
+
CanvasPattern(PaintStyle* style);
|
|
12
|
+
|
|
13
|
+
~CanvasPattern() {
|
|
14
|
+
canvas_native_paint_style_destroy(this->GetPaintStyle());
|
|
15
|
+
this->style_ = nullptr;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
PaintStyle* GetPaintStyle();
|
|
19
|
+
|
|
20
|
+
static void Init(const v8::Local<v8::Object> &canvasModule, v8::Isolate *isolate);
|
|
21
|
+
|
|
22
|
+
static CanvasPattern *GetPointer(const v8::Local<v8::Object> &object);
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
static v8::Local<v8::Object> NewInstance(v8::Isolate *isolate, CanvasPattern *pattern) {
|
|
25
|
+
auto context = isolate->GetCurrentContext();
|
|
26
|
+
v8::EscapableHandleScope scope(isolate);
|
|
27
|
+
auto object = CanvasPattern::GetCtor(isolate)->GetFunction(
|
|
28
|
+
context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
|
|
29
|
+
SetNativeType(isolate, object, NativeType::CanvasPattern);
|
|
30
|
+
auto ext = v8::External::New(isolate, pattern);
|
|
31
|
+
object->SetInternalField(0, ext);
|
|
32
|
+
return scope.Escape(object);
|
|
33
|
+
}
|
|
21
34
|
|
|
22
|
-
|
|
35
|
+
static v8::Local<v8::FunctionTemplate> GetCtor(v8::Isolate *isolate);
|
|
23
36
|
|
|
24
|
-
|
|
37
|
+
static void SetTransform(const v8::FunctionCallbackInfo<v8::Value> &args);
|
|
25
38
|
|
|
26
39
|
private:
|
|
27
|
-
|
|
40
|
+
PaintStyle* style_;
|
|
28
41
|
};
|
|
29
42
|
|