@shopify/react-native-skia 0.1.222 → 0.1.223

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. package/cpp/api/JsiSkApi.h +5 -0
  2. package/cpp/api/JsiSkFontMgrFactory.h +9 -4
  3. package/cpp/api/JsiSkParagraph.h +135 -0
  4. package/cpp/api/JsiSkParagraphBuilder.h +159 -0
  5. package/cpp/api/JsiSkParagraphStyle.h +124 -0
  6. package/cpp/api/JsiSkStrutStyle.h +96 -0
  7. package/cpp/api/JsiSkTextStyle.h +185 -0
  8. package/cpp/jsi/JsiHostObject.h +21 -0
  9. package/cpp/rnskia/dom/JsiDomApi.h +4 -0
  10. package/cpp/rnskia/dom/nodes/JsiParagraphNode.h +62 -0
  11. package/cpp/rnskia/dom/props/ParagraphProp.h +45 -0
  12. package/cpp/skia/modules/skunicode/include/SkUnicode.h +312 -0
  13. package/cpp/skia/src/base/SkTInternalLList.h +304 -0
  14. package/cpp/skia/src/base/SkUTF.h +95 -0
  15. package/cpp/skia/src/core/SkLRUCache.h +130 -0
  16. package/lib/commonjs/dom/nodes/JsiSkDOM.d.ts +2 -0
  17. package/lib/commonjs/dom/nodes/JsiSkDOM.js +7 -0
  18. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
  19. package/lib/commonjs/dom/nodes/drawings/ParagraphNode.d.ts +8 -0
  20. package/lib/commonjs/dom/nodes/drawings/ParagraphNode.js +41 -0
  21. package/lib/commonjs/dom/nodes/drawings/ParagraphNode.js.map +1 -0
  22. package/lib/commonjs/dom/types/NodeType.d.ts +2 -1
  23. package/lib/commonjs/dom/types/NodeType.js +1 -0
  24. package/lib/commonjs/dom/types/NodeType.js.map +1 -1
  25. package/lib/commonjs/dom/types/Paragraph.d.ts +8 -0
  26. package/lib/commonjs/dom/types/Paragraph.js +6 -0
  27. package/lib/commonjs/dom/types/Paragraph.js.map +1 -0
  28. package/lib/commonjs/dom/types/SkDOM.d.ts +2 -0
  29. package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
  30. package/lib/commonjs/dom/types/index.d.ts +1 -0
  31. package/lib/commonjs/dom/types/index.js +13 -0
  32. package/lib/commonjs/dom/types/index.js.map +1 -1
  33. package/lib/commonjs/renderer/HostComponents.d.ts +3 -1
  34. package/lib/commonjs/renderer/HostComponents.js +4 -0
  35. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  36. package/lib/commonjs/renderer/components/index.d.ts +1 -0
  37. package/lib/commonjs/renderer/components/index.js +13 -0
  38. package/lib/commonjs/renderer/components/index.js.map +1 -1
  39. package/lib/commonjs/renderer/components/paragraph/Paragraph.d.ts +4 -0
  40. package/lib/commonjs/renderer/components/paragraph/Paragraph.js +17 -0
  41. package/lib/commonjs/renderer/components/paragraph/Paragraph.js.map +1 -0
  42. package/lib/commonjs/renderer/components/paragraph/index.d.ts +1 -0
  43. package/lib/commonjs/renderer/components/paragraph/index.js +19 -0
  44. package/lib/commonjs/renderer/components/paragraph/index.js.map +1 -0
  45. package/lib/commonjs/skia/types/Paragraph/Paragraph.d.ts +56 -0
  46. package/lib/commonjs/skia/types/Paragraph/Paragraph.js +6 -0
  47. package/lib/commonjs/skia/types/Paragraph/Paragraph.js.map +1 -0
  48. package/lib/commonjs/skia/types/Paragraph/ParagraphBuilder.d.ts +60 -0
  49. package/lib/commonjs/skia/types/Paragraph/ParagraphBuilder.js +18 -0
  50. package/lib/commonjs/skia/types/Paragraph/ParagraphBuilder.js.map +1 -0
  51. package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.d.ts +41 -0
  52. package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.js +36 -0
  53. package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.js.map +1 -0
  54. package/lib/commonjs/skia/types/Paragraph/TextStyle.d.ts +62 -0
  55. package/lib/commonjs/skia/types/Paragraph/TextStyle.js +35 -0
  56. package/lib/commonjs/skia/types/Paragraph/TextStyle.js.map +1 -0
  57. package/lib/commonjs/skia/types/Paragraph/index.d.ts +6 -0
  58. package/lib/commonjs/skia/types/Paragraph/index.js +84 -0
  59. package/lib/commonjs/skia/types/Paragraph/index.js.map +1 -0
  60. package/lib/commonjs/skia/types/Skia.d.ts +2 -0
  61. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  62. package/lib/commonjs/skia/types/index.d.ts +1 -0
  63. package/lib/commonjs/skia/types/index.js +13 -0
  64. package/lib/commonjs/skia/types/index.js.map +1 -1
  65. package/lib/commonjs/skia/web/JsiSkParagraph.d.ts +16 -0
  66. package/lib/commonjs/skia/web/JsiSkParagraph.js +91 -0
  67. package/lib/commonjs/skia/web/JsiSkParagraph.js.map +1 -0
  68. package/lib/commonjs/skia/web/JsiSkParagraphBuilder.d.ts +15 -0
  69. package/lib/commonjs/skia/web/JsiSkParagraphBuilder.js +85 -0
  70. package/lib/commonjs/skia/web/JsiSkParagraphBuilder.js.map +1 -0
  71. package/lib/commonjs/skia/web/JsiSkParagraphBuilderFactory.d.ts +8 -0
  72. package/lib/commonjs/skia/web/JsiSkParagraphBuilderFactory.js +34 -0
  73. package/lib/commonjs/skia/web/JsiSkParagraphBuilderFactory.js.map +1 -0
  74. package/lib/commonjs/skia/web/JsiSkParagraphStyle.d.ts +5 -0
  75. package/lib/commonjs/skia/web/JsiSkParagraphStyle.js +59 -0
  76. package/lib/commonjs/skia/web/JsiSkParagraphStyle.js.map +1 -0
  77. package/lib/commonjs/skia/web/JsiSkTextStyle.d.ts +5 -0
  78. package/lib/commonjs/skia/web/JsiSkTextStyle.js +54 -0
  79. package/lib/commonjs/skia/web/JsiSkTextStyle.js.map +1 -0
  80. package/lib/commonjs/skia/web/JsiSkia.js +4 -1
  81. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  82. package/lib/module/dom/nodes/JsiSkDOM.d.ts +2 -0
  83. package/lib/module/dom/nodes/JsiSkDOM.js +6 -0
  84. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  85. package/lib/module/dom/nodes/drawings/ParagraphNode.d.ts +8 -0
  86. package/lib/module/dom/nodes/drawings/ParagraphNode.js +30 -0
  87. package/lib/module/dom/nodes/drawings/ParagraphNode.js.map +1 -0
  88. package/lib/module/dom/types/NodeType.d.ts +2 -1
  89. package/lib/module/dom/types/NodeType.js +1 -0
  90. package/lib/module/dom/types/NodeType.js.map +1 -1
  91. package/lib/module/dom/types/Paragraph.d.ts +8 -0
  92. package/lib/module/dom/types/Paragraph.js +2 -0
  93. package/lib/module/dom/types/Paragraph.js.map +1 -0
  94. package/lib/module/dom/types/SkDOM.d.ts +2 -0
  95. package/lib/module/dom/types/SkDOM.js.map +1 -1
  96. package/lib/module/dom/types/index.d.ts +1 -0
  97. package/lib/module/dom/types/index.js +1 -0
  98. package/lib/module/dom/types/index.js.map +1 -1
  99. package/lib/module/renderer/HostComponents.d.ts +3 -1
  100. package/lib/module/renderer/HostComponents.js +4 -0
  101. package/lib/module/renderer/HostComponents.js.map +1 -1
  102. package/lib/module/renderer/components/index.d.ts +1 -0
  103. package/lib/module/renderer/components/index.js +1 -0
  104. package/lib/module/renderer/components/index.js.map +1 -1
  105. package/lib/module/renderer/components/paragraph/Paragraph.d.ts +4 -0
  106. package/lib/module/renderer/components/paragraph/Paragraph.js +5 -0
  107. package/lib/module/renderer/components/paragraph/Paragraph.js.map +1 -0
  108. package/lib/module/renderer/components/paragraph/index.d.ts +1 -0
  109. package/lib/module/renderer/components/paragraph/index.js +2 -0
  110. package/lib/module/renderer/components/paragraph/index.js.map +1 -0
  111. package/lib/module/skia/types/Paragraph/Paragraph.d.ts +56 -0
  112. package/lib/module/skia/types/Paragraph/Paragraph.js +2 -0
  113. package/lib/module/skia/types/Paragraph/Paragraph.js.map +1 -0
  114. package/lib/module/skia/types/Paragraph/ParagraphBuilder.d.ts +60 -0
  115. package/lib/module/skia/types/Paragraph/ParagraphBuilder.js +11 -0
  116. package/lib/module/skia/types/Paragraph/ParagraphBuilder.js.map +1 -0
  117. package/lib/module/skia/types/Paragraph/ParagraphStyle.d.ts +41 -0
  118. package/lib/module/skia/types/Paragraph/ParagraphStyle.js +27 -0
  119. package/lib/module/skia/types/Paragraph/ParagraphStyle.js.map +1 -0
  120. package/lib/module/skia/types/Paragraph/TextStyle.d.ts +62 -0
  121. package/lib/module/skia/types/Paragraph/TextStyle.js +26 -0
  122. package/lib/module/skia/types/Paragraph/TextStyle.js.map +1 -0
  123. package/lib/module/skia/types/Paragraph/index.d.ts +6 -0
  124. package/lib/module/skia/types/Paragraph/index.js +7 -0
  125. package/lib/module/skia/types/Paragraph/index.js.map +1 -0
  126. package/lib/module/skia/types/Skia.d.ts +2 -0
  127. package/lib/module/skia/types/Skia.js.map +1 -1
  128. package/lib/module/skia/types/index.d.ts +1 -0
  129. package/lib/module/skia/types/index.js +1 -0
  130. package/lib/module/skia/types/index.js.map +1 -1
  131. package/lib/module/skia/web/JsiSkParagraph.d.ts +16 -0
  132. package/lib/module/skia/web/JsiSkParagraph.js +81 -0
  133. package/lib/module/skia/web/JsiSkParagraph.js.map +1 -0
  134. package/lib/module/skia/web/JsiSkParagraphBuilder.d.ts +15 -0
  135. package/lib/module/skia/web/JsiSkParagraphBuilder.js +73 -0
  136. package/lib/module/skia/web/JsiSkParagraphBuilder.js.map +1 -0
  137. package/lib/module/skia/web/JsiSkParagraphBuilderFactory.d.ts +8 -0
  138. package/lib/module/skia/web/JsiSkParagraphBuilderFactory.js +21 -0
  139. package/lib/module/skia/web/JsiSkParagraphBuilderFactory.js.map +1 -0
  140. package/lib/module/skia/web/JsiSkParagraphStyle.d.ts +5 -0
  141. package/lib/module/skia/web/JsiSkParagraphStyle.js +49 -0
  142. package/lib/module/skia/web/JsiSkParagraphStyle.js.map +1 -0
  143. package/lib/module/skia/web/JsiSkTextStyle.d.ts +5 -0
  144. package/lib/module/skia/web/JsiSkTextStyle.js +45 -0
  145. package/lib/module/skia/web/JsiSkTextStyle.js.map +1 -0
  146. package/lib/module/skia/web/JsiSkia.js +3 -1
  147. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  148. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
  149. package/lib/typescript/src/dom/nodes/drawings/ParagraphNode.d.ts +8 -0
  150. package/lib/typescript/src/dom/types/NodeType.d.ts +2 -1
  151. package/lib/typescript/src/dom/types/Paragraph.d.ts +8 -0
  152. package/lib/typescript/src/dom/types/SkDOM.d.ts +2 -0
  153. package/lib/typescript/src/dom/types/index.d.ts +1 -0
  154. package/lib/typescript/src/renderer/HostComponents.d.ts +3 -1
  155. package/lib/typescript/src/renderer/components/index.d.ts +1 -0
  156. package/lib/typescript/src/renderer/components/paragraph/Paragraph.d.ts +4 -0
  157. package/lib/typescript/src/renderer/components/paragraph/index.d.ts +1 -0
  158. package/lib/typescript/src/skia/types/Paragraph/Paragraph.d.ts +56 -0
  159. package/lib/typescript/src/skia/types/Paragraph/ParagraphBuilder.d.ts +60 -0
  160. package/lib/typescript/src/skia/types/Paragraph/ParagraphStyle.d.ts +41 -0
  161. package/lib/typescript/src/skia/types/Paragraph/TextStyle.d.ts +62 -0
  162. package/lib/typescript/src/skia/types/Paragraph/index.d.ts +6 -0
  163. package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
  164. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  165. package/lib/typescript/src/skia/web/JsiSkParagraph.d.ts +16 -0
  166. package/lib/typescript/src/skia/web/JsiSkParagraphBuilder.d.ts +15 -0
  167. package/lib/typescript/src/skia/web/JsiSkParagraphBuilderFactory.d.ts +8 -0
  168. package/lib/typescript/src/skia/web/JsiSkParagraphStyle.d.ts +5 -0
  169. package/lib/typescript/src/skia/web/JsiSkTextStyle.d.ts +5 -0
  170. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  171. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  172. package/libs/ios/libskottie.xcframework/Info.plist +5 -5
  173. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  174. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  175. package/libs/ios/libskparagraph.xcframework/Info.plist +5 -5
  176. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  177. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  178. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  179. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  180. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  181. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  182. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
  183. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
  184. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  185. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  186. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  187. package/package.json +1 -1
  188. package/src/dom/nodes/JsiSkDOM.ts +9 -0
  189. package/src/dom/nodes/drawings/ParagraphNode.ts +22 -0
  190. package/src/dom/types/NodeType.ts +3 -0
  191. package/src/dom/types/Paragraph.ts +10 -0
  192. package/src/dom/types/SkDOM.ts +4 -0
  193. package/src/dom/types/index.ts +1 -0
  194. package/src/renderer/HostComponents.ts +10 -0
  195. package/src/renderer/components/index.ts +2 -0
  196. package/src/renderer/components/paragraph/Paragraph.tsx +8 -0
  197. package/src/renderer/components/paragraph/index.ts +1 -0
  198. package/src/skia/types/Paragraph/Paragraph.ts +59 -0
  199. package/src/skia/types/Paragraph/ParagraphBuilder.ts +96 -0
  200. package/src/skia/types/Paragraph/ParagraphStyle.ts +45 -0
  201. package/src/skia/types/Paragraph/TextStyle.ts +70 -0
  202. package/src/skia/types/Paragraph/index.ts +6 -0
  203. package/src/skia/types/Skia.ts +3 -0
  204. package/src/skia/types/index.ts +1 -0
  205. package/src/skia/web/JsiSkParagraph.ts +69 -0
  206. package/src/skia/web/JsiSkParagraphBuilder.ts +99 -0
  207. package/src/skia/web/JsiSkParagraphBuilderFactory.ts +42 -0
  208. package/src/skia/web/JsiSkParagraphStyle.ts +65 -0
  209. package/src/skia/web/JsiSkTextStyle.ts +53 -0
  210. package/src/skia/web/JsiSkia.ts +2 -0
@@ -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"
@@ -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
- JSI_HOST_FUNCTION(System) {
26
- auto context = getContext();
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, &runtime] { fontMgr = context->createFontMgr(); });
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>(std::move(context), fontMgr));
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