Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
junmer committed Apr 22, 2015
2 parents 2ec48ad + 183ebc7 commit e46e3c5
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 34 deletions.
23 changes: 13 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
CHANGE LOG
===
# Change Log

## 0.6
## 0.7.3 (2015-04-22)

[+] first pub release
- glyph plugin add option hinting: keep ttf hint info (fpgm, prep, cvt). default = true. [\#4](https://github.com/ecomfe/fontmin/issues/4)

## 0.7
## 0.7.2 (2015-04-20)

[^] plugins option clone as default
- css plugin add option asFileName: rewrite fontFamily as filename force. default = false
- i18n doc zh-tw, jp, kr, en

## 0.7.1
## 0.7.1 (2015-04-20)

[^] css plugin add option fontPath: location of font file
- css plugin add option fontPath: location of font file. [gulp-fontmin\#1](https://github.com/ecomfe/gulp-fontmin/issues/1)

## 0.7.2
## 0.7 (2015-04-16)

[^] css plugin add option asFileName: rewrite fontFamily as filename force. default = false
- plugins option clone as default

## 0.6 (2015-04-13)

- first release
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
## Homepage

- [简体中文](http://ecomfe.github.io/fontmin/)
- [繁體中文](http://ecomfe.github.io/fontmin/tw.html)
- [日本語](http://ecomfe.github.io/fontmin/jp.html)
- [한국어](http://ecomfe.github.io/fontmin/kr.html)
- [English](http://ecomfe.github.io/fontmin/en.html)
- [繁體中文](http://ecomfe.github.io/fontmin/tw)
- [日本語](http://ecomfe.github.io/fontmin/jp)
- [한국어](http://ecomfe.github.io/fontmin/kr)
- [English](http://ecomfe.github.io/fontmin/en)

## Install

Expand Down Expand Up @@ -114,7 +114,8 @@ var Fontmin = require('fontmin');

var fontmin = new Fontmin()
.use(Fontmin.glyph({
text: '天地玄黄 宇宙洪荒'
text: '天地玄黄 宇宙洪荒',
hinting: false // keep ttf hint info (fpgm, prep, cvt). default = true
}));
```

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fontmin",
"version": "0.7.2",
"version": "0.7.3",
"description": "Minify font seamlessly, get required glyph from ttf, convert to ttf, eot, woff, svg",
"main": "index.js",
"keywords": [
Expand Down Expand Up @@ -37,9 +37,9 @@
"b3b": "0.0.1",
"buffer-to-vinyl": "^1.0.0",
"concat-stream": "^1.4.6",
"fonteditor-ttf": "0.0.5",
"fonteditor-ttf": "0.0.8",
"get-stdin": "^4.0.1",
"is-ttf": "^0.2.0",
"is-ttf": "^0.2.1",
"lodash": "^3.2.0",
"meow": "^3.0.0",
"pako": "^0.2.5",
Expand Down
31 changes: 18 additions & 13 deletions plugins/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,18 @@ function listUnicode(unicode) {
}

/**
* ttf数据结构转 icon 数据结构
* convert ttf obj to icon obj
*
* @param {ttfObject} ttf ttfObject对象
* @param {Object} options 选项
* @param {Object} options.iconPrefix icon 前缀
* @param {Object} options.fontFamily fontFamily
* @param {ttfObject} ttf ttfObject
* @param {Object} options icon options
* @param {string=} options.iconPrefix class prefix. default = 'icon'
* @return {Object} icon obj
*/
function ttfobject2icon(ttf, options) {

var glyfList = [];

// glyf 信息
// glyf info
var filtered = ttf.glyf.filter(function (g) {
return g.name !== '.notdef'
&& g.name !== '.null'
Expand All @@ -71,7 +70,6 @@ function ttfobject2icon(ttf, options) {
});

return {
fontFamily: options.fontFamily || ttf.name.fontFamily,
iconPrefix: options.iconPrefix || 'icon',
glyfList: glyfList
};
Expand All @@ -82,9 +80,9 @@ function ttfobject2icon(ttf, options) {
* css fontmin plugin
*
* @param {Object} opts opts
* @param {boolean=} opts.glyph 生成字型 css
* @param {boolean=} opts.base64 生成 base64
* @param {string=} opts.iconPrefix icon 前缀
* @param {boolean=} opts.glyph generate class for each glyph. default = false
* @param {boolean=} opts.base64 inject base64
* @param {string=} opts.iconPrefix icon prefix
* @param {string=} opts.fontFamily fontFamily
* @return {Object} stream.Transform instance
* @api public
Expand Down Expand Up @@ -131,16 +129,23 @@ module.exports = function (opts) {
// opts
_.extend(fontInfo, opts);

// ttf obj
var ttfObject = file.ttfObject || {
name: {}
};

// glyph
if (opts.glyph && file.ttfObject) {
if (opts.glyph && ttfObject.glyf) {
_.extend(
fontInfo,
ttfobject2icon(file.ttfObject, opts)
ttfobject2icon(ttfObject, opts)
);
}

// font family
fontInfo.fontFamily = fontInfo.fontFamily || fontFile;
fontInfo.fontFamily = opts.fontFamily
|| ttfObject.name.fontFamilyfontFile
|| fontFile;

// rewrite font family as filename
if (opts.asFileName) {
Expand Down
8 changes: 5 additions & 3 deletions plugins/glyph.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function minifyTtfObject(ttfObject, text, useBasicText, plugin) {
*/
function minifyTtfBuffer(contents, opts) {

var ttfobj = new TTFReader().read(b2ab(contents));
var ttfobj = new TTFReader(opts).read(b2ab(contents));

var miniObj = minifyTtfObject(
ttfobj,
Expand All @@ -143,7 +143,7 @@ function minifyTtfBuffer(contents, opts) {
opts.use
);

var ttfBuffer = ab2b(new TTFWriter().write(miniObj));
var ttfBuffer = ab2b(new TTFWriter(opts).write(miniObj));

return {
object: miniObj,
Expand All @@ -159,12 +159,14 @@ function minifyTtfBuffer(contents, opts) {
* @param {Object} opts opts
* @param {string=} opts.text text
* @param {boolean=} opts.basicText useBasicText
* @param {boolean=} opts.hinting hint
* @param {Function=} opts.use plugin
* @return {Object} stream.Transform instance
* @api public
*/
module.exports = function (opts) {
opts = opts || {};

opts = _.extend({hinting: true}, opts);

return through.ctor({
objectMode: true
Expand Down
22 changes: 22 additions & 0 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ describe('glyph plugin', function () {
assert(isTtf(getFile(outputFiles, 'ttf').contents));
});

it('output ttf should have `cvt ` table', function () {
assert(
isTtf(
getFile(outputFiles, 'ttf').contents, {
tables: ['cvt ']
}
)
);
});

it('output should miner than input', function () {
var srcBuffer = fs.readFileSync(srcPath);
assert(srcBuffer.length > getFile(outputFiles, 'ttf').contents.length);
Expand Down Expand Up @@ -228,4 +238,16 @@ describe('css plugin', function () {
}
});

it('dest css should have fontPath "./"', function() {
try {
expect(fs.readFileSync(destFile + '.css', {
encoding: 'utf-8'
})).to.have.string('./');
}
catch (ex) {
assert(false);
}
});


});

0 comments on commit e46e3c5

Please sign in to comment.