react-native-nano-icons 0.2.0 → 1.0.0-beta.1
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/LICENSES.md +40 -0
- package/README.md +41 -10
- package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +31 -0
- package/android/src/main/java/com/nanoicons/NanoIconView.kt +50 -15
- package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +78 -12
- package/ios/NanoIconFontResolver.h +5 -0
- package/ios/NanoIconFontResolver.mm +32 -0
- package/ios/NanoIconView.h +0 -4
- package/ios/NanoIconView.mm +62 -57
- package/ios/NanoIconsFontLoader.mm +10 -32
- package/lib/commonjs/cli/build.d.ts +11 -3
- package/lib/commonjs/cli/build.js +86 -25
- package/lib/commonjs/cli/config.d.ts +1 -1
- package/lib/commonjs/cli/config.js +1 -1
- package/lib/commonjs/cli/expoConfig.d.ts +3 -2
- package/lib/commonjs/cli/expoConfig.js +22 -9
- package/lib/commonjs/cli/index.d.ts +5 -5
- package/lib/commonjs/cli/index.js +16 -14
- package/lib/commonjs/cli/link.d.ts +4 -3
- package/lib/commonjs/cli/link.js +127 -45
- package/lib/commonjs/cli/logger.js +9 -7
- package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -3
- package/lib/commonjs/plugin/src/buildFonts.js +5 -15
- package/lib/commonjs/plugin/src/index.d.ts +2 -2
- package/lib/commonjs/plugin/src/index.js +2 -2
- package/lib/commonjs/plugin/src/types.d.ts +10 -1
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +1 -1
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +6 -13
- package/lib/commonjs/scripts/cli.js +46 -23
- package/lib/commonjs/src/core/flatten/arcs.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/arcs.js +136 -0
- package/lib/commonjs/src/core/flatten/document.d.ts +35 -0
- package/lib/commonjs/src/core/flatten/document.js +164 -0
- package/lib/commonjs/src/core/flatten/dom.d.ts +24 -0
- package/lib/commonjs/src/core/flatten/dom.js +221 -0
- package/lib/commonjs/src/core/flatten/element.d.ts +12 -0
- package/lib/commonjs/src/core/flatten/element.js +97 -0
- package/lib/commonjs/src/core/flatten/geometry.d.ts +21 -0
- package/lib/commonjs/src/core/flatten/geometry.js +85 -0
- package/lib/commonjs/src/core/flatten/index.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/index.js +11 -0
- package/lib/commonjs/src/core/flatten/inherit.d.ts +13 -0
- package/lib/commonjs/src/core/flatten/inherit.js +249 -0
- package/lib/commonjs/src/core/flatten/path.d.ts +19 -0
- package/lib/commonjs/src/core/flatten/path.js +439 -0
- package/lib/commonjs/src/core/flatten/pathops.d.ts +14 -0
- package/lib/commonjs/src/core/flatten/pathops.js +236 -0
- package/lib/commonjs/src/core/flatten/shape.d.ts +29 -0
- package/lib/commonjs/src/core/flatten/shape.js +415 -0
- package/lib/commonjs/src/core/flatten/stages/clip-path.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/clip-path.js +20 -0
- package/lib/commonjs/src/core/flatten/stages/collapse.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/collapse.js +86 -0
- package/lib/commonjs/src/core/flatten/stages/defs.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/defs.js +49 -0
- package/lib/commonjs/src/core/flatten/stages/discard.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/discard.js +50 -0
- package/lib/commonjs/src/core/flatten/stages/fill-rule.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/fill-rule.js +7 -0
- package/lib/commonjs/src/core/flatten/stages/nested-svg.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/nested-svg.js +131 -0
- package/lib/commonjs/src/core/flatten/stages/opacity.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/opacity.js +7 -0
- package/lib/commonjs/src/core/flatten/stages/shapes.d.ts +7 -0
- package/lib/commonjs/src/core/flatten/stages/shapes.js +37 -0
- package/lib/commonjs/src/core/flatten/stages/stroke.d.ts +3 -0
- package/lib/commonjs/src/core/flatten/stages/stroke.js +34 -0
- package/lib/commonjs/src/core/flatten/stages/styles.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/styles.js +29 -0
- package/lib/commonjs/src/core/flatten/stages/use.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/use.js +80 -0
- package/lib/commonjs/src/core/flatten/stages/validate.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/validate.js +39 -0
- package/lib/commonjs/src/core/flatten/stages.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages.js +40 -0
- package/lib/commonjs/src/core/flatten/transform.d.ts +35 -0
- package/lib/commonjs/src/core/flatten/transform.js +221 -0
- package/lib/commonjs/src/core/font/compile.d.ts +2 -1
- package/lib/commonjs/src/core/font/compile.js +21 -7
- package/lib/commonjs/src/core/font/metrics.js +7 -0
- package/lib/commonjs/src/core/font/quadratic.d.ts +1 -0
- package/lib/commonjs/src/core/font/quadratic.js +31 -0
- package/lib/commonjs/src/core/glyph/merge.d.ts +7 -0
- package/lib/commonjs/src/core/glyph/merge.js +57 -0
- package/lib/commonjs/src/core/glyph/parse.d.ts +26 -0
- package/lib/commonjs/src/core/{svg/svg_dom.js → glyph/parse.js} +21 -77
- package/lib/commonjs/src/core/{svg/layers.d.ts → glyph/placement.d.ts} +1 -13
- package/lib/commonjs/src/core/{svg/layers.js → glyph/placement.js} +0 -17
- package/lib/commonjs/src/core/glyph/validate.d.ts +8 -0
- package/lib/commonjs/src/core/glyph/validate.js +33 -0
- package/lib/commonjs/src/core/pathkit/contours.d.ts +74 -0
- package/lib/commonjs/src/core/{svg/svg_pathops.js → pathkit/contours.js} +72 -312
- package/lib/commonjs/src/core/pathkit/evenodd.d.ts +12 -0
- package/lib/commonjs/src/core/pathkit/evenodd.js +51 -0
- package/lib/commonjs/src/core/pathkit/load.d.ts +2 -0
- package/lib/commonjs/src/core/pathkit/load.js +26 -0
- package/lib/commonjs/src/core/pathkit/types.d.ts +69 -0
- package/lib/commonjs/src/core/pathkit/types.js +2 -0
- package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/iconPool.d.ts +3 -0
- package/lib/commonjs/src/core/pipeline/iconPool.js +51 -0
- package/lib/commonjs/src/core/pipeline/index.d.ts +3 -3
- package/lib/commonjs/src/core/pipeline/index.js +6 -5
- package/lib/commonjs/src/core/pipeline/prepare.d.ts +19 -0
- package/lib/commonjs/src/core/pipeline/prepare.js +56 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +22 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.js +78 -0
- package/lib/commonjs/src/core/pipeline/prepareWorker.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/prepareWorker.js +12 -0
- package/lib/commonjs/src/core/pipeline/{run.d.ts → runFontPipeline.d.ts} +7 -4
- package/lib/commonjs/src/core/pipeline/runFontPipeline.js +109 -0
- package/lib/commonjs/src/core/types.d.ts +3 -92
- package/lib/commonjs/src/utils/fingerPrint.d.ts +8 -1
- package/lib/commonjs/src/utils/fingerPrint.js +8 -1
- package/lib/commonjs/src/utils/fontIdentity.d.ts +4 -0
- package/lib/commonjs/src/utils/fontIdentity.js +24 -0
- package/lib/commonjs/src/utils/packageVersion.d.ts +2 -0
- package/lib/commonjs/src/utils/packageVersion.js +37 -0
- package/lib/commonjs/src/utils/parse.d.ts +0 -1
- package/lib/commonjs/src/utils/parse.js +0 -8
- package/lib/commonjs/src/utils/svgPatterns.d.ts +38 -0
- package/lib/commonjs/src/utils/svgPatterns.js +46 -0
- package/lib/module/const/codegenPrimitives.js +1 -2
- package/lib/module/const/colors.js +1 -2
- package/lib/module/createNanoIconsSet.js +1 -2
- package/lib/module/createNanoIconsSet.native.js +11 -4
- package/lib/module/createNanoIconsSet.shared.js +12 -7
- package/lib/module/createNanoIconsSet.web.js +7 -5
- package/lib/module/fontIntegrity.js +99 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.node.js +1 -2
- package/lib/module/loadDynamicFont.js +14 -7
- package/lib/module/nativeFontLoader.js +3 -0
- package/lib/module/nativeFontLoader.web.js +3 -0
- package/lib/module/specs/NativeNanoIconsFontLoader.js +1 -2
- package/lib/module/types.js +1 -2
- package/lib/module/utils/fingerPrint.js +3 -3
- package/lib/module/utils/fontIdentity.js +20 -0
- package/lib/module/utils/glyphRuntime.js +1 -2
- package/lib/module/utils/packageVersion.js +29 -0
- package/lib/module/utils/parse.js +1 -9
- package/lib/module/utils/runtimeLog.js +12 -0
- package/lib/module/utils/shallowEqualColor.js +1 -2
- package/lib/module/utils/svgPatterns.js +49 -0
- package/lib/typescript/src/core/flatten/arcs.d.ts +3 -0
- package/lib/typescript/src/core/flatten/document.d.ts +36 -0
- package/lib/typescript/src/core/flatten/dom.d.ts +25 -0
- package/lib/typescript/src/core/flatten/element.d.ts +13 -0
- package/lib/typescript/src/core/flatten/geometry.d.ts +22 -0
- package/lib/typescript/src/core/flatten/index.d.ts +3 -0
- package/lib/typescript/src/core/flatten/inherit.d.ts +14 -0
- package/lib/typescript/src/core/flatten/path.d.ts +20 -0
- package/lib/typescript/src/core/flatten/pathops.d.ts +15 -0
- package/lib/typescript/src/core/flatten/shape.d.ts +30 -0
- package/lib/typescript/src/core/flatten/stages/clip-path.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/collapse.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/defs.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/discard.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/fill-rule.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/nested-svg.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/opacity.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/shapes.d.ts +8 -0
- package/lib/typescript/src/core/flatten/stages/stroke.d.ts +4 -0
- package/lib/typescript/src/core/flatten/stages/styles.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/use.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/validate.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages.d.ts +3 -0
- package/lib/typescript/src/core/flatten/transform.d.ts +36 -0
- package/lib/typescript/src/core/glyph/merge.d.ts +8 -0
- package/lib/typescript/src/core/glyph/parse.d.ts +27 -0
- package/lib/typescript/src/core/{svg/layers.d.ts → glyph/placement.d.ts} +2 -14
- package/lib/typescript/src/core/glyph/validate.d.ts +9 -0
- package/lib/typescript/src/core/pathkit/contours.d.ts +75 -0
- package/lib/typescript/src/core/pathkit/evenodd.d.ts +13 -0
- package/lib/typescript/src/core/pathkit/load.d.ts +3 -0
- package/lib/typescript/src/core/pathkit/types.d.ts +70 -0
- package/lib/typescript/src/core/types.d.ts +3 -92
- package/lib/typescript/src/fontIntegrity.d.ts +24 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/nativeFontLoader.d.ts +2 -0
- package/lib/typescript/src/nativeFontLoader.web.d.ts +3 -0
- package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
- package/lib/typescript/src/types.d.ts +5 -0
- package/lib/typescript/src/utils/fingerPrint.d.ts +8 -1
- package/lib/typescript/src/utils/fontIdentity.d.ts +5 -0
- package/lib/typescript/src/utils/packageVersion.d.ts +3 -0
- package/lib/typescript/src/utils/parse.d.ts +0 -1
- package/lib/typescript/src/utils/runtimeLog.d.ts +5 -0
- package/lib/typescript/src/utils/svgPatterns.d.ts +39 -0
- package/package.json +13 -11
- package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
- package/lib/commonjs/src/core/pipeline/managers.d.ts +0 -11
- package/lib/commonjs/src/core/pipeline/managers.js +0 -104
- package/lib/commonjs/src/core/pipeline/run.js +0 -189
- package/lib/commonjs/src/core/svg/svg_dom.d.ts +0 -51
- package/lib/commonjs/src/core/svg/svg_pathops.d.ts +0 -32
- package/lib/module/const/codegenPrimitives.js.map +0 -1
- package/lib/module/const/colors.js.map +0 -1
- package/lib/module/core/font/compile.js +0 -81
- package/lib/module/core/font/compile.js.map +0 -1
- package/lib/module/core/font/metrics.js +0 -37
- package/lib/module/core/font/metrics.js.map +0 -1
- package/lib/module/core/pipeline/config.js +0 -20
- package/lib/module/core/pipeline/config.js.map +0 -1
- package/lib/module/core/pipeline/index.js +0 -5
- package/lib/module/core/pipeline/index.js.map +0 -1
- package/lib/module/core/pipeline/managers.js +0 -94
- package/lib/module/core/pipeline/managers.js.map +0 -1
- package/lib/module/core/pipeline/run.js +0 -204
- package/lib/module/core/pipeline/run.js.map +0 -1
- package/lib/module/core/shims/pathops.py +0 -181
- package/lib/module/core/shims/picosvg-0.22.3-py3-none-any.whl +0 -0
- package/lib/module/core/svg/layers.js +0 -85
- package/lib/module/core/svg/layers.js.map +0 -1
- package/lib/module/core/svg/svg_dom.js +0 -170
- package/lib/module/core/svg/svg_dom.js.map +0 -1
- package/lib/module/core/svg/svg_pathops.js +0 -750
- package/lib/module/core/svg/svg_pathops.js.map +0 -1
- package/lib/module/core/tsconfig.json +0 -32
- package/lib/module/core/types.js +0 -2
- package/lib/module/core/types.js.map +0 -1
- package/lib/module/createNanoIconsSet.js.map +0 -1
- package/lib/module/createNanoIconsSet.native.js.map +0 -1
- package/lib/module/createNanoIconsSet.shared.js.map +0 -1
- package/lib/module/createNanoIconsSet.web.js.map +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/module/index.node.js.map +0 -1
- package/lib/module/loadDynamicFont.js.map +0 -1
- package/lib/module/specs/NativeNanoIconsFontLoader.js.map +0 -1
- package/lib/module/types.js.map +0 -1
- package/lib/module/utils/fingerPrint.js.map +0 -1
- package/lib/module/utils/glyphRuntime.js.map +0 -1
- package/lib/module/utils/parse.js.map +0 -1
- package/lib/module/utils/shallowEqualColor.js.map +0 -1
- package/lib/typescript/__tests__/build.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/build.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/clippath.e2e.test.d.ts +0 -3
- package/lib/typescript/__tests__/clippath.e2e.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/fingerprint.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/fingerprint.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/glyphRuntime.unit.test.d.ts +0 -2
- package/lib/typescript/__tests__/glyphRuntime.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/link.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/link.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/loadDynamicFont.unit.test.d.ts +0 -2
- package/lib/typescript/__tests__/loadDynamicFont.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/pipeline.e2e.test.d.ts +0 -3
- package/lib/typescript/__tests__/pipeline.e2e.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/placement.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/placement.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/svg_dom.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/svg_dom.unit.test.d.ts.map +0 -1
- package/lib/typescript/cli/build.d.ts +0 -32
- package/lib/typescript/cli/build.d.ts.map +0 -1
- package/lib/typescript/cli/link.d.ts +0 -12
- package/lib/typescript/cli/link.d.ts.map +0 -1
- package/lib/typescript/cli/logger.d.ts +0 -28
- package/lib/typescript/cli/logger.d.ts.map +0 -1
- package/lib/typescript/src/const/codegenPrimitives.d.ts.map +0 -1
- package/lib/typescript/src/const/colors.d.ts.map +0 -1
- package/lib/typescript/src/core/font/compile.d.ts +0 -21
- package/lib/typescript/src/core/font/compile.d.ts.map +0 -1
- package/lib/typescript/src/core/font/metrics.d.ts +0 -2
- package/lib/typescript/src/core/font/metrics.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/config.d.ts +0 -16
- package/lib/typescript/src/core/pipeline/config.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/index.d.ts +0 -4
- package/lib/typescript/src/core/pipeline/index.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/managers.d.ts +0 -12
- package/lib/typescript/src/core/pipeline/managers.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/run.d.ts +0 -15
- package/lib/typescript/src/core/pipeline/run.d.ts.map +0 -1
- package/lib/typescript/src/core/svg/layers.d.ts.map +0 -1
- package/lib/typescript/src/core/svg/svg_dom.d.ts +0 -52
- package/lib/typescript/src/core/svg/svg_dom.d.ts.map +0 -1
- package/lib/typescript/src/core/svg/svg_pathops.d.ts +0 -33
- package/lib/typescript/src/core/svg/svg_pathops.d.ts.map +0 -1
- package/lib/typescript/src/core/types.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.native.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.shared.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.web.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/lib/typescript/src/index.node.d.ts.map +0 -1
- package/lib/typescript/src/loadDynamicFont.d.ts.map +0 -1
- package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts.map +0 -1
- package/lib/typescript/src/types.d.ts.map +0 -1
- package/lib/typescript/src/utils/fingerPrint.d.ts.map +0 -1
- package/lib/typescript/src/utils/glyphRuntime.d.ts.map +0 -1
- package/lib/typescript/src/utils/parse.d.ts.map +0 -1
- package/lib/typescript/src/utils/shallowEqualColor.d.ts.map +0 -1
- package/plugin/src/buildFonts.ts +0 -42
- package/plugin/src/index.ts +0 -21
- package/plugin/src/types.ts +0 -42
- package/plugin/src/withNanoIconsFontLinking.ts +0 -136
- package/plugin/tsconfig.json +0 -9
- package/scripts/cli.ts +0 -63
- package/scripts/tsconfig.json +0 -25
- package/src/const/colors.ts +0 -150
- package/src/core/font/compile.ts +0 -99
- package/src/core/font/metrics.ts +0 -44
- package/src/core/pipeline/config.ts +0 -25
- package/src/core/pipeline/index.ts +0 -3
- package/src/core/pipeline/managers.ts +0 -132
- package/src/core/pipeline/run.ts +0 -274
- package/src/core/shims/pathops.py +0 -181
- package/src/core/shims/picosvg-0.22.3-py3-none-any.whl +0 -0
- package/src/core/svg/layers.ts +0 -110
- package/src/core/svg/svg_dom.ts +0 -194
- package/src/core/svg/svg_pathops.ts +0 -1040
- package/src/core/tsconfig.json +0 -32
- package/src/core/types.ts +0 -157
- package/src/createNanoIconsSet.native.tsx +0 -192
- package/src/createNanoIconsSet.shared.tsx +0 -174
- package/src/createNanoIconsSet.tsx +0 -20
- package/src/createNanoIconsSet.web.tsx +0 -109
- package/src/index.node.ts +0 -14
- package/src/index.ts +0 -6
- package/src/loadDynamicFont.ts +0 -162
- package/src/types.ts +0 -31
- package/src/utils/fingerPrint.ts +0 -20
- package/src/utils/glyphRuntime.ts +0 -46
- package/src/utils/parse.ts +0 -67
- package/src/utils/shallowEqualColor.ts +0 -17
package/src/core/font/compile.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
import { forceTtfMetrics } from './metrics.js';
|
|
5
|
-
import svg2ttf from 'svg2ttf';
|
|
6
|
-
|
|
7
|
-
export type FontGlyph = {
|
|
8
|
-
codepoint: number;
|
|
9
|
-
advanceWidth: number;
|
|
10
|
-
/** Path data already in font coordinates (Y-up, placement applied). */
|
|
11
|
-
d: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
function escapeXml(s: string): string {
|
|
15
|
-
return s.replace(/&/g, '&').replace(/"/g, '"');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Build an SVG font XML string from pre-transformed glyph data.
|
|
20
|
-
*/
|
|
21
|
-
function buildSvgFontXml(opts: {
|
|
22
|
-
fontName: string;
|
|
23
|
-
glyphs: FontGlyph[];
|
|
24
|
-
upm: number;
|
|
25
|
-
ascent: number;
|
|
26
|
-
descent: number;
|
|
27
|
-
}): string {
|
|
28
|
-
const { fontName, glyphs, upm, ascent, descent } = opts;
|
|
29
|
-
|
|
30
|
-
const glyphLines = glyphs.map((g) => {
|
|
31
|
-
const hex = g.codepoint.toString(16);
|
|
32
|
-
const name = `u${hex.padStart(4, '0')}`;
|
|
33
|
-
return `<glyph glyph-name="${name}" unicode="&#x${hex};" horiz-adv-x="${g.advanceWidth}" d="${escapeXml(g.d)}"/>`;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
return `<?xml version="1.0" standalone="no"?>
|
|
37
|
-
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
38
|
-
<svg xmlns="http://www.w3.org/2000/svg">
|
|
39
|
-
<defs>
|
|
40
|
-
<font id="${escapeXml(fontName)}" horiz-adv-x="${upm}">
|
|
41
|
-
<font-face font-family="${escapeXml(fontName)}" units-per-em="${upm}" ascent="${ascent}" descent="${-Math.abs(descent)}"/>
|
|
42
|
-
<missing-glyph horiz-adv-x="0"/>
|
|
43
|
-
${glyphLines.join('\n')}
|
|
44
|
-
</font>
|
|
45
|
-
</defs>
|
|
46
|
-
</svg>`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function parseCompileTtfFromGlyphsError(
|
|
50
|
-
err: unknown,
|
|
51
|
-
codepointToIcon: Map<number, string>
|
|
52
|
-
) {
|
|
53
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
54
|
-
const cpMatch = msg.match(/glyph\s+"u([0-9a-fA-F]+)"/);
|
|
55
|
-
if (cpMatch) {
|
|
56
|
-
const cp = parseInt(cpMatch[1]!, 16);
|
|
57
|
-
const iconName = codepointToIcon.get(cp);
|
|
58
|
-
const detail = iconName
|
|
59
|
-
? `icon "${iconName}" (codepoint u${cpMatch[1]})`
|
|
60
|
-
: `codepoint u${cpMatch[1]}`;
|
|
61
|
-
throw new Error(`Font compilation failed for ${detail}: ${msg}`);
|
|
62
|
-
}
|
|
63
|
-
throw err;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Compile a TTF font from pre-transformed glyph data.
|
|
68
|
-
* Builds SVG font XML directly (no intermediate files), then converts via svg2ttf.
|
|
69
|
-
*/
|
|
70
|
-
export async function compileTtfFromGlyphs(opts: {
|
|
71
|
-
glyphs: FontGlyph[];
|
|
72
|
-
outTtfPath: string;
|
|
73
|
-
fontName: string;
|
|
74
|
-
upm: number;
|
|
75
|
-
ascent: number;
|
|
76
|
-
descent: number;
|
|
77
|
-
lineGap?: number;
|
|
78
|
-
}): Promise<void> {
|
|
79
|
-
const { glyphs, outTtfPath, fontName, upm, ascent, descent } = opts;
|
|
80
|
-
const lineGap = opts.lineGap ?? 0;
|
|
81
|
-
|
|
82
|
-
if (glyphs.length === 0) throw new Error('No glyphs to compile');
|
|
83
|
-
|
|
84
|
-
const svgFontString = buildSvgFontXml({
|
|
85
|
-
fontName,
|
|
86
|
-
glyphs,
|
|
87
|
-
upm,
|
|
88
|
-
ascent,
|
|
89
|
-
descent,
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
const ttfRaw = svg2ttf(svgFontString);
|
|
93
|
-
const rawBuf = Buffer.from(ttfRaw.buffer);
|
|
94
|
-
|
|
95
|
-
const fixedBuf = forceTtfMetrics(rawBuf, upm, ascent, descent, lineGap);
|
|
96
|
-
|
|
97
|
-
fs.mkdirSync(path.dirname(outTtfPath), { recursive: true });
|
|
98
|
-
fs.writeFileSync(outTtfPath, fixedBuf);
|
|
99
|
-
}
|
package/src/core/font/metrics.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Font } from 'fonteditor-core';
|
|
2
|
-
|
|
3
|
-
export function forceTtfMetrics(
|
|
4
|
-
ttfBuffer: Buffer,
|
|
5
|
-
upm: number,
|
|
6
|
-
ascent: number,
|
|
7
|
-
descent: number,
|
|
8
|
-
lineGap: number
|
|
9
|
-
): Buffer {
|
|
10
|
-
const font = Font.create(ttfBuffer, {
|
|
11
|
-
type: 'ttf',
|
|
12
|
-
hinting: false,
|
|
13
|
-
compound2simple: false,
|
|
14
|
-
combinePath: false,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const data = font.get();
|
|
18
|
-
|
|
19
|
-
data.head.unitsPerEm = upm;
|
|
20
|
-
|
|
21
|
-
data.hhea.ascent = ascent;
|
|
22
|
-
data.hhea.descent = -Math.abs(descent);
|
|
23
|
-
data.hhea.lineGap = lineGap;
|
|
24
|
-
|
|
25
|
-
data['OS/2'].usWinAscent = ascent;
|
|
26
|
-
data['OS/2'].usWinDescent = Math.abs(descent);
|
|
27
|
-
data['OS/2'].sTypoAscender = ascent;
|
|
28
|
-
data['OS/2'].sTypoDescender = -Math.abs(descent);
|
|
29
|
-
data['OS/2'].sTypoLineGap = lineGap;
|
|
30
|
-
|
|
31
|
-
// Set USE_TYPO_METRICS flag (bit 7) in fsSelection.
|
|
32
|
-
// This tells renderers to use sTypoAscender/sTypoDescender/sTypoLineGap for
|
|
33
|
-
// line height calculations instead of the Win metrics (usWinAscent/usWinDescent).
|
|
34
|
-
// Without this flag, Windows and some Android renderers ignore the Typo values
|
|
35
|
-
// set above and fall back to Win metrics, causing icons to appear clipped or
|
|
36
|
-
// misaligned vertically. The bitwise OR preserves all other existing style flags
|
|
37
|
-
// (italic, bold, etc.) while ensuring this bit is always on.
|
|
38
|
-
data['OS/2'].fsSelection = (data['OS/2'].fsSelection || 0) | (1 << 7);
|
|
39
|
-
|
|
40
|
-
font.set(data);
|
|
41
|
-
|
|
42
|
-
const out = font.write({ type: 'ttf', hinting: false }) as ArrayBuffer;
|
|
43
|
-
return Buffer.from(out);
|
|
44
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
|
|
3
|
-
export type PipelineConfig = {
|
|
4
|
-
fontFamily: string;
|
|
5
|
-
upm: number;
|
|
6
|
-
safeZone: number;
|
|
7
|
-
startUnicode: number;
|
|
8
|
-
linking: 'static' | 'dynamic';
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type PipelinePaths = {
|
|
12
|
-
inputDir: string;
|
|
13
|
-
outputDir: string;
|
|
14
|
-
tempDir: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export function ensureEmptyDir(dir: string): void {
|
|
18
|
-
if (fs.existsSync(dir)) fs.rmSync(dir, { recursive: true, force: true });
|
|
19
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Create directory if it does not exist; do not remove existing contents (for shared output dirs). */
|
|
23
|
-
export function ensureDir(dir: string): void {
|
|
24
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
25
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { loadPyodide } from 'pyodide';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import fs from 'node:fs/promises';
|
|
4
|
-
import type { PathKitModule, PyodideModule } from '../types.js';
|
|
5
|
-
import { buildPathopsBackend } from '../svg/svg_pathops.js';
|
|
6
|
-
|
|
7
|
-
/** Package root (where package.json lives). */
|
|
8
|
-
function getPackageRoot(): string {
|
|
9
|
-
// Compiled to lib/commonjs/src/core/pipeline/ — 5 dirs up is package root.
|
|
10
|
-
// Running from source (Jest/ts-node) in src/core/pipeline/ — 3 dirs up is package root.
|
|
11
|
-
return __dirname.includes(`${path.sep}lib${path.sep}`)
|
|
12
|
-
? path.resolve(__dirname, '../../../../..')
|
|
13
|
-
: path.resolve(__dirname, '../../..');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class PathKitManager {
|
|
17
|
-
private static instance: PathKitModule | null = null;
|
|
18
|
-
|
|
19
|
-
static async getInstance(): Promise<PathKitModule> {
|
|
20
|
-
if (this.instance) return this.instance;
|
|
21
|
-
|
|
22
|
-
const PathKitInit = require('pathkit-wasm/bin/pathkit.js') as (
|
|
23
|
-
opts: unknown
|
|
24
|
-
) => any;
|
|
25
|
-
const pathkitJsPath =
|
|
26
|
-
require.resolve('pathkit-wasm/bin/pathkit.js') as string;
|
|
27
|
-
const pathkitBinDir = path.dirname(pathkitJsPath);
|
|
28
|
-
const pathkitWasmPath = path.join(pathkitBinDir, 'pathkit.wasm');
|
|
29
|
-
|
|
30
|
-
const wasmBinary = await fs.readFile(pathkitWasmPath);
|
|
31
|
-
|
|
32
|
-
const pkInit = PathKitInit({
|
|
33
|
-
wasmBinary,
|
|
34
|
-
locateFile: (file: string) => path.join(pathkitBinDir, file),
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const PathKit: PathKitModule = await (typeof pkInit?.ready === 'function'
|
|
38
|
-
? pkInit.ready()
|
|
39
|
-
: pkInit);
|
|
40
|
-
this.instance = PathKit;
|
|
41
|
-
return PathKit;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export class PyodideManager {
|
|
46
|
-
private static instance: PyodideModule | null = null;
|
|
47
|
-
|
|
48
|
-
static async getInstance(): Promise<PyodideModule> {
|
|
49
|
-
if (this.instance) return this.instance;
|
|
50
|
-
|
|
51
|
-
const pyodideAsmPath = require.resolve('pyodide/pyodide.asm.js') as string;
|
|
52
|
-
const pyodideDir = path.dirname(pyodideAsmPath) + path.sep;
|
|
53
|
-
|
|
54
|
-
const py = (await loadPyodide({
|
|
55
|
-
indexURL: pyodideDir,
|
|
56
|
-
})) as unknown as PyodideModule;
|
|
57
|
-
py.mountNodeFS('/app', process.cwd());
|
|
58
|
-
|
|
59
|
-
const PathKit = await PathKitManager.getInstance();
|
|
60
|
-
py.registerJsModule('_pathops_js', buildPathopsBackend(PathKit));
|
|
61
|
-
|
|
62
|
-
const pathopsPyPath = path.join(
|
|
63
|
-
getPackageRoot(),
|
|
64
|
-
'src',
|
|
65
|
-
'core',
|
|
66
|
-
'shims',
|
|
67
|
-
'pathops.py'
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
const pathopsPy = await fs.readFile(pathopsPyPath, 'utf8');
|
|
71
|
-
py.FS.writeFile('/pathops.py', pathopsPy);
|
|
72
|
-
|
|
73
|
-
await py.loadPackage(['micropip', 'lxml'], { messageCallback: () => {} });
|
|
74
|
-
|
|
75
|
-
// Resolve local picosvg wheel path for offline-first installation.
|
|
76
|
-
const picosvgWhlDir = path.join(getPackageRoot(), 'src', 'core', 'shims');
|
|
77
|
-
const picosvgWhl = (await fs.readdir(picosvgWhlDir)).find(
|
|
78
|
-
(f) => f.startsWith('picosvg-') && f.endsWith('.whl')
|
|
79
|
-
);
|
|
80
|
-
const localWhlUrl = picosvgWhl
|
|
81
|
-
? `file://${path.join(picosvgWhlDir, picosvgWhl)}`
|
|
82
|
-
: null;
|
|
83
|
-
|
|
84
|
-
py.globals.set('_picosvg_local_whl', localWhlUrl);
|
|
85
|
-
|
|
86
|
-
await py.runPythonAsync(`
|
|
87
|
-
import sys
|
|
88
|
-
if "/" not in sys.path:
|
|
89
|
-
sys.path.insert(0, "/")
|
|
90
|
-
|
|
91
|
-
import micropip
|
|
92
|
-
|
|
93
|
-
_whl = _picosvg_local_whl
|
|
94
|
-
if _whl:
|
|
95
|
-
try:
|
|
96
|
-
await micropip.install(_whl, deps=False)
|
|
97
|
-
except Exception:
|
|
98
|
-
await micropip.install("picosvg", deps=False)
|
|
99
|
-
else:
|
|
100
|
-
await micropip.install("picosvg", deps=False)
|
|
101
|
-
|
|
102
|
-
import pathops
|
|
103
|
-
import picosvg
|
|
104
|
-
`);
|
|
105
|
-
|
|
106
|
-
this.instance = py;
|
|
107
|
-
return py;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
static async picoFromFile(
|
|
111
|
-
hostFilePath: string,
|
|
112
|
-
content?: string
|
|
113
|
-
): Promise<string> {
|
|
114
|
-
const py = await this.getInstance();
|
|
115
|
-
const svgContent = content ?? (await fs.readFile(hostFilePath, 'utf-8'));
|
|
116
|
-
py.globals.set('_svg_content', svgContent);
|
|
117
|
-
const out = py.runPython(`
|
|
118
|
-
from picosvg.svg import SVG
|
|
119
|
-
svg = SVG.fromstring(_svg_content)
|
|
120
|
-
pico = svg.topicosvg()
|
|
121
|
-
pico.tostring(pretty_print=True)
|
|
122
|
-
`);
|
|
123
|
-
return out;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export async function picoFromFile(
|
|
128
|
-
hostFilePath: string,
|
|
129
|
-
content?: string
|
|
130
|
-
): Promise<string> {
|
|
131
|
-
return PyodideManager.picoFromFile(hostFilePath, content);
|
|
132
|
-
}
|
package/src/core/pipeline/run.ts
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
import fsp from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
compileTtfFromGlyphs,
|
|
6
|
-
parseCompileTtfFromGlyphsError,
|
|
7
|
-
type FontGlyph,
|
|
8
|
-
} from '../font/compile.js';
|
|
9
|
-
import { picoFromFile, PathKitManager } from './managers.js';
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
ensureDir,
|
|
13
|
-
type PipelineConfig,
|
|
14
|
-
type PipelinePaths,
|
|
15
|
-
} from './config.js';
|
|
16
|
-
import {
|
|
17
|
-
parseFlattenedSvg,
|
|
18
|
-
preprocessSvg,
|
|
19
|
-
shouldSkipPath,
|
|
20
|
-
validateSvg,
|
|
21
|
-
extractOriginalEvenoddDs,
|
|
22
|
-
restoreOriginalEvenoddDs,
|
|
23
|
-
} from '../svg/svg_dom.js';
|
|
24
|
-
import { computePlacement, transformPathForFont } from '../svg/layers.js';
|
|
25
|
-
import { convertEvenoddToWinding } from '../svg/svg_pathops.js';
|
|
26
|
-
import type { GlyphLayer, NanoGlyphMap } from '../types.js';
|
|
27
|
-
import type { NanoLogger } from '../types.js';
|
|
28
|
-
|
|
29
|
-
export type PipelineResult = {
|
|
30
|
-
ttfPath: string;
|
|
31
|
-
glyphmapPath: string;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// ---------------------------------------------------------------------------
|
|
35
|
-
// Same-color path merging
|
|
36
|
-
// ---------------------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
type ParsedPath = {
|
|
39
|
-
d: string;
|
|
40
|
-
fill: string | null;
|
|
41
|
-
fillRule?: 'evenodd';
|
|
42
|
-
noMerge?: boolean;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Concatenate multiple SVG path `d` strings into a single compound path.
|
|
47
|
-
* This preserves the exact geometry of each path (no boolean operations)
|
|
48
|
-
* while combining them into one glyph. Under nonzero winding, this renders
|
|
49
|
-
* identically to drawing each path separately with the same color.
|
|
50
|
-
*/
|
|
51
|
-
function concatPathDs(ds: string[]): string | null {
|
|
52
|
-
if (ds.length === 0) return null;
|
|
53
|
-
if (ds.length === 1) return ds[0]!;
|
|
54
|
-
return ds.join(' ');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Merge consecutive same-color paths into single compound paths via boolean UNION.
|
|
59
|
-
* Preserves z-order: only merges runs of adjacent paths with identical fill color.
|
|
60
|
-
*/
|
|
61
|
-
function mergeSameColorPaths(
|
|
62
|
-
paths: ParsedPath[],
|
|
63
|
-
logger?: NanoLogger
|
|
64
|
-
): ParsedPath[] {
|
|
65
|
-
if (paths.length <= 1) return paths;
|
|
66
|
-
|
|
67
|
-
const result: ParsedPath[] = [];
|
|
68
|
-
let i = 0;
|
|
69
|
-
|
|
70
|
-
while (i < paths.length) {
|
|
71
|
-
const fill = paths[i]!.fill;
|
|
72
|
-
|
|
73
|
-
// Find consecutive run of same fill that are all mergeable.
|
|
74
|
-
// Paths converted from evenodd have compound hole structure and must not
|
|
75
|
-
// be merged — their CW hole contours would cancel CCW contours from
|
|
76
|
-
// adjacent paths, producing incorrect fill.
|
|
77
|
-
let j = i + 1;
|
|
78
|
-
if (!paths[i]!.noMerge) {
|
|
79
|
-
while (
|
|
80
|
-
j < paths.length &&
|
|
81
|
-
paths[j]!.fill === fill &&
|
|
82
|
-
!paths[j]!.noMerge
|
|
83
|
-
) {
|
|
84
|
-
j++;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (j - i === 1) {
|
|
89
|
-
result.push(paths[i]!);
|
|
90
|
-
} else {
|
|
91
|
-
const group = paths.slice(i, j);
|
|
92
|
-
const merged = concatPathDs(group.map((p) => p.d));
|
|
93
|
-
if (merged) {
|
|
94
|
-
logger?.info(
|
|
95
|
-
` ⊕ Merged ${group.length} same-color paths (fill=${fill})`
|
|
96
|
-
);
|
|
97
|
-
result.push({ d: merged, fill });
|
|
98
|
-
} else {
|
|
99
|
-
result.push(...group);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
i = j;
|
|
103
|
-
}
|
|
104
|
-
return result;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// ---------------------------------------------------------------------------
|
|
108
|
-
// Pipeline
|
|
109
|
-
// ---------------------------------------------------------------------------
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Run the font pipeline with given config and paths.
|
|
113
|
-
* Uses the singleton Pyodide/PathKit instance (initialized on first call).
|
|
114
|
-
*/
|
|
115
|
-
export async function runPipeline(
|
|
116
|
-
config: PipelineConfig,
|
|
117
|
-
paths: PipelinePaths,
|
|
118
|
-
options?: { logger?: NanoLogger; inputHash?: string }
|
|
119
|
-
): Promise<PipelineResult> {
|
|
120
|
-
const startTime = Date.now();
|
|
121
|
-
const logger = options?.logger;
|
|
122
|
-
|
|
123
|
-
logger?.update(`Building "${config.fontFamily}"…`);
|
|
124
|
-
|
|
125
|
-
ensureDir(paths.outputDir);
|
|
126
|
-
|
|
127
|
-
const files = (await fsp.readdir(paths.inputDir)).filter((f) =>
|
|
128
|
-
f.toLowerCase().endsWith('.svg')
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
const glyphMap: NanoGlyphMap = {
|
|
132
|
-
m: {
|
|
133
|
-
f: config.fontFamily,
|
|
134
|
-
u: config.upm,
|
|
135
|
-
z: config.safeZone,
|
|
136
|
-
s: config.startUnicode,
|
|
137
|
-
...(config.linking === 'dynamic' ? { l: 'd' as const } : {}),
|
|
138
|
-
},
|
|
139
|
-
i: {},
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
let currentUnicode = config.startUnicode;
|
|
143
|
-
const codepointToIcon = new Map<number, string>();
|
|
144
|
-
const allGlyphs: FontGlyph[] = [];
|
|
145
|
-
|
|
146
|
-
const PathKit = await PathKitManager.getInstance();
|
|
147
|
-
|
|
148
|
-
for (const file of files) {
|
|
149
|
-
const iconName = path.parse(file).name;
|
|
150
|
-
const filePath = path.join(paths.inputDir, file);
|
|
151
|
-
|
|
152
|
-
logger?.info(`Processing ${file}`);
|
|
153
|
-
|
|
154
|
-
const rawContent = await fsp.readFile(filePath, 'utf-8');
|
|
155
|
-
|
|
156
|
-
const validation = validateSvg(rawContent);
|
|
157
|
-
if (validation.valid === false) {
|
|
158
|
-
logger?.warn(
|
|
159
|
-
`Skipping "${config.fontFamily}:${file}": ${validation.reason}`
|
|
160
|
-
);
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const preprocessed = preprocessSvg(rawContent);
|
|
165
|
-
|
|
166
|
-
// Preserve original evenodd `d` strings BEFORE picosvg processes them.
|
|
167
|
-
// Picosvg's simplify (via our PathKit shim) can drop contours from
|
|
168
|
-
// multi-subpath evenodd paths — we restore the originals after.
|
|
169
|
-
const originalEvenoddDs = extractOriginalEvenoddDs(preprocessed);
|
|
170
|
-
|
|
171
|
-
const flattenedSvg = await picoFromFile(filePath, preprocessed);
|
|
172
|
-
const parsed = parseFlattenedSvg(flattenedSvg, {
|
|
173
|
-
onSanitize: (original) => {
|
|
174
|
-
logger?.info(
|
|
175
|
-
` ⚠ Sanitized path in "${file}": path was missing initial moveto (prepended M from endpoint)`
|
|
176
|
-
);
|
|
177
|
-
logger?.info(` Original: ${original.slice(0, 80)}…`);
|
|
178
|
-
},
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
// Restore original evenodd path data (undamaged by picosvg's simplify),
|
|
182
|
-
// then convert to nonzero winding with our containment-based algorithm.
|
|
183
|
-
// Mark as noMerge — compound paths with holes must stay separate so their
|
|
184
|
-
// CW hole contours don't cancel adjacent paths' CCW contours.
|
|
185
|
-
if (originalEvenoddDs.length > 0) {
|
|
186
|
-
restoreOriginalEvenoddDs(parsed.paths, originalEvenoddDs);
|
|
187
|
-
}
|
|
188
|
-
for (const p of parsed.paths) {
|
|
189
|
-
if (p.fillRule === 'evenodd') {
|
|
190
|
-
logger?.info(
|
|
191
|
-
` ↻ Converting evenodd path to nonzero winding in "${file}"`
|
|
192
|
-
);
|
|
193
|
-
p.d = convertEvenoddToWinding(PathKit, p.d);
|
|
194
|
-
delete p.fillRule;
|
|
195
|
-
(p as ParsedPath).noMerge = true;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Merge consecutive same-color paths into single compound glyphs
|
|
200
|
-
const mergedPaths = mergeSameColorPaths(parsed.paths, logger);
|
|
201
|
-
|
|
202
|
-
const { vx, vy, scale, xOff, yOff, adv } = computePlacement({
|
|
203
|
-
upm: config.upm,
|
|
204
|
-
safeZone: config.safeZone,
|
|
205
|
-
viewBox: parsed.viewBox,
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
const layers: GlyphLayer[] = [];
|
|
209
|
-
|
|
210
|
-
for (const p of mergedPaths) {
|
|
211
|
-
if (shouldSkipPath(p.d, p.fill)) continue;
|
|
212
|
-
|
|
213
|
-
const cp = currentUnicode++;
|
|
214
|
-
codepointToIcon.set(cp, iconName);
|
|
215
|
-
|
|
216
|
-
const fontD = transformPathForFont(PathKit, p.d, {
|
|
217
|
-
vx,
|
|
218
|
-
vy,
|
|
219
|
-
scale,
|
|
220
|
-
xOff,
|
|
221
|
-
yOff,
|
|
222
|
-
upm: config.upm,
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
allGlyphs.push({
|
|
226
|
-
codepoint: cp,
|
|
227
|
-
advanceWidth: adv,
|
|
228
|
-
d: fontD,
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
layers.push([cp, p.fill || 'black']);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (layers.length > 0) {
|
|
235
|
-
glyphMap.i[iconName] = [adv, layers];
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const glyphmapPath = path.join(
|
|
240
|
-
paths.outputDir,
|
|
241
|
-
`${config.fontFamily}.glyphmap.json`
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
if (options?.inputHash) {
|
|
245
|
-
glyphMap.m.h = options.inputHash;
|
|
246
|
-
}
|
|
247
|
-
await fsp.writeFile(glyphmapPath, JSON.stringify(glyphMap), 'utf8');
|
|
248
|
-
|
|
249
|
-
logger?.info(`Compiling TTF…`);
|
|
250
|
-
const ttfPath = path.join(paths.outputDir, `${config.fontFamily}.ttf`);
|
|
251
|
-
|
|
252
|
-
try {
|
|
253
|
-
await compileTtfFromGlyphs({
|
|
254
|
-
glyphs: allGlyphs,
|
|
255
|
-
outTtfPath: ttfPath,
|
|
256
|
-
fontName: config.fontFamily,
|
|
257
|
-
upm: config.upm,
|
|
258
|
-
ascent: config.upm,
|
|
259
|
-
descent: 0,
|
|
260
|
-
});
|
|
261
|
-
} catch (err: unknown) {
|
|
262
|
-
parseCompileTtfFromGlyphsError(err, codepointToIcon);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const iconCount = Object.keys(glyphMap.i).length;
|
|
266
|
-
const elapsed = Date.now() - startTime;
|
|
267
|
-
logger?.succeed(
|
|
268
|
-
`Built ${config.fontFamily}.ttf [${iconCount} icon${
|
|
269
|
-
iconCount === 1 ? '' : 's'
|
|
270
|
-
} in ${elapsed}ms]`
|
|
271
|
-
);
|
|
272
|
-
|
|
273
|
-
return { ttfPath, glyphmapPath };
|
|
274
|
-
}
|