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.
39 lines
1.0 KiB
39 lines
1.0 KiB
var fs = require('fs')
|
|
var path = require('path')
|
|
var Canvas = require('..')
|
|
|
|
var Font = Canvas.Font
|
|
|
|
if (!Font) {
|
|
throw new Error('Need to compile with font support')
|
|
}
|
|
|
|
function fontFile (name) {
|
|
return path.join(__dirname, '/pfennigFont/', name)
|
|
}
|
|
|
|
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.
|
|
ctx.addFont(pfennigFont)
|
|
|
|
ctx.font = 'normal normal 50px Helvetica'
|
|
|
|
ctx.fillText('Quo Vaids?', 0, 70)
|
|
|
|
ctx.font = 'bold 50px pfennigFont'
|
|
ctx.fillText('Quo Vaids?', 0, 140)
|
|
|
|
ctx.font = 'italic 50px pfennigFont'
|
|
ctx.fillText('Quo Vaids?', 0, 210)
|
|
|
|
ctx.font = 'bold italic 50px pfennigFont'
|
|
ctx.fillText('Quo Vaids?', 0, 280)
|
|
|
|
canvas.createPNGStream().pipe(fs.createWriteStream(path.join(__dirname, 'font.png')))
|
|
|