@shopify/react-native-skia 0.1.201 → 0.1.203
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.
- package/android/CMakeLists.txt +9 -9
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +11 -0
- package/cpp/api/JsiSkApi.h +8 -0
- package/cpp/api/JsiSkFontMgr.h +54 -0
- package/cpp/api/JsiSkFontMgrFactory.h +40 -0
- package/cpp/api/JsiSkFontStyle.h +61 -0
- package/cpp/api/JsiSkTypeFaceFontProvider.h +80 -0
- package/cpp/api/JsiSkTypeFaceFontProviderFactory.h +32 -0
- package/cpp/rnskia/RNSkPlatformContext.h +6 -0
- package/cpp/rnskia/RNSkView.h +5 -2
- package/cpp/skia/include/core/SkColorTable.h +1 -1
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +5 -14
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +7 -56
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +1 -0
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +9 -2
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +31 -0
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +105 -0
- package/lib/commonjs/skia/core/Data.d.ts +2 -0
- package/lib/commonjs/skia/core/Data.js +29 -1
- package/lib/commonjs/skia/core/Data.js.map +1 -1
- package/lib/commonjs/skia/core/Font.d.ts +14 -1
- package/lib/commonjs/skia/core/Font.js +93 -1
- package/lib/commonjs/skia/core/Font.js.map +1 -1
- package/lib/commonjs/skia/types/Font/FontMgr.d.ts +8 -0
- package/lib/commonjs/skia/types/Font/FontMgr.js +6 -0
- package/lib/commonjs/skia/types/Font/FontMgr.js.map +1 -0
- package/lib/commonjs/skia/types/Font/FontMgrFactory.d.ts +4 -0
- package/lib/commonjs/skia/types/Font/FontMgrFactory.js +6 -0
- package/lib/commonjs/skia/types/Font/FontMgrFactory.js.map +1 -0
- package/lib/commonjs/skia/types/Font/index.d.ts +2 -0
- package/lib/commonjs/skia/types/Font/index.js +26 -0
- package/lib/commonjs/skia/types/Font/index.js.map +1 -1
- package/lib/commonjs/skia/types/Paragraph/TypefaceFontProvider.d.ts +10 -0
- package/lib/commonjs/skia/types/Paragraph/TypefaceFontProvider.js +6 -0
- package/lib/commonjs/skia/types/Paragraph/TypefaceFontProvider.js.map +1 -0
- package/lib/commonjs/skia/types/Paragraph/TypefaceFontProviderFactory.d.ts +4 -0
- package/lib/commonjs/skia/types/Paragraph/TypefaceFontProviderFactory.js +6 -0
- package/lib/commonjs/skia/types/Paragraph/TypefaceFontProviderFactory.js.map +1 -0
- package/lib/commonjs/skia/types/Skia.d.ts +4 -1
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/web/Host.d.ts +1 -1
- package/lib/commonjs/skia/web/Host.js +0 -2
- package/lib/commonjs/skia/web/Host.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkFontMgr.d.ts +10 -0
- package/lib/commonjs/skia/web/JsiSkFontMgr.js +34 -0
- package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.d.ts +8 -0
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js +32 -0
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.d.ts +13 -0
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.js +90 -0
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProviderFactory.d.ts +7 -0
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProviderFactory.js +25 -0
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProviderFactory.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkia.js +7 -1
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/skia/core/Data.d.ts +2 -0
- package/lib/module/skia/core/Data.js +24 -1
- package/lib/module/skia/core/Data.js.map +1 -1
- package/lib/module/skia/core/Font.d.ts +14 -1
- package/lib/module/skia/core/Font.js +83 -1
- package/lib/module/skia/core/Font.js.map +1 -1
- package/lib/module/skia/types/Font/FontMgr.d.ts +8 -0
- package/lib/module/skia/types/Font/FontMgr.js +2 -0
- package/lib/module/skia/types/Font/FontMgr.js.map +1 -0
- package/lib/module/skia/types/Font/FontMgrFactory.d.ts +4 -0
- package/lib/module/skia/types/Font/FontMgrFactory.js +2 -0
- package/lib/module/skia/types/Font/FontMgrFactory.js.map +1 -0
- package/lib/module/skia/types/Font/index.d.ts +2 -0
- package/lib/module/skia/types/Font/index.js +2 -0
- package/lib/module/skia/types/Font/index.js.map +1 -1
- package/lib/module/skia/types/Paragraph/TypefaceFontProvider.d.ts +10 -0
- package/lib/module/skia/types/Paragraph/TypefaceFontProvider.js +2 -0
- package/lib/module/skia/types/Paragraph/TypefaceFontProvider.js.map +1 -0
- package/lib/module/skia/types/Paragraph/TypefaceFontProviderFactory.d.ts +4 -0
- package/lib/module/skia/types/Paragraph/TypefaceFontProviderFactory.js +2 -0
- package/lib/module/skia/types/Paragraph/TypefaceFontProviderFactory.js.map +1 -0
- package/lib/module/skia/types/Skia.d.ts +4 -1
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/web/Host.d.ts +1 -1
- package/lib/module/skia/web/Host.js +0 -2
- package/lib/module/skia/web/Host.js.map +1 -1
- package/lib/module/skia/web/JsiSkFontMgr.d.ts +10 -0
- package/lib/module/skia/web/JsiSkFontMgr.js +24 -0
- package/lib/module/skia/web/JsiSkFontMgr.js.map +1 -0
- package/lib/module/skia/web/JsiSkFontMgrFactory.d.ts +8 -0
- package/lib/module/skia/web/JsiSkFontMgrFactory.js +21 -0
- package/lib/module/skia/web/JsiSkFontMgrFactory.js.map +1 -0
- package/lib/module/skia/web/JsiSkTypefaceFontProvider.d.ts +13 -0
- package/lib/module/skia/web/JsiSkTypefaceFontProvider.js +80 -0
- package/lib/module/skia/web/JsiSkTypefaceFontProvider.js.map +1 -0
- package/lib/module/skia/web/JsiSkTypefaceFontProviderFactory.d.ts +7 -0
- package/lib/module/skia/web/JsiSkTypefaceFontProviderFactory.js +14 -0
- package/lib/module/skia/web/JsiSkTypefaceFontProviderFactory.js.map +1 -0
- package/lib/module/skia/web/JsiSkia.js +5 -1
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/typescript/src/skia/core/Data.d.ts +2 -0
- package/lib/typescript/src/skia/core/Font.d.ts +14 -1
- package/lib/typescript/src/skia/types/Font/FontMgr.d.ts +8 -0
- package/lib/typescript/src/skia/types/Font/FontMgrFactory.d.ts +4 -0
- package/lib/typescript/src/skia/types/Font/index.d.ts +2 -0
- package/lib/typescript/src/skia/types/Paragraph/TypefaceFontProvider.d.ts +10 -0
- package/lib/typescript/src/skia/types/Paragraph/TypefaceFontProviderFactory.d.ts +4 -0
- package/lib/typescript/src/skia/types/Skia.d.ts +4 -1
- package/lib/typescript/src/skia/web/Host.d.ts +1 -1
- package/lib/typescript/src/skia/web/JsiSkFontMgr.d.ts +10 -0
- package/lib/typescript/src/skia/web/JsiSkFontMgrFactory.d.ts +8 -0
- package/lib/typescript/src/skia/web/JsiSkTypefaceFontProvider.d.ts +13 -0
- package/lib/typescript/src/skia/web/JsiSkTypefaceFontProviderFactory.d.ts +7 -0
- package/libs/android/arm64-v8a/libskia.a +0 -0
- package/libs/android/arm64-v8a/libskottie.a +0 -0
- package/libs/android/arm64-v8a/libskparagraph.a +0 -0
- package/libs/android/arm64-v8a/libskshaper.a +0 -0
- package/libs/android/arm64-v8a/libskunicode.a +0 -0
- package/libs/android/armeabi-v7a/libskia.a +0 -0
- package/libs/android/armeabi-v7a/libskottie.a +0 -0
- package/libs/android/armeabi-v7a/libskparagraph.a +0 -0
- package/libs/android/armeabi-v7a/libskshaper.a +0 -0
- package/libs/android/armeabi-v7a/libskunicode.a +0 -0
- package/libs/android/x86/libskia.a +0 -0
- package/libs/android/x86/libskottie.a +0 -0
- package/libs/android/x86/libskparagraph.a +0 -0
- package/libs/android/x86/libskshaper.a +0 -0
- package/libs/android/x86/libskunicode.a +0 -0
- package/libs/android/x86_64/libskia.a +0 -0
- package/libs/android/x86_64/libskottie.a +0 -0
- package/libs/android/x86_64/libskparagraph.a +0 -0
- package/libs/android/x86_64/libskshaper.a +0 -0
- package/libs/android/x86_64/libskunicode.a +0 -0
- package/libs/ios/libskia.xcframework/Info.plist +5 -5
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
- package/libs/ios/libskparagraph.xcframework/Info.plist +42 -0
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libskunicode.xcframework/Info.plist +42 -0
- package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
- package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
- package/libs/ios/libsvg.xcframework/Info.plist +5 -5
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +3 -1
- package/react-native-skia.podspec +2 -2
- package/src/skia/core/Data.ts +31 -1
- package/src/skia/core/Font.ts +109 -2
- package/src/skia/types/Font/FontMgr.ts +10 -0
- package/src/skia/types/Font/FontMgrFactory.ts +5 -0
- package/src/skia/types/Font/index.ts +2 -0
- package/src/skia/types/Paragraph/TypefaceFontProvider.ts +11 -0
- package/src/skia/types/Paragraph/TypefaceFontProviderFactory.ts +5 -0
- package/src/skia/types/Skia.ts +4 -2
- package/src/skia/web/Host.ts +1 -1
- package/src/skia/web/JsiSkFontMgr.ts +26 -0
- package/src/skia/web/JsiSkFontMgrFactory.ts +22 -0
- package/src/skia/web/JsiSkTypefaceFontProvider.ts +89 -0
- package/src/skia/web/JsiSkTypefaceFontProviderFactory.ts +18 -0
- package/src/skia/web/JsiSkia.ts +4 -0
- package/ios/RNSkia-iOS/SkiaMetalRenderer.h +0 -5
- package/ios/RNSkia-iOS/SkiaMetalRenderer.mm +0 -55
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>AvailableLibraries</key>
|
|
6
|
+
<array>
|
|
7
|
+
<dict>
|
|
8
|
+
<key>LibraryIdentifier</key>
|
|
9
|
+
<string>ios-arm64_arm64e</string>
|
|
10
|
+
<key>LibraryPath</key>
|
|
11
|
+
<string>libskunicode.a</string>
|
|
12
|
+
<key>SupportedArchitectures</key>
|
|
13
|
+
<array>
|
|
14
|
+
<string>arm64</string>
|
|
15
|
+
<string>arm64e</string>
|
|
16
|
+
</array>
|
|
17
|
+
<key>SupportedPlatform</key>
|
|
18
|
+
<string>ios</string>
|
|
19
|
+
</dict>
|
|
20
|
+
<dict>
|
|
21
|
+
<key>LibraryIdentifier</key>
|
|
22
|
+
<string>ios-arm64_arm64e_x86_64-simulator</string>
|
|
23
|
+
<key>LibraryPath</key>
|
|
24
|
+
<string>libskunicode.a</string>
|
|
25
|
+
<key>SupportedArchitectures</key>
|
|
26
|
+
<array>
|
|
27
|
+
<string>arm64</string>
|
|
28
|
+
<string>arm64e</string>
|
|
29
|
+
<string>x86_64</string>
|
|
30
|
+
</array>
|
|
31
|
+
<key>SupportedPlatform</key>
|
|
32
|
+
<string>ios</string>
|
|
33
|
+
<key>SupportedPlatformVariant</key>
|
|
34
|
+
<string>simulator</string>
|
|
35
|
+
</dict>
|
|
36
|
+
</array>
|
|
37
|
+
<key>CFBundlePackageType</key>
|
|
38
|
+
<string>XFWK</string>
|
|
39
|
+
<key>XCFrameworkFormatVersion</key>
|
|
40
|
+
<string>1.0</string>
|
|
41
|
+
</dict>
|
|
42
|
+
</plist>
|
|
Binary file
|
|
@@ -6,32 +6,32 @@
|
|
|
6
6
|
<array>
|
|
7
7
|
<dict>
|
|
8
8
|
<key>LibraryIdentifier</key>
|
|
9
|
-
<string>ios-
|
|
9
|
+
<string>ios-arm64_arm64e_x86_64-simulator</string>
|
|
10
10
|
<key>LibraryPath</key>
|
|
11
11
|
<string>libsvg.a</string>
|
|
12
12
|
<key>SupportedArchitectures</key>
|
|
13
13
|
<array>
|
|
14
14
|
<string>arm64</string>
|
|
15
15
|
<string>arm64e</string>
|
|
16
|
+
<string>x86_64</string>
|
|
16
17
|
</array>
|
|
17
18
|
<key>SupportedPlatform</key>
|
|
18
19
|
<string>ios</string>
|
|
20
|
+
<key>SupportedPlatformVariant</key>
|
|
21
|
+
<string>simulator</string>
|
|
19
22
|
</dict>
|
|
20
23
|
<dict>
|
|
21
24
|
<key>LibraryIdentifier</key>
|
|
22
|
-
<string>ios-
|
|
25
|
+
<string>ios-arm64_arm64e</string>
|
|
23
26
|
<key>LibraryPath</key>
|
|
24
27
|
<string>libsvg.a</string>
|
|
25
28
|
<key>SupportedArchitectures</key>
|
|
26
29
|
<array>
|
|
27
30
|
<string>arm64</string>
|
|
28
31
|
<string>arm64e</string>
|
|
29
|
-
<string>x86_64</string>
|
|
30
32
|
</array>
|
|
31
33
|
<key>SupportedPlatform</key>
|
|
32
34
|
<string>ios</string>
|
|
33
|
-
<key>SupportedPlatformVariant</key>
|
|
34
|
-
<string>simulator</string>
|
|
35
35
|
</dict>
|
|
36
36
|
</array>
|
|
37
37
|
<key>CFBundlePackageType</key>
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"setup-skia-web": "./scripts/setup-canvaskit.js"
|
|
8
8
|
},
|
|
9
9
|
"title": "React Native Skia",
|
|
10
|
-
"version": "0.1.
|
|
10
|
+
"version": "0.1.203",
|
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
|
12
12
|
"main": "lib/module/index.js",
|
|
13
13
|
"files": [
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
"libs/ios/libsvg.xcframework",
|
|
34
34
|
"libs/ios/libskottie.xcframework",
|
|
35
35
|
"libs/ios/libsksg.xcframework",
|
|
36
|
+
"libs/ios/libskparagraph.xcframework",
|
|
37
|
+
"libs/ios/libskunicode.xcframework",
|
|
36
38
|
"react-native-skia.podspec",
|
|
37
39
|
"scripts/setup-canvaskit.js",
|
|
38
40
|
"dist/**"
|
|
@@ -34,8 +34,8 @@ Pod::Spec.new do |s|
|
|
|
34
34
|
'libs/ios/libskia.xcframework',
|
|
35
35
|
'libs/ios/libsvg.xcframework',
|
|
36
36
|
'libs/ios/libskshaper.xcframework',
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
'libs/ios/libskparagraph.xcframework',
|
|
38
|
+
'libs/ios/libskunicode.xcframework',
|
|
39
39
|
]
|
|
40
40
|
|
|
41
41
|
# All iOS cpp/h files
|
package/src/skia/core/Data.ts
CHANGED
|
@@ -18,7 +18,7 @@ const factoryWrapper = <T>(
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
const loadData = <T>(
|
|
21
|
+
export const loadData = <T>(
|
|
22
22
|
source: DataSourceParam,
|
|
23
23
|
factory: (data: SkData) => T | null,
|
|
24
24
|
onError?: (err: Error) => void
|
|
@@ -37,6 +37,7 @@ const loadData = <T>(
|
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
+
|
|
40
41
|
const useLoading = <T extends SkJSIInstance<string>>(
|
|
41
42
|
source: DataSourceParam,
|
|
42
43
|
loader: () => Promise<T | null>
|
|
@@ -61,6 +62,35 @@ const useLoading = <T extends SkJSIInstance<string>>(
|
|
|
61
62
|
return data;
|
|
62
63
|
};
|
|
63
64
|
|
|
65
|
+
export const useCollectionLoading = <T extends SkJSIInstance<string>>(
|
|
66
|
+
source: DataSourceParam[],
|
|
67
|
+
loader: () => Promise<(T | null)[]>
|
|
68
|
+
) => {
|
|
69
|
+
const mounted = useRef(false);
|
|
70
|
+
const [data, setData] = useState<T[] | null>(null);
|
|
71
|
+
const dataRef = useRef<T[] | null>(null);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
mounted.current = true;
|
|
75
|
+
loader().then((result) => {
|
|
76
|
+
const value = result.filter((r) => r !== null) as T[];
|
|
77
|
+
if (mounted.current) {
|
|
78
|
+
setData(value);
|
|
79
|
+
dataRef.current = value;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return () => {
|
|
84
|
+
dataRef.current?.forEach((instance) => instance?.dispose());
|
|
85
|
+
mounted.current = false;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
89
|
+
}, [source]);
|
|
90
|
+
|
|
91
|
+
return data;
|
|
92
|
+
};
|
|
93
|
+
|
|
64
94
|
export const useRawData = <T extends SkJSIInstance<string>>(
|
|
65
95
|
source: DataSourceParam,
|
|
66
96
|
factory: (data: SkData) => T | null,
|
package/src/skia/core/Font.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/*global SkiaApi*/
|
|
2
|
-
import { useMemo } from "react";
|
|
2
|
+
import { useEffect, useMemo, useState } from "react";
|
|
3
3
|
|
|
4
4
|
import { Skia } from "../Skia";
|
|
5
|
-
import
|
|
5
|
+
import { FontSlant } from "../types";
|
|
6
|
+
import type { DataModule, DataSourceParam, SkFontMgr } from "../types";
|
|
7
|
+
import { Platform } from "../../Platform";
|
|
8
|
+
import type { SkTypefaceFontProvider } from "../types/Paragraph/TypefaceFontProvider";
|
|
6
9
|
|
|
7
10
|
import { useTypeface } from "./Typeface";
|
|
8
11
|
|
|
@@ -25,3 +28,107 @@ export const useFont = (
|
|
|
25
28
|
}
|
|
26
29
|
}, [size, typeface]);
|
|
27
30
|
};
|
|
31
|
+
|
|
32
|
+
type Slant = "normal" | "italic" | "oblique";
|
|
33
|
+
type Weight =
|
|
34
|
+
| "normal"
|
|
35
|
+
| "bold"
|
|
36
|
+
| "100"
|
|
37
|
+
| "200"
|
|
38
|
+
| "300"
|
|
39
|
+
| "400"
|
|
40
|
+
| "500"
|
|
41
|
+
| "600"
|
|
42
|
+
| "700"
|
|
43
|
+
| "800"
|
|
44
|
+
| "900";
|
|
45
|
+
|
|
46
|
+
interface RNFontStyle {
|
|
47
|
+
fontFamily: string;
|
|
48
|
+
fontSize: number;
|
|
49
|
+
fontStyle: Slant;
|
|
50
|
+
fontWeight: Weight;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const defaultFontStyle: RNFontStyle = {
|
|
54
|
+
fontFamily: "System",
|
|
55
|
+
fontSize: 14,
|
|
56
|
+
fontStyle: "normal",
|
|
57
|
+
fontWeight: "normal",
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const slant = (s: Slant) => {
|
|
61
|
+
if (s === "italic") {
|
|
62
|
+
return FontSlant.Italic;
|
|
63
|
+
} else if (s === "oblique") {
|
|
64
|
+
return FontSlant.Oblique;
|
|
65
|
+
} else {
|
|
66
|
+
return FontSlant.Upright;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const weight = (fontWeight: Weight) => {
|
|
71
|
+
switch (fontWeight) {
|
|
72
|
+
case "normal":
|
|
73
|
+
return 400;
|
|
74
|
+
case "bold":
|
|
75
|
+
return 700;
|
|
76
|
+
default:
|
|
77
|
+
return parseInt(fontWeight, 10);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const matchFont = (
|
|
82
|
+
inputStyle: Partial<RNFontStyle> = {},
|
|
83
|
+
fontMgr: SkFontMgr = Skia.FontMgr.System()
|
|
84
|
+
) => {
|
|
85
|
+
const fontStyle = {
|
|
86
|
+
...defaultFontStyle,
|
|
87
|
+
...inputStyle,
|
|
88
|
+
};
|
|
89
|
+
const style = {
|
|
90
|
+
weight: weight(fontStyle.fontWeight),
|
|
91
|
+
width: 5,
|
|
92
|
+
slant: slant(fontStyle.fontStyle),
|
|
93
|
+
};
|
|
94
|
+
const typeface = fontMgr.matchFamilyStyle(fontStyle.fontFamily, style);
|
|
95
|
+
return Skia.Font(typeface, fontStyle.fontSize);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const listFontFamilies = (fontMgr: SkFontMgr = Skia.FontMgr.System()) =>
|
|
99
|
+
new Array(fontMgr.countFamilies())
|
|
100
|
+
.fill(0)
|
|
101
|
+
.map((_, i) => fontMgr.getFamilyName(i));
|
|
102
|
+
|
|
103
|
+
const loadTypefaces = (typefacesToLoad: Record<string, DataModule[]>) => {
|
|
104
|
+
const promises = Object.keys(typefacesToLoad).flatMap((familyName) => {
|
|
105
|
+
return typefacesToLoad[familyName].map((typefaceToLoad) => {
|
|
106
|
+
return Skia.Data.fromURI(Platform.resolveAsset(typefaceToLoad)).then(
|
|
107
|
+
(data) => {
|
|
108
|
+
const tf = Skia.Typeface.MakeFreeTypeFaceFromData(data);
|
|
109
|
+
if (tf === null) {
|
|
110
|
+
throw new Error(`Couldn't create typeface for ${familyName}`);
|
|
111
|
+
}
|
|
112
|
+
return [familyName, tf] as const;
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
return Promise.all(promises);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const useFonts = (sources: Record<string, DataModule[]>) => {
|
|
121
|
+
const [fontMgr, setFontMgr] = useState<null | SkTypefaceFontProvider>(null);
|
|
122
|
+
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
loadTypefaces(sources).then((result) => {
|
|
125
|
+
const fMgr = Skia.TypefaceFontProvider.Make();
|
|
126
|
+
result.forEach(([familyName, typeface]) => {
|
|
127
|
+
fMgr.registerFont(typeface, familyName);
|
|
128
|
+
});
|
|
129
|
+
setFontMgr(fMgr);
|
|
130
|
+
});
|
|
131
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
132
|
+
}, []);
|
|
133
|
+
return fontMgr;
|
|
134
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SkJSIInstance } from "../JsiInstance";
|
|
2
|
+
import type { SkTypeface } from "../Typeface";
|
|
3
|
+
|
|
4
|
+
import type { FontStyle } from "./Font";
|
|
5
|
+
|
|
6
|
+
export interface SkFontMgr extends SkJSIInstance<"FontMgr"> {
|
|
7
|
+
countFamilies(): number;
|
|
8
|
+
getFamilyName(index: number): string;
|
|
9
|
+
matchFamilyStyle(name: string, style: FontStyle): SkTypeface;
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SkFontMgr } from "../Font";
|
|
2
|
+
import type { SkTypeface } from "../Typeface";
|
|
3
|
+
|
|
4
|
+
export interface SkTypefaceFontProvider extends SkFontMgr {
|
|
5
|
+
/**
|
|
6
|
+
* Registers a given typeface with the given family name.
|
|
7
|
+
* @param typeface - Typeface.
|
|
8
|
+
* @param family
|
|
9
|
+
*/
|
|
10
|
+
registerFont(typeface: SkTypeface, familyName: string): void;
|
|
11
|
+
}
|
package/src/skia/types/Skia.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ImageFilterFactory } from "./ImageFilter";
|
|
2
2
|
import type { PathFactory } from "./Path";
|
|
3
3
|
import type { ColorFilterFactory } from "./ColorFilter";
|
|
4
|
-
import type { SkFont } from "./Font";
|
|
4
|
+
import type { SkFont, FontMgrFactory } from "./Font";
|
|
5
5
|
import type { SkTypeface, TypefaceFactory } from "./Typeface";
|
|
6
6
|
import type { ImageFactory } from "./Image";
|
|
7
7
|
import type { MaskFilterFactory } from "./MaskFilter";
|
|
@@ -27,7 +27,7 @@ import type { SkPath } from "./Path/Path";
|
|
|
27
27
|
import type { SkContourMeasureIter } from "./ContourMeasure";
|
|
28
28
|
import type { PictureFactory, SkPictureRecorder } from "./Picture";
|
|
29
29
|
import type { Color, SkColor } from "./Color";
|
|
30
|
-
|
|
30
|
+
import type { TypefaceFontProviderFactory } from "./Paragraph/TypefaceFontProviderFactory";
|
|
31
31
|
/**
|
|
32
32
|
* Declares the interface for the native Skia API
|
|
33
33
|
*/
|
|
@@ -51,6 +51,8 @@ export interface Skia {
|
|
|
51
51
|
ColorFilter: ColorFilterFactory;
|
|
52
52
|
Font: (typeface?: SkTypeface, size?: number) => SkFont;
|
|
53
53
|
Typeface: TypefaceFactory;
|
|
54
|
+
TypefaceFontProvider: TypefaceFontProviderFactory;
|
|
55
|
+
FontMgr: FontMgrFactory;
|
|
54
56
|
MaskFilter: MaskFilterFactory;
|
|
55
57
|
RuntimeEffect: RuntimeEffectFactory;
|
|
56
58
|
ImageFilter: ImageFilterFactory;
|
package/src/skia/web/Host.ts
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CanvasKit, FontMgr } from "canvaskit-wasm";
|
|
2
|
+
|
|
3
|
+
import type { FontStyle, SkFontMgr, SkTypeface } from "../types";
|
|
4
|
+
|
|
5
|
+
import { HostObject, NotImplementedOnRNWeb } from "./Host";
|
|
6
|
+
|
|
7
|
+
export class JsiSkFontMgr
|
|
8
|
+
extends HostObject<FontMgr, "FontMgr">
|
|
9
|
+
implements SkFontMgr
|
|
10
|
+
{
|
|
11
|
+
constructor(CanvasKit: CanvasKit, ref: FontMgr) {
|
|
12
|
+
super(CanvasKit, ref, "FontMgr");
|
|
13
|
+
}
|
|
14
|
+
dispose() {
|
|
15
|
+
this.ref.delete();
|
|
16
|
+
}
|
|
17
|
+
countFamilies() {
|
|
18
|
+
return this.ref.countFamilies();
|
|
19
|
+
}
|
|
20
|
+
getFamilyName(index: number) {
|
|
21
|
+
return this.ref.getFamilyName(index);
|
|
22
|
+
}
|
|
23
|
+
matchFamilyStyle(_familyName: string, _fontStyle: FontStyle): SkTypeface {
|
|
24
|
+
throw new NotImplementedOnRNWeb();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CanvasKit } from "canvaskit-wasm";
|
|
2
|
+
|
|
3
|
+
import type { FontMgrFactory } from "../types";
|
|
4
|
+
|
|
5
|
+
import { Host } from "./Host";
|
|
6
|
+
import { JsiSkFontMgr } from "./JsiSkFontMgr";
|
|
7
|
+
|
|
8
|
+
export class JsiSkFontMgrFactory extends Host implements FontMgrFactory {
|
|
9
|
+
constructor(CanvasKit: CanvasKit) {
|
|
10
|
+
super(CanvasKit);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
System() {
|
|
14
|
+
const fontMgr = this.CanvasKit.TypefaceFontProvider.Make();
|
|
15
|
+
if (!fontMgr) {
|
|
16
|
+
throw new Error("Couldn't create system font manager");
|
|
17
|
+
}
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
19
|
+
// @ts-expect-error
|
|
20
|
+
return new JsiSkFontMgr(this.CanvasKit, fontMgr);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { CanvasKit, TypefaceFontProvider } from "canvaskit-wasm";
|
|
2
|
+
|
|
3
|
+
import type { SkTypefaceFontProvider } from "../types/Paragraph/TypefaceFontProvider";
|
|
4
|
+
import type { FontStyle, SkTypeface } from "../types";
|
|
5
|
+
|
|
6
|
+
import { HostObject, NotImplementedOnRNWeb } from "./Host";
|
|
7
|
+
|
|
8
|
+
export class JsiSkTypefaceFontProvider
|
|
9
|
+
extends HostObject<TypefaceFontProvider, "FontMgr">
|
|
10
|
+
implements SkTypefaceFontProvider
|
|
11
|
+
{
|
|
12
|
+
private allocatedPointers: number[] = [];
|
|
13
|
+
|
|
14
|
+
constructor(CanvasKit: CanvasKit, ref: TypefaceFontProvider) {
|
|
15
|
+
super(CanvasKit, ref, "FontMgr");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
matchFamilyStyle(_name: string, _style: FontStyle): SkTypeface {
|
|
19
|
+
throw new NotImplementedOnRNWeb();
|
|
20
|
+
}
|
|
21
|
+
countFamilies() {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
23
|
+
// @ts-expect-error
|
|
24
|
+
return this.ref.countFamilies();
|
|
25
|
+
}
|
|
26
|
+
getFamilyName(index: number) {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
return this.ref.getFamilyName(index);
|
|
30
|
+
}
|
|
31
|
+
registerFont(typeface: SkTypeface, familyName: string) {
|
|
32
|
+
const strLen = lengthBytesUTF8(familyName) + 1;
|
|
33
|
+
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
35
|
+
// @ts-expect-error
|
|
36
|
+
const strPtr = this.CanvasKit._malloc(strLen);
|
|
37
|
+
stringToUTF8(this.CanvasKit, familyName, strPtr, strLen);
|
|
38
|
+
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
40
|
+
// @ts-expect-error
|
|
41
|
+
this.ref._registerFont(typeface.ref, strPtr);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
dispose() {
|
|
45
|
+
for (const ptr of this.allocatedPointers) {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
47
|
+
// @ts-expect-error
|
|
48
|
+
this.CanvasKit._free(ptr);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.ref.delete();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const lengthBytesUTF8 = (str: string) => {
|
|
56
|
+
// TextEncoder will give us the byte length in UTF8 form
|
|
57
|
+
const encoder = new TextEncoder();
|
|
58
|
+
const utf8 = encoder.encode(str);
|
|
59
|
+
return utf8.length;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const stringToUTF8 = (
|
|
63
|
+
CanvasKit: CanvasKit,
|
|
64
|
+
str: string,
|
|
65
|
+
outPtr: number,
|
|
66
|
+
maxBytesToWrite: number
|
|
67
|
+
) => {
|
|
68
|
+
// TextEncoder will give us the byte array in UTF8 form
|
|
69
|
+
const encoder = new TextEncoder();
|
|
70
|
+
const utf8 = encoder.encode(str);
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
72
|
+
// @ts-expect-error
|
|
73
|
+
const heap: Int8Array = CanvasKit.HEAPU8;
|
|
74
|
+
|
|
75
|
+
// Check if there's enough space
|
|
76
|
+
if (utf8.length > maxBytesToWrite) {
|
|
77
|
+
throw new Error("Not enough space to write UTF8 encoded string");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Copy the bytes
|
|
81
|
+
for (let i = 0; i < utf8.length; i++) {
|
|
82
|
+
heap[outPtr + i] = utf8[i];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Null terminate
|
|
86
|
+
if (utf8.length < maxBytesToWrite) {
|
|
87
|
+
heap[outPtr + utf8.length] = 0;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CanvasKit } from "canvaskit-wasm";
|
|
2
|
+
|
|
3
|
+
import { Host } from "./Host";
|
|
4
|
+
import { JsiSkTypefaceFontProvider } from "./JsiSkTypefaceFontProvider";
|
|
5
|
+
|
|
6
|
+
export class JsiSkTypefaceFontProviderFactory
|
|
7
|
+
extends Host
|
|
8
|
+
implements JsiSkTypefaceFontProviderFactory
|
|
9
|
+
{
|
|
10
|
+
constructor(CanvasKit: CanvasKit) {
|
|
11
|
+
super(CanvasKit);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
Make() {
|
|
15
|
+
const tf = this.CanvasKit.TypefaceFontProvider.Make();
|
|
16
|
+
return new JsiSkTypefaceFontProvider(this.CanvasKit, tf);
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/skia/web/JsiSkia.ts
CHANGED
|
@@ -37,6 +37,8 @@ import { JsiSkFont } from "./JsiSkFont";
|
|
|
37
37
|
import { MakeVertices } from "./JsiSkVerticesFactory";
|
|
38
38
|
import { JsiSkPath } from "./JsiSkPath";
|
|
39
39
|
import { JsiSkTypeface } from "./JsiSkTypeface";
|
|
40
|
+
import { JsiSkTypefaceFontProviderFactory } from "./JsiSkTypefaceFontProviderFactory";
|
|
41
|
+
import { JsiSkFontMgrFactory } from "./JsiSkFontMgrFactory";
|
|
40
42
|
|
|
41
43
|
export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
42
44
|
Point: (x: number, y: number) =>
|
|
@@ -102,4 +104,6 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
|
102
104
|
return new JsiSkRect(CanvasKit, CanvasKit.XYWHRect(x, y, width, height));
|
|
103
105
|
},
|
|
104
106
|
Surface: new JsiSkSurfaceFactory(CanvasKit),
|
|
107
|
+
TypefaceFontProvider: new JsiSkTypefaceFontProviderFactory(CanvasKit),
|
|
108
|
+
FontMgr: new JsiSkFontMgrFactory(CanvasKit),
|
|
105
109
|
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#pragma clang diagnostic push
|
|
2
|
-
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
3
|
-
|
|
4
|
-
#import "SkCanvas.h"
|
|
5
|
-
#import "SkColorSpace.h"
|
|
6
|
-
#import "SkSurface.h"
|
|
7
|
-
|
|
8
|
-
#import <include/gpu/GrBackendSurface.h>
|
|
9
|
-
#import <include/gpu/GrDirectContext.h>
|
|
10
|
-
#import <include/gpu/ganesh/SkSurfaceGanesh.h>
|
|
11
|
-
|
|
12
|
-
#pragma clang diagnostic pop
|
|
13
|
-
|
|
14
|
-
#import <MetalKit/MetalKit.h>
|
|
15
|
-
|
|
16
|
-
struct OffscreenRenderContext {
|
|
17
|
-
id<MTLDevice> device;
|
|
18
|
-
id<MTLCommandQueue> commandQueue;
|
|
19
|
-
sk_sp<GrDirectContext> skiaContext;
|
|
20
|
-
id<MTLTexture> texture;
|
|
21
|
-
|
|
22
|
-
OffscreenRenderContext(int width, int height) {
|
|
23
|
-
device = MTLCreateSystemDefaultDevice();
|
|
24
|
-
commandQueue =
|
|
25
|
-
id<MTLCommandQueue>(CFRetain((GrMTLHandle)[device newCommandQueue]));
|
|
26
|
-
skiaContext = GrDirectContext::MakeMetal((__bridge void *)device,
|
|
27
|
-
(__bridge void *)commandQueue);
|
|
28
|
-
// Create a Metal texture descriptor
|
|
29
|
-
MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor
|
|
30
|
-
texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
|
|
31
|
-
width:width
|
|
32
|
-
height:height
|
|
33
|
-
mipmapped:NO];
|
|
34
|
-
textureDescriptor.usage =
|
|
35
|
-
MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead;
|
|
36
|
-
texture = [device newTextureWithDescriptor:textureDescriptor];
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
sk_sp<SkSurface> MakeOffscreenMetalSurface(int width, int height) {
|
|
41
|
-
auto ctx = new OffscreenRenderContext(width, height);
|
|
42
|
-
|
|
43
|
-
// Create a GrBackendTexture from the Metal texture
|
|
44
|
-
GrMtlTextureInfo info;
|
|
45
|
-
info.fTexture.retain((__bridge void *)ctx->texture);
|
|
46
|
-
GrBackendTexture backendTexture(width, height, GrMipMapped::kNo, info);
|
|
47
|
-
|
|
48
|
-
// Create a SkSurface from the GrBackendTexture
|
|
49
|
-
auto surface = SkSurfaces::WrapBackendTexture(
|
|
50
|
-
ctx->skiaContext.get(), backendTexture, kTopLeft_GrSurfaceOrigin, 0,
|
|
51
|
-
kBGRA_8888_SkColorType, nullptr, nullptr,
|
|
52
|
-
[](void *addr) { delete (OffscreenRenderContext *)addr; }, ctx);
|
|
53
|
-
|
|
54
|
-
return surface;
|
|
55
|
-
}
|