vexflow-native 2.4.0 → 2.5.0
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/README.md +7 -1
- package/lib/module/base/FontManager.js +41 -27
- package/lib/module/base/FontManager.js.map +1 -1
- package/lib/module/base/VexflowCanvas.js +8 -6
- package/lib/module/base/VexflowCanvas.js.map +1 -1
- package/lib/module/base/VexflowRecordingClone.js +83 -0
- package/lib/module/base/VexflowRecordingClone.js.map +1 -0
- package/lib/module/base/VexflowRecordingContext.js +1 -80
- package/lib/module/base/VexflowRecordingContext.js.map +1 -1
- package/lib/module/base/builtInTextFont.js +21 -0
- package/lib/module/base/builtInTextFont.js.map +1 -0
- package/lib/module/base/cssFontShorthand.js +34 -0
- package/lib/module/base/cssFontShorthand.js.map +1 -0
- package/lib/module/base/fonts/OFL.txt +93 -0
- package/lib/module/base/fonts/academico.js +12 -0
- package/lib/module/base/fonts/academico.js.map +1 -0
- package/lib/module/base/pictureRetirement.js +70 -0
- package/lib/module/base/pictureRetirement.js.map +1 -0
- package/lib/module/base/setupVexflowReactNative.js +1 -36
- package/lib/module/base/setupVexflowReactNative.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/MeasureParser.js +22 -119
- package/lib/module/musicxml/MusicXmlParser/MeasureParser.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/MusicXmlNotes.js +129 -0
- package/lib/module/musicxml/MusicXmlParser/MusicXmlNotes.js.map +1 -0
- package/lib/module/musicxml/MusicXmlParser/PartParser.js +8 -1
- package/lib/module/musicxml/MusicXmlParser/PartParser.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/Spanners.js +8 -5
- package/lib/module/musicxml/MusicXmlParser/Spanners.js.map +1 -1
- package/lib/module/musicxml/MusicXmlParser/mappers.js +83 -3
- package/lib/module/musicxml/MusicXmlParser/mappers.js.map +1 -1
- package/lib/module/renderer/Layout/DocumentLayout.js +13 -4
- package/lib/module/renderer/Layout/DocumentLayout.js.map +1 -1
- package/lib/module/renderer/Layout/VerticalSpacing.js +37 -7
- package/lib/module/renderer/Layout/VerticalSpacing.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/ScoreOverlayPicture.js +80 -46
- package/lib/module/renderer/ScoreRenderer/ScoreOverlayPicture.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js +10 -22
- package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/ScoreScrollbar.js +18 -8
- package/lib/module/renderer/ScoreRenderer/ScoreScrollbar.js.map +1 -1
- package/lib/module/renderer/ScoreRenderer/utils.js +42 -88
- package/lib/module/renderer/ScoreRenderer/utils.js.map +1 -1
- package/lib/module/renderer/constants.js +1 -1
- package/lib/module/renderer/layout.js +7 -3
- package/lib/module/renderer/layout.js.map +1 -1
- package/lib/module/renderer/lyrics.js +127 -0
- package/lib/module/renderer/lyrics.js.map +1 -0
- package/lib/module/renderer/measure.js +11 -9
- package/lib/module/renderer/measure.js.map +1 -1
- package/lib/module/renderer/measureBounds.js +5 -0
- package/lib/module/renderer/measureBounds.js.map +1 -1
- package/lib/module/renderer/measureModifiers.js +24 -6
- package/lib/module/renderer/measureModifiers.js.map +1 -1
- package/lib/module/renderer/noteModifiers.js +5 -13
- package/lib/module/renderer/noteModifiers.js.map +1 -1
- package/lib/module/renderer/{fixedNoteSpacing.js → noteSpacing.js} +46 -10
- package/lib/module/renderer/noteSpacing.js.map +1 -0
- package/lib/module/renderer/render.js +37 -20
- package/lib/module/renderer/render.js.map +1 -1
- package/lib/typescript/src/base/FontManager.d.ts +12 -7
- package/lib/typescript/src/base/FontManager.d.ts.map +1 -1
- package/lib/typescript/src/base/VexflowCanvas.d.ts.map +1 -1
- package/lib/typescript/src/base/VexflowRecordingClone.d.ts +8 -0
- package/lib/typescript/src/base/VexflowRecordingClone.d.ts.map +1 -0
- package/lib/typescript/src/base/VexflowRecordingContext.d.ts.map +1 -1
- package/lib/typescript/src/base/builtInTextFont.d.ts +6 -0
- package/lib/typescript/src/base/builtInTextFont.d.ts.map +1 -0
- package/lib/typescript/src/base/cssFontShorthand.d.ts +3 -0
- package/lib/typescript/src/base/cssFontShorthand.d.ts.map +1 -0
- package/lib/typescript/src/base/fonts/academico.d.ts +5 -0
- package/lib/typescript/src/base/fonts/academico.d.ts.map +1 -0
- package/lib/typescript/src/base/pictureRetirement.d.ts +26 -0
- package/lib/typescript/src/base/pictureRetirement.d.ts.map +1 -0
- package/lib/typescript/src/base/setupVexflowReactNative.d.ts +0 -8
- package/lib/typescript/src/base/setupVexflowReactNative.d.ts.map +1 -1
- package/lib/typescript/src/base/types.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts +4 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/MeasureParser.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlNotes.d.ts +13 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlNotes.d.ts.map +1 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/PartParser.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts +6 -0
- package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts.map +1 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts +7 -1
- package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts.map +1 -1
- package/lib/typescript/src/renderer/Layout/DocumentLayout.d.ts.map +1 -1
- package/lib/typescript/src/renderer/Layout/VerticalSpacing.d.ts +6 -0
- package/lib/typescript/src/renderer/Layout/VerticalSpacing.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreOverlayPicture.d.ts +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreOverlayPicture.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreRenderer.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreScrollbar.d.ts +1 -0
- package/lib/typescript/src/renderer/ScoreRenderer/ScoreScrollbar.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts +14 -11
- package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts.map +1 -1
- package/lib/typescript/src/renderer/ScoreRenderer/utils.d.ts +8 -27
- package/lib/typescript/src/renderer/ScoreRenderer/utils.d.ts.map +1 -1
- package/lib/typescript/src/renderer/layout.d.ts +4 -1
- package/lib/typescript/src/renderer/layout.d.ts.map +1 -1
- package/lib/typescript/src/renderer/lyrics.d.ts +42 -0
- package/lib/typescript/src/renderer/lyrics.d.ts.map +1 -0
- package/lib/typescript/src/renderer/measure.d.ts +2 -2
- package/lib/typescript/src/renderer/measure.d.ts.map +1 -1
- package/lib/typescript/src/renderer/measureBounds.d.ts +3 -0
- package/lib/typescript/src/renderer/measureBounds.d.ts.map +1 -1
- package/lib/typescript/src/renderer/measureModifiers.d.ts +14 -4
- package/lib/typescript/src/renderer/measureModifiers.d.ts.map +1 -1
- package/lib/typescript/src/renderer/noteModifiers.d.ts +2 -1
- package/lib/typescript/src/renderer/noteModifiers.d.ts.map +1 -1
- package/lib/typescript/src/renderer/{fixedNoteSpacing.d.ts → noteSpacing.d.ts} +9 -1
- package/lib/typescript/src/renderer/noteSpacing.d.ts.map +1 -0
- package/lib/typescript/src/renderer/render.d.ts.map +1 -1
- package/lib/typescript/src/renderer/types.d.ts +17 -7
- package/lib/typescript/src/renderer/types.d.ts.map +1 -1
- package/lib/typescript/src/state/types.d.ts +8 -2
- package/lib/typescript/src/state/types.d.ts.map +1 -1
- package/package.json +34 -26
- package/src/base/FontManager.ts +50 -31
- package/src/base/VexflowCanvas.tsx +10 -10
- package/src/base/VexflowRecordingClone.ts +89 -0
- package/src/base/VexflowRecordingContext.ts +8 -81
- package/src/base/builtInTextFont.ts +25 -0
- package/src/base/cssFontShorthand.ts +45 -0
- package/src/base/fonts/OFL.txt +93 -0
- package/src/base/fonts/academico.ts +10 -0
- package/src/base/pictureRetirement.ts +74 -0
- package/src/base/setupVexflowReactNative.ts +1 -49
- package/src/base/types.ts +0 -3
- package/src/musicxml/MusicXmlParser/InternalTypes.ts +5 -0
- package/src/musicxml/MusicXmlParser/MeasureParser.ts +31 -182
- package/src/musicxml/MusicXmlParser/MusicXmlNotes.ts +198 -0
- package/src/musicxml/MusicXmlParser/PartParser.ts +10 -3
- package/src/musicxml/MusicXmlParser/Spanners.ts +11 -8
- package/src/musicxml/MusicXmlParser/mappers.ts +55 -6
- package/src/renderer/Layout/DocumentLayout.ts +12 -3
- package/src/renderer/Layout/VerticalSpacing.ts +46 -13
- package/src/renderer/ScoreRenderer/ScoreOverlayPicture.tsx +127 -66
- package/src/renderer/ScoreRenderer/ScoreRenderer.tsx +8 -23
- package/src/renderer/ScoreRenderer/ScoreScrollbar.tsx +16 -2
- package/src/renderer/ScoreRenderer/types.ts +14 -12
- package/src/renderer/ScoreRenderer/utils.ts +54 -125
- package/src/renderer/constants.ts +1 -1
- package/src/renderer/layout.ts +15 -4
- package/src/renderer/lyrics.ts +163 -0
- package/src/renderer/measure.tsx +16 -9
- package/src/renderer/measureBounds.ts +10 -0
- package/src/renderer/measureModifiers.ts +27 -7
- package/src/renderer/noteModifiers.ts +8 -9
- package/src/renderer/{fixedNoteSpacing.ts → noteSpacing.ts} +60 -9
- package/src/renderer/render.tsx +51 -25
- package/src/renderer/types.ts +17 -7
- package/src/state/types.ts +8 -2
- package/lib/module/renderer/fixedNoteSpacing.js.map +0 -1
- package/lib/module/utils.js +0 -44
- package/lib/module/utils.js.map +0 -1
- package/lib/typescript/src/renderer/fixedNoteSpacing.d.ts.map +0 -1
- package/lib/typescript/src/utils.d.ts +0 -1
- package/lib/typescript/src/utils.d.ts.map +0 -1
- package/src/utils.tsx +0 -42
|
@@ -90,11 +90,17 @@ export interface MeasureState {
|
|
|
90
90
|
tempo?: Tempo;
|
|
91
91
|
}
|
|
92
92
|
export interface MeasureLeftModifiers {
|
|
93
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* undefined = shown on the first measure and at every system start
|
|
95
|
+
* (`spacing.clefOnEachSystem`); false hides it there too.
|
|
96
|
+
*/
|
|
94
97
|
showClef?: boolean;
|
|
95
98
|
/** undefined = hidden. */
|
|
96
99
|
showMeter?: boolean;
|
|
97
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* undefined = shown where the clef is by default; false hides it there too.
|
|
102
|
+
* Never drawn on a percussion clef.
|
|
103
|
+
*/
|
|
98
104
|
showKeySignature?: boolean;
|
|
99
105
|
/** undefined = 'single'; only 'single' and 'repeat-begin' render here. */
|
|
100
106
|
startBarline?: Barline;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/state/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,EAAE,GAAG,MAAM,CAAC;AAExB,MAAM,MAAM,IAAI,GACZ,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,SAAS,GACT,eAAe,GACf,YAAY,GACZ,YAAY,GACZ,SAAS,GACT,QAAQ,GACR,YAAY,GACZ,KAAK,CAAC;AAEV,MAAM,MAAM,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAE3D,MAAM,MAAM,UAAU,GAClB,IAAI,GACJ,GAAG,GACH,GAAG,GACH,GAAG,GACH,IAAI,GACJ,GAAG,GACH,cAAc,GACd,eAAe,CAAC;AAEpB,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,OAAO,GACP,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,KAAK,CAAC;AAEV,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,MAAM,GAAG,M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AAC;CACjB;AAED,MAAM,MAAM,cAAc,GACtB,sBAAsB,GACtB,iBAAiB,GACjB,eAAe,GACf,oBAAoB,GACpB,mBAAmB,CAAC;AAExB,MAAM,WAAW,GAAG;IAClB,EAAE,EAAE,EAAE,CAAC;IACP,UAAU,EAAE,EAAE,CAAC;IACf,QAAQ,EAAE,EAAE,CAAC;CACd;AAED,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,EAAE,CAAC;IACP,UAAU,EAAE,EAAE,CAAC;IACf,QAAQ,EAAE,EAAE,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,EAAE,CAAC;IACP,OAAO,EAAE,EAAE,CAAC;IACZ,OAAO,EAAE,EAAE,EAAE,CAAC;IACd,KAAK,EAAE,QAAQ,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,EAAE,CAAC;IACP,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,cAAc,EAAE,CAAC;IAC/B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;CACzB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vexflow-native",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "React Native backend for rendering music notation using react-native-skia",
|
|
5
5
|
"main": "./lib/module/base/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/base/index.d.ts",
|
|
@@ -35,13 +35,6 @@
|
|
|
35
35
|
"files": [
|
|
36
36
|
"src",
|
|
37
37
|
"lib",
|
|
38
|
-
"react-native.config.js",
|
|
39
|
-
"!ios/build",
|
|
40
|
-
"!android/build",
|
|
41
|
-
"!android/gradle",
|
|
42
|
-
"!android/gradlew",
|
|
43
|
-
"!android/gradlew.bat",
|
|
44
|
-
"!android/local.properties",
|
|
45
38
|
"!**/__tests__",
|
|
46
39
|
"!**/__fixtures__",
|
|
47
40
|
"!**/__mocks__",
|
|
@@ -54,7 +47,7 @@
|
|
|
54
47
|
"typecheck": "tsc",
|
|
55
48
|
"lint": "eslint src example --ext .js,.ts,.tsx",
|
|
56
49
|
"lint:fix": "yarn lint --fix",
|
|
57
|
-
"format": "prettier --write README.md package.json \"docs/*.md\" \"src/**/*.{ts,tsx}\"",
|
|
50
|
+
"format": "prettier --write README.md package.json \"docs/*.md\" \"src/**/*.{ts,tsx}\" CONTRIBUTING.md \"example/src/**/*.{ts,tsx}\" \"example/*.{js,ts,tsx}\"",
|
|
58
51
|
"test": "jest",
|
|
59
52
|
"docs:api": "typedoc",
|
|
60
53
|
"release": "release-it --only-version"
|
|
@@ -104,7 +97,6 @@
|
|
|
104
97
|
"react-native-skia": "3.6.3",
|
|
105
98
|
"react-native-worklets": "0.10.1",
|
|
106
99
|
"release-it": "^19.0.4",
|
|
107
|
-
"turbo": "^2.5.6",
|
|
108
100
|
"typedoc": "0.28.20",
|
|
109
101
|
"typescript": "^5.9.2",
|
|
110
102
|
"vexflow": "^5.0.0"
|
|
@@ -148,22 +140,38 @@
|
|
|
148
140
|
"useTabs": false
|
|
149
141
|
},
|
|
150
142
|
"jest": {
|
|
151
|
-
"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
143
|
+
"projects": [
|
|
144
|
+
{
|
|
145
|
+
"displayName": "library",
|
|
146
|
+
"preset": "@react-native/jest-preset",
|
|
147
|
+
"testMatch": [
|
|
148
|
+
"**/__tests__/**/*.test.[jt]s?(x)"
|
|
149
|
+
],
|
|
150
|
+
"moduleNameMapper": {
|
|
151
|
+
"^react-native-skia$": "<rootDir>/src/__tests__/skiaMock"
|
|
152
|
+
},
|
|
153
|
+
"modulePathIgnorePatterns": [
|
|
154
|
+
"<rootDir>/example/node_modules",
|
|
155
|
+
"<rootDir>/lib/",
|
|
156
|
+
"<rootDir>/prev-implementation/",
|
|
157
|
+
"<rootDir>/.claude/"
|
|
158
|
+
],
|
|
159
|
+
"testPathIgnorePatterns": [
|
|
160
|
+
"<rootDir>/example/(?!src/benchmark/)",
|
|
161
|
+
"<rootDir>/prev-implementation/"
|
|
162
|
+
]
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"displayName": "example",
|
|
166
|
+
"rootDir": "example",
|
|
167
|
+
"preset": "@react-native/jest-preset",
|
|
168
|
+
"testMatch": [
|
|
169
|
+
"<rootDir>/src/components/**/*.test.tsx"
|
|
170
|
+
],
|
|
171
|
+
"moduleNameMapper": {
|
|
172
|
+
"^react-native($|/.*)": "<rootDir>/node_modules/react-native$1"
|
|
173
|
+
}
|
|
174
|
+
}
|
|
167
175
|
]
|
|
168
176
|
},
|
|
169
177
|
"commitlint": {
|
package/src/base/FontManager.ts
CHANGED
|
@@ -6,10 +6,7 @@ import type {
|
|
|
6
6
|
SkTypeface,
|
|
7
7
|
SkTypefaceFontProvider,
|
|
8
8
|
} from 'react-native-skia';
|
|
9
|
-
|
|
10
|
-
// import Logger, { LogCategory } from '../shared/Logger';
|
|
11
|
-
|
|
12
|
-
// const Log = Logger.extend(LogCategory.FontManager);
|
|
9
|
+
import { builtInTextTypeface } from './builtInTextFont';
|
|
13
10
|
|
|
14
11
|
interface ResolvedFont {
|
|
15
12
|
family: string;
|
|
@@ -32,7 +29,7 @@ function parseSize(size?: string | number): number {
|
|
|
32
29
|
const match = size.trim().match(/^(\d+(?:\.\d+)?)(px|pt|em|%)?$/);
|
|
33
30
|
|
|
34
31
|
if (match) {
|
|
35
|
-
const value = parseFloat(match
|
|
32
|
+
const value = parseFloat(match[1] || '30');
|
|
36
33
|
const unit = match[2] || 'pt';
|
|
37
34
|
|
|
38
35
|
switch (unit) {
|
|
@@ -49,7 +46,7 @@ function parseSize(size?: string | number): number {
|
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
48
|
|
|
52
|
-
return 30; // Default font size in
|
|
49
|
+
return 30; // Default font size in points
|
|
53
50
|
}
|
|
54
51
|
|
|
55
52
|
function parseWeight(weight?: string | number): FontWeight {
|
|
@@ -93,7 +90,7 @@ export default class FontManager {
|
|
|
93
90
|
|
|
94
91
|
private fontProvider: SkTypefaceFontProvider;
|
|
95
92
|
private defaultFontName: string;
|
|
96
|
-
private
|
|
93
|
+
private registeredFamilies: Record<string, string> = {};
|
|
97
94
|
// Instances never cross runtimes; each runtime builds its own, so these
|
|
98
95
|
// caches are runtime-local.
|
|
99
96
|
private familyMatchCache: Record<string, string> = {};
|
|
@@ -118,11 +115,17 @@ export default class FontManager {
|
|
|
118
115
|
);
|
|
119
116
|
}
|
|
120
117
|
|
|
121
|
-
|
|
118
|
+
for (const family of families) {
|
|
119
|
+
const key = family.toLowerCase();
|
|
120
|
+
|
|
121
|
+
if (this.registeredFamilies[key] == null) {
|
|
122
|
+
this.registeredFamilies[key] = family;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
122
125
|
}
|
|
123
126
|
|
|
124
|
-
private
|
|
125
|
-
return this.
|
|
127
|
+
private registeredFamily(family: string): string | undefined {
|
|
128
|
+
return this.registeredFamilies[family.toLowerCase()];
|
|
126
129
|
}
|
|
127
130
|
|
|
128
131
|
private getFamiliesFromFont(font: string | FontInfo): string[] {
|
|
@@ -151,8 +154,10 @@ export default class FontManager {
|
|
|
151
154
|
let matched = this.defaultFontName;
|
|
152
155
|
|
|
153
156
|
for (const family of families) {
|
|
154
|
-
|
|
155
|
-
|
|
157
|
+
const registered = this.registeredFamily(family);
|
|
158
|
+
|
|
159
|
+
if (registered != null) {
|
|
160
|
+
matched = registered;
|
|
156
161
|
break;
|
|
157
162
|
}
|
|
158
163
|
}
|
|
@@ -161,36 +166,50 @@ export default class FontManager {
|
|
|
161
166
|
return matched;
|
|
162
167
|
}
|
|
163
168
|
|
|
164
|
-
/**
|
|
165
|
-
* the
|
|
166
|
-
|
|
167
|
-
* knows none of them, or when the provider has the first one. */
|
|
168
|
-
private matchSystemTypeface(
|
|
169
|
-
font: string | FontInfo | undefined,
|
|
170
|
-
style: { weight: FontWeight; slant: FontSlant; width: FontWidth }
|
|
171
|
-
): SkTypeface | null {
|
|
172
|
-
if (!font || this.matchFontFamilyName(font) !== this.defaultFontName) {
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
|
|
169
|
+
/** The OS font manager, or null where there is none to ask (CanvasKit on
|
|
170
|
+
* the web gives an empty one). */
|
|
171
|
+
private systemFonts(): SkFontMgr | null {
|
|
176
172
|
if (this.systemFontMgr === undefined) {
|
|
177
173
|
try {
|
|
178
|
-
|
|
174
|
+
const fontMgr = Skia.FontMgr.System();
|
|
175
|
+
this.systemFontMgr = fontMgr.countFamilies() > 0 ? fontMgr : null;
|
|
179
176
|
} catch {
|
|
180
177
|
this.systemFontMgr = null;
|
|
181
178
|
}
|
|
182
179
|
}
|
|
183
180
|
|
|
184
|
-
|
|
181
|
+
return this.systemFontMgr;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** A typeface from outside the provider, for a request the provider has
|
|
185
|
+
* none of the families of: the system typeface for the first requested
|
|
186
|
+
* family the OS knows, walking the list in order until a provider family is
|
|
187
|
+
* reached — so a requested family the OS knows wins over a later provider
|
|
188
|
+
* family; without system fonts, the built-in text face unless the provider
|
|
189
|
+
* has a requested family; null otherwise. */
|
|
190
|
+
private matchFallbackTypeface(
|
|
191
|
+
font: string | FontInfo | undefined,
|
|
192
|
+
style: { weight: FontWeight; slant: FontSlant; width: FontWidth }
|
|
193
|
+
): SkTypeface | null {
|
|
194
|
+
if (!font || this.matchFontFamilyName(font) !== this.defaultFontName) {
|
|
185
195
|
return null;
|
|
186
196
|
}
|
|
187
197
|
|
|
188
|
-
|
|
189
|
-
|
|
198
|
+
const families = this.getFamiliesFromFont(font);
|
|
199
|
+
const systemFontMgr = this.systemFonts();
|
|
200
|
+
|
|
201
|
+
if (!systemFontMgr) {
|
|
202
|
+
return families.some((family) => this.registeredFamily(family) != null)
|
|
203
|
+
? null
|
|
204
|
+
: builtInTextTypeface(style.weight);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
for (const family of families) {
|
|
208
|
+
if (this.registeredFamily(family) != null) {
|
|
190
209
|
return null;
|
|
191
210
|
}
|
|
192
211
|
try {
|
|
193
|
-
const typeface =
|
|
212
|
+
const typeface = systemFontMgr.matchFamilyStyle(family, style);
|
|
194
213
|
if (typeface) {
|
|
195
214
|
return typeface;
|
|
196
215
|
}
|
|
@@ -247,12 +266,12 @@ export default class FontManager {
|
|
|
247
266
|
}
|
|
248
267
|
|
|
249
268
|
const typeface =
|
|
250
|
-
this.
|
|
269
|
+
this.matchFallbackTypeface(font, fontStyle) ??
|
|
251
270
|
this.fontProvider.matchFamilyStyle(family, fontStyle);
|
|
252
271
|
|
|
253
272
|
if (!typeface) {
|
|
254
273
|
throw new Error(
|
|
255
|
-
`Failed to create SkFont. No matching typeface found for family "${family}" with weight "${resolvedWeight}" and slant "${slant}".`
|
|
274
|
+
`Failed to create SkFont. No matching typeface found for family "${family}" with weight "${FontWeight[resolvedWeight]}" and slant "${FontSlant[slant]}".`
|
|
256
275
|
);
|
|
257
276
|
}
|
|
258
277
|
|
|
@@ -2,23 +2,21 @@ import { Canvas, Picture, Skia, useCanvasSize } from 'react-native-skia';
|
|
|
2
2
|
import React, { useMemo } from 'react';
|
|
3
3
|
import { StyleSheet } from 'react-native';
|
|
4
4
|
|
|
5
|
+
import { usePictureRetirement } from './pictureRetirement';
|
|
5
6
|
import type { VexflowCanvasProps } from './types';
|
|
6
7
|
import VexflowRecordingContext from './VexflowRecordingContext';
|
|
7
8
|
import { renderVexflowRecordingCommands } from './VexflowRecordingReplay';
|
|
8
9
|
|
|
9
10
|
const VexflowCanvas: React.FC<VexflowCanvasProps> = (props) => {
|
|
10
|
-
const {
|
|
11
|
-
onDraw,
|
|
12
|
-
fontManager,
|
|
13
|
-
defaultFont,
|
|
14
|
-
// width: propWidth,
|
|
15
|
-
// height: propHeight,
|
|
16
|
-
// colorScheme = 'light',
|
|
17
|
-
} = props;
|
|
11
|
+
const { onDraw, fontManager, defaultFont } = props;
|
|
18
12
|
|
|
19
13
|
const { size: canvasSize, onLayout } = useCanvasSize();
|
|
20
14
|
|
|
21
15
|
const picture = useMemo(() => {
|
|
16
|
+
if (canvasSize.width === 0 || canvasSize.height === 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
22
20
|
const recorder = Skia.PictureRecorder();
|
|
23
21
|
const canvas = recorder.beginRecording(
|
|
24
22
|
Skia.XYWHRect(0, 0, canvasSize.width, canvasSize.height)
|
|
@@ -37,9 +35,11 @@ const VexflowCanvas: React.FC<VexflowCanvasProps> = (props) => {
|
|
|
37
35
|
return recorder.finishRecordingAsPicture();
|
|
38
36
|
}, [onDraw, canvasSize, fontManager, defaultFont]);
|
|
39
37
|
|
|
38
|
+
usePictureRetirement(picture);
|
|
39
|
+
|
|
40
40
|
return (
|
|
41
41
|
<Canvas style={styles.canvas} onLayout={onLayout}>
|
|
42
|
-
<Picture picture={picture} />
|
|
42
|
+
{picture ? <Picture picture={picture} /> : null}
|
|
43
43
|
</Canvas>
|
|
44
44
|
);
|
|
45
45
|
};
|
|
@@ -48,6 +48,6 @@ export default VexflowCanvas;
|
|
|
48
48
|
|
|
49
49
|
const styles = StyleSheet.create({
|
|
50
50
|
canvas: {
|
|
51
|
-
flex: 1,
|
|
51
|
+
flex: 1,
|
|
52
52
|
},
|
|
53
53
|
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
VexflowRecordingCommand,
|
|
3
|
+
VexflowRecordingFont,
|
|
4
|
+
VexflowRecordingLineCap,
|
|
5
|
+
VexflowRecordingPaint,
|
|
6
|
+
VexflowRecordingPathCommand,
|
|
7
|
+
VexflowRecordingRect,
|
|
8
|
+
} from './VexflowRecordingTypes';
|
|
9
|
+
|
|
10
|
+
export function makeRect(
|
|
11
|
+
x: number,
|
|
12
|
+
y: number,
|
|
13
|
+
width: number,
|
|
14
|
+
height: number
|
|
15
|
+
): VexflowRecordingRect {
|
|
16
|
+
return { x, y, width, height };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function normalizeLineCap(cap: string): VexflowRecordingLineCap {
|
|
20
|
+
if (cap === 'round' || cap === 'square') {
|
|
21
|
+
return cap;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return 'butt';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function clonePaint(
|
|
28
|
+
paint: VexflowRecordingPaint
|
|
29
|
+
): VexflowRecordingPaint {
|
|
30
|
+
return {
|
|
31
|
+
...paint,
|
|
32
|
+
...(paint.lineDash ? { lineDash: [...paint.lineDash] } : null),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function cloneFont(font: VexflowRecordingFont): VexflowRecordingFont {
|
|
37
|
+
return {
|
|
38
|
+
...font,
|
|
39
|
+
font:
|
|
40
|
+
typeof font.font === 'object' && font.font ? { ...font.font } : font.font,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function clonePathCommand(
|
|
45
|
+
command: VexflowRecordingPathCommand
|
|
46
|
+
): VexflowRecordingPathCommand {
|
|
47
|
+
if (command.type === 'addRect' || command.type === 'addArc') {
|
|
48
|
+
return {
|
|
49
|
+
...command,
|
|
50
|
+
rect: { ...command.rect },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return { ...command };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function cloneCommand(
|
|
58
|
+
command: VexflowRecordingCommand
|
|
59
|
+
): VexflowRecordingCommand {
|
|
60
|
+
switch (command.type) {
|
|
61
|
+
case 'fillRect':
|
|
62
|
+
return {
|
|
63
|
+
...command,
|
|
64
|
+
rect: { ...command.rect },
|
|
65
|
+
paint: clonePaint(command.paint),
|
|
66
|
+
};
|
|
67
|
+
case 'fillPath':
|
|
68
|
+
case 'strokePath':
|
|
69
|
+
return {
|
|
70
|
+
...command,
|
|
71
|
+
path: command.path.map((pathCommand) => clonePathCommand(pathCommand)),
|
|
72
|
+
paint: clonePaint(command.paint),
|
|
73
|
+
};
|
|
74
|
+
case 'fillText':
|
|
75
|
+
return {
|
|
76
|
+
...command,
|
|
77
|
+
paint: clonePaint(command.paint),
|
|
78
|
+
font: cloneFont(command.font),
|
|
79
|
+
};
|
|
80
|
+
case 'clipRect':
|
|
81
|
+
case 'clearRect':
|
|
82
|
+
return {
|
|
83
|
+
...command,
|
|
84
|
+
rect: { ...command.rect },
|
|
85
|
+
};
|
|
86
|
+
default:
|
|
87
|
+
return { ...command };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -10,13 +10,19 @@ import {
|
|
|
10
10
|
resolveVexflowColor,
|
|
11
11
|
type VexflowColorScheme,
|
|
12
12
|
} from './VexflowColorScheme';
|
|
13
|
+
import {
|
|
14
|
+
cloneCommand,
|
|
15
|
+
cloneFont,
|
|
16
|
+
clonePaint,
|
|
17
|
+
clonePathCommand,
|
|
18
|
+
makeRect,
|
|
19
|
+
normalizeLineCap,
|
|
20
|
+
} from './VexflowRecordingClone';
|
|
13
21
|
import type {
|
|
14
22
|
VexflowRecordingCommand,
|
|
15
23
|
VexflowRecordingFont,
|
|
16
|
-
VexflowRecordingLineCap,
|
|
17
24
|
VexflowRecordingPaint,
|
|
18
25
|
VexflowRecordingPathCommand,
|
|
19
|
-
VexflowRecordingRect,
|
|
20
26
|
} from './VexflowRecordingTypes';
|
|
21
27
|
|
|
22
28
|
const showSilentLogs = false;
|
|
@@ -462,82 +468,3 @@ export default class VexflowRecordingContext implements VexflowRenderContext {
|
|
|
462
468
|
this.commands.push(command);
|
|
463
469
|
}
|
|
464
470
|
}
|
|
465
|
-
|
|
466
|
-
function makeRect(
|
|
467
|
-
x: number,
|
|
468
|
-
y: number,
|
|
469
|
-
width: number,
|
|
470
|
-
height: number
|
|
471
|
-
): VexflowRecordingRect {
|
|
472
|
-
return { x, y, width, height };
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
function normalizeLineCap(cap: string): VexflowRecordingLineCap {
|
|
476
|
-
if (cap === 'round' || cap === 'square') {
|
|
477
|
-
return cap;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
return 'butt';
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
function clonePaint(paint: VexflowRecordingPaint): VexflowRecordingPaint {
|
|
484
|
-
return {
|
|
485
|
-
...paint,
|
|
486
|
-
...(paint.lineDash ? { lineDash: [...paint.lineDash] } : null),
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
function cloneFont(font: VexflowRecordingFont): VexflowRecordingFont {
|
|
491
|
-
return {
|
|
492
|
-
...font,
|
|
493
|
-
font:
|
|
494
|
-
typeof font.font === 'object' && font.font ? { ...font.font } : font.font,
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
function clonePathCommand(
|
|
499
|
-
command: VexflowRecordingPathCommand
|
|
500
|
-
): VexflowRecordingPathCommand {
|
|
501
|
-
if (command.type === 'addRect' || command.type === 'addArc') {
|
|
502
|
-
return {
|
|
503
|
-
...command,
|
|
504
|
-
rect: { ...command.rect },
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
return { ...command };
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
function cloneCommand(
|
|
512
|
-
command: VexflowRecordingCommand
|
|
513
|
-
): VexflowRecordingCommand {
|
|
514
|
-
switch (command.type) {
|
|
515
|
-
case 'fillRect':
|
|
516
|
-
return {
|
|
517
|
-
...command,
|
|
518
|
-
rect: { ...command.rect },
|
|
519
|
-
paint: clonePaint(command.paint),
|
|
520
|
-
};
|
|
521
|
-
case 'fillPath':
|
|
522
|
-
case 'strokePath':
|
|
523
|
-
return {
|
|
524
|
-
...command,
|
|
525
|
-
path: command.path.map((pathCommand) => clonePathCommand(pathCommand)),
|
|
526
|
-
paint: clonePaint(command.paint),
|
|
527
|
-
};
|
|
528
|
-
case 'fillText':
|
|
529
|
-
return {
|
|
530
|
-
...command,
|
|
531
|
-
paint: clonePaint(command.paint),
|
|
532
|
-
font: cloneFont(command.font),
|
|
533
|
-
};
|
|
534
|
-
case 'clipRect':
|
|
535
|
-
case 'clearRect':
|
|
536
|
-
return {
|
|
537
|
-
...command,
|
|
538
|
-
rect: { ...command.rect },
|
|
539
|
-
};
|
|
540
|
-
default:
|
|
541
|
-
return { ...command };
|
|
542
|
-
}
|
|
543
|
-
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FontWeight, Skia } from 'react-native-skia';
|
|
2
|
+
import type { SkTypeface } from 'react-native-skia';
|
|
3
|
+
import { ACADEMICO_WOFF2 } from './fonts/academico';
|
|
4
|
+
|
|
5
|
+
// Deliberately not a worklet: FontManager (a worklet class) captures
|
|
6
|
+
// builtInTextTypeface as a remote-function reference on native, so the font
|
|
7
|
+
// data never enters a worklet closure. Called only without system fonts (the
|
|
8
|
+
// web), where worklets run on the JS thread.
|
|
9
|
+
const decoded: Partial<
|
|
10
|
+
Record<keyof typeof ACADEMICO_WOFF2, SkTypeface | null>
|
|
11
|
+
> = {};
|
|
12
|
+
|
|
13
|
+
/** The built-in Latin text face (Academico; bold from semibold up), decoded
|
|
14
|
+
* on first use once per JS runtime. */
|
|
15
|
+
export function builtInTextTypeface(weight: FontWeight): SkTypeface | null {
|
|
16
|
+
const face = weight >= FontWeight.SemiBold ? 'bold' : 'regular';
|
|
17
|
+
|
|
18
|
+
if (decoded[face] === undefined) {
|
|
19
|
+
decoded[face] = Skia.Typeface.MakeFreeTypeFaceFromData(
|
|
20
|
+
Skia.Data.fromBase64(ACADEMICO_WOFF2[face])
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return decoded[face];
|
|
25
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { FontInfo } from 'vexflow';
|
|
2
|
+
|
|
3
|
+
const FONT_SIZE_PATTERN =
|
|
4
|
+
/(\d+(?:\.\d+)?(?:px|pt|em|rem|%|in|mm|cm)?)(?:\/[^\s]+)?/i;
|
|
5
|
+
const FONT_STYLE_PATTERN = /\b(italic|oblique|normal)\b/i;
|
|
6
|
+
const FONT_WEIGHT_PATTERN = /\b(bold|bolder|lighter|normal|[1-9]00)\b/i;
|
|
7
|
+
|
|
8
|
+
export function parseCssFontShorthand(
|
|
9
|
+
cssFontShorthand: string
|
|
10
|
+
): Required<FontInfo> {
|
|
11
|
+
const source = cssFontShorthand.trim();
|
|
12
|
+
|
|
13
|
+
if (source.length === 0) {
|
|
14
|
+
return emptyFontInfo();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const sizeMatch = source.match(FONT_SIZE_PATTERN);
|
|
18
|
+
|
|
19
|
+
if (!sizeMatch || sizeMatch.index === undefined) {
|
|
20
|
+
return emptyFontInfo();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const prefix = source.slice(0, sizeMatch.index).trim();
|
|
24
|
+
const family = source.slice(sizeMatch.index + sizeMatch[0].length).trim();
|
|
25
|
+
const style =
|
|
26
|
+
prefix.match(FONT_STYLE_PATTERN)?.[1]?.toLowerCase() ?? 'normal';
|
|
27
|
+
const weight =
|
|
28
|
+
prefix.match(FONT_WEIGHT_PATTERN)?.[1]?.toLowerCase() ?? 'normal';
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
family,
|
|
32
|
+
size: sizeMatch[1] ?? '',
|
|
33
|
+
weight,
|
|
34
|
+
style,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function emptyFontInfo(): Required<FontInfo> {
|
|
39
|
+
return {
|
|
40
|
+
family: '',
|
|
41
|
+
size: '',
|
|
42
|
+
weight: '',
|
|
43
|
+
style: '',
|
|
44
|
+
};
|
|
45
|
+
}
|