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

套件詳情v4.1.0

icon_font_generator

將 SVG 圖標轉換為 OTF 字體並產生 Flutter 兼容類別。提供 API 和 CLI 工具。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
3.4萬
喜歡數
147
Pub 分數
130

安裝套件

flutter pub add icon_font_generator

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter/Dart 套件,可將 SVG 圖示轉換為 OTF 字型,並產生對應的 Dart 類別,以方便在 Flutter 應用中整合。它提供命令列介面(CLI)與 API,支援自動化,讓開發者能簡化跨多個平台的圖示管理。所產生的字型相容於 Android、iOS、Web、macOS、Windows 與 Linux,確保圖示呈現的一致性。非常適合需要有效管理自訂圖示集的團隊。

適用情境

  • 從 SVG 生成自訂圖示字體
  • 自動化圖標資產創建
  • 將向量圖示整合到Flutter應用中
  • 支援多平台圖示渲染
  • 簡化從設計到程式碼的工作流程

主要特色

  • SVG 轉 OTF 字體轉換
  • 圖示Dart類別產生
  • CLI 與 API 接口
  • 跨平台支援
  • 自定圖標集管理
  • 與 Flutter 的輕鬆整合

適合對象

  • Flutter 開發者
  • 設計團隊
  • UI/UX 工程師
  • 需要自定圖標的應用
  • 頻繁更新圖標的專案

使用建議

  • 需要SVG檔案作為輸入
  • 需要為 CLI 或 API 使用進行設定
  • 可能需要額外的建構步驟
  • 字型檔案大小考量
  • 僅限圖示使用情境

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

icon_font_generator

pub package

The icon_font_generator 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.

Font generation

Install via dev dependency
$ flutter pub add --dev icon_font_generator

# And it's ready to go:
$ flutter pub run icon_font_generator:generate <input-svg-dir> <output-font-file> [options]
or Globally activate the package:
$ pub global activate icon_font_generator

# And it's ready to go:
$ icon_font_generator <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.
  • -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.
  • --[no-]format Format dart generated code.

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 icon_font_generator yaml configuration file. pubspec.yaml and icon_font.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:

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

Updated Flutter project's pubspec.yaml:

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

Config file

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

icon_font:
  input_svg_dir: "assets/svg/"
  output_font_file: "fonts/my_icons_font.otf"
  
  output_class_file: "lib/my_icons.dart"
  class_name: "MyIcons"
  package: my_font_package
  format: true

  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.

Contributing

Any suggestions, issues, pull requests are welcomed.

License

MIT

Credits

This software is fork of unsupported package:

所屬分類

依賴

依賴清單 11 項

原始碼儲存庫

使用此套件的專案