How to use the fonteditor-core/ttf/ttfwriter 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 / ttfwriter.spec.js View on Github external
it('test write ttf', function () {
        let buffer = new TTFWriter().write(fontObject);
        assert.ok(buffer.byteLength > 1000);
        assert.ok(buffer.byteLength < 10000);

        let ttf = new TTFReader().read(buffer);

        assert.equal(ttf.version, 1);

        assert.equal(ttf.head.magickNumber, 1594834165);
        assert.equal(ttf.head.unitsPerEm, 512);

        assert.equal(ttf.post.format, 2);
        assert.equal(ttf.post.underlinePosition, 0);
        assert.equal(ttf.post.underlineThickness, 0);

        assert.equal(ttf.hhea.advanceWidthMax, 682);
        assert.equal(ttf.hhea.ascent, 480);
github kekee000 / fonteditor-core / demo / js / svg2ttfobject.js View on Github external
}).done(function (data) {

            let ttfObject = svg2ttfobject(data);
            let writer = new TTFWriter();

            let ttfBuffer = writer.write(ttfObject);
            let base64str = ttf2base64(ttfBuffer);

            let saveBtn = $('.saveas');
            saveBtn.attr('href', base64str);
            saveBtn.attr('download', 'save.ttf');
            console.log(ttfObject);
        });
github kekee000 / fonteditor-core / demo / js / ttfwriter.js View on Github external
$.getJSON('./data/baiduHealth.json', function (ttf) {

            let reader = new TTFReader();
            let writer = new TTFWriter();
            let buffer = writer.write(ttf);

            let ttfData = reader.read(buffer);

            console.log(ttfData);

            let base64str = ttf2base64(buffer);
            let saveBtn = $('.saveas');
            saveBtn.attr('href', base64str);
            saveBtn.attr('download', 'save.ttf');
        });
    }
github kekee000 / fonteditor-core / demo / js / ttfmin.js View on Github external
return u.charCodeAt(0);
        })
    });

    if (indexList.length) {
        let glyfList = ttf.getGlyf(indexList);
        glyfList.unshift(ttf.getGlyfByIndex(0));
        ttf.get().glyf = glyfList;
    }
    else {
        ttf.get().glyf = [ttf.getGlyfByIndex(0)];
    }

    let family = 'font-with-hitting';
    ttf.get().name.fontFamily = family;
    let writer = new TTFWriter({
        hinting: true
    });
    let buffer = writer.write(ttf.get());
    setFont({
        family: family,
        data: ttf2base64(buffer)
    }, '#' + family);



    family = 'font-without-hitting';
    ttf.get().name.fontFamily = family;
    writer = new TTFWriter({
        hinting: false
    });
    buffer = writer.write(ttf.get());
github kekee000 / fonteditor-core / demo / js / ttfmin.js View on Github external
let family = 'font-with-hitting';
    ttf.get().name.fontFamily = family;
    let writer = new TTFWriter({
        hinting: true
    });
    let buffer = writer.write(ttf.get());
    setFont({
        family: family,
        data: ttf2base64(buffer)
    }, '#' + family);



    family = 'font-without-hitting';
    ttf.get().name.fontFamily = family;
    writer = new TTFWriter({
        hinting: false
    });
    buffer = writer.write(ttf.get());
    setFont({
        family: family,
        data: ttf2base64(buffer)
    }, '#' + family);

    $('.ttf-text').html(text);
}