@shopify/react-native-skia 0.1.202 → 0.1.203

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. package/android/CMakeLists.txt +9 -9
  2. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +11 -0
  3. package/cpp/api/JsiSkApi.h +8 -0
  4. package/cpp/api/JsiSkFontMgr.h +54 -0
  5. package/cpp/api/JsiSkFontMgrFactory.h +40 -0
  6. package/cpp/api/JsiSkFontStyle.h +61 -0
  7. package/cpp/api/JsiSkTypeFaceFontProvider.h +80 -0
  8. package/cpp/api/JsiSkTypeFaceFontProviderFactory.h +32 -0
  9. package/cpp/rnskia/RNSkPlatformContext.h +6 -0
  10. package/cpp/skia/include/core/SkColorTable.h +1 -1
  11. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +1 -0
  12. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +7 -0
  13. package/lib/commonjs/skia/core/Data.d.ts +2 -0
  14. package/lib/commonjs/skia/core/Data.js +29 -1
  15. package/lib/commonjs/skia/core/Data.js.map +1 -1
  16. package/lib/commonjs/skia/core/Font.d.ts +14 -1
  17. package/lib/commonjs/skia/core/Font.js +93 -1
  18. package/lib/commonjs/skia/core/Font.js.map +1 -1
  19. package/lib/commonjs/skia/types/Font/FontMgr.d.ts +8 -0
  20. package/lib/commonjs/skia/types/Font/FontMgr.js +6 -0
  21. package/lib/commonjs/skia/types/Font/FontMgr.js.map +1 -0
  22. package/lib/commonjs/skia/types/Font/FontMgrFactory.d.ts +4 -0
  23. package/lib/commonjs/skia/types/Font/FontMgrFactory.js +6 -0
  24. package/lib/commonjs/skia/types/Font/FontMgrFactory.js.map +1 -0
  25. package/lib/commonjs/skia/types/Font/index.d.ts +2 -0
  26. package/lib/commonjs/skia/types/Font/index.js +26 -0
  27. package/lib/commonjs/skia/types/Font/index.js.map +1 -1
  28. package/lib/commonjs/skia/types/Paragraph/TypefaceFontProvider.d.ts +10 -0
  29. package/lib/commonjs/skia/types/Paragraph/TypefaceFontProvider.js +6 -0
  30. package/lib/commonjs/skia/types/Paragraph/TypefaceFontProvider.js.map +1 -0
  31. package/lib/commonjs/skia/types/Paragraph/TypefaceFontProviderFactory.d.ts +4 -0
  32. package/lib/commonjs/skia/types/Paragraph/TypefaceFontProviderFactory.js +6 -0
  33. package/lib/commonjs/skia/types/Paragraph/TypefaceFontProviderFactory.js.map +1 -0
  34. package/lib/commonjs/skia/types/Skia.d.ts +4 -1
  35. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  36. package/lib/commonjs/skia/web/Host.d.ts +1 -1
  37. package/lib/commonjs/skia/web/Host.js +0 -2
  38. package/lib/commonjs/skia/web/Host.js.map +1 -1
  39. package/lib/commonjs/skia/web/JsiSkFontMgr.d.ts +10 -0
  40. package/lib/commonjs/skia/web/JsiSkFontMgr.js +34 -0
  41. package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +1 -0
  42. package/lib/commonjs/skia/web/JsiSkFontMgrFactory.d.ts +8 -0
  43. package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js +32 -0
  44. package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js.map +1 -0
  45. package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.d.ts +13 -0
  46. package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.js +90 -0
  47. package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.js.map +1 -0
  48. package/lib/commonjs/skia/web/JsiSkTypefaceFontProviderFactory.d.ts +7 -0
  49. package/lib/commonjs/skia/web/JsiSkTypefaceFontProviderFactory.js +25 -0
  50. package/lib/commonjs/skia/web/JsiSkTypefaceFontProviderFactory.js.map +1 -0
  51. package/lib/commonjs/skia/web/JsiSkia.js +7 -1
  52. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  53. package/lib/module/skia/core/Data.d.ts +2 -0
  54. package/lib/module/skia/core/Data.js +24 -1
  55. package/lib/module/skia/core/Data.js.map +1 -1
  56. package/lib/module/skia/core/Font.d.ts +14 -1
  57. package/lib/module/skia/core/Font.js +83 -1
  58. package/lib/module/skia/core/Font.js.map +1 -1
  59. package/lib/module/skia/types/Font/FontMgr.d.ts +8 -0
  60. package/lib/module/skia/types/Font/FontMgr.js +2 -0
  61. package/lib/module/skia/types/Font/FontMgr.js.map +1 -0
  62. package/lib/module/skia/types/Font/FontMgrFactory.d.ts +4 -0
  63. package/lib/module/skia/types/Font/FontMgrFactory.js +2 -0
  64. package/lib/module/skia/types/Font/FontMgrFactory.js.map +1 -0
  65. package/lib/module/skia/types/Font/index.d.ts +2 -0
  66. package/lib/module/skia/types/Font/index.js +2 -0
  67. package/lib/module/skia/types/Font/index.js.map +1 -1
  68. package/lib/module/skia/types/Paragraph/TypefaceFontProvider.d.ts +10 -0
  69. package/lib/module/skia/types/Paragraph/TypefaceFontProvider.js +2 -0
  70. package/lib/module/skia/types/Paragraph/TypefaceFontProvider.js.map +1 -0
  71. package/lib/module/skia/types/Paragraph/TypefaceFontProviderFactory.d.ts +4 -0
  72. package/lib/module/skia/types/Paragraph/TypefaceFontProviderFactory.js +2 -0
  73. package/lib/module/skia/types/Paragraph/TypefaceFontProviderFactory.js.map +1 -0
  74. package/lib/module/skia/types/Skia.d.ts +4 -1
  75. package/lib/module/skia/types/Skia.js.map +1 -1
  76. package/lib/module/skia/web/Host.d.ts +1 -1
  77. package/lib/module/skia/web/Host.js +0 -2
  78. package/lib/module/skia/web/Host.js.map +1 -1
  79. package/lib/module/skia/web/JsiSkFontMgr.d.ts +10 -0
  80. package/lib/module/skia/web/JsiSkFontMgr.js +24 -0
  81. package/lib/module/skia/web/JsiSkFontMgr.js.map +1 -0
  82. package/lib/module/skia/web/JsiSkFontMgrFactory.d.ts +8 -0
  83. package/lib/module/skia/web/JsiSkFontMgrFactory.js +21 -0
  84. package/lib/module/skia/web/JsiSkFontMgrFactory.js.map +1 -0
  85. package/lib/module/skia/web/JsiSkTypefaceFontProvider.d.ts +13 -0
  86. package/lib/module/skia/web/JsiSkTypefaceFontProvider.js +80 -0
  87. package/lib/module/skia/web/JsiSkTypefaceFontProvider.js.map +1 -0
  88. package/lib/module/skia/web/JsiSkTypefaceFontProviderFactory.d.ts +7 -0
  89. package/lib/module/skia/web/JsiSkTypefaceFontProviderFactory.js +14 -0
  90. package/lib/module/skia/web/JsiSkTypefaceFontProviderFactory.js.map +1 -0
  91. package/lib/module/skia/web/JsiSkia.js +5 -1
  92. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  93. package/lib/typescript/src/skia/core/Data.d.ts +2 -0
  94. package/lib/typescript/src/skia/core/Font.d.ts +14 -1
  95. package/lib/typescript/src/skia/types/Font/FontMgr.d.ts +8 -0
  96. package/lib/typescript/src/skia/types/Font/FontMgrFactory.d.ts +4 -0
  97. package/lib/typescript/src/skia/types/Font/index.d.ts +2 -0
  98. package/lib/typescript/src/skia/types/Paragraph/TypefaceFontProvider.d.ts +10 -0
  99. package/lib/typescript/src/skia/types/Paragraph/TypefaceFontProviderFactory.d.ts +4 -0
  100. package/lib/typescript/src/skia/types/Skia.d.ts +4 -1
  101. package/lib/typescript/src/skia/web/Host.d.ts +1 -1
  102. package/lib/typescript/src/skia/web/JsiSkFontMgr.d.ts +10 -0
  103. package/lib/typescript/src/skia/web/JsiSkFontMgrFactory.d.ts +8 -0
  104. package/lib/typescript/src/skia/web/JsiSkTypefaceFontProvider.d.ts +13 -0
  105. package/lib/typescript/src/skia/web/JsiSkTypefaceFontProviderFactory.d.ts +7 -0
  106. package/libs/android/arm64-v8a/libskia.a +0 -0
  107. package/libs/android/arm64-v8a/libskottie.a +0 -0
  108. package/libs/android/arm64-v8a/libskparagraph.a +0 -0
  109. package/libs/android/arm64-v8a/libskshaper.a +0 -0
  110. package/libs/android/arm64-v8a/libskunicode.a +0 -0
  111. package/libs/android/armeabi-v7a/libskia.a +0 -0
  112. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  113. package/libs/android/armeabi-v7a/libskparagraph.a +0 -0
  114. package/libs/android/armeabi-v7a/libskshaper.a +0 -0
  115. package/libs/android/armeabi-v7a/libskunicode.a +0 -0
  116. package/libs/android/x86/libskia.a +0 -0
  117. package/libs/android/x86/libskottie.a +0 -0
  118. package/libs/android/x86/libskparagraph.a +0 -0
  119. package/libs/android/x86/libskshaper.a +0 -0
  120. package/libs/android/x86/libskunicode.a +0 -0
  121. package/libs/android/x86_64/libskia.a +0 -0
  122. package/libs/android/x86_64/libskottie.a +0 -0
  123. package/libs/android/x86_64/libskparagraph.a +0 -0
  124. package/libs/android/x86_64/libskshaper.a +0 -0
  125. package/libs/android/x86_64/libskunicode.a +0 -0
  126. package/libs/ios/libskia.xcframework/Info.plist +5 -5
  127. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  128. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  129. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  130. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  131. package/libs/ios/libskparagraph.xcframework/Info.plist +42 -0
  132. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  133. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  134. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  135. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  136. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  137. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  138. package/libs/ios/libskunicode.xcframework/Info.plist +42 -0
  139. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
  140. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
  141. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  142. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  143. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  144. package/package.json +3 -1
  145. package/react-native-skia.podspec +2 -2
  146. package/src/skia/core/Data.ts +31 -1
  147. package/src/skia/core/Font.ts +109 -2
  148. package/src/skia/types/Font/FontMgr.ts +10 -0
  149. package/src/skia/types/Font/FontMgrFactory.ts +5 -0
  150. package/src/skia/types/Font/index.ts +2 -0
  151. package/src/skia/types/Paragraph/TypefaceFontProvider.ts +11 -0
  152. package/src/skia/types/Paragraph/TypefaceFontProviderFactory.ts +5 -0
  153. package/src/skia/types/Skia.ts +4 -2
  154. package/src/skia/web/Host.ts +1 -1
  155. package/src/skia/web/JsiSkFontMgr.ts +26 -0
  156. package/src/skia/web/JsiSkFontMgrFactory.ts +22 -0
  157. package/src/skia/web/JsiSkTypefaceFontProvider.ts +89 -0
  158. package/src/skia/web/JsiSkTypefaceFontProviderFactory.ts +18 -0
  159. package/src/skia/web/JsiSkia.ts +4 -0
@@ -9,8 +9,8 @@ set (PACKAGE_NAME "rnskia")
9
9
  set (SKIA_LIB "skia")
10
10
  set (SKIA_SVG_LIB "svg")
11
11
  set (SKIA_SKSHAPER_LIB "skshaper")
12
- #set (SKIA_SKPARAGRAPH_LIB "skparagraph")
13
- #set (SKIA_SKUNICODE_LIB "skunicode")
12
+ set (SKIA_SKPARAGRAPH_LIB "skparagraph")
13
+ set (SKIA_SKUNICODE_LIB "skunicode")
14
14
 
15
15
  # Clear some variables
16
16
  unset(LIBRN_DIR CACHE)
@@ -84,7 +84,7 @@ target_include_directories(
84
84
  ../cpp/skia/include/utils/
85
85
  ../cpp/skia/include/pathops/
86
86
  ../cpp/skia/modules/
87
- #cpp/skia/modules/skparagraph/include/
87
+ ../cpp/skia/modules/skparagraph/include/
88
88
  ../cpp/skia/include/
89
89
  ../cpp/skia
90
90
 
@@ -113,11 +113,11 @@ set_property(TARGET svg PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libsvg.a")
113
113
  add_library(skshaper STATIC IMPORTED)
114
114
  set_property(TARGET skshaper PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskshaper.a")
115
115
 
116
- #add_library(skparagraph STATIC IMPORTED)
117
- #set_property(TARGET skparagraph PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskparagraph.a")
116
+ add_library(skparagraph STATIC IMPORTED)
117
+ set_property(TARGET skparagraph PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskparagraph.a")
118
118
 
119
- #add_library(skunicode STATIC IMPORTED)
120
- #set_property(TARGET skunicode PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskunicode.a")
119
+ add_library(skunicode STATIC IMPORTED)
120
+ set_property(TARGET skunicode PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskunicode.a")
121
121
 
122
122
 
123
123
  find_library(
@@ -202,8 +202,8 @@ target_link_libraries(
202
202
  ${TURBOMODULES_LIB}
203
203
  ${SKIA_SVG_LIB}
204
204
  ${SKIA_SKSHAPER_LIB}
205
- #${SKIA_SKPARAGRAPH_LIB}
206
- #${SKIA_SKUNICODE_LIB}
205
+ ${SKIA_SKPARAGRAPH_LIB}
206
+ ${SKIA_SKUNICODE_LIB}
207
207
  ${SKIA_LIB}
208
208
  -ljnigraphics
209
209
  -lGLESv2
@@ -9,6 +9,13 @@
9
9
  #include <RNSkPlatformContext.h>
10
10
  #include <SkiaOpenGLSurfaceFactory.h>
11
11
 
12
+ #pragma clang diagnostic push
13
+ #pragma clang diagnostic ignored "-Wdocumentation"
14
+
15
+ #include "include/ports/SkFontMgr_android.h"
16
+
17
+ #pragma clang diagnostic pop
18
+
12
19
  namespace RNSkia {
13
20
  namespace jsi = facebook::jsi;
14
21
 
@@ -41,6 +48,10 @@ public:
41
48
  return SkiaOpenGLSurfaceFactory::makeOffscreenSurface(width, height);
42
49
  }
43
50
 
51
+ sk_sp<SkFontMgr> createFontMgr() override {
52
+ return SkFontMgr_New_Android(nullptr);
53
+ }
54
+
44
55
  void runOnMainThread(std::function<void()> task) override {
45
56
  _jniPlatformContext->runTaskOnMainThread(task);
46
57
  }
@@ -12,6 +12,8 @@
12
12
  #include "JsiSkContourMeasureIter.h"
13
13
  #include "JsiSkDataFactory.h"
14
14
  #include "JsiSkFont.h"
15
+ #include "JsiSkFontMgr.h"
16
+ #include "JsiSkFontMgrFactory.h"
15
17
  #include "JsiSkImage.h"
16
18
  #include "JsiSkImageFactory.h"
17
19
  #include "JsiSkImageFilter.h"
@@ -39,6 +41,7 @@
39
41
  #include "JsiSkShaderFactory.h"
40
42
  #include "JsiSkSurfaceFactory.h"
41
43
  #include "JsiSkTextBlobFactory.h"
44
+ #include "JsiSkTypeFaceFontProviderFactory.h"
42
45
  #include "JsiSkTypeface.h"
43
46
  #include "JsiSkTypefaceFactory.h"
44
47
  #include "JsiSkVertices.h"
@@ -100,6 +103,11 @@ public:
100
103
  std::make_shared<JsiSkSurfaceFactory>(context));
101
104
  installReadonlyProperty("Picture",
102
105
  std::make_shared<JsiSkPictureFactory>(context));
106
+ installReadonlyProperty("FontMgr",
107
+ std::make_shared<JsiSkFontMgrFactory>(context));
108
+ installReadonlyProperty(
109
+ "TypefaceFontProvider",
110
+ std::make_shared<JsiSkTypefaceFontProviderFactory>(context));
103
111
  }
104
112
  };
105
113
  } // namespace RNSkia
@@ -0,0 +1,54 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <numeric>
5
+ #include <utility>
6
+ #include <vector>
7
+
8
+ #include "JsiSkFontStyle.h"
9
+ #include "JsiSkHostObjects.h"
10
+ #include "RNSkLog.h"
11
+ #include <jsi/jsi.h>
12
+
13
+ #pragma clang diagnostic push
14
+ #pragma clang diagnostic ignored "-Wdocumentation"
15
+
16
+ #include "SkFontMgr.h"
17
+
18
+ #pragma clang diagnostic pop
19
+
20
+ namespace RNSkia {
21
+
22
+ namespace jsi = facebook::jsi;
23
+
24
+ class JsiSkFontMgr : public JsiSkWrappingSkPtrHostObject<SkFontMgr> {
25
+ public:
26
+ EXPORT_JSI_API_TYPENAME(JsiSkFontMgr, "FontMgr")
27
+
28
+ JsiSkFontMgr(std::shared_ptr<RNSkPlatformContext> context,
29
+ sk_sp<SkFontMgr> fontMgr)
30
+ : JsiSkWrappingSkPtrHostObject(std::move(context), fontMgr) {}
31
+
32
+ JSI_HOST_FUNCTION(countFamilies) { return getObject()->countFamilies(); }
33
+
34
+ JSI_HOST_FUNCTION(getFamilyName) {
35
+ auto i = static_cast<int>(arguments[0].asNumber());
36
+ SkString name;
37
+ getObject()->getFamilyName(i, &name);
38
+ return jsi::String::createFromUtf8(runtime, name.c_str());
39
+ }
40
+
41
+ JSI_HOST_FUNCTION(matchFamilyStyle) {
42
+ auto name = arguments[0].asString(runtime).utf8(runtime);
43
+ auto fontStyle = JsiSkFontStyle::fromValue(runtime, arguments[1]);
44
+ auto typeface = getObject()->matchFamilyStyle(name.c_str(), *fontStyle);
45
+ return jsi::Object::createFromHostObject(
46
+ runtime, std::make_shared<JsiSkTypeface>(getContext(), typeface));
47
+ }
48
+
49
+ JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkFontMgr, countFamilies),
50
+ JSI_EXPORT_FUNC(JsiSkFontMgr, getFamilyName),
51
+ JSI_EXPORT_FUNC(JsiSkFontMgr, matchFamilyStyle))
52
+ };
53
+
54
+ } // namespace RNSkia
@@ -0,0 +1,40 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <utility>
5
+ #include <vector>
6
+
7
+ #include <jsi/jsi.h>
8
+
9
+ #include "JsiSkHostObjects.h"
10
+
11
+ #pragma clang diagnostic push
12
+ #pragma clang diagnostic ignored "-Wdocumentation"
13
+
14
+ #include "SkFontMgr.h"
15
+ #include "include/ports/SkFontMgr_data.h"
16
+
17
+ #pragma clang diagnostic pop
18
+
19
+ namespace RNSkia {
20
+
21
+ namespace jsi = facebook::jsi;
22
+
23
+ class JsiSkFontMgrFactory : public JsiSkHostObject {
24
+ public:
25
+ JSI_HOST_FUNCTION(System) {
26
+ auto context = getContext();
27
+ static SkOnce once;
28
+ static sk_sp<SkFontMgr> fontMgr;
29
+ once([&context, &runtime] { fontMgr = context->createFontMgr(); });
30
+ return jsi::Object::createFromHostObject(
31
+ runtime, std::make_shared<JsiSkFontMgr>(std::move(context), fontMgr));
32
+ }
33
+
34
+ JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkFontMgrFactory, System))
35
+
36
+ explicit JsiSkFontMgrFactory(std::shared_ptr<RNSkPlatformContext> context)
37
+ : JsiSkHostObject(std::move(context)) {}
38
+ };
39
+
40
+ } // namespace RNSkia
@@ -0,0 +1,61 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <utility>
5
+
6
+ #include <jsi/jsi.h>
7
+
8
+ #include "JsiSkHostObjects.h"
9
+
10
+ #pragma clang diagnostic push
11
+ #pragma clang diagnostic ignored "-Wdocumentation"
12
+
13
+ #include "SkFontStyle.h"
14
+
15
+ #pragma clang diagnostic pop
16
+
17
+ namespace RNSkia {
18
+
19
+ namespace jsi = facebook::jsi;
20
+
21
+ class JsiSkFontStyle : public JsiSkWrappingSharedPtrHostObject<SkFontStyle> {
22
+ public:
23
+ JSI_API_TYPENAME("FontStyle");
24
+
25
+ JsiSkFontStyle(std::shared_ptr<RNSkPlatformContext> context,
26
+ const SkFontStyle &fontStyle)
27
+ : JsiSkWrappingSharedPtrHostObject<SkFontStyle>(
28
+ std::move(context), std::make_shared<SkFontStyle>(fontStyle)) {}
29
+
30
+ /**
31
+ Returns the underlying object from a host object of this type
32
+ */
33
+ static std::shared_ptr<SkFontStyle> fromValue(jsi::Runtime &runtime,
34
+ const jsi::Value &obj) {
35
+ const auto &object = obj.asObject(runtime);
36
+ if (object.isHostObject(runtime)) {
37
+ return object.asHostObject<JsiSkFontStyle>(runtime)->getObject();
38
+ } else {
39
+ auto weight =
40
+ static_cast<int>(object.getProperty(runtime, "weight").asNumber());
41
+ auto width =
42
+ static_cast<int>(object.getProperty(runtime, "width").asNumber());
43
+ auto slant = static_cast<SkFontStyle::Slant>(
44
+ object.getProperty(runtime, "slant").asNumber());
45
+ SkFontStyle style(weight, width, slant);
46
+ return std::make_shared<SkFontStyle>(style);
47
+ }
48
+ }
49
+
50
+ /**
51
+ Returns the jsi object from a host object of this type
52
+ */
53
+ static jsi::Value toValue(jsi::Runtime &runtime,
54
+ std::shared_ptr<RNSkPlatformContext> context,
55
+ const SkFontStyle &fontStyle) {
56
+ return jsi::Object::createFromHostObject(
57
+ runtime,
58
+ std::make_shared<JsiSkFontStyle>(std::move(context), fontStyle));
59
+ }
60
+ };
61
+ } // namespace RNSkia
@@ -0,0 +1,80 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <utility>
5
+
6
+ #include <jsi/jsi.h>
7
+
8
+ #include "JsiSkFontStyle.h"
9
+ #include "JsiSkHostObjects.h"
10
+ #include "JsiSkTypeface.h"
11
+
12
+ #include "RNSkLog.h"
13
+
14
+ #pragma clang diagnostic push
15
+ #pragma clang diagnostic ignored "-Wdocumentation"
16
+
17
+ #include "SkFont.h"
18
+ #include "skparagraph/include/TypefaceFontProvider.h"
19
+
20
+ #pragma clang diagnostic pop
21
+
22
+ namespace RNSkia {
23
+
24
+ namespace jsi = facebook::jsi;
25
+ namespace para = skia::textlayout;
26
+
27
+ class JsiSkTypefaceFontProvider
28
+ : public JsiSkWrappingSkPtrHostObject<para::TypefaceFontProvider> {
29
+ public:
30
+ EXPORT_JSI_API_TYPENAME(JsiSkTypefaceFontProvider, "FontMgr")
31
+ JSI_EXPORT_FUNCTIONS(
32
+ JSI_EXPORT_FUNC(JsiSkTypefaceFontProvider, dispose),
33
+ JSI_EXPORT_FUNC(JsiSkTypefaceFontProvider, registerFont),
34
+ JSI_EXPORT_FUNC(JsiSkTypefaceFontProvider, matchFamilyStyle),
35
+ JSI_EXPORT_FUNC(JsiSkTypefaceFontProvider, countFamilies),
36
+ JSI_EXPORT_FUNC(JsiSkTypefaceFontProvider, getFamilyName))
37
+
38
+ JSI_HOST_FUNCTION(registerFont) {
39
+ sk_sp<SkTypeface> typeface =
40
+ JsiSkTypeface::fromValue(runtime, arguments[0]);
41
+ SkString familyName(arguments[1].asString(runtime).utf8(runtime).c_str());
42
+ auto result = getObject()->registerTypeface(typeface, familyName);
43
+ return jsi::Value::undefined();
44
+ }
45
+
46
+ JSI_HOST_FUNCTION(matchFamilyStyle) {
47
+ auto name = arguments[0].asString(runtime).utf8(runtime);
48
+ auto fontStyle = JsiSkFontStyle::fromValue(runtime, arguments[1]);
49
+ auto typeface = getObject()->matchFamilyStyle(name.c_str(), *fontStyle);
50
+ return jsi::Object::createFromHostObject(
51
+ runtime, std::make_shared<JsiSkTypeface>(getContext(), typeface));
52
+ }
53
+
54
+ JSI_HOST_FUNCTION(countFamilies) { return getObject()->countFamilies(); }
55
+
56
+ JSI_HOST_FUNCTION(getFamilyName) {
57
+ auto i = static_cast<int>(arguments[0].asNumber());
58
+ SkString name;
59
+ getObject()->getFamilyName(i, &name);
60
+ return jsi::String::createFromUtf8(runtime, name.c_str());
61
+ }
62
+
63
+ JsiSkTypefaceFontProvider(std::shared_ptr<RNSkPlatformContext> context,
64
+ sk_sp<para::TypefaceFontProvider> tfProvider)
65
+ : JsiSkWrappingSkPtrHostObject(std::move(context),
66
+ std::move(tfProvider)) {}
67
+
68
+ /**
69
+ Returns the jsi object from a host object of this type
70
+ */
71
+ static jsi::Value toValue(jsi::Runtime &runtime,
72
+ std::shared_ptr<RNSkPlatformContext> context,
73
+ sk_sp<para::TypefaceFontProvider> tfProvider) {
74
+ return jsi::Object::createFromHostObject(
75
+ runtime, std::make_shared<JsiSkTypefaceFontProvider>(
76
+ std::move(context), std::move(tfProvider)));
77
+ }
78
+ };
79
+
80
+ } // namespace RNSkia
@@ -0,0 +1,32 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <utility>
5
+
6
+ #include <jsi/jsi.h>
7
+
8
+ #include "JsiSkData.h"
9
+ #include "JsiSkHostObjects.h"
10
+ #include "JsiSkTypefaceFontProvider.h"
11
+
12
+ namespace RNSkia {
13
+
14
+ namespace jsi = facebook::jsi;
15
+ namespace para = skia::textlayout;
16
+
17
+ class JsiSkTypefaceFontProviderFactory : public JsiSkHostObject {
18
+ public:
19
+ JSI_HOST_FUNCTION(Make) {
20
+ return jsi::Object::createFromHostObject(
21
+ runtime, std::make_shared<JsiSkTypefaceFontProvider>(
22
+ getContext(), sk_make_sp<para::TypefaceFontProvider>()));
23
+ }
24
+
25
+ JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkTypefaceFontProviderFactory, Make))
26
+
27
+ explicit JsiSkTypefaceFontProviderFactory(
28
+ std::shared_ptr<RNSkPlatformContext> context)
29
+ : JsiSkHostObject(std::move(context)) {}
30
+ };
31
+
32
+ } // namespace RNSkia
@@ -15,6 +15,7 @@
15
15
  #pragma clang diagnostic ignored "-Wdocumentation"
