-
Notifications
You must be signed in to change notification settings - Fork 1.2k
SVG support on Windows? #1211
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
Comments
#1206 is needed for it to work on Windows, and no release has been made since that was merged. Can you try installing from GitHub? ( |
Sorry, I haven't cut a release in quite a while. Did it now, please try with |
OK - installed latest, still no luck with the standard install of |
Also you appear to have published the I just tried to install it for an unrelated project that uses the old 1.x api using just |
oh no, not again 😅 fixed 👌 |
@nrkn I got close to getting it to work with only pre-compiled binaries on the GNOME FTP server, but I can't find a ready-made librsvg-2-2.lib to link against. In #1123 it sounds like @timknip maybe built RSVG with mingw, @Khorynthium perhaps as well. That's probably the only viable way forward -- hopefully we can get it in prebuilds though. |
I'm trying to use canvas with svg support in Electron, I can't use the prebuilt (because of Electron js), so npm install is building the library.
I get the following error :
the GTK bundle i have http://ftp.gnome.org/pub/GNOME/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip didn't contain any librsvg file, I tried to download a librsvg lib but without success Where can i find a complete GTK binaries for win32 so I can build the node canvas with svg support?? |
I tried to download librsvg for win32, I get node_canvas to compile (I generated the .lib from the .dll) but at run time I am getting an error : So the librsvg I get is not the one used in the node_canvas library |
Any update on this ? @khkassem @zbjornson any information on how to build node-canvas on Windows with svg support ? Or is there a prebuilt binary perhaps ? I am developing an Electron application that exports PDF and SVG files that can have SVG embedded documents inside a canvas renderer. Without SVG support I cannot export the documents that have embedded SVG. On macOS I can succesfully recompile the library with SVG support, but I have not yet looked at how to do it in Windows, just wondering if there are some easy guides how to do it. Thanks! |
Okay I got the library building. Steps I had to do: Download all the dependency libraries from https://download.gnome.org/binaries/win64/
Extract and copy the .dll dependencies to C:\GTK\bin Cd to the MSVC tools directory
Generate a .def file from the librsvg-2-2.dll:
Edit this exports file manually and save to C:\GTK\bin\librsvg-2-2.def to get this:
Generate the librsvg-2-2.lib file from the .def file:
Okay now all the dependencies should be met. Then I edited the binding.gyp file (set with_rsvg to true):
And added the include_dirs to the windows section:
Had to remove the LIBRSVG_VERSION definition from the init.cc also: ...
#ifdef HAVE_GIF
#ifndef GIF_LIB_VERSION
char gif_version[10];
snprintf(gif_version, 10, "%d.%d.%d", GIFLIB_MAJOR, GIFLIB_MINOR, GIFLIB_RELEASE);
Nan::Set(target, Nan::New<String>("gifVersion").ToLocalChecked(), Nan::New<String>(gif_version).ToLocalChecked()).Check();
#else
Nan::Set(target, Nan::New<String>("gifVersion").ToLocalChecked(), Nan::New<String>(GIF_LIB_VERSION).ToLocalChecked()).Check();
#endif
#endif
#ifdef HAVE_RSVG
Nan::Set(target, Nan::New<String>("rsvgVersion").ToLocalChecked(), Nan::New<String>("2.2").ToLocalChecked()).Check();
#endif
char freetype_version[10];
snprintf(freetype_version, 10, "%d.%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH);
Nan::Set(target, Nan::New<String>("freetypeVersion").ToLocalChecked(), Nan::New<String>(freetype_version).ToLocalChecked()).Check();
}
NODE_MODULE(canvas, init); I just replaced it with "2.2" as you can see. Probably this would have to be set by package-config and the build has not been tested on Windows ? Don't know, just guessing. After this I could build the canvas succesfully with
From my Electron project root directory. "error while reading from input stream" And also I see these messages in my electron debug log:
Now, if I export a document without embedded SVG elements in it through node-canvas to a PDF or SVG file, and after this succeeds, running the export again with embedded SVG, will not give the "error while reading from input stream" error and will not show the GLib errors. But the resulting PDF from my app will be rendered without the SVG elements in it, where they should be in the exported PDF they will be just empty. So my guess is if I try to export directly with elements with SVG in them, the node-canvas library fails to initialize properly at all, but when I do a initial run without the SVG elements, the library is initialized properly and after that I can export the SVG elements, but for some reason it fails to read the SVG elements. On mac the elements are correctly rasterized as images in the resulting PDF or SVG. Just to clarify, I have an application where you can load SVG images to be rendered in a canvas, and then I have support for exporting that canvas to a PDF/SVG via node-canvas. Any idea what might cause this ? Works perfectly fine on macOS like I said .. not sure I want to go digging any deeper in this :P But let's see, I will at least take a look at the sources if I can figure it out .. EDIT: Ok looking at some reports found online, my best guess currently is that some of the dependency libraries or glib or something has been built against different version, at least the g_type_init() call seemed to be deprecated in some newer versions of glib or something. |
It seems the librsvg win64 .dll file that can be downloaded from gnome.org is the old version, not the newer one built with Rust. Probably this is causing the library not to work and causing the g_type_init() calls also being missing. No idea where to find a build of the Rust -version for win64 .dll build. Only builds I can see are in msys2, but those are built as .a and .dll.a files, not as dll .. damn. Any info on where to find newer builds for librsvg2 (the rust version, after 2017 developed ? ) would be dandy. |
Okay just another update, I got it building using the MSYS2 build instructions and hacking away. I wish the instructions on the WIndows build would just point to this page by default, now I wasted couple of days trying to get the normal build process working, but I can see that for most cases this could be sufficient, but if you want to enable SVG support then the MSYS2 build process is the only way to go, and it requires manual hacking to get there. I will document later on what I did get it compiling and working. |
Consider using skr-canvas, no additional dependencies to install, no node-gyp, and native support for SVG. |
Glad to see this PR adding SVG landed, but it doesn't appear to work on Windows when using a standard
npm install canvas
So I looked at the binding.gyp and saw options for windows and that librsvg was false by default, so tried
node-gyp rebuild --with_rsvg=true
but it complains that it's missing headers etc. for librsvg:I found the librsvg files built for windows with dlls, src and headers etc on the same ftp server as gtk but not sure where to put them? Tried just copying them into c:\gtk at the appropriate places but rebuild still failing
Also tried putting them in c:\librsvg, I'm not a C++ dev though so really just guessing and flailing in the dark here, any ideas?
The text was updated successfully, but these errors were encountered: