패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.2.0

fontify

SVG 아이콘을 OTF 폰트로 변환하고 Flutter 호환 클래스를 생성합니다. API 및 CLI 도구를 제공합니다.

30일 다운로드
256
좋아요
51
Pub 점수
40

패키지 설치

flutter pub add fontify

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Fontify는 SVG 아이콘을 OTF 폰트로 변환하고, 쉽게 통합할 수 있도록 Flutter 호환 Dart 클래스를 생성합니다. 명령줄 인터페이스(CLI)와 API를 제공하여 개발자가 커스텀 아이콘을 Flutter 애플리케이션 내에서 폰트로 번들링할 수 있게 해줍니다. 이는 여러 이미지 자산이 필요하지 않게 하여 아이콘 관리를 간소화하고, 폰트 기반 렌더링을 통해 성능을 향상시킵니다. 이 도구는 커스텀 또는 브랜드 아이콘 세트가 필요한 프로젝트에 특히 유용합니다.

사용 사례

  • SVG에서 사용자 지정 아이콘 폰트 만들기
  • Flutter 앱에 브랜드 아이콘 통합하기
  • 글꼴 기반 아이콘을 사용하여 앱 번들 크기 줄이기
  • CI/CD 파이프라인에서 아이콘 폰트 생성 자동화

주요 기능

  • SVG에서 OTF 폰트로의 변환
  • Flutter 클래스 생성
  • CLI 및 API 지원
  • 사용자 정의 아이콘 이름 지정을 지원합니다
  • Flutter 성능에 최적화됨

적합한 대상

  • 맞춤형 아이콘을 필요로 하는 플러터 개발자
  • 대규모 아이콘 세트를 관리하는 팀
  • 자산 오버헤드를 최소화하려는 프로젝트

고려 사항

  • 입력으로 SVG 파일이 필요합니다
  • 글꼴 기반 아이콘 렌더링에 제한됨
  • 내장된 아이콘 편집 도구 없음
  • 런타임 중에 아이콘을 동적으로 변경하는 데 적합하지 않습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Fontify

pub package

The Fontify package provides an easy way to convert SVG icons to OpenType font and generate Flutter-compatible class that contains identifiers for the icons (just like CupertinoIcons or Icons classes).

The package is written fully in Dart and doesn't require any external dependency. Compatible with dart2js and dart2native.

Using CLI tool

Globally activate the package:

$ pub global activate fontify

And it's ready to go:

$ fontify <input-svg-dir> <output-font-file> [options]

Required positional arguments:

  • <input-svg-dir> Path to the input directory that contains .svg files.
  • <output-font-file> Path to the output font file. Should have .otf extension.

Flutter class options:

  • -o or --output-class-file=<path> Output path for Flutter-compatible class that contains identifiers for the icons.
  • -i or --indent=<indent> Number of spaces in leading indentation for Flutter class file. (defaults to "2")
  • -c or --class-name=<name> Name for a generated class.
  • -p or --package=<name> Name of a package that provides a font. Used to provide a font through package dependency.

Font options:

  • -f or --font-name=<name> Name for a generated font.
  • --[no-]normalize Enables glyph normalization for the font. Disable this if every icon has the same size and positioning. (defaults to on)
  • --[no-]ignore-shapes Disables SVG shape-to-path conversion (circle, rect, etc.). (defaults to on)

Other options:

  • -z or --config-file=<path> Path to Fontify yaml configuration file. pubspec.yaml and fontify.yaml files are used by default.
  • -r or --recursive Recursively look for .svg files.
  • -v or --verbose Display every logging message.
  • -h or --help Shows usage information.

Usage example:

$ fontify assets/svg/ fonts/my_icons_font.otf --output-class-file=lib/my_icons.dart --indent=4 -r

Updated Flutter project's pubspec.yaml:

...

flutter:
  fonts:
    - family: Fontify Icons
      fonts:
        - asset: fonts/my_icons_font.otf

CLI tool config file

Fontify's configuration can also be placed in yaml file. Add fontify section to either pubspec.yaml or fontify.yaml file:

fontify:
  input_svg_dir: "assets/svg/"
  output_font_file: "fonts/my_icons_font.otf"
  
  output_class_file: "lib/my_icons.dart"
  class_name: "MyIcons"
  indent: 4
  package: my_font_package

  font_name: "My Icons"
  normalize: true
  ignore_shapes: true

  recursive: true
  verbose: false

input_svg_dir and output_font_file keys are required. It's possible to specify any other config file by using --config-file option.

Using API

svgToOtf and generateFlutterClass functions can be used for generating font and Flutter class.

The example of API usage is located in example folder.

Notes

  • Generated OpenType font is using CFF table.
  • Generated font is using PostScript Table (post) of version 3.0, i.e., it doesn't contain glyph names.
  • Supported SVG elements: path, g, circle, rect, polyline, polygon, line.
  • SVG transforms are applied to paths according to specs.
  • SVG <g> element's children are expanded to the root with transformations applied. Anything else related to the group is ignored and group referencing is not supported.
  • Consider using Non-zero fill rule.
  • When ignoreShapes is set to false, every SVG shape's (circle, rect, etc.) outline is converted to path. Note that any attributes like "fill" or "stroke" are ignored and only the outline is used, so the resulting glyph may look different from SVG icon. It's recommended to convert every element in SVG to path.
  • When normalize is set to false, it's recommended that SVG icons have the same height. Otherwise, final result might not look as expected.
  • When Flutter class is generated, static variables names derive from SVG file name converted to pascal case with non-allowed characters removed. Name is set to 'unnamed', if it's empty. Suffix '_{i+1}' is added, if name already exists.

Planned

  • Support svg-to-ttf conversion (cubic-to-quad curves approximation needs to be done).
  • Support ligatures.
  • Support font variations.

Contributing

Any suggestions, issues, pull requests are welcomed.

License

MIT

카테고리

의존성

의존성 목록 9 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.