Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
9.99k stars 1.15k forks source link

Some Chinese fonts are downgraded to default fonts after rendering #2238

Open jianghai opened 1 year ago

jianghai commented 1 year ago

Steps to Reproduce

registerFont('./xx/HYYakuHei-EEW.ttf', { family: 'HYYakuHei-EEW' });

const canvas = createCanvas(100, 100);
  const ctx = canvas.getContext('2d');
  ctx.font = '20px HYYakuHei-EEW';
  ctx.fillText('测试', 20, 50);

output out

However, everything is rendered correctly using the canvas API in Chrome browser, so it shouldn't be a font problem.

<canvas id="canvas"></canvas>
  <script>
    const canvas = document.getElementById("canvas");
    const ctx = canvas.getContext("2d");

    ctx.font = "20px HYYakuHei-EEW";
    ctx.fillText("测试", 20, 50);
  </script>

output image

font name is from PostScript image

Your Environment

sukbearai commented 1 year ago

怎么解决的?

jianghai commented 1 year ago

Okay, I switched to a different canvas library and solved it. https://github.com/Brooooooklyn/canvas

sukbearai commented 1 year ago

Okay, I switched to a different canvas library and solved it. https://github.com/Brooooooklyn/canvas

其实是你字体包的问题,我换了一个字体就能显示中文了。好像是字体包的编码不兼容