Skip to content

Commit

Permalink
Merge pull request #52 from purplebamboo/ignore-types
Browse files Browse the repository at this point in the history
feat: `convert()` 和 `font.output()` 中的 `types` 选项将自动忽略不支持的格式
  • Loading branch information
yisibl authored May 11, 2021
2 parents ded8df1 + d18c916 commit f48f2e5
Show file tree
Hide file tree
Showing 33 changed files with 425 additions and 1,183 deletions.
18 changes: 11 additions & 7 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# 0.3.0 (2021-05-11)
- `convert()``font.output()` 中的 `types` 选项将自动忽略不支持的格式
- 升级相关依赖
- 更新测试用例,生成 ttx 文件,方便查看升级后的字体变化
- 由于升级的 ttf2woff2 依赖 Node.js >=12.19.0,font-carrier 不再支持小于 12.19.0 的版本
# 0.2.1 (2021-03-16)

* Engine 中的 `convert()` 方法支持转换 ttf 文件(之前只支持 svg 字体)
- Engine 中的 `convert()` 方法支持转换 ttf 文件(之前只支持 svg 字体)

# 0.2.0 (2019-09-06)
* New: 支持配置 svg2ttf 的 options 参数
* Fix: 部分字体基线错位
* Fix: 升级 svgpath,修复 [arcs 解析错误](https://github.com/fontello/svgpath/issues/23)
* Update: 升级除 ttf2svg 以外的所有依赖
* Doc: 增加 MIT LICENSE,增加 changelog.md
- New: 支持配置 svg2ttf 的 options 参数
- Fix: 部分字体基线错位
- Fix: 升级 svgpath,修复 [arcs 解析错误](https://github.com/fontello/svgpath/issues/23)
- Update: 升级除 ttf2svg 以外的所有依赖
- Doc: 增加 MIT LICENSE,增加 changelog.md
4 changes: 2 additions & 2 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var transFont = fontCarrier.transfer('./test/test.ttf')
`font.output(options)`

* options.path 可选。导出的文件路径,不需要后缀
* options.types 可选。导出的字体类型默认是 ['ttf', 'eot', 'woff', woff2, 'svg']
* options.types 可选。导出的字体类型默认是 ['ttf', 'eot', 'woff', woff2, 'svg'],忽略不支持的格式

返回一个对象,包含导出的所有字体的buffer

Expand All @@ -40,7 +40,7 @@ eg.
```js
font.output({
path: './iconfont',
types: [ttf]
types: ['ttf'],
})
```

Expand Down
13 changes: 7 additions & 6 deletions lib/helper/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ fontEngine.parse = (function() {
/**
* 一次性的生成其余几种字体,接受一个svg字体
*
* @param {string|buffer|path} fontBuffer 字体输入可以是路径,buffer对象,string对象
* @param {string} outputTypes 字体输出的类型,默认是所有四种
* @param {string} outputPath 字体的输出路径,不需要带后缀
* @return {array} outFonts 返回转换后的字体buffer数组
* @param {string|buffer|path} fontBuffer 字体输入可以是路径buffer对象,string 对象
* @param {string} outputTypes 字体输出的类型默认是所有四种,忽略其他不支持的格式
* @param {string} outputPath 字体的输出路径不需要带后缀
* @return {array} outFonts 返回转换后的字体 buffer 数组
*/
fontEngine.convert = (function() {

Expand All @@ -272,7 +272,7 @@ fontEngine.convert = (function() {
ttfBuffer = fontEngine.svg2ttf(input, options)
}

_.each(outputTypes, function(type, k) {
_.each(outputTypes, function(type) {
if (type === 'svg') {
result[type] = input
} else {
Expand All @@ -291,9 +291,10 @@ fontEngine.convert = (function() {

return function(options) {
var inputBuffer = _normalizeInput(options.input)

var outputPath = _normalizePath(options.path)
var outputTypes = options.types || ALL_FONTS_TYPES
// 移除不支持的字体格式,防止报错
outputTypes = outputTypes.filter(item => ALL_FONTS_TYPES.includes(item))

if (!inputBuffer) {
helper.showError('font convert input error,support path,buffer,string.please check if the file exist,while the input is a path.')
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"name": "font-carrier",
"version": "0.2.1",
"version": "0.3.0",
"description": "字体搬运工,中文字体解决方案,iconfont",
"main": "./lib/index.js",
"scripts": {
"test": "node ./test/index.js",
"ttx": "ttx -f test/font1.ttf test/font2.ttf test/font3.ttf test/test.ttf"
"ttx": "ttx -f test/font-out/font1.ttf test/font-out/font2.ttf test/font-out/font3.ttf test/font-out/arrow-up.ttf"
},
"author": [
"purplebamboo <[email protected]>",
"yisibl <[email protected]>"
],
"dependencies": {
"lodash": "^4.17.15",
"lodash": "^4.17.21",
"multiline": "^2.0.0",
"opentype.js": "^1.1.0",
"svg2ttf": "^4.3.0",
"svg2ttf": "^5.2.0",
"svg_pathify": "^0.0.8",
"svgpath": "^2.2.2",
"svgpath": "^2.3.1",
"ttf2eot": "^2.0.0",
"ttf2svg": "0.0.7",
"ttf2woff": "^2.0.1",
"ttf2woff2": "^3.0.0",
"ttf2woff": "^2.0.2",
"ttf2woff2": "^4.0.2",
"xmldom": "^0.1.27"
},
"devDependencies": {},
Expand All @@ -30,7 +30,7 @@
"url": "git://github.com/purplebamboo/font-carrier.git"
},
"engines": {
"node": ">= 0.4.x"
"node": ">=12.19.0"
},
"keywords": [
"font",
Expand Down
Binary file added test/font-out/arrow-up.ttf
Binary file not shown.
Loading

0 comments on commit f48f2e5

Please sign in to comment.