Skip to content

Commit

Permalink
remove debug info of woff2
Browse files Browse the repository at this point in the history
  • Loading branch information
kekee000 committed Mar 2, 2020
1 parent d676f12 commit 00233dd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fonteditor-core",
"version": "2.0.7",
"version": "2.1.0",
"description": "fonts (ttf, woff, woff2, eot, svg, otf) parse, write, transform, glyph adjust.",
"keywords": [
"sfnt",
Expand Down Expand Up @@ -34,7 +34,7 @@
}
],
"scripts": {
"publish:npm": "npm run build && npm publish",
"publish:npm": "npm run build && npm publish --registry=https://registry.npmjs.org/",
"test": "./node_modules/.bin/mocha --require @babel/register test/spec/*.spec.js test/spec/**/*.spec.js",
"test:node": "npm run build && ./node_modules/mocha/bin/mocha test/node-spec/**/*.spec.js ",
"dev": "webpack-dev-server --open --config ./config/webpack.dev.js",
Expand Down Expand Up @@ -65,6 +65,7 @@
"css-loader": "^3.2.0",
"html-webpack-plugin": "^3.2.0",
"mocha": "^6.2.1",
"pako": "^1.0.10",
"style-loader": "^1.0.0",
"webpack": "^4.41.1",
"webpack-cli": "^3.3.9",
Expand Down
48 changes: 48 additions & 0 deletions test/spec/ttf/ttf2woff.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {readData} from '../data';
import TTFReader from 'fonteditor-core/ttf/ttfreader';
import ttf2woff from 'fonteditor-core/ttf/ttf2woff';
import woff2ttf from 'fonteditor-core/ttf/woff2ttf';
import pako from 'pako';
import { fstat } from 'fs';

describe('ttf 转 woff', function () {

Expand Down Expand Up @@ -48,3 +50,49 @@ describe('ttf 转 woff', function () {
assert.equal(ttf.cmap[57400], 16);
});
});


describe('ttf 转 woff with deflate', function () {

let woffBuffer = ttf2woff(readData('baiduHealth.ttf'), {
deflate: pako.deflate
});

it('test woff format', function () {
assert.ok(woffBuffer.byteLength > 1000);
assert.ok(woffBuffer.byteLength < 10000);
});
require('fs').writeFileSync('baiduHealth-deflate.woff', Buffer.from(woffBuffer));
it('test read woff', function () {
let ttfBuffer = woff2ttf(woffBuffer, {
inflate: pako.inflate
});
let ttf = new TTFReader().read(ttfBuffer);

assert.equal(ttf.version, 1);

assert.equal(ttf.head.magickNumber, 1594834165);
assert.equal(ttf.head.unitsPerEm, 512);

assert.equal(ttf.post.format, 2);
assert.equal(ttf.post.underlinePosition, 0);
assert.equal(ttf.post.underlineThickness, 0);

assert.equal(ttf.hhea.advanceWidthMax, 682);
assert.equal(ttf.hhea.ascent, 480);
assert.equal(ttf.hhea.descent, -33);

assert.equal(ttf.maxp.version, 1);
assert.equal(ttf.maxp.numGlyphs, 17);

assert.equal(ttf.glyf[0].advanceWidth, 512);
assert.equal(ttf.glyf[0].leftSideBearing, 0);
assert.equal(ttf.glyf[0].name, '.notdef');
assert.equal(ttf.glyf[3].contours[0].length, 31);
assert.equal(ttf.glyf[16].compound, true);
assert.equal(ttf.glyf[16].glyfs.length, 2);

assert.equal(ttf.cmap[0], 1);
assert.equal(ttf.cmap[57400], 16);
});
});
3 changes: 2 additions & 1 deletion woff2/woff2.js

Large diffs are not rendered by default.

Binary file modified woff2/woff2.wasm
Binary file not shown.

0 comments on commit 00233dd

Please sign in to comment.