@shopify/react-native-skia 0.1.155 → 0.1.156
Sign up to get free protection for your applications and to get access to all the features.
- package/android/cpp/jni/JniLoad.cpp +5 -5
- package/android/cpp/jni/JniPlatformContext.cpp +107 -119
- package/android/cpp/jni/JniSkiaManager.cpp +18 -20
- package/android/cpp/jni/include/JniPlatformContext.h +41 -45
- package/android/cpp/jni/include/JniSkiaBaseView.h +52 -55
- package/android/cpp/jni/include/JniSkiaDrawView.h +72 -77
- package/android/cpp/jni/include/JniSkiaManager.h +51 -53
- package/android/cpp/jni/include/JniSkiaPictureView.h +74 -78
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +36 -45
- package/android/cpp/rnskia-android/RNSkAndroidView.h +87 -92
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +62 -65
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +20 -17
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +257 -313
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +107 -110
- package/cpp/api/JsiSkApi.h +66 -62
- package/cpp/api/JsiSkCanvas.h +38 -30
- package/cpp/api/JsiSkColor.h +58 -56
- package/cpp/api/JsiSkColorFilter.h +5 -3
- package/cpp/api/JsiSkColorFilterFactory.h +23 -21
- package/cpp/api/JsiSkContourMeasure.h +74 -85
- package/cpp/api/JsiSkContourMeasureIter.h +68 -75
- package/cpp/api/JsiSkData.h +16 -22
- package/cpp/api/JsiSkDataFactory.h +86 -79
- package/cpp/api/JsiSkFont.h +286 -311
- package/cpp/api/JsiSkHostObjects.h +15 -16
- package/cpp/api/JsiSkImage.h +107 -103
- package/cpp/api/JsiSkImageFactory.h +34 -36
- package/cpp/api/JsiSkImageFilter.h +5 -3
- package/cpp/api/JsiSkImageFilterFactory.h +71 -68
- package/cpp/api/JsiSkImageInfo.h +41 -38
- package/cpp/api/JsiSkMaskFilter.h +5 -3
- package/cpp/api/JsiSkMaskFilterFactory.h +2 -3
- package/cpp/api/JsiSkMatrix.h +26 -36
- package/cpp/api/JsiSkPaint.h +20 -13
- package/cpp/api/JsiSkPath.h +70 -85
- package/cpp/api/JsiSkPathEffect.h +5 -3
- package/cpp/api/JsiSkPathEffectFactory.h +33 -28
- package/cpp/api/JsiSkPathFactory.h +68 -67
- package/cpp/api/JsiSkPicture.h +28 -22
- package/cpp/api/JsiSkPictureFactory.h +13 -12
- package/cpp/api/JsiSkPictureRecorder.h +21 -19
- package/cpp/api/JsiSkPoint.h +6 -8
- package/cpp/api/JsiSkRRect.h +11 -7
- package/cpp/api/JsiSkRSXform.h +82 -85
- package/cpp/api/JsiSkRect.h +9 -9
- package/cpp/api/JsiSkRuntimeEffect.h +182 -186
- package/cpp/api/JsiSkRuntimeEffectFactory.h +10 -11
- package/cpp/api/JsiSkRuntimeShaderBuilder.h +64 -61
- package/cpp/api/JsiSkSVG.h +4 -5
- package/cpp/api/JsiSkSVGFactory.h +28 -27
- package/cpp/api/JsiSkShader.h +3 -2
- package/cpp/api/JsiSkShaderFactory.h +37 -25
- package/cpp/api/JsiSkSurface.h +44 -40
- package/cpp/api/JsiSkSurfaceFactory.h +22 -22
- package/cpp/api/JsiSkTextBlob.h +28 -31
- package/cpp/api/JsiSkTextBlobFactory.h +88 -87
- package/cpp/api/JsiSkTypeface.h +6 -5
- package/cpp/api/JsiSkTypefaceFactory.h +22 -21
- package/cpp/api/JsiSkVertices.h +137 -124
- package/cpp/api/third_party/CSSColorParser.cpp +161 -174
- package/cpp/api/third_party/CSSColorParser.h +172 -96
- package/cpp/jsi/JsiHostObject.cpp +11 -9
- package/cpp/jsi/JsiHostObject.h +31 -24
- package/cpp/jsi/JsiSimpleValueWrapper.h +74 -83
- package/cpp/jsi/JsiValueWrapper.h +52 -54
- package/cpp/rnskia/RNSkAnimation.h +26 -29
- package/cpp/rnskia/RNSkDispatchQueue.cpp +50 -61
- package/cpp/rnskia/RNSkDispatchQueue.h +3 -1
- package/cpp/rnskia/RNSkInfoParameter.h +12 -12
- package/cpp/rnskia/RNSkJsView.cpp +82 -81
- package/cpp/rnskia/RNSkJsView.h +45 -41
- package/cpp/rnskia/RNSkJsiViewApi.h +99 -89
- package/cpp/rnskia/RNSkManager.cpp +8 -7
- package/cpp/rnskia/RNSkManager.h +8 -6
- package/cpp/rnskia/RNSkPictureView.h +44 -37
- package/cpp/rnskia/RNSkPlatformContext.h +39 -28
- package/cpp/rnskia/RNSkValueApi.h +33 -34
- package/cpp/rnskia/RNSkView.h +108 -93
- package/cpp/rnskia/values/RNSkClockValue.h +63 -64
- package/cpp/rnskia/values/RNSkComputedValue.h +32 -30
- package/cpp/rnskia/values/RNSkReadonlyValue.h +60 -59
- package/cpp/rnskia/values/RNSkValue.h +38 -40
- package/cpp/utils/RNSkLog.h +9 -7
- package/cpp/utils/RNSkMeasureTime.h +7 -7
- package/cpp/utils/RNSkTimingInfo.h +27 -24
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +8 -9
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +24 -23
- package/ios/RNSkia-iOS/RNSkiOSView.h +16 -13
- package/ios/RNSkia-iOS/SkiaUIView.h +9 -8
- package/lib/commonjs/dom/nodes/JsiSkDOM.js +6 -0
- package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/commonjs/dom/nodes/LayerNode.js +43 -0
- package/lib/commonjs/dom/nodes/LayerNode.js.map +1 -0
- package/lib/commonjs/dom/types/NodeType.js +1 -0
- package/lib/commonjs/dom/types/NodeType.js.map +1 -1
- package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
- package/lib/commonjs/renderer/HostComponents.js +3 -0
- package/lib/commonjs/renderer/HostComponents.js.map +1 -1
- package/lib/commonjs/renderer/components/Group.js +19 -4
- package/lib/commonjs/renderer/components/Group.js.map +1 -1
- package/lib/commonjs/renderer/components/Paint.js +6 -1
- package/lib/commonjs/renderer/components/Paint.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.js +3 -2
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaView.js +6 -3
- package/lib/commonjs/views/SkiaView.js.map +1 -1
- package/lib/module/dom/nodes/JsiSkDOM.js +5 -0
- package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/module/dom/nodes/LayerNode.js +32 -0
- package/lib/module/dom/nodes/LayerNode.js.map +1 -0
- package/lib/module/dom/types/NodeType.js +1 -0
- package/lib/module/dom/types/NodeType.js.map +1 -1
- package/lib/module/dom/types/SkDOM.js.map +1 -1
- package/lib/module/renderer/HostComponents.js +3 -0
- package/lib/module/renderer/HostComponents.js.map +1 -1
- package/lib/module/renderer/components/Group.js +16 -3
- package/lib/module/renderer/components/Group.js.map +1 -1
- package/lib/module/renderer/components/Paint.js +7 -1
- package/lib/module/renderer/components/Paint.js.map +1 -1
- package/lib/module/views/SkiaPictureView.js +2 -2
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaView.js +4 -2
- package/lib/module/views/SkiaView.js.map +1 -1
- package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
- package/lib/typescript/src/dom/nodes/LayerNode.d.ts +8 -0
- package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
- package/lib/typescript/src/dom/types/SkDOM.d.ts +1 -0
- package/lib/typescript/src/renderer/HostComponents.d.ts +2 -1
- package/lib/typescript/src/renderer/components/Group.d.ts +5 -1
- package/lib/typescript/src/views/SkiaView.d.ts +3 -0
- package/libs/android/arm64-v8a/libskottie.a +0 -0
- package/libs/android/arm64-v8a/libsksg.a +0 -0
- package/libs/android/armeabi-v7a/libskottie.a +0 -0
- package/libs/android/armeabi-v7a/libsksg.a +0 -0
- package/libs/android/x86/libskottie.a +0 -0
- package/libs/android/x86/libsksg.a +0 -0
- package/libs/android/x86_64/libskottie.a +0 -0
- package/libs/android/x86_64/libsksg.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskottie.xcframework/Info.plist +42 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
- package/libs/ios/libsksg.xcframework/Info.plist +42 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
- package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libsvg.xcframework/Info.plist +5 -5
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +3 -1
- package/src/dom/nodes/JsiSkDOM.ts +5 -0
- package/src/dom/nodes/LayerNode.ts +35 -0
- package/src/dom/types/NodeType.ts +1 -0
- package/src/dom/types/SkDOM.ts +1 -0
- package/src/renderer/HostComponents.ts +3 -0
- package/src/renderer/components/Group.tsx +16 -3
- package/src/renderer/components/Paint.tsx +7 -1
- package/src/views/SkiaPictureView.tsx +2 -3
- package/src/views/SkiaView.tsx +2 -2
package/cpp/api/JsiSkFont.h
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
3
|
#include <memory>
|
4
|
+
#include <numeric>
|
4
5
|
#include <utility>
|
5
6
|
#include <vector>
|
6
|
-
#include <numeric>
|
7
7
|
|
8
|
-
#include <jsi/jsi.h>
|
9
8
|
#include "JsiSkHostObjects.h"
|
10
9
|
#include <RNSkLog.h>
|
10
|
+
#include <jsi/jsi.h>
|
11
11
|
|
12
12
|
#include "JsiSkPaint.h"
|
13
|
+
#include "JsiSkPoint.h"
|
13
14
|
#include "JsiSkRect.h"
|
14
15
|
#include "JsiSkTypeface.h"
|
15
|
-
#include "JsiSkPoint.h"
|
16
|
-
|
17
16
|
|
18
17
|
#pragma clang diagnostic push
|
19
18
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
@@ -23,313 +22,289 @@
|
|
23
22
|
|
24
23
|
#pragma clang diagnostic pop
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
int
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
{
|
308
|
-
return JSI_HOST_FUNCTION_LAMBDA
|
309
|
-
{
|
310
|
-
// Handle arguments
|
311
|
-
if (count == 2)
|
312
|
-
{
|
313
|
-
auto typeface = JsiSkTypeface::fromValue(runtime, arguments[0]);
|
314
|
-
auto size = arguments[1].asNumber();
|
315
|
-
return jsi::Object::createFromHostObject(
|
316
|
-
runtime,
|
317
|
-
std::make_shared<JsiSkFont>(std::move(context), SkFont(typeface, size)));
|
318
|
-
}
|
319
|
-
else if (count == 1)
|
320
|
-
{
|
321
|
-
auto typeface = JsiSkTypeface::fromValue(runtime, arguments[0]);
|
322
|
-
return jsi::Object::createFromHostObject(
|
323
|
-
runtime, std::make_shared<JsiSkFont>(std::move(context), SkFont(typeface)));
|
324
|
-
}
|
325
|
-
else
|
326
|
-
{
|
327
|
-
// Return the newly constructed object
|
328
|
-
return jsi::Object::createFromHostObject(
|
329
|
-
runtime, std::make_shared<JsiSkFont>(std::move(context), SkFont()));
|
330
|
-
}
|
331
|
-
};
|
332
|
-
}
|
25
|
+
namespace RNSkia {
|
26
|
+
|
27
|
+
namespace jsi = facebook::jsi;
|
28
|
+
|
29
|
+
class JsiSkFont : public JsiSkWrappingSharedPtrHostObject<SkFont> {
|
30
|
+
public:
|
31
|
+
// TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
|
32
|
+
JSI_PROPERTY_GET(__typename__) {
|
33
|
+
return jsi::String::createFromUtf8(runtime, "Font");
|
34
|
+
}
|
35
|
+
|
36
|
+
JSI_HOST_FUNCTION(getGlyphWidths) {
|
37
|
+
auto jsiGlyphs = arguments[0].asObject(runtime).asArray(runtime);
|
38
|
+
std::vector<SkGlyphID> glyphs;
|
39
|
+
int glyphsSize = static_cast<int>(jsiGlyphs.size(runtime));
|
40
|
+
|
41
|
+
std::vector<SkScalar> widthPtrs;
|
42
|
+
widthPtrs.resize(glyphsSize);
|
43
|
+
|
44
|
+
glyphs.reserve(glyphsSize);
|
45
|
+
for (int i = 0; i < glyphsSize; i++) {
|
46
|
+
glyphs.push_back(jsiGlyphs.getValueAtIndex(runtime, i).asNumber());
|
47
|
+
}
|
48
|
+
if (count > 1) {
|
49
|
+
auto paint = JsiSkPaint::fromValue(runtime, arguments[1]);
|
50
|
+
getObject()->getWidthsBounds(glyphs.data(), glyphsSize,
|
51
|
+
static_cast<SkScalar *>(widthPtrs.data()),
|
52
|
+
nullptr, paint.get());
|
53
|
+
} else {
|
54
|
+
getObject()->getWidthsBounds(glyphs.data(), glyphsSize,
|
55
|
+
static_cast<SkScalar *>(widthPtrs.data()),
|
56
|
+
nullptr, nullptr);
|
57
|
+
}
|
58
|
+
auto jsiWidths = jsi::Array(runtime, glyphsSize);
|
59
|
+
for (int i = 0; i < glyphsSize; i++) {
|
60
|
+
jsiWidths.setValueAtIndex(
|
61
|
+
runtime, i,
|
62
|
+
jsi::Value(
|
63
|
+
SkScalarToDouble(static_cast<SkScalar *>(widthPtrs.data())[i])));
|
64
|
+
}
|
65
|
+
return jsiWidths;
|
66
|
+
}
|
67
|
+
|
68
|
+
JSI_HOST_FUNCTION(getTextWidth) {
|
69
|
+
auto str = arguments[0].asString(runtime).utf8(runtime);
|
70
|
+
auto numGlyphIDs = getObject()->countText(str.c_str(), str.length(),
|
71
|
+
SkTextEncoding::kUTF8);
|
72
|
+
std::vector<SkGlyphID> glyphs;
|
73
|
+
glyphs.resize(numGlyphIDs);
|
74
|
+
int glyphsSize = static_cast<int>(numGlyphIDs);
|
75
|
+
getObject()->textToGlyphs(str.c_str(), str.length(), SkTextEncoding::kUTF8,
|
76
|
+
static_cast<SkGlyphID *>(glyphs.data()),
|
77
|
+
glyphsSize);
|
78
|
+
std::vector<SkScalar> widthPtrs;
|
79
|
+
widthPtrs.resize(numGlyphIDs);
|
80
|
+
if (count > 1) {
|
81
|
+
auto paint = JsiSkPaint::fromValue(runtime, arguments[1]);
|
82
|
+
getObject()->getWidthsBounds(glyphs.data(), glyphsSize,
|
83
|
+
static_cast<SkScalar *>(widthPtrs.data()),
|
84
|
+
nullptr, paint.get());
|
85
|
+
} else {
|
86
|
+
getObject()->getWidthsBounds(glyphs.data(), glyphsSize,
|
87
|
+
static_cast<SkScalar *>(widthPtrs.data()),
|
88
|
+
nullptr, nullptr);
|
89
|
+
}
|
90
|
+
return jsi::Value(std::accumulate(widthPtrs.begin(), widthPtrs.end(), 0));
|
91
|
+
}
|
92
|
+
|
93
|
+
JSI_HOST_FUNCTION(getMetrics) {
|
94
|
+
SkFontMetrics fm;
|
95
|
+
getObject()->getMetrics(&fm);
|
96
|
+
auto metrics = jsi::Object(runtime);
|
97
|
+
metrics.setProperty(runtime, "ascent", fm.fAscent);
|
98
|
+
metrics.setProperty(runtime, "descent", fm.fDescent);
|
99
|
+
metrics.setProperty(runtime, "leading", fm.fLeading);
|
100
|
+
if (!(fm.fFlags & SkFontMetrics::kBoundsInvalid_Flag)) {
|
101
|
+
auto bounds = SkRect::MakeLTRB(fm.fXMin, fm.fTop, fm.fXMax, fm.fBottom);
|
102
|
+
auto jsiBounds =
|
103
|
+
JsiSkRect::toValue(runtime, getContext(), std::move(bounds));
|
104
|
+
metrics.setProperty(runtime, "bounds", std::move(jsiBounds));
|
105
|
+
}
|
106
|
+
return metrics;
|
107
|
+
}
|
108
|
+
|
109
|
+
JSI_HOST_FUNCTION(getGlyphIDs) {
|
110
|
+
auto str = arguments[0].asString(runtime).utf8(runtime);
|
111
|
+
int numGlyphIDs =
|
112
|
+
count > 1 && !arguments[1].isNull() && !arguments[1].isUndefined()
|
113
|
+
? static_cast<int>(arguments[1].asNumber())
|
114
|
+
: getObject()->countText(str.c_str(), str.length(),
|
115
|
+
SkTextEncoding::kUTF8);
|
116
|
+
std::vector<SkGlyphID> glyphIDs;
|
117
|
+
glyphIDs.resize(numGlyphIDs);
|
118
|
+
getObject()->textToGlyphs(str.c_str(), str.length(), SkTextEncoding::kUTF8,
|
119
|
+
static_cast<SkGlyphID *>(glyphIDs.data()),
|
120
|
+
numGlyphIDs);
|
121
|
+
auto jsiGlyphIDs = jsi::Array(runtime, numGlyphIDs);
|
122
|
+
for (int i = 0; i < numGlyphIDs; i++) {
|
123
|
+
jsiGlyphIDs.setValueAtIndex(runtime, i,
|
124
|
+
jsi::Value(static_cast<int>(glyphIDs[i])));
|
125
|
+
}
|
126
|
+
return jsiGlyphIDs;
|
127
|
+
}
|
128
|
+
|
129
|
+
JSI_HOST_FUNCTION(getGlyphIntercepts) {
|
130
|
+
auto jsiGlyphs = arguments[0].asObject(runtime).asArray(runtime);
|
131
|
+
auto jsiPositions = arguments[1].asObject(runtime).asArray(runtime);
|
132
|
+
auto top = arguments[2].asNumber();
|
133
|
+
auto bottom = arguments[3].asNumber();
|
134
|
+
std::vector<SkPoint> positions;
|
135
|
+
int pointsSize = static_cast<int>(jsiPositions.size(runtime));
|
136
|
+
positions.reserve(pointsSize);
|
137
|
+
for (int i = 0; i < pointsSize; i++) {
|
138
|
+
std::shared_ptr<SkPoint> point = JsiSkPoint::fromValue(
|
139
|
+
runtime, jsiPositions.getValueAtIndex(runtime, i).asObject(runtime));
|
140
|
+
positions.push_back(*point.get());
|
141
|
+
}
|
142
|
+
|
143
|
+
std::vector<SkGlyphID> glyphs;
|
144
|
+
int glyphsSize = static_cast<int>(jsiGlyphs.size(runtime));
|
145
|
+
glyphs.reserve(glyphsSize);
|
146
|
+
for (int i = 0; i < glyphsSize; i++) {
|
147
|
+
glyphs.push_back(jsiGlyphs.getValueAtIndex(runtime, i).asNumber());
|
148
|
+
}
|
149
|
+
|
150
|
+
if (glyphs.size() > positions.size()) {
|
151
|
+
throw jsi::JSError(runtime, "Not enough x,y position pairs for glyphs");
|
152
|
+
return jsi::Value::null();
|
153
|
+
}
|
154
|
+
auto sects = getObject()->getIntercepts(
|
155
|
+
glyphs.data(), SkToInt(glyphs.size()), positions.data(), top, bottom);
|
156
|
+
auto jsiSects = jsi::Array(runtime, sects.size());
|
157
|
+
for (int i = 0; i < sects.size(); i++) {
|
158
|
+
jsiSects.setValueAtIndex(runtime, i,
|
159
|
+
jsi::Value(static_cast<int>(sects.at(i))));
|
160
|
+
}
|
161
|
+
return jsiSects;
|
162
|
+
}
|
163
|
+
|
164
|
+
JSI_HOST_FUNCTION(getScaleX) {
|
165
|
+
return jsi::Value(SkScalarToDouble(getObject()->getScaleX()));
|
166
|
+
}
|
167
|
+
|
168
|
+
JSI_HOST_FUNCTION(getSize) {
|
169
|
+
return jsi::Value(SkScalarToDouble(getObject()->getSize()));
|
170
|
+
}
|
171
|
+
|
172
|
+
JSI_HOST_FUNCTION(getSkewX) {
|
173
|
+
return jsi::Value(SkScalarToDouble(getObject()->getSkewX()));
|
174
|
+
}
|
175
|
+
|
176
|
+
JSI_HOST_FUNCTION(isEmbolden) {
|
177
|
+
return jsi::Value(getObject()->isEmbolden());
|
178
|
+
}
|
179
|
+
|
180
|
+
JSI_HOST_FUNCTION(getTypeface) {
|
181
|
+
return JsiSkTypeface::toValue(
|
182
|
+
runtime, getContext(), sk_sp<SkTypeface>(getObject()->getTypeface()));
|
183
|
+
}
|
184
|
+
|
185
|
+
JSI_HOST_FUNCTION(setEdging) {
|
186
|
+
auto edging = arguments[0].asNumber();
|
187
|
+
getObject()->setEdging(static_cast<SkFont::Edging>(edging));
|
188
|
+
return jsi::Value::undefined();
|
189
|
+
}
|
190
|
+
|
191
|
+
JSI_HOST_FUNCTION(embeddedBitmaps) {
|
192
|
+
auto embeddedBitmaps = arguments[0].getBool();
|
193
|
+
getObject()->setEmbeddedBitmaps(embeddedBitmaps);
|
194
|
+
return jsi::Value::undefined();
|
195
|
+
}
|
196
|
+
|
197
|
+
JSI_HOST_FUNCTION(setHinting) {
|
198
|
+
auto hinting = arguments[0].asNumber();
|
199
|
+
getObject()->setHinting(static_cast<SkFontHinting>(hinting));
|
200
|
+
return jsi::Value::undefined();
|
201
|
+
}
|
202
|
+
|
203
|
+
JSI_HOST_FUNCTION(setLinearMetrics) {
|
204
|
+
auto linearMetrics = arguments[0].getBool();
|
205
|
+
getObject()->setLinearMetrics(linearMetrics);
|
206
|
+
return jsi::Value::undefined();
|
207
|
+
}
|
208
|
+
|
209
|
+
JSI_HOST_FUNCTION(setScaleX) {
|
210
|
+
auto scaleX = arguments[0].asNumber();
|
211
|
+
getObject()->setScaleX(scaleX);
|
212
|
+
return jsi::Value::undefined();
|
213
|
+
}
|
214
|
+
|
215
|
+
JSI_HOST_FUNCTION(setSkewX) {
|
216
|
+
auto skewX = arguments[0].asNumber();
|
217
|
+
getObject()->setSkewX(skewX);
|
218
|
+
return jsi::Value::undefined();
|
219
|
+
}
|
220
|
+
|
221
|
+
JSI_HOST_FUNCTION(setSize) {
|
222
|
+
auto size = arguments[0].asNumber();
|
223
|
+
getObject()->setSize(size);
|
224
|
+
return jsi::Value::undefined();
|
225
|
+
}
|
226
|
+
|
227
|
+
JSI_HOST_FUNCTION(setEmbolden) {
|
228
|
+
auto embolden = arguments[0].asNumber();
|
229
|
+
getObject()->setEmbolden(embolden);
|
230
|
+
return jsi::Value::undefined();
|
231
|
+
}
|
232
|
+
|
233
|
+
JSI_HOST_FUNCTION(setSubpixel) {
|
234
|
+
auto subpixel = arguments[0].asNumber();
|
235
|
+
getObject()->setSubpixel(subpixel);
|
236
|
+
return jsi::Value::undefined();
|
237
|
+
}
|
238
|
+
|
239
|
+
JSI_HOST_FUNCTION(setTypeface) {
|
240
|
+
auto typeface = arguments[0].isNull()
|
241
|
+
? nullptr
|
242
|
+
: JsiSkTypeface::fromValue(runtime, arguments[0]);
|
243
|
+
getObject()->setTypeface(typeface);
|
244
|
+
return jsi::Value::undefined();
|
245
|
+
}
|
246
|
+
|
247
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkFont, getSize),
|
248
|
+
JSI_EXPORT_FUNC(JsiSkFont, getMetrics),
|
249
|
+
JSI_EXPORT_FUNC(JsiSkFont, getGlyphIDs),
|
250
|
+
JSI_EXPORT_FUNC(JsiSkFont, getGlyphIntercepts),
|
251
|
+
JSI_EXPORT_FUNC(JsiSkFont, getScaleX),
|
252
|
+
JSI_EXPORT_FUNC(JsiSkFont, getSkewX),
|
253
|
+
JSI_EXPORT_FUNC(JsiSkFont, getTypeface),
|
254
|
+
JSI_EXPORT_FUNC(JsiSkFont, setEdging),
|
255
|
+
JSI_EXPORT_FUNC(JsiSkFont, embeddedBitmaps),
|
256
|
+
JSI_EXPORT_FUNC(JsiSkFont, setHinting),
|
257
|
+
JSI_EXPORT_FUNC(JsiSkFont, setLinearMetrics),
|
258
|
+
JSI_EXPORT_FUNC(JsiSkFont, setScaleX),
|
259
|
+
JSI_EXPORT_FUNC(JsiSkFont, setSkewX),
|
260
|
+
JSI_EXPORT_FUNC(JsiSkFont, setSize),
|
261
|
+
JSI_EXPORT_FUNC(JsiSkFont, setEmbolden),
|
262
|
+
JSI_EXPORT_FUNC(JsiSkFont, setSubpixel),
|
263
|
+
JSI_EXPORT_FUNC(JsiSkFont, setTypeface),
|
264
|
+
JSI_EXPORT_FUNC(JsiSkFont, getGlyphWidths),
|
265
|
+
JSI_EXPORT_FUNC(JsiSkFont, getTextWidth))
|
266
|
+
|
267
|
+
JsiSkFont(std::shared_ptr<RNSkPlatformContext> context, const SkFont &font)
|
268
|
+
: JsiSkWrappingSharedPtrHostObject(std::move(context),
|
269
|
+
std::make_shared<SkFont>(font)) {}
|
270
|
+
|
271
|
+
/**
|
272
|
+
Returns the underlying object from a host object of this type
|
273
|
+
*/
|
274
|
+
static std::shared_ptr<SkFont> fromValue(jsi::Runtime &runtime,
|
275
|
+
const jsi::Value &obj) {
|
276
|
+
return obj.asObject(runtime).asHostObject<JsiSkFont>(runtime)->getObject();
|
277
|
+
}
|
278
|
+
|
279
|
+
/**
|
280
|
+
* Creates the function for construction a new instance of the SkFont
|
281
|
+
* wrapper
|
282
|
+
* @param context Platform context
|
283
|
+
* @return A function for creating a new host object wrapper for the SkFont
|
284
|
+
* class
|
285
|
+
*/
|
286
|
+
static const jsi::HostFunctionType
|
287
|
+
createCtor(std::shared_ptr<RNSkPlatformContext> context) {
|
288
|
+
return JSI_HOST_FUNCTION_LAMBDA {
|
289
|
+
// Handle arguments
|
290
|
+
if (count == 2) {
|
291
|
+
auto typeface = JsiSkTypeface::fromValue(runtime, arguments[0]);
|
292
|
+
auto size = arguments[1].asNumber();
|
293
|
+
return jsi::Object::createFromHostObject(
|
294
|
+
runtime, std::make_shared<JsiSkFont>(std::move(context),
|
295
|
+
SkFont(typeface, size)));
|
296
|
+
} else if (count == 1) {
|
297
|
+
auto typeface = JsiSkTypeface::fromValue(runtime, arguments[0]);
|
298
|
+
return jsi::Object::createFromHostObject(
|
299
|
+
runtime,
|
300
|
+
std::make_shared<JsiSkFont>(std::move(context), SkFont(typeface)));
|
301
|
+
} else {
|
302
|
+
// Return the newly constructed object
|
303
|
+
return jsi::Object::createFromHostObject(
|
304
|
+
runtime, std::make_shared<JsiSkFont>(std::move(context), SkFont()));
|
305
|
+
}
|
333
306
|
};
|
307
|
+
}
|
308
|
+
};
|
334
309
|
|
335
310
|
} // namespace RNSkia
|