@shopify/react-native-skia 0.1.221 → 0.1.223

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.
Files changed (223) hide show
  1. package/android/cpp/rnskia-android/RNSkAndroidView.h +3 -0
  2. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +1 -0
  3. package/android/cpp/rnskia-android/SkiaOpenGLHelper.h +0 -1
  4. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +46 -6
  5. package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +3 -3
  6. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +8 -14
  7. package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +93 -105
  8. package/cpp/api/JsiSkApi.h +5 -0
  9. package/cpp/api/JsiSkFontMgrFactory.h +9 -4
  10. package/cpp/api/JsiSkParagraph.h +135 -0
  11. package/cpp/api/JsiSkParagraphBuilder.h +159 -0
  12. package/cpp/api/JsiSkParagraphStyle.h +124 -0
  13. package/cpp/api/JsiSkStrutStyle.h +96 -0
  14. package/cpp/api/JsiSkTextStyle.h +185 -0
  15. package/cpp/jsi/JsiHostObject.h +21 -0
  16. package/cpp/rnskia/dom/JsiDomApi.h +4 -0
  17. package/cpp/rnskia/dom/nodes/JsiParagraphNode.h +62 -0
  18. package/cpp/rnskia/dom/props/ParagraphProp.h +45 -0
  19. package/cpp/skia/modules/skunicode/include/SkUnicode.h +312 -0
  20. package/cpp/skia/src/base/SkTInternalLList.h +304 -0
  21. package/cpp/skia/src/base/SkUTF.h +95 -0
  22. package/cpp/skia/src/core/SkLRUCache.h +130 -0
  23. package/cpp/utils/RNSkLog.h +3 -3
  24. package/lib/commonjs/dom/nodes/JsiSkDOM.d.ts +2 -0
  25. package/lib/commonjs/dom/nodes/JsiSkDOM.js +7 -0
  26. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
  27. package/lib/commonjs/dom/nodes/drawings/ParagraphNode.d.ts +8 -0
  28. package/lib/commonjs/dom/nodes/drawings/ParagraphNode.js +41 -0
  29. package/lib/commonjs/dom/nodes/drawings/ParagraphNode.js.map +1 -0
  30. package/lib/commonjs/dom/types/NodeType.d.ts +2 -1
  31. package/lib/commonjs/dom/types/NodeType.js +1 -0
  32. package/lib/commonjs/dom/types/NodeType.js.map +1 -1
  33. package/lib/commonjs/dom/types/Paragraph.d.ts +8 -0
  34. package/lib/commonjs/dom/types/Paragraph.js +6 -0
  35. package/lib/commonjs/dom/types/Paragraph.js.map +1 -0
  36. package/lib/commonjs/dom/types/SkDOM.d.ts +2 -0
  37. package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
  38. package/lib/commonjs/dom/types/index.d.ts +1 -0
  39. package/lib/commonjs/dom/types/index.js +13 -0
  40. package/lib/commonjs/dom/types/index.js.map +1 -1
  41. package/lib/commonjs/renderer/HostComponents.d.ts +3 -1
  42. package/lib/commonjs/renderer/HostComponents.js +4 -0
  43. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  44. package/lib/commonjs/renderer/components/index.d.ts +1 -0
  45. package/lib/commonjs/renderer/components/index.js +13 -0
  46. package/lib/commonjs/renderer/components/index.js.map +1 -1
  47. package/lib/commonjs/renderer/components/paragraph/Paragraph.d.ts +4 -0
  48. package/lib/commonjs/renderer/components/paragraph/Paragraph.js +17 -0
  49. package/lib/commonjs/renderer/components/paragraph/Paragraph.js.map +1 -0
  50. package/lib/commonjs/renderer/components/paragraph/index.d.ts +1 -0
  51. package/lib/commonjs/renderer/components/paragraph/index.js +19 -0
  52. package/lib/commonjs/renderer/components/paragraph/index.js.map +1 -0
  53. package/lib/commonjs/skia/types/Paragraph/Paragraph.d.ts +56 -0
  54. package/lib/commonjs/skia/types/Paragraph/Paragraph.js +6 -0
  55. package/lib/commonjs/skia/types/Paragraph/Paragraph.js.map +1 -0
  56. package/lib/commonjs/skia/types/Paragraph/ParagraphBuilder.d.ts +60 -0
  57. package/lib/commonjs/skia/types/Paragraph/ParagraphBuilder.js +18 -0
  58. package/lib/commonjs/skia/types/Paragraph/ParagraphBuilder.js.map +1 -0
  59. package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.d.ts +41 -0
  60. package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.js +36 -0
  61. package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.js.map +1 -0
  62. package/lib/commonjs/skia/types/Paragraph/TextStyle.d.ts +62 -0
  63. package/lib/commonjs/skia/types/Paragraph/TextStyle.js +35 -0
  64. package/lib/commonjs/skia/types/Paragraph/TextStyle.js.map +1 -0
  65. package/lib/commonjs/skia/types/Paragraph/index.d.ts +6 -0
  66. package/lib/commonjs/skia/types/Paragraph/index.js +84 -0
  67. package/lib/commonjs/skia/types/Paragraph/index.js.map +1 -0
  68. package/lib/commonjs/skia/types/Skia.d.ts +2 -0
  69. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  70. package/lib/commonjs/skia/types/index.d.ts +1 -0
  71. package/lib/commonjs/skia/types/index.js +13 -0
  72. package/lib/commonjs/skia/types/index.js.map +1 -1
  73. package/lib/commonjs/skia/web/JsiSkImage.js +0 -6
  74. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  75. package/lib/commonjs/skia/web/JsiSkParagraph.d.ts +16 -0
  76. package/lib/commonjs/skia/web/JsiSkParagraph.js +91 -0
  77. package/lib/commonjs/skia/web/JsiSkParagraph.js.map +1 -0
  78. package/lib/commonjs/skia/web/JsiSkParagraphBuilder.d.ts +15 -0
  79. package/lib/commonjs/skia/web/JsiSkParagraphBuilder.js +85 -0
  80. package/lib/commonjs/skia/web/JsiSkParagraphBuilder.js.map +1 -0
  81. package/lib/commonjs/skia/web/JsiSkParagraphBuilderFactory.d.ts +8 -0
  82. package/lib/commonjs/skia/web/JsiSkParagraphBuilderFactory.js +34 -0
  83. package/lib/commonjs/skia/web/JsiSkParagraphBuilderFactory.js.map +1 -0
  84. package/lib/commonjs/skia/web/JsiSkParagraphStyle.d.ts +5 -0
  85. package/lib/commonjs/skia/web/JsiSkParagraphStyle.js +59 -0
  86. package/lib/commonjs/skia/web/JsiSkParagraphStyle.js.map +1 -0
  87. package/lib/commonjs/skia/web/JsiSkTextStyle.d.ts +5 -0
  88. package/lib/commonjs/skia/web/JsiSkTextStyle.js +54 -0
  89. package/lib/commonjs/skia/web/JsiSkTextStyle.js.map +1 -0
  90. package/lib/commonjs/skia/web/JsiSkia.js +4 -1
  91. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  92. package/lib/module/dom/nodes/JsiSkDOM.d.ts +2 -0
  93. package/lib/module/dom/nodes/JsiSkDOM.js +6 -0
  94. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  95. package/lib/module/dom/nodes/drawings/ParagraphNode.d.ts +8 -0
  96. package/lib/module/dom/nodes/drawings/ParagraphNode.js +30 -0
  97. package/lib/module/dom/nodes/drawings/ParagraphNode.js.map +1 -0
  98. package/lib/module/dom/types/NodeType.d.ts +2 -1
  99. package/lib/module/dom/types/NodeType.js +1 -0
  100. package/lib/module/dom/types/NodeType.js.map +1 -1
  101. package/lib/module/dom/types/Paragraph.d.ts +8 -0
  102. package/lib/module/dom/types/Paragraph.js +2 -0
  103. package/lib/module/dom/types/Paragraph.js.map +1 -0
  104. package/lib/module/dom/types/SkDOM.d.ts +2 -0
  105. package/lib/module/dom/types/SkDOM.js.map +1 -1
  106. package/lib/module/dom/types/index.d.ts +1 -0
  107. package/lib/module/dom/types/index.js +1 -0
  108. package/lib/module/dom/types/index.js.map +1 -1
  109. package/lib/module/renderer/HostComponents.d.ts +3 -1
  110. package/lib/module/renderer/HostComponents.js +4 -0
  111. package/lib/module/renderer/HostComponents.js.map +1 -1
  112. package/lib/module/renderer/components/index.d.ts +1 -0
  113. package/lib/module/renderer/components/index.js +1 -0
  114. package/lib/module/renderer/components/index.js.map +1 -1
  115. package/lib/module/renderer/components/paragraph/Paragraph.d.ts +4 -0
  116. package/lib/module/renderer/components/paragraph/Paragraph.js +5 -0
  117. package/lib/module/renderer/components/paragraph/Paragraph.js.map +1 -0
  118. package/lib/module/renderer/components/paragraph/index.d.ts +1 -0
  119. package/lib/module/renderer/components/paragraph/index.js +2 -0
  120. package/lib/module/renderer/components/paragraph/index.js.map +1 -0
  121. package/lib/module/skia/types/Paragraph/Paragraph.d.ts +56 -0
  122. package/lib/module/skia/types/Paragraph/Paragraph.js +2 -0
  123. package/lib/module/skia/types/Paragraph/Paragraph.js.map +1 -0
  124. package/lib/module/skia/types/Paragraph/ParagraphBuilder.d.ts +60 -0
  125. package/lib/module/skia/types/Paragraph/ParagraphBuilder.js +11 -0
  126. package/lib/module/skia/types/Paragraph/ParagraphBuilder.js.map +1 -0
  127. package/lib/module/skia/types/Paragraph/ParagraphStyle.d.ts +41 -0
  128. package/lib/module/skia/types/Paragraph/ParagraphStyle.js +27 -0
  129. package/lib/module/skia/types/Paragraph/ParagraphStyle.js.map +1 -0
  130. package/lib/module/skia/types/Paragraph/TextStyle.d.ts +62 -0
  131. package/lib/module/skia/types/Paragraph/TextStyle.js +26 -0
  132. package/lib/module/skia/types/Paragraph/TextStyle.js.map +1 -0
  133. package/lib/module/skia/types/Paragraph/index.d.ts +6 -0
  134. package/lib/module/skia/types/Paragraph/index.js +7 -0
  135. package/lib/module/skia/types/Paragraph/index.js.map +1 -0
  136. package/lib/module/skia/types/Skia.d.ts +2 -0
  137. package/lib/module/skia/types/Skia.js.map +1 -1
  138. package/lib/module/skia/types/index.d.ts +1 -0
  139. package/lib/module/skia/types/index.js +1 -0
  140. package/lib/module/skia/types/index.js.map +1 -1
  141. package/lib/module/skia/web/JsiSkImage.js +0 -6
  142. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  143. package/lib/module/skia/web/JsiSkParagraph.d.ts +16 -0
  144. package/lib/module/skia/web/JsiSkParagraph.js +81 -0
  145. package/lib/module/skia/web/JsiSkParagraph.js.map +1 -0
  146. package/lib/module/skia/web/JsiSkParagraphBuilder.d.ts +15 -0
  147. package/lib/module/skia/web/JsiSkParagraphBuilder.js +73 -0
  148. package/lib/module/skia/web/JsiSkParagraphBuilder.js.map +1 -0
  149. package/lib/module/skia/web/JsiSkParagraphBuilderFactory.d.ts +8 -0
  150. package/lib/module/skia/web/JsiSkParagraphBuilderFactory.js +21 -0
  151. package/lib/module/skia/web/JsiSkParagraphBuilderFactory.js.map +1 -0
  152. package/lib/module/skia/web/JsiSkParagraphStyle.d.ts +5 -0
  153. package/lib/module/skia/web/JsiSkParagraphStyle.js +49 -0
  154. package/lib/module/skia/web/JsiSkParagraphStyle.js.map +1 -0
  155. package/lib/module/skia/web/JsiSkTextStyle.d.ts +5 -0
  156. package/lib/module/skia/web/JsiSkTextStyle.js +45 -0
  157. package/lib/module/skia/web/JsiSkTextStyle.js.map +1 -0
  158. package/lib/module/skia/web/JsiSkia.js +3 -1
  159. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  160. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
  161. package/lib/typescript/src/dom/nodes/drawings/ParagraphNode.d.ts +8 -0
  162. package/lib/typescript/src/dom/types/NodeType.d.ts +2 -1
  163. package/lib/typescript/src/dom/types/Paragraph.d.ts +8 -0
  164. package/lib/typescript/src/dom/types/SkDOM.d.ts +2 -0
  165. package/lib/typescript/src/dom/types/index.d.ts +1 -0
  166. package/lib/typescript/src/renderer/HostComponents.d.ts +3 -1
  167. package/lib/typescript/src/renderer/components/index.d.ts +1 -0
  168. package/lib/typescript/src/renderer/components/paragraph/Paragraph.d.ts +4 -0
  169. package/lib/typescript/src/renderer/components/paragraph/index.d.ts +1 -0
  170. package/lib/typescript/src/skia/types/Paragraph/Paragraph.d.ts +56 -0
  171. package/lib/typescript/src/skia/types/Paragraph/ParagraphBuilder.d.ts +60 -0
  172. package/lib/typescript/src/skia/types/Paragraph/ParagraphStyle.d.ts +41 -0
  173. package/lib/typescript/src/skia/types/Paragraph/TextStyle.d.ts +62 -0
  174. package/lib/typescript/src/skia/types/Paragraph/index.d.ts +6 -0
  175. package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
  176. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  177. package/lib/typescript/src/skia/web/JsiSkParagraph.d.ts +16 -0
  178. package/lib/typescript/src/skia/web/JsiSkParagraphBuilder.d.ts +15 -0
  179. package/lib/typescript/src/skia/web/JsiSkParagraphBuilderFactory.d.ts +8 -0
  180. package/lib/typescript/src/skia/web/JsiSkParagraphStyle.d.ts +5 -0
  181. package/lib/typescript/src/skia/web/JsiSkTextStyle.d.ts +5 -0
  182. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  183. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  184. package/libs/ios/libskottie.xcframework/Info.plist +5 -5
  185. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  186. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  187. package/libs/ios/libskparagraph.xcframework/Info.plist +5 -5
  188. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  189. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  190. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  191. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  192. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  193. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  194. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
  195. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
  196. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  197. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  198. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  199. package/package.json +1 -1
  200. package/src/dom/nodes/JsiSkDOM.ts +9 -0
  201. package/src/dom/nodes/drawings/ParagraphNode.ts +22 -0
  202. package/src/dom/types/NodeType.ts +3 -0
  203. package/src/dom/types/Paragraph.ts +10 -0
  204. package/src/dom/types/SkDOM.ts +4 -0
  205. package/src/dom/types/index.ts +1 -0
  206. package/src/renderer/HostComponents.ts +10 -0
  207. package/src/renderer/components/index.ts +2 -0
  208. package/src/renderer/components/paragraph/Paragraph.tsx +8 -0
  209. package/src/renderer/components/paragraph/index.ts +1 -0
  210. package/src/skia/types/Paragraph/Paragraph.ts +59 -0
  211. package/src/skia/types/Paragraph/ParagraphBuilder.ts +96 -0
  212. package/src/skia/types/Paragraph/ParagraphStyle.ts +45 -0
  213. package/src/skia/types/Paragraph/TextStyle.ts +70 -0
  214. package/src/skia/types/Paragraph/index.ts +6 -0
  215. package/src/skia/types/Skia.ts +3 -0
  216. package/src/skia/types/index.ts +1 -0
  217. package/src/skia/web/JsiSkImage.ts +0 -6
  218. package/src/skia/web/JsiSkParagraph.ts +69 -0
  219. package/src/skia/web/JsiSkParagraphBuilder.ts +99 -0
  220. package/src/skia/web/JsiSkParagraphBuilderFactory.ts +42 -0
  221. package/src/skia/web/JsiSkParagraphStyle.ts +65 -0
  222. package/src/skia/web/JsiSkTextStyle.ts +53 -0
  223. package/src/skia/web/JsiSkia.ts +2 -0
@@ -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
@@ -0,0 +1,185 @@
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
+ #include "ParagraphStyle.h"
15
+
16
+ #pragma clang diagnostic pop
17
+
18
+ namespace RNSkia {
19
+
20
+ namespace jsi = facebook::jsi;
21
+
22
+ namespace para = skia::textlayout;
23
+
24
+ /**
25
+ Implementation of the TextStyle object in JSI for the paragraph builder
26
+ */
27
+ class JsiSkTextStyle {
28
+ public:
29
+ static para::TextStyle fromValue(jsi::Runtime &runtime,
30
+ const jsi::Value &value) {
31
+
32
+ para::TextStyle retVal;
33
+
34
+ // Accept undefined && null
35
+ if (value.isUndefined() || value.isNull()) {
36
+ return retVal;
37
+ }
38
+
39
+ // Read values from the argument - expected to be a TextStyle shaped object
40
+ if (!value.isObject()) {
41
+ throw jsi::JSError(runtime, "Expected SkTextStyle as first argument");
42
+ }
43
+
44
+ auto object = value.asObject(runtime);
45
+
46
+ if (object.hasProperty(runtime, "backgroundColor")) {
47
+ auto propValue = object.getProperty(runtime, "backgroundColor");
48
+ SkPaint p;
49
+ p.setColor(JsiSkColor::fromValue(runtime, propValue));
50
+ retVal.setBackgroundPaint(p);
51
+ }
52
+ if (object.hasProperty(runtime, "color")) {
53
+ auto propValue = object.getProperty(runtime, "color");
54
+ retVal.setColor(JsiSkColor::fromValue(runtime, propValue));
55
+ }
56
+ if (object.hasProperty(runtime, "decoration")) {
57
+ auto propValue = object.getProperty(runtime, "decoration");
58
+ retVal.setDecoration(
59
+ static_cast<para::TextDecoration>(propValue.asNumber()));
60
+ }
61
+ if (object.hasProperty(runtime, "decorationColor")) {
62
+ auto propValue = object.getProperty(runtime, "decorationColor");
63
+ retVal.setDecorationColor(JsiSkColor::fromValue(runtime, propValue));
64
+ }
65
+ if (object.hasProperty(runtime, "decorationThickness")) {
66
+ auto propValue = object.getProperty(runtime, "decorationThickness");
67
+ retVal.setDecorationThicknessMultiplier(propValue.asNumber());
68
+ }
69
+ if (object.hasProperty(runtime, "decorationStyle")) {
70
+ auto propValue = object.getProperty(runtime, "decorationStyle");
71
+ retVal.setDecorationStyle(
72
+ static_cast<para::TextDecorationStyle>(propValue.asNumber()));
73
+ }
74
+ if (object.hasProperty(runtime, "fontFamilies")) {
75
+ auto propValue = object.getProperty(runtime, "fontFamilies")
76
+ .asObject(runtime)
77
+ .asArray(runtime);
78
+ auto size = propValue.size(runtime);
79
+ std::vector<SkString> families(size);
80
+ for (size_t i = 0; i < size; ++i) {
81
+ families[i] = propValue.getValueAtIndex(runtime, i)
82
+ .asString(runtime)
83
+ .utf8(runtime)
84
+ .c_str();
85
+ }
86
+ retVal.setFontFamilies(families);
87
+ }
88
+ if (object.hasProperty(runtime, "fontFeatures")) {
89
+ auto propValue = object.getProperty(runtime, "fontFeatures")
90
+ .asObject(runtime)
91
+ .asArray(runtime);
92
+ auto size = propValue.size(runtime);
93
+ retVal.resetFontFeatures();
94
+ for (size_t i = 0; i < size; ++i) {
95
+ auto element = propValue.getValueAtIndex(runtime, i).asObject(runtime);
96
+ auto name = element.getProperty(runtime, "name")
97
+ .asString(runtime)
98
+ .utf8(runtime);
99
+ auto value = element.getProperty(runtime, "value").asNumber();
100
+ retVal.addFontFeature(SkString(name), value);
101
+ }
102
+ }
103
+ if (object.hasProperty(runtime, "fontSize")) {
104
+ auto propValue = object.getProperty(runtime, "fontSize");
105
+ retVal.setFontSize(propValue.asNumber());
106
+ }
107
+ if (object.hasProperty(runtime, "fontStyle")) {
108
+ auto propValue =
109
+ object.getProperty(runtime, "fontStyle").asObject(runtime);
110
+ auto weight = static_cast<SkFontStyle::Weight>(
111
+ propValue.hasProperty(runtime, "weight")
112
+ ? propValue.getProperty(runtime, "weight").asNumber()
113
+ : SkFontStyle::Weight::kNormal_Weight);
114
+
115
+ auto width = static_cast<SkFontStyle::Width>(
116
+ propValue.hasProperty(runtime, "width")
117
+ ? propValue.getProperty(runtime, "width").asNumber()
118
+ : SkFontStyle::Width::kNormal_Width);
119
+
120
+ auto slant = static_cast<SkFontStyle::Slant>(
121
+ propValue.hasProperty(runtime, "slant")
122
+ ? propValue.getProperty(runtime, "slant").asNumber()
123
+ : SkFontStyle::Slant::kUpright_Slant);
124
+
125
+ retVal.setFontStyle(SkFontStyle(weight, width, slant));
126
+ }
127
+ if (object.hasProperty(runtime, "foregroundColor")) {
128
+ auto propValue = object.getProperty(runtime, "foregroundColor");
129
+ SkPaint p;
130
+ p.setColor(JsiSkColor::fromValue(runtime, propValue));
131
+ retVal.setForegroundColor(p);
132
+ }
133
+ if (object.hasProperty(runtime, "heightMultiplier")) {
134
+ auto propValue = object.getProperty(runtime, "heightMultiplier");
135
+ retVal.setHeight(propValue.asNumber());
136
+ retVal.setHeightOverride(true);
137
+ }
138
+ if (object.hasProperty(runtime, "halfLeading")) {
139
+ auto propValue = object.getProperty(runtime, "halfLeading");
140
+ retVal.setHalfLeading(propValue.asNumber());
141
+ }
142
+ if (object.hasProperty(runtime, "letterSpacing")) {
143
+ auto propValue = object.getProperty(runtime, "letterSpacing");
144
+ retVal.setLetterSpacing(propValue.asNumber());
145
+ }
146
+ if (object.hasProperty(runtime, "locale")) {
147
+ auto propValue = object.getProperty(runtime, "locale");
148
+ retVal.setLocale(SkString(propValue.asString(runtime).utf8(runtime)));
149
+ }
150
+ if (object.hasProperty(runtime, "shadows")) {
151
+ auto propValue = object.getProperty(runtime, "shadows")
152
+ .asObject(runtime)
153
+ .asArray(runtime);
154
+ auto size = propValue.size(runtime);
155
+ retVal.resetShadows();
156
+ for (size_t i = 0; i < size; ++i) {
157
+ auto element = propValue.getValueAtIndex(runtime, i).asObject(runtime);
158
+ auto color = element.hasProperty(runtime, "color")
159
+ ? JsiSkColor::fromValue(
160
+ runtime, element.getProperty(runtime, "color"))
161
+ : SK_ColorBLACK;
162
+ SkPoint offset =
163
+ element.hasProperty(runtime, "offset")
164
+ ? *JsiSkPoint::fromValue(runtime,
165
+ element.getProperty(runtime, "offset"))
166
+ .get()
167
+ : SkPoint::Make(0, 0);
168
+ auto blurSigma =
169
+ element.hasProperty(runtime, "blurRadius")
170
+ ? element.getProperty(runtime, "blurRadius").asNumber()
171
+ : 0;
172
+ retVal.addShadow(para::TextShadow(color, offset, blurSigma));
173
+ }
174
+ }
175
+ if (object.hasProperty(runtime, "textBaseline")) {
176
+ auto propValue = object.getProperty(runtime, "textBaseline");
177
+ retVal.setTextBaseline(
178
+ static_cast<para::TextBaseline>(propValue.asNumber()));
179
+ }
180
+
181
+ return retVal;
182
+ }
183
+ };
184
+
185
+ } // namespace RNSkia
@@ -331,6 +331,27 @@ protected:
331
331
  return value.asHostObject<T>(runtime);
332
332
  }
333
333
 
334
+ /**
335
+ Returns argument as host object or nullptr if the value is not a valid host
336
+ object of requested type
337
+ */
338
+ template <typename T = HostObject>
339
+ static std::shared_ptr<T>
340
+ tryGetArgumentAsHostObject(jsi::Runtime &runtime, const jsi::Value *arguments,
341
+ size_t count, size_t index) {
342
+ const jsi::Value &value = getArgument(runtime, arguments, count, index);
343
+ if (!value.isObject()) {
344
+ return nullptr;
345
+ }
346
+
347
+ auto object = value.asObject(runtime);
348
+ if (!object.isHostObject(runtime)) {
349
+ return nullptr;
350
+ }
351
+
352
+ return object.asHostObject<T>(runtime);
353
+ }
354
+
334
355
  /**
335
356
  Returns argument as array or throws
336
357
  */
@@ -48,6 +48,7 @@
48
48
  #include "nodes/JsiTextPathNode.h"
49
49
 
50
50
  #include "nodes/JsiLayerNode.h"
51
+ #include "nodes/JsiParagraphNode.h"
51
52
 
52
53
  namespace RNSkia {
53
54
 
@@ -162,6 +163,9 @@ public:
162
163
  installFunction("TextBlobNode", JsiTextBlobNode::createCtor(context));
163
164
 
164
165
  installFunction("LayerNode", JsiLayerNode::createCtor(context));
166
+
167
+ // Paragraph node
168
+ installFunction("ParagraphNode", JsiParagraphNode::createCtor(context));
165
169
  }
