【问题标题】:Convert Google fonts path to SVG path将 Google 字体路径转换为 ​​SVG 路径
【发布时间】:2020-11-02 11:37:14
【问题描述】:

我正在尝试按照https://github.com/danmarshall/google-font-to-svg-path 的示例将 Google 字体创建为 svg。我的代码如下:

opentype.load('https://fonts.googleapis.com/css2?family=' + 'ABeeZee', (err, font) => {
  const textModel = new makerjs.models.Text(font, 'Test', 20, false, false, 1);
  const svg = makerjs.exporter.toSVG(textModel);
  console.log(svg);
});

我不断收到错误消息:ERROR TypeError: Cannot read property 'forEachGlyph' of null,我该如何解决?我的代码基于此处的示例:https://github.com/danmarshall/google-font-to-svg-path/blob/master/index.ts#L73-L97

【问题讨论】:

    标签: javascript svg opentype


    【解决方案1】:

    我是这样解决的:

    const url = 'http://fonts.gstatic.com/s/quicksand/v21/6xK-dSZaM9iE8KbpRA_LJ3z8mH9BOJvgkKEo18G0wx40QDw.ttf';
    const text = 'hello';
    const size = 14;
    const union = false;
    const bezierAccuracy = 0;
    let svg = null;
    opentype.load(url, (err, font) => {
      const textModel = new makerjs.models.Text(font, text, size, union, false, bezierAccuracy);
      svg = makerjs.exporter.toSVG(textModel);
    });
    return svg;
    

    【讨论】:

      猜你喜欢
      • 2015-03-06
      • 2017-08-23
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      • 1970-01-01
      • 2019-04-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多