1.9.15 • Published 9 years ago
use-iconfonts v1.9.15
use-iconfonts
暂时只能运行在node环境下 借鉴nfroidure/svgiconfont字体打包工具,扩展了功能提供svg内容可以直接作为数据源编译成字体。
Please Use New Version "use-icons"
New version of the library has migrated to the Use-Icons
future
之后版本 - 可以运行在游览器环境
feature
can build font's file
- .woff2 browser chrome、firefox
- .woff browser chrome、firefox
- .ttf browser chrome、firefox、opera、Safari, Android, iOS 4.2+
- .eot browser IE+
- .svg browser iOS 4.1-
Install
npm install --save use-iconfontsdemo
"use strict";
/**
* Created by rocky on 16/7/1.
*/
var fs = require("fs");
var mkdirp = require("mkdirp");
var path = require("path");
var fontBunder = require("use-iconfonts").fontBunder;
//svg dir
var p = __dirname + "/../template/svgs/";
var fb = new fontBunder();
var content = fs.readFileSync(p + "clear.svg", "utf8");
var fonts = [
{
unicode : "e001",
file : p + "add.svg", //test use file path
},
{
unicode : "e002",
content : content,//test use file content
},
{
unicode : "e003",
file : p + "upa.svg",
}
];
// 设置输出是可以生成demo.html 默认为true
fb.setHasDemo(false);
// 设置输出文件格式为zip 默认为true
fb.setIsZip(false);
// 设置css不压缩
fb.setCleanCss(false);
// 重新设置viewBox大小 默认为true
fb.resetViewBoxSize(false);
//开始生成文件
fb.generate(fonts, {
fontName : "myfont" //设置字体名
},function (rs) {
//当setIsZip(false), rs返回一个文件二进制内容数组,否则返回zip文件对象二进制内容
var p = path.normalize(__dirname + "/../out/");
mkdirp.sync(p);
if(rs instanceof Array) {
rs.map(function(val) {
fs.writeFileSync(p + val.name, val.content);
})
} else {
fs.writeFileSync(p + "aa1.zip", rs, "utf8");
}
});document
Api
- setHasDemo(bool)
- boolean set:false 不输出demo例子, Default: true
- setIsZip(bool)
- boolean set:false 不作为zip输出,Default: ture
- setCleanCss(bool)
- boolean set:false 不输出压缩有的css,Default: ture
- resetViewBoxSize(bool)
- boolean set:false 使用默认svg width and height, Default: true, 重新设置viewBox width height
- generate(fontConfings, options, callback)
fontConfigs array
[ { file : "path/file/aaa.svg", //可以输入file文件地址 unicode : "ea01",字体unicode码, }, { content : "svg-content", //也可以输入文件内容 unicode : "ea01",字体unicode码, }, ]options object
- 可以参考svgicons2svgfont.options,中options配置介绍。
- prependUnicode 自动生成unicode, default - false, true - auto unicode
- startUnicode 自动开始编号 start unicode, default - 0xEA01
- fontName 生成的字体模板名称 fontName
- className 生成的字体模板样式名称 className
- iconPrefix 生成字体样式模板的class前缀 如.icon-ea01 (icon为前缀)
- callback function
example
var callback = function (rs) { if(rs instanceof Array) { rs.map(function(val) { fs.writeFileSync(p + val.name, val.content); }) } else { fs.writeFileSync(p + "aa1.zip", rs, "utf8"); } }
use font example
/* 第一步:使用font-face声明字体 */
@font-face {font-family: 'iconfonts';
src: url('iconfonts.eot'); /* IE9*/
src: url('iconfonts.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('iconfonts.woff2') format('woff2'),/* chrome、firefox, the latest version*/
url('iconfonts.woff') format('woff'), /* chrome、firefox */
url('iconfonts.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/
url('iconfonts.svg#iconfont') format('svg'); /* iOS 4.1- */
}
/* 第二步:定义使用iconfont的样式(use iconfont.css) */
.iconfont{
font-family:"iconfont" !important;
font-size:16px;
font-style:normal;
-webkit-font-smoothing: antialiased;
-webkit-text-stroke-width: 0.2px;
-moz-osx-font-smoothing: grayscale;
}
[class*="icon-"]:before{
font-family:"iconfont" !important;
font-style:normal;
-webkit-font-smoothing: antialiased;
-webkit-text-stroke-width: 0.2px;
-moz-osx-font-smoothing: grayscale;
}
/* 第三步:挑选相应图标并获取字体编码,应用于页面
* 1、在支持css3游览器。建议使用
* eg: <div class="icon-eb01"></div>;
* 2、在支持伪类:before,:after游览器下。建议使用
* eg:<div class="iconfont icon-eb01"></div>
* 3、低版本游览器模式(如:IE6,IE7,IE8...)。建议使用
* eg:<div class="iconfont"></div>
*/
<i class="icon-ea01"></i> //support Css3
<i class="iconfont icon-ea01"></i> //support IE9+
<i class="iconfont"></i> //support IE6,7,8author
rockywu wjl19890427@hotmail.com
1.9.15
9 years ago
1.9.14
9 years ago
1.9.13
9 years ago
1.9.12
9 years ago
1.9.11
9 years ago
1.9.10
9 years ago
1.9.9
9 years ago
1.9.8
9 years ago
1.9.7
9 years ago
1.9.6
9 years ago
1.9.5
9 years ago
1.9.4
9 years ago
1.9.3
9 years ago
1.9.2
9 years ago
1.9.1
9 years ago
0.1.37
9 years ago
0.1.36
9 years ago
0.1.35
10 years ago
0.1.34
10 years ago
0.1.33
10 years ago
0.1.32
10 years ago
0.1.31
10 years ago
0.1.30
10 years ago
0.1.29
10 years ago
0.1.28
10 years ago
0.1.27
10 years ago
0.1.26
10 years ago
0.1.25
10 years ago
0.1.24
10 years ago
0.1.23
10 years ago
0.1.22
10 years ago
0.1.21
10 years ago
0.1.20
10 years ago
0.1.19
10 years ago
0.1.18
10 years ago
0.1.17
10 years ago
0.1.16
10 years ago
0.1.15
10 years ago
0.1.13
10 years ago
0.1.12
10 years ago
0.1.8
10 years ago
0.1.7
10 years ago
0.1.6
10 years ago