You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

9 years ago
var fs = require('fs')
var path = require('path')
var Canvas = require('..')
9 years ago
var Font = Canvas.Font
if (!Font) {
9 years ago
throw new Error('Need to compile with font support')
}
9 years ago
function fontFile (name) {
return path.join(__dirname, '/pfennigFont/', name)
}
9 years ago
var pfennigFont = new Font('pfennigFont', fontFile('Pfennig.ttf'))
pfennigFont.addFace(fontFile('PfennigBold.ttf'), 'bold')
pfennigFont.addFace(fontFile('PfennigItalic.ttf'), 'normal', 'italic')
pfennigFont.addFace(fontFile('PfennigBoldItalic.ttf'), 'bold', 'italic')
var canvas = new Canvas(320, 320)
var ctx = canvas.getContext('2d')
// Tell the ctx to use the font.
9 years ago
ctx.addFont(pfennigFont)
9 years ago
ctx.font = 'normal normal 50px Helvetica'
9 years ago
ctx.fillText('Quo Vaids?', 0, 70)
9 years ago
ctx.font = 'bold 50px pfennigFont'
ctx.fillText('Quo Vaids?', 0, 140)
9 years ago
ctx.font = 'italic 50px pfennigFont'
ctx.fillText('Quo Vaids?', 0, 210)
9 years ago
ctx.font = 'bold italic 50px pfennigFont'
ctx.fillText('Quo Vaids?', 0, 280)
9 years ago
canvas.createPNGStream().pipe(fs.createWriteStream(path.join(__dirname, 'font.png')))