搜尋套件、儲存庫與 APP 分類

套件詳情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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。