split fonteditor-core from fonteditor
This commit is contained in:
@@ -1,221 +0,0 @@
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var lang = require('common/lang');
|
||||
|
||||
describe('测试overwrite', function () {
|
||||
|
||||
it('test normal object', function () {
|
||||
var result = lang.overwrite(
|
||||
{
|
||||
x: 1
|
||||
},
|
||||
{
|
||||
x: 2
|
||||
}
|
||||
);
|
||||
expect(result.x).toBe(2);
|
||||
});
|
||||
|
||||
it('test null object', function () {
|
||||
var result = lang.overwrite(
|
||||
{
|
||||
x: 1
|
||||
},
|
||||
null
|
||||
);
|
||||
expect(result.x).toBe(1);
|
||||
|
||||
var result = lang.overwrite(
|
||||
{
|
||||
x: 1
|
||||
},
|
||||
undefined
|
||||
);
|
||||
expect(result.x).toBe(1);
|
||||
|
||||
var result = lang.overwrite(
|
||||
{
|
||||
x: 1
|
||||
},
|
||||
false
|
||||
);
|
||||
expect(result.x).toBe(1);
|
||||
});
|
||||
|
||||
it('test fields', function () {
|
||||
var result = lang.overwrite(
|
||||
{
|
||||
x: 1
|
||||
},
|
||||
{
|
||||
x: 2
|
||||
},
|
||||
['x']
|
||||
);
|
||||
expect(result.x).toBe(2);
|
||||
|
||||
var result = lang.overwrite(
|
||||
{
|
||||
x: 1
|
||||
},
|
||||
{
|
||||
x: 2
|
||||
},
|
||||
['y']
|
||||
);
|
||||
expect(result.x).toBe(1);
|
||||
|
||||
});
|
||||
|
||||
it('test deep overwrite', function () {
|
||||
var result = lang.overwrite(
|
||||
{
|
||||
level1: {
|
||||
x: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
level1: {
|
||||
y: 3
|
||||
}
|
||||
}
|
||||
);
|
||||
expect(result.level1.y).toBe(3);
|
||||
|
||||
var result = lang.overwrite(
|
||||
{
|
||||
level1: {
|
||||
x: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
level1: {
|
||||
x: 2
|
||||
}
|
||||
}
|
||||
);
|
||||
expect(result.level1.x).toBe(2);
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('test null overwrite', function () {
|
||||
var result = lang.overwrite(
|
||||
{
|
||||
level1: {
|
||||
x: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
level1: {
|
||||
x: null
|
||||
}
|
||||
}
|
||||
);
|
||||
expect(result.level1.x).toBeNull();
|
||||
});
|
||||
|
||||
it('test string overwrite', function () {
|
||||
var result = lang.overwrite(
|
||||
'abcde',
|
||||
{
|
||||
0: 'f'
|
||||
}
|
||||
);
|
||||
expect(result['0']).toBe('a');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('测试equals', function () {
|
||||
|
||||
it('test normal object', function () {
|
||||
var result = lang.equals(
|
||||
{
|
||||
x: 1
|
||||
},
|
||||
{
|
||||
x: 2
|
||||
}
|
||||
);
|
||||
expect(result).toBeFalsy();
|
||||
|
||||
|
||||
var result = lang.equals(
|
||||
{
|
||||
x: null
|
||||
},
|
||||
{
|
||||
x: undefined
|
||||
}
|
||||
);
|
||||
expect(result).toBeFalsy();
|
||||
|
||||
var result = lang.equals(
|
||||
{
|
||||
x: 1
|
||||
},
|
||||
{
|
||||
x: '1'
|
||||
}
|
||||
);
|
||||
expect(result).toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
it('test basic type', function () {
|
||||
var result = lang.equals(
|
||||
null,
|
||||
undefined
|
||||
);
|
||||
expect(result).toBeTruthy();
|
||||
|
||||
var result = lang.equals(
|
||||
1,
|
||||
2
|
||||
);
|
||||
expect(result).toBeFalsy();
|
||||
|
||||
var result = lang.equals(
|
||||
1,
|
||||
'1'
|
||||
);
|
||||
expect(result).toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
it('test deep equals', function () {
|
||||
var result = lang.equals(
|
||||
{
|
||||
level1: {
|
||||
x: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
level1: {
|
||||
y: 1
|
||||
}
|
||||
}
|
||||
);
|
||||
expect(result).toBeFalsy();
|
||||
|
||||
var result = lang.equals(
|
||||
{
|
||||
level1: {
|
||||
x: 1
|
||||
}
|
||||
},
|
||||
{
|
||||
level1: {
|
||||
x: 1
|
||||
}
|
||||
}
|
||||
);
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -7,9 +7,6 @@
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
// common
|
||||
require('./common/lang.spec');
|
||||
|
||||
// math
|
||||
require('./math/getBezierQ2T.spec');
|
||||
|
||||
@@ -17,19 +14,5 @@ define(
|
||||
// graphics
|
||||
require('./graphics/vector.spec');
|
||||
require('./graphics/isSegmentCross.spec');
|
||||
|
||||
// ttf
|
||||
require('./ttf/reader.spec');
|
||||
require('./ttf/writer.spec');
|
||||
require('./ttf/ttfreader.spec');
|
||||
require('./ttf/ttfwriter.spec');
|
||||
require('./ttf/otfreader.spec');
|
||||
require('./ttf/otf2ttfobject.spec');
|
||||
require('./ttf/ttf2woff.spec');
|
||||
require('./ttf/woff2ttf.spec');
|
||||
require('./ttf/ttf2eot.spec');
|
||||
require('./ttf/eot2ttf.spec');
|
||||
require('./ttf/svg2ttfobject.spec');
|
||||
require('./ttf/ttf2svg.spec');
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var TTFReader = require('ttf/ttfreader');
|
||||
var ttf2eot = require('ttf/ttf2eot');
|
||||
var eot2ttf = require('ttf/eot2ttf');
|
||||
|
||||
describe('eot 转 ttf', function () {
|
||||
|
||||
var eotBuffer = ttf2eot(require('data/baiduHealth-hinting.ttf'))
|
||||
var ttf = new TTFReader({
|
||||
hinting: true
|
||||
}).read(eot2ttf(eotBuffer));
|
||||
|
||||
it('test read ttf2eot', function () {
|
||||
|
||||
expect(ttf.version).toBe(1);
|
||||
|
||||
expect(ttf.head.magickNumber).toBe(1594834165);
|
||||
expect(ttf.head.unitsPerEm).toBe(512);
|
||||
|
||||
expect(ttf.post.format).toBe(2);
|
||||
expect(ttf.post.underlinePosition).toBe(0);
|
||||
expect(ttf.post.underlineThickness).toBe(0);
|
||||
|
||||
expect(ttf.hhea.advanceWidthMax).toBe(682);
|
||||
expect(ttf.hhea.ascent).toBe(480);
|
||||
expect(ttf.hhea.descent).toBe(-32);
|
||||
|
||||
expect(ttf.maxp.version).toBe(1);
|
||||
expect(ttf.maxp.numGlyphs).toBe(17);
|
||||
|
||||
expect(ttf.glyf[0].advanceWidth).toBe(512);
|
||||
expect(ttf.glyf[0].leftSideBearing).toBe(0);
|
||||
expect(ttf.glyf[0].name).toBe('.notdef');
|
||||
expect(ttf.glyf[3].contours[0].length).toBe(31);
|
||||
|
||||
expect(ttf.cmap[0]).toBe(1);
|
||||
expect(ttf.cmap[57400]).toBe(16);
|
||||
});
|
||||
|
||||
it('test read hinting', function () {
|
||||
expect(ttf.cvt.length).toBe(24);
|
||||
expect(ttf.fpgm.length).toBe(371);
|
||||
expect(ttf.prep.length).toBe(204);
|
||||
expect(ttf.gasp.length).toBe(8);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
@@ -1,31 +0,0 @@
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var OTFReader = require('ttf/otfreader');
|
||||
var otf2ttfobject = require('ttf/otf2ttfobject');
|
||||
|
||||
describe('otf 转ttf object', function () {
|
||||
|
||||
var fontObject = new OTFReader().read(require('data/BalladeContour.otf'));
|
||||
var numGlyphs = fontObject.maxp.numGlyphs;
|
||||
var glyfContours = fontObject.glyf[3].contours.length;
|
||||
var glyfAdvanceWidth = fontObject.glyf[3].advanceWidth;
|
||||
var glyfLeftSideBearing = fontObject.glyf[3].leftSideBearing;
|
||||
|
||||
|
||||
var ttfObject = otf2ttfobject(fontObject);
|
||||
|
||||
it('test otf2ttfobject', function () {
|
||||
expect(ttfObject.version).toBe(1);
|
||||
expect(!!ttfObject.CFF).toBe(false);
|
||||
expect(!!ttfObject.VORG).toBe(false);
|
||||
expect(ttfObject.glyf.length).toBe(numGlyphs);
|
||||
expect(ttfObject.glyf[3].contours.length).toBe(glyfContours);
|
||||
expect(ttfObject.glyf[3].advanceWidth).toBe(glyfAdvanceWidth);
|
||||
expect(ttfObject.glyf[3].leftSideBearing).toBe(glyfLeftSideBearing);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
@@ -1,81 +0,0 @@
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var OTFReader = require('ttf/otfreader');
|
||||
|
||||
describe('读otf数据', function () {
|
||||
|
||||
var fontObject = new OTFReader().read(require('data/BalladeContour.otf'));
|
||||
|
||||
it('test read otf', function () {
|
||||
expect(fontObject.version).toBe('OTTO');
|
||||
expect(fontObject.numTables).toBe(9);
|
||||
expect(fontObject.rengeShift).toBe(16);
|
||||
expect(fontObject.searchRenge).toBe(128);
|
||||
});
|
||||
|
||||
it('test read otf head', function () {
|
||||
expect(fontObject.head.magickNumber).toBe(1594834165);
|
||||
expect(fontObject.head.unitsPerEm).toBe(1000);
|
||||
expect(fontObject.head.checkSumAdjustment).toBe(2157456233);
|
||||
});
|
||||
|
||||
it('test read otf name', function () {
|
||||
expect(fontObject.name.fontFamily).toBe('Ballade Contour');
|
||||
expect(fontObject.name.fontSubFamily).toBe('Regular');
|
||||
expect(fontObject.name.fullName).toBe('BalladeContour');
|
||||
});
|
||||
|
||||
|
||||
it('test read otf post', function () {
|
||||
expect(fontObject.post.format).toBe(3);
|
||||
expect(fontObject.post.underlinePosition).toBe(-75);
|
||||
expect(fontObject.post.underlineThickness).toBe(50);
|
||||
});
|
||||
|
||||
it('test read otf hhea', function () {
|
||||
expect(fontObject.hhea.advanceWidthMax).toBe(1081);
|
||||
expect(fontObject.hhea.ascent).toBe(758);
|
||||
expect(fontObject.hhea.descent).toBe(-146);
|
||||
});
|
||||
|
||||
it('test read otf maxp', function () {
|
||||
expect(fontObject.maxp.version).toBe(0.3125);
|
||||
expect(fontObject.maxp.numGlyphs).toBe(47);
|
||||
});
|
||||
|
||||
it('test read otf glyf', function () {
|
||||
expect(fontObject.glyf[0].advanceWidth).toBe(500);
|
||||
expect(fontObject.glyf[3].contours[0].length).toBe(96);
|
||||
});
|
||||
|
||||
it('test read otf CFF', function () {
|
||||
expect(!!fontObject.CFF).toBe(true);
|
||||
expect(fontObject.CFF.defaultWidthX).toBe(500);
|
||||
expect(fontObject.CFF.nominalWidthX).toBe(708);
|
||||
expect(fontObject.CFF.topDict.uniqueId).toBe(308228);
|
||||
expect(fontObject.CFF.topDict.familyName).toBe('Ballade Contour');
|
||||
expect(fontObject.CFF.topDict.weight).toBe('Normal');
|
||||
expect(fontObject.CFF.topDict.underlineThickness).toBe(50);
|
||||
expect(fontObject.CFF.topDict.underlinePosition).toBe(-100);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('读错误otf数据', function () {
|
||||
|
||||
it('test read version error', function () {
|
||||
expect(function () {
|
||||
new OTFReader().read(new Uint8Array([0, 1, 0, 0, 25, 4, 11]).buffer);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('test read range error', function () {
|
||||
expect(function () {
|
||||
new OTFReader().read(new Uint8Array([0, 1, 0, 0, 0, 10, 11, 45, 8]).buffer);
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -1,50 +0,0 @@
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var Writer = require('ttf/writer');
|
||||
var Reader = require('ttf/reader');
|
||||
|
||||
describe('读数据', function () {
|
||||
var buffer = new ArrayBuffer(100);
|
||||
var writer = new Writer(buffer, 0, 100);
|
||||
var now = Math.round(new Date().getTime() / 1000) * 1000;
|
||||
|
||||
// 基本类型
|
||||
writer.writeInt8(10);
|
||||
writer.writeInt16(2442);
|
||||
writer.writeInt32(-10);
|
||||
writer.writeUint8(10);
|
||||
writer.writeUint16(2442);
|
||||
writer.writeUint32(5375673);
|
||||
// 扩展类型
|
||||
writer.writeString('baidu');
|
||||
writer.writeFixed(12.36);
|
||||
writer.writeLongDateTime(now);
|
||||
writer.writeBytes([3, 4, 5]);
|
||||
|
||||
|
||||
|
||||
it('test read basic datatype', function () {
|
||||
var reader = new Reader(buffer, 0, 100);
|
||||
expect(reader.readInt8()).toBe(10);
|
||||
expect(reader.readInt16()).toBe(2442);
|
||||
expect(reader.readInt32()).toBe(-10);
|
||||
expect(reader.readUint8()).toBe(10);
|
||||
expect(reader.readUint16()).toBe(2442);
|
||||
expect(reader.readUint32()).toBe(5375673);
|
||||
});
|
||||
|
||||
it('test read extend datatype', function () {
|
||||
var reader = new Reader(buffer, 0, 100);
|
||||
reader.seek(14);
|
||||
expect(reader.readString(5)).toEqual('baidu');
|
||||
expect(reader.readFixed()).toBeCloseTo(12.36, 2);
|
||||
expect(reader.readLongDateTime().getTime()).toEqual(now);
|
||||
expect(reader.readBytes(3)).toEqual([3, 4, 5]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
@@ -1,50 +0,0 @@
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var svg2ttfobject = require('ttf/svg2ttfobject');
|
||||
|
||||
describe('svg转ttf对象', function () {
|
||||
|
||||
var ttfObject = svg2ttfobject(require('data/iconfont-xin.svg'));
|
||||
|
||||
it('test svg glyf', function () {
|
||||
expect(ttfObject.from).toBe('svg');
|
||||
expect(ttfObject.glyf.length).toBe(1);
|
||||
expect(ttfObject.glyf[0].contours.length).toBe(7);
|
||||
});
|
||||
|
||||
var fontObject = svg2ttfobject(require('data/icomoon.svg'));
|
||||
|
||||
it('test svg font', function () {
|
||||
expect(fontObject.from).toBe('svgfont');
|
||||
expect(fontObject.id).toBe('icomoon');
|
||||
expect(fontObject.name.fontFamily).toBe('icomoon');
|
||||
expect(fontObject.metadata).toBe('Generated by IcoMoon');
|
||||
});
|
||||
|
||||
it('test svg font glyf', function () {
|
||||
expect(fontObject.glyf.length).toBe(3);
|
||||
expect(fontObject.glyf[2].leftSideBearing).toBe(0);
|
||||
expect(fontObject.glyf[2].advanceWidth).toBe(1024);
|
||||
expect(fontObject.glyf[2].contours.length).toBe(7);
|
||||
expect(fontObject.glyf[2].unicode[0]).toBe(57345);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('读错误svg数据', function () {
|
||||
|
||||
it('test read svg error', function () {
|
||||
expect(function () {
|
||||
svg2ttfobject('');
|
||||
}).toThrow();
|
||||
|
||||
expect(function () {
|
||||
svg2ttfobject('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg></svg>');
|
||||
}).toThrow();
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -1,50 +0,0 @@
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var TTFReader = require('ttf/ttfreader');
|
||||
var ttf2eot = require('ttf/ttf2eot');
|
||||
var eot2ttf = require('ttf/eot2ttf');
|
||||
|
||||
describe('ttf 转 eot', function () {
|
||||
|
||||
var eotBuffer = ttf2eot(require('data/baiduHealth.ttf'))
|
||||
|
||||
it('test woff format', function () {
|
||||
expect(eotBuffer.byteLength).toBeGreaterThan(1000);
|
||||
expect(eotBuffer.byteLength).toBeLessThan(10000);
|
||||
});
|
||||
|
||||
it('test read ttf2eot', function () {
|
||||
var ttf = new TTFReader().read(eot2ttf(eotBuffer));
|
||||
|
||||
expect(ttf.version).toBe(1);
|
||||
|
||||
expect(ttf.head.magickNumber).toBe(1594834165);
|
||||
expect(ttf.head.unitsPerEm).toBe(512);
|
||||
|
||||
expect(ttf.post.format).toBe(2);
|
||||
expect(ttf.post.underlinePosition).toBe(0);
|
||||
expect(ttf.post.underlineThickness).toBe(0);
|
||||
|
||||
expect(ttf.hhea.advanceWidthMax).toBe(682);
|
||||
expect(ttf.hhea.ascent).toBe(480);
|
||||
expect(ttf.hhea.descent).toBe(-33);
|
||||
|
||||
expect(ttf.maxp.version).toBe(1);
|
||||
expect(ttf.maxp.numGlyphs).toBe(17);
|
||||
|
||||
expect(ttf.glyf[0].advanceWidth).toBe(512);
|
||||
expect(ttf.glyf[0].leftSideBearing).toBe(0);
|
||||
expect(ttf.glyf[0].name).toBe('.notdef');
|
||||
expect(ttf.glyf[3].contours[0].length).toBe(31);
|
||||
expect(ttf.glyf[16].compound).toBe(true);
|
||||
expect(ttf.glyf[16].glyfs.length).toBe(2);
|
||||
|
||||
expect(ttf.cmap[0]).toBe(1);
|
||||
expect(ttf.cmap[57400]).toBe(16);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
@@ -1,37 +0,0 @@
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var TTFReader = require('ttf/ttfreader');
|
||||
var ttf2svg = require('ttf/ttf2svg');
|
||||
var svg2ttfobject = require('ttf/svg2ttfobject');
|
||||
|
||||
describe('ttf 转 eot', function () {
|
||||
|
||||
var fontObject = new TTFReader().read(require('data/baiduHealth.ttf'));
|
||||
var svg = ttf2svg(fontObject);
|
||||
var ttf = svg2ttfobject(svg);
|
||||
|
||||
it('test genrate svg font', function () {
|
||||
expect(svg.length).toBeGreaterThan(1000);
|
||||
});
|
||||
|
||||
it('test read svg font', function () {
|
||||
expect(ttf.from).toBe('svgfont');
|
||||
expect(ttf.name.fontFamily).toBe('baiduHealth');
|
||||
|
||||
expect(ttf.head.unitsPerEM).toBe(fontObject.head.unitsPerEM);
|
||||
expect(ttf.head.xMax).toBe(fontObject.head.xMax);
|
||||
expect(ttf.head.yMax).toBe(fontObject.head.yMax);
|
||||
|
||||
expect(ttf.hhea.ascent).toBe(fontObject.hhea.ascent);
|
||||
expect(ttf.hhea.descent).toBe(fontObject.hhea.descent);
|
||||
|
||||
expect(ttf.glyf.length).toBe(14);
|
||||
expect(ttf.glyf[3].contours.length).toBe(3);
|
||||
expect(ttf.glyf[3].unicode[0]).toBe(57357);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
@@ -1,50 +0,0 @@
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var TTFReader = require('ttf/ttfreader');
|
||||
var ttf2woff = require('ttf/ttf2woff');
|
||||
var woff2ttf = require('ttf/woff2ttf');
|
||||
|
||||
describe('ttf 转 woff', function () {
|
||||
|
||||
var woffBuffer = ttf2woff(require('data/baiduHealth.ttf'))
|
||||
|
||||
it('test woff format', function () {
|
||||
expect(woffBuffer.byteLength).toBeGreaterThan(1000);
|
||||
expect(woffBuffer.byteLength).toBeLessThan(10000);
|
||||
});
|
||||
|
||||
it('test read ttf2woff', function () {
|
||||
var ttf = new TTFReader().read(woff2ttf(woffBuffer));
|
||||
|
||||
expect(ttf.version).toBe(1);
|
||||
|
||||
expect(ttf.head.magickNumber).toBe(1594834165);
|
||||
expect(ttf.head.unitsPerEm).toBe(512);
|
||||
|
||||
expect(ttf.post.format).toBe(2);
|
||||
expect(ttf.post.underlinePosition).toBe(0);
|
||||
expect(ttf.post.underlineThickness).toBe(0);
|
||||
|
||||
expect(ttf.hhea.advanceWidthMax).toBe(682);
|
||||
expect(ttf.hhea.ascent).toBe(480);
|
||||
expect(ttf.hhea.descent).toBe(-33);
|
||||
|
||||
expect(ttf.maxp.version).toBe(1);
|
||||
expect(ttf.maxp.numGlyphs).toBe(17);
|
||||
|
||||
expect(ttf.glyf[0].advanceWidth).toBe(512);
|
||||
expect(ttf.glyf[0].leftSideBearing).toBe(0);
|
||||
expect(ttf.glyf[0].name).toBe('.notdef');
|
||||
expect(ttf.glyf[3].contours[0].length).toBe(31);
|
||||
expect(ttf.glyf[16].compound).toBe(true);
|
||||
expect(ttf.glyf[16].glyfs.length).toBe(2);
|
||||
|
||||
expect(ttf.cmap[0]).toBe(1);
|
||||
expect(ttf.cmap[57400]).toBe(16);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
@@ -1,105 +0,0 @@
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var TTFReader = require('ttf/ttfreader');
|
||||
|
||||
describe('读ttf数据', function () {
|
||||
|
||||
var fontObject = new TTFReader().read(require('data/baiduHealth.ttf'));
|
||||
|
||||
it('test read ttf', function () {
|
||||
expect(fontObject.version).toBe(1);
|
||||
expect(fontObject.numTables).toBe(15);
|
||||
expect(fontObject.rengeShift).toBe(112);
|
||||
expect(fontObject.searchRenge).toBe(128);
|
||||
});
|
||||
|
||||
it('test read ttf head', function () {
|
||||
expect(fontObject.head.magickNumber).toBe(1594834165);
|
||||
expect(fontObject.head.unitsPerEm).toBe(512);
|
||||
expect(fontObject.head.checkSumAdjustment).toBe(541516270);
|
||||
});
|
||||
|
||||
it('test read ttf name', function () {
|
||||
expect(fontObject.name.fontFamily).toBe('baiduHealth');
|
||||
expect(fontObject.name.fontSubFamily).toBe('Regular');
|
||||
expect(fontObject.name.fullName).toBe('baiduHealth');
|
||||
});
|
||||
|
||||
|
||||
it('test read ttf post', function () {
|
||||
expect(fontObject.post.format).toBe(2);
|
||||
expect(fontObject.post.underlinePosition).toBe(0);
|
||||
expect(fontObject.post.underlineThickness).toBe(0);
|
||||
});
|
||||
|
||||
it('test read ttf hhea', function () {
|
||||
expect(fontObject.hhea.advanceWidthMax).toBe(682);
|
||||
expect(fontObject.hhea.ascent).toBe(480);
|
||||
expect(fontObject.hhea.descent).toBe(-33);
|
||||
});
|
||||
|
||||
it('test read ttf maxp', function () {
|
||||
expect(fontObject.maxp.version).toBe(1);
|
||||
expect(fontObject.maxp.numGlyphs).toBe(17);
|
||||
});
|
||||
|
||||
it('test read ttf glyf', function () {
|
||||
expect(fontObject.glyf[0].advanceWidth).toBe(512);
|
||||
expect(fontObject.glyf[0].leftSideBearing).toBe(0);
|
||||
expect(fontObject.glyf[0].name).toBe('.notdef');
|
||||
expect(fontObject.glyf[3].contours[0].length).toBe(31);
|
||||
expect(fontObject.glyf[16].compound).toBe(true);
|
||||
expect(fontObject.glyf[16].glyfs.length).toBe(2);
|
||||
});
|
||||
|
||||
it('test read ttf cmap', function () {
|
||||
expect(fontObject.cmap[0]).toBe(1);
|
||||
expect(fontObject.cmap[57400]).toBe(16);
|
||||
});
|
||||
});
|
||||
|
||||
describe('转换compound到simple', function () {
|
||||
|
||||
var fontObject = new TTFReader({
|
||||
compound2simple: true
|
||||
}).read(require('data/baiduHealth.ttf'));
|
||||
|
||||
it('test read ttf glyf', function () {
|
||||
expect(!!fontObject.glyf[16].compound).toBe(false);
|
||||
expect(!!fontObject.glyf[16].glyfs).toBe(false);
|
||||
expect(fontObject.glyf[16].contours.length).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('读ttf hinting数据', function () {
|
||||
var fontObject = new TTFReader({
|
||||
hinting: true
|
||||
}).read(require('data/baiduHealth-hinting.ttf'));
|
||||
|
||||
it('test read hinting', function () {
|
||||
expect(fontObject.cvt.length).toBe(24);
|
||||
expect(fontObject.fpgm.length).toBe(371);
|
||||
expect(fontObject.prep.length).toBe(204);
|
||||
expect(fontObject.gasp.length).toBe(8);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('读错误ttf数据', function () {
|
||||
|
||||
it('test read version error', function () {
|
||||
expect(function () {
|
||||
new TTFReader().read(new Uint8Array([0, 1, 0, 0, 25, 4, 11]).buffer);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('test read range error', function () {
|
||||
expect(function () {
|
||||
new TTFReader().read(new Uint8Array([0, 1, 0, 0, 0, 10, 11, 45, 8]).buffer);
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -1,93 +0,0 @@
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var lang = require('common/lang');
|
||||
var TTFReader = require('ttf/ttfreader');
|
||||
var TTFWriter = require('ttf/ttfwriter');
|
||||
|
||||
|
||||
describe('写ttf数据', function () {
|
||||
|
||||
var fontObject = new TTFReader().read(require('data/baiduHealth.ttf'));
|
||||
|
||||
it('test write ttf', function () {
|
||||
var buffer = new TTFWriter().write(fontObject);
|
||||
expect(buffer.byteLength).toBeGreaterThan(1000);
|
||||
expect(buffer.byteLength).toBeLessThan(10000);
|
||||
|
||||
var ttf = new TTFReader().read(buffer);
|
||||
|
||||
expect(ttf.version).toBe(1);
|
||||
|
||||
expect(ttf.head.magickNumber).toBe(1594834165);
|
||||
expect(ttf.head.unitsPerEm).toBe(512);
|
||||
|
||||
expect(ttf.post.format).toBe(2);
|
||||
expect(ttf.post.underlinePosition).toBe(0);
|
||||
expect(ttf.post.underlineThickness).toBe(0);
|
||||
|
||||
expect(ttf.hhea.advanceWidthMax).toBe(682);
|
||||
expect(ttf.hhea.ascent).toBe(480);
|
||||
expect(ttf.hhea.descent).toBe(-33);
|
||||
|
||||
expect(ttf.maxp.version).toBe(1);
|
||||
expect(ttf.maxp.numGlyphs).toBe(17);
|
||||
|
||||
expect(ttf.glyf[0].advanceWidth).toBe(512);
|
||||
expect(ttf.glyf[0].leftSideBearing).toBe(0);
|
||||
expect(ttf.glyf[0].name).toBe('.notdef');
|
||||
expect(ttf.glyf[3].contours[0].length).toBe(31);
|
||||
expect(ttf.glyf[16].compound).toBe(true);
|
||||
expect(ttf.glyf[16].glyfs.length).toBe(2);
|
||||
|
||||
expect(ttf.cmap[0]).toBe(1);
|
||||
expect(ttf.cmap[57400]).toBe(16);
|
||||
|
||||
});
|
||||
|
||||
it('test write ttf error', function () {
|
||||
expect(function () {
|
||||
var ttf = lang.extend({}, fontObject);
|
||||
ttf.head = null;
|
||||
new TTFWriter().write(ttf);
|
||||
}).toThrow();
|
||||
|
||||
expect(function () {
|
||||
var ttf = lang.extend({}, fontObject);
|
||||
ttf.glyf.length = 0;
|
||||
new TTFWriter().write(ttf);
|
||||
}).toThrow();
|
||||
|
||||
expect(function () {
|
||||
var ttf = lang.extend({}, fontObject);
|
||||
ttf.name = null;
|
||||
new TTFWriter().write(ttf);
|
||||
}).toThrow();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('写ttf hinting数据', function () {
|
||||
|
||||
var fontObject = new TTFReader({
|
||||
hinting: true
|
||||
}).read(require('data/baiduHealth-hinting.ttf'));
|
||||
|
||||
it('test write ttf hinting', function () {
|
||||
var buffer = new TTFWriter({
|
||||
hinting: true
|
||||
}).write(fontObject);
|
||||
expect(buffer.byteLength).toBeGreaterThan(1000);
|
||||
expect(buffer.byteLength).toBeLessThan(10000);
|
||||
|
||||
var ttf = new TTFReader().read(buffer);
|
||||
expect(fontObject.cvt.length).toBe(24);
|
||||
expect(fontObject.fpgm.length).toBe(371);
|
||||
expect(fontObject.prep.length).toBe(204);
|
||||
expect(fontObject.gasp.length).toBe(8);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -1,53 +0,0 @@
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var TTFReader = require('ttf/ttfreader');
|
||||
var ttf2woff = require('ttf/ttf2woff');
|
||||
var woff2ttf = require('ttf/woff2ttf');
|
||||
|
||||
describe('woff 转 ttf', function () {
|
||||
|
||||
var woffBuffer = ttf2woff(require('data/baiduHealth-hinting.ttf'))
|
||||
var ttf = new TTFReader({
|
||||
hinting: true
|
||||
}).read(woff2ttf(woffBuffer));
|
||||
|
||||
it('test read ttf2woff', function () {
|
||||
|
||||
expect(ttf.version).toBe(1);
|
||||
|
||||
expect(ttf.head.magickNumber).toBe(1594834165);
|
||||
expect(ttf.head.unitsPerEm).toBe(512);
|
||||
|
||||
expect(ttf.post.format).toBe(2);
|
||||
expect(ttf.post.underlinePosition).toBe(0);
|
||||
expect(ttf.post.underlineThickness).toBe(0);
|
||||
|
||||
expect(ttf.hhea.advanceWidthMax).toBe(682);
|
||||
expect(ttf.hhea.ascent).toBe(480);
|
||||
expect(ttf.hhea.descent).toBe(-32);
|
||||
|
||||
expect(ttf.maxp.version).toBe(1);
|
||||
expect(ttf.maxp.numGlyphs).toBe(17);
|
||||
|
||||
expect(ttf.glyf[0].advanceWidth).toBe(512);
|
||||
expect(ttf.glyf[0].leftSideBearing).toBe(0);
|
||||
expect(ttf.glyf[0].name).toBe('.notdef');
|
||||
expect(ttf.glyf[3].contours[0].length).toBe(31);
|
||||
|
||||
expect(ttf.cmap[0]).toBe(1);
|
||||
expect(ttf.cmap[57400]).toBe(16);
|
||||
});
|
||||
|
||||
it('test read hinting', function () {
|
||||
expect(ttf.cvt.length).toBe(24);
|
||||
expect(ttf.fpgm.length).toBe(371);
|
||||
expect(ttf.prep.length).toBe(204);
|
||||
expect(ttf.gasp.length).toBe(8);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
@@ -1,97 +0,0 @@
|
||||
|
||||
define(
|
||||
function (require) {
|
||||
|
||||
var Writer = require('ttf/writer');
|
||||
var Reader = require('ttf/reader');
|
||||
|
||||
describe('写基本数据', function () {
|
||||
|
||||
var buffer = new ArrayBuffer(100);
|
||||
|
||||
it('test write basic datatype', function () {
|
||||
var writer = new Writer(buffer, 0, 100);
|
||||
|
||||
// 基本类型
|
||||
writer.writeInt8(10);
|
||||
writer.writeInt16(2442);
|
||||
writer.writeInt32(-10);
|
||||
writer.writeUint8(10);
|
||||
writer.writeUint16(2442);
|
||||
writer.writeUint32(5375673);
|
||||
|
||||
writer.writeUint8(55.45444444);
|
||||
writer.writeUint16(55.45444444);
|
||||
writer.writeUint32(55.45444444);
|
||||
|
||||
var reader = new Reader(buffer, 0, 100);
|
||||
|
||||
expect(reader.readInt8()).toBe(10);
|
||||
expect(reader.readInt16()).toBe(2442);
|
||||
expect(reader.readInt32()).toBe(-10);
|
||||
expect(reader.readUint8()).toBe(10);
|
||||
expect(reader.readUint16()).toBe(2442);
|
||||
expect(reader.readUint32()).toBe(5375673);
|
||||
|
||||
expect(reader.readUint8()).toBe(55);
|
||||
expect(reader.readUint16()).toBe(55);
|
||||
expect(reader.readUint32()).toBe(55);
|
||||
});
|
||||
|
||||
it('test write decimals', function () {
|
||||
var writer = new Writer(buffer, 0, 100);
|
||||
|
||||
// 基本类型
|
||||
writer.writeInt8(-55.99999);
|
||||
writer.writeInt16(-55.99999);
|
||||
writer.writeInt32(-55.999999);
|
||||
|
||||
writer.writeUint8(55.45444444);
|
||||
writer.writeUint16(55.45444444);
|
||||
writer.writeUint32(55.45444444);
|
||||
|
||||
var reader = new Reader(buffer, 0, 100);
|
||||
|
||||
|
||||
expect(reader.readInt8()).toBe(-55);
|
||||
expect(reader.readInt16()).toBe(-55);
|
||||
expect(reader.readInt32()).toBe(-55);
|
||||
|
||||
expect(reader.readUint8()).toBe(55);
|
||||
expect(reader.readUint16()).toBe(55);
|
||||
expect(reader.readUint32()).toBe(55);
|
||||
});
|
||||
|
||||
|
||||
it('test write extend datatype', function () {
|
||||
var writer = new Writer(buffer, 0, 100);
|
||||
var now = Math.round(new Date().getTime() / 1000) * 1000;
|
||||
|
||||
// 扩展类型
|
||||
writer.writeString('baidu');
|
||||
writer.writeFixed(12.36);
|
||||
writer.writeLongDateTime(now);
|
||||
writer.writeBytes([3, 4, 5]);
|
||||
|
||||
var reader = new Reader(buffer, 0, 100);
|
||||
|
||||
expect(reader.readString(0, 5)).toEqual('baidu');
|
||||
expect(reader.readFixed()).toBeCloseTo(12.36, 2);
|
||||
expect(reader.readLongDateTime().getTime()).toEqual(now);
|
||||
expect(reader.readBytes(3)).toEqual([3, 4, 5]);
|
||||
});
|
||||
|
||||
it('test seek', function () {
|
||||
var writer = new Writer(buffer, 0, 100);
|
||||
// 测试seek
|
||||
writer.seek(50);
|
||||
writer.writeFixed(12.36);
|
||||
|
||||
var reader = new Reader(buffer, 0, 100);
|
||||
reader.seek(50);
|
||||
expect(reader.readFixed()).toBeCloseTo(12.36, 2);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user