通常状况我经过 iconfont 或者 icomoon 来实现图标管理生成字体,导入到项目中使用。css
┌────────┐ ┌────────────┐ │iconfont│──┐ │ Project │ └────────┘ │ ┌────────────┐ ┌────────┐ │ ┌────────┐ │ ├─▶│created font│─▶│download│──▶│ │use font│ │ ┌────────┐ │ └────────────┘ └────────┘ │ └────────┘ │ │icomoon │──┘ └────────────┘ └────────┘
彩色图标
。经过图标平台网站下载 svg 图标,将图标放到项目中管理,经过 svgtofont.js 工具来生成它,这将是新的字体图标使用方式:html
┌────────────────────┐ │ Project │ │ │ ┌────────┐ │ ┌───────────┐ │ │iconfont│──┐ │ │ svg │──┐ │ └────────┘ │ ┌────────────┐ │ └───────────┘ │ │ ├─▶│download svg│──▶│ ┌───────────┐ │ │ ┌────────┐ │ └────────────┘ │┌──│create font│◀─┘ │ │icomoon │──┘ ││ └───────────┘ │ └────────┘ ││ ┌───────────┐ │ │└─▶│ use font │ │ │ └───────────┘ │ └────────────────────┘
新的方式维护方式好处:node
图标
,再也不维护字体文件
SVG Symbol
在项目中使用读取一组 SVG图标并从SVG图标输出 TTF/EOT/WOFF/WOFF2/SVG 字体,字体生成器。git
特性github
SVG Symbol
文件。https://github.com/uiwjs/iconsweb
https://github.com/uiwjs/file...npm
npm i svgtofont
简单的使用方式c#
const svgtofont = require("svgtofont"); svgtofont({ src: path.resolve(process.cwd(), "icon"), // svg 图标目录路径 dist: path.resolve(process.cwd(), "fonts"), // 输出到指定目录中 fontName: "svgtofont", // 设置字体名称 css: true, // 生成字体文件 }).then(() => { console.log('done!'); });
const svgtofont = require("svgtofont"); const path = require("path"); svgtofont({ src: path.resolve(process.cwd(), "icon"), // svg 图标目录路径 dist: path.resolve(process.cwd(), "fonts"), // 输出到指定目录中 fontName: "svgtofont", // 设置字体名称 css: true, // 生成字体文件 startNumber: 20000, // unicode起始编号 svgicons2svgfont: { fontHeight: 1000, normalize: true }, // website = null, 没有演示html文件 website: { title: "svgtofont", // Must be a .svg format image. logo: path.resolve(process.cwd(), "svg", "git.svg"), version: pkg.version, meta: { description: "Converts SVG fonts to TTF/EOT/WOFF/WOFF2/SVG format.", keywords: "svgtofont,TTF,EOT,WOFF,WOFF2,SVG" }, description: ``, links: [ { title: "GitHub", url: "https://github.com/jaywcjlove/svgtofont" }, { title: "Feedback", url: "https://github.com/jaywcjlove/svgtofont/issues" }, { title: "Font Class", url: "index.html" }, { title: "Unicode", url: "unicode.html" } ], footerInfo: `Licensed under MIT. (Yes it's free and <a href="https://github.com/jaywcjlove/svgtofont">open-sourced</a>` } }).then(() => { console.log('done!'); });;
svgtofont 提供 API,能够一个一个的本身生成,也能够自动经过上面方法自动生成api
const { createSVG, createTTF, createEOT, createWOFF, createWOFF2 } = require("svgtofont/src/utils"); const options = { ... }; createSVG(options) // SVG => SVG Font .then(UnicodeObjChar => createTTF(options)) // SVG Font => TTF .then(() => createEOT(options)) // TTF => EOT .then(() => createWOFF(options)) // TTF => WOFF .then(() => createWOFF2(options)) // TTF => WOFF2 .then(() => createSvgSymbol(options)) // SVG Files => SVG Symbol
svgtofont(options)
Type:String
Default value:dist
svg 图标路径bash
Type:String
Default value:svg
输出到指定目录
Type:String
Default value:iconfont
您想要的字体名称。
Type:Number
Default value:10000
unicode起始编号
Type:String
Default value: font name
建立字体类名称前缀,默认值字体名称。
Type:Boolean
Default value:false
建立CSS / LESS文件,默认为“true”。
这是 svgicons2svgfont 的设置
Type:String
Default value:'iconfont'
您想要的字体名称,与前面 fontName
同样。
Type:String
Default value: the options.fontName value
你想要的字体ID。
Type:String
Default value:''
你想要的字体样式。
Type:String
Default value:''
你想要的字体粗细。
Type:Boolean
Default value:false
建立最大输入图标宽度的等宽字体。
Type:Boolean
Default value:false
计算字形的边界并使其水平居中。
Type:Boolean
Default value:false
经过将图标缩放到最高图标的高度来标准化图标。
Type:Number
Default value:MAX(icons.height)
输出的字体高度(默认为最高输入图标的高度)。
Type:Number
Default value:10e12
设置SVG路径舍入。
Type:Number
Default value:0
字体降低。 本身修复字体基线颇有用。
警告: 降低是一个正值!
Type:Number
Default value:fontHeight - descent
字体上升。 仅当您知道本身在作什么时才使用此选项。 为您计算一个合适的值。
Type:String
Default value:undefined
字体 metadata。 你能够设置任何
字符数据,但它是适合说起版权的地方。
Type:Function
Default value:console.log
容许您提供本身的日志记录功能。 设置为 function(){}
禁用日志记录
这是 svg2ttf 的设置
Type:
String
版权字符串
Type:
String
用于覆盖建立时间的Unix时间戳(以秒为单位)
Type:
Number
font version string, can be Version x.y
or x.y
.
定义预览Web内容。 例:
{ ... // website = null, no demo html files website: { title: "svgtofont", logo: path.resolve(process.cwd(), "svg", "git.svg"), version: pkg.version, meta: { description: "Converts SVG fonts to TTF/EOT/WOFF/WOFF2/SVG format.", keywords: "svgtofont,TTF,EOT,WOFF,WOFF2,SVG", favicon: "./favicon.png" }, footerLinks: [ { title: "GitHub", url: "https://github.com/jaywcjlove/svgtofont" }, { title: "Feedback", url: "https://github.com/jaywcjlove/svgtofont/issues" }, { title: "Font Class", url: "index.html" }, { title: "Unicode", url: "unicode.html" } ] } }
Type:String
Default value: index.ejs
自定义模板可自定义参数。 您能够根据默认模板定义本身的模板。
{ website: { template: path.join(process.cwd(), "my-template.ejs") } }
Type:String
Default value:font-class
, Enum{font-class
,unicode
,symbol
}
设置默认主页。
假设字体名称定义为 svgtofont
,默认主页为unicode
,将生成:
font-class.html index.html symbol.html svgtofont.css svgtofont.eot svgtofont.less svgtofont.svg svgtofont.symbol.svg svgtofont.ttf svgtofont.woff svgtofont.woff2
预览demo font-class.html
, symbol.html
和 index.html
。自动生成样式svgtofont.css
和 svgtofont.less
。
<svg class="icon" aria-hidden="true"> <use xlink:href="svgtofont.symbol.svg#svgtofont-git"></use> </svg>
<style> .iconfont { font-family: "svgtofont-iconfont" !important; font-size: 16px; font-style: normal; -webkit-font-smoothing: antialiased; -webkit-text-stroke-width: 0.2px; -moz-osx-font-smoothing: grayscale; } </style> <span class="iconfont"></span>
支持.less
和.css
样式引用。
<link rel="stylesheet" type="text/css" href="node_modules/fonts/svgtofont.css"> <i class="svgtofont-apple"></i>
Licensed under the MIT License.