Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('test write extend datatype', function () {
let writer = new Writer(buffer, 0, 100);
let now = Math.round(new Date().getTime() / 1000) * 1000;
// 扩展类型
writer.writeString('baidu');
writer.writeFixed(12.36);
writer.writeLongDateTime(now);
writer.writeBytes([3, 4, 5]);
let reader = new Reader(buffer, 0, 100);
assert.equal(reader.readString(0, 5), 'baidu');
assert.equal(reader.readFixed().toFixed(2), 12.36);
assert.equal(reader.readLongDateTime().getTime(), now);
assert.deepEqual(reader.readBytes(3), [3, 4, 5]);
});
it('test write basic datatype', function () {
let 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);
let reader = new Reader(buffer, 0, 100);
assert.equal(reader.readInt8(), 10);
assert.equal(reader.readInt16(), 2442);
assert.equal(reader.readInt32(), -10);
assert.equal(reader.readUint8(), 10);
assert.equal(reader.readUint16(), 2442);
assert.equal(reader.readUint32(), 5375673);
assert.equal(reader.readUint8(), 55);
assert.equal(reader.readUint16(), 55);
assert.equal(reader.readUint32(), 55);
});
it('test seek', function () {
let writer = new Writer(buffer, 0, 100);
// 测试seek
writer.seek(50);
writer.writeFixed(12.36);
let reader = new Reader(buffer, 0, 100);
reader.seek(50);
assert.equal(reader.readFixed().toFixed(2), 12.36);
});
});
it('test write extend datatype', function () {
let writer = new Writer(buffer, 0, 100);
let now = Math.round(new Date().getTime() / 1000) * 1000;
// 扩展类型
writer.writeString('baidu');
writer.writeFixed(12.36);
writer.writeLongDateTime(now);
writer.writeBytes([3, 4, 5]);
let reader = new Reader(buffer, 0, 100);
assert.equal(reader.readString(0, 5), 'baidu');
assert.equal(reader.readFixed().toFixed(2), 12.36);
assert.equal(reader.readLongDateTime().getTime(), now);
assert.deepEqual(reader.readBytes(3), [3, 4, 5]);
});
it('test write basic datatype', function () {
let 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);
let reader = new Reader(buffer, 0, 100);
assert.equal(reader.readInt8(), 10);
OS2Tbl.write(OS2Writer, ttf);
// 写入hhea
let hheaTbl = new supportTables['hhea']();
let hheaWriter = new Writer(new ArrayBuffer(hheaTbl.size(ttf)));
hheaTbl.write(hheaWriter, ttf);
// 读取测试
let maxpReader = new Reader(maxpWriter.getBuffer());
maxpTbl.offset = 0;
ttf.maxp = maxpTbl.read(maxpReader, ttf);
let locaReader = new Reader(locaWriter.getBuffer());
locaTbl.offset = 0;
ttf.loca = locaTbl.read(locaReader, ttf);
console.log('loca readed');
console.log(ttf.loca);
let glyfReader = new Reader(glyfWriter.getBuffer());
glyfTbl.offset = 0;
ttf.tables = {
glyf: {
length: 1
}
};
ttf.readOptions = {};
let glyf = glyfTbl.read(glyfReader, ttf);
console.log('glyf readed');
console.log(glyf);
// 写入post
let postTbl = new supportTables['post']();
let postWriter = new Writer(new ArrayBuffer(postTbl.size(ttf)));
postTbl.write(postWriter, ttf);
// 写入OS2
OS2Tbl = new supportTables['OS/2']();
let OS2Writer = new Writer(new ArrayBuffer(OS2Tbl.size(ttf)));
OS2Tbl.write(OS2Writer, ttf);
// 写入hhea
let hheaTbl = new supportTables['hhea']();
let hheaWriter = new Writer(new ArrayBuffer(hheaTbl.size(ttf)));
hheaTbl.write(hheaWriter, ttf);
// 读取测试
let maxpReader = new Reader(maxpWriter.getBuffer());
maxpTbl.offset = 0;
ttf.maxp = maxpTbl.read(maxpReader, ttf);
let locaReader = new Reader(locaWriter.getBuffer());
locaTbl.offset = 0;
ttf.loca = locaTbl.read(locaReader, ttf);
console.log('loca readed');
console.log(ttf.loca);
let glyfReader = new Reader(glyfWriter.getBuffer());
onSuccess(binaryData) {
let ttfReader = new TTFReader({
// hinting: true,
subset: [65, 0x160, 0x161, 0x162]
});
let ttfData = ttfReader.read(binaryData);
console.log(ttfData);
},
onError() {
locaTbl.write(locaWriter, ttf);
// 写入cmap
let cmapTbl = new supportTables['cmap']();
let cmapWriter = new Writer(new ArrayBuffer(cmapTbl.size(ttf)));
cmapTbl.write(cmapWriter, ttf);
// 写入hmtx
let hmtxTbl = new supportTables['hmtx']();
let hmtxWriter = new Writer(new ArrayBuffer(hmtxTbl.size(ttf)));
hmtxTbl.write(hmtxWriter, ttf);
// 写入name
let nameTbl = new supportTables['name']();
let nameWriter = new Writer(new ArrayBuffer(nameTbl.size(ttf)));
nameTbl.write(nameWriter, ttf);
// 写入post
let postTbl = new supportTables['post']();
let postWriter = new Writer(new ArrayBuffer(postTbl.size(ttf)));
postTbl.write(postWriter, ttf);
// 写入OS2
OS2Tbl = new supportTables['OS/2']();
let OS2Writer = new Writer(new ArrayBuffer(OS2Tbl.size(ttf)));
OS2Tbl.write(OS2Writer, ttf);
// 写入hhea
// 写入glyf
let glyfTbl = new supportTables['glyf']();
size = glyfTbl.size(ttf);
let glyfWriter = new Writer(new ArrayBuffer(size));
glyfTbl.write(glyfWriter, ttf);
// 写入loca
let locaTbl = new supportTables['loca']();
let locaWriter = new Writer(new ArrayBuffer(locaTbl.size(ttf)));
locaTbl.write(locaWriter, ttf);
// 写入cmap
let cmapTbl = new supportTables['cmap']();
let cmapWriter = new Writer(new ArrayBuffer(cmapTbl.size(ttf)));
cmapTbl.write(cmapWriter, ttf);
// 写入hmtx
let hmtxTbl = new supportTables['hmtx']();
let hmtxWriter = new Writer(new ArrayBuffer(hmtxTbl.size(ttf)));
hmtxTbl.write(hmtxWriter, ttf);
// 写入name
let nameTbl = new supportTables['name']();
let nameWriter = new Writer(new ArrayBuffer(nameTbl.size(ttf)));
nameTbl.write(nameWriter, ttf);
// 写入post
let postTbl = new supportTables['post']();
let postWriter = new Writer(new ArrayBuffer(postTbl.size(ttf)));