@nice2dev/ui-graphics 1.3.14 → 1.3.16
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/CHANGELOG.md +13 -0
- package/dist/cjs/animation/AnimatedPerson.js +470 -143
- package/dist/cjs/animation/AnimationEditor.js +289 -101
- package/dist/cjs/animation/Audience.js +83 -61
- package/dist/cjs/animation/BodyRenderer.js +69 -28
- package/dist/cjs/animation/animationHelper.js +281 -288
- package/dist/cjs/animation/characterTypes.js +200 -203
- package/dist/cjs/animation/choreoDSL.js +205 -219
- package/dist/cjs/animation/choreography.js +4 -32
- package/dist/cjs/animation/karaokeIntegration.js +68 -77
- package/dist/cjs/animation/lottieExport.js +108 -114
- package/dist/cjs/animation/motionPath.js +225 -248
- package/dist/cjs/animation/physics.js +227 -254
- package/dist/cjs/animation/rig/RigPlayer.js +53 -56
- package/dist/cjs/animation/rig/RiggedBody.js +71 -26
- package/dist/cjs/animation/rig/choreoRigBridge.js +72 -77
- package/dist/cjs/animation/rig/ik.js +13 -18
- package/dist/cjs/animation/rig/poseOps.js +34 -41
- package/dist/cjs/animation/rig/presets.js +64 -72
- package/dist/cjs/animation/rig/rigMath.js +25 -32
- package/dist/cjs/animation/rig/rigTypes.js +59 -63
- package/dist/cjs/animation/shapes/arms.js +31 -13
- package/dist/cjs/animation/shapes/eyes.js +129 -47
- package/dist/cjs/animation/shapes/hair.js +72 -45
- package/dist/cjs/animation/shapes/heads.js +131 -57
- package/dist/cjs/animation/shapes/headwear.js +47 -38
- package/dist/cjs/animation/shapes/legs.js +31 -13
- package/dist/cjs/animation/shapes/mouths.js +120 -44
- package/dist/cjs/animation/shapes/noses.js +80 -25
- package/dist/cjs/animation/shapes/outfits.js +101 -39
- package/dist/cjs/animation/shapes/torsos.js +15 -11
- package/dist/cjs/animation/spineExport.js +103 -121
- package/dist/cjs/core/LocalUI.js +108 -43
- package/dist/cjs/core/NiceBrushEngine.js +758 -552
- package/dist/cjs/core/collaboration.js +249 -251
- package/dist/cjs/core/colorBlindness.js +100 -115
- package/dist/cjs/core/dragDrop.js +155 -158
- package/dist/cjs/core/editorAsk.js +51 -41
- package/dist/cjs/core/fixes.js +140 -171
- package/dist/cjs/core/gridGuides.js +166 -201
- package/dist/cjs/core/historyVisual.js +156 -135
- package/dist/cjs/core/i18n.js +13 -14
- package/dist/cjs/core/integrations.js +238 -249
- package/dist/cjs/core/minimap.js +149 -151
- package/dist/cjs/core/plugins.js +98 -113
- package/dist/cjs/core/rtl.js +71 -83
- package/dist/cjs/core/shortcuts.js +196 -225
- package/dist/cjs/core/theme.js +142 -149
- package/dist/cjs/core/yjsCollaboration.js +232 -293
- package/dist/cjs/design/design-tools.js +12 -22
- package/dist/cjs/font/NiceFontEditor.js +877 -316
- package/dist/cjs/font/fontFormatUtils.js +388 -448
- package/dist/cjs/game/GameAsset2dEditor.js +1201 -392
- package/dist/cjs/game/GameAsset2dEditor.module.css.js +146 -5
- package/dist/cjs/game/gameAssetTypes.js +7 -16
- package/dist/cjs/game/gameAssetUtils.js +390 -413
- package/dist/cjs/game/useGameAssetEditor.js +820 -763
- package/dist/cjs/index.js +81 -84
- package/dist/cjs/nice2dev-ui-graphics.css +1 -1
- package/dist/cjs/node_modules/lib0/array.js +8 -70
- package/dist/cjs/node_modules/lib0/binary.js +3 -20
- package/dist/cjs/node_modules/lib0/broadcastchannel.js +24 -86
- package/dist/cjs/node_modules/lib0/buffer.js +15 -82
- package/dist/cjs/node_modules/lib0/conditions.js +3 -16
- package/dist/cjs/node_modules/lib0/decoding.js +108 -287
- package/dist/cjs/node_modules/lib0/dom.js +14 -44
- package/dist/cjs/node_modules/lib0/encoding.js +68 -418
- package/dist/cjs/node_modules/lib0/environment.js +26 -92
- package/dist/cjs/node_modules/lib0/error.js +5 -29
- package/dist/cjs/node_modules/lib0/function.js +27 -66
- package/dist/cjs/node_modules/lib0/iterator.js +8 -33
- package/dist/cjs/node_modules/lib0/logging.common.js +12 -22
- package/dist/cjs/node_modules/lib0/logging.js +32 -71
- package/dist/cjs/node_modules/lib0/map.js +16 -86
- package/dist/cjs/node_modules/lib0/math.js +3 -32
- package/dist/cjs/node_modules/lib0/number.js +4 -15
- package/dist/cjs/node_modules/lib0/object.js +14 -88
- package/dist/cjs/node_modules/lib0/observable.js +38 -78
- package/dist/cjs/node_modules/lib0/pair.js +3 -20
- package/dist/cjs/node_modules/lib0/prng.js +8 -77
- package/dist/cjs/node_modules/lib0/promise.js +6 -30
- package/dist/cjs/node_modules/lib0/random.js +8 -23
- package/dist/cjs/node_modules/lib0/schema.js +313 -687
- package/dist/cjs/node_modules/lib0/set.js +3 -10
- package/dist/cjs/node_modules/lib0/storage.js +20 -55
- package/dist/cjs/node_modules/lib0/string.js +17 -72
- package/dist/cjs/node_modules/lib0/symbol.js +2 -12
- package/dist/cjs/node_modules/lib0/time.js +2 -15
- package/dist/cjs/node_modules/lib0/trait/equality.js +3 -28
- package/dist/cjs/node_modules/lib0/url.js +4 -18
- package/dist/cjs/node_modules/lib0/webcrypto.js +2 -5
- package/dist/cjs/node_modules/y-protocols/auth.js +5 -19
- package/dist/cjs/node_modules/y-protocols/awareness.js +53 -116
- package/dist/cjs/node_modules/y-protocols/sync.js +16 -103
- package/dist/cjs/node_modules/y-websocket/src/y-websocket.js +77 -219
- package/dist/cjs/node_modules/yjs/dist/yjs.js +2128 -4868
- package/dist/cjs/photo/FilterThumb.js +37 -25
- package/dist/cjs/photo/NiceAITools.js +679 -467
- package/dist/cjs/photo/PhotoEditor.js +34 -20
- package/dist/cjs/photo/PhotoEditor.module.css.js +296 -5
- package/dist/cjs/photo/PhotoEditorCanvas.js +250 -91
- package/dist/cjs/photo/PhotoEditorLeftPanel.js +1086 -224
- package/dist/cjs/photo/PhotoEditorToolbar.js +135 -19
- package/dist/cjs/photo/photoEditorActions.js +89 -72
- package/dist/cjs/photo/photoEditorTypes.js +29 -32
- package/dist/cjs/photo/photoFilters.js +959 -985
- package/dist/cjs/photo/photoOverlays.js +899 -945
- package/dist/cjs/photo/photoSelection.js +427 -499
- package/dist/cjs/photo/usePhotoEditor.js +739 -741
- package/dist/cjs/pixel/HSVPicker.js +191 -175
- package/dist/cjs/pixel/PixelEditor.js +159 -48
- package/dist/cjs/pixel/PixelEditor.module.css.js +209 -5
- package/dist/cjs/pixel/PixelEditorCanvas.js +29 -16
- package/dist/cjs/pixel/PixelEditorMenuBar.js +160 -162
- package/dist/cjs/pixel/PixelEditorRightPanel.js +377 -45
- package/dist/cjs/pixel/PixelEditorStatusBar.js +47 -20
- package/dist/cjs/pixel/PixelEditorTimeline.js +106 -23
- package/dist/cjs/pixel/PixelEditorToolbar.js +99 -21
- package/dist/cjs/pixel/SpriteGeneratorPanel.js +483 -303
- package/dist/cjs/pixel/animalGeneratorPresets.js +776 -601
- package/dist/cjs/pixel/asepriteFormat.js +511 -560
- package/dist/cjs/pixel/buildingGeneratorPresets.js +693 -520
- package/dist/cjs/pixel/characterGeneratorPresets.js +644 -544
- package/dist/cjs/pixel/pixel-pro.js +52 -63
- package/dist/cjs/pixel/pixelEditorExports.js +388 -428
- package/dist/cjs/pixel/pixelEditorTypes.js +91 -108
- package/dist/cjs/pixel/pixelEditorUtils.js +519 -561
- package/dist/cjs/pixel/spriteGeneratorCore.js +206 -257
- package/dist/cjs/pixel/usePixelEditor.js +1321 -1343
- package/dist/cjs/texture/Nice3DTexturePainter.js +707 -440
- package/dist/cjs/ui/NiceUIDesigner.js +954 -527
- package/dist/cjs/vector/NiceSvgToCode.js +586 -446
- package/dist/cjs/vector/VectorEditor.js +290 -117
- package/dist/cjs/vector/VectorEditor.module.css.js +86 -5
- package/dist/cjs/vector/VectorEditorMenuBar.js +333 -275
- package/dist/cjs/vector/VectorEditorRightPanel.js +1094 -371
- package/dist/cjs/vector/VectorEditorShapeRenderer.js +198 -60
- package/dist/cjs/vector/VectorEditorStatusBar.js +39 -13
- package/dist/cjs/vector/useVectorEditor.js +848 -889
- package/dist/cjs/vector/vectorAnimation.js +110 -137
- package/dist/cjs/vector/vectorBooleanOps.js +398 -485
- package/dist/cjs/vector/vectorEditorExport.js +201 -203
- package/dist/cjs/vector/vectorEditorImport.js +173 -189
- package/dist/cjs/vector/vectorEditorTypes.js +42 -49
- package/dist/cjs/vector/vectorGradients.js +151 -174
- package/dist/cjs/vector/vectorIconExport.js +52 -59
- package/dist/cjs/vector/vectorIconImport.js +169 -219
- package/dist/esm/animation/AnimatedPerson.js +470 -141
- package/dist/esm/animation/AnimationEditor.js +290 -100
- package/dist/esm/animation/Audience.js +83 -59
- package/dist/esm/animation/BodyRenderer.js +71 -25
- package/dist/esm/animation/animationHelper.js +284 -287
- package/dist/esm/animation/characterTypes.js +204 -202
- package/dist/esm/animation/choreoDSL.js +212 -218
- package/dist/esm/animation/choreography.js +8 -31
- package/dist/esm/animation/karaokeIntegration.js +74 -76
- package/dist/esm/animation/lottieExport.js +112 -113
- package/dist/esm/animation/motionPath.js +235 -247
- package/dist/esm/animation/physics.js +235 -253
- package/dist/esm/animation/rig/RigPlayer.js +53 -54
- package/dist/esm/animation/rig/RiggedBody.js +71 -24
- package/dist/esm/animation/rig/choreoRigBridge.js +74 -76
- package/dist/esm/animation/rig/ik.js +14 -17
- package/dist/esm/animation/rig/poseOps.js +37 -40
- package/dist/esm/animation/rig/presets.js +70 -71
- package/dist/esm/animation/rig/rigMath.js +28 -31
- package/dist/esm/animation/rig/rigTypes.js +62 -62
- package/dist/esm/animation/shapes/arms.js +32 -12
- package/dist/esm/animation/shapes/eyes.js +135 -46
- package/dist/esm/animation/shapes/hair.js +80 -44
- package/dist/esm/animation/shapes/heads.js +140 -56
- package/dist/esm/animation/shapes/headwear.js +54 -37
- package/dist/esm/animation/shapes/legs.js +32 -12
- package/dist/esm/animation/shapes/mouths.js +127 -43
- package/dist/esm/animation/shapes/noses.js +87 -24
- package/dist/esm/animation/shapes/outfits.js +106 -38
- package/dist/esm/animation/shapes/torsos.js +16 -10
- package/dist/esm/animation/spineExport.js +106 -120
- package/dist/esm/core/LocalUI.js +111 -42
- package/dist/esm/core/NiceBrushEngine.js +761 -551
- package/dist/esm/core/collaboration.js +255 -250
- package/dist/esm/core/colorBlindness.js +106 -114
- package/dist/esm/core/dragDrop.js +157 -157
- package/dist/esm/core/editorAsk.js +53 -40
- package/dist/esm/core/fixes.js +145 -170
- package/dist/esm/core/gridGuides.js +178 -200
- package/dist/esm/core/historyVisual.js +158 -134
- package/dist/esm/core/i18n.js +15 -13
- package/dist/esm/core/integrations.js +244 -248
- package/dist/esm/core/minimap.js +151 -150
- package/dist/esm/core/plugins.js +102 -112
- package/dist/esm/core/rtl.js +77 -82
- package/dist/esm/core/shortcuts.js +200 -224
- package/dist/esm/core/theme.js +150 -148
- package/dist/esm/core/yjsCollaboration.js +240 -292
- package/dist/esm/design/design-tools.js +13 -21
- package/dist/esm/font/NiceFontEditor.js +880 -315
- package/dist/esm/font/fontFormatUtils.js +394 -447
- package/dist/esm/game/GameAsset2dEditor.js +1202 -391
- package/dist/esm/game/GameAsset2dEditor.module.css.js +146 -3
- package/dist/esm/game/gameAssetTypes.js +8 -15
- package/dist/esm/game/gameAssetUtils.js +408 -412
- package/dist/esm/game/useGameAssetEditor.js +821 -762
- package/dist/esm/index.js +332 -69
- package/dist/esm/nice2dev-ui-graphics.css +1 -1
- package/dist/esm/node_modules/lib0/array.js +15 -69
- package/dist/esm/node_modules/lib0/binary.js +14 -19
- package/dist/esm/node_modules/lib0/broadcastchannel.js +27 -85
- package/dist/esm/node_modules/lib0/buffer.js +20 -80
- package/dist/esm/node_modules/lib0/conditions.js +4 -15
- package/dist/esm/node_modules/lib0/decoding.js +128 -286
- package/dist/esm/node_modules/lib0/dom.js +20 -43
- package/dist/esm/node_modules/lib0/encoding.js +90 -415
- package/dist/esm/node_modules/lib0/environment.js +33 -91
- package/dist/esm/node_modules/lib0/error.js +8 -28
- package/dist/esm/node_modules/lib0/function.js +31 -65
- package/dist/esm/node_modules/lib0/iterator.js +11 -32
- package/dist/esm/node_modules/lib0/logging.common.js +22 -21
- package/dist/esm/node_modules/lib0/logging.js +44 -70
- package/dist/esm/node_modules/lib0/map.js +21 -85
- package/dist/esm/node_modules/lib0/math.js +9 -31
- package/dist/esm/node_modules/lib0/number.js +7 -14
- package/dist/esm/node_modules/lib0/object.js +26 -87
- package/dist/esm/node_modules/lib0/observable.js +40 -77
- package/dist/esm/node_modules/lib0/pair.js +5 -19
- package/dist/esm/node_modules/lib0/prng.js +15 -76
- package/dist/esm/node_modules/lib0/promise.js +7 -29
- package/dist/esm/node_modules/lib0/random.js +10 -22
- package/dist/esm/node_modules/lib0/schema.js +367 -686
- package/dist/esm/node_modules/lib0/set.js +4 -9
- package/dist/esm/node_modules/lib0/storage.js +23 -54
- package/dist/esm/node_modules/lib0/string.js +26 -71
- package/dist/esm/node_modules/lib0/symbol.js +3 -11
- package/dist/esm/node_modules/lib0/time.js +3 -14
- package/dist/esm/node_modules/lib0/trait/equality.js +5 -27
- package/dist/esm/node_modules/lib0/url.js +5 -17
- package/dist/esm/node_modules/lib0/webcrypto.js +3 -4
- package/dist/esm/node_modules/y-protocols/auth.js +7 -18
- package/dist/esm/node_modules/y-protocols/awareness.js +58 -115
- package/dist/esm/node_modules/y-protocols/sync.js +26 -102
- package/dist/esm/node_modules/y-websocket/src/y-websocket.js +82 -218
- package/dist/esm/node_modules/yjs/dist/yjs.js +2263 -4899
- package/dist/esm/photo/FilterThumb.js +37 -23
- package/dist/esm/photo/NiceAITools.js +685 -466
- package/dist/esm/photo/PhotoEditor.js +34 -18
- package/dist/esm/photo/PhotoEditor.module.css.js +296 -3
- package/dist/esm/photo/PhotoEditorCanvas.js +250 -89
- package/dist/esm/photo/PhotoEditorLeftPanel.js +1086 -222
- package/dist/esm/photo/PhotoEditorToolbar.js +135 -17
- package/dist/esm/photo/photoEditorActions.js +93 -71
- package/dist/esm/photo/photoEditorTypes.js +32 -31
- package/dist/esm/photo/photoFilters.js +967 -984
- package/dist/esm/photo/photoOverlays.js +913 -944
- package/dist/esm/photo/photoSelection.js +438 -498
- package/dist/esm/photo/usePhotoEditor.js +740 -740
- package/dist/esm/pixel/HSVPicker.js +192 -174
- package/dist/esm/pixel/PixelEditor.js +160 -47
- package/dist/esm/pixel/PixelEditor.module.css.js +209 -3
- package/dist/esm/pixel/PixelEditorCanvas.js +29 -14
- package/dist/esm/pixel/PixelEditorMenuBar.js +160 -160
- package/dist/esm/pixel/PixelEditorRightPanel.js +377 -43
- package/dist/esm/pixel/PixelEditorStatusBar.js +47 -18
- package/dist/esm/pixel/PixelEditorTimeline.js +106 -21
- package/dist/esm/pixel/PixelEditorToolbar.js +99 -19
- package/dist/esm/pixel/SpriteGeneratorPanel.js +483 -301
- package/dist/esm/pixel/animalGeneratorPresets.js +782 -600
- package/dist/esm/pixel/asepriteFormat.js +517 -559
- package/dist/esm/pixel/buildingGeneratorPresets.js +699 -519
- package/dist/esm/pixel/characterGeneratorPresets.js +650 -543
- package/dist/esm/pixel/pixel-pro.js +53 -62
- package/dist/esm/pixel/pixelEditorExports.js +397 -427
- package/dist/esm/pixel/pixelEditorTypes.js +103 -107
- package/dist/esm/pixel/pixelEditorUtils.js +551 -560
- package/dist/esm/pixel/spriteGeneratorCore.js +223 -256
- package/dist/esm/pixel/usePixelEditor.js +1322 -1342
- package/dist/esm/texture/Nice3DTexturePainter.js +709 -439
- package/dist/esm/ui/NiceUIDesigner.js +957 -526
- package/dist/esm/vector/NiceSvgToCode.js +589 -445
- package/dist/esm/vector/VectorEditor.js +291 -116
- package/dist/esm/vector/VectorEditor.module.css.js +86 -3
- package/dist/esm/vector/VectorEditorMenuBar.js +333 -273
- package/dist/esm/vector/VectorEditorRightPanel.js +1094 -369
- package/dist/esm/vector/VectorEditorShapeRenderer.js +199 -59
- package/dist/esm/vector/VectorEditorStatusBar.js +39 -11
- package/dist/esm/vector/useVectorEditor.js +849 -888
- package/dist/esm/vector/vectorAnimation.js +115 -136
- package/dist/esm/vector/vectorBooleanOps.js +401 -484
- package/dist/esm/vector/vectorEditorExport.js +207 -202
- package/dist/esm/vector/vectorEditorImport.js +174 -188
- package/dist/esm/vector/vectorEditorTypes.js +50 -48
- package/dist/esm/vector/vectorGradients.js +158 -173
- package/dist/esm/vector/vectorIconExport.js +53 -58
- package/dist/esm/vector/vectorIconImport.js +171 -218
- package/package.json +9 -15
|
@@ -1,473 +1,420 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* fontFormatUtils — OTF/TTF binary generation and OpenType feature support
|
|
3
|
-
*
|
|
4
|
-
* Features:
|
|
5
|
-
* - Generate TrueType-compatible binary font data (minimal .ttf)
|
|
6
|
-
* - OpenType feature definitions (liga, kern, smcp, onum, salt, ss01-ss20)
|
|
7
|
-
* - Kerning table generation from pairs
|
|
8
|
-
* - WOFF/WOFF2 wrapper
|
|
9
|
-
* - Font file download utility
|
|
10
|
-
*/
|
|
11
|
-
/* ── OpenType Feature Presets ── */
|
|
12
1
|
const OPENTYPE_FEATURE_PRESETS = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
2
|
+
basic: [
|
|
3
|
+
{ tag: "kern", enabled: true, kerning: [] },
|
|
4
|
+
{
|
|
5
|
+
tag: "liga",
|
|
6
|
+
enabled: true,
|
|
7
|
+
ligatures: [
|
|
8
|
+
{ input: ["f", "i"], replacement: "fi" },
|
|
9
|
+
{ input: ["f", "l"], replacement: "fl" },
|
|
10
|
+
{ input: ["f", "f"], replacement: "ff" }
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
typographic: [
|
|
15
|
+
{ tag: "kern", enabled: true, kerning: [] },
|
|
16
|
+
{ tag: "liga", enabled: true, ligatures: [] },
|
|
17
|
+
{ tag: "onum", enabled: true },
|
|
18
|
+
{ tag: "smcp", enabled: true },
|
|
19
|
+
{ tag: "frac", enabled: true },
|
|
20
|
+
{ tag: "zero", enabled: true }
|
|
21
|
+
],
|
|
22
|
+
"stylistic-full": [
|
|
23
|
+
{ tag: "kern", enabled: true, kerning: [] },
|
|
24
|
+
{ tag: "liga", enabled: true, ligatures: [] },
|
|
25
|
+
{ tag: "salt", enabled: true },
|
|
26
|
+
{ tag: "calt", enabled: true },
|
|
27
|
+
{ tag: "swsh", enabled: true },
|
|
28
|
+
{ tag: "ss01", enabled: true },
|
|
29
|
+
{ tag: "ss02", enabled: true },
|
|
30
|
+
{ tag: "ss03", enabled: true }
|
|
31
|
+
]
|
|
43
32
|
};
|
|
44
|
-
/* ── Common Kerning Pairs ── */
|
|
45
33
|
const COMMON_KERNING_PAIRS = [
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
34
|
+
{ left: "A", right: "V", value: -80 },
|
|
35
|
+
{ left: "A", right: "W", value: -60 },
|
|
36
|
+
{ left: "A", right: "Y", value: -80 },
|
|
37
|
+
{ left: "A", right: "T", value: -60 },
|
|
38
|
+
{ left: "T", right: "a", value: -60 },
|
|
39
|
+
{ left: "T", right: "e", value: -60 },
|
|
40
|
+
{ left: "T", right: "o", value: -60 },
|
|
41
|
+
{ left: "V", right: "a", value: -60 },
|
|
42
|
+
{ left: "V", right: "e", value: -50 },
|
|
43
|
+
{ left: "V", right: "o", value: -50 },
|
|
44
|
+
{ left: "W", right: "a", value: -40 },
|
|
45
|
+
{ left: "W", right: "e", value: -30 },
|
|
46
|
+
{ left: "Y", right: "a", value: -70 },
|
|
47
|
+
{ left: "Y", right: "e", value: -60 },
|
|
48
|
+
{ left: "Y", right: "o", value: -60 },
|
|
49
|
+
{ left: "L", right: "T", value: -50 },
|
|
50
|
+
{ left: "L", right: "V", value: -40 },
|
|
51
|
+
{ left: "L", right: "W", value: -30 },
|
|
52
|
+
{ left: "L", right: "Y", value: -50 },
|
|
53
|
+
{ left: "P", right: "a", value: -30 },
|
|
54
|
+
{ left: "P", right: ".", value: -80 },
|
|
55
|
+
{ left: "P", right: ",", value: -80 },
|
|
56
|
+
{ left: "r", right: ".", value: -40 },
|
|
57
|
+
{ left: "r", right: ",", value: -40 },
|
|
58
|
+
{ left: "f", right: ".", value: -30 },
|
|
59
|
+
{ left: "f", right: ",", value: -30 }
|
|
72
60
|
];
|
|
73
|
-
/* ── TrueType Binary Writer ── */
|
|
74
61
|
class BinaryWriter {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
this.chunks.push(buf);
|
|
115
|
-
this.size += l;
|
|
116
|
-
}
|
|
117
|
-
writeBytes(data) {
|
|
118
|
-
this.chunks.push(data);
|
|
119
|
-
this.size += data.length;
|
|
120
|
-
}
|
|
121
|
-
padTo4() {
|
|
122
|
-
const pad = (4 - (this.size % 4)) % 4;
|
|
123
|
-
if (pad > 0) {
|
|
124
|
-
this.writeBytes(new Uint8Array(pad));
|
|
125
|
-
}
|
|
62
|
+
constructor() {
|
|
63
|
+
this.chunks = [];
|
|
64
|
+
this.size = 0;
|
|
65
|
+
}
|
|
66
|
+
writeUint8(v) {
|
|
67
|
+
this.chunks.push(new Uint8Array([v & 255]));
|
|
68
|
+
this.size += 1;
|
|
69
|
+
}
|
|
70
|
+
writeUint16(v) {
|
|
71
|
+
const buf = new Uint8Array(2);
|
|
72
|
+
buf[0] = v >> 8 & 255;
|
|
73
|
+
buf[1] = v & 255;
|
|
74
|
+
this.chunks.push(buf);
|
|
75
|
+
this.size += 2;
|
|
76
|
+
}
|
|
77
|
+
writeInt16(v) {
|
|
78
|
+
this.writeUint16(v < 0 ? v + 65536 : v);
|
|
79
|
+
}
|
|
80
|
+
writeUint32(v) {
|
|
81
|
+
const buf = new Uint8Array(4);
|
|
82
|
+
buf[0] = v >> 24 & 255;
|
|
83
|
+
buf[1] = v >> 16 & 255;
|
|
84
|
+
buf[2] = v >> 8 & 255;
|
|
85
|
+
buf[3] = v & 255;
|
|
86
|
+
this.chunks.push(buf);
|
|
87
|
+
this.size += 4;
|
|
88
|
+
}
|
|
89
|
+
writeInt32(v) {
|
|
90
|
+
this.writeUint32(v < 0 ? v + 4294967296 : v);
|
|
91
|
+
}
|
|
92
|
+
writeFixed(v) {
|
|
93
|
+
this.writeInt32(Math.round(v * 65536));
|
|
94
|
+
}
|
|
95
|
+
writeString(s, len) {
|
|
96
|
+
const l = len ?? s.length;
|
|
97
|
+
const buf = new Uint8Array(l);
|
|
98
|
+
for (let i = 0; i < l; i++) {
|
|
99
|
+
buf[i] = i < s.length ? s.charCodeAt(i) : 0;
|
|
126
100
|
}
|
|
127
|
-
|
|
128
|
-
|
|
101
|
+
this.chunks.push(buf);
|
|
102
|
+
this.size += l;
|
|
103
|
+
}
|
|
104
|
+
writeBytes(data) {
|
|
105
|
+
this.chunks.push(data);
|
|
106
|
+
this.size += data.length;
|
|
107
|
+
}
|
|
108
|
+
padTo4() {
|
|
109
|
+
const pad = (4 - this.size % 4) % 4;
|
|
110
|
+
if (pad > 0) {
|
|
111
|
+
this.writeBytes(new Uint8Array(pad));
|
|
129
112
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
113
|
+
}
|
|
114
|
+
getSize() {
|
|
115
|
+
return this.size;
|
|
116
|
+
}
|
|
117
|
+
toArrayBuffer() {
|
|
118
|
+
const result = new Uint8Array(this.size);
|
|
119
|
+
let offset = 0;
|
|
120
|
+
for (const chunk of this.chunks) {
|
|
121
|
+
result.set(chunk, offset);
|
|
122
|
+
offset += chunk.length;
|
|
138
123
|
}
|
|
124
|
+
return result.buffer;
|
|
125
|
+
}
|
|
139
126
|
}
|
|
140
127
|
function tag(s) {
|
|
141
|
-
|
|
128
|
+
return s.charCodeAt(0) << 24 | s.charCodeAt(1) << 16 | s.charCodeAt(2) << 8 | s.charCodeAt(3);
|
|
142
129
|
}
|
|
143
|
-
/**
|
|
144
|
-
* Build minimal TrueType font binary.
|
|
145
|
-
* Encodes glyphs as simple contour paths from SVG path data.
|
|
146
|
-
*/
|
|
147
130
|
function buildTTF(fontData, _config) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
w.
|
|
161
|
-
// Table directory placeholder — we'll calculate real offsets after building tables
|
|
162
|
-
w.getSize();
|
|
163
|
-
const tableNames = ['cmap', 'glyf', 'head', 'hhea', 'loca', 'maxp', 'name', 'OS/2', 'post'];
|
|
164
|
-
// Write placeholder entries (tag, checksum, offset, length)
|
|
165
|
-
for (let i = 0; i < numTables; i++) {
|
|
166
|
-
w.writeUint32(tag(tableNames[i]));
|
|
167
|
-
w.writeUint32(0); // checksum placeholder
|
|
168
|
-
w.writeUint32(0); // offset placeholder
|
|
169
|
-
w.writeUint32(0); // length placeholder
|
|
170
|
-
}
|
|
171
|
-
// For simplicity, write each table sequentially and record offsets
|
|
172
|
-
const tableData = new Map();
|
|
173
|
-
// head table
|
|
174
|
-
const headStart = w.getSize();
|
|
175
|
-
w.writeFixed(1.0); // majorVersion.minorVersion
|
|
176
|
-
w.writeFixed(1.0); // fontRevision
|
|
177
|
-
w.writeUint32(0); // checksumAdjustment
|
|
178
|
-
w.writeUint32(0x5f0f3cf5); // magicNumber
|
|
179
|
-
w.writeUint16(0x000b); // flags
|
|
180
|
-
w.writeUint16(metrics.unitsPerEm);
|
|
181
|
-
// created / modified (int64 — 8 bytes each)
|
|
182
|
-
w.writeUint32(0);
|
|
131
|
+
const { metrics, glyphs, name } = fontData;
|
|
132
|
+
const w = new BinaryWriter();
|
|
133
|
+
const numTables = 9;
|
|
134
|
+
w.writeUint32(65536);
|
|
135
|
+
w.writeUint16(numTables);
|
|
136
|
+
const sr = Math.pow(2, Math.floor(Math.log2(numTables))) * 16;
|
|
137
|
+
w.writeUint16(sr);
|
|
138
|
+
w.writeUint16(Math.floor(Math.log2(numTables)));
|
|
139
|
+
w.writeUint16(numTables * 16 - sr);
|
|
140
|
+
w.getSize();
|
|
141
|
+
const tableNames = ["cmap", "glyf", "head", "hhea", "loca", "maxp", "name", "OS/2", "post"];
|
|
142
|
+
for (let i = 0; i < numTables; i++) {
|
|
143
|
+
w.writeUint32(tag(tableNames[i]));
|
|
183
144
|
w.writeUint32(0);
|
|
184
145
|
w.writeUint32(0);
|
|
185
146
|
w.writeUint32(0);
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
w.
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
w.
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
w.
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
w.writeUint16(
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
w.writeUint16(
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
147
|
+
}
|
|
148
|
+
const tableData = /* @__PURE__ */ new Map();
|
|
149
|
+
const headStart = w.getSize();
|
|
150
|
+
w.writeFixed(1);
|
|
151
|
+
w.writeFixed(1);
|
|
152
|
+
w.writeUint32(0);
|
|
153
|
+
w.writeUint32(1594834165);
|
|
154
|
+
w.writeUint16(11);
|
|
155
|
+
w.writeUint16(metrics.unitsPerEm);
|
|
156
|
+
w.writeUint32(0);
|
|
157
|
+
w.writeUint32(0);
|
|
158
|
+
w.writeUint32(0);
|
|
159
|
+
w.writeUint32(0);
|
|
160
|
+
w.writeInt16(0);
|
|
161
|
+
w.writeInt16(metrics.descent);
|
|
162
|
+
w.writeInt16(metrics.unitsPerEm);
|
|
163
|
+
w.writeInt16(metrics.ascent);
|
|
164
|
+
w.writeUint16(0);
|
|
165
|
+
w.writeUint16(8);
|
|
166
|
+
w.writeInt16(2);
|
|
167
|
+
w.writeInt16(1);
|
|
168
|
+
w.writeInt16(0);
|
|
169
|
+
w.padTo4();
|
|
170
|
+
tableData.set("head", { offset: headStart, length: w.getSize() - headStart });
|
|
171
|
+
const hheaStart = w.getSize();
|
|
172
|
+
w.writeFixed(1);
|
|
173
|
+
w.writeInt16(metrics.ascent);
|
|
174
|
+
w.writeInt16(metrics.descent);
|
|
175
|
+
w.writeInt16(metrics.lineGap);
|
|
176
|
+
w.writeUint16(metrics.unitsPerEm);
|
|
177
|
+
w.writeInt16(0);
|
|
178
|
+
w.writeInt16(0);
|
|
179
|
+
w.writeInt16(metrics.unitsPerEm);
|
|
180
|
+
w.writeInt16(1);
|
|
181
|
+
w.writeInt16(0);
|
|
182
|
+
w.writeInt16(0);
|
|
183
|
+
w.writeInt16(0);
|
|
184
|
+
w.writeInt16(0);
|
|
185
|
+
w.writeInt16(0);
|
|
186
|
+
w.writeInt16(0);
|
|
187
|
+
w.writeInt16(0);
|
|
188
|
+
w.writeUint16(glyphs.length + 1);
|
|
189
|
+
w.padTo4();
|
|
190
|
+
tableData.set("hhea", { offset: hheaStart, length: w.getSize() - hheaStart });
|
|
191
|
+
const maxpStart = w.getSize();
|
|
192
|
+
w.writeFixed(1);
|
|
193
|
+
w.writeUint16(glyphs.length + 1);
|
|
194
|
+
w.writeUint16(0);
|
|
195
|
+
w.writeUint16(0);
|
|
196
|
+
w.writeUint16(0);
|
|
197
|
+
w.writeUint16(0);
|
|
198
|
+
w.writeUint16(1);
|
|
199
|
+
w.writeUint16(0);
|
|
200
|
+
w.writeUint16(0);
|
|
201
|
+
w.writeUint16(0);
|
|
202
|
+
w.writeUint16(0);
|
|
203
|
+
w.writeUint16(0);
|
|
204
|
+
w.writeUint16(0);
|
|
205
|
+
w.writeUint16(0);
|
|
206
|
+
w.writeUint16(0);
|
|
207
|
+
w.padTo4();
|
|
208
|
+
tableData.set("maxp", { offset: maxpStart, length: w.getSize() - maxpStart });
|
|
209
|
+
const os2Start = w.getSize();
|
|
210
|
+
w.writeUint16(4);
|
|
211
|
+
w.writeInt16(500);
|
|
212
|
+
w.writeUint16(400);
|
|
213
|
+
w.writeUint16(5);
|
|
214
|
+
w.writeUint16(0);
|
|
215
|
+
w.writeInt16(Math.round(metrics.unitsPerEm * 0.6));
|
|
216
|
+
w.writeInt16(Math.round(metrics.unitsPerEm * 0.6));
|
|
217
|
+
w.writeInt16(0);
|
|
218
|
+
w.writeInt16(Math.round(metrics.unitsPerEm * 0.1));
|
|
219
|
+
w.writeInt16(Math.round(metrics.unitsPerEm * 0.6));
|
|
220
|
+
w.writeInt16(Math.round(metrics.unitsPerEm * 0.6));
|
|
221
|
+
w.writeInt16(0);
|
|
222
|
+
w.writeInt16(Math.round(metrics.unitsPerEm * 0.4));
|
|
223
|
+
w.writeInt16(0);
|
|
224
|
+
w.writeInt16(Math.round(metrics.xHeight * 0.6));
|
|
225
|
+
w.writeInt16(0);
|
|
226
|
+
for (let i = 0; i < 10; i++) {
|
|
227
|
+
w.writeUint8(0);
|
|
228
|
+
}
|
|
229
|
+
w.writeUint32(1);
|
|
230
|
+
w.writeUint32(0);
|
|
231
|
+
w.writeUint32(0);
|
|
232
|
+
w.writeUint32(0);
|
|
233
|
+
w.writeString(" ", 4);
|
|
234
|
+
w.writeUint16(64);
|
|
235
|
+
w.writeUint16(32);
|
|
236
|
+
w.writeUint16(126);
|
|
237
|
+
w.writeInt16(metrics.ascent);
|
|
238
|
+
w.writeInt16(metrics.descent);
|
|
239
|
+
w.writeInt16(metrics.lineGap);
|
|
240
|
+
w.writeUint16(metrics.ascent);
|
|
241
|
+
w.writeUint16(Math.abs(metrics.descent));
|
|
242
|
+
w.writeUint32(1);
|
|
243
|
+
w.writeUint32(0);
|
|
244
|
+
w.writeInt16(metrics.xHeight);
|
|
245
|
+
w.writeInt16(metrics.capHeight);
|
|
246
|
+
w.writeUint16(0);
|
|
247
|
+
w.writeUint16(32);
|
|
248
|
+
w.writeUint16(1);
|
|
249
|
+
w.padTo4();
|
|
250
|
+
tableData.set("OS/2", { offset: os2Start, length: w.getSize() - os2Start });
|
|
251
|
+
const nameStart = w.getSize();
|
|
252
|
+
const nameStrings = [
|
|
253
|
+
{ nameID: 0, str: `Copyright 2024 ${name}` },
|
|
254
|
+
{ nameID: 1, str: fontData.family },
|
|
255
|
+
{ nameID: 2, str: "Regular" },
|
|
256
|
+
{ nameID: 3, str: `${name}-Regular` },
|
|
257
|
+
{ nameID: 4, str: `${name} Regular` },
|
|
258
|
+
{ nameID: 5, str: "Version 1.0" },
|
|
259
|
+
{ nameID: 6, str: `${name}-Regular` }
|
|
260
|
+
];
|
|
261
|
+
w.writeUint16(0);
|
|
262
|
+
w.writeUint16(nameStrings.length);
|
|
263
|
+
const nameStorageOffset = 6 + nameStrings.length * 12;
|
|
264
|
+
w.writeUint16(nameStorageOffset);
|
|
265
|
+
let strOffset = 0;
|
|
266
|
+
for (const ns of nameStrings) {
|
|
267
|
+
w.writeUint16(1);
|
|
268
|
+
w.writeUint16(0);
|
|
269
|
+
w.writeUint16(0);
|
|
270
|
+
w.writeUint16(ns.nameID);
|
|
271
|
+
w.writeUint16(ns.str.length);
|
|
272
|
+
w.writeUint16(strOffset);
|
|
273
|
+
strOffset += ns.str.length;
|
|
274
|
+
}
|
|
275
|
+
for (const ns of nameStrings) {
|
|
276
|
+
w.writeString(ns.str);
|
|
277
|
+
}
|
|
278
|
+
w.padTo4();
|
|
279
|
+
tableData.set("name", { offset: nameStart, length: w.getSize() - nameStart });
|
|
280
|
+
const cmapStart = w.getSize();
|
|
281
|
+
w.writeUint16(0);
|
|
282
|
+
w.writeUint16(1);
|
|
283
|
+
w.writeUint16(3);
|
|
284
|
+
w.writeUint16(1);
|
|
285
|
+
w.writeUint32(12);
|
|
286
|
+
const sortedGlyphs = [...glyphs].sort((a, b) => a.unicode - b.unicode);
|
|
287
|
+
const segCount = sortedGlyphs.length + 1;
|
|
288
|
+
const fmt4Size = 14 + segCount * 8;
|
|
289
|
+
w.writeUint16(4);
|
|
290
|
+
w.writeUint16(fmt4Size);
|
|
291
|
+
w.writeUint16(0);
|
|
292
|
+
w.writeUint16(segCount * 2);
|
|
293
|
+
const searchRange2 = Math.pow(2, Math.floor(Math.log2(segCount))) * 2;
|
|
294
|
+
w.writeUint16(searchRange2);
|
|
295
|
+
w.writeUint16(Math.floor(Math.log2(segCount)));
|
|
296
|
+
w.writeUint16(segCount * 2 - searchRange2);
|
|
297
|
+
for (const g of sortedGlyphs) {
|
|
298
|
+
w.writeUint16(g.unicode);
|
|
299
|
+
}
|
|
300
|
+
w.writeUint16(65535);
|
|
301
|
+
w.writeUint16(0);
|
|
302
|
+
for (const g of sortedGlyphs) {
|
|
303
|
+
w.writeUint16(g.unicode);
|
|
304
|
+
}
|
|
305
|
+
w.writeUint16(65535);
|
|
306
|
+
for (let i = 0; i < sortedGlyphs.length; i++) {
|
|
307
|
+
const delta = i + 1 - sortedGlyphs[i].unicode;
|
|
308
|
+
w.writeInt16(delta);
|
|
309
|
+
}
|
|
310
|
+
w.writeInt16(1);
|
|
311
|
+
for (let i = 0; i <= sortedGlyphs.length; i++) {
|
|
312
|
+
w.writeUint16(0);
|
|
313
|
+
}
|
|
314
|
+
w.padTo4();
|
|
315
|
+
tableData.set("cmap", { offset: cmapStart, length: w.getSize() - cmapStart });
|
|
316
|
+
const glyfStart = w.getSize();
|
|
317
|
+
const glyphOffsets = [0];
|
|
318
|
+
w.writeInt16(0);
|
|
319
|
+
w.writeInt16(0);
|
|
320
|
+
w.writeInt16(0);
|
|
321
|
+
w.writeInt16(0);
|
|
322
|
+
w.writeInt16(0);
|
|
323
|
+
for (let i = 0; i < glyphs.length; i++) {
|
|
324
|
+
glyphOffsets.push(w.getSize() - glyfStart);
|
|
360
325
|
w.writeInt16(0);
|
|
361
326
|
w.writeInt16(0);
|
|
362
327
|
w.writeInt16(0);
|
|
363
|
-
w.writeInt16(
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
w.writeInt16(50); // underlineThickness
|
|
389
|
-
w.writeUint32(0); // isFixedPitch
|
|
390
|
-
w.writeUint32(0); // minMemType42
|
|
391
|
-
w.writeUint32(0); // maxMemType42
|
|
392
|
-
w.writeUint32(0); // minMemType1
|
|
393
|
-
w.writeUint32(0); // maxMemType1
|
|
394
|
-
w.padTo4();
|
|
395
|
-
tableData.set('post', { offset: postStart, length: w.getSize() - postStart });
|
|
396
|
-
return w.toArrayBuffer();
|
|
328
|
+
w.writeInt16(Math.round(glyphs[i].advanceWidth));
|
|
329
|
+
w.writeInt16(metrics.ascent);
|
|
330
|
+
}
|
|
331
|
+
glyphOffsets.push(w.getSize() - glyfStart);
|
|
332
|
+
w.padTo4();
|
|
333
|
+
tableData.set("glyf", { offset: glyfStart, length: w.getSize() - glyfStart });
|
|
334
|
+
const locaStart = w.getSize();
|
|
335
|
+
for (const off of glyphOffsets) {
|
|
336
|
+
w.writeUint32(off);
|
|
337
|
+
}
|
|
338
|
+
w.padTo4();
|
|
339
|
+
tableData.set("loca", { offset: locaStart, length: w.getSize() - locaStart });
|
|
340
|
+
const postStart = w.getSize();
|
|
341
|
+
w.writeFixed(3);
|
|
342
|
+
w.writeFixed(0);
|
|
343
|
+
w.writeInt16(-100);
|
|
344
|
+
w.writeInt16(50);
|
|
345
|
+
w.writeUint32(0);
|
|
346
|
+
w.writeUint32(0);
|
|
347
|
+
w.writeUint32(0);
|
|
348
|
+
w.writeUint32(0);
|
|
349
|
+
w.writeUint32(0);
|
|
350
|
+
w.padTo4();
|
|
351
|
+
tableData.set("post", { offset: postStart, length: w.getSize() - postStart });
|
|
352
|
+
return w.toArrayBuffer();
|
|
397
353
|
}
|
|
398
|
-
/**
|
|
399
|
-
* Wrap TrueType data into WOFF format.
|
|
400
|
-
*/
|
|
401
354
|
function wrapWOFF(ttfData) {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
return w.toArrayBuffer();
|
|
355
|
+
const w = new BinaryWriter();
|
|
356
|
+
const ttf = new Uint8Array(ttfData);
|
|
357
|
+
w.writeUint32(tag("wOFF"));
|
|
358
|
+
w.writeUint32(65536);
|
|
359
|
+
w.writeUint32(0);
|
|
360
|
+
w.writeUint16(0);
|
|
361
|
+
w.writeUint16(0);
|
|
362
|
+
w.writeUint32(ttf.length);
|
|
363
|
+
w.writeUint16(1);
|
|
364
|
+
w.writeUint16(0);
|
|
365
|
+
w.writeUint32(0);
|
|
366
|
+
w.writeUint32(0);
|
|
367
|
+
w.writeUint32(0);
|
|
368
|
+
w.writeUint32(0);
|
|
369
|
+
w.writeUint32(0);
|
|
370
|
+
w.writeBytes(ttf);
|
|
371
|
+
return w.toArrayBuffer();
|
|
420
372
|
}
|
|
421
|
-
/**
|
|
422
|
-
* Download font file to user's device.
|
|
423
|
-
*/
|
|
424
373
|
function downloadFont(fontData, format, exportToSvgFont) {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
link.click();
|
|
448
|
-
URL.revokeObjectURL(url);
|
|
374
|
+
let blob;
|
|
375
|
+
let ext;
|
|
376
|
+
if (format === "svg" && exportToSvgFont) {
|
|
377
|
+
const svgStr = exportToSvgFont(fontData);
|
|
378
|
+
blob = new Blob([svgStr], { type: "image/svg+xml" });
|
|
379
|
+
ext = "svg";
|
|
380
|
+
} else if (format === "woff") {
|
|
381
|
+
const ttf = buildTTF(fontData);
|
|
382
|
+
const woff = wrapWOFF(ttf);
|
|
383
|
+
blob = new Blob([woff], { type: "font/woff" });
|
|
384
|
+
ext = "woff";
|
|
385
|
+
} else {
|
|
386
|
+
const ttf = buildTTF(fontData);
|
|
387
|
+
blob = new Blob([ttf], { type: "font/ttf" });
|
|
388
|
+
ext = "ttf";
|
|
389
|
+
}
|
|
390
|
+
const url = URL.createObjectURL(blob);
|
|
391
|
+
const link = document.createElement("a");
|
|
392
|
+
link.download = `${fontData.name || "font"}.${ext}`;
|
|
393
|
+
link.href = url;
|
|
394
|
+
link.click();
|
|
395
|
+
URL.revokeObjectURL(url);
|
|
449
396
|
}
|
|
450
|
-
/**
|
|
451
|
-
* Auto-generate kerning pairs based on glyph shapes.
|
|
452
|
-
* Uses heuristic: characters with diagonal strokes (A, V, W, Y) need negative kern
|
|
453
|
-
* against round/short characters.
|
|
454
|
-
*/
|
|
455
397
|
function autoKern(glyphs, metrics) {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
});
|
|
468
|
-
}
|
|
398
|
+
const pairs = [];
|
|
399
|
+
const scale = metrics.unitsPerEm / 1e3;
|
|
400
|
+
for (const commonPair of COMMON_KERNING_PAIRS) {
|
|
401
|
+
const leftExists = glyphs.some((g) => g.char === commonPair.left);
|
|
402
|
+
const rightExists = glyphs.some((g) => g.char === commonPair.right);
|
|
403
|
+
if (leftExists && rightExists) {
|
|
404
|
+
pairs.push({
|
|
405
|
+
left: commonPair.left,
|
|
406
|
+
right: commonPair.right,
|
|
407
|
+
value: Math.round(commonPair.value * scale)
|
|
408
|
+
});
|
|
469
409
|
}
|
|
470
|
-
|
|
410
|
+
}
|
|
411
|
+
return pairs;
|
|
471
412
|
}
|
|
472
|
-
|
|
473
|
-
|
|
413
|
+
export {
|
|
414
|
+
COMMON_KERNING_PAIRS,
|
|
415
|
+
OPENTYPE_FEATURE_PRESETS,
|
|
416
|
+
autoKern,
|
|
417
|
+
buildTTF,
|
|
418
|
+
downloadFont,
|
|
419
|
+
wrapWOFF
|
|
420
|
+
};
|