-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
Documentation Issue?
The docs state (note emphasis):
To use a font file that is not installed as a system font, use
registerFont()
to register the font with Canvas. This must be done before the Canvas is created.
However, going against the docs and loading the font after creating and drawing into the canvas seems to work just fine for me. My code:
var fs = require('fs');
var Canvas = require('canvas');
var canvas = Canvas.createCanvas(640, 100);
var ctx = canvas.getContext('2d');
ctx.strokeStyle = 'gray';
ctx.fillStyle = 'yellow';
ctx.beginPath();
ctx.rect( 50, 10, 300, 80 );
ctx.fill();
ctx.stroke();
Canvas.registerFont(('futurastd-m.otf'), { family: 'FuturaStdMedium' });
ctx.font = 'normal normal 36px FuturaStdMedium';
ctx.fillStyle = 'black';
ctx.fillText('Now is the time for all good men.', 10, 35);
canvas.createPNGStream().pipe(fs.createWriteStream('output.png'));
Output:
This renders correctly. I guess I was expecting it to crash or something? My question is, is this just a documentation issue? Was the requirement a previous limitation with node-canvas v1 perhaps, now gone with v2?
Your Environment
- Version: node-canvas HEAD revision, compiled from source 2021/11/03 (reported version: 2.8)
- Environment: CentOS Linux release 7.7.1908 (Core)
Metadata
Metadata
Assignees
Labels
No labels