-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
The script is executed without error . Unfortunately, the command
ctx.font = 'bold 72px fontOpenSans';
is ignored and it will set the default font and size .
When Canvas is set to PDF mode , the font is also not set , nor embedded in the PDF document .
System: Ubuntu Server 14.04 / NodeJS 5.6 / node-canvas 1.3.12
Code-Snippet :
var Canvas = require('canvas')
, Font = Canvas.Font
, fs = require('fs');
if (!Font) {
throw new Error('Need to compile with font support');
}
var fontOpenSans = new Font('fontOpenSans', 'OpenSans-Regular.ttf');
fontOpenSans.addFace('OpenSans-Bold.ttf', 'bold');
var canvas = new Canvas(600,800);
var ctx = canvas.getContext('2d');
// Tell the ctx to use the font.
ctx.addFont(fontOpenSans);
ctx.font = 'bold 72px fontOpenSans';
ctx.fillText('Open Sans Dummy-Text', 50, 80);
fs.writeFile('font.png', canvas.toBuffer());