Skip to content

Commit

Permalink
Support fallback font when Verdana isn't available
Browse files Browse the repository at this point in the history
  • Loading branch information
ForbesLindesay committed Jul 22, 2015
1 parent e2fbb58 commit 36b664f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions measure-text.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
'use strict';

var path = require('path');
var fs = require('fs');
var PDFDocument = require('pdfkit');

var doc = (new PDFDocument({size:'A4', layout:'landscape'}))
.font(path.join(__dirname, 'Verdana.ttf'))
.fontSize(11);
var doc = (new PDFDocument({size:'A4', layout:'landscape'}));
try {
doc = doc.font(path.join(__dirname, 'Verdana.ttf'));
} catch (ex) {
doc = doc.font('Helvetica-Bold')
console.warn('Could not load font file "Verdana.ttf", text widths will therefore be approximate', ex);
}
doc = doc.fontSize(11);

module.exports = measure;
function measure(str) {
Expand Down

0 comments on commit 36b664f

Please sign in to comment.