@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,45 @@
1
+ #pragma once
2
+
3
+ #include "DerivedNodeProp.h"
4
+
5
+ #include "JsiSkParagraph.h"
6
+
7
+ #include <memory>
8
+ #include <string>
9
+
10
+ namespace RNSkia {
11
+
12
+ class ParagraphProp : public DerivedProp<para::Paragraph *> {
13
+ public:
14
+ explicit ParagraphProp(PropId name,
15
+ const std::function<void(BaseNodeProp *)> &onChange)
16
+ : DerivedProp<para::Paragraph *>(onChange) {
17
+ _paragraphProp = defineProperty<NodeProp>(name);
18
+ }
19
+
20
+ void updateDerivedValue() override {
21
+ if (_paragraphProp->isSet()) {
22
+ if (_paragraphProp->value().getType() != PropType::HostObject) {
23
+ throw std::runtime_error("Expected Paragraph object for the " +
24
+ std::string(getName()) + " property.");
25
+ }
26
+
27
+ auto ptr = std::dynamic_pointer_cast<JsiSkParagraph>(
28
+ _paragraphProp->value().getAsHostObject());
29
+
30
+ if (ptr == nullptr) {
31
+ throw std::runtime_error("Expected paragraph object for the " +
32
+ std::string(getName()) + " property.");
33
+ }
34
+
35
+ setDerivedValue(ptr->getParagraph());
36
+ } else {
37
+ setDerivedValue(nullptr);
38
+ }
39
+ }
40
+
41
+ private:
42
+ NodeProp *_paragraphProp;
43
+ };
44
+
45
+ } // namespace RNSkia
@@ -0,0 +1,312 @@
1
+ /*
2
+ * Copyright 2020 Google LLC
3
+ *
4
+ * Use of this source code is governed by a BSD-style license that can be
5
+ * found in the LICENSE file.
6
+ */
7
+ #ifndef SkUnicode_DEFINED
8
+ #define SkUnicode_DEFINED
9
+ #include "include/core/SkSpan.h"
10
+ #include "include/core/SkString.h"
11
+ #include "include/core/SkTypes.h"
12
+ #include "include/private/base/SkTArray.h"
13
+ #include "include/private/base/SkTo.h"
14
+ #include "src/base/SkUTF.h"
15
+
16
+ #include <cstddef>
17
+ #include <cstdint>
18
+ #include <memory>
19
+ #include <string>
20
+ #include <vector>
21
+
22
+ #if !defined(SKUNICODE_IMPLEMENTATION)
23
+ #define SKUNICODE_IMPLEMENTATION 0
24
+ #endif
25
+
26
+ #if !defined(SKUNICODE_API)
27
+ #if defined(SKUNICODE_DLL)
28
+ #if defined(_MSC_VER)
29
+ #if SKUNICODE_IMPLEMENTATION
30
+ #define SKUNICODE_API __declspec(dllexport)
31
+ #else
32
+ #define SKUNICODE_API __declspec(dllimport)
33
+ #endif
34
+ #else
35
+ #define SKUNICODE_API __attribute__((visibility("default")))
36
+ #endif
37
+ #else
38
+ #define SKUNICODE_API
39
+ #endif
40
+ #endif
41
+
42
+ namespace sknonstd {
43
+ template <typename T> struct is_bitmask_enum;
44
+ }
45
+
46
+ class SKUNICODE_API SkBidiIterator {
47
+ public:
48
+ typedef int32_t Position;
49
+ typedef uint8_t Level;
50
+ struct Region {
51
+ Region(Position start, Position end, Level level)
52
+ : start(start), end(end), level(level) { }
53
+ Position start;
54
+ Position end;
55
+ Level level;
56
+ };
57
+ enum Direction {
58
+ kLTR,
59
+ kRTL,
60
+ };
61
+ virtual ~SkBidiIterator() = default;
62
+ virtual Position getLength() = 0;
63
+ virtual Level getLevelAt(Position) = 0;
64
+ };
65
+
66
+ class SKUNICODE_API SkBreakIterator {
67
+ public:
68
+ typedef int32_t Position;
69
+ typedef int32_t Status;
70
+ virtual ~SkBreakIterator() = default;
71
+ virtual Position first() = 0;
72
+ virtual Position current() = 0;
73
+ virtual Position next() = 0;
74
+ virtual Status status() = 0;
75
+ virtual bool isDone() = 0;
76
+ virtual bool setText(const char utftext8[], int utf8Units) = 0;
77
+ virtual bool setText(const char16_t utftext16[], int utf16Units) = 0;
78
+ };
79
+
80
+ class SKUNICODE_API SkUnicode {
81
+ public:
82
+ enum CodeUnitFlags {
83
+ kNoCodeUnitFlag = 0x00,
84
+ kPartOfWhiteSpaceBreak = 0x01,
85
+ kGraphemeStart = 0x02,
86
+ kSoftLineBreakBefore = 0x04,
87
+ kHardLineBreakBefore = 0x08,
88
+ kPartOfIntraWordBreak = 0x10,
89
+ kControl = 0x20,
90
+ kTabulation = 0x40,
91
+ kGlyphClusterStart = 0x80,
92
+ kIdeographic = 0x100,
93
+ kEmoji = 0x200,
94
+ kWordBreak = 0x400,
95
+ kSentenceBreak = 0x800,
96
+ };
97
+ enum class TextDirection {
98
+ kLTR,
99
+ kRTL,
100
+ };
101
+ typedef size_t Position;
102
+ typedef uint8_t BidiLevel;
103
+ struct BidiRegion {
104
+ BidiRegion(Position start, Position end, BidiLevel level)
105
+ : start(start), end(end), level(level) { }
106
+ Position start;
107
+ Position end;
108
+ BidiLevel level;
109
+ };
110
+ enum class LineBreakType {
111
+ kSoftLineBreak = 0,
112
+ kHardLineBreak = 100,
113
+ };
114
+
115
+ enum class BreakType { kWords, kGraphemes, kLines, kSentences };
116
+ struct LineBreakBefore {
117
+ LineBreakBefore(Position pos, LineBreakType breakType)
118
+ : pos(pos), breakType(breakType) { }
119
+ Position pos;
120
+ LineBreakType breakType;
121
+ };
122
+
123
+ virtual ~SkUnicode() = default;
124
+
125
+ virtual SkString toUpper(const SkString&) = 0;
126
+
127
+ virtual bool isControl(SkUnichar utf8) = 0;
128
+ virtual bool isWhitespace(SkUnichar utf8) = 0;
129
+ virtual bool isSpace(SkUnichar utf8) = 0;
130
+ virtual bool isTabulation(SkUnichar utf8) = 0;
131
+ virtual bool isHardBreak(SkUnichar utf8) = 0;
132
+ virtual bool isEmoji(SkUnichar utf8) = 0;
133
+ virtual bool isIdeographic(SkUnichar utf8) = 0;
134
+
135
+ // Methods used in SkShaper and SkText
136
+ virtual std::unique_ptr<SkBidiIterator> makeBidiIterator
137
+ (const uint16_t text[], int count, SkBidiIterator::Direction) = 0;
138
+ virtual std::unique_ptr<SkBidiIterator> makeBidiIterator
139
+ (const char text[], int count, SkBidiIterator::Direction) = 0;
140
+ virtual std::unique_ptr<SkBreakIterator> makeBreakIterator
141
+ (const char locale[], BreakType breakType) = 0;
142
+ virtual std::unique_ptr<SkBreakIterator> makeBreakIterator(BreakType type) = 0;
143
+
144
+ // Methods used in SkParagraph
145
+ static bool hasTabulationFlag(SkUnicode::CodeUnitFlags flags);
146
+ static bool hasHardLineBreakFlag(SkUnicode::CodeUnitFlags flags);
147
+ static bool hasSoftLineBreakFlag(SkUnicode::CodeUnitFlags flags);
148
+ static bool hasGraphemeStartFlag(SkUnicode::CodeUnitFlags flags);
149
+ static bool hasControlFlag(SkUnicode::CodeUnitFlags flags);
150
+ static bool hasPartOfWhiteSpaceBreakFlag(SkUnicode::CodeUnitFlags flags);
151
+
152
+ static bool extractBidi(const char utf8[],
153
+ int utf8Units,
154
+ TextDirection dir,
155
+ std::vector<BidiRegion>* bidiRegions);
156
+ virtual bool getBidiRegions(const char utf8[],
157
+ int utf8Units,
158
+ TextDirection dir,
159
+ std::vector<BidiRegion>* results) = 0;
160
+ // Returns results in utf16
161
+ virtual bool getWords(const char utf8[], int utf8Units, const char* locale,
162
+ std::vector<Position>* results) = 0;
163
+ virtual bool getUtf8Words(const char utf8[],
164
+ int utf8Units,
165
+ const char* locale,
166
+ std::vector<Position>* results) = 0;
167
+ virtual bool getSentences(const char utf8[],
168
+ int utf8Units,
169
+ const char* locale,
170
+ std::vector<Position>* results) = 0;
171
+ virtual bool computeCodeUnitFlags(
172
+ char utf8[], int utf8Units, bool replaceTabs,
173
+ skia_private::TArray<SkUnicode::CodeUnitFlags, true>* results) = 0;
174
+ virtual bool computeCodeUnitFlags(
175
+ char16_t utf16[], int utf16Units, bool replaceTabs,
176
+ skia_private::TArray<SkUnicode::CodeUnitFlags, true>* results) = 0;
177
+
178
+ static SkString convertUtf16ToUtf8(const char16_t * utf16, int utf16Units);
179
+ static SkString convertUtf16ToUtf8(const std::u16string& utf16);
180
+ static std::u16string convertUtf8ToUtf16(const char* utf8, int utf8Units);
181
+ static std::u16string convertUtf8ToUtf16(const SkString& utf8);
182
+
183
+ template <typename Appender8, typename Appender16>
184
+ static bool extractUtfConversionMapping(SkSpan<const char> utf8, Appender8&& appender8, Appender16&& appender16) {
185
+ size_t size8 = 0;
186
+ size_t size16 = 0;
187
+ auto ptr = utf8.begin();
188
+ auto end = utf8.end();
189
+ while (ptr < end) {
190
+
191
+ size_t index = SkToSizeT(ptr - utf8.begin());
192
+ SkUnichar u = SkUTF::NextUTF8(&ptr, end);
193
+
194
+ // All UTF8 code units refer to the same codepoint
195
+ size_t next = SkToSizeT(ptr - utf8.begin());
196
+ for (auto i = index; i < next; ++i) {
197
+ //fUTF16IndexForUTF8Index.emplace_back(fUTF8IndexForUTF16Index.size());
198
+ appender16(size8);
199
+ ++size16;
200
+ }
201
+ //SkASSERT(fUTF16IndexForUTF8Index.size() == next);
202
+ SkASSERT(size16 == next);
203
+ if (size16 != next) {
204
+ return false;
205
+ }
206
+
207
+ // One or two UTF16 code units refer to the same codepoint
208
+ uint16_t buffer[2];
209
+ size_t count = SkUTF::ToUTF16(u, buffer);
210
+ //fUTF8IndexForUTF16Index.emplace_back(index);
211
+ appender8(index);
212
+ ++size8;
213
+ if (count > 1) {
214
+ //fUTF8IndexForUTF16Index.emplace_back(index);
215
+ appender8(index);
216
+ ++size8;
217
+ }
218
+ }
219
+ //fUTF16IndexForUTF8Index.emplace_back(fUTF8IndexForUTF16Index.size());
220
+ appender16(size8);
221
+ ++size16;
222
+ //fUTF8IndexForUTF16Index.emplace_back(fText.size());
223
+ appender8(utf8.size());
224
+ ++size8;
225
+
226
+ return true;
227
+ }
228
+
229
+ template <typename Callback>
230
+ void forEachCodepoint(const char* utf8, int32_t utf8Units, Callback&& callback) {
231
+ const char* current = utf8;
232
+ const char* end = utf8 + utf8Units;
233
+ while (current < end) {
234
+ auto before = current - utf8;
235
+ SkUnichar unichar = SkUTF::NextUTF8(&current, end);
236
+ if (unichar < 0) unichar = 0xFFFD;
237
+ auto after = current - utf8;
238
+ uint16_t buffer[2];
239
+ size_t count = SkUTF::ToUTF16(unichar, buffer);
240
+ callback(unichar, before, after, count);
241
+ }
242
+ }
243
+
244
+ template <typename Callback>
245
+ void forEachCodepoint(const char16_t* utf16, int32_t utf16Units, Callback&& callback) {
246
+ const char16_t* current = utf16;
247
+ const char16_t* end = utf16 + utf16Units;
248
+ while (current < end) {
249
+ auto before = current - utf16;
250
+ SkUnichar unichar = SkUTF::NextUTF16((const uint16_t**)&current, (const uint16_t*)end);
251
+ auto after = current - utf16;
252
+ callback(unichar, before, after);
253
+ }
254
+ }
255
+
256
+ template <typename Callback>
257
+ void forEachBidiRegion(const uint16_t utf16[], int utf16Units, SkBidiIterator::Direction dir, Callback&& callback) {
258
+ auto iter = makeBidiIterator(utf16, utf16Units, dir);
259
+ const uint16_t* start16 = utf16;
260
+ const uint16_t* end16 = utf16 + utf16Units;
261
+ SkBidiIterator::Level currentLevel = 0;
262
+
263
+ SkBidiIterator::Position pos16 = 0;
264
+ while (pos16 <= iter->getLength()) {
265
+ auto level = iter->getLevelAt(pos16);
266
+ if (pos16 == 0) {
267
+ currentLevel = level;
268
+ } else if (level != currentLevel) {
269
+ callback(pos16, start16 - utf16, currentLevel);
270
+ currentLevel = level;
271
+ }
272
+ if (start16 == end16) {
273
+ break;
274
+ }
275
+ SkUnichar u = SkUTF::NextUTF16(&start16, end16);
276
+ pos16 += SkUTF::ToUTF16(u);
277
+ }
278
+ }
279
+
280
+ template <typename Callback>
281
+ void forEachBreak(const char16_t utf16[], int utf16Units, SkUnicode::BreakType type, Callback&& callback) {
282
+ auto iter = makeBreakIterator(type);
283
+ iter->setText(utf16, utf16Units);
284
+ auto pos = iter->first();
285
+ do {
286
+ callback(pos, iter->status());
287
+ pos = iter->next();
288
+ } while (!iter->isDone());
289
+ }
290
+
291
+ virtual void reorderVisual(const BidiLevel runLevels[], int levelsCount, int32_t logicalFromVisual[]) = 0;
292
+
293
+ virtual std::unique_ptr<SkUnicode> copy() = 0;
294
+
295
+ static std::unique_ptr<SkUnicode> Make();
296
+
297
+ static std::unique_ptr<SkUnicode> MakeIcuBasedUnicode();
298
+
299
+ static std::unique_ptr<SkUnicode> MakeClientBasedUnicode(
300
+ SkSpan<char> text,
301
+ std::vector<SkUnicode::Position> words,
302
+ std::vector<SkUnicode::Position> graphemeBreaks,
303
+ std::vector<SkUnicode::LineBreakBefore> lineBreaks);
304
+
305
+ static std::unique_ptr<SkUnicode> MakeLibgraphemeBasedUnicode();
306
+ };
307
+
308
+ namespace sknonstd {
309
+ template <> struct is_bitmask_enum<SkUnicode::CodeUnitFlags> : std::true_type {};
310
+ } // namespace sknonstd
311
+
312
+ #endif // SkUnicode_DEFINED
@@ -0,0 +1,304 @@
1
+ /*
2
+ * Copyright 2012 Google Inc.
3
+ *
4
+ * Use of this source code is governed by a BSD-style license that can be
5
+ * found in the LICENSE file.
6
+ */
7
+
8
+ #ifndef SkTInternalLList_DEFINED
9
+ #define SkTInternalLList_DEFINED
10
+
11
+ #include "include/private/base/SkAssert.h"
12
+ #include "include/private/base/SkDebug.h"
13
+ #include "include/private/base/SkTo.h"
14
+
15
+ /**
16
+ * This macro creates the member variables required by the SkTInternalLList class. It should be
17
+ * placed in the private section of any class that will be stored in a double linked list.
18
+ */
19
+ #define SK_DECLARE_INTERNAL_LLIST_INTERFACE(ClassName) \
20
+ friend class SkTInternalLList<ClassName>; \
21
+ /* back pointer to the owning list - for debugging */ \
22
+ SkDEBUGCODE(SkTInternalLList<ClassName>* fList = nullptr;) \
23
+ ClassName* fPrev = nullptr; \
24
+ ClassName* fNext = nullptr
25
+
26
+ /**
27
+ * This class implements a templated internal doubly linked list data structure.
28
+ */
29
+ template <class T> class SkTInternalLList {
30
+ public:
31
+ SkTInternalLList() {}
32
+
33
+ void reset() {
34
+ fHead = nullptr;
35
+ fTail = nullptr;
36
+ }
37
+
38
+ void remove(T* entry) {
39
+ SkASSERT(fHead && fTail);
40
+ SkASSERT(this->isInList(entry));
41
+
42
+ T* prev = entry->fPrev;
43
+ T* next = entry->fNext;
44
+
45
+ if (prev) {
46
+ prev->fNext = next;
47
+ } else {
48
+ fHead = next;
49
+ }
50
+ if (next) {
51
+ next->fPrev = prev;
52
+ } else {
53
+ fTail = prev;
54
+ }
55
+
56
+ entry->fPrev = nullptr;
57
+ entry->fNext = nullptr;
58
+
59
+ #ifdef SK_DEBUG
60
+ entry->fList = nullptr;
61
+ #endif
62
+ }
63
+
64
+ void addToHead(T* entry) {
65
+ SkASSERT(nullptr == entry->fPrev && nullptr == entry->fNext);
66
+ SkASSERT(nullptr == entry->fList);
67
+
68
+ entry->fPrev = nullptr;
69
+ entry->fNext = fHead;
70
+ if (fHead) {
71
+ fHead->fPrev = entry;
72
+ }
73
+ fHead = entry;
74
+ if (nullptr == fTail) {
75
+ fTail = entry;
76
+ }
77
+
78
+ #ifdef SK_DEBUG
79
+ entry->fList = this;
80
+ #endif
81
+ }
82
+
83
+ void addToTail(T* entry) {
84
+ SkASSERT(nullptr == entry->fPrev && nullptr == entry->fNext);
85
+ SkASSERT(nullptr == entry->fList);
86
+
87
+ entry->fPrev = fTail;
88
+ entry->fNext = nullptr;
89
+ if (fTail) {
90
+ fTail->fNext = entry;
91
+ }
92
+ fTail = entry;
93
+ if (nullptr == fHead) {
94
+ fHead = entry;
95
+ }
96
+
97
+ #ifdef SK_DEBUG
98
+ entry->fList = this;
99
+ #endif
100
+ }
101
+
102
+ /**
103
+ * Inserts a new list entry before an existing list entry. The new entry must not already be
104
+ * a member of this or any other list. If existingEntry is NULL then the new entry is added
105
+ * at the tail.
106
+ */
107
+ void addBefore(T* newEntry, T* existingEntry) {
108
+ SkASSERT(newEntry);
109
+
110
+ if (nullptr == existingEntry) {
111
+ this->addToTail(newEntry);
112
+ return;
113
+ }
114
+
115
+ SkASSERT(this->isInList(existingEntry));
116
+ newEntry->fNext = existingEntry;
117
+ T* prev = existingEntry->fPrev;
118
+ existingEntry->fPrev = newEntry;
119
+ newEntry->fPrev = prev;
120
+ if (nullptr == prev) {
121
+ SkASSERT(fHead == existingEntry);
122
+ fHead = newEntry;
123
+ } else {
124
+ prev->fNext = newEntry;
125
+ }
126
+ #ifdef SK_DEBUG
127
+ newEntry->fList = this;
128
+ #endif
129
+ }
130
+
131
+ /**
132
+ * Inserts a new list entry after an existing list entry. The new entry must not already be
133
+ * a member of this or any other list. If existingEntry is NULL then the new entry is added
134
+ * at the head.
135
+ */
136
+ void addAfter(T* newEntry, T* existingEntry) {
137
+ SkASSERT(newEntry);
138
+
139
+ if (nullptr == existingEntry) {
140
+ this->addToHead(newEntry);
141
+ return;
142
+ }
143
+
144
+ SkASSERT(this->isInList(existingEntry));
145
+ newEntry->fPrev = existingEntry;
146
+ T* next = existingEntry->fNext;
147
+ existingEntry->fNext = newEntry;
148
+ newEntry->fNext = next;
149
+ if (nullptr == next) {
150
+ SkASSERT(fTail == existingEntry);
151
+ fTail = newEntry;
152
+ } else {
153
+ next->fPrev = newEntry;
154
+ }
155
+ #ifdef SK_DEBUG
156
+ newEntry->fList = this;
157
+ #endif
158
+ }
159
+
160
+ void concat(SkTInternalLList&& list) {
161
+ if (list.isEmpty()) {
162
+ return;
163
+ }
164
+
165
+ list.fHead->fPrev = fTail;
166
+ if (!fHead) {
167
+ SkASSERT(!list.fHead->fPrev);
168
+ fHead = list.fHead;
169
+ } else {
170
+ SkASSERT(fTail);
171
+ fTail->fNext = list.fHead;
172
+ }
173
+ fTail = list.fTail;
174
+
175
+ #ifdef SK_DEBUG
176
+ for (T* node = list.fHead; node; node = node->fNext) {
177
+ SkASSERT(node->fList == &list);
178
+ node->fList = this;
179
+ }
180
+ #endif
181
+
182
+ list.fHead = list.fTail = nullptr;
183
+ }
184
+
185
+ bool isEmpty() const {
186
+ SkASSERT(SkToBool(fHead) == SkToBool(fTail));
187
+ return !fHead;
188
+ }
189
+
190
+ T* head() const { return fHead; }
191
+ T* tail() const { return fTail; }
192
+
193
+ class Iter {
194
+ public:
195
+ enum IterStart {
196
+ kHead_IterStart,
197
+ kTail_IterStart
198
+ };
199
+
200
+ Iter() : fCurr(nullptr) {}
201
+ Iter(const Iter& iter) : fCurr(iter.fCurr) {}
202
+ Iter& operator= (const Iter& iter) { fCurr = iter.fCurr; return *this; }
203
+
204
+ T* init(const SkTInternalLList& list, IterStart startLoc) {
205
+ if (kHead_IterStart == startLoc) {
206
+ fCurr = list.fHead;
207
+ } else {
208
+ SkASSERT(kTail_IterStart == startLoc);
209
+ fCurr = list.fTail;
210
+ }
211
+
212
+ return fCurr;
213
+ }
214
+
215
+ T* get() { return fCurr; }
216
+
217
+ /**
218
+ * Return the next/previous element in the list or NULL if at the end.
219
+ */
220
+ T* next() {
221
+ if (nullptr == fCurr) {
222
+ return nullptr;
223
+ }
224
+
225
+ fCurr = fCurr->fNext;
226
+ return fCurr;
227
+ }
228
+
229
+ T* prev() {
230
+ if (nullptr == fCurr) {
231
+ return nullptr;
232
+ }
233
+
234
+ fCurr = fCurr->fPrev;
235
+ return fCurr;
236
+ }
237
+
238
+ /**
239
+ * C++11 range-for interface.
240
+ */
241
+ bool operator!=(const Iter& that) { return fCurr != that.fCurr; }
242
+ T* operator*() { return this->get(); }
243
+ void operator++() { this->next(); }
244
+
245
+ private:
246
+ T* fCurr;
247
+ };
248
+
249
+ Iter begin() const {
250
+ Iter iter;
251
+ iter.init(*this, Iter::kHead_IterStart);
252
+ return iter;
253
+ }
254
+
255
+ Iter end() const { return Iter(); }
256
+
257
+ #ifdef SK_DEBUG
258
+ void validate() const {
259
+ SkASSERT(!fHead == !fTail);
260
+ Iter iter;
261
+ for (T* item = iter.init(*this, Iter::kHead_IterStart); item; item = iter.next()) {
262
+ SkASSERT(this->isInList(item));
263
+ if (nullptr == item->fPrev) {
264
+ SkASSERT(fHead == item);
265
+ } else {
266
+ SkASSERT(item->fPrev->fNext == item);
267
+ }
268
+ if (nullptr == item->fNext) {
269
+ SkASSERT(fTail == item);
270
+ } else {
271
+ SkASSERT(item->fNext->fPrev == item);
272
+ }
273
+ }
274
+ }
275
+
276
+ /**
277
+ * Debugging-only method that uses the list back pointer to check if 'entry' is indeed in 'this'
278
+ * list.
279
+ */
280
+ bool isInList(const T* entry) const {
281
+ return entry->fList == this;
282
+ }
283
+
284
+ /**
285
+ * Debugging-only method that laboriously counts the list entries.
286
+ */
287
+ int countEntries() const {
288
+ int count = 0;
289
+ for (T* entry = fHead; entry; entry = entry->fNext) {
290
+ ++count;
291
+ }
292
+ return count;
293
+ }
294
+ #endif // SK_DEBUG
295
+
296
+ private:
297
+ T* fHead = nullptr;
298
+ T* fTail = nullptr;
299
+
300
+ SkTInternalLList(const SkTInternalLList&) = delete;
301
+ SkTInternalLList& operator=(const SkTInternalLList&) = delete;
302
+ };
303
+
304
+ #endif