Skip to content

Canvas.registerFont is not a function #838

Closed

Description

@veltman

It looks like @chearon's new font API was recently merged:

#715

I was previously using an install of canvas from his fork as dependency, so the merge is great news, but so far it seems to fail on OS X.

Here's a bare-bones example test:

var path = require("path"),
    Canvas = require("canvas");

Canvas.registerFont(path.join(__dirname, "SourceSansPro-Regular.ttf"), { family: "Source Sans Pro"});

With canvas@1.6.2, Node v4.5.0 on OS X El Capitan, running that script throws the following error:

TypeError: Canvas.registerFont is not a function
    at Object.<anonymous> (/canvas-test/test.js:4:8)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:974:3

Am I missing something? That appears to be the correct API, based on the updated font example.

Activity

  1. chearon commented on Nov 4, 2016

    @chearon
    Collaborator

    Yeah, it isn't released yet, it's gonna be in version 2.0 which @LinusU is still working on merging stuff in for (note the top of the README.md on master)

  2. veltman commented on Nov 4, 2016

    @veltman
    Author

    Ohhh, gotcha. So we've been using the patch on your fork as a dependency:

    https://github.com/nypublicradio/audiogram/blob/master/package.json#L28

    But it looks like your fork was deleted and rebuilt, or something similar, two weeks ago, so that URL is broken now. Would it make sense to use your most recent commit on the current fork:

    chearon@50b7c12

    Or is that going to go away too?

    Thanks for all your work on the font issues!

  3. chearon commented on Nov 4, 2016

    @chearon
    Collaborator

    Oh shoot, I was worried that might happen, seems like a few people were relying on my branch and I forgot to wait a while before I deleted it.

    Anyways yes, since that commit is in master it is there to stay, you could also link to the Automattic master at this point

  4. veltman commented on Nov 4, 2016

    @veltman
    Author

    Well linking to the Automattic master is what throws that registerFont error, because it's the 1.x version, right? I'm not sure how to get the benefit of the font fixes while changing as little else as possible. A temporary solution might be for me to put that working commit onto GH from an old installation, any objection to that?

  5. chearon commented on Nov 4, 2016

    @chearon
    Collaborator

    It shouldn't if you use the git URL - registerFont is on Automattic/node-canvas's master right now, it's just not in any NPM release. But I also just now pushed up my prefer-pango branch in case anyone else is still using it

  6. veltman commented on Nov 4, 2016

    @veltman
    Author

    Oh, sorry, I see! I'll give that a shot. In the meantime, it looks like this commit:

    https://github.com/chearon/node-canvas.git#12971f64a66b

    also works, so I'll deploy that as a temporary fix and then test out the main master.

  7. chearon commented on Nov 4, 2016

    @chearon
    Collaborator

    Yep, the 2 after that are just small improvements

  8. jleclanche commented on Dec 25, 2016

    @jleclanche

    Any word on a release? There hasn't been any since October, would love one :)

  9. added a commit that references this issue on Mar 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions