opentypejs/opentype.js

Need to implement TrueType font hinting export (fpgm, cvt, prep tables)

Open

#380 opened on Apr 29, 2019

View on GitHub
 (3 comments) (0 reactions) (0 assignees)JavaScript (4,170 stars) (512 forks)batch import
good first issue

Description

i use the opentype.js in node. when i use a .ttf font generated a new .ttf font , and use the new font in browser.when i set the fontSize 12px , it looks like different with the source font file. it does not hint. how should i do.

const FONT_PATH = path.resolve(__dirname, '../fonts/msyh.ttf');
const font = opentype.loadSync(FONT_PATH);
let str = '大李士专陈';
let start = 0x10000;
let glyphs = []
var notdefGlyph = new opentype.Glyph({
    name: '.notdef',
    unicode: 0,
    advanceWidth: 1024,
    path: new opentype.Path()
});

glyphs.push(notdefGlyph)

let words = [...new Set(str)];

words.forEach(word => {
    start++
    let oldGlyph = font.charToGlyph(word);
    let glyph = new opentype.Glyph({
        name: 'uni' + start,
        unicode: start,
        advanceWidth: oldGlyph.advanceWidth,
        path: oldGlyph.path
    });
    glyphs.push(glyph)
})

var font1 = new opentype.Font({
    familyName: 'OpenTypeSans',
    styleName: 'Medium',
    unitsPerEm: font.unitsPerEm,
    ascender: font.ascender,
    descender: font.descender,
    glyphs: glyphs
});
font1.download('msyhcp.ttf');

Your Environment

  • Version used: 0.11.0
  • Font used: msyh.ttf
  • Browser Name and version: chrome
  • Operating System and version (desktop or mobile):desktop windows 7
  • Link to your project:
  • Node Version: 8.10.0

Contributor guide