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

Canvas.registerFont is not a function #878

Closed
SomeoneCares11 opened this issue Feb 24, 2017 · 6 comments
Closed

Canvas.registerFont is not a function #878

SomeoneCares11 opened this issue Feb 24, 2017 · 6 comments

Comments

@SomeoneCares11
Copy link

SomeoneCares11 commented Feb 24, 2017

Why i'm getting this error, i just installed canvas via npm install canvas
and i update the canvas using clone

root@ns3484799:/home/ProBot/node_modules/canvas/examples# node font.js
/home/ProBot/node_modules/canvas/lib/canvas.js:83
  return Canvas._registerFont(fs.realpathSync(src), fontFace);
                ^

TypeError: Canvas._registerFont is not a function
    at Function.Canvas.registerFont (/home/ProBot/node_modules/canvas/lib/canvas.js:83:17)
    at Object.<anonymous> (/home/ProBot/node_modules/canvas/examples/font.js:13:8)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)

@chearon
Copy link
Collaborator

chearon commented Feb 24, 2017

It's not released yet, Canvas.registerFont is a part of 2.0 but that hasn't been published to NPM yet. See the end of #743

@LinusU LinusU closed this as completed Feb 28, 2017
@latipun7
Copy link

I got this issue. I install this package with npm install Automattic/node-canvas so it's downloading the v2.0, right?

TypeError: Canvas.registerFont is not a function

Then I tried to commend that line, but I got this new error

TypeError: Canvas is not a constructor

What happen? can I go wrong from the require() ?

This is my code:

const Canvas = require('canvas');
const path = require('path');

const Image = Canvas.Image;
// Canvas.registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'BackIssuesBB_reg.ttf'), { family: 'BackIssuesBB' });

const canvas = new Canvas(530, 391);
const ctx = canvas.getContext('2d');

Thanks in advance.

@LinusU
Copy link
Collaborator

LinusU commented Jul 15, 2017

It's because the interface have changed on the latest master, and unfortunately registerFont is temporarily broken. You can try to install the latest alpha instead

@latipun7
Copy link

Thank you. I think it's worked now, but got this warning issues instead

(node.exe:19652): Pango-WARNING **: couldn't load font "sans serif Not-Rotated 10px", falling back to "Sans Not-Rotated 10px", expect ugly output.

(node.exe:19652): Pango-WARNING **: couldn't load font "sans serif 10px", falling back to "Sans 10px", expect ugly output.

from this code:

Canvas.registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'BackIssuesBB_reg.ttf'), { family: 'Back Issues BB' });

ctx.font = '12px Back Issues BB';
ctx.fillStyle = '#131313';
ctx.fillText(line, 162, 100);

Canvas version: v2.0.0-alpha.1

@chearon
Copy link
Collaborator

chearon commented Jul 18, 2017

@RyuukiBeat looks like it couldn't load your font, and then it couldn't load a fallback

Can you try loading a font like the one distributed here and see if that gives you the same problem?

The fallback isn't loading because you might need to change your pango.aliases file according to what you have available on Windows.

@latipun7
Copy link

@chearon Thank you, and sorry. What I mean is, the Canvas working properly and the fonts registered/loaded. But I don't know why the warning shows up.

So, it's cool. As long as it's worked. Thank you.

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

4 participants