How to use the fonteditor-core/ttf/reader 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);
        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);
    });
github kekee000 / fonteditor-core / test / spec / ttf / writer.spec.js View on Github external
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);
    });
});
github kekee000 / fonteditor-core / demo / js / ttfTableWriter.js View on Github external
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);
github kekee000 / fonteditor-core / test / spec / ttf / reader.spec.js View on Github external
it('test read extend datatype', function () {
        let reader = new Reader(buffer, 0, 100);
        reader.seek(14);
        assert.equal(reader.readString(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 / demo / js / ttfTableWriter.js View on Github external
console.log('name readed');
    console.log(name);


    let postReader = new Reader(postWriter.getBuffer());
    postTbl.offset = 0;
    ttf.tables = ttf.tables || {};
    ttf.tables.post = {
        length: postWriter.offset
    };
    let post = postTbl.read(postReader, ttf);
    console.log('post readed');
    console.log(post);


    let OS2Reader = new Reader(OS2Writer.getBuffer());
    OS2Tbl.offset = 0;
    let OS2 = OS2Tbl.read(OS2Reader, ttf);
    console.log('OS2 readed');
    console.log(OS2);

    let hheaReader = new Reader(hheaWriter.getBuffer());
    hheaTbl.offset = 0;
    let hhea = hheaTbl.read(hheaReader, ttf);
    console.log('hhea readed');
    console.log(hhea);

    delete ttf.support;
}
github kekee000 / fonteditor-core / demo / js / ttfTableWriter.js View on Github external
length: 1
        }
    };
    ttf.readOptions = {};
    let glyf = glyfTbl.read(glyfReader, ttf);
    console.log('glyf readed');
    console.log(glyf);

    let cmapReader = new Reader(cmapWriter.getBuffer());
    cmapTbl.offset = 0;
    let cmap = cmapTbl.read(cmapReader, ttf);
    console.log('cmap readed');
    console.log(cmap);


    let hmtxReader = new Reader(hmtxWriter.getBuffer());
    hmtxTbl.offset = 0;
    let hmtx = hmtxTbl.read(hmtxReader, ttf);
    console.log('hmtx readed');
    console.log(hmtx);


    let nameReader = new Reader(nameWriter.getBuffer());
    nameTbl.offset = 0;
    let name = nameTbl.read(nameReader, ttf);
    console.log('name readed');
    console.log(name);


    let postReader = new Reader(postWriter.getBuffer());
    postTbl.offset = 0;
    ttf.tables = ttf.tables || {};
github kekee000 / fonteditor-core / demo / js / ttfTableWriter.js View on Github external
ttf.tables = ttf.tables || {};
    ttf.tables.post = {
        length: postWriter.offset
    };
    let post = postTbl.read(postReader, ttf);
    console.log('post readed');
    console.log(post);


    let OS2Reader = new Reader(OS2Writer.getBuffer());
    OS2Tbl.offset = 0;
    let OS2 = OS2Tbl.read(OS2Reader, ttf);
    console.log('OS2 readed');
    console.log(OS2);

    let hheaReader = new Reader(hheaWriter.getBuffer());
    hheaTbl.offset = 0;
    let hhea = hheaTbl.read(hheaReader, ttf);
    console.log('hhea readed');
    console.log(hhea);

    delete ttf.support;
}
github kekee000 / fonteditor-core / demo / js / ttfTableWriter.js View on Github external
let hmtxReader = new Reader(hmtxWriter.getBuffer());
    hmtxTbl.offset = 0;
    let hmtx = hmtxTbl.read(hmtxReader, ttf);
    console.log('hmtx readed');
    console.log(hmtx);


    let nameReader = new Reader(nameWriter.getBuffer());
    nameTbl.offset = 0;
    let name = nameTbl.read(nameReader, ttf);
    console.log('name readed');
    console.log(name);


    let postReader = new Reader(postWriter.getBuffer());
    postTbl.offset = 0;
    ttf.tables = ttf.tables || {};
    ttf.tables.post = {
        length: postWriter.offset
    };
    let post = postTbl.read(postReader, ttf);
    console.log('post readed');
    console.log(post);


    let OS2Reader = new Reader(OS2Writer.getBuffer());
    OS2Tbl.offset = 0;
    let OS2 = OS2Tbl.read(OS2Reader, ttf);
    console.log('OS2 readed');
    console.log(OS2);