How to use the fonteditor-core/ttf/writer function in fonteditor-core

To help you get started, we’ve selected a few fonteditor-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kekee000 / fonteditor-core / test / spec / ttf / writer.spec.js View on Github external
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]);
    });
github kekee000 / fonteditor-core / test / spec / ttf / writer.spec.js View on Github external
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);
github kekee000 / fonteditor-core / demo / js / ttfTableWriter.js View on Github external
// 写入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());
github kekee000 / fonteditor-core / demo / js / ttfTableWriter.js View on Github external
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
github kekee000 / fonteditor-core / demo / js / ttfTableWriter.js View on Github external
// 写入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)));
github kekee000 / fonteditor-core / demo / js / ttfTableWriter.js View on Github external
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);


    // 读取测试
github kekee000 / fonteditor-core / demo / js / ttfTableWriter.js View on Github external
// 写入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());
github kekee000 / fonteditor-core / demo / js / ttfTableWriter.js View on Github external
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)));