opentypejs/opentype.js

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

开放

#380 创建于 2019年4月29日

 (3 条评论) (0 个反应) (0 位负责人)JavaScript (512 个派生)batch import
good first issue

仓库指标

星标
 (4,170 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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

贡献者指南