Skip to content

nahpu/nahpu-icon-generator

Repository files navigation

nahpu-icon-generator

Tests

Generate a TrueType font (.ttf) from a directory of SVG files. Used internally for the NAHPU app to create custom Flutter icon fonts.

Requirements

This project uses uv for dependency management.

Usage

  1. Place your .svg files inside the svg/ directory.
  2. Run the command-line application:
uv run python main.py --input svg --output font-output/icon_font.ttf --font-name NahpuIcons --weight 1.5

The script will:

  • Map each SVG to a Unicode Private Use Area (PUA) codepoint starting from U+E000 sequentially.
  • Automatically expand the stroke of _outlined.svg files 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 the IconData mappings, ready to be used in your Flutter project.

Using the Font in Flutter

To use the generated font in your Flutter application, follow these steps:

1. Add the font to your pubspec.yaml

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.ttf

2. Include the Dart Class

Copy 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.

3. Display the Icon

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,
)

Testing

This project includes automated unit tests using pytest. To run the test suite:

uv run pytest

About

Generate font icon from SVG. Use internally for in NAHPU app.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages