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

Added support for Freetype, JPEG, Giflib, and Pango on Windows #620

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 52 additions & 7 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
['OS=="win"', {
'variables': {
'GTK_Root%': 'C:/GTK', # Set the location of GTK all-in-one bundle
'JPEG_ROOT%': 'C:/libjpeg-turbo', # Set the location of LibJpeg Turbo
'GIF_Root': 'C:/giflib', # Set the location of GifLib source root
# NOTE: Freetype2 when built and installed by CMake, creates the include directory like: linclude/freetype2. You need to rename freetype2 to freetype.
'FT_Root': 'C:/freetype', # Points to Freetype root of CMake install directory
'with_jpeg%': 'false',
'with_gif%': 'false',
'with_pango%': 'false',
Expand Down Expand Up @@ -60,6 +64,7 @@
'include_dirs': [
'<(GTK_Root)/include',
'<(GTK_Root)/include/cairo',
'src/unistd' # needed for Freetype, GifLib, and Pango
],
'defines': [
'snprintf=_snprintf',
Expand Down Expand Up @@ -105,7 +110,29 @@
],
'conditions': [
['OS=="win"', {
# No support for windows right now.
'libraries': [
'-l<(FT_Root)/lib/freetype.lib'
],
'include_dirs': [
'<(FT_Root)/include',
'<(FT_Root)/include/freetype'
],
'configurations': {
'Debug': {
'msvs_settings': {
'VCLinkerTool': {
'IgnoreDefaultLibraryNames': ['libcmtd']
}
}
},
'Release': {
'msvs_settings': {
'VCLinkerTool': {
'IgnoreDefaultLibraryNames': ['libcmt']
}
}
}
}
}, { # 'OS!="win"'
'include_dirs': [ # tried to pass through cflags but failed.
# Need to include the header files of cairo AND freetype.
Expand All @@ -122,8 +149,16 @@
'conditions': [
['OS=="win"', {
'libraries': [
'-l<(GTK_Root)/lib/pangocairo.lib'
]
'-l<(GTK_Root)/lib/fontconfig.lib',
'-l<(GTK_Root)/lib/gobject-2.0.lib',
'-l<(GTK_Root)/lib/pango-1.0.lib',
'-l<(GTK_Root)/lib/pangocairo-1.0.lib'
],
'include_dirs': [
'<(GTK_Root)/include/glib-2.0',
'<(GTK_Root)/lib/glib-2.0/include',
'<(GTK_Root)/include/pango-1.0',
]
}, { # 'OS!="win"'
'include_dirs': [ # tried to pass through cflags but failed
'<!@(pkg-config pangocairo --cflags-only-I | sed s/-I//g)'
Expand All @@ -141,7 +176,10 @@
'conditions': [
['OS=="win"', {
'libraries': [
'-l<(GTK_Root)/lib/jpeg.lib'
'-l<(JPEG_ROOT)/lib/jpeg.lib'
],
'include_dirs': [
'<(JPEG_ROOT)/include'
]
}, {
'libraries': [
Expand All @@ -156,9 +194,16 @@
],
'conditions': [
['OS=="win"', {
'libraries': [
'-l<(GTK_Root)/lib/gif.lib'
]
'sources': [
'<(GIF_Root)/lib/dgif_lib.c',
'<(GIF_Root)/lib/egif_lib.c',
'<(GIF_Root)/lib/gif_err.c',
'<(GIF_Root)/lib/gif_font.c',
'<(GIF_Root)/lib/gif_hash.c',
'<(GIF_Root)/lib/quantize.c',
'<(GIF_Root)/lib/gifalloc.c'
],
'include_dirs': ["<(GIF_Root)/lib"]
}, {
'libraries': [
'-lgif'
Expand Down
29 changes: 29 additions & 0 deletions src/CanvasRenderingContext2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
#define isinf(x) (!_finite(x))
#endif

#ifdef _WIN32
// This is not available out of the box on Windows (MSVC)
char* strndup( const char* s , size_t size );
#endif

#ifndef isnan
#define isnan(x) std::isnan(x)
#define isinf(x) std::isinf(x)
Expand Down Expand Up @@ -2548,3 +2553,27 @@ NAN_METHOD(Context2d::ArcTo) {

NanReturnUndefined();
}

#ifdef _WIN32
// From: https://code.google.com/p/madp-win/source/browse/src/argp-standalone-1.3/strndup.c
char *
strndup (const char *s, size_t size)
{
char *r;
char *end = (char*)memchr(s, 0, size);

if (end)
/* Length + 1 */
size = end - s + 1;

r = (char*)malloc(size);

if (size)
{
memcpy(r, s, size-1);
r[size-1] = '\0';
}
return r;
}
#endif

2 changes: 2 additions & 0 deletions src/unistd/unistd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* This is needed on Windows (MSVC) for Freetype, Pango, and GifLib to pass compilation */
#include <stdint.h>