16
16
 
17
17
  #include "SkData.h"
18
+ #include "SkFontMgr.h"
18
19
  #include "SkImage.h"
19
20
  #include "SkStream.h"
20
21
  #include "SkSurface.h"
@@ -132,6 +133,11 @@ public:
132
133
  */
133
134
  virtual sk_sp<SkSurface> makeOffscreenSurface(int width, int height) = 0;
134
135
 
136
+ /**
137
+ * Return the Platform specific font manager
138
+ */
139
+ virtual sk_sp<SkFontMgr> createFontMgr() = 0;
140
+
135
141
  /**
136
142
  * Creates an skImage containing the screenshot of a native view and its
137
143
  * children.
@@ -19,7 +19,7 @@ class SkWriteBuffer;
19
19
  * of `SkColorFilters::Table`, and provides a way to share the table data between client code and
20
20
  * the returned SkColorFilter. Once created, an SkColorTable is immutable.
21
21
  */
22
- class SkColorTable : public SkRefCnt {
22
+ class SK_API SkColorTable : public SkRefCnt {
23
23
  public:
24
24
  // Creates a new SkColorTable with 'table' used for all four channels. The table is copied into
25
25
  // the SkColorTable.
@@ -64,6 +64,7 @@ public:
64
64
 
65
65
  void raiseError(const std::exception &err) override;
66
66
  sk_sp<SkSurface> makeOffscreenSurface(int width, int height) override;
67
+ sk_sp<SkFontMgr> createFontMgr() override;
67
68
 
68
69
  void willInvalidateModules() {
69
70
  // We need to do some house-cleaning here!
@@ -9,8 +9,11 @@
9
9
  #pragma clang diagnostic push
10
10
  #pragma clang diagnostic ignored "-Wdocumentation"
11
11
 
12
+ #include "SkFontMgr.h"
12
13
  #include "SkSurface.h"
13
14
 
15
+ #include "include/ports/SkFontMgr_mac_ct.h"
16
+
14
17
  #pragma clang diagnostic pop
15
18
 
16
19
  namespace RNSkia {
@@ -62,6 +65,10 @@ sk_sp<SkSurface> RNSkiOSPlatformContext::makeOffscreenSurface(int width,
62
65
  return SkiaMetalSurfaceFactory::makeOffscreenSurface(width, height);
63
66
  }
64
67
 
68
+ sk_sp<SkFontMgr> RNSkiOSPlatformContext::createFontMgr() {
69
+ return SkFontMgr_New_CoreText(nullptr);
70
+ }
71
+
65
72
  void RNSkiOSPlatformContext::runOnMainThread(std::function<void()> func) {
66
73
  dispatch_async(dispatch_get_main_queue(), ^{
67
74
  func();
@@ -1,3 +1,5 @@
1
1
  import type { SkData, DataSourceParam, SkJSIInstance } from "../types";
2
+ export declare const loadData: <T>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: ((err: Error) => void) | undefined) => Promise<T | null>;
3
+ export declare const useCollectionLoading: <T extends SkJSIInstance<string>>(source: DataSourceParam[], loader: () => Promise<(T | null)[]>) => T[] | null;
2
4
  export declare const useRawData: <T extends SkJSIInstance<string>>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: ((err: Error) => void) | undefined) => T | null;
3
5
  export declare const useData: (source: DataSourceParam, onError?: ((err: Error) => void) | undefined) => SkData | null;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useRawData = exports.useData = void 0;
6
+ exports.useRawData = exports.useData = exports.useCollectionLoading = exports.loadData = void 0;
7
7
 
8
8
  var _react = require("react");
9
9
 
@@ -33,6 +33,8 @@ const loadData = (source, factory, onError) => {
33
33
  }
34
34
  };
35
35
 
36
+ exports.loadData = loadData;
37
+
36
38
  const useLoading = (source, loader) => {
37
39
  const mounted = (0, _react.useRef)(false);
38
40
  const [data, setData] = (0, _react.useState)(null);
@@ -55,6 +57,32 @@ const useLoading = (source, loader) => {
55
57
  return data;
56
58
  };
57
59
 
60
+ const useCollectionLoading = (source, loader) => {
61
+ const mounted = (0, _react.useRef)(false);
62
+ const [data, setData] = (0, _react.useState)(null);
63
+ const dataRef = (0, _react.useRef)(null);
64
+ (0, _react.useEffect)(() => {
65
+ mounted.current = true;
66
+ loader().then(result => {
67
+ const value = result.filter(r => r !== null);
68
+
69
+ if (mounted.current) {
70
+ setData(value);
71
+ dataRef.current = value;
72
+ }
73
+ });
74
+ return () => {
75
+ var _dataRef$current2;
76
+
77
+ (_dataRef$current2 = dataRef.current) === null || _dataRef$current2 === void 0 ? void 0 : _dataRef$current2.forEach(instance => instance === null || instance === void 0 ? void 0 : instance.dispose());
78
+ mounted.current = false;
79
+ }; // eslint-disable-next-line react-hooks/exhaustive-deps
80
+ }, [source]);
81
+ return data;
82
+ };
83
+
84
+ exports.useCollectionLoading = useCollectionLoading;
85
+
58
86
  const useRawData = (source, factory, onError) => useLoading(source, () => loadData(source, factory, onError));
59
87
 
60
88
  exports.useRawData = useRawData;
@@ -1 +1 @@
1
- {"version":3,"names":["factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","source","undefined","Promise","resolve","Uint8Array","Skia","Data","fromBytes","uri","Platform","resolveAsset","fromURI","then","d","useLoading","loader","mounted","useRef","data","setData","useState","dataRef","useEffect","current","value","dispose","useRawData","identity","useData"],"sources":["Data.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkData, DataSourceParam, SkJSIInstance } from \"../types\";\nimport { Platform } from \"../../Platform\";\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nconst loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri =\n typeof source === \"string\" ? source : Platform.resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\nconst useLoading = <T extends SkJSIInstance<string>>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T | null>(null);\n const dataRef = useRef<T | null>(null);\n useEffect(() => {\n mounted.current = true;\n loader().then((value) => {\n if (mounted.current) {\n setData(value);\n dataRef.current = value;\n }\n });\n return () => {\n dataRef.current?.dispose();\n mounted.current = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useRawData = <T extends SkJSIInstance<string>>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData<T>(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AAEA,MAAMA,cAAc,GAAG,CACrBC,KADqB,EAErBC,OAFqB,EAGrBC,OAHqB,KAIlB;EACH,MAAMC,aAAa,GAAGF,OAAO,CAACD,KAAD,CAA7B;;EACA,IAAIG,aAAa,KAAK,IAAtB,EAA4B;IAC1BD,OAAO,IAA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Y,KAAD,IAAW;MACvB,IAAIR,OAAO,CAACO,OAAZ,EAAqB;QACnBJ,OAAO,CAACK,KAAD,CAAP;QACAH,OAAO,CAACE,OAAR,GAAkBC,KAAlB;MACD;IACF,CALD;IAMA,OAAO,MAAM;MAAA;;MACX,oBAAAH,OAAO,CAACE,OAAR,sEAAiBE,OAAjB;MACAT,OAAO,CAACO,OAAR,GAAkB,KAAlB;IACD,CAHD,CARc,CAYd;EACD,CAbD,EAaG,CAACvB,MAAD,CAbH;EAcA,OAAOkB,IAAP;AACD,CAtBD;;AAwBO,MAAMQ,UAAU,GAAG,CACxB1B,MADwB,EAExBL,OAFwB,EAGxBC,OAHwB,KAIrBkB,UAAU,CAACd,MAAD,EAAS,MAAMD,QAAQ,CAAIC,MAAJ,EAAYL,OAAZ,EAAqBC,OAArB,CAAvB,CAJR;;;;AAMP,MAAM+B,QAAQ,GAAIT,IAAD,IAAkBA,IAAnC;;AAEO,MAAMU,OAAO,GAAG,CACrB5B,MADqB,EAErBJ,OAFqB,KAGlB8B,UAAU,CAAC1B,MAAD,EAAS2B,QAAT,EAAmB/B,OAAnB,CAHR"}
1
+ {"version":3,"names":["factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","source","undefined","Promise","resolve","Uint8Array","Skia","Data","fromBytes","uri","Platform","resolveAsset","fromURI","then","d","useLoading","loader","mounted","useRef","data","setData","useState","dataRef","useEffect","current","value","dispose","useCollectionLoading","result","filter","r","forEach","instance","useRawData","identity","useData"],"sources":["Data.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkData, DataSourceParam, SkJSIInstance } from \"../types\";\nimport { Platform } from \"../../Platform\";\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nexport const loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri =\n typeof source === \"string\" ? source : Platform.resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\n\nconst useLoading = <T extends SkJSIInstance<string>>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T | null>(null);\n const dataRef = useRef<T | null>(null);\n useEffect(() => {\n mounted.current = true;\n loader().then((value) => {\n if (mounted.current) {\n setData(value);\n dataRef.current = value;\n }\n });\n return () => {\n dataRef.current?.dispose();\n mounted.current = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useCollectionLoading = <T extends SkJSIInstance<string>>(\n source: DataSourceParam[],\n loader: () => Promise<(T | null)[]>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T[] | null>(null);\n const dataRef = useRef<T[] | null>(null);\n\n useEffect(() => {\n mounted.current = true;\n loader().then((result) => {\n const value = result.filter((r) => r !== null) as T[];\n if (mounted.current) {\n setData(value);\n dataRef.current = value;\n }\n });\n\n return () => {\n dataRef.current?.forEach((instance) => instance?.dispose());\n mounted.current = false;\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n\n return data;\n};\n\nexport const useRawData = <T extends SkJSIInstance<string>>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData<T>(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;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AAcA,QAAd,uBAAcA,QAAQ,CAAEN,OAAV,EAAvC;MACAT,OAAO,CAACO,OAAR,GAAkB,KAAlB;IACD,CAHD,CAVc,CAed;EACD,CAhBD,EAgBG,CAACvB,MAAD,CAhBH;EAkBA,OAAOkB,IAAP;AACD,CA3BM;;;;AA6BA,MAAMc,UAAU,GAAG,CACxBhC,MADwB,EAExBL,OAFwB,EAGxBC,OAHwB,KAIrBkB,UAAU,CAACd,MAAD,EAAS,MAAMD,QAAQ,CAAIC,MAAJ,EAAYL,OAAZ,EAAqBC,OAArB,CAAvB,CAJR;;;;AAMP,MAAMqC,QAAQ,GAAIf,IAAD,IAAkBA,IAAnC;;AAEO,MAAMgB,OAAO,GAAG,CACrBlC,MADqB,EAErBJ,OAFqB,KAGlBoC,UAAU,CAAChC,MAAD,EAASiC,QAAT,EAAmBrC,OAAnB,CAHR"}
@@ -1,5 +1,18 @@
1
- import type { DataSourceParam } from "../types";
1
+ import type { DataModule, DataSourceParam, SkFontMgr } from "../types";
2
+ import type { SkTypefaceFontProvider } from "../types/Paragraph/TypefaceFontProvider";
2
3
  /**
3
4
  * Returns a Skia Font object
4
5
  * */
5
6
  export declare const useFont: (font: DataSourceParam, size?: number, onError?: ((err: Error) => void) | undefined) => import("../types").SkFont | null;
7
+ declare type Slant = "normal" | "italic" | "oblique";
8
+ declare type Weight = "normal" | "bold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900";
9
+ interface RNFontStyle {
10
+ fontFamily: string;
11
+ fontSize: number;
12
+ fontStyle: Slant;
13
+ fontWeight: Weight;
14
+ }
15
+ export declare const matchFont: (inputStyle?: Partial<RNFontStyle>, fontMgr?: SkFontMgr) => import("../types").SkFont;
16
+ export declare const listFontFamilies: (fontMgr?: SkFontMgr) => string[];
17
+ export declare const useFonts: (sources: Record<string, DataModule[]>) => SkTypefaceFontProvider | null;
18
+ export {};
@@ -3,12 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useFont = void 0;
6
+ exports.useFonts = exports.useFont = exports.matchFont = exports.listFontFamilies = void 0;
7
7
 
8
8
  var _react = require("react");
9
9
 
10
10
  var _Skia = require("../Skia");
11
11
 
12
+ var _types = require("../types");
13
+
14
+ var _Platform = require("../../Platform");
15
+
12
16
  var _Typeface = require("./Typeface");
13
17
 
14
18
  /*global SkiaApi*/
@@ -30,4 +34,92 @@ const useFont = (font, size, onError) => {
30
34
  };
31
35
 
32
36
  exports.useFont = useFont;
37
+ const defaultFontStyle = {
38
+ fontFamily: "System",
39
+ fontSize: 14,
40
+ fontStyle: "normal",
41
+ fontWeight: "normal"
42
+ };
43
+
44
+ const slant = s => {
45
+ if (s === "italic") {
46
+ return _types.FontSlant.Italic;
47
+ } else if (s === "oblique") {
48
+ return _types.FontSlant.Oblique;
49
+ } else {
50
+ return _types.FontSlant.Upright;
51
+ }
52
+ };
53
+
54
+ const weight = fontWeight => {
55
+ switch (fontWeight) {
56
+ case "normal":
57
+ return 400;
58
+
59
+ case "bold":
60
+ return 700;
61
+
62
+ default:
63
+ return parseInt(fontWeight, 10);
64
+ }
65
+ };
66
+
67
+ const matchFont = function () {
68
+ let inputStyle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
69
+ let fontMgr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _Skia.Skia.FontMgr.System();
70
+ const fontStyle = { ...defaultFontStyle,
71
+ ...inputStyle
72
+ };
73
+ const style = {
74
+ weight: weight(fontStyle.fontWeight),
75
+ width: 5,
76
+ slant: slant(fontStyle.fontStyle)
77
+ };
78
+ const typeface = fontMgr.matchFamilyStyle(fontStyle.fontFamily, style);
79
+ return _Skia.Skia.Font(typeface, fontStyle.fontSize);
80
+ };
81
+
82
+ exports.matchFont = matchFont;
83
+
84
+ const listFontFamilies = function () {
85
+ let fontMgr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _Skia.Skia.FontMgr.System();
86
+ return new Array(fontMgr.countFamilies()).fill(0).map((_, i) => fontMgr.getFamilyName(i));
87
+ };
88
+
89
+ exports.listFontFamilies = listFontFamilies;
90
+
91
+ const loadTypefaces = typefacesToLoad => {
92
+ const promises = Object.keys(typefacesToLoad).flatMap(familyName => {
93
+ return typefacesToLoad[familyName].map(typefaceToLoad => {
94
+ return _Skia.Skia.Data.fromURI(_Platform.Platform.resolveAsset(typefaceToLoad)).then(data => {
95
+ const tf = _Skia.Skia.Typeface.MakeFreeTypeFaceFromData(data);
96
+
97
+ if (tf === null) {
98
+ throw new Error(`Couldn't create typeface for ${familyName}`);
99
+ }
100
+
101
+ return [familyName, tf];
102
+ });
103
+ });
104
+ });
105
+ return Promise.all(promises);
106
+ };
107
+
108
+ const useFonts = sources => {
109
+ const [fontMgr, setFontMgr] = (0, _react.useState)(null);
110
+ (0, _react.useEffect)(() => {
111
+ loadTypefaces(sources).then(result => {
112
+ const fMgr = _Skia.Skia.TypefaceFontProvider.Make();
113
+
114
+ result.forEach(_ref => {
115
+ let [familyName, typeface] = _ref;
116
+ fMgr.registerFont(typeface, familyName);
117
+ });
118
+ setFontMgr(fMgr);
119
+ }); // eslint-disable-next-line react-hooks/exhaustive-deps
120
+ }, []);
121
+ return fontMgr;
122
+ };
123
+
124
+ exports.useFonts = useFonts;
33
125
  //# sourceMappingURL=Font.js.map