commit 1b99c33beb7fb03bdd1c2816187355e4efb42fce Author: jebbs Date: Mon Jun 11 17:06:22 2018 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..7192523 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +out +node_modules +.DS_Store diff --git a/index.js b/index.js new file mode 100644 index 0000000..3a67e8a --- /dev/null +++ b/index.js @@ -0,0 +1,50 @@ +// 待抽取字体的汉字 +var text = ''; +// 输入字体路径 +var sourceFontFile = 'input.ttf'; +// 输出字体名称 +var outputFontFile = 'output'; + +var fs = require('fs'); +var path = require('path'); +const outDir = 'out'; + +if (!fs.existsSync(outDir)) fs.mkdirSync(outDir); + +var fontCarrier = require('font-carrier'); +var transFont = fontCarrier.transfer(sourceFontFile); + +// 创建目标字体 +var font = fontCarrier.create(); + +// 向字体中写入抽取的字形信息 +if (text.length === 1) + font.setGlyph(text, transFont.getGlyph(text)); +else + font.setGlyph(transFont.getGlyph(text)); + +// 将字体写入文件 +font.output({ + path: path.join(outDir, outputFontFile) +}); + +var testFile=` + + +

Make sure following text is displayed as expected:

+

+ ${text} +

+ + +` +fs.writeFileSync(path.join(outDir, 'test.htm'),testFile); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..6865ecc --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "font", + "version": "1.0.0", + "description": "", + "main": "index.js", + "author": "", + "license": "MIT", + "dependencies": { + "font-carrier": "0.0.12" + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..1d0fcf8 --- /dev/null +++ b/readme.md @@ -0,0 +1,26 @@ +# 关于 + +此项目用于精简 web 项目的字体。 + +## 如何使用 + +#### 修改 index.js,将以下三个变量按实际需要配置: + +```js +// 待抽取字体的字符 +var text = '待抽取字体的字符'; +// 输入字体路径 +var sourceFontFile = 'input.ttf'; +// 输出字体名称 +var outputFontFile = 'output'; +``` + +#### 执行这个文件 + +```sh +node "index.js" +``` + +#### 检查输出 + +前往`out`目录,打开`test.htm`,检查所需的字符是否正常显示。若正常,out 目录下的文件即为精简后的字体。 \ No newline at end of file