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

Windows: with node-canvas, "cannot register existing type 'PangoCairoFontMap'" #2531

Closed
laurieherault opened this issue Jan 13, 2021 · 6 comments
Labels

Comments

@laurieherault
Copy link

Are you using the latest version? Is the version currently in use as reported by npm ls sharp the same as the latest version as reported by npm view sharp dist-tags.latest?
Yes (0.27.0)

What are the steps to reproduce?

  • Install Sharp 0.27.0 on Windows 10
  • Convert SVG with text to PNG
  • Error :
Fontconfig error: Cannot load default config file

(sharp:6452): GLib-GObject-WARNING **: 17:17:43.297: cannot register existing type 'PangoFontMap'

(sharp:6452): GLib-GObject-WARNING **: 17:17:43.298: cannot add private field to invalid (non-instantiatable) type '<invalid>'

(sharp:6452): GLib-GObject-CRITICAL **: 17:17:43.298: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed

(sharp:6452): GLib-CRITICAL **: 17:17:43.298: g_once_init_leave: assertion 'result != 0' failed

(sharp:6452): GLib-GObject-CRITICAL **: 17:17:43.299: g_type_register_static: assertion 'parent_type > 0' failed

(sharp:6452): GLib-GObject-WARNING **: 17:17:43.299: cannot add private field to invalid (non-instantiatable) type '<invalid>'

(sharp:6452): GLib-GObject-CRITICAL **: 17:17:43.299: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed

(sharp:6452): GLib-CRITICAL **: 17:17:43.299: g_once_init_leave: assertion 'result != 0' failed

(sharp:6452): GLib-GObject-CRITICAL **: 17:17:43.299: g_type_register_static: assertion 'parent_type > 0' failed

(sharp:6452): GLib-GObject-WARNING **: 17:17:43.299: cannot register existing type 'PangoCairoFontMap'

More information

  • It's work well with Sharp 0.25.4 on Windows 10 or Sharp 0.27.0 on Linux
  • The problem start with v0.26.0

What is the expected behaviour?
Generate a PNG from SVG

Are you able to provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem?

  const test = `
  <svg width="200" height="250" version="1.1" xmlns="http://www.w3.org/2000/svg">
    <text x="10" y="10">
      Hi !
    </text>
  </svg>`;

  const data1 = await sharp(Buffer.from(test), { density: 72 })
    .png()
    .toBuffer();

Are you able to provide a sample image that helps explain the problem?
No

What is the output of running npx envinfo --binaries --system?
System:
OS: Windows 10 10.0.19042
CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
Memory: 3.36 GB / 15.93 GB
Binaries:
Node: 14.15.1 - C:\Program Files\nodejs\node.EXE
npm: 6.13.7 - C:\Program Files\nodejs\npm.CMD

@lovell
Copy link
Owner

lovell commented Jan 13, 2021

Hi, thanks for reporting, are you sure v0.26.0 is similarly broken? I think this relates to #2515, which only affects v0.27.0.

@laurieherault
Copy link
Author

Hi,
Thanks for your fast answer!

But I opened an issue too quickly (Sorry....). My example is incomplete. The problem comes from an incompatibility with node-canvas once it is used (and not just loaded).

Yes we have problème with 0.26.0 and 0.27.0. The 0.25.4 work.

const sharp = require('sharp');
const { createCanvas } = require("canvas");

async function test() {
  // We use node-canvas for measure text width for the SVG generation
  const canvas = createCanvas(600, 60);
  const ctx = canvas.getContext("2d"); 

  const test = `<svg width="200" height="250" version="1.1" xmlns="http://www.w3.org/2000/svg">
    <text x="10" y="10">
      Hi !
    </text>
  </svg>`;

  // When we transform the SVG to PNG we have a bug
  const data1 = await sharp(Buffer.from(test), { density: 72 })
    .png()
    .toBuffer();
  console.log(data1);
}

test();

@lovell
Copy link
Owner

lovell commented Jan 13, 2021

Does setting the PANGOCAIRO_BACKEND="win32" environment variable help?

@laurieherault
Copy link
Author

I have another error with PANGOCAIRO_BACKEND="win32" :

Pango-ERROR **: 20:37:16.763: Unknown $PANGOCAIRO_BACKEND value.
  Available backends are: fontconfig

@lovell
Copy link
Owner

lovell commented Jan 13, 2021

Thanks for checking, the only other quick fix I can think of is to alter the order in which sharp and canvas are required.

Since v0.26.0 of sharp, the prebuilt shared library we provide is statically-linked to help avoid conflict with other native modules.

The prebuilt binaries provided by canvas are all dynamically-linked DLLs, some of which are for rather old versions of the dependencies - see https://github.com/node-gfx/node-canvas-prebuilt - perhaps ask if they would be willing/able to either update or provide a single statically-linked DLL?

@lovell lovell changed the title Cannot convert SVG with text WindowsCannot convert SVG with text Jan 13, 2021
@lovell lovell changed the title WindowsCannot convert SVG with text Windows: with node-canvas, "cannot register existing type 'PangoCairoFontMap'" Jan 13, 2021
@laurieherault
Copy link
Author

We decided not to use node-canvas anymore. It's easier :)
Thank you !

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

No branches or pull requests

2 participants