Because I despise nitpicking stuff like indentation and spacing in pull request comments, I'd like to nudge forward our automated style checking, at least for new files being added. I don't want to totally rewrite server.js just to get automated style checking… the blame tracking is just too useful. So let's it's just take care of that when we start splitting it out. More discussion in #948.
32 lines
761 B
JavaScript
32 lines
761 B
JavaScript
'use strict';
|
|
|
|
const path = require('path');
|
|
const PDFDocument = require('pdfkit');
|
|
let doc = new PDFDocument({size: 'A4', layout: 'landscape'});
|
|
|
|
// Attempt to use a particular font.
|
|
// callback: (optional) takes an error if it failed.
|
|
function loadFont(path, callback) {
|
|
try {
|
|
doc = doc.font(path);
|
|
if (callback) { callback(null); }
|
|
} catch(err) {
|
|
doc = doc.font('Helvetica-Bold');
|
|
if (callback) { callback(err); }
|
|
}
|
|
}
|
|
|
|
loadFont(path.join(__dirname, '..', 'Verdana.ttf'), function (err) {
|
|
if (err && process.env.FALLBACK_FONT_PATH) {
|
|
loadFont(process.env.FALLBACK_FONT_PATH);
|
|
}
|
|
});
|
|
doc = doc.fontSize(11);
|
|
|
|
function measure(str) {
|
|
return doc.widthOfString(str);
|
|
}
|
|
|
|
module.exports = measure;
|
|
module.exports.loadFont = loadFont;
|