我正在使用paper-jsdom-canvas
. PaperJS 无法使用我registerFont
使用canvas
. 但是当我尝试canvas
直接使用该项目时,字体渲染没有任何问题。
PaperJS
项目1.3.5
使用node-canvas
. 我更新了要使用的项目2.4.1
。我修复的唯一损坏的地方是Canvas.js
文件第 52 行。
改变了
impl._canvas = new Canvas(size.width, size.height, type);
至
impl._canvas = Canvas.createCanvas(size.width, size.height, type);
所有属性都按预期工作。操作系统安装的字体也被检测到。但是自定义字体被忽略了。
registerFont('path-to-font-file', {family: 'CustomFont'});
const canvas = createCanvas(600, 600);
const paperCanvas = createCanvas(600, 600);
const ctx = canvas.getContext('2d');
ctx.font = "normal 30px CustomFont";
ctx.fillText("Hello World", 10, 50);
// using paperjs
const paper = require("paper");
const project = new paper.Project(paperCanvas);
var text = new paper.PointText();
text.fillColor = 'white';
text.content = 'HELLO';
text.fontSize = '60';
text.fontFamily = 'CustomFont';
text.strokeWidth = 0;
text.strokeColor = 'blue';
text.position = project.view.center;
text.selected = true;
project.activeLayer.addChild(text);
project.view.draw();
// return canvas.toDataURL(); this canvas renders font correctly.
return project.view.element.toDataURL(); // paper does not use registered font
要使自定义字体使用,还需要进行哪些其他更改PaperJS
?