LearnBoost/node-canvas — pull request #410 by balsamiqMarco (2014-05-06 10:29:52+00:00)
Title: Load font file in FontConfig when using Pango

We need the text rendering capabilities of Pango (i.e. kerning), so we built node-canvas with 'with_pango' set to true. Problem is, that we use a custom TrueType font and it seems that node-canvas doesn't load it properly when using Pango.

The proposed change fixes the font loading step by calling FontConfig API.

Sample code:

var canvas = new Canvas(400,40);
var ctx = canvas.getContext('2d');
var Font = Canvas.Font;

var myFont = new Font('MyFont', '../fonts/pip.ttf');
myFont.addFace('../fonts/pipBold.ttf', 'bold');

// Do not call addFont when using Pango
//ctx.addFont(myFont);

ctx.font = "30px MyFont";
ctx.fillText("kerning enabled AVAVAVA", 2, 32);