react-native-nano-icons 0.2.1 → 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 +72 -11
- 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/LICENSES.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Third-Party Notices
|
|
2
|
+
|
|
3
|
+
This project bundles or depends on the following third-party software:
|
|
4
|
+
|
|
5
|
+
1. @react-native-vector-icons/common
|
|
6
|
+
License: MIT
|
|
7
|
+
Source: https://github.com/oblador/react-native-vector-icons
|
|
8
|
+
|
|
9
|
+
2. fonteditor-core
|
|
10
|
+
License: MIT
|
|
11
|
+
Source: https://www.npmjs.com/package/fonteditor-core
|
|
12
|
+
|
|
13
|
+
3. @xmldom/xmldom
|
|
14
|
+
License: MIT
|
|
15
|
+
Source: https://github.com/xmldom/xmldom
|
|
16
|
+
|
|
17
|
+
4. minimist
|
|
18
|
+
License: MIT
|
|
19
|
+
Source: https://github.com/minimistjs/minimist
|
|
20
|
+
|
|
21
|
+
5. svg2ttf
|
|
22
|
+
License: MIT
|
|
23
|
+
Source: https://www.npmjs.com/package/svg2ttf
|
|
24
|
+
|
|
25
|
+
6. pathkit-wasm
|
|
26
|
+
License: BSD-3-Clause
|
|
27
|
+
Source: https://www.npmjs.com/package/pathkit-wasm
|
|
28
|
+
|
|
29
|
+
7. picosvg
|
|
30
|
+
License: Apache-2.0
|
|
31
|
+
Source: https://github.com/googlefonts/picosvg
|
|
32
|
+
Note: `src/core/flatten/` is a TypeScript port of picosvg
|
|
33
|
+
(Copyright 2020 Google LLC), redistributed under the Apache License,
|
|
34
|
+
Version 2.0. This entry is the attribution notice for that port.
|
|
35
|
+
|
|
36
|
+
Full license texts:
|
|
37
|
+
|
|
38
|
+
- MIT License: https://opensource.org/licenses/MIT
|
|
39
|
+
- BSD 3-Clause License: https://opensource.org/licenses/BSD-3-Clause
|
|
40
|
+
- Apache License 2.0: https://www.apache.org/licenses/LICENSE-2.0
|
package/README.md
CHANGED
|
@@ -116,11 +116,12 @@ The plugin accepts an object with an `iconSets` array, allowing you to generate
|
|
|
116
116
|
| Property | Type | Required | Default | Description |
|
|
117
117
|
| :------------- | :------- | :------- | :------------- | :------------------------------------------------------------------------------------------------------------------------- |
|
|
118
118
|
| `inputDir` | `string` | **Yes** | — | Path to the directory containing your `.svg` files (e.g., `./assets/icons/ui`). |
|
|
119
|
-
| `fontFamily` | `string` | No | Folder Name | The name of the generated
|
|
119
|
+
| `fontFamily` | `string` | No | Folder Name | The name of the generated `.ttf` and `.glyphmap.json` files. If omitted, the name of the `inputDir` folder is used (e.g., `ui`). The font family registered at runtime is `glyphMap.m.f`, which appends a short build hash (e.g. `ui-1a2b3c4d`) so every build of the set is distinct. |
|
|
120
120
|
| `outputDir` | `string` | No | `../nanoicons` | Path where the `.ttf` and `.json` artifacts will be saved. Defaults to a sibling `nanoicons` folder relative to the input. |
|
|
121
121
|
| `upm` | `number` | No | `1024` | Units Per Em. Defines the resolution of the font grid. |
|
|
122
122
|
| `startUnicode` | `string` | No | `0xe900` | The starting Hex Unicode point for the first icon glyph. |
|
|
123
123
|
| `linking` | `'static' \| 'dynamic'` | No | `'static'` | Delivery mode for the generated TTF. `'static'` bundles it into the native app. `'dynamic'` excludes it from native linking so the host app can deliver it at runtime (i.e. via OTA update). See [Dynamic linking](#dynamic-linking-expo-ota-updates-support). |
|
|
124
|
+
| `web` | `boolean` | No | `false` | Also emit `<fontFamily>.woff2` into `outputDir`, rebuilt together with the `.ttf` on every change. It is never linked natively; link it on web like any other web font. |
|
|
124
125
|
|
|
125
126
|
<details>
|
|
126
127
|
<summary>Default Dir Path Behavior</summary>
|
|
@@ -135,7 +136,7 @@ The plugin accepts an object with an `iconSets` array, allowing you to generate
|
|
|
135
136
|
|
|
136
137
|
Bare apps don't have a prebuild step, so you run the same pipeline via the CLI:
|
|
137
138
|
|
|
138
|
-
1. **Config** – Add a `.nanoicons.json` with the same `iconSets` shape as the Expo plugin (see options above).
|
|
139
|
+
1. **Config** – Add a `.nanoicons.json` with the same `iconSets` shape as the Expo plugin (see options above). Paths in it are relative to the app root.
|
|
139
140
|
<details>
|
|
140
141
|
<summary>.nanoicons.json example</summary>
|
|
141
142
|
|
|
@@ -154,18 +155,24 @@ Bare apps don't have a prebuild step, so you run the same pipeline via the CLI:
|
|
|
154
155
|
2. **Build and link** – From the app root run:
|
|
155
156
|
|
|
156
157
|
```sh
|
|
157
|
-
npx react-native-nano-icons
|
|
158
|
+
npx react-native-nano-icons
|
|
158
159
|
```
|
|
159
160
|
|
|
161
|
+
If the config lives elsewhere in the app, pass it: `--path path/to/.nanoicons.json`. From outside the app (for example a monorepo root), pass the app folder: `--path apps/mobile`. A folder with a `package.json` counts as the app, so the CLI reads the config, builds and links there.
|
|
162
|
+
|
|
160
163
|
This works exactly like the config plugin, removing any necessity for manual Xcode/Android Studio font linking steps.
|
|
161
164
|
|
|
162
165
|
> [!TIP]
|
|
163
166
|
> Run `EXPO_DEBUG=1 npx expo prebuild` or `npx react-native-nano-icons --verbose` to get font build-time logs.
|
|
164
167
|
|
|
165
168
|
> [!NOTE]
|
|
166
|
-
>
|
|
167
|
-
|
|
168
|
-
>
|
|
169
|
+
> In [Expo Go](https://expo.dev/go), icons are rendered using a regular `<Text>` fallback so you can iterate quickly. You will need to link the font manually via the already included [`expo-font` library](https://docs.expo.dev/versions/latest/sdk/font/), keyed by `glyphMap.m.f`. [Once you move to a development build](https://docs.expo.dev/develop/development-builds/expo-go-to-dev-build/), the library automatically switches to the native component implementation. Remember to remove any `expo-font`-related icon font setup after the switch.
|
|
170
|
+
|
|
171
|
+
> [!NOTE]
|
|
172
|
+
> With `web: true`, the `my-icons` set also gets `assets/icons/nanoicons/my-icons.woff2` next to its `.ttf`. Link it on web like any regular font, named `my-icons`. If you want to `require()` it through Metro (e.g. with `expo-font`), add this to `metro.config.js`:
|
|
173
|
+
> ```js
|
|
174
|
+
> config.resolver.assetExts.push("woff2");
|
|
175
|
+
> ```
|
|
169
176
|
|
|
170
177
|
### 4. Use
|
|
171
178
|
|
|
@@ -242,11 +249,11 @@ export const Icon = createNanoIconSet(glyphMap, require("./dynamic-ota-icons.ttf
|
|
|
242
249
|
> [!NOTE]
|
|
243
250
|
> In [Expo Go](https://expo.dev/go), the native font loader is unavailable, but you can still see real icons by loading the font manually via [`expo-font`](https://docs.expo.dev/versions/latest/sdk/font/) — use the value of `glyphMap.m.f` as the family name key. [Once you move to a development build](https://docs.expo.dev/develop/development-builds/expo-go-to-dev-build/), the library registers the font automatically and you can remove the `expo-font` setup.
|
|
244
251
|
|
|
245
|
-
> If a dynamic glyphmap gets no font, icons render
|
|
252
|
+
> If a dynamic glyphmap gets no font, its icons render blank until one is registered under `glyphMap.m.f` (with a dev warning).
|
|
246
253
|
|
|
247
254
|
### 5. Font Regeneration
|
|
248
255
|
|
|
249
|
-
**The build script detects changes in path and contents of the SVGs** in your input directory based on a fingerprint hash. If anything changes (file names, SVG attributes/nodes) or the output font/glyphmap files are deleted, the icon set is regenerated during `prebuild` or manual script run.
|
|
256
|
+
**The build script detects changes in path and contents of the SVGs** in your input directory, in the set's config (`upm`, `safeZone`, `startUnicode`) and in the library version or the versions of the packages it builds fonts with, based on a fingerprint hash. If anything changes (file names, SVG attributes/nodes, config, an upgrade of `react-native-nano-icons` or of a font-building dependency) or the output font/glyphmap files are deleted, the icon set is regenerated during `prebuild` or manual script run. The first 8 characters of the fingerprint become part of the runtime font family (`glyphMap.m.f`), so a rebuilt set never clashes with a previous build that is still bundled in the app.
|
|
250
257
|
|
|
251
258
|
### Regenerating dynamic fonts only (useful for an OTA update) ☁️
|
|
252
259
|
|
|
@@ -254,7 +261,7 @@ When your `dynamic` icons change and you want to ship them via OTA update, you d
|
|
|
254
261
|
|
|
255
262
|
```sh
|
|
256
263
|
# run from your app root
|
|
257
|
-
npx react-native-nano-icons --
|
|
264
|
+
npx react-native-nano-icons --dynamic
|
|
258
265
|
```
|
|
259
266
|
|
|
260
267
|
|
|
@@ -264,10 +271,34 @@ npx react-native-nano-icons --path path/to/.nanoicons.json --dynamic
|
|
|
264
271
|
> # run from your app root
|
|
265
272
|
> npx react-native-nano-icons --dynamic --app-config
|
|
266
273
|
> ```
|
|
267
|
-
> This reads your config directly from `app.json` / `app.config.js` / `app.config.ts` (no separate `.nanoicons.json` needed).
|
|
274
|
+
> This reads your config directly from `app.json` / `app.config.js` / `app.config.ts` (no separate `.nanoicons.json` needed). In a monorepo, run it from the app's folder or point it there with `--path <app root>`.
|
|
268
275
|
|
|
269
276
|
The CLI rebuilds only the sets defined with `linking: "dynamic"`, and skips all native linking. Commit the updated `.ttf` and `.glyphmap.json` and push your OTA update as usual ☁️ 🚀
|
|
270
277
|
|
|
278
|
+
> [!NOTE]
|
|
279
|
+
> A full (non `--dynamic`) run keeps the native projects in sync with the config: the fonts linked natively are exactly the products of the current static sets. Copies of sets that were switched to dynamic, removed from the config, or rebuilt under a new fingerprint are deleted from `ios/nanoicons-fonts`, `UIAppFonts`, and `android/app/src/main/assets/fonts`. Fonts you added yourself are left alone.
|
|
280
|
+
|
|
281
|
+
### Font integrity check
|
|
282
|
+
|
|
283
|
+
Every icon build is deterministic: the same SVGs, config and toolchain produce the same font identity, and the glyphmap refers to that exact font. At startup the library checks, once per icon set, that this font is available to the renderer, so the app always renders the font its glyphmap refers to. The check fails when the glyphmap in the JS bundle and the font in the app come from different builds, for example after an OTA update that changed icons without a new binary. In development a warning is printed. In every build the issue is recorded:
|
|
284
|
+
|
|
285
|
+
```TypeScript
|
|
286
|
+
import { addFontIntegrityListener, getFontIntegrityIssues } from "react-native-nano-icons";
|
|
287
|
+
|
|
288
|
+
addFontIntegrityListener((issue, status) => {
|
|
289
|
+
// status: "found" | "resolved"
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
getFontIntegrityIssues(); // current issues
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
- `"found"`: the set's font is missing or out of date, so its icons render blank. A listener added later receives the current issues immediately.
|
|
296
|
+
- `"resolved"`: a font for that set loaded later (for example through `loadFont`), and the issue was dropped.
|
|
297
|
+
|
|
298
|
+
Forward `"found"` issues to your error monitoring (e.g. Sentry) to catch a bad OTA update.
|
|
299
|
+
|
|
300
|
+
For every scenario and its message, see [FONT_INTEGRITY.md](https://github.com/software-mansion-labs/react-native-nano-icons/blob/main/packages/react-native-nano-icons/docs/FONT_INTEGRITY.md).
|
|
301
|
+
|
|
271
302
|
---
|
|
272
303
|
|
|
273
304
|
## 🎨 Multicolor Icons
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package com.nanoicons
|
|
2
|
+
|
|
3
|
+
import android.content.res.AssetManager
|
|
4
|
+
import android.graphics.Typeface
|
|
5
|
+
import com.facebook.react.bridge.UiThreadUtil
|
|
6
|
+
import com.facebook.react.common.assets.ReactFontManager
|
|
7
|
+
import java.util.Collections
|
|
8
|
+
import java.util.WeakHashMap
|
|
9
|
+
|
|
10
|
+
object NanoIconFonts {
|
|
11
|
+
private val liveViews: MutableSet<NanoIconView> =
|
|
12
|
+
Collections.newSetFromMap(WeakHashMap())
|
|
13
|
+
|
|
14
|
+
fun resolve(family: String, assets: AssetManager): Typeface? {
|
|
15
|
+
val typeface =
|
|
16
|
+
ReactFontManager.getInstance().getTypeface(family, Typeface.NORMAL, assets)
|
|
17
|
+
val systemFallback = Typeface.create(family, Typeface.NORMAL)
|
|
18
|
+
return if (typeface == null || typeface == systemFallback) null else typeface
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fun track(view: NanoIconView) {
|
|
22
|
+
liveViews.add(view)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fun register(family: String, typeface: Typeface) {
|
|
26
|
+
ReactFontManager.getInstance().setTypeface(family, Typeface.NORMAL, typeface)
|
|
27
|
+
UiThreadUtil.runOnUiThread {
|
|
28
|
+
for (view in liveViews.toList()) view.resolveFontIfMissing()
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -5,43 +5,57 @@ import android.graphics.Canvas
|
|
|
5
5
|
import android.graphics.Paint
|
|
6
6
|
import android.graphics.Typeface
|
|
7
7
|
import android.view.View
|
|
8
|
-
import com.facebook.react.common.assets.ReactFontManager
|
|
9
8
|
|
|
10
9
|
class NanoIconView(context: Context) : View(context) {
|
|
11
10
|
|
|
12
11
|
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
|
12
|
+
private val fontMetrics = Paint.FontMetrics()
|
|
13
13
|
private var codepoints: IntArray = intArrayOf()
|
|
14
14
|
private var colors: IntArray = intArrayOf()
|
|
15
15
|
private var cachedFontFamily: String? = null
|
|
16
16
|
private var cachedTypeface: Typeface? = null
|
|
17
17
|
// Cached String objects — rebuilt only when codepoints change
|
|
18
18
|
private var cachedTexts: Array<String> = emptyArray()
|
|
19
|
-
// Cached baseline — rebuilt
|
|
19
|
+
// Cached baseline — rebuilt when font, size, or bounds change
|
|
20
20
|
private var cachedBaseline: Float = 0f
|
|
21
|
+
// Derived from the loaded font's metrics; recomputed on typeface change.
|
|
22
|
+
private var textSizeFactor = 0f
|
|
23
|
+
private var baselineFactor = 0f
|
|
21
24
|
|
|
22
25
|
init {
|
|
23
26
|
// Transparent background, no default drawing
|
|
24
27
|
setBackgroundColor(0x00000000)
|
|
28
|
+
NanoIconFonts.track(this)
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
fun setFontFamily(fontFamily: String) {
|
|
28
32
|
if (fontFamily != cachedFontFamily) {
|
|
29
33
|
cachedFontFamily = fontFamily
|
|
30
|
-
|
|
31
|
-
.getTypeface(fontFamily, Typeface.NORMAL, context.assets)
|
|
32
|
-
paint.typeface = cachedTypeface
|
|
33
|
-
updateBaseline()
|
|
34
|
-
invalidate()
|
|
34
|
+
applyTypeface(NanoIconFonts.resolve(fontFamily, context.assets))
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
fun resolveFontIfMissing() {
|
|
39
|
+
val family = cachedFontFamily ?: return
|
|
40
|
+
if (cachedTypeface != null) return
|
|
41
|
+
val typeface = NanoIconFonts.resolve(family, context.assets) ?: return
|
|
42
|
+
applyTypeface(typeface)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private fun applyTypeface(typeface: Typeface?) {
|
|
46
|
+
cachedTypeface = typeface
|
|
47
|
+
paint.typeface = typeface
|
|
48
|
+
updateFontFactors()
|
|
49
|
+
fitToBounds()
|
|
50
|
+
invalidate()
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
fun setFontSize(size: Float) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
54
|
+
// Only seeds a size for use before the first layout; bounds win after that.
|
|
55
|
+
paint.textSize = size * resources.displayMetrics.density
|
|
56
|
+
if (textSizeFactor <= 0f) updateFontFactors()
|
|
57
|
+
fitToBounds()
|
|
58
|
+
invalidate()
|
|
45
59
|
}
|
|
46
60
|
|
|
47
61
|
fun setCodepoints(values: IntArray) {
|
|
@@ -55,8 +69,29 @@ class NanoIconView(context: Context) : View(context) {
|
|
|
55
69
|
invalidate()
|
|
56
70
|
}
|
|
57
71
|
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
|
73
|
+
super.onSizeChanged(w, h, oldw, oldh)
|
|
74
|
+
fitToBounds()
|
|
75
|
+
invalidate()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private fun updateFontFactors() {
|
|
79
|
+
val ts = paint.textSize
|
|
80
|
+
if (cachedTypeface == null || ts <= 0f) return
|
|
81
|
+
paint.getFontMetrics(fontMetrics)
|
|
82
|
+
val band = fontMetrics.descent - fontMetrics.ascent
|
|
83
|
+
if (band <= 0f) return
|
|
84
|
+
textSizeFactor = ts / band
|
|
85
|
+
baselineFactor = 1f - fontMetrics.descent / band
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Font scale is derived from the bounds, not from the fontSize prop.
|
|
89
|
+
private fun fitToBounds() {
|
|
90
|
+
val h = height.toFloat()
|
|
91
|
+
if (h <= 0f || textSizeFactor <= 0f) return
|
|
92
|
+
cachedBaseline = h * baselineFactor
|
|
93
|
+
val size = h * textSizeFactor
|
|
94
|
+
if (paint.textSize != size) paint.textSize = size
|
|
60
95
|
}
|
|
61
96
|
|
|
62
97
|
override fun onDraw(canvas: Canvas) {
|
|
@@ -4,10 +4,12 @@ import android.graphics.Typeface
|
|
|
4
4
|
import android.net.Uri
|
|
5
5
|
import com.facebook.react.bridge.Promise
|
|
6
6
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
-
import com.facebook.react.
|
|
7
|
+
import com.facebook.react.bridge.UiThreadUtil
|
|
8
8
|
import java.io.File
|
|
9
9
|
import java.io.InputStream
|
|
10
10
|
import java.net.URL
|
|
11
|
+
import java.nio.ByteBuffer
|
|
12
|
+
import java.nio.charset.Charset
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Registers a dynamically-linked (OTA) font at runtime so the NanoIconView can
|
|
@@ -23,21 +25,43 @@ class NanoIconsFontLoaderModule(reactContext: ReactApplicationContext) :
|
|
|
23
25
|
override fun getName(): String = NAME
|
|
24
26
|
|
|
25
27
|
override fun registerFont(family: String, uri: String, promise: Promise) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
val bytes =
|
|
29
|
+
try {
|
|
30
|
+
openStream(uri).use { it.readBytes() }
|
|
31
|
+
} catch (e: Exception) {
|
|
32
|
+
promise.reject(REGISTER_CODE, "Could not read font at $uri", e)
|
|
33
|
+
return
|
|
30
34
|
}
|
|
31
35
|
|
|
36
|
+
val postScriptName = runCatching { TtfNames.postScriptName(bytes) }.getOrNull()
|
|
37
|
+
if (postScriptName == null) {
|
|
38
|
+
promise.reject(REGISTER_CODE, "Invalid font data")
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
if (postScriptName != family) {
|
|
42
|
+
promise.reject(
|
|
43
|
+
"E_NANOICONS_FONT_MISMATCH",
|
|
44
|
+
"Font name \"$postScriptName\" does not match family \"$family\". " +
|
|
45
|
+
"The TTF PostScript name must equal glyphMap.m.f."
|
|
46
|
+
)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
val cacheFile = File.createTempFile("nanoicon_", ".ttf", reactApplicationContext.cacheDir)
|
|
52
|
+
cacheFile.writeBytes(bytes)
|
|
32
53
|
val typeface = Typeface.createFromFile(cacheFile)
|
|
33
|
-
|
|
54
|
+
NanoIconFonts.register(family, typeface)
|
|
34
55
|
promise.resolve(true)
|
|
35
56
|
} catch (e: Exception) {
|
|
36
|
-
promise.reject(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
57
|
+
promise.reject(REGISTER_CODE, "Invalid font data", e)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
override fun isFontRegistered(family: String, promise: Promise) {
|
|
62
|
+
val assets = reactApplicationContext.assets
|
|
63
|
+
UiThreadUtil.runOnUiThread {
|
|
64
|
+
promise.resolve(NanoIconFonts.resolve(family, assets) != null)
|
|
41
65
|
}
|
|
42
66
|
}
|
|
43
67
|
|
|
@@ -59,5 +83,42 @@ class NanoIconsFontLoaderModule(reactContext: ReactApplicationContext) :
|
|
|
59
83
|
|
|
60
84
|
companion object {
|
|
61
85
|
const val NAME = "NanoIconsFontLoader"
|
|
86
|
+
private const val REGISTER_CODE = "E_NANOICONS_FONT_REGISTER"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
object TtfNames {
|
|
91
|
+
private const val NAME_ID_POSTSCRIPT = 6
|
|
92
|
+
|
|
93
|
+
fun postScriptName(bytes: ByteArray): String? {
|
|
94
|
+
val buf = ByteBuffer.wrap(bytes)
|
|
95
|
+
val numTables = buf.getShort(4).toInt() and 0xffff
|
|
96
|
+
var nameOffset = -1
|
|
97
|
+
for (i in 0 until numTables) {
|
|
98
|
+
val record = 12 + i * 16
|
|
99
|
+
val tag = String(bytes, record, 4, Charsets.US_ASCII)
|
|
100
|
+
if (tag == "name") {
|
|
101
|
+
nameOffset = buf.getInt(record + 8)
|
|
102
|
+
break
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (nameOffset < 0) return null
|
|
106
|
+
|
|
107
|
+
val count = buf.getShort(nameOffset + 2).toInt() and 0xffff
|
|
108
|
+
val stringsOffset = nameOffset + (buf.getShort(nameOffset + 4).toInt() and 0xffff)
|
|
109
|
+
var postScript: String? = null
|
|
110
|
+
for (i in 0 until count) {
|
|
111
|
+
val record = nameOffset + 6 + i * 12
|
|
112
|
+
val platformId = buf.getShort(record).toInt() and 0xffff
|
|
113
|
+
val nameId = buf.getShort(record + 6).toInt() and 0xffff
|
|
114
|
+
if (nameId != NAME_ID_POSTSCRIPT) continue
|
|
115
|
+
val length = buf.getShort(record + 8).toInt() and 0xffff
|
|
116
|
+
val offset = buf.getShort(record + 10).toInt() and 0xffff
|
|
117
|
+
val charset: Charset =
|
|
118
|
+
if (platformId == 1) Charsets.ISO_8859_1 else Charsets.UTF_16BE
|
|
119
|
+
val value = String(bytes, stringsOffset + offset, length, charset)
|
|
120
|
+
if (postScript == null || platformId == 3) postScript = value
|
|
121
|
+
}
|
|
122
|
+
return postScript
|
|
62
123
|
}
|
|
63
124
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#import "NanoIconFontResolver.h"
|
|
2
|
+
|
|
3
|
+
static NSMutableDictionary *sNanoIconFontCache;
|
|
4
|
+
static dispatch_once_t sNanoIconFontCacheOnce;
|
|
5
|
+
|
|
6
|
+
CTFontRef NanoIconResolveFont(NSString *family, CGFloat size) {
|
|
7
|
+
dispatch_once(&sNanoIconFontCacheOnce, ^{ sNanoIconFontCache = [NSMutableDictionary new]; });
|
|
8
|
+
|
|
9
|
+
NSString *key = [NSString stringWithFormat:@"%@:%.1f", family, size];
|
|
10
|
+
@synchronized(sNanoIconFontCache) {
|
|
11
|
+
id existing = sNanoIconFontCache[key];
|
|
12
|
+
if (existing) {
|
|
13
|
+
return (__bridge CTFontRef)existing;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)family, size, NULL);
|
|
17
|
+
if (!font) return NULL;
|
|
18
|
+
|
|
19
|
+
NSString *postScriptName = (__bridge_transfer NSString *)CTFontCopyPostScriptName(font);
|
|
20
|
+
if (![postScriptName isEqualToString:family]) {
|
|
21
|
+
CFRelease(font);
|
|
22
|
+
return NULL;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
sNanoIconFontCache[key] = (__bridge id)font;
|
|
26
|
+
return font;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
BOOL NanoIconIsFontResolvable(NSString *family) {
|
|
31
|
+
return NanoIconResolveFont(family, 12.0) != NULL;
|
|
32
|
+
}
|
package/ios/NanoIconView.h
CHANGED
|
@@ -3,7 +3,3 @@
|
|
|
3
3
|
|
|
4
4
|
@interface NanoIconView : RCTViewComponentView
|
|
5
5
|
@end
|
|
6
|
-
|
|
7
|
-
// Clears cached CTFontRef entries for `family` so the next render fetches a
|
|
8
|
-
// fresh reference after an OTA font re-registration within the same process.
|
|
9
|
-
void NanoIconInvalidateFontCache(NSString *family);
|
package/ios/NanoIconView.mm
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#import "NanoIconView.h"
|
|
2
|
+
#import "NanoIconFontResolver.h"
|
|
2
3
|
#import <CoreText/CoreText.h>
|
|
3
4
|
#import <React/RCTConversions.h>
|
|
4
5
|
#import <React/RCTFabricComponentsPlugins.h>
|
|
@@ -9,6 +10,7 @@ using namespace facebook::react;
|
|
|
9
10
|
|
|
10
11
|
// Forward-declare so the layer subclass can call the drawing method.
|
|
11
12
|
@interface NanoIconView ()
|
|
13
|
+
- (void)_resolveFontIfMissing;
|
|
12
14
|
- (void)_drawIconInContext:(CGContextRef)context bounds:(CGRect)bounds;
|
|
13
15
|
@end
|
|
14
16
|
|
|
@@ -24,40 +26,27 @@ using namespace facebook::react;
|
|
|
24
26
|
}
|
|
25
27
|
@end
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
static
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (font) sNanoIconFontCache[key] = (__bridge id)font;
|
|
43
|
-
return font;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Clears cached entries for `family` after OTA font re-registration.
|
|
47
|
-
void NanoIconInvalidateFontCache(NSString *family) {
|
|
48
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
49
|
-
if (!sNanoIconFontCache) return;
|
|
50
|
-
NSString *prefix = [family stringByAppendingString:@":"];
|
|
51
|
-
NSArray<NSString *> *keys = [sNanoIconFontCache.allKeys
|
|
52
|
-
filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSString *k, id _) {
|
|
53
|
-
return [k hasPrefix:prefix];
|
|
54
|
-
}]];
|
|
55
|
-
[sNanoIconFontCache removeObjectsForKeys:keys];
|
|
29
|
+
static NSHashTable<NanoIconView *> *sNanoIconLiveViews;
|
|
30
|
+
static dispatch_once_t sNanoIconLiveViewsOnce;
|
|
31
|
+
|
|
32
|
+
static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
33
|
+
dispatch_once(&sNanoIconLiveViewsOnce, ^{
|
|
34
|
+
sNanoIconLiveViews = [NSHashTable weakObjectsHashTable];
|
|
35
|
+
[[NSNotificationCenter defaultCenter]
|
|
36
|
+
addObserverForName:(__bridge NSString *)kCTFontManagerRegisteredFontsChangedNotification
|
|
37
|
+
object:nil
|
|
38
|
+
queue:[NSOperationQueue mainQueue]
|
|
39
|
+
usingBlock:^(__unused NSNotification *note) {
|
|
40
|
+
for (NanoIconView *live in [sNanoIconLiveViews allObjects]) {
|
|
41
|
+
[live _resolveFontIfMissing];
|
|
42
|
+
}
|
|
43
|
+
}];
|
|
56
44
|
});
|
|
45
|
+
[sNanoIconLiveViews addObject:view];
|
|
57
46
|
}
|
|
58
47
|
|
|
59
48
|
@implementation NanoIconView {
|
|
60
|
-
CTFontRef _font; // borrowed from
|
|
49
|
+
CTFontRef _font; // borrowed from the shared resolver cache — do NOT CFRelease
|
|
61
50
|
NSString *_fontFamily;
|
|
62
51
|
CGFloat _fontSize;
|
|
63
52
|
std::vector<CGGlyph> _glyphs;
|
|
@@ -92,6 +81,7 @@ void NanoIconInvalidateFontCache(NSString *family) {
|
|
|
92
81
|
|
|
93
82
|
_fitScale = 1.0;
|
|
94
83
|
_baselinePosition = CGPointZero;
|
|
84
|
+
NanoIconTrackLiveView(self);
|
|
95
85
|
|
|
96
86
|
// _drawingLayer is created lazily only when inline in Text
|
|
97
87
|
}
|
|
@@ -186,6 +176,7 @@ void NanoIconInvalidateFontCache(NSString *family) {
|
|
|
186
176
|
NanoIconDrawingLayer *layer = [NanoIconDrawingLayer layer];
|
|
187
177
|
layer.owner = self;
|
|
188
178
|
layer.opaque = NO;
|
|
179
|
+
layer.needsDisplayOnBoundsChange = YES;
|
|
189
180
|
layer.contentsScale = [UIScreen mainScreen].scale;
|
|
190
181
|
[self.layer addSublayer:layer];
|
|
191
182
|
_drawingLayer = layer;
|
|
@@ -204,10 +195,11 @@ void NanoIconInvalidateFontCache(NSString *family) {
|
|
|
204
195
|
}
|
|
205
196
|
}
|
|
206
197
|
|
|
207
|
-
//
|
|
198
|
+
// _cachedBaselineOffset and _fitScale are both derived from bounds.
|
|
208
199
|
- (void)setBounds:(CGRect)bounds {
|
|
209
200
|
if (!CGSizeEqualToSize(self.bounds.size, bounds.size)) {
|
|
210
201
|
_baselineOffsetValid = NO;
|
|
202
|
+
_metricsValid = NO;
|
|
211
203
|
}
|
|
212
204
|
[super setBounds:bounds];
|
|
213
205
|
}
|
|
@@ -353,7 +345,7 @@ void NanoIconInvalidateFontCache(NSString *family) {
|
|
|
353
345
|
oldViewProps.fontSize != newViewProps.fontSize) {
|
|
354
346
|
_fontFamily = [NSString stringWithUTF8String:newViewProps.fontFamily.c_str()];
|
|
355
347
|
_fontSize = newViewProps.fontSize;
|
|
356
|
-
_font =
|
|
348
|
+
_font = NanoIconResolveFont(_fontFamily, _fontSize);
|
|
357
349
|
_metricsValid = NO;
|
|
358
350
|
fontChanged = YES;
|
|
359
351
|
needsRedraw = YES;
|
|
@@ -361,27 +353,7 @@ void NanoIconInvalidateFontCache(NSString *family) {
|
|
|
361
353
|
|
|
362
354
|
// Map Unicode codepoints to font glyph IDs, handling surrogate pairs for codepoints > 0xFFFF.
|
|
363
355
|
if (fontChanged || oldViewProps.codepoints != newViewProps.codepoints) {
|
|
364
|
-
|
|
365
|
-
if (!fontChanged && _fontFamily) {
|
|
366
|
-
_font = NanoIconGetCachedFont(_fontFamily, _fontSize);
|
|
367
|
-
}
|
|
368
|
-
const auto &codepoints = newViewProps.codepoints;
|
|
369
|
-
_glyphs.resize(codepoints.size());
|
|
370
|
-
for (size_t i = 0; i < codepoints.size(); i++) {
|
|
371
|
-
int32_t cp = codepoints[i];
|
|
372
|
-
if (cp <= 0xFFFF) {
|
|
373
|
-
UniChar ch = (UniChar)cp;
|
|
374
|
-
CTFontGetGlyphsForCharacters(_font, &ch, &_glyphs[i], 1);
|
|
375
|
-
} else {
|
|
376
|
-
UniChar surr[2] = {
|
|
377
|
-
(UniChar)(0xD800 + ((cp - 0x10000) >> 10)),
|
|
378
|
-
(UniChar)(0xDC00 + ((cp - 0x10000) & 0x3FF))
|
|
379
|
-
};
|
|
380
|
-
CGGlyph pair[2] = {0, 0};
|
|
381
|
-
CTFontGetGlyphsForCharacters(_font, surr, pair, 2);
|
|
382
|
-
_glyphs[i] = pair[0];
|
|
383
|
-
}
|
|
384
|
-
}
|
|
356
|
+
[self _mapGlyphs:newViewProps.codepoints];
|
|
385
357
|
needsRedraw = YES;
|
|
386
358
|
}
|
|
387
359
|
|
|
@@ -396,17 +368,50 @@ void NanoIconInvalidateFontCache(NSString *family) {
|
|
|
396
368
|
}
|
|
397
369
|
|
|
398
370
|
[super updateProps:props oldProps:oldProps];
|
|
399
|
-
if (needsRedraw)
|
|
400
|
-
|
|
401
|
-
|
|
371
|
+
if (needsRedraw) [self _setNeedsRedraw];
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
- (void)_mapGlyphs:(const std::vector<int32_t> &)codepoints {
|
|
375
|
+
_glyphs.assign(codepoints.size(), 0);
|
|
376
|
+
if (!_font) return;
|
|
377
|
+
for (size_t i = 0; i < codepoints.size(); i++) {
|
|
378
|
+
int32_t cp = codepoints[i];
|
|
379
|
+
if (cp <= 0xFFFF) {
|
|
380
|
+
UniChar ch = (UniChar)cp;
|
|
381
|
+
CTFontGetGlyphsForCharacters(_font, &ch, &_glyphs[i], 1);
|
|
402
382
|
} else {
|
|
403
|
-
[
|
|
383
|
+
UniChar surr[2] = {
|
|
384
|
+
(UniChar)(0xD800 + ((cp - 0x10000) >> 10)),
|
|
385
|
+
(UniChar)(0xDC00 + ((cp - 0x10000) & 0x3FF))
|
|
386
|
+
};
|
|
387
|
+
CGGlyph pair[2] = {0, 0};
|
|
388
|
+
CTFontGetGlyphsForCharacters(_font, surr, pair, 2);
|
|
389
|
+
_glyphs[i] = pair[0];
|
|
404
390
|
}
|
|
405
391
|
}
|
|
406
392
|
}
|
|
407
393
|
|
|
394
|
+
- (void)_resolveFontIfMissing {
|
|
395
|
+
if (_font || _fontFamily.length == 0) return;
|
|
396
|
+
_font = NanoIconResolveFont(_fontFamily, _fontSize);
|
|
397
|
+
if (!_font) return;
|
|
398
|
+
const auto &viewProps = static_cast<const NanoIconViewProps &>(*_props);
|
|
399
|
+
[self _mapGlyphs:viewProps.codepoints];
|
|
400
|
+
_metricsValid = NO;
|
|
401
|
+
[self _setNeedsRedraw];
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
- (void)_setNeedsRedraw {
|
|
405
|
+
if (_isInlineInText && _drawingLayer) {
|
|
406
|
+
[_drawingLayer setNeedsDisplay];
|
|
407
|
+
} else {
|
|
408
|
+
[self setNeedsDisplay];
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
408
412
|
- (void)dealloc {
|
|
409
413
|
// _font is borrowed from static cache — do not release
|
|
414
|
+
[sNanoIconLiveViews removeObject:self];
|
|
410
415
|
[self _releaseCachedColors];
|
|
411
416
|
}
|
|
412
417
|
|