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

No Text Rendering (macos sierra, node v6.9.1) #837

Closed
eugeneware opened this issue Nov 3, 2016 · 12 comments
Closed

No Text Rendering (macos sierra, node v6.9.1) #837

eugeneware opened this issue Nov 3, 2016 · 12 comments

Comments

@eugeneware
Copy link

Issue or Feature

When I try to write text to a canvas it simply doesn't appear. I've tried custom fonts and built-in fonts.

Steps to Reproduce

$ nvm use 6.9.1 && npm i -S canvas@1.6.2 && node test.js
// test.js
var Canvas = require('canvas')
  , canvas = new Canvas(200, 200)
  , fs = require('fs')
  , ctx = canvas.getContext('2d');

ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, 200, 200);

ctx.fillStyle = '#000';
ctx.font = '30px Helvetica';
ctx.fillText("Awesome!", 50, 100);

canvas.pngStream().pipe(fs.createWriteStream('./out.png'));

Actual Result

image

Expected Result

image

Notes

The weird thing, is that it works on node 0.10 with canvas@1.1:

$ nvm use 0.10 && npm i -S canvas@1.1 && node test.js

But fails with node 4 LTS as well.

A coworker who's running El Capitan has it running fine.

Your Environment

  • Version of node-canvas: 1.6.2
  • Environment: node 6.9.1, macOS 10.12.1 (macOS Sierra)
  • Libraries:
$ brew list --versions pkg-config cairo pango libpng jpeg giflib
pkg-config 0.29.1_2
cairo 1.14.6_1
pango 1.40.3
libpng 1.6.25 1.6.26
jpeg 8d
giflib 4.2.3
@chearon
Copy link
Collaborator

chearon commented Nov 4, 2016

that's weird, can you try doing npm install canvas-prebuilt and require('canvas-prebuilt') and see if that works instead? that would rule out an issue with libraries on your system

@eugeneware
Copy link
Author

Hi @chearon. That fixed the problem.

It works with the pre-built libraries.

Is there any way to debug and track down the issue with my libraries?

This is what happens when I install canvas:

$ npm i -S canvas

> canvas@1.6.2 install /Users/eugeneware/Dropbox/work/scratch/canvas-work/node_modules/canvas
> node-gyp rebuild

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
  array-index setting "length": 0 +0ms
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
  SOLINK_MODULE(target) Release/canvas-postbuild.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9
  CXX(target) Release/obj.target/canvas/src/Canvas.o
  CXX(target) Release/obj.target/canvas/src/CanvasGradient.o
  CXX(target) Release/obj.target/canvas/src/CanvasPattern.o
  CXX(target) Release/obj.target/canvas/src/CanvasRenderingContext2d.o
  CXX(target) Release/obj.target/canvas/src/color.o
  CXX(target) Release/obj.target/canvas/src/Image.o
  CXX(target) Release/obj.target/canvas/src/ImageData.o
  CXX(target) Release/obj.target/canvas/src/init.o
  CXX(target) Release/obj.target/canvas/src/FontFace.o
  SOLINK_MODULE(target) Release/canvas.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9
/Users/eugeneware/Dropbox/work/scratch/canvas-work
└─┬ canvas@1.6.2
  └── nan@2.4.0

npm WARN canvas-work No description
npm WARN canvas-work No repository field.
npm WARN canvas-work No license field.

@LinusU
Copy link
Collaborator

LinusU commented Nov 4, 2016

@chearon Do you think it has something to do with having pango vs. not having pango installed?

@chearon
Copy link
Collaborator

chearon commented Nov 4, 2016

I don't think so because he is using the latest version of Pango. I'm really not sure what would cause that since canvas-prebuilt gets Pango from homebrew too. Maybe a brew reinstall pango would do it, or maybe you installed Pango or Cairo with non-default options?

@LinusU
Copy link
Collaborator

LinusU commented Nov 4, 2016

Interesting, I think I have the same problem on my machine... I'll try to investigate

@chearon
Copy link
Collaborator

chearon commented Nov 4, 2016

I can't reproduce it with the same OS, node, and canvas version

@eugeneware
Copy link
Author

I used the default installation instructions on the README.md. Ie.

brew install pkg-config cairo pango libpng jpeg giflib

Didn't change any options.

Tried the reinstall, but no difference:

$ brew reinstall pango
==> Reinstalling pango
==> Downloading https://homebrew.bintray.com/bottles/pango-1.40.3.sierra.bottle.tar.gz
Already downloaded: /Users/eugeneware/Library/Caches/Homebrew/pango-1.40.3.sierra.bottle.tar.gz
==> Pouring pango-1.40.3.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/pango/1.40.3: 125 files, 5.1M
 Σ canvas-work$ npm rebuild canvas

> canvas@1.6.2 install /Users/eugeneware/Dropbox/work/scratch/canvas-work/node_modules/canvas
> node-gyp rebuild

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
  SOLINK_MODULE(target) Release/canvas-postbuild.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9
  CXX(target) Release/obj.target/canvas/src/Canvas.o
  CXX(target) Release/obj.target/canvas/src/CanvasGradient.o
  CXX(target) Release/obj.target/canvas/src/CanvasPattern.o
  CXX(target) Release/obj.target/canvas/src/CanvasRenderingContext2d.o
  CXX(target) Release/obj.target/canvas/src/color.o
  CXX(target) Release/obj.target/canvas/src/Image.o
  CXX(target) Release/obj.target/canvas/src/ImageData.o
  CXX(target) Release/obj.target/canvas/src/init.o
  CXX(target) Release/obj.target/canvas/src/FontFace.o
  SOLINK_MODULE(target) Release/canvas.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9
canvas@1.6.2 /Users/eugeneware/Dropbox/work/scratch/canvas-work/node_modules/canvas

Still has the issue.

Any way to debug this, or see any error messages/warnings?

It looks like a build environment issue of some description.

@eugeneware
Copy link
Author

OK. Had a breakthrough. I did a:

brew uninstall pango and then npm rebuild canvas and now it works.

So, looks to be some issue with having pango installed?

Any ideas?

@chearon
Copy link
Collaborator

chearon commented Nov 7, 2016

That means it's more than likely something inside Pango since if you don't have Pango, the node-canvas 1.x versions will use primitive Cairo font drawing methods.

To be extra sure... try copying the example here into something like test.c, then compile it (if you have pango and cairo installed with homebrew) with gcc test.c $(pkg-config --libs --cflags pangcairo). You use it like ./a.out test.png then open test.png and see if you see any text

@eugeneware
Copy link
Author

Hi @chearon - I think we're getting somewhere.

I modified the test program to output the error code and string:

  if (status != CAIRO_STATUS_SUCCESS)
    {
      g_printerr ("Could not save png to '%s'. Error: %d %s\n", filename, status, cairo_status_to_string(status));
      return 1;
    }

It's printing out this error:

$ ./pangotest out.png
Could not save png to 'out.png'. Error: 1 out of memory

@eugeneware
Copy link
Author

OK. I've managed to solve this problem!

The issue was that I had a: export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig in my .bash_profile.

When I have this environment variable and compile I get the memory error.

When I don't, it works fine!

Thanks so much to @chearon and all the others on this issue for their help! So frustrating!

I must have had that line there from years ago for some reason and completely forgot about it!

At least if anyone else has this issue, hopefully they'll find this issue!

Thanks again!

@chearon
Copy link
Collaborator

chearon commented Nov 7, 2016

Nice!! Thanks for following through with the solution

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

3 participants