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);
// 写入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());
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)));
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
let hheaTbl = new supportTables['hhea']();
let hheaWriter = new Writer(new ArrayBuffer(hheaTbl.size(ttf)));
hheaTbl.write(hheaWriter, 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
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());
let OS2Tbl = new supportTables['OS/2']();
let size = OS2Tbl.size(ttf);
// 写入maxp
let maxpTbl = new supportTables['maxp']();
size = maxpTbl.size(ttf);
let maxpWriter = new Writer(new ArrayBuffer(size));
maxpTbl.write(maxpWriter, ttf);
// 写入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)));