Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded Fonts is not working #733

Closed
msykosch opened this issue Mar 7, 2016 · 3 comments
Closed

Embedded Fonts is not working #733

msykosch opened this issue Mar 7, 2016 · 3 comments

Comments

@msykosch
Copy link

msykosch commented Mar 7, 2016

The script is executed without error . Unfortunately, the command

ctx.font = 'bold 72px fontOpenSans';

is ignored and it will set the default font and size .

When Canvas is set to PDF mode , the font is also not set , nor embedded in the PDF document .

System: Ubuntu Server 14.04 / NodeJS 5.6 / node-canvas 1.3.12

Code-Snippet :

var Canvas = require('canvas')
, Font = Canvas.Font
, fs = require('fs');

if (!Font) {
throw new Error('Need to compile with font support');
}

var fontOpenSans = new Font('fontOpenSans', 'OpenSans-Regular.ttf');
fontOpenSans.addFace('OpenSans-Bold.ttf', 'bold');

var canvas = new Canvas(600,800);
var ctx = canvas.getContext('2d');

// Tell the ctx to use the font.
ctx.addFont(fontOpenSans);

ctx.font = 'bold 72px fontOpenSans';
ctx.fillText('Open Sans Dummy-Text', 50, 80);

fs.writeFile('font.png', canvas.toBuffer());

@chearon
Copy link
Collaborator

chearon commented Mar 8, 2016

if you compiled with Pango, try ctx.font = 'bold 72px "Open Sans"';

@msykosch
Copy link
Author

msykosch commented Mar 8, 2016

It works!

Pango is the Problem.

Thank you.

@chearon
Copy link
Collaborator

chearon commented Mar 8, 2016

No problem, you won't have to do that when I finish work on #715

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants