@shopify/react-native-skia 0.1.222 → 0.1.224
Sign up to get free protection for your applications and to get access to all the features.
- package/cpp/api/JsiSkApi.h +6 -1
- package/cpp/api/JsiSkFontMgrFactory.h +9 -4
- package/cpp/api/JsiSkParagraph.h +135 -0
- package/cpp/api/JsiSkParagraphBuilder.h +159 -0
- package/cpp/api/JsiSkParagraphStyle.h +124 -0
- package/cpp/api/JsiSkStrutStyle.h +96 -0
- package/cpp/api/JsiSkTextStyle.h +185 -0
- package/cpp/api/{JsiSkTypeFaceFontProviderFactory.h → JsiSkTypefaceFontProviderFactory.h} +1 -1
- package/cpp/jsi/JsiHostObject.h +21 -0
- package/cpp/rnskia/dom/JsiDomApi.h +4 -0
- package/cpp/rnskia/dom/nodes/JsiParagraphNode.h +62 -0
- package/cpp/rnskia/dom/props/ParagraphProp.h +45 -0
- package/cpp/skia/modules/skunicode/include/SkUnicode.h +312 -0
- package/cpp/skia/src/base/SkTInternalLList.h +304 -0
- package/cpp/skia/src/base/SkUTF.h +95 -0
- package/cpp/skia/src/core/SkLRUCache.h +130 -0
- package/lib/commonjs/dom/nodes/JsiSkDOM.d.ts +2 -0
- package/lib/commonjs/dom/nodes/JsiSkDOM.js +7 -0
- package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/commonjs/dom/nodes/drawings/ParagraphNode.d.ts +8 -0
- package/lib/commonjs/dom/nodes/drawings/ParagraphNode.js +41 -0
- package/lib/commonjs/dom/nodes/drawings/ParagraphNode.js.map +1 -0
- package/lib/commonjs/dom/types/NodeType.d.ts +2 -1
- package/lib/commonjs/dom/types/NodeType.js +1 -0
- package/lib/commonjs/dom/types/NodeType.js.map +1 -1
- package/lib/commonjs/dom/types/Paragraph.d.ts +8 -0
- package/lib/commonjs/dom/types/Paragraph.js +6 -0
- package/lib/commonjs/dom/types/Paragraph.js.map +1 -0
- package/lib/commonjs/dom/types/SkDOM.d.ts +2 -0
- package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
- package/lib/commonjs/dom/types/index.d.ts +1 -0
- package/lib/commonjs/dom/types/index.js +13 -0
- package/lib/commonjs/dom/types/index.js.map +1 -1
- package/lib/commonjs/renderer/HostComponents.d.ts +3 -1
- package/lib/commonjs/renderer/HostComponents.js +4 -0
- package/lib/commonjs/renderer/HostComponents.js.map +1 -1
- package/lib/commonjs/renderer/components/index.d.ts +1 -0
- package/lib/commonjs/renderer/components/index.js +13 -0
- package/lib/commonjs/renderer/components/index.js.map +1 -1
- package/lib/commonjs/renderer/components/paragraph/Paragraph.d.ts +4 -0
- package/lib/commonjs/renderer/components/paragraph/Paragraph.js +17 -0
- package/lib/commonjs/renderer/components/paragraph/Paragraph.js.map +1 -0
- package/lib/commonjs/renderer/components/paragraph/index.d.ts +1 -0
- package/lib/commonjs/renderer/components/paragraph/index.js +19 -0
- package/lib/commonjs/renderer/components/paragraph/index.js.map +1 -0
- package/lib/commonjs/skia/types/Paragraph/Paragraph.d.ts +56 -0
- package/lib/commonjs/skia/types/Paragraph/Paragraph.js +6 -0
- package/lib/commonjs/skia/types/Paragraph/Paragraph.js.map +1 -0
- package/lib/commonjs/skia/types/Paragraph/ParagraphBuilder.d.ts +60 -0
- package/lib/commonjs/skia/types/Paragraph/ParagraphBuilder.js +18 -0
- package/lib/commonjs/skia/types/Paragraph/ParagraphBuilder.js.map +1 -0
- package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.d.ts +41 -0
- package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.js +36 -0
- package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.js.map +1 -0
- package/lib/commonjs/skia/types/Paragraph/TextStyle.d.ts +62 -0
- package/lib/commonjs/skia/types/Paragraph/TextStyle.js +35 -0
- package/lib/commonjs/skia/types/Paragraph/TextStyle.js.map +1 -0
- package/lib/commonjs/skia/types/Paragraph/index.d.ts +6 -0
- package/lib/commonjs/skia/types/Paragraph/index.js +84 -0
- package/lib/commonjs/skia/types/Paragraph/index.js.map +1 -0
- package/lib/commonjs/skia/types/Skia.d.ts +2 -0
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/index.d.ts +1 -0
- package/lib/commonjs/skia/types/index.js +13 -0
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkParagraph.d.ts +16 -0
- package/lib/commonjs/skia/web/JsiSkParagraph.js +91 -0
- package/lib/commonjs/skia/web/JsiSkParagraph.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkParagraphBuilder.d.ts +15 -0
- package/lib/commonjs/skia/web/JsiSkParagraphBuilder.js +85 -0
- package/lib/commonjs/skia/web/JsiSkParagraphBuilder.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkParagraphBuilderFactory.d.ts +8 -0
- package/lib/commonjs/skia/web/JsiSkParagraphBuilderFactory.js +34 -0
- package/lib/commonjs/skia/web/JsiSkParagraphBuilderFactory.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkParagraphStyle.d.ts +5 -0
- package/lib/commonjs/skia/web/JsiSkParagraphStyle.js +59 -0
- package/lib/commonjs/skia/web/JsiSkParagraphStyle.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkTextStyle.d.ts +5 -0
- package/lib/commonjs/skia/web/JsiSkTextStyle.js +54 -0
- package/lib/commonjs/skia/web/JsiSkTextStyle.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkia.js +4 -1
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/dom/nodes/JsiSkDOM.d.ts +2 -0
- package/lib/module/dom/nodes/JsiSkDOM.js +6 -0
- package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/module/dom/nodes/drawings/ParagraphNode.d.ts +8 -0
- package/lib/module/dom/nodes/drawings/ParagraphNode.js +30 -0
- package/lib/module/dom/nodes/drawings/ParagraphNode.js.map +1 -0
- package/lib/module/dom/types/NodeType.d.ts +2 -1
- package/lib/module/dom/types/NodeType.js +1 -0
- package/lib/module/dom/types/NodeType.js.map +1 -1
- package/lib/module/dom/types/Paragraph.d.ts +8 -0
- package/lib/module/dom/types/Paragraph.js +2 -0
- package/lib/module/dom/types/Paragraph.js.map +1 -0
- package/lib/module/dom/types/SkDOM.d.ts +2 -0
- package/lib/module/dom/types/SkDOM.js.map +1 -1
- package/lib/module/dom/types/index.d.ts +1 -0
- package/lib/module/dom/types/index.js +1 -0
- package/lib/module/dom/types/index.js.map +1 -1
- package/lib/module/renderer/HostComponents.d.ts +3 -1
- package/lib/module/renderer/HostComponents.js +4 -0
- package/lib/module/renderer/HostComponents.js.map +1 -1
- package/lib/module/renderer/components/index.d.ts +1 -0
- package/lib/module/renderer/components/index.js +1 -0
- package/lib/module/renderer/components/index.js.map +1 -1
- package/lib/module/renderer/components/paragraph/Paragraph.d.ts +4 -0
- package/lib/module/renderer/components/paragraph/Paragraph.js +5 -0
- package/lib/module/renderer/components/paragraph/Paragraph.js.map +1 -0
- package/lib/module/renderer/components/paragraph/index.d.ts +1 -0
- package/lib/module/renderer/components/paragraph/index.js +2 -0
- package/lib/module/renderer/components/paragraph/index.js.map +1 -0
- package/lib/module/skia/types/Paragraph/Paragraph.d.ts +56 -0
- package/lib/module/skia/types/Paragraph/Paragraph.js +2 -0
- package/lib/module/skia/types/Paragraph/Paragraph.js.map +1 -0
- package/lib/module/skia/types/Paragraph/ParagraphBuilder.d.ts +60 -0
- package/lib/module/skia/types/Paragraph/ParagraphBuilder.js +11 -0
- package/lib/module/skia/types/Paragraph/ParagraphBuilder.js.map +1 -0
- package/lib/module/skia/types/Paragraph/ParagraphStyle.d.ts +41 -0
- package/lib/module/skia/types/Paragraph/ParagraphStyle.js +27 -0
- package/lib/module/skia/types/Paragraph/ParagraphStyle.js.map +1 -0
- package/lib/module/skia/types/Paragraph/TextStyle.d.ts +62 -0
- package/lib/module/skia/types/Paragraph/TextStyle.js +26 -0
- package/lib/module/skia/types/Paragraph/TextStyle.js.map +1 -0
- package/lib/module/skia/types/Paragraph/index.d.ts +6 -0
- package/lib/module/skia/types/Paragraph/index.js +7 -0
- package/lib/module/skia/types/Paragraph/index.js.map +1 -0
- package/lib/module/skia/types/Skia.d.ts +2 -0
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/index.d.ts +1 -0
- package/lib/module/skia/types/index.js +1 -0
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkParagraph.d.ts +16 -0
- package/lib/module/skia/web/JsiSkParagraph.js +81 -0
- package/lib/module/skia/web/JsiSkParagraph.js.map +1 -0
- package/lib/module/skia/web/JsiSkParagraphBuilder.d.ts +15 -0
- package/lib/module/skia/web/JsiSkParagraphBuilder.js +73 -0
- package/lib/module/skia/web/JsiSkParagraphBuilder.js.map +1 -0
- package/lib/module/skia/web/JsiSkParagraphBuilderFactory.d.ts +8 -0
- package/lib/module/skia/web/JsiSkParagraphBuilderFactory.js +21 -0
- package/lib/module/skia/web/JsiSkParagraphBuilderFactory.js.map +1 -0
- package/lib/module/skia/web/JsiSkParagraphStyle.d.ts +5 -0
- package/lib/module/skia/web/JsiSkParagraphStyle.js +49 -0
- package/lib/module/skia/web/JsiSkParagraphStyle.js.map +1 -0
- package/lib/module/skia/web/JsiSkTextStyle.d.ts +5 -0
- package/lib/module/skia/web/JsiSkTextStyle.js +45 -0
- package/lib/module/skia/web/JsiSkTextStyle.js.map +1 -0
- package/lib/module/skia/web/JsiSkia.js +3 -1
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
- package/lib/typescript/src/dom/nodes/drawings/ParagraphNode.d.ts +8 -0
- package/lib/typescript/src/dom/types/NodeType.d.ts +2 -1
- package/lib/typescript/src/dom/types/Paragraph.d.ts +8 -0
- package/lib/typescript/src/dom/types/SkDOM.d.ts +2 -0
- package/lib/typescript/src/dom/types/index.d.ts +1 -0
- package/lib/typescript/src/renderer/HostComponents.d.ts +3 -1
- package/lib/typescript/src/renderer/components/index.d.ts +1 -0
- package/lib/typescript/src/renderer/components/paragraph/Paragraph.d.ts +4 -0
- package/lib/typescript/src/renderer/components/paragraph/index.d.ts +1 -0
- package/lib/typescript/src/skia/types/Paragraph/Paragraph.d.ts +56 -0
- package/lib/typescript/src/skia/types/Paragraph/ParagraphBuilder.d.ts +60 -0
- package/lib/typescript/src/skia/types/Paragraph/ParagraphStyle.d.ts +41 -0
- package/lib/typescript/src/skia/types/Paragraph/TextStyle.d.ts +62 -0
- package/lib/typescript/src/skia/types/Paragraph/index.d.ts +6 -0
- package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
- package/lib/typescript/src/skia/types/index.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkParagraph.d.ts +16 -0
- package/lib/typescript/src/skia/web/JsiSkParagraphBuilder.d.ts +15 -0
- package/lib/typescript/src/skia/web/JsiSkParagraphBuilderFactory.d.ts +8 -0
- package/lib/typescript/src/skia/web/JsiSkParagraphStyle.d.ts +5 -0
- package/lib/typescript/src/skia/web/JsiSkTextStyle.d.ts +5 -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 +5 -5
- 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/libskparagraph.xcframework/Info.plist +5 -5
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -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/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/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
- package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.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 +1 -1
- package/src/dom/nodes/JsiSkDOM.ts +9 -0
- package/src/dom/nodes/drawings/ParagraphNode.ts +22 -0
- package/src/dom/types/NodeType.ts +3 -0
- package/src/dom/types/Paragraph.ts +10 -0
- package/src/dom/types/SkDOM.ts +4 -0
- package/src/dom/types/index.ts +1 -0
- package/src/renderer/HostComponents.ts +10 -0
- package/src/renderer/components/index.ts +2 -0
- package/src/renderer/components/paragraph/Paragraph.tsx +8 -0
- package/src/renderer/components/paragraph/index.ts +1 -0
- package/src/skia/types/Paragraph/Paragraph.ts +59 -0
- package/src/skia/types/Paragraph/ParagraphBuilder.ts +96 -0
- package/src/skia/types/Paragraph/ParagraphStyle.ts +45 -0
- package/src/skia/types/Paragraph/TextStyle.ts +70 -0
- package/src/skia/types/Paragraph/index.ts +6 -0
- package/src/skia/types/Skia.ts +3 -0
- package/src/skia/types/index.ts +1 -0
- package/src/skia/web/JsiSkParagraph.ts +69 -0
- package/src/skia/web/JsiSkParagraphBuilder.ts +99 -0
- package/src/skia/web/JsiSkParagraphBuilderFactory.ts +42 -0
- package/src/skia/web/JsiSkParagraphStyle.ts +65 -0
- package/src/skia/web/JsiSkTextStyle.ts +53 -0
- package/src/skia/web/JsiSkia.ts +2 -0
- /package/cpp/api/{JsiSkTypeFaceFontProvider.h → JsiSkTypefaceFontProvider.h} +0 -0
package/cpp/api/JsiSkApi.h
CHANGED
@@ -24,6 +24,7 @@
|
|
24
24
|
#include "JsiSkMaskFilterFactory.h"
|
25
25
|
#include "JsiSkMatrix.h"
|
26
26
|
#include "JsiSkPaint.h"
|
27
|
+
#include "JsiSkParagraphBuilder.h"
|
27
28
|
#include "JsiSkPath.h"
|
28
29
|
#include "JsiSkPathEffect.h"
|
29
30
|
#include "JsiSkPathEffectFactory.h"
|
@@ -43,9 +44,9 @@
|
|
43
44
|
#include "JsiSkShaderFactory.h"
|
44
45
|
#include "JsiSkSurfaceFactory.h"
|
45
46
|
#include "JsiSkTextBlobFactory.h"
|
46
|
-
#include "JsiSkTypeFaceFontProviderFactory.h"
|
47
47
|
#include "JsiSkTypeface.h"
|
48
48
|
#include "JsiSkTypefaceFactory.h"
|
49
|
+
#include "JsiSkTypefaceFontProviderFactory.h"
|
49
50
|
#include "JsiSkVertices.h"
|
50
51
|
|
51
52
|
namespace RNSkia {
|
@@ -112,6 +113,10 @@ public:
|
|
112
113
|
installReadonlyProperty(
|
113
114
|
"TypefaceFontProvider",
|
114
115
|
std::make_shared<JsiSkTypefaceFontProviderFactory>(context));
|
116
|
+
|
117
|
+
installReadonlyProperty(
|
118
|
+
"ParagraphBuilder",
|
119
|
+
std::make_shared<JsiSkParagraphBuilderFactory>(context));
|
115
120
|
}
|
116
121
|
};
|
117
122
|
} // namespace RNSkia
|
@@ -22,13 +22,18 @@ namespace jsi = facebook::jsi;
|
|
22
22
|
|
23
23
|
class JsiSkFontMgrFactory : public JsiSkHostObject {
|
24
24
|
public:
|
25
|
-
|
26
|
-
|
25
|
+
static sk_sp<SkFontMgr>
|
26
|
+
getFontMgr(std::shared_ptr<RNSkPlatformContext> context) {
|
27
27
|
static SkOnce once;
|
28
28
|
static sk_sp<SkFontMgr> fontMgr;
|
29
|
-
once([&context
|
29
|
+
once([&context] { fontMgr = context->createFontMgr(); });
|
30
|
+
return fontMgr;
|
31
|
+
}
|
32
|
+
|
33
|
+
JSI_HOST_FUNCTION(System) {
|
34
|
+
auto fontMgr = JsiSkFontMgrFactory::getFontMgr(getContext());
|
30
35
|
return jsi::Object::createFromHostObject(
|
31
|
-
runtime, std::make_shared<JsiSkFontMgr>(
|
36
|
+
runtime, std::make_shared<JsiSkFontMgr>(getContext(), fontMgr));
|
32
37
|
}
|
33
38
|
|
34
39
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkFontMgrFactory, System))
|
@@ -0,0 +1,135 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <memory>
|
4
|
+
#include <string>
|
5
|
+
#include <utility>
|
6
|
+
#include <vector>
|
7
|
+
|
8
|
+
#include <jsi/jsi.h>
|
9
|
+
|
10
|
+
#include <JsiSkCanvas.h>
|
11
|
+
#include <JsiSkHostObjects.h>
|
12
|
+
#include <JsiSkPath.h>
|
13
|
+
#include <JsiSkRect.h>
|
14
|
+
|
15
|
+
#pragma clang diagnostic push
|
16
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
17
|
+
|
18
|
+
#include "Paragraph.h"
|
19
|
+
#include "ParagraphBuilder.h"
|
20
|
+
#include "ParagraphStyle.h"
|
21
|
+
|
22
|
+
#pragma clang diagnostic pop
|
23
|
+
|
24
|
+
namespace RNSkia {
|
25
|
+
|
26
|
+
namespace jsi = facebook::jsi;
|
27
|
+
|
28
|
+
namespace para = skia::textlayout;
|
29
|
+
|
30
|
+
/**
|
31
|
+
Implementation of the Paragraph object in JSI
|
32
|
+
*/
|
33
|
+
class JsiSkParagraph : public JsiSkHostObject {
|
34
|
+
public:
|
35
|
+
JSI_HOST_FUNCTION(layout) {
|
36
|
+
auto width = getArgumentAsNumber(runtime, arguments, count, 0);
|
37
|
+
_paragraph->layout(width);
|
38
|
+
return jsi::Value::undefined();
|
39
|
+
}
|
40
|
+
|
41
|
+
JSI_HOST_FUNCTION(paint) {
|
42
|
+
auto jsiCanvas =
|
43
|
+
getArgumentAsHostObject<JsiSkCanvas>(runtime, arguments, count, 0);
|
44
|
+
auto x = getArgumentAsNumber(runtime, arguments, count, 1);
|
45
|
+
auto y = getArgumentAsNumber(runtime, arguments, count, 2);
|
46
|
+
_paragraph->paint(jsiCanvas->getCanvas(), x, y);
|
47
|
+
return jsi::Value::undefined();
|
48
|
+
}
|
49
|
+
|
50
|
+
JSI_HOST_FUNCTION(getHeight) {
|
51
|
+
return static_cast<double>(_paragraph->getHeight());
|
52
|
+
}
|
53
|
+
|
54
|
+
JSI_HOST_FUNCTION(getMaxWidth) {
|
55
|
+
return static_cast<double>(_paragraph->getMaxWidth());
|
56
|
+
}
|
57
|
+
|
58
|
+
JSI_HOST_FUNCTION(getGlyphPositionAtCoordinate) {
|
59
|
+
auto dx = getArgumentAsNumber(runtime, arguments, count, 0);
|
60
|
+
auto dy = getArgumentAsNumber(runtime, arguments, count, 1);
|
61
|
+
auto result = _paragraph->getGlyphPositionAtCoordinate(dx, dy);
|
62
|
+
return result.position;
|
63
|
+
}
|
64
|
+
|
65
|
+
JSI_HOST_FUNCTION(getRectsForRange) {
|
66
|
+
auto start = getArgumentAsNumber(runtime, arguments, count, 0);
|
67
|
+
auto end = getArgumentAsNumber(runtime, arguments, count, 1);
|
68
|
+
auto result =
|
69
|
+
_paragraph->getRectsForRange(start, end, para::RectHeightStyle::kTight,
|
70
|
+
para::RectWidthStyle::kTight);
|
71
|
+
auto returnValue = jsi::Array(runtime, result.size());
|
72
|
+
for (size_t i = 0; i < result.size(); ++i) {
|
73
|
+
returnValue.setValueAtIndex(
|
74
|
+
runtime, i,
|
75
|
+
JsiSkRect::toValue(runtime, getContext(), result[i].rect));
|
76
|
+
}
|
77
|
+
return returnValue;
|
78
|
+
}
|
79
|
+
|
80
|
+
JSI_HOST_FUNCTION(getLineMetrics) {
|
81
|
+
std::vector<para::LineMetrics> metrics;
|
82
|
+
_paragraph->getLineMetrics(metrics);
|
83
|
+
auto returnValue = jsi::Array(runtime, metrics.size());
|
84
|
+
auto height = 0;
|
85
|
+
for (size_t i = 0; i < metrics.size(); ++i) {
|
86
|
+
returnValue.setValueAtIndex(
|
87
|
+
runtime, i,
|
88
|
+
JsiSkRect::toValue(runtime, getContext(),
|
89
|
+
SkRect::MakeXYWH(metrics[i].fLeft, height,
|
90
|
+
metrics[i].fWidth,
|
91
|
+
metrics[i].fHeight)));
|
92
|
+
height += metrics[i].fHeight;
|
93
|
+
}
|
94
|
+
return returnValue;
|
95
|
+
}
|
96
|
+
|
97
|
+
JSI_HOST_FUNCTION(getRectsForPlaceholders) {
|
98
|
+
std::vector<para::TextBox> placeholderInfos =
|
99
|
+
_paragraph->getRectsForPlaceholders();
|
100
|
+
auto returnValue = jsi::Array(runtime, placeholderInfos.size());
|
101
|
+
for (size_t i = 0; i < placeholderInfos.size(); ++i) {
|
102
|
+
auto obj = jsi::Object(runtime);
|
103
|
+
obj.setProperty(
|
104
|
+
runtime, "rect",
|
105
|
+
JsiSkRect::toValue(runtime, getContext(), placeholderInfos[i].rect));
|
106
|
+
obj.setProperty(runtime, "direction",
|
107
|
+
static_cast<double>(placeholderInfos[i].direction));
|
108
|
+
returnValue.setValueAtIndex(runtime, i, obj);
|
109
|
+
}
|
110
|
+
return returnValue;
|
111
|
+
}
|
112
|
+
|
113
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkParagraph, layout),
|
114
|
+
JSI_EXPORT_FUNC(JsiSkParagraph, paint),
|
115
|
+
JSI_EXPORT_FUNC(JsiSkParagraph, getMaxWidth),
|
116
|
+
JSI_EXPORT_FUNC(JsiSkParagraph, getHeight),
|
117
|
+
JSI_EXPORT_FUNC(JsiSkParagraph, getRectsForPlaceholders),
|
118
|
+
JSI_EXPORT_FUNC(JsiSkParagraph,
|
119
|
+
getGlyphPositionAtCoordinate),
|
120
|
+
JSI_EXPORT_FUNC(JsiSkParagraph, getRectsForRange),
|
121
|
+
JSI_EXPORT_FUNC(JsiSkParagraph, getLineMetrics))
|
122
|
+
|
123
|
+
explicit JsiSkParagraph(std::shared_ptr<RNSkPlatformContext> context,
|
124
|
+
para::ParagraphBuilder *paragraphBuilder)
|
125
|
+
: JsiSkHostObject(std::move(context)) {
|
126
|
+
_paragraph = paragraphBuilder->Build();
|
127
|
+
}
|
128
|
+
|
129
|
+
para::Paragraph *getParagraph() { return _paragraph.get(); }
|
130
|
+
|
131
|
+
private:
|
132
|
+
std::unique_ptr<para::Paragraph> _paragraph;
|
133
|
+
};
|
134
|
+
|
135
|
+
} // namespace RNSkia
|
@@ -0,0 +1,159 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <memory>
|
4
|
+
#include <utility>
|
5
|
+
|
6
|
+
#include <jsi/jsi.h>
|
7
|
+
|
8
|
+
#include <JsiSkFont.h>
|
9
|
+
#include <JsiSkFontMgr.h>
|
10
|
+
#include <JsiSkHostObjects.h>
|
11
|
+
#include <JsiSkParagraph.h>
|
12
|
+
#include <JsiSkParagraphStyle.h>
|
13
|
+
#include <JsiSkTextStyle.h>
|
14
|
+
#include <JsiSkTypefaceFontProvider.h>
|
15
|
+
|
16
|
+
#pragma clang diagnostic push
|
17
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
18
|
+
|
19
|
+
#include "ParagraphBuilder.h"
|
20
|
+
|
21
|
+
#pragma clang diagnostic pop
|
22
|
+
|
23
|
+
namespace RNSkia {
|
24
|
+
|
25
|
+
namespace jsi = facebook::jsi;
|
26
|
+
|
27
|
+
namespace para = skia::textlayout;
|
28
|
+
|
29
|
+
/**
|
30
|
+
Implementation of the ParagraphBuilder object in JSI
|
31
|
+
*/
|
32
|
+
class JsiSkParagraphBuilder : public JsiSkHostObject {
|
33
|
+
public:
|
34
|
+
JSI_API_TYPENAME("ParagraphBuilder");
|
35
|
+
|
36
|
+
JSI_HOST_FUNCTION(build) {
|
37
|
+
return jsi::Object::createFromHostObject(
|
38
|
+
runtime,
|
39
|
+
std::make_shared<JsiSkParagraph>(getContext(), _builder.get()));
|
40
|
+
}
|
41
|
+
|
42
|
+
JSI_HOST_FUNCTION(reset) {
|
43
|
+
_builder->Reset();
|
44
|
+
return jsi::Value::undefined();
|
45
|
+
}
|
46
|
+
|
47
|
+
JSI_HOST_FUNCTION(addText) {
|
48
|
+
auto text = getArgumentAsString(runtime, arguments, count, 0).utf8(runtime);
|
49
|
+
_builder->addText(text.c_str());
|
50
|
+
return thisValue.asObject(runtime);
|
51
|
+
}
|
52
|
+
|
53
|
+
JSI_HOST_FUNCTION(addPlaceholder) {
|
54
|
+
auto width =
|
55
|
+
count >= 1 ? getArgumentAsNumber(runtime, arguments, count, 0) : 0;
|
56
|
+
auto height =
|
57
|
+
count >= 2 ? getArgumentAsNumber(runtime, arguments, count, 1) : 0;
|
58
|
+
auto alignment =
|
59
|
+
count >= 3 ? static_cast<para::PlaceholderAlignment>(
|
60
|
+
getArgumentAsNumber(runtime, arguments, count, 2))
|
61
|
+
: para::PlaceholderAlignment::kBaseline;
|
62
|
+
auto baseline = count >= 4
|
63
|
+
? static_cast<para::TextBaseline>(
|
64
|
+
getArgumentAsNumber(runtime, arguments, count, 3))
|
65
|
+
: para::TextBaseline::kAlphabetic;
|
66
|
+
auto offset =
|
67
|
+
count >= 5 ? getArgumentAsNumber(runtime, arguments, count, 4) : 0;
|
68
|
+
|
69
|
+
para::PlaceholderStyle style(width, height, alignment, baseline, offset);
|
70
|
+
_builder->addPlaceholder(style);
|
71
|
+
|
72
|
+
return thisValue.asObject(runtime);
|
73
|
+
}
|
74
|
+
|
75
|
+
JSI_HOST_FUNCTION(pushStyle) {
|
76
|
+
auto textStyle = JsiSkTextStyle::fromValue(runtime, arguments[0]);
|
77
|
+
// Foreground paint
|
78
|
+
if (count >= 2) {
|
79
|
+
auto foreground =
|
80
|
+
tryGetArgumentAsHostObject<JsiSkPaint>(runtime, arguments, count, 1);
|
81
|
+
if (foreground) {
|
82
|
+
textStyle.setForegroundPaint(*foreground->getObject().get());
|
83
|
+
}
|
84
|
+
}
|
85
|
+
// Background paint
|
86
|
+
if (count >= 3) {
|
87
|
+
auto background =
|
88
|
+
tryGetArgumentAsHostObject<JsiSkPaint>(runtime, arguments, count, 2);
|
89
|
+
if (background) {
|
90
|
+
textStyle.setBackgroundPaint(*background->getObject().get());
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
_builder->pushStyle(textStyle);
|
95
|
+
|
96
|
+
return thisValue.asObject(runtime);
|
97
|
+
}
|
98
|
+
|
99
|
+
JSI_HOST_FUNCTION(pop) {
|
100
|
+
_builder->pop();
|
101
|
+
return thisValue.asObject(runtime);
|
102
|
+
}
|
103
|
+
|
104
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkParagraphBuilder, build),
|
105
|
+
JSI_EXPORT_FUNC(JsiSkParagraphBuilder, reset),
|
106
|
+
JSI_EXPORT_FUNC(JsiSkParagraphBuilder, addText),
|
107
|
+
JSI_EXPORT_FUNC(JsiSkParagraphBuilder, addPlaceholder),
|
108
|
+
JSI_EXPORT_FUNC(JsiSkParagraphBuilder, pushStyle),
|
109
|
+
JSI_EXPORT_FUNC(JsiSkParagraphBuilder, pop))
|
110
|
+
|
111
|
+
explicit JsiSkParagraphBuilder(std::shared_ptr<RNSkPlatformContext> context,
|
112
|
+
para::ParagraphStyle paragraphStyle,
|
113
|
+
sk_sp<SkFontMgr> fontManager)
|
114
|
+
: JsiSkHostObject(std::move(context)) {
|
115
|
+
_fontCollection = sk_make_sp<para::FontCollection>();
|
116
|
+
_fontCollection->setDefaultFontManager(getContext()->createFontMgr());
|
117
|
+
if (fontManager != nullptr) {
|
118
|
+
_fontCollection->setAssetFontManager(fontManager);
|
119
|
+
}
|
120
|
+
_fontCollection->enableFontFallback();
|
121
|
+
_builder = para::ParagraphBuilder::make(paragraphStyle, _fontCollection);
|
122
|
+
}
|
123
|
+
|
124
|
+
private:
|
125
|
+
std::unique_ptr<para::ParagraphBuilder> _builder;
|
126
|
+
sk_sp<para::FontCollection> _fontCollection;
|
127
|
+
};
|
128
|
+
|
129
|
+
/**
|
130
|
+
Implementation of the ParagraphBuilderFactory for making ParagraphBuilder JSI
|
131
|
+
object
|
132
|
+
*/
|
133
|
+
class JsiSkParagraphBuilderFactory : public JsiSkHostObject {
|
134
|
+
public:
|
135
|
+
JSI_HOST_FUNCTION(Make) {
|
136
|
+
// Get paragraph style from params
|
137
|
+
auto paragraphStyle =
|
138
|
+
count > 0 ? JsiSkParagraphStyle::fromValue(runtime, arguments[0])
|
139
|
+
: para::ParagraphStyle();
|
140
|
+
|
141
|
+
// get font manager
|
142
|
+
auto fontMgr =
|
143
|
+
count > 1 ? JsiSkTypefaceFontProvider::fromValue(runtime, arguments[1])
|
144
|
+
: nullptr;
|
145
|
+
|
146
|
+
// Create the paragraph builder
|
147
|
+
return jsi::Object::createFromHostObject(
|
148
|
+
runtime, std::make_shared<JsiSkParagraphBuilder>(
|
149
|
+
getContext(), paragraphStyle, fontMgr));
|
150
|
+
}
|
151
|
+
|
152
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkParagraphBuilderFactory, Make))
|
153
|
+
|
154
|
+
explicit JsiSkParagraphBuilderFactory(
|
155
|
+
std::shared_ptr<RNSkPlatformContext> context)
|
156
|
+
: JsiSkHostObject(std::move(context)) {}
|
157
|
+
};
|
158
|
+
|
159
|
+
} // namespace RNSkia
|
@@ -0,0 +1,124 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <codecvt>
|
4
|
+
#include <locale>
|
5
|
+
#include <memory>
|
6
|
+
#include <string>
|
7
|
+
#include <utility>
|
8
|
+
#include <vector>
|
9
|
+
|
10
|
+
#include <jsi/jsi.h>
|
11
|
+
|
12
|
+
#include <JsiSkStrutStyle.h>
|
13
|
+
#include <JsiSkTextStyle.h>
|
14
|
+
|
15
|
+
#pragma clang diagnostic push
|
16
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
17
|
+
|
18
|
+
#include "Paragraph.h"
|
19
|
+
|
20
|
+
#pragma clang diagnostic pop
|
21
|
+
|
22
|
+
namespace RNSkia {
|
23
|
+
|
24
|
+
namespace jsi = facebook::jsi;
|
25
|
+
|
26
|
+
namespace para = skia::textlayout;
|
27
|
+
/**
|
28
|
+
Implementation of the ParagraphStyle object in JSI
|
29
|
+
*/
|
30
|
+
class JsiSkParagraphStyle {
|
31
|
+
public:
|
32
|
+
/**
|
33
|
+
disableHinting?: boolean;
|
34
|
+
ellipsis?: string;
|
35
|
+
heightMultiplier?: number;
|
36
|
+
maxLines?: number;
|
37
|
+
replaceTabCharacters?: boolean;
|
38
|
+
strutStyle?: SkStrutStyle;
|
39
|
+
textAlign?: SkTextAlign;
|
40
|
+
textDirection?: SkTextDirection;
|
41
|
+
textHeightBehavior?: SkTextHeightBehavior;
|
42
|
+
textStyle?: SkTextStyle;
|
43
|
+
*/
|
44
|
+
static para::ParagraphStyle fromValue(jsi::Runtime &runtime,
|
45
|
+
const jsi::Value &value) {
|
46
|
+
para::ParagraphStyle retVal;
|
47
|
+
|
48
|
+
// Accept undefined && null
|
49
|
+
if (value.isUndefined() || value.isNull()) {
|
50
|
+
return retVal;
|
51
|
+
}
|
52
|
+
|
53
|
+
// Read values from the argument - expected to be a ParagraphStyle shaped
|
54
|
+
// object
|
55
|
+
if (!value.isObject()) {
|
56
|
+
throw jsi::JSError(runtime, "Expected SkParagrahStyle as first argument");
|
57
|
+
}
|
58
|
+
|
59
|
+
auto object = value.asObject(runtime);
|
60
|
+
|
61
|
+
if (object.hasProperty(runtime, "disableHinting")) {
|
62
|
+
auto propValue = object.getProperty(runtime, "disableHinting");
|
63
|
+
if (propValue.asBool()) {
|
64
|
+
retVal.turnHintingOff();
|
65
|
+
}
|
66
|
+
}
|
67
|
+
if (object.hasProperty(runtime, "ellipsis")) {
|
68
|
+
auto propValue = object.getProperty(runtime, "ellipsis");
|
69
|
+
auto inStr = propValue.asString(runtime).utf8(runtime);
|
70
|
+
std::u16string uStr;
|
71
|
+
fromUTF8(inStr, uStr);
|
72
|
+
retVal.setEllipsis(uStr);
|
73
|
+
}
|
74
|
+
if (object.hasProperty(runtime, "heightMultiplier")) {
|
75
|
+
auto propValue = object.getProperty(runtime, "heightMultiplier");
|
76
|
+
retVal.setHeight(propValue.asNumber());
|
77
|
+
}
|
78
|
+
if (object.hasProperty(runtime, "maxLines")) {
|
79
|
+
auto propValue = object.getProperty(runtime, "maxLines");
|
80
|
+
if (propValue.asNumber() != 0) {
|
81
|
+
retVal.setMaxLines(propValue.asNumber());
|
82
|
+
}
|
83
|
+
}
|
84
|
+
if (object.hasProperty(runtime, "replaceTabCharacters")) {
|
85
|
+
auto propValue = object.getProperty(runtime, "replaceTabCharacters");
|
86
|
+
retVal.setReplaceTabCharacters(propValue.asBool());
|
87
|
+
}
|
88
|
+
if (object.hasProperty(runtime, "textAlign")) {
|
89
|
+
auto propValue = object.getProperty(runtime, "textAlign");
|
90
|
+
retVal.setTextAlign(static_cast<para::TextAlign>(propValue.asNumber()));
|
91
|
+
}
|
92
|
+
if (object.hasProperty(runtime, "textDirection")) {
|
93
|
+
auto propValue = object.getProperty(runtime, "textDirection");
|
94
|
+
retVal.setTextDirection(
|
95
|
+
static_cast<para::TextDirection>(propValue.asNumber()));
|
96
|
+
}
|
97
|
+
if (object.hasProperty(runtime, "textHeightBehavior")) {
|
98
|
+
auto propValue = object.getProperty(runtime, "textHeightBehavior");
|
99
|
+
retVal.setTextHeightBehavior(
|
100
|
+
static_cast<para::TextHeightBehavior>(propValue.asNumber()));
|
101
|
+
}
|
102
|
+
if (object.hasProperty(runtime, "strutStyle")) {
|
103
|
+
auto propValue = object.getProperty(runtime, "strutStyle");
|
104
|
+
retVal.setStrutStyle(JsiSkStrutStyle::fromValue(runtime, propValue));
|
105
|
+
}
|
106
|
+
if (object.hasProperty(runtime, "textStyle")) {
|
107
|
+
auto propValue = object.getProperty(runtime, "textStyle");
|
108
|
+
retVal.setTextStyle(JsiSkTextStyle::fromValue(runtime, propValue));
|
109
|
+
}
|
110
|
+
|
111
|
+
return retVal;
|
112
|
+
}
|
113
|
+
|
114
|
+
private:
|
115
|
+
template <typename T>
|
116
|
+
static void fromUTF8(
|
117
|
+
const std::string &source,
|
118
|
+
std::basic_string<T, std::char_traits<T>, std::allocator<T>> &result) {
|
119
|
+
std::wstring_convert<std::codecvt_utf8_utf16<T>, T> convertor;
|
120
|
+
result = convertor.from_bytes(source);
|
121
|
+
}
|
122
|
+
};
|
123
|
+
|
124
|
+
} // namespace RNSkia
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <memory>
|
4
|
+
#include <string>
|
5
|
+
#include <utility>
|
6
|
+
#include <vector>
|
7
|
+
|
8
|
+
#include <jsi/jsi.h>
|
9
|
+
|
10
|
+
#pragma clang diagnostic push
|
11
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
12
|
+
|
13
|
+
#include "Paragraph.h"
|
14
|
+
|
15
|
+
#pragma clang diagnostic pop
|
16
|
+
|
17
|
+
namespace RNSkia {
|
18
|
+
|
19
|
+
namespace jsi = facebook::jsi;
|
20
|
+
|
21
|
+
namespace para = skia::textlayout;
|
22
|
+
|
23
|
+
/**
|
24
|
+
Implementation of the TextStyle object in JSI for the paragraph builder
|
25
|
+
*/
|
26
|
+
class JsiSkStrutStyle {
|
27
|
+
public:
|
28
|
+
static para::StrutStyle fromValue(jsi::Runtime &runtime,
|
29
|
+
const jsi::Value &value) {
|
30
|
+
// Read values from the argument - expected to be a TextStyle shaped object
|
31
|
+
if (!value.isObject()) {
|
32
|
+
throw jsi::JSError(runtime, "Expected SkStrutStyle as first argument");
|
33
|
+
}
|
34
|
+
/**
|
35
|
+
strutEnabled?: boolean;
|
36
|
+
fontFamilies?: string[];
|
37
|
+
fontStyle?: SkTextFontStyle;
|
38
|
+
fontSize?: number;
|
39
|
+
heightMultiplier?: number;
|
40
|
+
halfLeading?: boolean;
|
41
|
+
leading?: number;
|
42
|
+
forceStrutHeight?: boolean;
|
43
|
+
*/
|
44
|
+
auto object = value.asObject(runtime);
|
45
|
+
|
46
|
+
para::StrutStyle retVal;
|
47
|
+
|
48
|
+
if (object.hasProperty(runtime, "strutEnabled")) {
|
49
|
+
auto propValue = object.getProperty(runtime, "strutEnabled");
|
50
|
+
retVal.setStrutEnabled(propValue.asBool());
|
51
|
+
}
|
52
|
+
if (object.hasProperty(runtime, "fontFamilies")) {
|
53
|
+
auto propValue = object.getProperty(runtime, "fontFamilies")
|
54
|
+
.asObject(runtime)
|
55
|
+
.asArray(runtime);
|
56
|
+
auto size = propValue.size(runtime);
|
57
|
+
std::vector<SkString> families(size);
|
58
|
+
for (size_t i = 0; i < size; ++i) {
|
59
|
+
families[i] = propValue.getValueAtIndex(runtime, i)
|
60
|
+
.asString(runtime)
|
61
|
+
.utf8(runtime)
|
62
|
+
.c_str();
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
if (object.hasProperty(runtime, "fontStyle")) {
|
67
|
+
auto propValue = object.getProperty(runtime, "fontStyle");
|
68
|
+
retVal.setFontStyle(*JsiSkFontStyle::fromValue(runtime, propValue).get());
|
69
|
+
}
|
70
|
+
if (object.hasProperty(runtime, "fontSize")) {
|
71
|
+
auto propValue = object.getProperty(runtime, "fontSize");
|
72
|
+
retVal.setFontSize(propValue.asNumber());
|
73
|
+
}
|
74
|
+
if (object.hasProperty(runtime, "heightMultiplier")) {
|
75
|
+
auto propValue = object.getProperty(runtime, "heightMultiplier");
|
76
|
+
retVal.setHeight(propValue.asNumber());
|
77
|
+
retVal.setHeightOverride(true);
|
78
|
+
}
|
79
|
+
if (object.hasProperty(runtime, "halfLeading")) {
|
80
|
+
auto propValue = object.getProperty(runtime, "halfLeading");
|
81
|
+
retVal.setHalfLeading(propValue.asBool());
|
82
|
+
}
|
83
|
+
if (object.hasProperty(runtime, "leading")) {
|
84
|
+
auto propValue = object.getProperty(runtime, "leading");
|
85
|
+
retVal.setLeading(propValue.asNumber());
|
86
|
+
}
|
87
|
+
if (object.hasProperty(runtime, "forceStrutHeight")) {
|
88
|
+
auto propValue = object.getProperty(runtime, "forceStrutHeight");
|
89
|
+
retVal.setForceStrutHeight(propValue.asBool());
|
90
|
+
}
|
91
|
+
|
92
|
+
return retVal;
|
93
|
+
}
|
94
|
+
};
|
95
|
+
|
96
|
+
} // namespace RNSkia
|