166
170
  };
167
171
 
@@ -0,0 +1,62 @@
1
+ #pragma once
2
+
3
+ #include "JsiDomDrawingNode.h"
4
+ #include "ParagraphProp.h"
5
+
6
+ #include <memory>
7
+
8
+ namespace RNSkia {
9
+
10
+ class JsiParagraphNode : public JsiDomDrawingNode,
11
+ public JsiDomNodeCtor<JsiParagraphNode> {
12
+ public:
13
+ explicit JsiParagraphNode(std::shared_ptr<RNSkPlatformContext> context)
14
+ : JsiDomDrawingNode(context, "skParagraph") {}
15
+
16
+ protected:
17
+ void draw(DrawingContext *context) override {
18
+ auto x = _xProp->value().getAsNumber();
19
+ auto y = _yProp->value().getAsNumber();
20
+ auto width = static_cast<SkScalar>(_widthProp->value().getAsNumber());
21
+
22
+ auto p = *_paragraphProp->getDerivedValue();
23
+ if (p != nullptr) {
24
+
25
+ // Let's ensure that we don't perform unnecessary layouts on the
26
+ // paragraph. We should only layout if we have a new paragraph or if the
27
+ // layout width has changed.
28
+ if (_lastLayoutWidth != width || _lastLayoutParagraph != p) {
29
+ // perform layout!
30
+ p->layout(width);
31
+ _lastLayoutWidth = width;
32
+ _lastLayoutParagraph = p;
33
+ }
34
+ // Paint the layout to the canvas
35
+ p->paint(context->getCanvas(), x, y);
36
+ }
37
+ }
38
+
39
+ void defineProperties(NodePropsContainer *container) override {
40
+ JsiDomDrawingNode::defineProperties(container);
41
+ _paragraphProp = container->defineProperty<ParagraphProp>("paragraph");
42
+
43
+ _xProp = container->defineProperty<NodeProp>("x");
44
+ _xProp->require();
45
+
46
+ _yProp = container->defineProperty<NodeProp>("y");
47
+ _yProp->require();
48
+
49
+ _widthProp = container->defineProperty<NodeProp>("width");
50
+ _widthProp->require();
51
+ }
52
+
53
+ private:
54
+ ParagraphProp *_paragraphProp;
55
+ NodeProp *_xProp;
56
+ NodeProp *_yProp;
57
+ NodeProp *_widthProp;
58
+ SkScalar _lastLayoutWidth;
59
+ para::Paragraph *_lastLayoutParagraph = nullptr;
60
+ };
61
+
62
+ } // namespace RNSkia