Generate a TrueType font (.ttf) from a directory of SVG files. Used internally for the NAHPU app to create custom Flutter icon fonts.
This project uses uv for dependency management.
- Place your
.svgfiles inside thesvg/directory. - Run the command-line application:
uv run python main.py --input svg --output font-output/icon_font.ttf --font-name NahpuIcons --weight 1.5The script will:
- Map each SVG to a Unicode Private Use Area (PUA) codepoint starting from
U+E000sequentially. - Automatically expand the stroke of
_outlined.svgfiles to the specified--weight(default: 1.5). - Generate a TrueType Font file (
icon_font.ttf) in the output directory. - Automatically generate a Dart class file (
nahpu_icons.dart) containing theIconDatamappings, ready to be used in your Flutter project.
To use the generated font in your Flutter application, follow these steps:
Copy the generated icon_font.ttf to your Flutter project's assets directory (e.g., assets/fonts/) and register it in your pubspec.yaml:
flutter:
fonts:
- family: NahpuIcons
fonts:
- asset: assets/fonts/icon_font.ttfCopy the generated nahpu_icons.dart file into your Flutter project's lib/ directory. This file already contains all the correct static constants mapping to the generated Unicode codepoints.
NAHPU put this file in
lib/services/types/nahpu_icon.dart.
Use it inside your Flutter widgets just like any standard Icon using the static constants provided by the generated class:
import 'path/to/nahpu_icons.dart';
Icon(
NahpuIcons.myCustomIcon,
size: 24.0,
color: Colors.black,
)This project includes automated unit tests using pytest.
To run the test suite:
uv run pytest