Buscar pacotes, repositórios e categorias de apps

Detalhes do pacotev0.2.0

fontify

Converte ícones SVG para fonte OTF e gera uma classe compatível com Flutter. Fornece uma API e uma ferramenta de linha de comando.

Downloads em 30 dias
256
Curtidas
51
Pontos Pub
40

Instalar pacote

flutter pub add fontify

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

Fontify converte ícones SVG em fontes OTF e gera uma classe Dart compatível com Flutter para fácil integração. Ele oferece tanto uma interface de linha de comando (CLI) quanto uma API, permitindo que desenvolvedores empacotem ícones personalizados como fontes em seus aplicativos Flutter. Isso simplifica a gestão de ícones, reduzindo a necessidade de múltiplos recursos de imagem e melhorando o desempenho por meio da renderização baseada em fontes. A ferramenta é particularmente útil para projetos que exigem conjuntos de ícones personalizados ou com marca.

Casos de uso

  • Criando fontes de ícones personalizadas a partir de SVGs
  • Integrando ícones da marca em aplicativos Flutter
  • Reduzindo o tamanho do pacote do aplicativo com ícones baseados em fontes
  • Automatizando a geração de fontes de ícones em pipelines CI/CD

Principais recursos

  • Conversão de SVG para fonte OTF
  • Geração de classe Flutter
  • Suporte a CLI e API
  • Suporta nomeação personalizada de ícones
  • Otimizado para desempenho do Flutter

Indicado para

  • Desenvolvedores Flutter que precisam de ícones personalizados
  • Equipes gerenciando conjuntos grandes de ícones
  • Projetos com o objetivo de minimizar a sobrecarga de ativos

Considerações

  • Requer arquivos SVG como entrada
  • Limitado à renderização de ícones baseada em fonte
  • Sem ferramentas embutidas de edição de ícones
  • Não adequado para alterações dinâmicas de ícones em tempo de execução

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

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

Categorias

Dependências

Lista de dependências 9 itens

Repositório-fonte

Projetos que usam este pacote

Ainda não há dados.