Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Converts SVG icons to OTF font and generates Flutter-compatible class. Provides an API and a CLI tool.

License

NotificationsYou must be signed in to change notification settings

westracer/fontify

Repository files navigation

pub package

The Fontify package provides an easy way to convert SVG icons to OpenType fontand generate Flutter-compatible class that contains identifiers for the icons(just likeCupertinoIcons orIcons 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-]normalizeEnables glyph normalization for the font.Disable this if every icon has the same size and positioning.(defaults to on)
  • --[no-]ignore-shapesDisables 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--recursiveRecursively look for .svg files.
  • -v or--verboseDisplay every logging message.
  • -h or--helpShows 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 Iconsfonts:        -asset:fonts/my_icons_font.otf

CLI tool config file

Fontify's configuration can also be placed in yaml file.Addfontify section to eitherpubspec.yaml orfontify.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:4package:my_font_packagefont_name:"My Icons"normalize:trueignore_shapes:truerecursive:trueverbose:false

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

Using API

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

The example of API usage is located inexample 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 usingNon-zero fill rule.
  • WhenignoreShapes 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.
  • Whennormalize 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 nameconverted 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

About

Converts SVG icons to OTF font and generates Flutter-compatible class. Provides an API and a CLI tool.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp