From e3ca10fbe70ab531d9c6f412f49762072bc102f0 Mon Sep 17 00:00:00 2001 From: magicode Date: Sun, 27 Oct 2013 10:04:44 -0400 Subject: [PATCH 001/183] add deps --- binding.gyp | 71 ++-- deps/cairo.gyp | 246 ++++++++++++ deps/common.gyp | 41 ++ deps/custom-include/cairo/cairo-features.h | 31 ++ deps/custom-include/cairo/config.h | 414 +++++++++++++++++++++ deps/custom-include/jpeg/jconfig.1.h | 45 +++ deps/custom-include/jpeg/jconfig.h | 103 +++++ deps/custom-include/jpeg/jconfig9.h | 54 +++ deps/custom-include/pixman/config.h | 174 +++++++++ deps/custom-include/png/pnglibconf.h | 211 +++++++++++ deps/ensure_deps.sh | 67 ++++ deps/freetype.gyp | 243 ++++++++++++ deps/gif.gyp | 22 ++ deps/jpeg.gyp | 113 ++++++ deps/libpng.gyp | 68 ++++ deps/locations.gyp | 14 + deps/pixman.gyp | 60 +++ deps/zlib.gyp | 60 +++ 18 files changed, 2009 insertions(+), 28 deletions(-) create mode 100644 deps/cairo.gyp create mode 100644 deps/common.gyp create mode 100644 deps/custom-include/cairo/cairo-features.h create mode 100644 deps/custom-include/cairo/config.h create mode 100644 deps/custom-include/jpeg/jconfig.1.h create mode 100644 deps/custom-include/jpeg/jconfig.h create mode 100644 deps/custom-include/jpeg/jconfig9.h create mode 100644 deps/custom-include/pixman/config.h create mode 100644 deps/custom-include/png/pnglibconf.h create mode 100755 deps/ensure_deps.sh create mode 100644 deps/freetype.gyp create mode 100644 deps/gif.gyp create mode 100644 deps/jpeg.gyp create mode 100644 deps/libpng.gyp create mode 100644 deps/locations.gyp create mode 100644 deps/pixman.gyp create mode 100644 deps/zlib.gyp diff --git a/binding.gyp b/binding.gyp index 0fc293a0c..ab47cf2e8 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,23 +1,26 @@ { - 'conditions': [ - ['OS=="win"', { - 'variables': { - 'GTK_Root%': 'C:/GTK', # Set the location of GTK all-in-one bundle - 'with_jpeg%': 'false', - 'with_gif%': 'false', - 'with_pango%': 'false', - 'with_freetype%': 'false' - } - }, { # 'OS!="win"' - 'variables': { - 'with_jpeg%': ' header file. */ +#define HAVE_BYTESWAP_H 1 + +/* Define to 1 if you have the `clock_gettime' function. */ +#define HAVE_CLOCK_GETTIME 1 + +/* Define to 1 if you have the `ctime_r' function. */ +#define HAVE_CTIME_R 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `drand48' function. */ +#define HAVE_DRAND48 1 + +/* Define to 1 if you have the `FcFini' function. */ +#define HAVE_FCFINI 1 + +/* Define to 1 if you have the `FcInit' function. */ +#define HAVE_FCINIT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `feclearexcept' function. */ +#define HAVE_FECLEAREXCEPT 1 + +/* Define to 1 if you have the `fedisableexcept' function. */ +#define HAVE_FEDISABLEEXCEPT 1 + +/* Define to 1 if you have the `feenableexcept' function. */ +#define HAVE_FEENABLEEXCEPT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FENV_H 1 + +/* Define to 1 if you have the `flockfile' function. */ +#define HAVE_FLOCKFILE 1 + +/* Define to 1 if you have the `fork' function. */ +#define HAVE_FORK 1 + +/* Define to 1 if you have the `FT_Get_X11_Font_Format' function. */ +#define HAVE_FT_GET_X11_FONT_FORMAT 1 + +/* Define to 1 if you have the `FT_GlyphSlot_Embolden' function. */ +#define HAVE_FT_GLYPHSLOT_EMBOLDEN 1 + +/* Define to 1 if you have the `FT_GlyphSlot_Oblique' function. */ +#define HAVE_FT_GLYPHSLOT_OBLIQUE 1 + +/* Define to 1 if you have the `FT_Library_SetLcdFilter' function. */ +#define HAVE_FT_LIBRARY_SETLCDFILTER 1 + +/* Define to 1 if you have the `FT_Load_Sfnt_Table' function. */ +#define HAVE_FT_LOAD_SFNT_TABLE 1 + +/* Define to 1 if you have the `funlockfile' function. */ +#define HAVE_FUNLOCKFILE 1 + +/* Whether you have gcov */ +/* #undef HAVE_GCOV */ + +/* Define to 1 if you have the `getline' function. */ +#define HAVE_GETLINE 1 + +/* Enable if your compiler supports the Intel __sync_* atomic primitives */ +#define HAVE_INTEL_ATOMIC_PRIMITIVES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_IO_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LIBGEN_H 1 + +/* Define to 1 if you have the `rt' library (-lrt). */ +#define HAVE_LIBRT 1 + +/* Enable if you have libatomic-ops-dev installed */ +/* #undef HAVE_LIB_ATOMIC_OPS */ + +/* Define to 1 if you have the `link' function. */ +#define HAVE_LINK 1 + +/* Define to 1 if you have the Valgrind lockdep tool */ +/* #undef HAVE_LOCKDEP */ + +/* Define to 1 if you have lzo available */ +/* #undef HAVE_LZO */ + +/* Define to 1 if you have the Valgrind memfault tool */ +/* #undef HAVE_MEMFAULT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to non-zero if your system has mkdir, and to 2 if your version of + mkdir requires a mode parameter */ +#define HAVE_MKDIR 2 + +/* Define to 1 if you have the `mmap' function. */ +#define HAVE_MMAP 1 + +/* Enable if you have MacOS X atomic operations */ +/* #undef HAVE_OS_ATOMIC_OPS */ + +/* Define to 1 if you have the `poppler_page_render' function. */ +/* #undef HAVE_POPPLER_PAGE_RENDER */ + +/* Define to 1 if you have the `raise' function. */ +#define HAVE_RAISE 1 + +/* Define to 1 if you have the `rsvg_pixbuf_from_file' function. */ +/* #undef HAVE_RSVG_PIXBUF_FROM_FILE */ + +/* Define to 1 if you have the `sched_getaffinity' function. */ +#define HAVE_SCHED_GETAFFINITY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SCHED_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SETJMP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strndup' function. */ +#define HAVE_STRNDUP 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_INT_TYPES_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_MMAN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_POLL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_WAIT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TIME_H 1 + +/* Define to 1 if the system has the type `uint128_t'. */ +/* #undef HAVE_UINT128_T */ + +/* Define to 1 if the system has the type `uint64_t'. */ +#define HAVE_UINT64_T 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have Valgrind */ +/* #undef HAVE_VALGRIND */ + +/* Define to 1 if you have the `waitpid' function. */ +#define HAVE_WAITPID 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_X11_EXTENSIONS_SHMPROTO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_X11_EXTENSIONS_SHMSTR_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_X11_EXTENSIONS_XSHM_H 1 + +/* Define to 1 if you have the `XRenderCreateConicalGradient' function. */ +#define HAVE_XRENDERCREATECONICALGRADIENT 1 + +/* Define to 1 if you have the `XRenderCreateLinearGradient' function. */ +#define HAVE_XRENDERCREATELINEARGRADIENT 1 + +/* Define to 1 if you have the `XRenderCreateRadialGradient' function. */ +#define HAVE_XRENDERCREATERADIALGRADIENT 1 + +/* Define to 1 if you have zlib available */ +#define HAVE_ZLIB 1 + +/* Define to 1 if the system has the type `__uint128_t'. */ +#define HAVE___UINT128_T 1 + +/* Define to 1 if shared memory segments are released deferred. */ +#define IPC_RMID_DEFERRED_RELEASE 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "http://bugs.freedesktop.org/enter_bug.cgi?product=cairo" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME USE_cairo_INSTEAD + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING USE_cairo_version_OR_cairo_version_string_INSTEAD + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME USE_cairo_INSTEAD + +/* Define to the home page for this package. */ +#define PACKAGE_URL "http://cairographics.org/" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION USE_cairo_version_OR_cairo_version_string_INSTEAD + +/* Shared library file extension */ +#define SHARED_LIB_EXT "so" + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 8 + +/* The size of `long long', as computed by sizeof. */ +#define SIZEOF_LONG_LONG 8 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 8 + +/* The size of `void *', as computed by sizeof. */ +#define SIZEOF_VOID_P 8 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif + + +/* Define to the value your compiler uses to support the warn-unused-result + attribute */ +#define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + + +/* Deal with multiple architecture compiles on Mac OS X */ +#ifdef __APPLE_CC__ +#ifdef __BIG_ENDIAN__ +#define WORDS_BIGENDIAN 1 +#define FLOAT_WORDS_BIGENDIAN 1 +#else +/* #undef WORDS_BIGENDIAN */ +/* #undef FLOAT_WORDS_BIGENDIAN */ +#endif +#endif + + +/* Define to 1 if the X Window System is missing or not being used. */ +/* #undef X_DISPLAY_MISSING */ + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to 1 if on MINIX. */ +/* #undef _MINIX */ + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +/* #undef _POSIX_1_SOURCE */ + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +/* #undef _POSIX_SOURCE */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif diff --git a/deps/custom-include/jpeg/jconfig.1.h b/deps/custom-include/jpeg/jconfig.1.h new file mode 100644 index 000000000..9594ec56b --- /dev/null +++ b/deps/custom-include/jpeg/jconfig.1.h @@ -0,0 +1,45 @@ +/* jconfig.h. Generated automatically by configure. */ +/* jconfig.cfg --- source file edited by configure script */ +/* see jconfig.doc for explanations */ + +#define HAVE_PROTOTYPES +#define HAVE_UNSIGNED_CHAR +#define HAVE_UNSIGNED_SHORT +#undef void +#undef const +#undef CHAR_IS_UNSIGNED +#define HAVE_STDDEF_H +#define HAVE_STDLIB_H +#undef NEED_BSD_STRINGS +#undef NEED_SYS_TYPES_H +#undef NEED_FAR_POINTERS +#undef NEED_SHORT_EXTERNAL_NAMES +/* Define this if you get warnings about undefined structures. */ +#undef INCOMPLETE_TYPES_BROKEN + +#ifdef JPEG_INTERNALS + +#undef RIGHT_SHIFT_IS_UNSIGNED +#define INLINE __inline__ +/* These are for configuring the JPEG memory manager. */ +#undef DEFAULT_MAX_MEM +#undef NO_MKTEMP + +#endif /* JPEG_INTERNALS */ + +#ifdef JPEG_CJPEG_DJPEG + +#define BMP_SUPPORTED /* BMP image file format */ +#define GIF_SUPPORTED /* GIF image file format */ +#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ +#undef RLE_SUPPORTED /* Utah RLE image file format */ +#define TARGA_SUPPORTED /* Targa image file format */ + +#undef TWO_FILE_COMMANDLINE +#undef NEED_SIGNAL_CATCHER +#undef DONT_USE_B_MODE + +/* Define this if you want percent-done progress reports from cjpeg/djpeg. */ +#undef PROGRESS_REPORT + +#endif /* JPEG_CJPEG_DJPEG */ diff --git a/deps/custom-include/jpeg/jconfig.h b/deps/custom-include/jpeg/jconfig.h new file mode 100644 index 000000000..d6989d1d3 --- /dev/null +++ b/deps/custom-include/jpeg/jconfig.h @@ -0,0 +1,103 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +/* + * jconfig.h to configure the IJG JPEG library for the Mozilla/Netscape + * environment. Note that there are also Mozilla mods in jmorecfg.h. + */ + +/* We assume an ANSI C or C++ compilation environment */ +#define HAVE_PROTOTYPES +#define HAVE_UNSIGNED_CHAR +#define HAVE_UNSIGNED_SHORT +/* #define void char */ +/* #define const */ +#ifndef HAVE_STDDEF_H +#define HAVE_STDDEF_H +#endif /* HAVE_STDDEF_H */ +#ifndef HAVE_STDLIB_H +#define HAVE_STDLIB_H +#endif /* HAVE_STDLIB_H */ +#undef NEED_BSD_STRINGS +#undef NEED_SYS_TYPES_H +#undef NEED_FAR_POINTERS +#undef NEED_SHORT_EXTERNAL_NAMES +/* Define this if you get warnings about undefined structures. */ +#undef INCOMPLETE_TYPES_BROKEN + +/* With this setting, the IJG code will work regardless of whether + * type "char" is signed or unsigned. + */ +#undef CHAR_IS_UNSIGNED + + +/* defines that need not be visible to callers of the IJG library */ + +#ifdef JPEG_INTERNALS + +/* If right shift of "long" quantities is unsigned on your machine, + * you'll have to define this. Fortunately few people should need it. + */ +#undef RIGHT_SHIFT_IS_UNSIGNED + +#ifdef XP_MAC /* Macintosh */ + +#define ALIGN_TYPE long /* for sane memory alignment */ +#define NO_GETENV /* we do have the function, but it's dead */ + +#endif /* XP_MAC */ + +#endif /* JPEG_INTERNALS */ + + +/* these defines are not interesting for building just the IJG library, + * but we leave 'em here anyway. + */ +#ifdef JPEG_CJPEG_DJPEG + +#define BMP_SUPPORTED /* BMP image file format */ +#define GIF_SUPPORTED /* GIF image file format */ +#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ +#undef RLE_SUPPORTED /* Utah RLE image file format */ +#define TARGA_SUPPORTED /* Targa image file format */ + +#undef TWO_FILE_COMMANDLINE +#undef NEED_SIGNAL_CATCHER +#undef DONT_USE_B_MODE +#undef PROGRESS_REPORT + +#endif /* JPEG_CJPEG_DJPEG */ \ No newline at end of file diff --git a/deps/custom-include/jpeg/jconfig9.h b/deps/custom-include/jpeg/jconfig9.h new file mode 100644 index 000000000..966b1d514 --- /dev/null +++ b/deps/custom-include/jpeg/jconfig9.h @@ -0,0 +1,54 @@ +/* jconfig.h. Generated from jconfig.cfg by configure. */ +/* jconfig.cfg --- source file edited by configure script */ +/* see jconfig.txt for explanations */ + +#define HAVE_PROTOTYPES 1 +#define HAVE_UNSIGNED_CHAR 1 +#define HAVE_UNSIGNED_SHORT 1 +/* #undef void */ +/* #undef const */ +/* #undef CHAR_IS_UNSIGNED */ +#define HAVE_STDDEF_H 1 +#define HAVE_STDLIB_H 1 +#define HAVE_LOCALE_H 1 +/* #undef NEED_BSD_STRINGS */ +/* #undef NEED_SYS_TYPES_H */ +/* #undef NEED_FAR_POINTERS */ +/* #undef NEED_SHORT_EXTERNAL_NAMES */ +/* Define this if you get warnings about undefined structures. */ +/* #undef INCOMPLETE_TYPES_BROKEN */ + +/* Define "boolean" as unsigned char, not int, on Windows systems. */ +#ifdef _WIN32 +#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ +typedef unsigned char boolean; +#endif +#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ +#endif + +#ifdef JPEG_INTERNALS + +/* #undef RIGHT_SHIFT_IS_UNSIGNED */ +#define INLINE __inline__ +/* These are for configuring the JPEG memory manager. */ +/* #undef DEFAULT_MAX_MEM */ +/* #undef NO_MKTEMP */ + +#endif /* JPEG_INTERNALS */ + +#ifdef JPEG_CJPEG_DJPEG + +#define BMP_SUPPORTED /* BMP image file format */ +#define GIF_SUPPORTED /* GIF image file format */ +#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ +/* #undef RLE_SUPPORTED */ +#define TARGA_SUPPORTED /* Targa image file format */ + +/* #undef TWO_FILE_COMMANDLINE */ +/* #undef NEED_SIGNAL_CATCHER */ +/* #undef DONT_USE_B_MODE */ + +/* Define this if you want percent-done progress reports from cjpeg/djpeg. */ +/* #undef PROGRESS_REPORT */ + +#endif /* JPEG_CJPEG_DJPEG */ diff --git a/deps/custom-include/pixman/config.h b/deps/custom-include/pixman/config.h new file mode 100644 index 000000000..a6d2c02ef --- /dev/null +++ b/deps/custom-include/pixman/config.h @@ -0,0 +1,174 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* Whether we have alarm() */ +#define HAVE_ALARM 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Whether we have feenableexcept() */ +#define HAVE_FEENABLEEXCEPT 1 + +/* Define to 1 if we have */ +#define HAVE_FENV_H 1 + +/* Whether the tool chain supports __float128 */ +#define HAVE_FLOAT128 /**/ + +/* Define to 1 if you have the `getisax' function. */ +/* #undef HAVE_GETISAX */ + +/* Whether we have getpagesize() */ +#define HAVE_GETPAGESIZE 1 + +/* Whether we have gettimeofday() */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `pixman-1' library (-lpixman-1). */ +/* #undef HAVE_LIBPIXMAN_1 */ + +/* Whether we have libpng */ +#define HAVE_LIBPNG 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Whether we have mmap() */ +#define HAVE_MMAP 1 + +/* Whether we have mprotect() */ +#define HAVE_MPROTECT 1 + +/* Whether we have posix_memalign() */ +#define HAVE_POSIX_MEMALIGN 1 + +/* Whether pthread_setspecific() is supported */ +/* #undef HAVE_PTHREAD_SETSPECIFIC */ + +/* Whether we have sigaction() */ +#define HAVE_SIGACTION 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if we have */ +#define HAVE_SYS_MMAN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "pixman" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "pixman@lists.freedesktop.org" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "pixman" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "pixman 0.30.2" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "pixman" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "0.30.2" + +/* enable TIMER_BEGIN/TIMER_END macros */ +/* #undef PIXMAN_TIMERS */ + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 8 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* The compiler supported TLS storage class */ +#define TLS __thread + +/* Whether the tool chain supports __attribute__((constructor)) */ +#define TOOLCHAIN_SUPPORTS_ATTRIBUTE_CONSTRUCTOR /**/ + +/* use ARM IWMMXT compiler intrinsics */ +/* #undef USE_ARM_IWMMXT */ + +/* use ARM NEON assembly optimizations */ +/* #undef USE_ARM_NEON */ + +/* use ARM SIMD assembly optimizations */ +/* #undef USE_ARM_SIMD */ + +/* use GNU-style inline assembler */ +#define USE_GCC_INLINE_ASM 1 + +/* use Loongson Multimedia Instructions */ +/* #undef USE_LOONGSON_MMI */ + +/* use MIPS DSPr2 assembly optimizations */ +/* #undef USE_MIPS_DSPR2 */ + +/* use OpenMP in the test suite */ +#define USE_OPENMP 1 + +/* use SSE2 compiler intrinsics */ +#define USE_SSE2 1 + +/* use VMX compiler intrinsics */ +/* #undef USE_VMX */ + +/* use x86 MMX compiler intrinsics */ +#define USE_X86_MMX 1 + +/* Version number of package */ +#define VERSION "0.30.2" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to sqrt if you do not have the `sqrtf' function. */ +/* #undef sqrtf */ diff --git a/deps/custom-include/png/pnglibconf.h b/deps/custom-include/png/pnglibconf.h new file mode 100644 index 000000000..e31ff3dec --- /dev/null +++ b/deps/custom-include/png/pnglibconf.h @@ -0,0 +1,211 @@ +/* libpng 1.6.6 STANDARD API DEFINITION */ + +/* pnglibconf.h - library build configuration */ + +/* Libpng version 1.6.6 - September 16, 2013 */ + +/* Copyright (c) 1998-2013 Glenn Randers-Pehrson */ + +/* This code is released under the libpng license. */ +/* For conditions of distribution and use, see the disclaimer */ +/* and license in png.h */ + +/* pnglibconf.h */ +/* Machine generated file: DO NOT EDIT */ +/* Derived from: scripts/pnglibconf.dfa */ +#ifndef PNGLCONF_H +#define PNGLCONF_H +/* options */ +#define PNG_16BIT_SUPPORTED +#define PNG_ALIGNED_MEMORY_SUPPORTED +/*#undef PNG_ARM_NEON_API_SUPPORTED*/ +/*#undef PNG_ARM_NEON_CHECK_SUPPORTED*/ +#define PNG_BENIGN_ERRORS_SUPPORTED +#define PNG_BENIGN_READ_ERRORS_SUPPORTED +/*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/ +#define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED +#define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED +#define PNG_COLORSPACE_SUPPORTED +#define PNG_CONSOLE_IO_SUPPORTED +#define PNG_CONVERT_tIME_SUPPORTED +#define PNG_EASY_ACCESS_SUPPORTED +/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/ +#define PNG_ERROR_TEXT_SUPPORTED +#define PNG_FIXED_POINT_SUPPORTED +#define PNG_FLOATING_ARITHMETIC_SUPPORTED +#define PNG_FLOATING_POINT_SUPPORTED +#define PNG_FORMAT_AFIRST_SUPPORTED +#define PNG_FORMAT_BGR_SUPPORTED +#define PNG_GAMMA_SUPPORTED +#define PNG_GET_PALETTE_MAX_SUPPORTED +#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED +#define PNG_INCH_CONVERSIONS_SUPPORTED +#define PNG_INFO_IMAGE_SUPPORTED +#define PNG_IO_STATE_SUPPORTED +#define PNG_MNG_FEATURES_SUPPORTED +#define PNG_POINTER_INDEXING_SUPPORTED +#define PNG_PROGRESSIVE_READ_SUPPORTED +#define PNG_READ_16BIT_SUPPORTED +#define PNG_READ_ALPHA_MODE_SUPPORTED +#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED +#define PNG_READ_BACKGROUND_SUPPORTED +#define PNG_READ_BGR_SUPPORTED +#define PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED +#define PNG_READ_COMPOSITE_NODIV_SUPPORTED +#define PNG_READ_COMPRESSED_TEXT_SUPPORTED +#define PNG_READ_EXPAND_16_SUPPORTED +#define PNG_READ_EXPAND_SUPPORTED +#define PNG_READ_FILLER_SUPPORTED +#define PNG_READ_GAMMA_SUPPORTED +#define PNG_READ_GET_PALETTE_MAX_SUPPORTED +#define PNG_READ_GRAY_TO_RGB_SUPPORTED +#define PNG_READ_INTERLACING_SUPPORTED +#define PNG_READ_INT_FUNCTIONS_SUPPORTED +#define PNG_READ_INVERT_ALPHA_SUPPORTED +#define PNG_READ_INVERT_SUPPORTED +#define PNG_READ_OPT_PLTE_SUPPORTED +#define PNG_READ_PACKSWAP_SUPPORTED +#define PNG_READ_PACK_SUPPORTED +#define PNG_READ_QUANTIZE_SUPPORTED +#define PNG_READ_RGB_TO_GRAY_SUPPORTED +#define PNG_READ_SCALE_16_TO_8_SUPPORTED +#define PNG_READ_SHIFT_SUPPORTED +#define PNG_READ_STRIP_16_TO_8_SUPPORTED +#define PNG_READ_STRIP_ALPHA_SUPPORTED +#define PNG_READ_SUPPORTED +#define PNG_READ_SWAP_ALPHA_SUPPORTED +#define PNG_READ_SWAP_SUPPORTED +#define PNG_READ_TEXT_SUPPORTED +#define PNG_READ_TRANSFORMS_SUPPORTED +#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_READ_USER_CHUNKS_SUPPORTED +#define PNG_READ_USER_TRANSFORM_SUPPORTED +#define PNG_READ_bKGD_SUPPORTED +#define PNG_READ_cHRM_SUPPORTED +#define PNG_READ_gAMA_SUPPORTED +#define PNG_READ_hIST_SUPPORTED +#define PNG_READ_iCCP_SUPPORTED +#define PNG_READ_iTXt_SUPPORTED +#define PNG_READ_oFFs_SUPPORTED +#define PNG_READ_pCAL_SUPPORTED +#define PNG_READ_pHYs_SUPPORTED +#define PNG_READ_sBIT_SUPPORTED +#define PNG_READ_sCAL_SUPPORTED +#define PNG_READ_sPLT_SUPPORTED +#define PNG_READ_sRGB_SUPPORTED +#define PNG_READ_tEXt_SUPPORTED +#define PNG_READ_tIME_SUPPORTED +#define PNG_READ_tRNS_SUPPORTED +#define PNG_READ_zTXt_SUPPORTED +/*#undef PNG_SAFE_LIMITS_SUPPORTED*/ +#define PNG_SAVE_INT_32_SUPPORTED +#define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_SEQUENTIAL_READ_SUPPORTED +#define PNG_SETJMP_SUPPORTED +#define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED +#define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED +#define PNG_SET_OPTION_SUPPORTED +#define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_SET_USER_LIMITS_SUPPORTED +#define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED +#define PNG_SIMPLIFIED_READ_BGR_SUPPORTED +#define PNG_SIMPLIFIED_READ_SUPPORTED +#define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED +#define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED +#define PNG_SIMPLIFIED_WRITE_SUPPORTED +#define PNG_STDIO_SUPPORTED +#define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_TEXT_SUPPORTED +#define PNG_TIME_RFC1123_SUPPORTED +#define PNG_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_USER_CHUNKS_SUPPORTED +#define PNG_USER_LIMITS_SUPPORTED +#define PNG_USER_MEM_SUPPORTED +#define PNG_USER_TRANSFORM_INFO_SUPPORTED +#define PNG_USER_TRANSFORM_PTR_SUPPORTED +#define PNG_WARNINGS_SUPPORTED +#define PNG_WRITE_16BIT_SUPPORTED +#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED +#define PNG_WRITE_BGR_SUPPORTED +#define PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED +#define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED +#define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED +#define PNG_WRITE_FILLER_SUPPORTED +#define PNG_WRITE_FILTER_SUPPORTED +#define PNG_WRITE_FLUSH_SUPPORTED +#define PNG_WRITE_GET_PALETTE_MAX_SUPPORTED +#define PNG_WRITE_INTERLACING_SUPPORTED +#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED +#define PNG_WRITE_INVERT_ALPHA_SUPPORTED +#define PNG_WRITE_INVERT_SUPPORTED +#define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED +#define PNG_WRITE_PACKSWAP_SUPPORTED +#define PNG_WRITE_PACK_SUPPORTED +#define PNG_WRITE_SHIFT_SUPPORTED +#define PNG_WRITE_SUPPORTED +#define PNG_WRITE_SWAP_ALPHA_SUPPORTED +#define PNG_WRITE_SWAP_SUPPORTED +#define PNG_WRITE_TEXT_SUPPORTED +#define PNG_WRITE_TRANSFORMS_SUPPORTED +#define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_WRITE_USER_TRANSFORM_SUPPORTED +#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED +#define PNG_WRITE_bKGD_SUPPORTED +#define PNG_WRITE_cHRM_SUPPORTED +#define PNG_WRITE_gAMA_SUPPORTED +#define PNG_WRITE_hIST_SUPPORTED +#define PNG_WRITE_iCCP_SUPPORTED +#define PNG_WRITE_iTXt_SUPPORTED +#define PNG_WRITE_oFFs_SUPPORTED +#define PNG_WRITE_pCAL_SUPPORTED +#define PNG_WRITE_pHYs_SUPPORTED +#define PNG_WRITE_sBIT_SUPPORTED +#define PNG_WRITE_sCAL_SUPPORTED +#define PNG_WRITE_sPLT_SUPPORTED +#define PNG_WRITE_sRGB_SUPPORTED +#define PNG_WRITE_tEXt_SUPPORTED +#define PNG_WRITE_tIME_SUPPORTED +#define PNG_WRITE_tRNS_SUPPORTED +#define PNG_WRITE_zTXt_SUPPORTED +#define PNG_bKGD_SUPPORTED +#define PNG_cHRM_SUPPORTED +#define PNG_gAMA_SUPPORTED +#define PNG_hIST_SUPPORTED +#define PNG_iCCP_SUPPORTED +#define PNG_iTXt_SUPPORTED +#define PNG_oFFs_SUPPORTED +#define PNG_pCAL_SUPPORTED +#define PNG_pHYs_SUPPORTED +#define PNG_sBIT_SUPPORTED +#define PNG_sCAL_SUPPORTED +#define PNG_sPLT_SUPPORTED +#define PNG_sRGB_SUPPORTED +#define PNG_tEXt_SUPPORTED +#define PNG_tIME_SUPPORTED +#define PNG_tRNS_SUPPORTED +#define PNG_zTXt_SUPPORTED +/* end of options */ +/* settings */ +#define PNG_API_RULE 0 +#define PNG_CALLOC_SUPPORTED +#define PNG_COST_SHIFT 3 +#define PNG_DEFAULT_READ_MACROS 1 +#define PNG_GAMMA_THRESHOLD_FIXED 5000 +#define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE +#define PNG_INFLATE_BUF_SIZE 1024 +#define PNG_MAX_GAMMA_8 11 +#define PNG_QUANTIZE_BLUE_BITS 5 +#define PNG_QUANTIZE_GREEN_BITS 5 +#define PNG_QUANTIZE_RED_BITS 5 +#define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1) +#define PNG_TEXT_Z_DEFAULT_STRATEGY 0 +#define PNG_WEIGHT_SHIFT 8 +#define PNG_ZBUF_SIZE 8192 +#define PNG_ZLIB_VERNUM 0 /* unknown */ +#define PNG_Z_DEFAULT_COMPRESSION (-1) +#define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0 +#define PNG_Z_DEFAULT_STRATEGY 1 +#define PNG_sCAL_PRECISION 5 +#define PNG_sRGB_PROFILE_CHECKS 2 +/* end of settings */ +#endif /* PNGLCONF_H */ diff --git a/deps/ensure_deps.sh b/deps/ensure_deps.sh new file mode 100755 index 000000000..3fc992450 --- /dev/null +++ b/deps/ensure_deps.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +cd $(dirname $0) + + +if [ ! -d "cairo-1.12.16" ]; then + if [ ! -f "cairo-1.12.16.tar.xz" ]; then + wget "http://cairographics.org/releases/cairo-1.12.16.tar.xz" + fi + tar -xf "cairo-1.12.16.tar.xz" + mv "cairo-1.12.16/src" "cairo-1.12.16/cairo" +fi + + +if [ ! -d "pixman-0.30.2" ]; then + if [ ! -f "pixman-0.30.2.tar.gz" ]; then + wget "http://cairographics.org/releases/pixman-0.30.2.tar.gz" + fi + tar -xf "pixman-0.30.2.tar.gz" +fi + + +if [ ! -d "freetype-2.5.0" ]; then + if [ ! -f "freetype-2.5.0.tar.gz" ]; then + wget "http://download.savannah.gnu.org/releases/freetype/freetype-2.5.0.tar.gz" + fi + tar -xf "freetype-2.5.0.tar.gz" +fi + +if [ ! -d "zlib-1.2.8" ]; then + if [ ! -f "zlib-1.2.8.tar.gz" ]; then + wget "http://zlib.net/zlib-1.2.8.tar.gz" + fi + tar -xf "zlib-1.2.8.tar.gz" +fi + +if [ ! -d "libpng-1.2.49" ]; then + if [ ! -f "libpng-1.2.49.tar.gz" ]; then + wget "http://sourceforge.net/projects/libpng/files/libpng12/older-releases/1.2.49/libpng-1.2.49.tar.gz" + fi + tar -xf "libpng-1.2.49.tar.gz" +fi + +if [ ! -d "jpeg-6b" ]; then + if [ ! -f "jpegsrc.v6b.tar.gz" ]; then + wget "http://www.ijg.org/files/jpegsrc.v6b.tar.gz" + fi + tar -xf "jpegsrc.v6b.tar.gz" +fi + +if [ ! -d "giflib-4.2.3" ]; then + if [ ! -f "giflib-4.2.3.tar.gz" ]; then + wget "http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-4.2.3.tar.gz" + fi + tar -xf "giflib-4.2.3.tar.gz" +fi + + + + +if [ ! -d "cairo-1.12.16" ] || [ ! -d "pixman-0.30.2" ] || [ ! -d "freetype-2.5.0" ] || [ ! -d "zlib-1.2.8" ] || [ ! -d "libpng-1.2.49" ] || [ ! -d "jpeg-6b" ] || [ ! -d "giflib-4.2.3" ]; then + echo false +else + echo true +fi + + diff --git a/deps/freetype.gyp b/deps/freetype.gyp new file mode 100644 index 000000000..fda44ce2a --- /dev/null +++ b/deps/freetype.gyp @@ -0,0 +1,243 @@ +{ + + 'includes': [ 'common.gyp' , 'locations.gyp'], + 'targets': [ + { + 'target_name': 'freetype', + 'type': 'static_library', + 'include_dirs': [ '<(freetype_root)include/'], + + 'libraries': [ + + ], + 'defines': [ 'FT2_BUILD_LIBRARY' ], + 'sources': [ + #"<(freetype_root)src/autofit/afangles.c", + #"<(freetype_root)src/autofit/afcjk.c", + #"<(freetype_root)src/autofit/afdummy.c", + #"<(freetype_root)src/autofit/afglobal.c", + #"<(freetype_root)src/autofit/afhints.c", + #"<(freetype_root)src/autofit/afindic.c", + #"<(freetype_root)src/autofit/aflatin2.c", + #"<(freetype_root)src/autofit/aflatin.c", + #"<(freetype_root)src/autofit/afloader.c", + #"<(freetype_root)src/autofit/afmodule.c", + #"<(freetype_root)src/autofit/afpic.c", + #"<(freetype_root)src/autofit/afwarp.c", + "<(freetype_root)src/autofit/autofit.c", + + #"<(freetype_root)src/base/basepic.c", + #"<(freetype_root)src/base/ftadvanc.c", + #"<(freetype_root)src/base/ftapi.c", + "<(freetype_root)src/base/ftbase.c", + #"<(freetype_root)src/base/ftbbox.c", + #"<(freetype_root)src/base/ftbitmap.c", + #"<(freetype_root)src/base/ftcalc.c", + #"<(freetype_root)src/base/ftcid.c", + #"<(freetype_root)src/base/ftdbgmem.c", + #"<(freetype_root)src/base/ftdebug.c", + #"<(freetype_root)src/base/ftfstype.c", + #"<(freetype_root)src/base/ftgasp.c", + #"<(freetype_root)src/base/ftgloadr.c", + #"<(freetype_root)src/base/ftglyph.c", + #"<(freetype_root)src/base/ftgxval.c", + #"<(freetype_root)src/base/ftinit.c", + #"<(freetype_root)src/base/ftlcdfil.c", + #"<(freetype_root)src/base/ftmac.c", + #"<(freetype_root)src/base/ftmm.c", + #"<(freetype_root)src/base/ftobjs.c", + #"<(freetype_root)src/base/ftotval.c", + #"<(freetype_root)src/base/ftoutln.c", + #"<(freetype_root)src/base/ftpatent.c", + #"<(freetype_root)src/base/ftpfr.c", + #"<(freetype_root)src/base/ftpic.c", + #"<(freetype_root)src/base/ftrfork.c", + #"<(freetype_root)src/base/ftsnames.c", + #"<(freetype_root)src/base/ftstream.c", + #"<(freetype_root)src/base/ftstroke.c", + #"<(freetype_root)src/base/ftsynth.c", + #"<(freetype_root)src/base/ftsystem.c", + #"<(freetype_root)src/base/fttrigon.c", + #"<(freetype_root)src/base/fttype1.c", + #"<(freetype_root)src/base/ftutil.c", + #"<(freetype_root)src/base/ftwinfnt.c", + #"<(freetype_root)src/base/ftxf86.c", + #"<(freetype_root)src/base/md5.c", + + "<(freetype_root)src/bdf/bdf.c", + #"<(freetype_root)src/bdf/bdfdrivr.c", + #"<(freetype_root)src/bdf/bdflib.c", + + "<(freetype_root)src/bzip2/ftbzip2.c", + + "<(freetype_root)src/cache/ftcache.c", + #"<(freetype_root)src/cache/ftcbasic.c", + #"<(freetype_root)src/cache/ftccache.c", + #"<(freetype_root)src/cache/ftccmap.c", + #"<(freetype_root)src/cache/ftcglyph.c", + #"<(freetype_root)src/cache/ftcimage.c", + #"<(freetype_root)src/cache/ftcmanag.c", + #"<(freetype_root)src/cache/ftcmru.c", + #"<(freetype_root)src/cache/ftcsbits.c", + + #"<(freetype_root)src/cff/cf2arrst.c", + #"<(freetype_root)src/cff/cf2blues.c", + #"<(freetype_root)src/cff/cf2error.c", + #"<(freetype_root)src/cff/cf2font.c", + #"<(freetype_root)src/cff/cf2ft.c", + #"<(freetype_root)src/cff/cf2hints.c", + #"<(freetype_root)src/cff/cf2intrp.c", + #"<(freetype_root)src/cff/cf2read.c", + #"<(freetype_root)src/cff/cf2stack.c", + "<(freetype_root)src/cff/cff.c", + #"<(freetype_root)src/cff/cffcmap.c", + #"<(freetype_root)src/cff/cffdrivr.c", + #"<(freetype_root)src/cff/cffgload.c", + #"<(freetype_root)src/cff/cffload.c", + #"<(freetype_root)src/cff/cffobjs.c", + #"<(freetype_root)src/cff/cffparse.c", + #"<(freetype_root)src/cff/cffpic.c", + + #"<(freetype_root)src/cid/cidgload.c", + #"<(freetype_root)src/cid/cidload.c", + #"<(freetype_root)src/cid/cidobjs.c", + #"<(freetype_root)src/cid/cidparse.c", + #"<(freetype_root)src/cid/cidriver.c", + "<(freetype_root)src/cid/type1cid.c", + + "<(freetype_root)src/gxvalid/gxvalid.c", + #"<(freetype_root)src/gxvalid/gxvbsln.c", + #"<(freetype_root)src/gxvalid/gxvcommn.c", + #"<(freetype_root)src/gxvalid/gxvfeat.c", + #"<(freetype_root)src/gxvalid/gxvfgen.c", + #"<(freetype_root)src/gxvalid/gxvjust.c", + #"<(freetype_root)src/gxvalid/gxvkern.c", + #"<(freetype_root)src/gxvalid/gxvlcar.c", + #"<(freetype_root)src/gxvalid/gxvmod.c", + #"<(freetype_root)src/gxvalid/gxvmort0.c", + #"<(freetype_root)src/gxvalid/gxvmort1.c", + #"<(freetype_root)src/gxvalid/gxvmort2.c", + #"<(freetype_root)src/gxvalid/gxvmort4.c", + #"<(freetype_root)src/gxvalid/gxvmort5.c", + #"<(freetype_root)src/gxvalid/gxvmort.c", + #"<(freetype_root)src/gxvalid/gxvmorx0.c", + #"<(freetype_root)src/gxvalid/gxvmorx1.c", + #"<(freetype_root)src/gxvalid/gxvmorx2.c", + #"<(freetype_root)src/gxvalid/gxvmorx4.c", + #"<(freetype_root)src/gxvalid/gxvmorx5.c", + #"<(freetype_root)src/gxvalid/gxvmorx.c", + #"<(freetype_root)src/gxvalid/gxvopbd.c", + #"<(freetype_root)src/gxvalid/gxvprop.c", + #"<(freetype_root)src/gxvalid/gxvtrak.c", + + #"<(freetype_root)src/gzip/adler32.c", + "<(freetype_root)src/gzip/ftgzip.c", + #"<(freetype_root)src/gzip/infblock.c", + #"<(freetype_root)src/gzip/infcodes.c", + #"<(freetype_root)src/gzip/inflate.c", + #"<(freetype_root)src/gzip/inftrees.c", + #"<(freetype_root)src/gzip/infutil.c", + #"<(freetype_root)src/gzip/zutil.c", + + "<(freetype_root)src/lzw/ftlzw.c", + #"<(freetype_root)src/lzw/ftzopen.c", + + "<(freetype_root)src/otvalid/otvalid.c", + #"<(freetype_root)src/otvalid/otvbase.c", + #"<(freetype_root)src/otvalid/otvcommn.c", + #"<(freetype_root)src/otvalid/otvgdef.c", + #"<(freetype_root)src/otvalid/otvgpos.c", + #"<(freetype_root)src/otvalid/otvgsub.c", + #"<(freetype_root)src/otvalid/otvjstf.c", + #"<(freetype_root)src/otvalid/otvmath.c", + #"<(freetype_root)src/otvalid/otvmod.c", + + "<(freetype_root)src/pcf/pcf.c", + #"<(freetype_root)src/pcf/pcfdrivr.c", + #"<(freetype_root)src/pcf/pcfread.c", + #"<(freetype_root)src/pcf/pcfutil.c", + + "<(freetype_root)src/pfr/pfr.c", + #"<(freetype_root)src/pfr/pfrcmap.c", + #"<(freetype_root)src/pfr/pfrdrivr.c", + #"<(freetype_root)src/pfr/pfrgload.c", + #"<(freetype_root)src/pfr/pfrload.c", + #"<(freetype_root)src/pfr/pfrobjs.c", + #"<(freetype_root)src/pfr/pfrsbit.c", + + #"<(freetype_root)src/psaux/afmparse.c", + "<(freetype_root)src/psaux/psaux.c", + #"<(freetype_root)src/psaux/psauxmod.c", + #"<(freetype_root)src/psaux/psconv.c", + #"<(freetype_root)src/psaux/psobjs.c", + #"<(freetype_root)src/psaux/t1cmap.c", + #"<(freetype_root)src/psaux/t1decode.c", + + #"<(freetype_root)src/pshinter/pshalgo.c", + #"<(freetype_root)src/pshinter/pshglob.c", + "<(freetype_root)src/pshinter/pshinter.c", + #"<(freetype_root)src/pshinter/pshmod.c", + #"<(freetype_root)src/pshinter/pshpic.c", + #"<(freetype_root)src/pshinter/pshrec.c", + + #"<(freetype_root)src/psnames/psmodule.c", + "<(freetype_root)src/psnames/psnames.c", + #"<(freetype_root)src/psnames/pspic.c", + + #"<(freetype_root)src/raster/ftraster.c", + #"<(freetype_root)src/raster/ftrend1.c", + "<(freetype_root)src/raster/raster.c", + #"<(freetype_root)src/raster/rastpic.c", + + #"<(freetype_root)src/sfnt/pngshim.c", + #"<(freetype_root)src/sfnt/sfdriver.c", + "<(freetype_root)src/sfnt/sfnt.c", + #"<(freetype_root)src/sfnt/sfntpic.c", + #"<(freetype_root)src/sfnt/sfobjs.c", + #"<(freetype_root)src/sfnt/ttbdf.c", + #"<(freetype_root)src/sfnt/ttcmap.c", + #"<(freetype_root)src/sfnt/ttkern.c", + #"<(freetype_root)src/sfnt/ttload.c", + #"<(freetype_root)src/sfnt/ttmtx.c", + #"<(freetype_root)src/sfnt/ttpost.c", + #"<(freetype_root)src/sfnt/ttsbit.c", + + #"<(freetype_root)src/smooth/ftgrays.c", + #"<(freetype_root)src/smooth/ftsmooth.c", + #"<(freetype_root)src/smooth/ftspic.c", + "<(freetype_root)src/smooth/smooth.c", + + "<(freetype_root)src/tools/apinames.c", + "<(freetype_root)src/tools/ftrandom/ftrandom.c", + "<(freetype_root)src/tools/test_afm.c", + "<(freetype_root)src/tools/test_bbox.c", + "<(freetype_root)src/tools/test_trig.c", + + "<(freetype_root)src/truetype/truetype.c", + #"<(freetype_root)src/truetype/ttdriver.c", + #"<(freetype_root)src/truetype/ttgload.c", + #"<(freetype_root)src/truetype/ttgxvar.c", + #"<(freetype_root)src/truetype/ttinterp.c", + #"<(freetype_root)src/truetype/ttobjs.c", + #"<(freetype_root)src/truetype/ttpic.c", + #"<(freetype_root)src/truetype/ttpload.c", + #"<(freetype_root)src/truetype/ttsubpix.c", + + #"<(freetype_root)src/type1/t1afm.c", + #"<(freetype_root)src/type1/t1driver.c", + #"<(freetype_root)src/type1/t1gload.c", + #"<(freetype_root)src/type1/t1load.c", + #"<(freetype_root)src/type1/t1objs.c", + #"<(freetype_root)src/type1/t1parse.c", + "<(freetype_root)src/type1/type1.c", + + #"<(freetype_root)src/type42/t42drivr.c", + #"<(freetype_root)src/type42/t42objs.c", + #"<(freetype_root)src/type42/t42parse.c", + "<(freetype_root)src/type42/type42.c", + + "<(freetype_root)src/winfonts/winfnt.c", + ], + }, + ] +} diff --git a/deps/gif.gyp b/deps/gif.gyp new file mode 100644 index 000000000..06eb77c61 --- /dev/null +++ b/deps/gif.gyp @@ -0,0 +1,22 @@ +{ + + 'includes': [ 'common.gyp' , 'locations.gyp'], + 'targets': [ + { + 'target_name': 'gif', + 'type': 'static_library', + 'include_dirs': [ '<(gif_root)lib/'], + 'libraries': [ + ], + 'defines': [ ], + 'sources': [ + "<(gif_root)lib/dgif_lib.c", + "<(gif_root)lib/egif_lib.c", + "<(gif_root)lib/gifalloc.c", + "<(gif_root)lib/gif_err.c", + "<(gif_root)lib/gif_font.c", + "<(gif_root)lib/gif_hash.c", + ], + }, + ] +} diff --git a/deps/jpeg.gyp b/deps/jpeg.gyp new file mode 100644 index 000000000..b450638c6 --- /dev/null +++ b/deps/jpeg.gyp @@ -0,0 +1,113 @@ +{ + + 'includes': [ 'common.gyp' , 'locations.gyp'], + 'targets': [ + { + 'target_name': 'libjpeg', + 'type': 'static_library', + 'include_dirs': [ + './custom-include/jpeg/', + '<(jpeg_root)' , + ], + + 'dependencies': [], + 'defines': [], + 'sources': [ + + #"<(jpeg_root)ansi2knr.c", + #"<(jpeg_root)cdjpeg.c", + #"<(jpeg_root)cjpeg.c", + #"<(jpeg_root)ckconfig.c", + #"<(jpeg_root)djpeg.c", + #"<(jpeg_root)example.c", + + + "<(jpeg_root)jcapimin.c", + "<(jpeg_root)jcapistd.c", + "<(jpeg_root)jccoefct.c", + "<(jpeg_root)jccolor.c", + "<(jpeg_root)jcdctmgr.c", + "<(jpeg_root)jchuff.c", + "<(jpeg_root)jchuff.h", + "<(jpeg_root)jcinit.c", + "<(jpeg_root)jcmainct.c", + "<(jpeg_root)jcmarker.c", + "<(jpeg_root)jcmaster.c", + "<(jpeg_root)jcomapi.c", + "./custom-include/jpeg/jconfig.h", + "<(jpeg_root)jcparam.c", + "<(jpeg_root)jcphuff.c", + "<(jpeg_root)jcprepct.c", + "<(jpeg_root)jcsample.c", + #"<(jpeg_root)jctrans.c", + "<(jpeg_root)jdapimin.c", + "<(jpeg_root)jdapistd.c", + "<(jpeg_root)jdatadst.c", + "<(jpeg_root)jdatasrc.c", + "<(jpeg_root)jdcoefct.c", + "<(jpeg_root)jdcolor.c", + "<(jpeg_root)jdct.h", + "<(jpeg_root)jddctmgr.c", + "<(jpeg_root)jdhuff.c", + "<(jpeg_root)jdhuff.h", + "<(jpeg_root)jdinput.c", + "<(jpeg_root)jdmainct.c", + "<(jpeg_root)jdmarker.c", + "<(jpeg_root)jdmaster.c", + "<(jpeg_root)jdmerge.c", + "<(jpeg_root)jdphuff.c", + "<(jpeg_root)jdpostct.c", + "<(jpeg_root)jdsample.c", + #"<(jpeg_root)jdtrans.c", + "<(jpeg_root)jerror.c", + "<(jpeg_root)jerror.h", + "<(jpeg_root)jfdctflt.c", + "<(jpeg_root)jfdctfst.c", + "<(jpeg_root)jfdctint.c", + "<(jpeg_root)jidctflt.c", + "<(jpeg_root)jidctfst.c", + "<(jpeg_root)jidctint.c", + "<(jpeg_root)jinclude.h", + + #"<(jpeg_root)jidctred.c", + + #"<(jpeg_root)jmemansi.c", + #"<(jpeg_root)jmemdos.c", + #"<(jpeg_root)jmemmac.c", + + "<(jpeg_root)jmemmgr.c", + + #"<(jpeg_root)jmemname.c", + "<(jpeg_root)jmemnobs.c", + #"<(jpeg_root)jpegtran.c", + + "<(jpeg_root)jquant1.c", + "<(jpeg_root)jquant2.c", + + "<(jpeg_root)jmemsys.h", + "<(jpeg_root)jmorecfg.h", + "<(jpeg_root)jpegint.h", + "<(jpeg_root)jpeglib.h", + + "<(jpeg_root)jutils.c", + "<(jpeg_root)jversion.h", + + #"<(jpeg_root)rdbmp.c", + #"<(jpeg_root)rdcolmap.c", + #"<(jpeg_root)rdgif.c", + #"<(jpeg_root)rdjpgcom.c", + #"<(jpeg_root)rdppm.c", + #"<(jpeg_root)rdrle.c", + #"<(jpeg_root)rdswitch.c", + #"<(jpeg_root)rdtarga.c", + #"<(jpeg_root)transupp.c", + #"<(jpeg_root)wrbmp.c", + #"<(jpeg_root)wrgif.c", + #"<(jpeg_root)wrjpgcom.c", + #"<(jpeg_root)wrppm.c", + #"<(jpeg_root)wrrle.c", + #"<(jpeg_root)wrtarga.c", + ], + }, + ] +} diff --git a/deps/libpng.gyp b/deps/libpng.gyp new file mode 100644 index 000000000..43c9a22c9 --- /dev/null +++ b/deps/libpng.gyp @@ -0,0 +1,68 @@ +{ + + 'includes': [ 'common.gyp' , 'locations.gyp'], + 'targets': [ + { + 'target_name': 'png', + 'type': 'static_library', + 'include_dirs': [ + '<(libpng_root)' , + './custom-include/png/', + ], + + 'dependencies': [ + 'zlib.gyp:zlib' + ], + 'defines': [], + 'sources': [ + #"<(libpng_root)arm/arm_init.c", + #"<(libpng_root)contrib/examples/iccfrompng.c", + #"<(libpng_root)contrib/examples/pngpixel.c", + #"<(libpng_root)contrib/examples/pngtopng.c", + #"<(libpng_root)contrib/gregbook/readpng2.c", + #"<(libpng_root)contrib/gregbook/readpng.c", + #"<(libpng_root)contrib/gregbook/readppm.c", + #"<(libpng_root)contrib/gregbook/rpng2-win.c", + #"<(libpng_root)contrib/gregbook/rpng2-x.c", + #"<(libpng_root)contrib/gregbook/rpng-win.c", + #"<(libpng_root)contrib/gregbook/rpng-x.c", + #"<(libpng_root)contrib/gregbook/wpng.c", + #"<(libpng_root)contrib/gregbook/writepng.c", + #"<(libpng_root)contrib/libtests/fakepng.c", + #"<(libpng_root)contrib/libtests/makepng.c", + #"<(libpng_root)contrib/libtests/pngstest.c", + #"<(libpng_root)contrib/libtests/pngunknown.c", + #"<(libpng_root)contrib/libtests/pngvalid.c", + #"<(libpng_root)contrib/libtests/readpng.c", + #"<(libpng_root)contrib/libtests/tarith.c", + #"<(libpng_root)contrib/libtests/timepng.c", + #"<(libpng_root)contrib/pngminus/png2pnm.c", + #"<(libpng_root)contrib/pngminus/pnm2png.c", + #"<(libpng_root)contrib/tools/checksum-icc.c", + #"<(libpng_root)contrib/tools/cvtcolor.c", + #"<(libpng_root)contrib/tools/makesRGB.c", + #"<(libpng_root)contrib/tools/pngfix.c", + #"<(libpng_root)contrib/tools/png-fix-itxt.c", + #"<(libpng_root)contrib/visupng/PngFile.c", + #"<(libpng_root)contrib/visupng/VisualPng.c", + #"<(libpng_root)example.c", + "<(libpng_root)png.c", + "<(libpng_root)pngerror.c", + "<(libpng_root)pngget.c", + "<(libpng_root)pngmem.c", + "<(libpng_root)pngpread.c", + "<(libpng_root)pngread.c", + "<(libpng_root)pngrio.c", + "<(libpng_root)pngrtran.c", + "<(libpng_root)pngrutil.c", + "<(libpng_root)pngset.c", + "<(libpng_root)pngtest.c", + "<(libpng_root)pngtrans.c", + "<(libpng_root)pngwio.c", + "<(libpng_root)pngwrite.c", + "<(libpng_root)pngwtran.c", + "<(libpng_root)pngwutil.c", + ], + }, + ] +} diff --git a/deps/locations.gyp b/deps/locations.gyp new file mode 100644 index 000000000..b9f6a1d92 --- /dev/null +++ b/deps/locations.gyp @@ -0,0 +1,14 @@ +{ + + 'variables': { + + 'cairo_root%': "./cairo-1.12.16/", + 'pixman_root%': "./pixman-0.30.2/", + 'freetype_root%': "./freetype-2.5.0/", + 'zlib_root%': "./zlib-1.2.8/", + 'libpng_root%': "./libpng-1.2.49/", + 'gif_root%': "./giflib-4.2.3/", + 'jpeg_root%': "./jpeg-6b/", + } + +} \ No newline at end of file diff --git a/deps/pixman.gyp b/deps/pixman.gyp new file mode 100644 index 000000000..6cd81e81f --- /dev/null +++ b/deps/pixman.gyp @@ -0,0 +1,60 @@ +{ + + 'includes': [ 'common.gyp' , 'locations.gyp'], + 'targets': [ + { + 'target_name': 'pixman', + 'type': 'static_library', + 'include_dirs': [ + './custom-include/pixman/', + '<(pixman_root)', + '<(pixman_root)pixman', + ], + + 'libraries': [ + + ] + , + 'defines': [ 'HAVE_CONFIG_H' ], + 'sources': [ + "<(pixman_root)pixman/pixman-access-accessors.c", + "<(pixman_root)pixman/pixman-access.c", + "<(pixman_root)pixman/pixman-arm.c", + "<(pixman_root)pixman/pixman-arm-neon.c", + "<(pixman_root)pixman/pixman-arm-simd.c", + "<(pixman_root)pixman/pixman-bits-image.c", + "<(pixman_root)pixman/pixman.c", + "<(pixman_root)pixman/pixman-combine32.c", + "<(pixman_root)pixman/pixman-combine-float.c", + "<(pixman_root)pixman/pixman-conical-gradient.c", + "<(pixman_root)pixman/pixman-edge-accessors.c", + "<(pixman_root)pixman/pixman-edge.c", + "<(pixman_root)pixman/pixman-fast-path.c", + "<(pixman_root)pixman/pixman-filter.c", + "<(pixman_root)pixman/pixman-general.c", + "<(pixman_root)pixman/pixman-glyph.c", + "<(pixman_root)pixman/pixman-gradient-walker.c", + "<(pixman_root)pixman/pixman-image.c", + "<(pixman_root)pixman/pixman-implementation.c", + "<(pixman_root)pixman/pixman-linear-gradient.c", + "<(pixman_root)pixman/pixman-matrix.c", + "<(pixman_root)pixman/pixman-mips.c", + "<(pixman_root)pixman/pixman-mips-dspr2.c", + "<(pixman_root)pixman/pixman-mmx.c", + "<(pixman_root)pixman/pixman-noop.c", + "<(pixman_root)pixman/pixman-ppc.c", + "<(pixman_root)pixman/pixman-radial-gradient.c", + "<(pixman_root)pixman/pixman-region16.c", + "<(pixman_root)pixman/pixman-region32.c", + #"<(pixman_root)pixman/pixman-region.c", + "<(pixman_root)pixman/pixman-solid-fill.c", + "<(pixman_root)pixman/pixman-sse2.c", + "<(pixman_root)pixman/pixman-timer.c", + "<(pixman_root)pixman/pixman-trap.c", + "<(pixman_root)pixman/pixman-utils.c", + #"<(pixman_root)pixman/pixman-vmx.c", + "<(pixman_root)pixman/pixman-x86.c", + ], + }, + ] +} diff --git a/deps/zlib.gyp b/deps/zlib.gyp new file mode 100644 index 000000000..05acdeda0 --- /dev/null +++ b/deps/zlib.gyp @@ -0,0 +1,60 @@ +{ + + 'includes': [ 'common.gyp' , 'locations.gyp'], + 'targets': [ + { + 'target_name': 'zlib', + 'type': 'static_library', + 'include_dirs': [ '<(zlib_root)' ], + + 'libraries': [ + + ], + 'defines': [ ], + 'sources': [ + "<(zlib_root)adler32.c", + "<(zlib_root)compress.c", + "<(zlib_root)contrib/blast/blast.c", + "<(zlib_root)contrib/infback9/infback9.c", + "<(zlib_root)contrib/infback9/inftree9.c", + "<(zlib_root)contrib/inflate86/inffas86.c", + "<(zlib_root)contrib/masmx64/inffas8664.c", + #"<(zlib_root)contrib/minizip/ioapi.c", + #"<(zlib_root)contrib/minizip/iowin32.c", + #"<(zlib_root)contrib/minizip/miniunz.c", + #"<(zlib_root)contrib/minizip/minizip.c", + #"<(zlib_root)contrib/minizip/mztools.c", + #"<(zlib_root)contrib/minizip/unzip.c", + #"<(zlib_root)contrib/minizip/zip.c", + #"<(zlib_root)contrib/puff/puff.c", + #"<(zlib_root)contrib/puff/pufftest.c", + #"<(zlib_root)contrib/testzlib/testzlib.c", + #"<(zlib_root)contrib/untgz/untgz.c", + "<(zlib_root)crc32.c", + "<(zlib_root)deflate.c", + #"<(zlib_root)examples/enough.c", + #"<(zlib_root)examples/fitblk.c", + #"<(zlib_root)examples/gun.c", + #"<(zlib_root)examples/gzappend.c", + #"<(zlib_root)examples/gzjoin.c", + #"<(zlib_root)examples/gzlog.c", + #"<(zlib_root)examples/zpipe.c", + #"<(zlib_root)examples/zran.c", + "<(zlib_root)gzclose.c", + "<(zlib_root)gzlib.c", + "<(zlib_root)gzread.c", + "<(zlib_root)gzwrite.c", + "<(zlib_root)infback.c", + "<(zlib_root)inffast.c", + "<(zlib_root)inflate.c", + "<(zlib_root)inftrees.c", + #"<(zlib_root)test/example.c", + #"<(zlib_root)test/infcover.c", + #"<(zlib_root)test/minigzip.c", + "<(zlib_root)trees.c", + "<(zlib_root)uncompr.c", + "<(zlib_root)zutil.c", + ], + }, + ] +} From 1152204352b8db2e80b8741da2787076f128f74e Mon Sep 17 00:00:00 2001 From: magicode Date: Sun, 27 Oct 2013 10:28:17 -0400 Subject: [PATCH 002/183] fix drop stdout --- deps/ensure_deps.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/deps/ensure_deps.sh b/deps/ensure_deps.sh index 3fc992450..3ddb7cbd4 100755 --- a/deps/ensure_deps.sh +++ b/deps/ensure_deps.sh @@ -5,7 +5,7 @@ cd $(dirname $0) if [ ! -d "cairo-1.12.16" ]; then if [ ! -f "cairo-1.12.16.tar.xz" ]; then - wget "http://cairographics.org/releases/cairo-1.12.16.tar.xz" + wget "http://cairographics.org/releases/cairo-1.12.16.tar.xz" > /dev/null 2>&1 fi tar -xf "cairo-1.12.16.tar.xz" mv "cairo-1.12.16/src" "cairo-1.12.16/cairo" @@ -14,7 +14,7 @@ fi if [ ! -d "pixman-0.30.2" ]; then if [ ! -f "pixman-0.30.2.tar.gz" ]; then - wget "http://cairographics.org/releases/pixman-0.30.2.tar.gz" + wget "http://cairographics.org/releases/pixman-0.30.2.tar.gz" > /dev/null 2>&1 fi tar -xf "pixman-0.30.2.tar.gz" fi @@ -22,35 +22,35 @@ fi if [ ! -d "freetype-2.5.0" ]; then if [ ! -f "freetype-2.5.0.tar.gz" ]; then - wget "http://download.savannah.gnu.org/releases/freetype/freetype-2.5.0.tar.gz" + wget "http://download.savannah.gnu.org/releases/freetype/freetype-2.5.0.tar.gz" > /dev/null 2>&1 fi tar -xf "freetype-2.5.0.tar.gz" fi if [ ! -d "zlib-1.2.8" ]; then if [ ! -f "zlib-1.2.8.tar.gz" ]; then - wget "http://zlib.net/zlib-1.2.8.tar.gz" + wget "http://zlib.net/zlib-1.2.8.tar.gz" > /dev/null 2>&1 fi tar -xf "zlib-1.2.8.tar.gz" fi if [ ! -d "libpng-1.2.49" ]; then if [ ! -f "libpng-1.2.49.tar.gz" ]; then - wget "http://sourceforge.net/projects/libpng/files/libpng12/older-releases/1.2.49/libpng-1.2.49.tar.gz" + wget "http://sourceforge.net/projects/libpng/files/libpng12/older-releases/1.2.49/libpng-1.2.49.tar.gz" > /dev/null 2>&1 fi tar -xf "libpng-1.2.49.tar.gz" fi if [ ! -d "jpeg-6b" ]; then if [ ! -f "jpegsrc.v6b.tar.gz" ]; then - wget "http://www.ijg.org/files/jpegsrc.v6b.tar.gz" + wget "http://www.ijg.org/files/jpegsrc.v6b.tar.gz" > /dev/null 2>&1 fi tar -xf "jpegsrc.v6b.tar.gz" fi if [ ! -d "giflib-4.2.3" ]; then if [ ! -f "giflib-4.2.3.tar.gz" ]; then - wget "http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-4.2.3.tar.gz" + wget "http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-4.2.3.tar.gz" > /dev/null 2>&1 fi tar -xf "giflib-4.2.3.tar.gz" fi From f91871592f09dc602aabe7d5af4c9a6b864bb604 Mon Sep 17 00:00:00 2001 From: magicode Date: Sun, 27 Oct 2013 17:31:19 -0400 Subject: [PATCH 003/183] fix libjpeg by libjpeg-turbo --- binding.gyp | 8 +- deps/custom-include/jpeg/jconfig.1.h | 45 --------- deps/custom-include/jpeg/jconfig.h | 131 +++++++++------------------ deps/ensure_deps.sh | 14 +-- deps/jpeg.gyp | 5 +- deps/locations.gyp | 3 +- 6 files changed, 60 insertions(+), 146 deletions(-) delete mode 100644 deps/custom-include/jpeg/jconfig.1.h diff --git a/binding.gyp b/binding.gyp index ab47cf2e8..036f0762e 100644 --- a/binding.gyp +++ b/binding.gyp @@ -59,10 +59,12 @@ 'deps/libpng.gyp:png', 'deps/jpeg.gyp:libjpeg', 'deps/gif.gyp:gif', + ] , 'include_dirs': [ - # './deps/<(jpeg_root)', - # './deps/custom-include/jpeg/', + + './deps/<(jpeg_root)', + #'./deps/custom-include/jpeg/', './deps/<(cairo_root)' , './deps/<(cairo_root)cairo/' , './deps/<(pixman_root)pixman/' @@ -118,7 +120,7 @@ ] }, { 'libraries': [ - '-ljpeg' + #'-ljpeg' ] }] ] diff --git a/deps/custom-include/jpeg/jconfig.1.h b/deps/custom-include/jpeg/jconfig.1.h deleted file mode 100644 index 9594ec56b..000000000 --- a/deps/custom-include/jpeg/jconfig.1.h +++ /dev/null @@ -1,45 +0,0 @@ -/* jconfig.h. Generated automatically by configure. */ -/* jconfig.cfg --- source file edited by configure script */ -/* see jconfig.doc for explanations */ - -#define HAVE_PROTOTYPES -#define HAVE_UNSIGNED_CHAR -#define HAVE_UNSIGNED_SHORT -#undef void -#undef const -#undef CHAR_IS_UNSIGNED -#define HAVE_STDDEF_H -#define HAVE_STDLIB_H -#undef NEED_BSD_STRINGS -#undef NEED_SYS_TYPES_H -#undef NEED_FAR_POINTERS -#undef NEED_SHORT_EXTERNAL_NAMES -/* Define this if you get warnings about undefined structures. */ -#undef INCOMPLETE_TYPES_BROKEN - -#ifdef JPEG_INTERNALS - -#undef RIGHT_SHIFT_IS_UNSIGNED -#define INLINE __inline__ -/* These are for configuring the JPEG memory manager. */ -#undef DEFAULT_MAX_MEM -#undef NO_MKTEMP - -#endif /* JPEG_INTERNALS */ - -#ifdef JPEG_CJPEG_DJPEG - -#define BMP_SUPPORTED /* BMP image file format */ -#define GIF_SUPPORTED /* GIF image file format */ -#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ -#undef RLE_SUPPORTED /* Utah RLE image file format */ -#define TARGA_SUPPORTED /* Targa image file format */ - -#undef TWO_FILE_COMMANDLINE -#undef NEED_SIGNAL_CATCHER -#undef DONT_USE_B_MODE - -/* Define this if you want percent-done progress reports from cjpeg/djpeg. */ -#undef PROGRESS_REPORT - -#endif /* JPEG_CJPEG_DJPEG */ diff --git a/deps/custom-include/jpeg/jconfig.h b/deps/custom-include/jpeg/jconfig.h index d6989d1d3..07676e4e2 100644 --- a/deps/custom-include/jpeg/jconfig.h +++ b/deps/custom-include/jpeg/jconfig.h @@ -1,103 +1,58 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* - * jconfig.h to configure the IJG JPEG library for the Mozilla/Netscape - * environment. Note that there are also Mozilla mods in jmorecfg.h. +/* jconfig.h. Generated by configure. */ +/* Version ID for the JPEG library. + * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60". */ +#define JPEG_LIB_VERSION 62 -/* We assume an ANSI C or C++ compilation environment */ -#define HAVE_PROTOTYPES -#define HAVE_UNSIGNED_CHAR -#define HAVE_UNSIGNED_SHORT -/* #define void char */ -/* #define const */ -#ifndef HAVE_STDDEF_H -#define HAVE_STDDEF_H -#endif /* HAVE_STDDEF_H */ -#ifndef HAVE_STDLIB_H -#define HAVE_STDLIB_H -#endif /* HAVE_STDLIB_H */ -#undef NEED_BSD_STRINGS -#undef NEED_SYS_TYPES_H -#undef NEED_FAR_POINTERS -#undef NEED_SHORT_EXTERNAL_NAMES -/* Define this if you get warnings about undefined structures. */ -#undef INCOMPLETE_TYPES_BROKEN - -/* With this setting, the IJG code will work regardless of whether - * type "char" is signed or unsigned. - */ -#undef CHAR_IS_UNSIGNED +/* libjpeg-turbo version */ +#define LIBJPEG_TURBO_VERSION 1.2.1 +/* Support arithmetic encoding */ +#define C_ARITH_CODING_SUPPORTED 1 -/* defines that need not be visible to callers of the IJG library */ +/* Support arithmetic decoding */ +#define D_ARITH_CODING_SUPPORTED 1 -#ifdef JPEG_INTERNALS +/* Compiler supports function prototypes. */ +#define HAVE_PROTOTYPES 1 -/* If right shift of "long" quantities is unsigned on your machine, - * you'll have to define this. Fortunately few people should need it. - */ -#undef RIGHT_SHIFT_IS_UNSIGNED +/* Define to 1 if you have the header file. */ +#define HAVE_STDDEF_H 1 -#ifdef XP_MAC /* Macintosh */ +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 -#define ALIGN_TYPE long /* for sane memory alignment */ -#define NO_GETENV /* we do have the function, but it's dead */ +/* Compiler supports 'unsigned char'. */ +#define HAVE_UNSIGNED_CHAR 1 -#endif /* XP_MAC */ +/* Compiler supports 'unsigned short'. */ +#define HAVE_UNSIGNED_SHORT 1 -#endif /* JPEG_INTERNALS */ +/* Compiler does not support pointers to unspecified structures. */ +/* #undef INCOMPLETE_TYPES_BROKEN */ +/* Compiler has rather than standard . */ +/* #undef NEED_BSD_STRINGS */ -/* these defines are not interesting for building just the IJG library, - * but we leave 'em here anyway. - */ -#ifdef JPEG_CJPEG_DJPEG +/* Linker requires that global names be unique in first 15 characters. */ +/* #undef NEED_SHORT_EXTERNAL_NAMES */ + +/* Need to include in order to obtain size_t. */ +#define NEED_SYS_TYPES_H 1 + +/* Broken compiler shifts signed values as an unsigned shift. */ +/* #undef RIGHT_SHIFT_IS_UNSIGNED */ + +/* Use accelerated SIMD routines. */ +/* #undef WITH_SIMD */ -#define BMP_SUPPORTED /* BMP image file format */ -#define GIF_SUPPORTED /* GIF image file format */ -#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ -#undef RLE_SUPPORTED /* Utah RLE image file format */ -#define TARGA_SUPPORTED /* Targa image file format */ +/* Define to 1 if type `char' is unsigned and you are not using gcc. */ +#ifndef __CHAR_UNSIGNED__ +/* # undef __CHAR_UNSIGNED__ */ +#endif -#undef TWO_FILE_COMMANDLINE -#undef NEED_SIGNAL_CATCHER -#undef DONT_USE_B_MODE -#undef PROGRESS_REPORT +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ -#endif /* JPEG_CJPEG_DJPEG */ \ No newline at end of file +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ diff --git a/deps/ensure_deps.sh b/deps/ensure_deps.sh index 3ddb7cbd4..63604656e 100755 --- a/deps/ensure_deps.sh +++ b/deps/ensure_deps.sh @@ -41,13 +41,15 @@ if [ ! -d "libpng-1.2.49" ]; then tar -xf "libpng-1.2.49.tar.gz" fi -if [ ! -d "jpeg-6b" ]; then - if [ ! -f "jpegsrc.v6b.tar.gz" ]; then - wget "http://www.ijg.org/files/jpegsrc.v6b.tar.gz" > /dev/null 2>&1 +if [ ! -d "libjpeg-turbo-1.2.1" ]; then + if [ ! -f "libjpeg-turbo-1.2.1.tar.gz" ]; then + wget "http://downloads.sourceforge.net/project/libjpeg-turbo/1.2.1/libjpeg-turbo-1.2.1.tar.gz" > /dev/null 2>&1 fi - tar -xf "jpegsrc.v6b.tar.gz" + tar -xf "libjpeg-turbo-1.2.1.tar.gz" fi + + if [ ! -d "giflib-4.2.3" ]; then if [ ! -f "giflib-4.2.3.tar.gz" ]; then wget "http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-4.2.3.tar.gz" > /dev/null 2>&1 @@ -56,9 +58,7 @@ if [ ! -d "giflib-4.2.3" ]; then fi - - -if [ ! -d "cairo-1.12.16" ] || [ ! -d "pixman-0.30.2" ] || [ ! -d "freetype-2.5.0" ] || [ ! -d "zlib-1.2.8" ] || [ ! -d "libpng-1.2.49" ] || [ ! -d "jpeg-6b" ] || [ ! -d "giflib-4.2.3" ]; then +if [ ! -d "cairo-1.12.16" ] || [ ! -d "pixman-0.30.2" ] || [ ! -d "freetype-2.5.0" ] || [ ! -d "zlib-1.2.8" ] || [ ! -d "libpng-1.2.49" ] || [ ! -d "libjpeg-turbo-1.2.1" ] || [ ! -d "giflib-4.2.3" ]; then echo false else echo true diff --git a/deps/jpeg.gyp b/deps/jpeg.gyp index b450638c6..3435fa876 100644 --- a/deps/jpeg.gyp +++ b/deps/jpeg.gyp @@ -21,7 +21,8 @@ #"<(jpeg_root)djpeg.c", #"<(jpeg_root)example.c", - + "<(jpeg_root)jsimd_none.c", + "<(jpeg_root)jcapimin.c", "<(jpeg_root)jcapistd.c", "<(jpeg_root)jccoefct.c", @@ -69,7 +70,7 @@ "<(jpeg_root)jidctint.c", "<(jpeg_root)jinclude.h", - #"<(jpeg_root)jidctred.c", + "<(jpeg_root)jidctred.c", #"<(jpeg_root)jmemansi.c", #"<(jpeg_root)jmemdos.c", diff --git a/deps/locations.gyp b/deps/locations.gyp index b9f6a1d92..a0f4070c5 100644 --- a/deps/locations.gyp +++ b/deps/locations.gyp @@ -8,7 +8,8 @@ 'zlib_root%': "./zlib-1.2.8/", 'libpng_root%': "./libpng-1.2.49/", 'gif_root%': "./giflib-4.2.3/", - 'jpeg_root%': "./jpeg-6b/", + 'jpeg_root%': "./libjpeg-turbo-1.2.1/", + } } \ No newline at end of file From e3a90bf24186b8c2a63971481cf4d4e7aa4059fb Mon Sep 17 00:00:00 2001 From: magicode Date: Sun, 27 Oct 2013 17:42:58 -0400 Subject: [PATCH 004/183] add config.h --- deps/custom-include/jpeg/config.h | 130 ++++++++++++++++++++++++++++ deps/custom-include/jpeg/jconfig9.h | 54 ------------ 2 files changed, 130 insertions(+), 54 deletions(-) create mode 100644 deps/custom-include/jpeg/config.h delete mode 100644 deps/custom-include/jpeg/jconfig9.h diff --git a/deps/custom-include/jpeg/config.h b/deps/custom-include/jpeg/config.h new file mode 100644 index 000000000..4eb5767b0 --- /dev/null +++ b/deps/custom-include/jpeg/config.h @@ -0,0 +1,130 @@ +/* config.h. Generated by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Build number */ +#define BUILD "20131027" + +/* Support arithmetic encoding */ +#define C_ARITH_CODING_SUPPORTED 1 + +/* Support arithmetic decoding */ +#define D_ARITH_CODING_SUPPORTED 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_JNI_H */ + +/* Define to 1 if you have the `memcpy' function. */ +#define HAVE_MEMCPY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `memset' function. */ +#define HAVE_MEMSET 1 + +/* Define if your compiler supports prototypes */ +#define HAVE_PROTOTYPES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDDEF_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if the system has the type `unsigned char'. */ +#define HAVE_UNSIGNED_CHAR 1 + +/* Define to 1 if the system has the type `unsigned short'. */ +#define HAVE_UNSIGNED_SHORT 1 + +/* Compiler does not support pointers to undefined structures. */ +/* #undef INCOMPLETE_TYPES_BROKEN */ + +/* How to obtain function inlining. */ +#define INLINE __attribute__((always_inline)) + +/* libjpeg API version */ +#define JPEG_LIB_VERSION 62 + +/* libjpeg-turbo version */ +#define LIBJPEG_TURBO_VERSION 1.2.1 + +/* Define if you have BSD-like bzero and bcopy */ +/* #undef NEED_BSD_STRINGS */ + +/* Define if you need short function names */ +/* #undef NEED_SHORT_EXTERNAL_NAMES */ + +/* Define if you have sys/types.h */ +#define NEED_SYS_TYPES_H 1 + +/* Name of package */ +#define PACKAGE "libjpeg-turbo" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "libjpeg-turbo" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "libjpeg-turbo 1.2.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "libjpeg-turbo" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.2.1" + +/* Define if shift is unsigned */ +/* #undef RIGHT_SHIFT_IS_UNSIGNED */ + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "1.2.1" + +/* Use accelerated SIMD routines. */ +/* #undef WITH_SIMD */ + +/* Define to 1 if type `char' is unsigned and you are not using gcc. */ +#ifndef __CHAR_UNSIGNED__ +/* # undef __CHAR_UNSIGNED__ */ +#endif + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to `unsigned' if does not define. */ +/* #undef size_t */ diff --git a/deps/custom-include/jpeg/jconfig9.h b/deps/custom-include/jpeg/jconfig9.h deleted file mode 100644 index 966b1d514..000000000 --- a/deps/custom-include/jpeg/jconfig9.h +++ /dev/null @@ -1,54 +0,0 @@ -/* jconfig.h. Generated from jconfig.cfg by configure. */ -/* jconfig.cfg --- source file edited by configure script */ -/* see jconfig.txt for explanations */ - -#define HAVE_PROTOTYPES 1 -#define HAVE_UNSIGNED_CHAR 1 -#define HAVE_UNSIGNED_SHORT 1 -/* #undef void */ -/* #undef const */ -/* #undef CHAR_IS_UNSIGNED */ -#define HAVE_STDDEF_H 1 -#define HAVE_STDLIB_H 1 -#define HAVE_LOCALE_H 1 -/* #undef NEED_BSD_STRINGS */ -/* #undef NEED_SYS_TYPES_H */ -/* #undef NEED_FAR_POINTERS */ -/* #undef NEED_SHORT_EXTERNAL_NAMES */ -/* Define this if you get warnings about undefined structures. */ -/* #undef INCOMPLETE_TYPES_BROKEN */ - -/* Define "boolean" as unsigned char, not int, on Windows systems. */ -#ifdef _WIN32 -#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ -typedef unsigned char boolean; -#endif -#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ -#endif - -#ifdef JPEG_INTERNALS - -/* #undef RIGHT_SHIFT_IS_UNSIGNED */ -#define INLINE __inline__ -/* These are for configuring the JPEG memory manager. */ -/* #undef DEFAULT_MAX_MEM */ -/* #undef NO_MKTEMP */ - -#endif /* JPEG_INTERNALS */ - -#ifdef JPEG_CJPEG_DJPEG - -#define BMP_SUPPORTED /* BMP image file format */ -#define GIF_SUPPORTED /* GIF image file format */ -#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ -/* #undef RLE_SUPPORTED */ -#define TARGA_SUPPORTED /* Targa image file format */ - -/* #undef TWO_FILE_COMMANDLINE */ -/* #undef NEED_SIGNAL_CATCHER */ -/* #undef DONT_USE_B_MODE */ - -/* Define this if you want percent-done progress reports from cjpeg/djpeg. */ -/* #undef PROGRESS_REPORT */ - -#endif /* JPEG_CJPEG_DJPEG */ From 5a74d97f5b2109ffe8e8624649bae4b578f6e12b Mon Sep 17 00:00:00 2001 From: magicode Date: Sun, 27 Oct 2013 17:43:54 -0400 Subject: [PATCH 005/183] gif true --- binding.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binding.gyp b/binding.gyp index 036f0762e..61844247d 100644 --- a/binding.gyp +++ b/binding.gyp @@ -15,7 +15,7 @@ }, { # 'OS!="win"' 'variables': { 'with_jpeg%': 'true', #' Date: Mon, 28 Oct 2013 07:03:52 -0400 Subject: [PATCH 006/183] add switching static or shared by -thin option --- binding.gyp | 149 +++------------------------------------------------- shared.gyp | 130 +++++++++++++++++++++++++++++++++++++++++++++ static.gyp | 42 +++++++++++++++ 3 files changed, 178 insertions(+), 143 deletions(-) create mode 100644 shared.gyp create mode 100644 static.gyp diff --git a/binding.gyp b/binding.gyp index 61844247d..8d1acc639 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,147 +1,10 @@ { - 'includes': [ 'deps/locations.gyp'], - 'variables':{ - 'ensure_deps%': ' Date: Sun, 25 May 2014 16:25:49 +0300 Subject: [PATCH 007/183] install with deps when cairo is not installed --- binding.gyp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/binding.gyp b/binding.gyp index 8d1acc639..20513fc7b 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,10 +1,12 @@ { + 'variables': { + 'has_cairo%': ' Date: Sun, 25 May 2014 16:29:36 +0300 Subject: [PATCH 008/183] install with deps when cairo is not installed fix --- binding.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binding.gyp b/binding.gyp index 20513fc7b..d97ebe6f6 100644 --- a/binding.gyp +++ b/binding.gyp @@ -3,7 +3,7 @@ 'has_cairo%': ' Date: Sun, 8 Mar 2015 22:45:18 +0100 Subject: [PATCH 009/183] first proof of concept rendering directly to fbdev --- binding.gyp | 1 + examples/simple_fbdev.js | 20 +++++++++++ src/Canvas.cc | 19 +++++++++-- src/Canvas.h | 4 ++- src/cairo_fbdev_canvas.c | 74 ++++++++++++++++++++++++++++++++++++++++ src/cairo_fbdev_canvas.h | 18 ++++++++++ 6 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 examples/simple_fbdev.js create mode 100644 src/cairo_fbdev_canvas.c create mode 100644 src/cairo_fbdev_canvas.h diff --git a/binding.gyp b/binding.gyp index afb73237b..a6c8bb0f7 100755 --- a/binding.gyp +++ b/binding.gyp @@ -42,6 +42,7 @@ 'target_name': 'canvas', 'include_dirs': [" #include #include "closure.h" +extern "C" { + #include "cairo_fbdev_canvas.h" +} #ifdef HAVE_JPEG #include "JPEGStream.h" @@ -72,7 +75,9 @@ NAN_METHOD(Canvas::New) { ? CANVAS_TYPE_PDF : !strcmp("svg", *String::Utf8Value(args[2])) ? CANVAS_TYPE_SVG - : CANVAS_TYPE_IMAGE; + : !strcmp("fbdev", *String::Utf8Value(args[2])) + ? CANVAS_TYPE_FBDEV + : CANVAS_TYPE_IMAGE; Canvas *canvas = new Canvas(width, height, type); canvas->Wrap(args.This()); NanReturnValue(args.This()); @@ -85,7 +90,7 @@ NAN_METHOD(Canvas::New) { NAN_GETTER(Canvas::GetType) { NanScope(); Canvas *canvas = ObjectWrap::Unwrap(args.This()); - NanReturnValue(NanNew(canvas->isPDF() ? "pdf" : canvas->isSVG() ? "svg" : "image")); + NanReturnValue(NanNew(canvas->isPDF() ? "pdf" : canvas->isSVG() ? "svg" : canvas->isFbDev() ? "fbdev" : "image")); } /* @@ -489,6 +494,12 @@ Canvas::Canvas(int w, int h, canvas_type_t t): ObjectWrap() { cairo_status_t status = closure_init((closure_t *) _closure, this, 0, PNG_NO_FILTERS); assert(status == CAIRO_STATUS_SUCCESS); _surface = cairo_svg_surface_create_for_stream(toBuffer, _closure, w, h); + } else if (CANVAS_TYPE_FBDEV == t) { + _surface = cairo_linuxfb_surface_create("/dev/fb0"); + assert(_surface); + cairo_linuxfb_device_t *dev = (cairo_linuxfb_device_t *)cairo_surface_get_user_data(_surface, NULL); + printf("fbid: %d", dev->fb_fd); + NanAdjustExternalMemory(4 * w * h); } else { _surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); assert(_surface); @@ -509,6 +520,7 @@ Canvas::~Canvas() { free(_closure); cairo_surface_destroy(_surface); break; + case CANVAS_TYPE_FBDEV: case CANVAS_TYPE_IMAGE: cairo_surface_destroy(_surface); NanAdjustExternalMemory(-4 * width * height); @@ -545,6 +557,9 @@ Canvas::resurface(Handle canvas) { cairo_destroy(prev); } break; + case CANVAS_TYPE_FBDEV: + printf("resurface for fbdev not implemented yet!\n"); + break; case CANVAS_TYPE_IMAGE: // Re-surface int old_width = cairo_image_surface_get_width(_surface); diff --git a/src/Canvas.h b/src/Canvas.h index 90ef1e55d..1e05fd9ec 100644 --- a/src/Canvas.h +++ b/src/Canvas.h @@ -40,7 +40,8 @@ using namespace node; typedef enum { CANVAS_TYPE_IMAGE, CANVAS_TYPE_PDF, - CANVAS_TYPE_SVG + CANVAS_TYPE_SVG, + CANVAS_TYPE_FBDEV } canvas_type_t; /* @@ -80,6 +81,7 @@ class Canvas: public node::ObjectWrap { inline bool isPDF(){ return CANVAS_TYPE_PDF == type; } inline bool isSVG(){ return CANVAS_TYPE_SVG == type; } + inline bool isFbDev(){ return CANVAS_TYPE_FBDEV == type; } inline cairo_surface_t *surface(){ return _surface; } inline void *closure(){ return _closure; } inline uint8_t *data(){ return cairo_image_surface_get_data(_surface); } diff --git a/src/cairo_fbdev_canvas.c b/src/cairo_fbdev_canvas.c new file mode 100644 index 000000000..d71a51cf1 --- /dev/null +++ b/src/cairo_fbdev_canvas.c @@ -0,0 +1,74 @@ +#include "cairo_fbdev_canvas.h" + +#include +#include +#include +#include +#include +#include + +static void cairo_linuxfb_surface_destroy(void *device) { + cairo_linuxfb_device_t *dev = (cairo_linuxfb_device_t *)device; + + if (dev == NULL) { + return; + } + munmap(dev->fb_data, dev->fb_screensize); + close(dev->fb_fd); + free(dev); +} + +cairo_surface_t *cairo_linuxfb_surface_create(const char *fb_name) { + cairo_linuxfb_device_t *device; + cairo_surface_t *surface; + + if (fb_name == NULL) { + fb_name = "/dev/fb0"; + } + + device = malloc(sizeof(*device)); + + // Open the file for reading and writing + device->fb_fd = open(fb_name, O_RDWR); + if (device->fb_fd == -1) { + perror("Error: cannot open framebuffer device"); + exit(1); + } + + // Get variable screen information + if (ioctl(device->fb_fd, FBIOGET_VSCREENINFO, &device->fb_vinfo) == -1) { + perror("Error reading variable information"); + exit(3); + } + + // Figure out the size of the screen in bytes + device->fb_screensize = device->fb_vinfo.xres * device->fb_vinfo.yres + * device->fb_vinfo.bits_per_pixel / 8; + + // Map the device to memory + device->fb_data = (char *)mmap(0, device->fb_screensize, + PROT_READ | PROT_WRITE, MAP_SHARED,#include + device->fb_fd, 0); + if ((int)device->fb_data == -1) { + perror("Error: failed to map framebuffer device to memory"); + exit(4); + } + + // Get fixed screen information + if (ioctl(device->fb_fd, FBIOGET_FSCREENINFO, &device->fb_finfo) == -1) { + perror("Error reading fixed information"); + exit(2); + } + + // dicide image format by bpp of fb device + surface = cairo_image_surface_create_for_data(device->fb_data, + CAIRO_FORMAT_ARGB32, + device->fb_vinfo.xres, + device->fb_vinfo.yres, + cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, + device->fb_vinfo.xres)); + cairo_surface_set_user_data(surface, NULL, device, + &cairo_linuxfb_surface_destroy); + + return surface; +} diff --git a/src/cairo_fbdev_canvas.h b/src/cairo_fbdev_canvas.h new file mode 100644 index 000000000..003040dca --- /dev/null +++ b/src/cairo_fbdev_canvas.h @@ -0,0 +1,18 @@ +#ifndef __CAIRO_FBDEV_CANVAS_H__ +#define __CAIRO_FBDEV_CANVAS_H__ + +#include +#include + +typedef struct _cairo_linuxfb_device { + int fb_fd; + char *fb_data; + long fb_screensize; + struct fb_var_screeninfo fb_vinfo; + struct fb_fix_screeninfo fb_finfo; +} cairo_linuxfb_device_t; + +static void cairo_linuxfb_surface_destroy(void *device); +cairo_surface_t *cairo_linuxfb_surface_create(const char *fb_name); + +#endif From d3d395d2bf2577621a1356c24aa711a854bf5d7a Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Sun, 8 Mar 2015 22:46:02 +0100 Subject: [PATCH 010/183] added link to linux framebuffer surface --- src/cairo_fbdev_canvas.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cairo_fbdev_canvas.c b/src/cairo_fbdev_canvas.c index d71a51cf1..44f2107dc 100644 --- a/src/cairo_fbdev_canvas.c +++ b/src/cairo_fbdev_canvas.c @@ -7,6 +7,8 @@ #include #include +// Linux framebuffer surface: http://lists.cairographics.org/archives/cairo/2010-July/020378.html + static void cairo_linuxfb_surface_destroy(void *device) { cairo_linuxfb_device_t *dev = (cairo_linuxfb_device_t *)device; From e219f5b5284065df4e48d31d2d24d76e9c68d23f Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Sun, 8 Mar 2015 23:00:40 +0100 Subject: [PATCH 011/183] size of canvas is now set by size of fbdevice fixed some stupid bugs and made it compile again --- examples/simple_fbdev.js | 4 +++- src/Canvas.cc | 10 +++++++--- src/cairo_fbdev_canvas.c | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/simple_fbdev.js b/examples/simple_fbdev.js index 5e74309be..fa2ee30d1 100644 --- a/examples/simple_fbdev.js +++ b/examples/simple_fbdev.js @@ -6,9 +6,11 @@ var fs = require('fs'); var Canvas = require('../lib/canvas'); -var canvas = new Canvas(320, 320) +var canvas = new Canvas(320, 320, "fbdev") var ctx = canvas.getContext('2d') +console.log("Width: " + canvas.width + ", Height: " + canvas.height); + ctx.fillStyle = "#00FF00"; ctx.fillRect(50, 50, 100, 100); diff --git a/src/Canvas.cc b/src/Canvas.cc index c2cade59d..d25289a66 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -15,6 +15,7 @@ #include #include #include "closure.h" + extern "C" { #include "cairo_fbdev_canvas.h" } @@ -495,11 +496,14 @@ Canvas::Canvas(int w, int h, canvas_type_t t): ObjectWrap() { assert(status == CAIRO_STATUS_SUCCESS); _surface = cairo_svg_surface_create_for_stream(toBuffer, _closure, w, h); } else if (CANVAS_TYPE_FBDEV == t) { + // TODO make it possible to change fb device _surface = cairo_linuxfb_surface_create("/dev/fb0"); assert(_surface); - cairo_linuxfb_device_t *dev = (cairo_linuxfb_device_t *)cairo_surface_get_user_data(_surface, NULL); - printf("fbid: %d", dev->fb_fd); - NanAdjustExternalMemory(4 * w * h); + cairo_linuxfb_device_t *dev = (cairo_linuxfb_device_t *) cairo_surface_get_user_data(_surface, NULL); + width = dev->fb_vinfo.xres; + height = dev->fb_vinfo.yres; + // TODO set external memory to actual bit depth + NanAdjustExternalMemory(4 * width * height); } else { _surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); assert(_surface); diff --git a/src/cairo_fbdev_canvas.c b/src/cairo_fbdev_canvas.c index 44f2107dc..afbb14faa 100644 --- a/src/cairo_fbdev_canvas.c +++ b/src/cairo_fbdev_canvas.c @@ -49,7 +49,7 @@ cairo_surface_t *cairo_linuxfb_surface_create(const char *fb_name) { // Map the device to memory device->fb_data = (char *)mmap(0, device->fb_screensize, - PROT_READ | PROT_WRITE, MAP_SHARED,#include + PROT_READ | PROT_WRITE, MAP_SHARED, device->fb_fd, 0); if ((int)device->fb_data == -1) { perror("Error: failed to map framebuffer device to memory"); @@ -62,7 +62,7 @@ cairo_surface_t *cairo_linuxfb_surface_create(const char *fb_name) { exit(2); } - // dicide image format by bpp of fb device + // TODO decide image format by bpp of fb device surface = cairo_image_surface_create_for_data(device->fb_data, CAIRO_FORMAT_ARGB32, device->fb_vinfo.xres, From 466ad8bf56e4d6255bdeb638e14fbf3180b0aeb9 Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Mon, 9 Mar 2015 14:30:23 +0100 Subject: [PATCH 012/183] started moving backends to external structure to be able to easier add new backends --- binding.gyp | 2 +- src/Canvas.cc | 2 +- src/backend/Backend.hpp | 44 +++++++++ src/backend/FBDevBackend.cpp | 96 +++++++++++++++++++ src/backend/FBDevBackend.hpp | 31 ++++++ src/backend/ImageBackend.cpp | 28 ++++++ src/backend/ImageBackend.hpp | 14 +++ src/backend/Makefile | 8 ++ src/backend/main.cpp | 18 ++++ src/{cairo_fbdev_canvas.c => cairo_linuxfb.c} | 37 ++++--- src/{cairo_fbdev_canvas.h => cairo_linuxfb.h} | 2 +- 11 files changed, 265 insertions(+), 17 deletions(-) create mode 100644 src/backend/Backend.hpp create mode 100644 src/backend/FBDevBackend.cpp create mode 100644 src/backend/FBDevBackend.hpp create mode 100644 src/backend/ImageBackend.cpp create mode 100644 src/backend/ImageBackend.hpp create mode 100644 src/backend/Makefile create mode 100644 src/backend/main.cpp rename src/{cairo_fbdev_canvas.c => cairo_linuxfb.c} (73%) rename src/{cairo_fbdev_canvas.h => cairo_linuxfb.h} (94%) diff --git a/binding.gyp b/binding.gyp index a6c8bb0f7..d198a0b41 100755 --- a/binding.gyp +++ b/binding.gyp @@ -42,7 +42,7 @@ 'target_name': 'canvas', 'include_dirs': [" + +#if HAVE_PANGO +#include +#else +#include +#endif + +using namespace std; + +class Backend +{ + protected: + string name; + + int width; + int height; + + cairo_surface_t *surface; + + public: + virtual ~Backend() { + this->destroySurface(); + }; + + virtual cairo_surface_t *createSurface(); + virtual cairo_surface_t *recreateSurface(); + virtual void destroySurface(); + + string getName() { return name; }; + + int getWidth() { return this->width; }; + void setWidth(int width) { this->width = width; this->recreateSurface(); }; + + int getHeight() { return this->width; }; + void setHeight(int height) { this->height = height; this->recreateSurface(); }; + + cairo_surface_t *getSurface() { return surface; }; +}; + +#endif diff --git a/src/backend/FBDevBackend.cpp b/src/backend/FBDevBackend.cpp new file mode 100644 index 000000000..5fa335d42 --- /dev/null +++ b/src/backend/FBDevBackend.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include +#include "FBDevBackend.hpp" + +FBDevBackend::FBDevBackend(string deviceName) { + this->name = "fbdev"; + this->fb_dn = deviceName; +} + +cairo_surface_t * FBDevBackend::createSurface() { + // Open the file for reading and writing + this->fb_fd = open(this->fb_dn.c_str(), O_RDWR); + if (this->fb_fd == -1) { + perror("Error: cannot open framebuffer device"); + exit(1); + } + + // Get variable screen information + if (ioctl(this->fb_fd, FBIOGET_VSCREENINFO, &this->fb_vinfo) == -1) { + perror("Error reading variable information"); + exit(3); + } + + // Figure out the size of the screen in bytes + this->fb_screensize = this->fb_vinfo.xres * this->fb_vinfo.yres * this->fb_vinfo.bits_per_pixel / 8; + + // Map the device to memory + this->fb_data = (unsigned char *) mmap( + 0, + this->fb_screensize, + PROT_READ | PROT_WRITE, + MAP_SHARED, + this->fb_fd, + 0 + ); + if (this->fb_data == MAP_FAILED) { + perror("Error: failed to map framebuffer device to memory"); + exit(4); + } + + // Get fixed screen information + if (ioctl(this->fb_fd, FBIOGET_FSCREENINFO, &this->fb_finfo) == -1) { + perror("Error reading fixed information"); + exit(2); + } + + // TODO decide image format by bpp of fb device + this->surface = cairo_image_surface_create_for_data( + this->fb_data, + CAIRO_FORMAT_ARGB32, + this->fb_vinfo.xres, + this->fb_vinfo.yres, + cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, this->fb_vinfo.xres) + ); + cairo_surface_set_user_data( + this->surface, + NULL, + this, + &cairo_linuxfb_surface_destroy + ); + return this->surface; +} + +void FBDevBackend::setWidth(int width) { + perror("Operation setWidth is not supported by this backend!"); + exit(1); +} + +void FBDevBackend::setHeight(int height) { + perror("Operation setWidth is not supported by this backend!"); + exit(1); +} + +cairo_surface_t *FBDevBackend::recreateSurface() { + perror("Operation recreateSurface is not supported by this backend!"); + exit(1); + return NULL; +} + +void FBDevBackend::destroySurface() { + cairo_surface_destroy(this->surface); +} + +static void cairo_linuxfb_surface_destroy(void *device) { + FBDevBackend *backend = (FBDevBackend *) device; + + if (backend == NULL) { + return; + } + munmap(backend->fb_data, backend->fb_screensize); + close(backend->fb_fd); +} diff --git a/src/backend/FBDevBackend.hpp b/src/backend/FBDevBackend.hpp new file mode 100644 index 000000000..a86bd2ebc --- /dev/null +++ b/src/backend/FBDevBackend.hpp @@ -0,0 +1,31 @@ +#ifndef __FBDEV_BACKEND_H__ +#define __FBDEV_BACKEND_H__ + +#include +#include +#include "Backend.hpp" + +using namespace std; + +class FBDevBackend : public Backend { + public: + string fb_dn; + int fb_fd; + struct fb_var_screeninfo fb_vinfo; + struct fb_fix_screeninfo fb_finfo; + long fb_screensize; + unsigned char *fb_data; + + virtual cairo_surface_t *createSurface(); + virtual cairo_surface_t *recreateSurface(); + virtual void destroySurface(); + + void setWidth(int width); + void setHeight(int height); + + FBDevBackend(string deviceName); +}; + +static void cairo_linuxfb_surface_destroy(void *device); + +#endif diff --git a/src/backend/ImageBackend.cpp b/src/backend/ImageBackend.cpp new file mode 100644 index 000000000..2892a9af5 --- /dev/null +++ b/src/backend/ImageBackend.cpp @@ -0,0 +1,28 @@ +#include "ImageBackend.hpp" + +ImageBackend::ImageBackend(int width, int height) { + this->name = "image"; + + this->width = width; + this->height = height; +} + +cairo_surface_t *ImageBackend::Backend::createSurface() { + this->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, this->width, this->height); + //NanAdjustExternalMemory(4 * this->width * this->height); + return this->surface; +} + +cairo_surface_t *ImageBackend::Backend::recreateSurface() { + int old_width = cairo_image_surface_get_width(this->surface); + int old_height = cairo_image_surface_get_height(this->surface); + cairo_surface_destroy(this->surface); + this->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); + //NanAdjustExternalMemory(4 * (width * height - old_width * old_height)); + return this->surface; +} + +void ImageBackend::Backend::destroySurface() { + cairo_surface_destroy(this->surface); + //NanAdjustExternalMemory(-4 * this->width * this->height); +} diff --git a/src/backend/ImageBackend.hpp b/src/backend/ImageBackend.hpp new file mode 100644 index 000000000..cae571c00 --- /dev/null +++ b/src/backend/ImageBackend.hpp @@ -0,0 +1,14 @@ +#ifndef __IMAGE_BACKEND_H__ +#define __IMAGE_BACKEND_H__ + +#include +#include "Backend.hpp" + +using namespace std; + +class ImageBackend : public Backend { + public: + ImageBackend(int width, int height); +}; + +#endif diff --git a/src/backend/Makefile b/src/backend/Makefile new file mode 100644 index 000000000..12a073d0e --- /dev/null +++ b/src/backend/Makefile @@ -0,0 +1,8 @@ +all: + g++ FBDevBackend.cpp ImageBackend.cpp main.cpp -lcairo -o backendtest + +run: all + ./backendtest + +clean: + rm -Rf backendtest diff --git a/src/backend/main.cpp b/src/backend/main.cpp new file mode 100644 index 000000000..0deb93e2f --- /dev/null +++ b/src/backend/main.cpp @@ -0,0 +1,18 @@ +#include "FBDevBackend.hpp" +#include "ImageBackend.hpp" + +int main() { + Backend *backend = NULL; + + backend = new FBDevBackend("/dev/fb0"); + backend->createSurface(); + cout << backend->getName() << endl; + cout << backend->getSurface() << endl; + delete backend; + + backend = new ImageBackend(1920, 1080); + backend->createSurface(); + cout << backend->getName() << endl; + cout << backend->getSurface() << endl; + delete backend; +} diff --git a/src/cairo_fbdev_canvas.c b/src/cairo_linuxfb.c similarity index 73% rename from src/cairo_fbdev_canvas.c rename to src/cairo_linuxfb.c index afbb14faa..f239440f9 100644 --- a/src/cairo_fbdev_canvas.c +++ b/src/cairo_linuxfb.c @@ -1,4 +1,4 @@ -#include "cairo_fbdev_canvas.h" +#include "cairo_linuxfb.h" #include #include @@ -44,13 +44,17 @@ cairo_surface_t *cairo_linuxfb_surface_create(const char *fb_name) { } // Figure out the size of the screen in bytes - device->fb_screensize = device->fb_vinfo.xres * device->fb_vinfo.yres - * device->fb_vinfo.bits_per_pixel / 8; + device->fb_screensize = device->fb_vinfo.xres * device->fb_vinfo.yres * device->fb_vinfo.bits_per_pixel / 8; // Map the device to memory - device->fb_data = (char *)mmap(0, device->fb_screensize, - PROT_READ | PROT_WRITE, MAP_SHARED, - device->fb_fd, 0); + device->fb_data = (char *) mmap( + 0, + device->fb_screensize, + PROT_READ | PROT_WRITE, + MAP_SHARED, + device->fb_fd, + 0 + ); if ((int)device->fb_data == -1) { perror("Error: failed to map framebuffer device to memory"); exit(4); @@ -63,14 +67,19 @@ cairo_surface_t *cairo_linuxfb_surface_create(const char *fb_name) { } // TODO decide image format by bpp of fb device - surface = cairo_image_surface_create_for_data(device->fb_data, - CAIRO_FORMAT_ARGB32, - device->fb_vinfo.xres, - device->fb_vinfo.yres, - cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, - device->fb_vinfo.xres)); - cairo_surface_set_user_data(surface, NULL, device, - &cairo_linuxfb_surface_destroy); + surface = cairo_image_surface_create_for_data( + device->fb_data, + CAIRO_FORMAT_ARGB32, + device->fb_vinfo.xres, + device->fb_vinfo.yres, + cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, device->fb_vinfo.xres) + ); + cairo_surface_set_user_data( + surface, + NULL, + device, + &cairo_linuxfb_surface_destroy + ); return surface; } diff --git a/src/cairo_fbdev_canvas.h b/src/cairo_linuxfb.h similarity index 94% rename from src/cairo_fbdev_canvas.h rename to src/cairo_linuxfb.h index 003040dca..f078e2432 100644 --- a/src/cairo_fbdev_canvas.h +++ b/src/cairo_linuxfb.h @@ -6,7 +6,7 @@ typedef struct _cairo_linuxfb_device { int fb_fd; - char *fb_data; + unsigned char *fb_data; long fb_screensize; struct fb_var_screeninfo fb_vinfo; struct fb_fix_screeninfo fb_finfo; From 616021aba34c1f1e1d2da106599b11f4e7a2c66d Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Mon, 9 Mar 2015 15:54:05 +0100 Subject: [PATCH 013/183] decide which cairo format to use by the bpp of the fb device --- src/backend/FBDevBackend.cpp | 36 +++++++++++++++++++++++++++++++----- src/backend/FBDevBackend.hpp | 3 +++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/backend/FBDevBackend.cpp b/src/backend/FBDevBackend.cpp index 5fa335d42..de96ab1ea 100644 --- a/src/backend/FBDevBackend.cpp +++ b/src/backend/FBDevBackend.cpp @@ -25,8 +25,31 @@ cairo_surface_t * FBDevBackend::createSurface() { exit(3); } + // set width, height and bpp according to the size of the fb device + this->width = this->fb_vinfo.xres; + this->height = this->fb_vinfo.yres; + this->bpp = this->fb_vinfo.bits_per_pixel; + + switch (this->bpp) { + case 32: + this->format = CAIRO_FORMAT_ARGB32; + break; + case 24: + this->format = CAIRO_FORMAT_RGB24; + break; + case 16: + this->format = CAIRO_FORMAT_RGB16_565; + break; + case 8: + this->format = CAIRO_FORMAT_A8; + break; + default: + perror("Could not determine fbdev color format"); + exit(1); + } + // Figure out the size of the screen in bytes - this->fb_screensize = this->fb_vinfo.xres * this->fb_vinfo.yres * this->fb_vinfo.bits_per_pixel / 8; + this->fb_screensize = this->width * this->height * this->bpp / 8; // Map the device to memory this->fb_data = (unsigned char *) mmap( @@ -51,17 +74,20 @@ cairo_surface_t * FBDevBackend::createSurface() { // TODO decide image format by bpp of fb device this->surface = cairo_image_surface_create_for_data( this->fb_data, - CAIRO_FORMAT_ARGB32, - this->fb_vinfo.xres, - this->fb_vinfo.yres, - cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, this->fb_vinfo.xres) + this->format, + this->width, + this->height, + cairo_format_stride_for_width(this->format, this->width) ); + + // set destroy callback cairo_surface_set_user_data( this->surface, NULL, this, &cairo_linuxfb_surface_destroy ); + return this->surface; } diff --git a/src/backend/FBDevBackend.hpp b/src/backend/FBDevBackend.hpp index a86bd2ebc..0e020c494 100644 --- a/src/backend/FBDevBackend.hpp +++ b/src/backend/FBDevBackend.hpp @@ -16,6 +16,9 @@ class FBDevBackend : public Backend { long fb_screensize; unsigned char *fb_data; + cairo_format_t format; + int bpp; + virtual cairo_surface_t *createSurface(); virtual cairo_surface_t *recreateSurface(); virtual void destroySurface(); From 331baab9d701bd432006b849468e11aa543ee4cb Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Mon, 9 Mar 2015 20:39:00 +0100 Subject: [PATCH 014/183] now with exceptions! --- src/backend/Backend.hpp | 28 ++++++++++++++++++++++---- src/backend/FBDevBackend.cpp | 39 ++++++++++++++++++++---------------- src/backend/FBDevBackend.hpp | 13 +++++++++++- src/backend/ImageBackend.cpp | 15 +++++++++----- src/backend/ImageBackend.hpp | 1 - src/backend/main.cpp | 19 ++++++++++++++---- 6 files changed, 83 insertions(+), 32 deletions(-) diff --git a/src/backend/Backend.hpp b/src/backend/Backend.hpp index b8b2fc9c5..830f99d51 100644 --- a/src/backend/Backend.hpp +++ b/src/backend/Backend.hpp @@ -1,12 +1,15 @@ #ifndef __BACKEND_H__ #define __BACKEND_H__ +#include #include +#include +#include #if HAVE_PANGO -#include + #include #else -#include + #include #endif using namespace std; @@ -15,10 +18,9 @@ class Backend { protected: string name; - + int width; int height; - cairo_surface_t *surface; public: @@ -41,4 +43,22 @@ class Backend cairo_surface_t *getSurface() { return surface; }; }; +class BackendOperationNotAvailable : public exception { + private: + Backend *backend; + string operation_name; + + public: + BackendOperationNotAvailable(Backend *backend, string operation_name) { + this->backend = backend; + this->operation_name = operation_name; + }; + ~BackendOperationNotAvailable() throw() {}; + const char *what() const throw() { + std::ostringstream o; + o << "operation " << this->operation_name << " not supported by backend " + backend->getName(); + return o.str().c_str(); + }; +}; + #endif diff --git a/src/backend/FBDevBackend.cpp b/src/backend/FBDevBackend.cpp index de96ab1ea..d3261b938 100644 --- a/src/backend/FBDevBackend.cpp +++ b/src/backend/FBDevBackend.cpp @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include #include "FBDevBackend.hpp" FBDevBackend::FBDevBackend(string deviceName) { @@ -15,14 +18,16 @@ cairo_surface_t * FBDevBackend::createSurface() { // Open the file for reading and writing this->fb_fd = open(this->fb_dn.c_str(), O_RDWR); if (this->fb_fd == -1) { - perror("Error: cannot open framebuffer device"); - exit(1); + std::ostringstream o; + o << "cannot open framebuffer device \"" << this->fb_dn << "\""; + throw FBDevBackendException(o.str()); } // Get variable screen information if (ioctl(this->fb_fd, FBIOGET_VSCREENINFO, &this->fb_vinfo) == -1) { - perror("Error reading variable information"); - exit(3); + std::ostringstream o; + o << "error reading variable information from device \"" << this->fb_dn << "\""; + throw FBDevBackendException(o.str()); } // set width, height and bpp according to the size of the fb device @@ -30,6 +35,7 @@ cairo_surface_t * FBDevBackend::createSurface() { this->height = this->fb_vinfo.yres; this->bpp = this->fb_vinfo.bits_per_pixel; + // switch through bpp and decide on which format for the cairo surface to use switch (this->bpp) { case 32: this->format = CAIRO_FORMAT_ARGB32; @@ -44,8 +50,9 @@ cairo_surface_t * FBDevBackend::createSurface() { this->format = CAIRO_FORMAT_A8; break; default: - perror("Could not determine fbdev color format"); - exit(1); + std::ostringstream o; + o << "could not determine color format of device \"" << this->fb_dn << "\""; + throw FBDevBackendException(o.str()); } // Figure out the size of the screen in bytes @@ -61,14 +68,16 @@ cairo_surface_t * FBDevBackend::createSurface() { 0 ); if (this->fb_data == MAP_FAILED) { - perror("Error: failed to map framebuffer device to memory"); - exit(4); + std::ostringstream o; + o << "failed to map framebuffer device \"" << this->fb_dn << "\" to memory"; + throw FBDevBackendException(o.str()); } // Get fixed screen information if (ioctl(this->fb_fd, FBIOGET_FSCREENINFO, &this->fb_finfo) == -1) { - perror("Error reading fixed information"); - exit(2); + std::ostringstream o; + o << "error reading fixed information from device \"" << this->fb_dn << "\""; + throw FBDevBackendException(o.str()); } // TODO decide image format by bpp of fb device @@ -92,19 +101,15 @@ cairo_surface_t * FBDevBackend::createSurface() { } void FBDevBackend::setWidth(int width) { - perror("Operation setWidth is not supported by this backend!"); - exit(1); + throw BackendOperationNotAvailable(this, "setWidth()"); } void FBDevBackend::setHeight(int height) { - perror("Operation setWidth is not supported by this backend!"); - exit(1); + throw BackendOperationNotAvailable(this, "setHeight()"); } cairo_surface_t *FBDevBackend::recreateSurface() { - perror("Operation recreateSurface is not supported by this backend!"); - exit(1); - return NULL; + throw BackendOperationNotAvailable(this, "recreateSurface()"); } void FBDevBackend::destroySurface() { diff --git a/src/backend/FBDevBackend.hpp b/src/backend/FBDevBackend.hpp index 0e020c494..39bb0f218 100644 --- a/src/backend/FBDevBackend.hpp +++ b/src/backend/FBDevBackend.hpp @@ -1,7 +1,8 @@ #ifndef __FBDEV_BACKEND_H__ #define __FBDEV_BACKEND_H__ -#include +#include +#include #include #include "Backend.hpp" @@ -31,4 +32,14 @@ class FBDevBackend : public Backend { static void cairo_linuxfb_surface_destroy(void *device); +class FBDevBackendException : public std::exception { + private: + string err_msg; + + public: + FBDevBackendException(const string msg) : err_msg(msg) {}; + ~FBDevBackendException() throw() {}; + const char *what() const throw() { return this->err_msg.c_str(); }; +}; + #endif diff --git a/src/backend/ImageBackend.cpp b/src/backend/ImageBackend.cpp index 2892a9af5..01ba32f3e 100644 --- a/src/backend/ImageBackend.cpp +++ b/src/backend/ImageBackend.cpp @@ -14,15 +14,20 @@ cairo_surface_t *ImageBackend::Backend::createSurface() { } cairo_surface_t *ImageBackend::Backend::recreateSurface() { - int old_width = cairo_image_surface_get_width(this->surface); - int old_height = cairo_image_surface_get_height(this->surface); - cairo_surface_destroy(this->surface); + if (this->surface != NULL) { + int old_width = cairo_image_surface_get_width(this->surface); + int old_height = cairo_image_surface_get_height(this->surface); + cairo_surface_destroy(this->surface); + //NanAdjustExternalMemory(-4 * old_width * old_height); + } this->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); //NanAdjustExternalMemory(4 * (width * height - old_width * old_height)); return this->surface; } void ImageBackend::Backend::destroySurface() { - cairo_surface_destroy(this->surface); - //NanAdjustExternalMemory(-4 * this->width * this->height); + if (this->surface != NULL) { + cairo_surface_destroy(this->surface); + //NanAdjustExternalMemory(-4 * this->width * this->height); + } } diff --git a/src/backend/ImageBackend.hpp b/src/backend/ImageBackend.hpp index cae571c00..55ea0feb7 100644 --- a/src/backend/ImageBackend.hpp +++ b/src/backend/ImageBackend.hpp @@ -1,7 +1,6 @@ #ifndef __IMAGE_BACKEND_H__ #define __IMAGE_BACKEND_H__ -#include #include "Backend.hpp" using namespace std; diff --git a/src/backend/main.cpp b/src/backend/main.cpp index 0deb93e2f..7d1220a26 100644 --- a/src/backend/main.cpp +++ b/src/backend/main.cpp @@ -1,18 +1,29 @@ #include "FBDevBackend.hpp" #include "ImageBackend.hpp" +#include + +void printBackendInfo(Backend *backend) { + cout << "Name: " << backend->getName() + << ", Surface Pointer: " << backend->getSurface() + << ", Size: " << backend->getWidth() << "x" << backend->getHeight() << endl; +} + int main() { Backend *backend = NULL; backend = new FBDevBackend("/dev/fb0"); backend->createSurface(); - cout << backend->getName() << endl; - cout << backend->getSurface() << endl; + try { + backend->recreateSurface(); + } catch (BackendOperationNotAvailable bona) { + cerr << bona.what() << endl; + } + printBackendInfo(backend); delete backend; backend = new ImageBackend(1920, 1080); backend->createSurface(); - cout << backend->getName() << endl; - cout << backend->getSurface() << endl; + printBackendInfo(backend); delete backend; } From 8d9a8cec595e7cb3d89979cd60ecb6483bcf231f Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Mon, 13 Apr 2015 14:56:52 +0200 Subject: [PATCH 015/183] added script to install linux dependencies --- install_packages.sh | 1 + 1 file changed, 1 insertion(+) create mode 100644 install_packages.sh diff --git a/install_packages.sh b/install_packages.sh new file mode 100644 index 000000000..3698da63f --- /dev/null +++ b/install_packages.sh @@ -0,0 +1 @@ +sudo apt-get install libcairo-dev libjpeg-dev libgif-dev libghc-pango-dev From 454691b5f322b034c52dc6cb5d831e48a3be572d Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Fri, 1 May 2015 20:07:24 +0200 Subject: [PATCH 016/183] node-canvas now using backend system --- binding.gyp | 5 +- examples/simple_fbdev.js | 2 +- src/Canvas.cc | 164 +++++------------- src/Canvas.h | 37 ++-- src/CanvasPattern.cc | 4 +- src/CanvasRenderingContext2d.cc | 14 +- src/PixelArray.cc | 4 +- src/backend/{Backend.hpp => Backend.h} | 12 +- .../{FBDevBackend.cpp => FBDevBackend.cc} | 4 +- .../{FBDevBackend.hpp => FBDevBackend.h} | 5 +- .../{ImageBackend.cpp => ImageBackend.cc} | 12 +- src/backend/ImageBackend.h | 21 +++ src/backend/ImageBackend.hpp | 13 -- src/backend/Makefile | 2 +- src/backend/backendtest | Bin 0 -> 29256 bytes src/backend/{main.cpp => main.cc} | 4 +- src/cairo_linuxfb.c | 85 --------- src/cairo_linuxfb.h | 18 -- 18 files changed, 114 insertions(+), 292 deletions(-) rename src/backend/{Backend.hpp => Backend.h} (86%) rename src/backend/{FBDevBackend.cpp => FBDevBackend.cc} (97%) rename src/backend/{FBDevBackend.hpp => FBDevBackend.h} (88%) rename src/backend/{ImageBackend.cpp => ImageBackend.cc} (70%) create mode 100644 src/backend/ImageBackend.h delete mode 100644 src/backend/ImageBackend.hpp create mode 100755 src/backend/backendtest rename src/backend/{main.cpp => main.cc} (91%) delete mode 100644 src/cairo_linuxfb.c delete mode 100644 src/cairo_linuxfb.h diff --git a/binding.gyp b/binding.gyp index d198a0b41..7053f907a 100755 --- a/binding.gyp +++ b/binding.gyp @@ -42,7 +42,8 @@ 'target_name': 'canvas', 'include_dirs': [" #include #include -#include -#include -#include "closure.h" -extern "C" { - #include "cairo_linuxfb.h" -} +#include "closure.h" #ifdef HAVE_JPEG #include "JPEGStream.h" #endif +#include "backend/FBDevBackend.h" +#include "backend/ImageBackend.h" + Persistent Canvas::constructor; /* @@ -68,18 +66,31 @@ Canvas::Initialize(Handle target) { NAN_METHOD(Canvas::New) { NanScope(); - int width = 0, height = 0; - canvas_type_t type = CANVAS_TYPE_IMAGE; + Backend *backend = NULL; + int width = 0; + int height = 0; if (args[0]->IsNumber()) width = args[0]->Uint32Value(); if (args[1]->IsNumber()) height = args[1]->Uint32Value(); - if (args[2]->IsString()) type = !strcmp("pdf", *String::Utf8Value(args[2])) - ? CANVAS_TYPE_PDF - : !strcmp("svg", *String::Utf8Value(args[2])) - ? CANVAS_TYPE_SVG - : !strcmp("fbdev", *String::Utf8Value(args[2])) - ? CANVAS_TYPE_FBDEV - : CANVAS_TYPE_IMAGE; - Canvas *canvas = new Canvas(width, height, type); + if (args[2]->IsString()) { + v8::String::Utf8Value param2(args[2]->ToString()); + string type = std::string(*param2); + if (type == "image") { + backend = new ImageBackend(width, height); + } else if (type == "fbdev") { + string deviceName = "/dev/fb0"; + if (args[3]->IsString()) { + v8::String::Utf8Value param3(args[3]->ToString()); + deviceName = std::string(*param3); + } + backend = new FBDevBackend(deviceName); + } else { + backend = new ImageBackend(width, height); + } + } else { + backend = new ImageBackend(width, height); + } + + Canvas *canvas = new Canvas(backend); canvas->Wrap(args.This()); NanReturnValue(args.This()); } @@ -91,7 +102,7 @@ NAN_METHOD(Canvas::New) { NAN_GETTER(Canvas::GetType) { NanScope(); Canvas *canvas = ObjectWrap::Unwrap(args.This()); - NanReturnValue(NanNew(canvas->isPDF() ? "pdf" : canvas->isSVG() ? "svg" : canvas->isFbDev() ? "fbdev" : "image")); + NanReturnValue(NanNew(canvas->backend()->getName())); } /* @@ -101,7 +112,7 @@ NAN_GETTER(Canvas::GetType) { NAN_GETTER(Canvas::GetWidth) { NanScope(); Canvas *canvas = ObjectWrap::Unwrap(args.This()); - NanReturnValue(NanNew(canvas->width)); + NanReturnValue(NanNew(canvas->getWidth())); } /* @@ -112,8 +123,7 @@ NAN_SETTER(Canvas::SetWidth) { NanScope(); if (value->IsNumber()) { Canvas *canvas = ObjectWrap::Unwrap(args.This()); - canvas->width = value->Uint32Value(); - canvas->resurface(args.This()); + canvas->backend()->setWidth(value->Uint32Value()); } } @@ -124,7 +134,7 @@ NAN_SETTER(Canvas::SetWidth) { NAN_GETTER(Canvas::GetHeight) { NanScope(); Canvas *canvas = ObjectWrap::Unwrap(args.This()); - NanReturnValue(NanNew(canvas->height)); + NanReturnValue(NanNew(canvas->getHeight())); } /* @@ -135,8 +145,7 @@ NAN_SETTER(Canvas::SetHeight) { NanScope(); if (value->IsNumber()) { Canvas *canvas = ObjectWrap::Unwrap(args.This()); - canvas->height = value->Uint32Value(); - canvas->resurface(args.This()); + canvas->backend()->setHeight(value->Uint32Value()); } } @@ -246,15 +255,6 @@ NAN_METHOD(Canvas::ToBuffer) { uint32_t filter = PNG_ALL_FILTERS; Canvas *canvas = ObjectWrap::Unwrap(args.This()); - // TODO: async / move this out - if (canvas->isPDF() || canvas->isSVG()) { - cairo_surface_finish(canvas->surface()); - closure_t *closure = (closure_t *) canvas->closure(); - - Local buf = NanNewBufferHandle((char*) closure->data, closure->len); - NanReturnValue(buf); - } - if (args.Length() > 1 && !(args[1]->StrictEquals(NanUndefined()) && args[2]->StrictEquals(NanUndefined()))) { if (!args[1]->StrictEquals(NanUndefined())) { bool good = true; @@ -476,39 +476,9 @@ NAN_METHOD(Canvas::StreamJPEGSync) { * Initialize cairo surface. */ -Canvas::Canvas(int w, int h, canvas_type_t t): ObjectWrap() { - type = t; - width = w; - height = h; - _surface = NULL; - _closure = NULL; - - if (CANVAS_TYPE_PDF == t) { - _closure = malloc(sizeof(closure_t)); - assert(_closure); - cairo_status_t status = closure_init((closure_t *) _closure, this, 0, PNG_NO_FILTERS); - assert(status == CAIRO_STATUS_SUCCESS); - _surface = cairo_pdf_surface_create_for_stream(toBuffer, _closure, w, h); - } else if (CANVAS_TYPE_SVG == t) { - _closure = malloc(sizeof(closure_t)); - assert(_closure); - cairo_status_t status = closure_init((closure_t *) _closure, this, 0, PNG_NO_FILTERS); - assert(status == CAIRO_STATUS_SUCCESS); - _surface = cairo_svg_surface_create_for_stream(toBuffer, _closure, w, h); - } else if (CANVAS_TYPE_FBDEV == t) { - // TODO make it possible to change fb device - _surface = cairo_linuxfb_surface_create("/dev/fb0"); - assert(_surface); - cairo_linuxfb_device_t *dev = (cairo_linuxfb_device_t *) cairo_surface_get_user_data(_surface, NULL); - width = dev->fb_vinfo.xres; - height = dev->fb_vinfo.yres; - // TODO set external memory to actual bit depth - NanAdjustExternalMemory(4 * width * height); - } else { - _surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); - assert(_surface); - NanAdjustExternalMemory(4 * w * h); - } +Canvas::Canvas(Backend* backend): ObjectWrap() { + _backend = backend; + this->backend()->createSurface(); } /* @@ -516,20 +486,7 @@ Canvas::Canvas(int w, int h, canvas_type_t t): ObjectWrap() { */ Canvas::~Canvas() { - switch (type) { - case CANVAS_TYPE_PDF: - case CANVAS_TYPE_SVG: - cairo_surface_finish(_surface); - closure_destroy((closure_t *) _closure); - free(_closure); - cairo_surface_destroy(_surface); - break; - case CANVAS_TYPE_FBDEV: - case CANVAS_TYPE_IMAGE: - cairo_surface_destroy(_surface); - NanAdjustExternalMemory(-4 * width * height); - break; - } + delete _backend; } /* @@ -540,47 +497,14 @@ void Canvas::resurface(Handle canvas) { NanScope(); Handle context; - switch (type) { - case CANVAS_TYPE_PDF: - cairo_pdf_surface_set_size(_surface, width, height); - break; - case CANVAS_TYPE_SVG: - // Re-surface - cairo_surface_finish(_surface); - closure_destroy((closure_t *) _closure); - cairo_surface_destroy(_surface); - closure_init((closure_t *) _closure, this, 0, PNG_NO_FILTERS); - _surface = cairo_svg_surface_create_for_stream(toBuffer, _closure, width, height); - - // Reset context - context = canvas->Get(NanNew("context")); - if (!context->IsUndefined()) { - Context2d *context2d = ObjectWrap::Unwrap(context->ToObject()); - cairo_t *prev = context2d->context(); - context2d->setContext(cairo_create(surface())); - cairo_destroy(prev); - } - break; - case CANVAS_TYPE_FBDEV: - printf("resurface for fbdev not implemented yet!\n"); - break; - case CANVAS_TYPE_IMAGE: - // Re-surface - int old_width = cairo_image_surface_get_width(_surface); - int old_height = cairo_image_surface_get_height(_surface); - cairo_surface_destroy(_surface); - _surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); - NanAdjustExternalMemory(4 * (width * height - old_width * old_height)); - - // Reset context - context = canvas->Get(NanNew("context")); - if (!context->IsUndefined()) { - Context2d *context2d = ObjectWrap::Unwrap(context->ToObject()); - cairo_t *prev = context2d->context(); - context2d->setContext(cairo_create(surface())); - cairo_destroy(prev); - } - break; + + backend()->recreateSurface(); + context = canvas->Get(NanNew("context")); + if (!context->IsUndefined()) { + Context2d *context2d = ObjectWrap::Unwrap(context->ToObject()); + cairo_t *prev = context2d->context(); + context2d->setContext(cairo_create(surface())); + cairo_destroy(prev); } } diff --git a/src/Canvas.h b/src/Canvas.h index 1e05fd9ec..8d9e78625 100644 --- a/src/Canvas.h +++ b/src/Canvas.h @@ -21,6 +21,8 @@ #include +#include "backend/Backend.h" + using namespace v8; using namespace node; @@ -33,26 +35,12 @@ using namespace node; #define CANVAS_MAX_STATES 64 #endif -/* - * Canvas types. - */ - -typedef enum { - CANVAS_TYPE_IMAGE, - CANVAS_TYPE_PDF, - CANVAS_TYPE_SVG, - CANVAS_TYPE_FBDEV -} canvas_type_t; - /* * Canvas. */ class Canvas: public node::ObjectWrap { public: - int width; - int height; - canvas_type_t type; static Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); @@ -79,19 +67,22 @@ class Canvas: public node::ObjectWrap { static int EIO_AfterToBuffer(eio_req *req); #endif - inline bool isPDF(){ return CANVAS_TYPE_PDF == type; } - inline bool isSVG(){ return CANVAS_TYPE_SVG == type; } - inline bool isFbDev(){ return CANVAS_TYPE_FBDEV == type; } - inline cairo_surface_t *surface(){ return _surface; } - inline void *closure(){ return _closure; } - inline uint8_t *data(){ return cairo_image_surface_get_data(_surface); } - inline int stride(){ return cairo_image_surface_get_stride(_surface); } - Canvas(int width, int height, canvas_type_t type); + inline Backend *backend() { return _backend; } + inline cairo_surface_t *surface(){ return backend()->getSurface(); } + inline uint8_t *data(){ return cairo_image_surface_get_data(backend()->getSurface()); } + inline int stride(){ return cairo_image_surface_get_stride(backend()->getSurface()); } + + inline int getWidth() { return backend()->getWidth(); } + inline int getHeight() { return backend()->getHeight(); } + + Canvas(Backend *backend); void resurface(Handle canvas); + inline void *closure(){ return _closure; } + private: ~Canvas(); - cairo_surface_t *_surface; + Backend *_backend; void *_closure; }; diff --git a/src/CanvasPattern.cc b/src/CanvasPattern.cc index 38c86d7a1..7bceabc11 100644 --- a/src/CanvasPattern.cc +++ b/src/CanvasPattern.cc @@ -58,8 +58,8 @@ NAN_METHOD(Pattern::New) { // Canvas } else if (NanHasInstance(Canvas::constructor, obj)) { Canvas *canvas = ObjectWrap::Unwrap(obj); - w = canvas->width; - h = canvas->height; + w = canvas->getWidth(); + h = canvas->getHeight(); surface = canvas->surface(); // Invalid diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 1844cd943..2b82d4660 100755 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -552,7 +552,7 @@ NAN_METHOD(Context2d::New) { NAN_METHOD(Context2d::AddPage) { NanScope(); Context2d *context = ObjectWrap::Unwrap(args.This()); - if (!context->canvas()->isPDF()) { + if (context->canvas()->backend()->getName() != "pdf") { return NanThrowError("only PDF canvases support .nextPage()"); } cairo_show_page(context->context()); @@ -596,8 +596,8 @@ NAN_METHOD(Context2d::PutImageData) { switch (args.Length()) { // imageData, dx, dy case 3: - cols = std::min(arr->width(), context->canvas()->width - dx); - rows = std::min(arr->height(), context->canvas()->height - dy); + cols = std::min(arr->width(), context->canvas()->getWidth() - dx); + rows = std::min(arr->height(), context->canvas()->getHeight() - dy); break; // imageData, dx, dy, sx, sy, sw, sh case 7: @@ -611,8 +611,8 @@ NAN_METHOD(Context2d::PutImageData) { if (sy + sh > arr->height()) sh = arr->height() - sy; dx += sx; dy += sy; - cols = std::min(sw, context->canvas()->width - dx); - rows = std::min(sh, context->canvas()->height - dy); + cols = std::min(sw, context->canvas()->getWidth() - dx); + rows = std::min(sh, context->canvas()->getHeight() - dy); break; default: return NanThrowError("invalid arguments"); @@ -691,8 +691,8 @@ NAN_METHOD(Context2d::DrawImage) { // Canvas } else if (NanHasInstance(Canvas::constructor, obj)) { Canvas *canvas = ObjectWrap::Unwrap(obj); - sw = canvas->width; - sh = canvas->height; + sw = canvas->getWidth(); + sh = canvas->getHeight(); surface = canvas->surface(); // Invalid diff --git a/src/PixelArray.cc b/src/PixelArray.cc index f39b3375d..f7a5a298c 100644 --- a/src/PixelArray.cc +++ b/src/PixelArray.cc @@ -99,8 +99,8 @@ PixelArray::PixelArray(Canvas *canvas, int sx, int sy, int width, int height): if (sx < 0) width += sx, sx = 0; if (sy < 0) height += sy, sy = 0; - if (sx + width > canvas->width) width = canvas->width - sx; - if (sy + height > canvas->height) height = canvas->height - sy; + if (sx + width > canvas->getWidth()) width = canvas->getWidth() - sx; + if (sy + height > canvas->getHeight()) height = canvas->getHeight() - sy; if (width <= 0 || height <= 0) return; // Normalize data (argb -> rgba) diff --git a/src/backend/Backend.hpp b/src/backend/Backend.h similarity index 86% rename from src/backend/Backend.hpp rename to src/backend/Backend.h index 830f99d51..d6dfede1a 100644 --- a/src/backend/Backend.hpp +++ b/src/backend/Backend.h @@ -18,19 +18,17 @@ class Backend { protected: string name; - + int width; int height; cairo_surface_t *surface; public: - virtual ~Backend() { - this->destroySurface(); - }; + virtual ~Backend() = 0; - virtual cairo_surface_t *createSurface(); - virtual cairo_surface_t *recreateSurface(); - virtual void destroySurface(); + virtual cairo_surface_t *createSurface() = 0; + virtual cairo_surface_t *recreateSurface() = 0; + virtual void destroySurface() = 0; string getName() { return name; }; diff --git a/src/backend/FBDevBackend.cpp b/src/backend/FBDevBackend.cc similarity index 97% rename from src/backend/FBDevBackend.cpp rename to src/backend/FBDevBackend.cc index d3261b938..f576d9bf9 100644 --- a/src/backend/FBDevBackend.cpp +++ b/src/backend/FBDevBackend.cc @@ -7,7 +7,7 @@ #include #include #include -#include "FBDevBackend.hpp" +#include "FBDevBackend.h" FBDevBackend::FBDevBackend(string deviceName) { this->name = "fbdev"; @@ -116,7 +116,7 @@ void FBDevBackend::destroySurface() { cairo_surface_destroy(this->surface); } -static void cairo_linuxfb_surface_destroy(void *device) { +void cairo_linuxfb_surface_destroy(void *device) { FBDevBackend *backend = (FBDevBackend *) device; if (backend == NULL) { diff --git a/src/backend/FBDevBackend.hpp b/src/backend/FBDevBackend.h similarity index 88% rename from src/backend/FBDevBackend.hpp rename to src/backend/FBDevBackend.h index 39bb0f218..73cdb2d66 100644 --- a/src/backend/FBDevBackend.hpp +++ b/src/backend/FBDevBackend.h @@ -4,7 +4,7 @@ #include #include #include -#include "Backend.hpp" +#include "Backend.h" using namespace std; @@ -28,9 +28,10 @@ class FBDevBackend : public Backend { void setHeight(int height); FBDevBackend(string deviceName); + ~FBDevBackend() { this->destroySurface(); } }; -static void cairo_linuxfb_surface_destroy(void *device); +void cairo_linuxfb_surface_destroy(void *device); class FBDevBackendException : public std::exception { private: diff --git a/src/backend/ImageBackend.cpp b/src/backend/ImageBackend.cc similarity index 70% rename from src/backend/ImageBackend.cpp rename to src/backend/ImageBackend.cc index 01ba32f3e..6530f9dc9 100644 --- a/src/backend/ImageBackend.cpp +++ b/src/backend/ImageBackend.cc @@ -1,4 +1,4 @@ -#include "ImageBackend.hpp" +#include "ImageBackend.h" ImageBackend::ImageBackend(int width, int height) { this->name = "image"; @@ -7,16 +7,16 @@ ImageBackend::ImageBackend(int width, int height) { this->height = height; } -cairo_surface_t *ImageBackend::Backend::createSurface() { +cairo_surface_t *ImageBackend::createSurface() { this->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, this->width, this->height); //NanAdjustExternalMemory(4 * this->width * this->height); return this->surface; } -cairo_surface_t *ImageBackend::Backend::recreateSurface() { +cairo_surface_t *ImageBackend::recreateSurface() { if (this->surface != NULL) { - int old_width = cairo_image_surface_get_width(this->surface); - int old_height = cairo_image_surface_get_height(this->surface); + //int old_width = cairo_image_surface_get_width(this->surface); + //int old_height = cairo_image_surface_get_height(this->surface); cairo_surface_destroy(this->surface); //NanAdjustExternalMemory(-4 * old_width * old_height); } @@ -25,7 +25,7 @@ cairo_surface_t *ImageBackend::Backend::recreateSurface() { return this->surface; } -void ImageBackend::Backend::destroySurface() { +void ImageBackend::destroySurface() { if (this->surface != NULL) { cairo_surface_destroy(this->surface); //NanAdjustExternalMemory(-4 * this->width * this->height); diff --git a/src/backend/ImageBackend.h b/src/backend/ImageBackend.h new file mode 100644 index 000000000..25d003a9e --- /dev/null +++ b/src/backend/ImageBackend.h @@ -0,0 +1,21 @@ +#ifndef __IMAGE_BACKEND_H__ +#define __IMAGE_BACKEND_H__ + +#include "Backend.h" + +using namespace std; + +class ImageBackend : public Backend { + public: + virtual cairo_surface_t *createSurface(); + virtual cairo_surface_t *recreateSurface(); + virtual void destroySurface(); + + void setWidth(int width); + void setHeight(int height); + + ImageBackend(int width, int height); + ~ImageBackend() { this->destroySurface(); } +}; + +#endif diff --git a/src/backend/ImageBackend.hpp b/src/backend/ImageBackend.hpp deleted file mode 100644 index 55ea0feb7..000000000 --- a/src/backend/ImageBackend.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef __IMAGE_BACKEND_H__ -#define __IMAGE_BACKEND_H__ - -#include "Backend.hpp" - -using namespace std; - -class ImageBackend : public Backend { - public: - ImageBackend(int width, int height); -}; - -#endif diff --git a/src/backend/Makefile b/src/backend/Makefile index 12a073d0e..6126f78bc 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -1,5 +1,5 @@ all: - g++ FBDevBackend.cpp ImageBackend.cpp main.cpp -lcairo -o backendtest + g++ FBDevBackend.cc ImageBackend.cc main.cc -lcairo -o backendtest run: all ./backendtest diff --git a/src/backend/backendtest b/src/backend/backendtest new file mode 100755 index 0000000000000000000000000000000000000000..c75c3986fd355482b3fd152a876ad14e6ff28085 GIT binary patch literal 29256 zcmcJ23w%`7)$g7p1L2VnCnGOCKuj*URUl4H2lp*4vxvS4&%~`Lx;@p%ovssTa-nUu*AuX3xnS zwD*2@^UJKg{(J4U*IsA8&N=&RZY-}{m*H{=9Wumc1aZOBybQ@-A#T5#S%sB~Y~dC2 z#2I1&5I6q3oI+H_G#yl`HO*FXnV?w|&rm>yS4I>)LvkoV25lixDlZwlDk|v*iq%vI z52sT;vQ?BZ3mTLWMf2DgAx0*ubd`_HqkM%bU!juMG>-%jG}ZMZb@X?JNyW44IK8bqNehhc8Fv(&1eWdiJ4Frj!344)`?K;z?uASq^v$EY#m+KwmA9BD~JJ{LiP~UkD@-I2b zJJf5AgFRIa{@mkG?$ZwC_BfQ=?cg_`L%Eka$nST+?{>iNgZ~953UO`zmnjvu%!7i!$|bxkB{V@c#upGsF~e;?t?}b5*^(s@!~~?FE+4 z74H?L%D)Bu)PFs*Q}JflL;mz$8boT+pGC^fVVgYy^JQJAsXZd6$UtC6OQbc>5e>CR z0|61ZtShi7yrZcj8gBPBhdMgK9U@RsvmsC)ZdY*4248ceHCz*_Z4S${v?*LhprfP!=Y$6&=6@4)Q6&>Q^=%EBJI~U z)khmuD)h93qNs3tQ@zw`rfPdTkgKyJtcrxoI->P;OO}w&N<<*g7Hx!8^?_@`I|I@_ zfOXxWKtp>t90+&Uh1;S{kya7dwsC!R$N6#sA^YYD?6I53tLhsA#yEJ zs-tbq6?N6oqN2LSPp3xY+7Gkg3GvV zV|B;cB2tD}w6rPG5vUDygjZIyHbpJG!&ih%b;v@xAX>AfI=b32O=<~MlMKfr%^iqK zogKiD5v>CSP#c#hP_(WQ7i~v( zcc3lY-VtdHH8(|f2D%El)`qLr7AseGl!V&a!mah>vld8IM_1NGI-@L4?rTD<^;((I z+yR^Im$iHouoX%FvFB<6<<;j00Olh%Pf0UqW zPc2Db+iGqB>o!$KssrTo>L}{q*f!JDL|Lr7WVO?yMv%a~i zi-y-0IZPn7qYho4xFQkQ+P!o_Q^k)%h01<&O508OBE&2wJ=YU%4#ic%9U`0WpxU{lj zjW1AKP+V}n@NL~%wx%LbRImb;B^fERbt~lQwg&e+@?R$3Atm_?@RWinhN=9;gv>l~ zS&U~v!p(7cuSF7+kA5d`j5JGW+)Al`lkAU$dui(y8@!&ssTjHk)IqOr2xn)i1iii?{Cq78s^@RQ*BH27_YkgbsX0}zdk9}; z$OnBv=Ez1=*9wikAjb(O59`q83v!fjx}G|8`+^)LTwenMdVE15d@oF8>u|d-$WfA4 zE@OVTFUXW|`qSZlUy!4O;X+wqk1xn^!Y6Y~{_OPyIYKxtoE7%@f*dD&D#zr{(@9UyvgtU&b-{ z6ZZu0z?T~M5d&Xl;KK%9VBkj$e7S*-7v4M{o_zDB}_a4vo z_qofLd4&I#!Kgd_MI`!r4`&~eLSyG&fTXd77vXo>JTGFz(_OqsjEo^HEGC|Y#>6o5 z=MkSl{2=r5iKn43v5)z=#M2O%*u(q`;%Vqh>}Gy4@igQmdYI23ej@R0%zv;HJmwOS z2r~Z;@igQms+fP1_{qe3nSYgd8sZX#%>RM-slHaX8t_lX$VOSGC!Yq z8afjDn4e2L4H=0&%+Da6hKj^)<|h+RLqwv7`3&OECBBXM50-$ZE}jT7{|@ogwG&m$ zze)Ug#Cw^4m3ZpPi9+W8K>SkTJWYaG z=6^ywb-~0i^FJV-x?W2Ivy>5np@z#lu|e>#4N-}Q|DHy=emZE2gLwN0Bxdbs?ai=Qs= z2+=uxGcv|o;ehSWxE}@NdiM~G2M6-Y$goR9r~BAfkk3-~Hf0za-k!J)c_?0up=ORh zc0=4B>m2d-m4gn&uRzD*_>gE@;g!+eK@TPUMK_CP@~5&`yWu)oTK#1Vh& z8Gr0|@dmWiW6S-qLn;F+_yXL04E2>DGM7$9VX>p6XCX3Rl$&$q_CsV_SxvS7rsIPc z#r(0Kmr`2aEliXxT_|>d#x&&R8pdZrD0WbZ#j5gEtk0X@J32P)mT!`5|1H!52WYII zGH=3F)q4B4dUSHBsv6ff_A*J%hUEiSDEu2J`vB>P7Xqg0^q24P_kWdi`(rPX{3`Ma zq2!HM;s-IhNp>jSjHD-z=X=FK;Yu&ecqM)rX;IbduUe|2FnmC)6GGRo{)4eGs>!{B zy9TH2N>`nqn0k`c2`aN+g95*-j-R}ztMe=1vN|EMnya%fwK|QIwZD9ys?NI@yd^sn ze-KHj)%hZ6k=5z*E;TMmo`n_~=u8V;n?!fhos3TCA*OdUFS-UlH%{yw&5mw7R@*x| zCwhACsHbzQk{jwNgdBy$pYW4{QbJ`+-WjgUv%3{M$kkg)|bpp&fKwx~3E1)|W z6y+xsAv<%9z3o#;yG{2UQSMtiYPs+Ghz=Z6_);*^eFs^B+&7%+zGwfz?i*I_tHIiX zh0qZ{LQ<;xULq~Jx9uLL>gmRsKagQ`xOd1M{GzL+UK`A zTvB!)^&BOju47qjlm@a~wlI0ctL9i@UPQl2WAYQl3ox2d1ECxzDTi`OpLb581ga}y zhy6Sn4#itgvtyYAVC3^awlemboD<~WOe&tG+RJGn7j=`lG58F{mz%j?1(POsUo!VF z^vm4nT0`--|8A81aQfUElDY4(a-(Gp#sAIB-H<-_v}EoYEB6TH?lg1fr_cQx$f$bH zLT>*}hiL-5vh1qloY;HZgBkm1tn)t(%%L9nC}*J-^cIzJ7nR??`7Q7x1B+<>1~`{w z`pSjL>tq-QJI=FrH%A-d8BMwzo*xdo{_V+WP_qWo_>g!`=gkr`r1=5X0V&-nH4= zPr1?bz5}Z4{Q-=y*(;rUIm=qkEjEq4SQ-0s6ks!UkzwqYC|S8`2Gpe*TLr{0_Hw(i zBa|D)j)E#hYmf}3p z`(xu1ZsU4xQa(A-RzBpU}0nq+*>Xkb1)3Uxhn*lH#@D5>gNLS?L9; zLq102=_BcwxVgS9Idid|+ufzG~ z0-W=mK)#d(_+81WK8y^gYCaa=e069AE}K}~!HS2p6|iU>6lw2X#PR_D^DPutKn*1549#Z1eCywwkwZr2g9{#rwDBX>I4IC26(i0`J) zWer&vpye>N0Scsga&;;6qepk*!frl-I`akoEw94iZtm@v-;o9JBjn6GDITM7J??iA zL2e#(!Ys5InKs}?fZ$(~{J=5F%euAXQ}BkqR=|ehPqI#q-bkLJ+`WfO)t!2>MaZ$r z{?y=lXE{~<=bN#ryY4XbGwqYL+t~bVmDAXh!H-|>lSm&Q( z7$8+sxsm#vw6XAfYdp;!c$`-{L-9jz%Jja?e~$4`8pr4wtD2c&+pV2ny2ra7LjmF&bKjIMAN+MoulRe)XT$D0GUT~Ip(MmwpC5+x50_A@{=ZX zFX|g3Eh-B$qTw8%H<|ITq5wJcqfhb} z_b!luKT*qqm0e&eV}GM)AK`B+{PSSe#@-;jBM$rng|7oHZxyd1m^NRL%q7$&dAb^k zuYibbiwc+zK()ockQ`0kWmlDLH}4j_{-N?X-2A> zO^jePb{h;cYN<2!-Vhhj*-6Q4Q}Td^mWv;89S=QOif1(gJ+!2QN%S<1O|r@uUo^`2 zh#v2qvJ7rqiDM{;r^{F3%l|@`P2Z5p3O@x*-J!}_Uq&8~V?acj2Y>7%=N`tLPyC0; zr|5<7hZAb@tl2iQ1*CU`pbm}Mtij!mdj!+xa3$a zm(HB)2e0dnMC}KcEruGYOY<#wRt@UY=JlXqh_cU>#m36ERK(sd+guU*ZCOoa|H8&; z9z4SDU)BR!UAg%6qCfhd{xB21%#L6DXDGPkuhFyg^Zv@%o0YNm*FwkG%$NMVhg|;E z$2#9c8QE8Er`}rj`LY0B5m@gB-aUjyPVWHKD?i#LLc!A-iF!IZ+u9=S*f-{>-RY?f z)m?)PFdo`G(;lMzcplMETOaOX`MOXm<)Do}UKOZGy~SED-hcZcD`5 z!*cgxwcMr&WZeE$RUJ`YE0WPXQ7u9 zZddeSbsa_&{rpmyo|+r}R`qyErO#R><(%>t6<5$MT~)cHHtnCSN}sk%OAN0Ia&(VM zUuDzq$@=L=bjS-lVyQ>9Oixv$sTJKwV%R5(NViyy&bqvzwvY}6k0eZVz zh<%`YL7yQU`u+$y2g6S`?qarrc7yhSehYLD=yRZhp!K+gi-X2N^RRl##SM2M=ykZU z-wOH?Xb)%*k5l%7-U@mI^k<+aKwk%)gL3b{^D8gtC@AefI15kQj)2|^dIEG9G;e|s z8!^olg6;&}4Z0t6ALw(SRiG0vS+;@Fv+_bL8Wv#fwiom=+*u5R-UfOC^a0`__bBn8 z^nN1``17Da(Bq)A=xD>6pFBK+9|7G8N!i(z7V;2>vHE@Hf_qa**)TtxfhtX-e+ zS~|*mGcy{JdY(i23CJx1wPZrc^y7fvM>@U4x6&JBI+bw;{<6>(zee<4TRHtnxt}6E z3b|b*x7U!n^p4Eltc-4wq-!EkOEQ zwCP&Jvs{;?)_-f#u1d(&K#uLoGvsV`y$88{kaM!@UZm5Lof0Z9-_Y{~Sr%Zf-$m$K zhardQE9uYrq&+V|PXWe)2aue#+R#JS?VhAu7W6y>xtVCwSsM*G=?C{jh>{mpADLt{*@IlB?G4H3-?fVL8 zKc%llI^FeLj=0sXGAdbs?D;dw`31(T?;)P$Gs+=9Jec&uROnd?e>RicW}94Xvb>){ z?skXkNA~;&(qBWpE=Jt4hg+q*Zto#oz}|HImF&G2>GXuC3-PS5&5q`z9T#O`tb*Ky zkh99^N~T|h^v99@B{Mx^Ckv3B*CTxv#^xnvy3wB>KzbDE7ntdtN&P=V`khEm*N#d5 zOGu}Oy-t2OiS&<|NQRY>29blT))`DcT)e<>g; z|2>pHig;GH;pd9}%saAr-5GC6S;|iK{0RE4hCbd;s@q|Wlv#lEN~G5#{RYId?lSaI zJL^cwMIlFir8h!Z4;XUXk22?GK$Po0L5OzDkxu@*2i5xA4{p{@l{ui5qgg&AFvzxrJr9`D=1LYjWp6eobyR z&u0%qPY?9K+>|gj=9)Usyx{CAPUkqR#~YVJvgHD|?}PLuPA^5H|`z zzM(Ldd9iEN0{1U7T%U12l95^Mz9l2Geg507%x}6V`aRd_K%aHFzn+nK)I}11agp!~ z8Cner%f7%}CboQBIXSNE+3vGk=gN#^$@M?5y!4dj1M?hvAHDkPqzpWAZq^9%av&BYH)o^hf3PM6r|zCqAe zjXzWsaX?GmeJ-)yeH}J{p;su`+@)Yj{WrVB*Az1K9Cbm1vW%&7K`(G`=8q8Qx{bL$ zwI0y6YhG}P=O|NL<;>pfzDj%n0IqF?>yqVeyq&$+eJ}%s{v<ozf;E6Q^pMJbim%^7O3*g{hKQ-#4OlanRo{@)$u#S&;G5`Bw;! zqO|dof=8uOf2W|9k>c+kjYWtLW_aBc;4oX!yy;$!X}mE{^4jjbN^X*(x_mr$;`+p=NqIb? zVP4yT;gI=lDqUs&|4#II5cYx=&60MOD7sG3Es8cM+NJ2Nir%N_cNN{Q=rfAGsOTGt zzOU$n*|NM@iY`*LMA3DMZc(&B(Jn=ARrEeZzpLneMW0dhMMd9G^nFDqV9`%umZFOk zEm3rxqFWSgP_#?YTNS-e(eEm{U(sh2eNoXj6n$UO38$&@6kMvkB*KG}Vg&;u=F8jiR7_XDjqcicefQr3)WX(r2+I z6F^#fxH&`_RIIHzDhl|^wgP+*hd6)VR?r^d58MjEjrhzK&j$jH^~kF^D8PQCd998s|)9^c9^R-%{}jLXU%~_(YLz{K&+ps>hvF`APUfz-vMr z&%_s4dYm&8Gt+#}PU)GL4f0e!PL1~{3SY;cE6sIz9C*5VJgX6>!(ixqfiapg)afC@ZyAmp4aKw;;HPRH@g(HJ-XbO zT9@f^zpBdB>ot41gX(#)F88UADVJVAr7L%vS_kTK536$Z`p{l(c8Qnu=yItZ>FWD7 z5?ttaJ+}Te#`yU5MoQD^nSuqEON{RqX9K4%CGGvOSmE~mTh4mM_s5OEJ!$&a6~Jdu z5w_6nfZq+A&KuGFF<<3-%t8Jc;PcV0zMSu6$yz1vbWYBPO8%vVQl6guQCNnB;SA`Z zuWl$njKjsiN&lgXg3!d&g9D0^Oeh4Z*mnu8g08ghs zCx{m>DfDl2Z4JymiqJW z!1L0KV}~8||B3M&q2J3sqSR$zU?=GbS&!0FTvs+awIus0m!mtp~(PXFZ&_%*;uzkPhTm*sOr!4faKr%O5M zhYot4bHM-VpeHLwmTMnBXDZy@uk(SYtJg&ic&!6|9q@GLs@>=yj|ac(AH5Gj&%ghs zaQk}c1qVF|2i%=2_1ou{1;D8t_Ne)2p7Q^tN`AOdUKj0?5O9jy&w2a4(xdl3=<(`j ztVdY;5R`iHveKh@O;0-DbD@yhkKUi5`&XgD?fr2JaBZ{JO|%_2%@_9mxYI%YD+;%t z7xz=(??*TQfGY)fbeMl;AY0bV7U%m3+pA zlc%ECr6!-#)pxeE>_irW z8)~fs1l8e!ID9LxZDkP-`HEs+UL6zcqhgH_Tsz6}frm_v?f%1)O=>SK*~sqLa@MasTOI{Z&Mj!$b-HmS4La1LFyLtW5bYqmJ0@hNb2Rkrq7s`qvB!Gar4 zy%!OlOR4*|nu=3rfO|gvaL|+!F2`Ms)Ln$?u;LLG0p4uj><5zqZ9UD8p=`dJ2j1*UlTr*DH z`cvy$d2M4TO3t98boHE@dXO$3Zfgv+eAMRp@g>}=+e*# zXPswjzeegPRvXO6o!SnaO|?5v-w_EkV)cMGil#wnx@2-TQA-xvaE)dq=dRRx+B@57 zoDeLx==0UYFzv9X-85(XjD+#soXl($w=Z>8Ti*p>E|Kdjr=yZl?5Uf(u8@P>vIUvv zlwul8ohg(Byh+|#=h;t!{-h_ore055(=XCf{D0eFwyBPmu1u|napLv=!vW9#>Kv42 z;NsRl{uJPG4%6obr&jG_+X4Dxa{V-Zy^H*21Eu-NRsh?VdZxDBw$yfm5@}hV95(={ ziOX2l5hjnd_K3CB2U|;I+>>=+bTr8&UA!6ING77$N@t( zp$^+o>e3ABq~=spoF{fUkz+}E%5}2o!lFWW#9Vm%-yT72_XUmjrZeE#@dvA?ULmL6 zB+qb{E-?=8wmT)Yyid43A&;eA0t}VL>G1mCWn6iE5W20VX-*KgSyoe#Y8v_fUtVOQ zts_tBG1#e=q;sD>zdqS#)bM@En@&2#JXLq<0oO=V=T7rI&L?hcrD$vXrJCxt`kZ-N zS@4c^FG{Cx+mp$k<`V@zKwAl^&Q9lU+YsYOZTs}7JE~rftb(2NkrK@O?+LV{gI)pY z_q!s)3l2d6XGqTaRj-RI{v5>c%14V^`;PSg-{i3*WkkQ9(r^(XX8wyZyqrYeR!~?V ziS=vGzZNO@yeOjW4`z6Q(7sJ3qFEB`WRd}|Yf{2SaCii7**~1&1&8leRQ})uW(5(d zyUwql!)*bESISm?y)UW|?@1`={h*SQI&_@q=kZ5-F}3}A|I{`-=cI7EB$oYJPSb0U zPJ25wulHHSRsJ58pX?_)wfzbf*C9ea)%o>)EIzpv_+BMw_n)r+E|q_clFL*3Q}ghg zkiv+%V3Z%P5Ulcb{yTw@UzMA!{k$jCi@>=^GlNoRK{3S4{CXc)-YhA?-)>pb^lVxN zP45M3=GXfaf@)*KJ=#!PKE;Y}*z)WB$L~?YMo`T_GWfOIzXuqVul=vzSn5 zlbjG99Z{67kC|WZQ_Cxn0<>?)4EFN(Bhk#S_p{x!{CeNpuFuE} zT~@^;Z!iCOz<4FWZIdO+f=u)w<{rsezxMK9MhZ1`YTFd_z8z1QE^A^}am)|K92U-%h(xm#^F3DDs%)dwoG5LU?^lto|aoWdG56XrGsv z-|q{us9)uOoDz+o^JzK(>1KXwKVZ4cr0vuybUw{bMP|aZ|MWhkJe7ZsPEZ-VI-{b~ zRr!TBT<2eH!^u_(n$j?1D}vK2RQYqYAfw5Aie){vCdx^T>!ie9^^)Z*u(X#=*Iy3{ V)W6e}pLd1K->$|%$&D}nzW~*9O0)m~ literal 0 HcmV?d00001 diff --git a/src/backend/main.cpp b/src/backend/main.cc similarity index 91% rename from src/backend/main.cpp rename to src/backend/main.cc index 7d1220a26..b3b9356f5 100644 --- a/src/backend/main.cpp +++ b/src/backend/main.cc @@ -1,5 +1,5 @@ -#include "FBDevBackend.hpp" -#include "ImageBackend.hpp" +#include "FBDevBackend.h" +#include "ImageBackend.h" #include diff --git a/src/cairo_linuxfb.c b/src/cairo_linuxfb.c deleted file mode 100644 index f239440f9..000000000 --- a/src/cairo_linuxfb.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "cairo_linuxfb.h" - -#include -#include -#include -#include -#include -#include - -// Linux framebuffer surface: http://lists.cairographics.org/archives/cairo/2010-July/020378.html - -static void cairo_linuxfb_surface_destroy(void *device) { - cairo_linuxfb_device_t *dev = (cairo_linuxfb_device_t *)device; - - if (dev == NULL) { - return; - } - munmap(dev->fb_data, dev->fb_screensize); - close(dev->fb_fd); - free(dev); -} - -cairo_surface_t *cairo_linuxfb_surface_create(const char *fb_name) { - cairo_linuxfb_device_t *device; - cairo_surface_t *surface; - - if (fb_name == NULL) { - fb_name = "/dev/fb0"; - } - - device = malloc(sizeof(*device)); - - // Open the file for reading and writing - device->fb_fd = open(fb_name, O_RDWR); - if (device->fb_fd == -1) { - perror("Error: cannot open framebuffer device"); - exit(1); - } - - // Get variable screen information - if (ioctl(device->fb_fd, FBIOGET_VSCREENINFO, &device->fb_vinfo) == -1) { - perror("Error reading variable information"); - exit(3); - } - - // Figure out the size of the screen in bytes - device->fb_screensize = device->fb_vinfo.xres * device->fb_vinfo.yres * device->fb_vinfo.bits_per_pixel / 8; - - // Map the device to memory - device->fb_data = (char *) mmap( - 0, - device->fb_screensize, - PROT_READ | PROT_WRITE, - MAP_SHARED, - device->fb_fd, - 0 - ); - if ((int)device->fb_data == -1) { - perror("Error: failed to map framebuffer device to memory"); - exit(4); - } - - // Get fixed screen information - if (ioctl(device->fb_fd, FBIOGET_FSCREENINFO, &device->fb_finfo) == -1) { - perror("Error reading fixed information"); - exit(2); - } - - // TODO decide image format by bpp of fb device - surface = cairo_image_surface_create_for_data( - device->fb_data, - CAIRO_FORMAT_ARGB32, - device->fb_vinfo.xres, - device->fb_vinfo.yres, - cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, device->fb_vinfo.xres) - ); - cairo_surface_set_user_data( - surface, - NULL, - device, - &cairo_linuxfb_surface_destroy - ); - - return surface; -} diff --git a/src/cairo_linuxfb.h b/src/cairo_linuxfb.h deleted file mode 100644 index f078e2432..000000000 --- a/src/cairo_linuxfb.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __CAIRO_FBDEV_CANVAS_H__ -#define __CAIRO_FBDEV_CANVAS_H__ - -#include -#include - -typedef struct _cairo_linuxfb_device { - int fb_fd; - unsigned char *fb_data; - long fb_screensize; - struct fb_var_screeninfo fb_vinfo; - struct fb_fix_screeninfo fb_finfo; -} cairo_linuxfb_device_t; - -static void cairo_linuxfb_surface_destroy(void *device); -cairo_surface_t *cairo_linuxfb_surface_create(const char *fb_name); - -#endif From 79d55f68a33f193d6bba18c9f38e61faca848f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sat, 2 May 2015 14:32:27 +0200 Subject: [PATCH 017/183] Added deps to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 130894492..d524b8316 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ node_modules # Vim cruft *.swp *.un~ +deps/ From a94281bfcb9c75aa33a3832b62f8e26ce34c4d50 Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Sat, 2 May 2015 15:29:20 +0200 Subject: [PATCH 018/183] removed nodejs 0.6 support updated nan to 1.8.4 --- package.json | 4 ++-- src/Canvas.cc | 31 ------------------------------- src/Canvas.h | 12 +----------- src/CanvasRenderingContext2d.cc | 1 - 4 files changed, 3 insertions(+), 45 deletions(-) diff --git a/package.json b/package.json index 5704b00f2..b096b9db8 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "test": "make test" }, "dependencies": { - "nan": "~1.7.0" + "nan": "~1.8.4" }, "devDependencies": { "express": "3.0", @@ -33,7 +33,7 @@ "should": "*" }, "engines": { - "node": ">= 0.6.0" + "node": ">= 0.10.0" }, "main": "./lib/canvas.js" } diff --git a/src/Canvas.cc b/src/Canvas.cc index c59fb78a5..c3cc93baa 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -181,47 +181,25 @@ toBuffer(void *c, const uint8_t *data, unsigned len) { * EIO toBuffer callback. */ -#if NODE_VERSION_AT_LEAST(0, 6, 0) void Canvas::ToBufferAsync(uv_work_t *req) { -#elif NODE_VERSION_AT_LEAST(0, 5, 4) -void -Canvas::EIO_ToBuffer(eio_req *req) { -#else -int -Canvas::EIO_ToBuffer(eio_req *req) { -#endif closure_t *closure = (closure_t *) req->data; closure->status = canvas_write_to_png_stream( closure->canvas->surface() , toBuffer , closure); - -#if !NODE_VERSION_AT_LEAST(0, 5, 4) - return 0; -#endif } /* * EIO after toBuffer callback. */ -#if NODE_VERSION_AT_LEAST(0, 6, 0) void Canvas::ToBufferAsyncAfter(uv_work_t *req) { -#else -int -Canvas::EIO_AfterToBuffer(eio_req *req) { -#endif - NanScope(); closure_t *closure = (closure_t *) req->data; -#if NODE_VERSION_AT_LEAST(0, 6, 0) delete req; -#else - ev_unref(EV_DEFAULT_UC); -#endif if (closure->status) { Local argv[1] = { Canvas::Error(closure->status) }; @@ -237,10 +215,6 @@ Canvas::EIO_AfterToBuffer(eio_req *req) { delete closure->pfn; closure_destroy(closure); free(closure); - -#if !NODE_VERSION_AT_LEAST(0, 6, 0) - return 0; -#endif } /* @@ -309,14 +283,9 @@ NAN_METHOD(Canvas::ToBuffer) { canvas->Ref(); closure->pfn = new NanCallback(args[0].As()); -#if NODE_VERSION_AT_LEAST(0, 6, 0) uv_work_t* req = new uv_work_t; req->data = closure; uv_queue_work(uv_default_loop(), req, ToBufferAsync, (uv_after_work_cb)ToBufferAsyncAfter); -#else - eio_custom(EIO_ToBuffer, EIO_PRI_DEFAULT, EIO_AfterToBuffer, closure); - ev_ref(EV_DEFAULT_UC); -#endif NanReturnUndefined(); // Sync diff --git a/src/Canvas.h b/src/Canvas.h index 8d9e78625..d3a46fdbd 100644 --- a/src/Canvas.h +++ b/src/Canvas.h @@ -53,19 +53,9 @@ class Canvas: public node::ObjectWrap { static NAN_METHOD(StreamPNGSync); static NAN_METHOD(StreamJPEGSync); static Local Error(cairo_status_t status); -#if NODE_VERSION_AT_LEAST(0, 6, 0) + static void ToBufferAsync(uv_work_t *req); static void ToBufferAsyncAfter(uv_work_t *req); -#else - static -#if NODE_VERSION_AT_LEAST(0, 5, 4) - void -#else - int -#endif - EIO_ToBuffer(eio_req *req); - static int EIO_AfterToBuffer(eio_req *req); -#endif inline Backend *backend() { return _backend; } inline cairo_surface_t *surface(){ return backend()->getSurface(); } diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 2b82d4660..76a729995 100755 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -376,7 +376,6 @@ Context2d::shadow(void (fn)(cairo_t *cr)) { double dx = x2-x1, dy = y2-y1; cairo_user_to_device_distance(_context, &dx, &dy); int pad = state->shadowBlur * 2; - cairo_surface_t *surface = cairo_get_group_target(_context); cairo_surface_t *shadow_surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, dx + 2 * pad, From af21558bb7f52135865595a95db5292d55e840c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sat, 2 May 2015 15:49:52 +0200 Subject: [PATCH 019/183] Left 'deps' folder only for downloaded files --- .gitignore | 1 + deps/locations.gyp | 15 -------- static.gyp | 18 +++++----- {deps => static}/cairo.gyp | 24 ++++++------- {deps => static}/common.gyp | 0 .../custom-include/cairo/cairo-features.h | 0 .../custom-include/cairo/config.h | 0 {deps => static}/custom-include/jpeg/config.h | 0 .../custom-include/jpeg/jconfig.h | 0 .../custom-include/pixman/config.h | 0 .../custom-include/png/pnglibconf.h | 0 {deps => static}/ensure_deps.sh | 7 ++-- {deps => static}/freetype.gyp | 0 {deps => static}/gif.gyp | 0 {deps => static}/jpeg.gyp | 34 +++++++++---------- {deps => static}/libpng.gyp | 12 +++---- static/locations.gyp | 11 ++++++ {deps => static}/pixman.gyp | 14 ++++---- {deps => static}/zlib.gyp | 0 19 files changed, 67 insertions(+), 69 deletions(-) delete mode 100644 deps/locations.gyp rename {deps => static}/cairo.gyp (97%) rename {deps => static}/common.gyp (100%) rename {deps => static}/custom-include/cairo/cairo-features.h (100%) rename {deps => static}/custom-include/cairo/config.h (100%) rename {deps => static}/custom-include/jpeg/config.h (100%) rename {deps => static}/custom-include/jpeg/jconfig.h (100%) rename {deps => static}/custom-include/pixman/config.h (100%) rename {deps => static}/custom-include/png/pnglibconf.h (100%) rename {deps => static}/ensure_deps.sh (97%) rename {deps => static}/freetype.gyp (100%) rename {deps => static}/gif.gyp (100%) rename {deps => static}/jpeg.gyp (92%) rename {deps => static}/libpng.gyp (95%) create mode 100644 static/locations.gyp rename {deps => static}/pixman.gyp (94%) rename {deps => static}/zlib.gyp (100%) diff --git a/.gitignore b/.gitignore index d524b8316..c0febb160 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ node_modules *.swp *.un~ deps/ +npm-debug.log diff --git a/deps/locations.gyp b/deps/locations.gyp deleted file mode 100644 index a0f4070c5..000000000 --- a/deps/locations.gyp +++ /dev/null @@ -1,15 +0,0 @@ -{ - - 'variables': { - - 'cairo_root%': "./cairo-1.12.16/", - 'pixman_root%': "./pixman-0.30.2/", - 'freetype_root%': "./freetype-2.5.0/", - 'zlib_root%': "./zlib-1.2.8/", - 'libpng_root%': "./libpng-1.2.49/", - 'gif_root%': "./giflib-4.2.3/", - 'jpeg_root%': "./libjpeg-turbo-1.2.1/", - - } - -} \ No newline at end of file diff --git a/static.gyp b/static.gyp index f28b531c6..77e1669a5 100644 --- a/static.gyp +++ b/static.gyp @@ -1,7 +1,7 @@ { - 'includes': [ 'deps/locations.gyp'], + 'includes': [ 'static/locations.gyp'], 'variables':{ - 'ensure_deps%': ' Date: Sun, 3 May 2015 01:44:27 +0200 Subject: [PATCH 020/183] Fixed included dirs for standalone build --- static.gyp | 13 +++++++------ static/cairo.gyp | 22 ++++++++++++---------- static/libpng.gyp | 1 + static/locations.gyp | 6 +++--- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/static.gyp b/static.gyp index 77e1669a5..f299bc55d 100644 --- a/static.gyp +++ b/static.gyp @@ -10,13 +10,14 @@ " Date: Sun, 21 Jun 2015 13:54:50 +0200 Subject: [PATCH 021/183] Removed useless index.js file (main is already defined in package.json) --- benchmarks/run.js | 2 +- examples/clock.js | 8 ++++---- examples/crop.js | 4 +--- examples/font.js | 2 +- examples/globalAlpha.js | 4 ++-- examples/gradients.js | 4 ++-- examples/grayscale-image.js | 4 ++-- examples/image-src.js | 34 +++++++++++++++++----------------- examples/kraken.js | 6 +++--- examples/live-clock.js | 6 +++--- examples/multi-page-pdf.js | 4 ++-- examples/pango-glyphs.js | 2 +- examples/pdf-images.js | 4 ++-- examples/ray.js | 8 ++++---- examples/resize.js | 3 +-- examples/simple_fbdev.js | 2 +- examples/small-pdf.js | 4 ++-- examples/small-svg.js | 2 +- examples/spark.js | 2 +- examples/state.js | 6 +++--- examples/text.js | 2 +- examples/voronoi.js | 16 ++++++++-------- index.js | 1 - test/canvas.test.js | 4 ++-- test/image.test.js | 10 +++++----- test/server.js | 2 +- 26 files changed, 71 insertions(+), 75 deletions(-) delete mode 100644 index.js diff --git a/benchmarks/run.js b/benchmarks/run.js index a251a590f..bd3ed77b8 100644 --- a/benchmarks/run.js +++ b/benchmarks/run.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , canvas = new Canvas(200, 200) , largeCanvas = new Canvas(1000, 1000) , ctx = canvas.getContext('2d'); diff --git a/examples/clock.js b/examples/clock.js index 4ed77cc82..7cf6642c5 100644 --- a/examples/clock.js +++ b/examples/clock.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , canvas = new Canvas(320, 320) , ctx = canvas.getContext('2d') , fs = require('fs'); @@ -53,7 +53,7 @@ function clock(ctx){ ctx.stroke(); } } - + var sec = now.getSeconds(); var min = now.getMinutes(); var hr = now.getHours(); @@ -79,7 +79,7 @@ function clock(ctx){ ctx.moveTo(x*-28,y*-28); ctx.lineTo(x*112,y*112); ctx.stroke(); - + // Write seconds var x = getX(sec * Math.PI/30); var y = getY(sec * Math.PI/30); @@ -110,4 +110,4 @@ var out = fs.createWriteStream(__dirname + '/clock.png') stream.on('data', function(chunk){ out.write(chunk); -}); \ No newline at end of file +}); diff --git a/examples/crop.js b/examples/crop.js index 37bd8f36a..a09c06b5a 100644 --- a/examples/crop.js +++ b/examples/crop.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , Image = Canvas.Image , fs = require('fs'); @@ -32,5 +32,3 @@ img.onload = function(){ }; img.src = __dirname + '/images/squid.png'; - - diff --git a/examples/font.js b/examples/font.js index 1a33f3b6a..20344432b 100644 --- a/examples/font.js +++ b/examples/font.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , canvas = new Canvas(320, 320) , Font = Canvas.Font , ctx = canvas.getContext('2d') diff --git a/examples/globalAlpha.js b/examples/globalAlpha.js index 4d79e24b7..8a68f1ba2 100644 --- a/examples/globalAlpha.js +++ b/examples/globalAlpha.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , canvas = new Canvas(150, 150) , ctx = canvas.getContext('2d') , fs = require('fs'); @@ -33,4 +33,4 @@ var out = fs.createWriteStream(__dirname + '/globalAlpha.png') stream.on('data', function(chunk){ out.write(chunk); -}); \ No newline at end of file +}); diff --git a/examples/gradients.js b/examples/gradients.js index 70ac64963..121529279 100644 --- a/examples/gradients.js +++ b/examples/gradients.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , canvas = new Canvas(320, 320) , ctx = canvas.getContext('2d') , fs = require('fs'); @@ -32,4 +32,4 @@ var out = fs.createWriteStream(__dirname + '/gradients.png') stream.on('data', function(chunk){ out.write(chunk); -}); \ No newline at end of file +}); diff --git a/examples/grayscale-image.js b/examples/grayscale-image.js index 5c3765727..81e86b732 100644 --- a/examples/grayscale-image.js +++ b/examples/grayscale-image.js @@ -2,7 +2,7 @@ * Passing grayscale image through canvas. Image should remain a gray square. * If image is distorted with lines, then grayscale images are being distorted. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , Image = Canvas.Image , canvas = new Canvas(288, 288) , ctx = canvas.getContext('2d') @@ -19,4 +19,4 @@ var out = fs.createWriteStream(__dirname + '/passedThroughGrayscale.jpg') stream.on('data', function(chunk){ out.write(chunk); -}); \ No newline at end of file +}); diff --git a/examples/image-src.js b/examples/image-src.js index b25ffa3db..bb9251a0b 100644 --- a/examples/image-src.js +++ b/examples/image-src.js @@ -3,28 +3,28 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , Image = Canvas.Image , canvas = new Canvas(200, 200) , ctx = canvas.getContext('2d') , fs = require('fs'); -ctx.fillRect(0,0,150,150); -ctx.save(); - -ctx.fillStyle = '#09F' +ctx.fillRect(0,0,150,150); +ctx.save(); + +ctx.fillStyle = '#09F' ctx.fillRect(15,15,120,120); - -ctx.save(); -ctx.fillStyle = '#FFF' -ctx.globalAlpha = 0.5; -ctx.fillRect(30,30,90,90); - -ctx.restore(); -ctx.fillRect(45,45,60,60); - -ctx.restore(); -ctx.fillRect(60,60,30,30); + +ctx.save(); +ctx.fillStyle = '#FFF' +ctx.globalAlpha = 0.5; +ctx.fillRect(30,30,90,90); + +ctx.restore(); +ctx.fillRect(45,45,60,60); + +ctx.restore(); +ctx.fillRect(60,60,30,30); var img = new Image; img.src = canvas.toBuffer(); @@ -42,4 +42,4 @@ var out = fs.createWriteStream(__dirname + '/image-src.png') stream.on('data', function(chunk){ out.write(chunk); -}); \ No newline at end of file +}); diff --git a/examples/kraken.js b/examples/kraken.js index 95fc8502c..dddbc80c2 100644 --- a/examples/kraken.js +++ b/examples/kraken.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , Image = Canvas.Image , canvas = new Canvas(400, 267) , ctx = canvas.getContext('2d') @@ -87,7 +87,7 @@ function blurTest() { ctx.putImageData(imgData, 0, 0); console.log('... finished in %dms', finishTime); } - + blurTest(); var out = fs.createWriteStream(__dirname + '/kraken.png') @@ -95,4 +95,4 @@ var out = fs.createWriteStream(__dirname + '/kraken.png') stream.on('data', function(chunk){ out.write(chunk); -}); \ No newline at end of file +}); diff --git a/examples/live-clock.js b/examples/live-clock.js index e8e3e9729..a6f24c4c8 100644 --- a/examples/live-clock.js +++ b/examples/live-clock.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , canvas = new Canvas(320, 320) , ctx = canvas.getContext('2d') , http = require('http'); @@ -53,7 +53,7 @@ function clock(ctx){ ctx.stroke(); } } - + var sec = now.getSeconds(); var min = now.getMinutes(); var hr = now.getHours(); @@ -79,7 +79,7 @@ function clock(ctx){ ctx.moveTo(x*-28,y*-28); ctx.lineTo(x*112,y*112); ctx.stroke(); - + // Write seconds var x = getX(sec * Math.PI/30); var y = getY(sec * Math.PI/30); diff --git a/examples/multi-page-pdf.js b/examples/multi-page-pdf.js index 8bf994bc2..4f8742823 100644 --- a/examples/multi-page-pdf.js +++ b/examples/multi-page-pdf.js @@ -1,5 +1,5 @@ -var Canvas = require('../') +var Canvas = require('..') , canvas = new Canvas(500, 500, 'pdf') , ctx = canvas.getContext('2d') , fs = require('fs'); @@ -36,4 +36,4 @@ h1('Page #3'); p('This is the third page'); fs.writeFile('out.pdf', canvas.toBuffer()); -console.log('created out.pdf'); \ No newline at end of file +console.log('created out.pdf'); diff --git a/examples/pango-glyphs.js b/examples/pango-glyphs.js index f0e1efd25..17616949a 100644 --- a/examples/pango-glyphs.js +++ b/examples/pango-glyphs.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , canvas = new Canvas(400, 100) , ctx = canvas.getContext('2d') , fs = require('fs'); diff --git a/examples/pdf-images.js b/examples/pdf-images.js index 76862b169..1dda52627 100644 --- a/examples/pdf-images.js +++ b/examples/pdf-images.js @@ -1,5 +1,5 @@ -var Canvas = require('../') +var Canvas = require('..') , Image = Canvas.Image , canvas = new Canvas(500, 500, 'pdf') , ctx = canvas.getContext('2d') @@ -44,4 +44,4 @@ p('Figure 1.1 - Lime cat is awesome'); ctx.addPage(); fs.writeFile('out.pdf', canvas.toBuffer()); -console.log('created out.pdf'); \ No newline at end of file +console.log('created out.pdf'); diff --git a/examples/ray.js b/examples/ray.js index 93b325a42..8c5ad1ed3 100644 --- a/examples/ray.js +++ b/examples/ray.js @@ -3,8 +3,8 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') - , canvas = new Canvas(243 * 4, 243) +var Canvas = require('..') + , canvas = new Canvas(243 * 4, 243) , ctx = canvas.getContext('2d') , fs = require('fs'); @@ -72,9 +72,9 @@ function getPointColour(x,y){ var start = new Date; render(10); ctx.translate(243,0); -render(6); +render(6); ctx.translate(243,0); -render(3); +render(3); ctx.translate(243,0); render(1); console.log('Rendered in %s seconds', (new Date - start) / 1000); diff --git a/examples/resize.js b/examples/resize.js index 7284fe92b..256375117 100644 --- a/examples/resize.js +++ b/examples/resize.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , Image = Canvas.Image , fs = require('fs'); @@ -31,4 +31,3 @@ img.onload = function(){ }; img.src = process.argv[2] || __dirname + '/images/squid.png'; - diff --git a/examples/simple_fbdev.js b/examples/simple_fbdev.js index 30eb3d5f3..218a30462 100644 --- a/examples/simple_fbdev.js +++ b/examples/simple_fbdev.js @@ -4,7 +4,7 @@ */ var fs = require('fs'); -var Canvas = require('../lib/canvas'); +var Canvas = require('..'); var canvas = new Canvas(0, 0, "fbdev") var ctx = canvas.getContext('2d') diff --git a/examples/small-pdf.js b/examples/small-pdf.js index 3004ffcb8..07a96840e 100644 --- a/examples/small-pdf.js +++ b/examples/small-pdf.js @@ -1,5 +1,5 @@ -var Canvas = require('../') +var Canvas = require('..') , canvas = new Canvas(400, 200, 'pdf') , ctx = canvas.getContext('2d') , fs = require('fs'); @@ -19,4 +19,4 @@ ctx.fillRect(x += 20, y, 10, 10); ctx.fillRect(x += 20, y, 10, 10); fs.writeFile('out.pdf', canvas.toBuffer()); -console.log('created out.pdf'); \ No newline at end of file +console.log('created out.pdf'); diff --git a/examples/small-svg.js b/examples/small-svg.js index 574c258c1..4ec0a519f 100644 --- a/examples/small-svg.js +++ b/examples/small-svg.js @@ -1,5 +1,5 @@ -var Canvas = require('../') +var Canvas = require('..') , canvas = new Canvas(400, 200, 'svg') , ctx = canvas.getContext('2d') , fs = require('fs'); diff --git a/examples/spark.js b/examples/spark.js index 6d6652dfc..bf94b3340 100644 --- a/examples/spark.js +++ b/examples/spark.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , canvas = new Canvas(40, 15) , ctx = canvas.getContext('2d') , fs = require('fs'); diff --git a/examples/state.js b/examples/state.js index 4b59c5e00..d43224f04 100644 --- a/examples/state.js +++ b/examples/state.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , canvas = new Canvas(150, 150) , ctx = canvas.getContext('2d') , fs = require('fs'); @@ -16,7 +16,7 @@ ctx.fillRect(15,15,120,120); // Draw a rectangle with new settings ctx.save(); // Save the current state ctx.fillStyle = '#FFF' // Make changes to the settings -ctx.globalAlpha = 0.5; +ctx.globalAlpha = 0.5; ctx.fillRect(30,30,90,90); // Draw a rectangle with new settings ctx.restore(); // Restore previous state @@ -30,4 +30,4 @@ var out = fs.createWriteStream(__dirname + '/state.png') stream.on('data', function(chunk){ out.write(chunk); -}); \ No newline at end of file +}); diff --git a/examples/text.js b/examples/text.js index 945a0e1b0..d3fb0d1f7 100644 --- a/examples/text.js +++ b/examples/text.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , canvas = new Canvas(200, 200) , ctx = canvas.getContext('2d') , fs = require('fs'); diff --git a/examples/voronoi.js b/examples/voronoi.js index 9f028bc59..bc8f3e63b 100644 --- a/examples/voronoi.js +++ b/examples/voronoi.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../lib/canvas') +var Canvas = require('..') , canvas = new Canvas(1920, 1200) , ctx = canvas.getContext('2d') , http = require('http') @@ -15,7 +15,7 @@ http.createServer(function (req, res) { var voronoi = voronoiFactory() , start = new Date; var bbox = { xl: 0, xr: canvas.width, yt: 0, yb: canvas.height }; - + for (var i =0 ;i<340;i++) { var x = Math.random()*canvas.width; @@ -39,7 +39,7 @@ http.createServer(function (req, res) { var sites = diagram.sites; var nSites = sites.length; - for (var iSite=nSites-1; iSite>=0; iSite-=1) + for (var iSite=nSites-1; iSite>=0; iSite-=1) { site = sites[iSite]; ctx.rect(site.x-0.5,site.y-0.5,1,1); @@ -48,7 +48,7 @@ http.createServer(function (req, res) { // ctx.stroke(); var cell = diagram.cells[diagram.sites[iSite].id]; - if (cell !== undefined) + if (cell !== undefined) { var halfedges = cell.halfedges; var nHalfedges = halfedges.length; @@ -62,7 +62,7 @@ http.createServer(function (req, res) { ctx.beginPath(); ctx.moveTo(v.x,v.y); - for (var iHalfedge=0; iHalfedge Date: Sun, 21 Jun 2015 19:22:57 +0200 Subject: [PATCH 022/183] Compile dependencies statically It's not working due lacks of _ZN8FontFace11constructorE symbol and also needs a workaround on system libraries (https://bugs.launchpad.net/ubuntu/+source/gcc-4.4/+bug/640734/comments/6) due to an unfixed bug on gcc (https://bugzilla.redhat.com/show_bug.cgi?id=214465), but it's a progress --- static.gyp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/static.gyp b/static.gyp index f299bc55d..287ee7afa 100644 --- a/static.gyp +++ b/static.gyp @@ -26,6 +26,9 @@ 'static/gif.gyp:gif', ], 'defines': [ 'HAVE_FREETYPE' ,'HAVE_JPEG' ,'HAVE_GIF' ], + 'libraries': [ + '-static' + ], 'sources': [ 'src/backend/ImageBackend.cc', 'src/backend/FBDevBackend.cc', From e7997f8fb662270cd80abe0d83c5aee838854a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Mon, 22 Jun 2015 04:20:27 +0200 Subject: [PATCH 023/183] Re-enabled FontFace.cc source code file & minor fix-ups --- .gitmodules | 0 examples/simple_fbdev.js | 7 ++----- static.gyp | 2 +- test/canvas.test.js | 8 ++++---- 4 files changed, 7 insertions(+), 10 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/simple_fbdev.js b/examples/simple_fbdev.js index 218a30462..b9a281864 100644 --- a/examples/simple_fbdev.js +++ b/examples/simple_fbdev.js @@ -14,9 +14,6 @@ console.log("Width: " + canvas.width + ", Height: " + canvas.height); ctx.fillStyle = "#00FF00"; ctx.fillRect(50, 50, 100, 100); -var out = fs.createWriteStream(__dirname + '/rectangle.png'); -var stream = canvas.createPNGStream(); +var outPath = __dirname + '/rectangle.png'; -stream.on('data', function(chunk){ - out.write(chunk); -}); +canvas.createPNGStream().pipe(fs.createWriteStream(outPath)); diff --git a/static.gyp b/static.gyp index 287ee7afa..4a4abd8fb 100644 --- a/static.gyp +++ b/static.gyp @@ -41,7 +41,7 @@ 'src/ImageData.cc', 'src/init.cc', 'src/PixelArray.cc', -# 'src/FontFace.cc', + 'src/FontFace.cc', ], 'cflags!': [ '-fno-exceptions' ], 'cflags_cc!': [ '-fno-exceptions' ], diff --git a/test/canvas.test.js b/test/canvas.test.js index 7d77e6753..5af1763b2 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -212,13 +212,13 @@ module.exports = { 'test Canvas#type': function(){ var canvas = new Canvas(10, 10); - assert('image' == canvas.type); + assert.equal(canvas.type, 'image'); var canvas = new Canvas(10, 10, 'pdf'); - assert('pdf' == canvas.type); + assert.equal(canvas.type, 'pdf'); var canvas = new Canvas(10, 10, 'svg'); - assert('svg' == canvas.type); + assert.equal(canvas.type, 'svg'); var canvas = new Canvas(10, 10, 'hey'); - assert('image' == canvas.type); + assert.equal(canvas.type, 'image'); }, 'test Canvas#getContext("2d")': function(){ From 8bcf1fd4cfbad1cb6e0f84cd62b1ba84610dc4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Thu, 25 Jun 2015 23:39:59 +0200 Subject: [PATCH 024/183] Updated versions of dependencies and libraries & improved ensure_deps.sh --- package.json | 4 +- static.gyp | 4 +- static/cairo.gyp | 10 ++--- static/ensure_deps.sh | 92 +++++++++++++++++++------------------------ static/locations.gyp | 14 +++---- 5 files changed, 57 insertions(+), 67 deletions(-) diff --git a/package.json b/package.json index b096b9db8..b4f0655de 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,8 @@ "nan": "~1.8.4" }, "devDependencies": { - "express": "3.0", - "jade": "0.28.1", + "express": "4.13", + "jade": "1.11.0", "mocha": "*", "should": "*" }, diff --git a/static.gyp b/static.gyp index 4a4abd8fb..6ed5ee525 100644 --- a/static.gyp +++ b/static.gyp @@ -11,8 +11,8 @@ './deps/<(freetype_root)/include', './deps/<(jpeg_root)', './static/custom-include/jpeg/', - './deps/<(cairo_root)' , - './deps/<(cairo_root)cairo/' , + './deps/<(cairo_root)', + './deps/<(cairo_root)src', './static/custom-include/cairo/', './deps/<(gif_root)/lib/', './deps/<(libpng_root)/', diff --git a/static/cairo.gyp b/static/cairo.gyp index cefd80265..1eb86aea1 100644 --- a/static/cairo.gyp +++ b/static/cairo.gyp @@ -6,18 +6,18 @@ 'targets': [ { 'variables': { - - 'cairo_src%': "<(cairo_root)cairo/", - }, + 'cairo_src%': "<(cairo_root)src/", + }, 'target_name': 'cairo', 'type': 'static_library', 'include_dirs': [ - '../static/custom-include/cairo/', + 'custom-include/cairo', '<(cairo_root)', - '<(cairo_src)' , + '<(cairo_src)', '<(freetype_root)include', '<(libpng_root)', + 'custom-include/png', '<(pixman_root)', '<(pixman_root)pixman', '<(zlib_root)', diff --git a/static/ensure_deps.sh b/static/ensure_deps.sh index d471160b2..53489dece 100755 --- a/static/ensure_deps.sh +++ b/static/ensure_deps.sh @@ -1,68 +1,58 @@ #!/usr/bin/env bash +CAIRO_VERSION=1.12.18 +FREETYPE_VERSION=2.6 +GIFLIB_VERSION=4.2.3 +LIBJPEG_VERSION=1.2.1 +LIBPNG_VERSION=1.2.53 +PIXMAN_VERSION=0.32.6 +ZLIB_VERSION=1.2.8 + +CAIRO_URL=http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz +FREETYPE_URL=http://download.savannah.gnu.org/releases/freetype/freetype-$FREETYPE_VERSION.tar.gz +GIFLIB_URL=http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-$GIFLIB_VERSION.tar.gz +LIBJPEG_URL=http://downloads.sourceforge.net/project/libjpeg-turbo/$LIBJPEG_VERSION/libjpeg-turbo-$LIBJPEG_VERSION.tar.gz +LIBPNG_URL=http://sourceforge.net/projects/libpng/files/libpng12/$LIBPNG_VERSION/libpng-$LIBPNG_VERSION.tar.xz +PIXMAN_URL=http://cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz +ZLIB_URL=http://zlib.net/zlib-$ZLIB_VERSION.tar.gz + + DEPS="$(dirname $0)/../deps" mkdir -p $DEPS cd $DEPS -if [ ! -d "cairo-1.12.16" ]; then - if [ ! -f "cairo-1.12.16.tar.xz" ]; then - wget "http://cairographics.org/releases/cairo-1.12.16.tar.xz" > /dev/null 2>&1 +fetch() +{ + if [ ! -d $2 ]; then + mkdir -p $2 && + curl -L $1 | tar xzf - -C $2 --strip-components=1 || exit $? fi - tar -xf "cairo-1.12.16.tar.xz" - mv "cairo-1.12.16/src" "cairo-1.12.16/cairo" -fi +} - -if [ ! -d "pixman-0.30.2" ]; then - if [ ! -f "pixman-0.30.2.tar.gz" ]; then - wget "http://cairographics.org/releases/pixman-0.30.2.tar.gz" > /dev/null 2>&1 +fetch_xz() +{ + if [ ! -d $2 ]; then + mkdir -p $2 && + curl -L $1 | tar xJf - -C $2 --strip-components=1 || exit $? fi - tar -xf "pixman-0.30.2.tar.gz" -fi - +} -if [ ! -d "freetype-2.5.0" ]; then - if [ ! -f "freetype-2.5.0.tar.gz" ]; then - wget "http://download.savannah.gnu.org/releases/freetype/freetype-2.5.0.tar.gz" > /dev/null 2>&1 - fi - tar -xf "freetype-2.5.0.tar.gz" -fi - -if [ ! -d "zlib-1.2.8" ]; then - if [ ! -f "zlib-1.2.8.tar.gz" ]; then - wget "http://zlib.net/zlib-1.2.8.tar.gz" > /dev/null 2>&1 - fi - tar -xf "zlib-1.2.8.tar.gz" -fi -if [ ! -d "libpng-1.2.49" ]; then - if [ ! -f "libpng-1.2.49.tar.gz" ]; then - wget "http://sourceforge.net/projects/libpng/files/libpng12/older-releases/1.2.49/libpng-1.2.49.tar.gz" > /dev/null 2>&1 - fi - tar -xf "libpng-1.2.49.tar.gz" -fi - -if [ ! -d "libjpeg-turbo-1.2.1" ]; then - if [ ! -f "libjpeg-turbo-1.2.1.tar.gz" ]; then - wget "http://downloads.sourceforge.net/project/libjpeg-turbo/1.2.1/libjpeg-turbo-1.2.1.tar.gz" > /dev/null 2>&1 - fi - tar -xf "libjpeg-turbo-1.2.1.tar.gz" -fi - - - -if [ ! -d "giflib-4.2.3" ]; then - if [ ! -f "giflib-4.2.3.tar.gz" ]; then - wget "http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-4.2.3.tar.gz" > /dev/null 2>&1 - fi - tar -xf "giflib-4.2.3.tar.gz" -fi +fetch_xz $CAIRO_URL cairo +fetch $FREETYPE_URL freetype +fetch $GIFLIB_URL giflib +fetch $LIBJPEG_URL libjpeg +fetch_xz $LIBPNG_URL libpng +fetch $PIXMAN_URL pixman +fetch $ZLIB_URL zlib -if [ ! -d "cairo-1.12.16" ] || [ ! -d "pixman-0.30.2" ] || [ ! -d "freetype-2.5.0" ] || [ ! -d "zlib-1.2.8" ] || [ ! -d "libpng-1.2.49" ] || [ ! -d "libjpeg-turbo-1.2.1" ] || [ ! -d "giflib-4.2.3" ]; then - echo false +if [ ! -d "cairo" ] || [ ! -d "freetype" ] || [ ! -d "giflib" ] \ +|| [ ! -d "libjpeg" ] || [ ! -d "libpng" ] || [ ! -d "pixman" ] \ +|| [ ! -d "zlib" ]; then + echo false else - echo true + echo true fi diff --git a/static/locations.gyp b/static/locations.gyp index 0e6b11261..aa1f98413 100644 --- a/static/locations.gyp +++ b/static/locations.gyp @@ -1,11 +1,11 @@ { 'variables': { - 'cairo_root%': "../deps/cairo-1.12.16/", - 'freetype_root%': "../deps/freetype-2.5.0/", - 'gif_root%': "../deps/giflib-4.2.3/", - 'jpeg_root%': "../deps/libjpeg-turbo-1.2.1/", - 'libpng_root%': "../deps/libpng-1.2.49/", - 'pixman_root%': "../deps/pixman-0.30.2/", - 'zlib_root%': "../deps/zlib-1.2.8/", + 'cairo_root%': "../deps/cairo/", + 'freetype_root%': "../deps/freetype/", + 'gif_root%': "../deps/giflib/", + 'jpeg_root%': "../deps/libjpeg/", + 'libpng_root%': "../deps/libpng/", + 'pixman_root%': "../deps/pixman/", + 'zlib_root%': "../deps/zlib/", } } From 590aa6be81446b1baf871781f4ceacb6baeff53a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Fri, 26 Jun 2015 00:57:02 +0200 Subject: [PATCH 025/183] Fix download of dependencies (silent download) --- static/ensure_deps.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/static/ensure_deps.sh b/static/ensure_deps.sh index 53489dece..e2e9986b6 100755 --- a/static/ensure_deps.sh +++ b/static/ensure_deps.sh @@ -26,27 +26,27 @@ cd $DEPS fetch() { if [ ! -d $2 ]; then - mkdir -p $2 && - curl -L $1 | tar xzf - -C $2 --strip-components=1 || exit $? + mkdir -p $2 && + curl -s -L $1 | tar xzf - -C $2 --strip-components=1 || exit $? fi } fetch_xz() { if [ ! -d $2 ]; then - mkdir -p $2 && - curl -L $1 | tar xJf - -C $2 --strip-components=1 || exit $? + mkdir -p $2 && + curl -s -L $1 | tar xJf - -C $2 --strip-components=1 || exit $? fi } -fetch_xz $CAIRO_URL cairo -fetch $FREETYPE_URL freetype -fetch $GIFLIB_URL giflib -fetch $LIBJPEG_URL libjpeg -fetch_xz $LIBPNG_URL libpng -fetch $PIXMAN_URL pixman -fetch $ZLIB_URL zlib +fetch_xz $CAIRO_URL cairo && +fetch $FREETYPE_URL freetype && +fetch $GIFLIB_URL giflib && +fetch $LIBJPEG_URL libjpeg && +fetch_xz $LIBPNG_URL libpng && +fetch $PIXMAN_URL pixman && +fetch $ZLIB_URL zlib || exit $? if [ ! -d "cairo" ] || [ ! -d "freetype" ] || [ ! -d "giflib" ] \ From 2eaef664222906b78823f4506d7ea2c56c420606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Fri, 26 Jun 2015 01:43:25 +0200 Subject: [PATCH 026/183] Move cairo/src to cairo/cairo so includes could work correctly --- static.gyp | 2 +- static/cairo.gyp | 2 +- static/ensure_deps.sh | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/static.gyp b/static.gyp index 6ed5ee525..ffa5193d6 100644 --- a/static.gyp +++ b/static.gyp @@ -12,7 +12,7 @@ './deps/<(jpeg_root)', './static/custom-include/jpeg/', './deps/<(cairo_root)', - './deps/<(cairo_root)src', + './deps/<(cairo_root)cairo', './static/custom-include/cairo/', './deps/<(gif_root)/lib/', './deps/<(libpng_root)/', diff --git a/static/cairo.gyp b/static/cairo.gyp index 1eb86aea1..47dc5347d 100644 --- a/static/cairo.gyp +++ b/static/cairo.gyp @@ -6,7 +6,7 @@ 'targets': [ { 'variables': { - 'cairo_src%': "<(cairo_root)src/", + 'cairo_src%': "<(cairo_root)cairo/", }, 'target_name': 'cairo', 'type': 'static_library', diff --git a/static/ensure_deps.sh b/static/ensure_deps.sh index e2e9986b6..3cb2a18d7 100755 --- a/static/ensure_deps.sh +++ b/static/ensure_deps.sh @@ -40,7 +40,11 @@ fetch_xz() } -fetch_xz $CAIRO_URL cairo && +if [ ! -d cairo ]; then + fetch_xz $CAIRO_URL cairo && + mv cairo/src cairo/cairo || exit $? +fi + fetch $FREETYPE_URL freetype && fetch $GIFLIB_URL giflib && fetch $LIBJPEG_URL libjpeg && From a877adf353d209d90b1e29783710f34af4b54067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sun, 28 Jun 2015 14:23:06 +0200 Subject: [PATCH 027/183] Added missing files to compile --- static.gyp | 5 ++-- static/freetype.gyp | 67 ++++++++++++++++++++++----------------------- static/jpeg.gyp | 3 ++ 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/static.gyp b/static.gyp index ffa5193d6..cae248e5a 100644 --- a/static.gyp +++ b/static.gyp @@ -26,9 +26,8 @@ 'static/gif.gyp:gif', ], 'defines': [ 'HAVE_FREETYPE' ,'HAVE_JPEG' ,'HAVE_GIF' ], - 'libraries': [ - '-static' - ], +# 'libraries': ['-static', '-Wl,--no-undefined'], + 'libraries': ['-static'], 'sources': [ 'src/backend/ImageBackend.cc', 'src/backend/FBDevBackend.cc', diff --git a/static/freetype.gyp b/static/freetype.gyp index fda44ce2a..ed176039e 100644 --- a/static/freetype.gyp +++ b/static/freetype.gyp @@ -1,15 +1,11 @@ -{ - +{ 'includes': [ 'common.gyp' , 'locations.gyp'], 'targets': [ { 'target_name': 'freetype', 'type': 'static_library', 'include_dirs': [ '<(freetype_root)include/'], - - 'libraries': [ - - ], + 'defines': [ 'FT2_BUILD_LIBRARY' ], 'sources': [ #"<(freetype_root)src/autofit/afangles.c", @@ -25,24 +21,25 @@ #"<(freetype_root)src/autofit/afpic.c", #"<(freetype_root)src/autofit/afwarp.c", "<(freetype_root)src/autofit/autofit.c", - + #"<(freetype_root)src/base/basepic.c", #"<(freetype_root)src/base/ftadvanc.c", #"<(freetype_root)src/base/ftapi.c", "<(freetype_root)src/base/ftbase.c", #"<(freetype_root)src/base/ftbbox.c", - #"<(freetype_root)src/base/ftbitmap.c", + "<(freetype_root)src/base/ftbitmap.c", #"<(freetype_root)src/base/ftcalc.c", #"<(freetype_root)src/base/ftcid.c", #"<(freetype_root)src/base/ftdbgmem.c", #"<(freetype_root)src/base/ftdebug.c", + "<(freetype_root)src/base/ftfntfmt.c", #"<(freetype_root)src/base/ftfstype.c", #"<(freetype_root)src/base/ftgasp.c", #"<(freetype_root)src/base/ftgloadr.c", #"<(freetype_root)src/base/ftglyph.c", #"<(freetype_root)src/base/ftgxval.c", - #"<(freetype_root)src/base/ftinit.c", - #"<(freetype_root)src/base/ftlcdfil.c", + "<(freetype_root)src/base/ftinit.c", + "<(freetype_root)src/base/ftlcdfil.c", #"<(freetype_root)src/base/ftmac.c", #"<(freetype_root)src/base/ftmm.c", #"<(freetype_root)src/base/ftobjs.c", @@ -55,21 +52,21 @@ #"<(freetype_root)src/base/ftsnames.c", #"<(freetype_root)src/base/ftstream.c", #"<(freetype_root)src/base/ftstroke.c", - #"<(freetype_root)src/base/ftsynth.c", - #"<(freetype_root)src/base/ftsystem.c", + "<(freetype_root)src/base/ftsynth.c", + "<(freetype_root)src/base/ftsystem.c", #"<(freetype_root)src/base/fttrigon.c", #"<(freetype_root)src/base/fttype1.c", #"<(freetype_root)src/base/ftutil.c", #"<(freetype_root)src/base/ftwinfnt.c", #"<(freetype_root)src/base/ftxf86.c", #"<(freetype_root)src/base/md5.c", - + "<(freetype_root)src/bdf/bdf.c", #"<(freetype_root)src/bdf/bdfdrivr.c", #"<(freetype_root)src/bdf/bdflib.c", - + "<(freetype_root)src/bzip2/ftbzip2.c", - + "<(freetype_root)src/cache/ftcache.c", #"<(freetype_root)src/cache/ftcbasic.c", #"<(freetype_root)src/cache/ftccache.c", @@ -79,7 +76,7 @@ #"<(freetype_root)src/cache/ftcmanag.c", #"<(freetype_root)src/cache/ftcmru.c", #"<(freetype_root)src/cache/ftcsbits.c", - + #"<(freetype_root)src/cff/cf2arrst.c", #"<(freetype_root)src/cff/cf2blues.c", #"<(freetype_root)src/cff/cf2error.c", @@ -97,14 +94,14 @@ #"<(freetype_root)src/cff/cffobjs.c", #"<(freetype_root)src/cff/cffparse.c", #"<(freetype_root)src/cff/cffpic.c", - + #"<(freetype_root)src/cid/cidgload.c", #"<(freetype_root)src/cid/cidload.c", #"<(freetype_root)src/cid/cidobjs.c", #"<(freetype_root)src/cid/cidparse.c", #"<(freetype_root)src/cid/cidriver.c", "<(freetype_root)src/cid/type1cid.c", - + "<(freetype_root)src/gxvalid/gxvalid.c", #"<(freetype_root)src/gxvalid/gxvbsln.c", #"<(freetype_root)src/gxvalid/gxvcommn.c", @@ -129,7 +126,7 @@ #"<(freetype_root)src/gxvalid/gxvopbd.c", #"<(freetype_root)src/gxvalid/gxvprop.c", #"<(freetype_root)src/gxvalid/gxvtrak.c", - + #"<(freetype_root)src/gzip/adler32.c", "<(freetype_root)src/gzip/ftgzip.c", #"<(freetype_root)src/gzip/infblock.c", @@ -138,10 +135,10 @@ #"<(freetype_root)src/gzip/inftrees.c", #"<(freetype_root)src/gzip/infutil.c", #"<(freetype_root)src/gzip/zutil.c", - + "<(freetype_root)src/lzw/ftlzw.c", #"<(freetype_root)src/lzw/ftzopen.c", - + "<(freetype_root)src/otvalid/otvalid.c", #"<(freetype_root)src/otvalid/otvbase.c", #"<(freetype_root)src/otvalid/otvcommn.c", @@ -151,12 +148,12 @@ #"<(freetype_root)src/otvalid/otvjstf.c", #"<(freetype_root)src/otvalid/otvmath.c", #"<(freetype_root)src/otvalid/otvmod.c", - + "<(freetype_root)src/pcf/pcf.c", #"<(freetype_root)src/pcf/pcfdrivr.c", #"<(freetype_root)src/pcf/pcfread.c", #"<(freetype_root)src/pcf/pcfutil.c", - + "<(freetype_root)src/pfr/pfr.c", #"<(freetype_root)src/pfr/pfrcmap.c", #"<(freetype_root)src/pfr/pfrdrivr.c", @@ -164,7 +161,7 @@ #"<(freetype_root)src/pfr/pfrload.c", #"<(freetype_root)src/pfr/pfrobjs.c", #"<(freetype_root)src/pfr/pfrsbit.c", - + #"<(freetype_root)src/psaux/afmparse.c", "<(freetype_root)src/psaux/psaux.c", #"<(freetype_root)src/psaux/psauxmod.c", @@ -172,23 +169,23 @@ #"<(freetype_root)src/psaux/psobjs.c", #"<(freetype_root)src/psaux/t1cmap.c", #"<(freetype_root)src/psaux/t1decode.c", - + #"<(freetype_root)src/pshinter/pshalgo.c", #"<(freetype_root)src/pshinter/pshglob.c", "<(freetype_root)src/pshinter/pshinter.c", #"<(freetype_root)src/pshinter/pshmod.c", #"<(freetype_root)src/pshinter/pshpic.c", #"<(freetype_root)src/pshinter/pshrec.c", - + #"<(freetype_root)src/psnames/psmodule.c", "<(freetype_root)src/psnames/psnames.c", #"<(freetype_root)src/psnames/pspic.c", - + #"<(freetype_root)src/raster/ftraster.c", #"<(freetype_root)src/raster/ftrend1.c", "<(freetype_root)src/raster/raster.c", #"<(freetype_root)src/raster/rastpic.c", - + #"<(freetype_root)src/sfnt/pngshim.c", #"<(freetype_root)src/sfnt/sfdriver.c", "<(freetype_root)src/sfnt/sfnt.c", @@ -201,18 +198,18 @@ #"<(freetype_root)src/sfnt/ttmtx.c", #"<(freetype_root)src/sfnt/ttpost.c", #"<(freetype_root)src/sfnt/ttsbit.c", - + #"<(freetype_root)src/smooth/ftgrays.c", #"<(freetype_root)src/smooth/ftsmooth.c", #"<(freetype_root)src/smooth/ftspic.c", "<(freetype_root)src/smooth/smooth.c", - + "<(freetype_root)src/tools/apinames.c", "<(freetype_root)src/tools/ftrandom/ftrandom.c", "<(freetype_root)src/tools/test_afm.c", "<(freetype_root)src/tools/test_bbox.c", "<(freetype_root)src/tools/test_trig.c", - + "<(freetype_root)src/truetype/truetype.c", #"<(freetype_root)src/truetype/ttdriver.c", #"<(freetype_root)src/truetype/ttgload.c", @@ -222,7 +219,7 @@ #"<(freetype_root)src/truetype/ttpic.c", #"<(freetype_root)src/truetype/ttpload.c", #"<(freetype_root)src/truetype/ttsubpix.c", - + #"<(freetype_root)src/type1/t1afm.c", #"<(freetype_root)src/type1/t1driver.c", #"<(freetype_root)src/type1/t1gload.c", @@ -230,14 +227,14 @@ #"<(freetype_root)src/type1/t1objs.c", #"<(freetype_root)src/type1/t1parse.c", "<(freetype_root)src/type1/type1.c", - + #"<(freetype_root)src/type42/t42drivr.c", #"<(freetype_root)src/type42/t42objs.c", #"<(freetype_root)src/type42/t42parse.c", "<(freetype_root)src/type42/type42.c", - + "<(freetype_root)src/winfonts/winfnt.c", ], }, ] -} +} diff --git a/static/jpeg.gyp b/static/jpeg.gyp index 4724bbc51..bd235245e 100644 --- a/static/jpeg.gyp +++ b/static/jpeg.gyp @@ -23,8 +23,10 @@ "<(jpeg_root)jsimd_none.c", + "<(jpeg_root)jaricom.c", "<(jpeg_root)jcapimin.c", "<(jpeg_root)jcapistd.c", + "<(jpeg_root)jcarith.c", "<(jpeg_root)jccoefct.c", "<(jpeg_root)jccolor.c", "<(jpeg_root)jcdctmgr.c", @@ -43,6 +45,7 @@ #"<(jpeg_root)jctrans.c", "<(jpeg_root)jdapimin.c", "<(jpeg_root)jdapistd.c", + "<(jpeg_root)jdarith.c", "<(jpeg_root)jdatadst.c", "<(jpeg_root)jdatasrc.c", "<(jpeg_root)jdcoefct.c", From e8de74d74e12af3293ecfe3fe64bc4b45955737f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sun, 28 Jun 2015 19:53:57 +0200 Subject: [PATCH 028/183] Implemented virtual destructor for Backend & move function definitions --- src/backend/Backend.cc | 58 ++++++++++++++++++++++++++++++++++++++++++ src/backend/Backend.h | 28 ++++++++------------ static.gyp | 2 +- 3 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 src/backend/Backend.cc diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc new file mode 100644 index 000000000..b457f08d1 --- /dev/null +++ b/src/backend/Backend.cc @@ -0,0 +1,58 @@ +#include "Backend.h" + + +Backend::~Backend(){} + + +string Backend::getName() +{ + return name; +} + +int Backend::getWidth() +{ + return this->width; +} +void Backend::setWidth(int width) +{ + this->width = width; + + this->recreateSurface(); +} + +int Backend::getHeight() +{ + return this->height; +} +void Backend::setHeight(int height) +{ + this->height = height; + + this->recreateSurface(); +} + +cairo_surface_t* Backend::getSurface() +{ + return surface; +} + + +BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend, + string operation_name) +{ + this->backend = backend; + this->operation_name = operation_name; +}; + +BackendOperationNotAvailable::~BackendOperationNotAvailable() throw() {}; + + +const char* BackendOperationNotAvailable::what() const throw() +{ + std::ostringstream o; + + o << "operation " << this->operation_name; + o << " not supported by backend " + backend->getName(); + + return o.str().c_str(); +}; diff --git a/src/backend/Backend.h b/src/backend/Backend.h index d6dfede1a..3becd3a2b 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -30,33 +30,27 @@ class Backend virtual cairo_surface_t *recreateSurface() = 0; virtual void destroySurface() = 0; - string getName() { return name; }; + string getName(); - int getWidth() { return this->width; }; - void setWidth(int width) { this->width = width; this->recreateSurface(); }; + int getWidth(); + void setWidth(int width); - int getHeight() { return this->width; }; - void setHeight(int height) { this->height = height; this->recreateSurface(); }; + int getHeight(); + void setHeight(int height); - cairo_surface_t *getSurface() { return surface; }; + cairo_surface_t* getSurface(); }; class BackendOperationNotAvailable : public exception { private: - Backend *backend; + Backend* backend; string operation_name; public: - BackendOperationNotAvailable(Backend *backend, string operation_name) { - this->backend = backend; - this->operation_name = operation_name; - }; - ~BackendOperationNotAvailable() throw() {}; - const char *what() const throw() { - std::ostringstream o; - o << "operation " << this->operation_name << " not supported by backend " + backend->getName(); - return o.str().c_str(); - }; + BackendOperationNotAvailable(Backend* backend, string operation_name); + ~BackendOperationNotAvailable() throw(); + + const char* what() const throw(); }; #endif diff --git a/static.gyp b/static.gyp index cae248e5a..930bf1a8b 100644 --- a/static.gyp +++ b/static.gyp @@ -26,9 +26,9 @@ 'static/gif.gyp:gif', ], 'defines': [ 'HAVE_FREETYPE' ,'HAVE_JPEG' ,'HAVE_GIF' ], -# 'libraries': ['-static', '-Wl,--no-undefined'], 'libraries': ['-static'], 'sources': [ + 'src/backend/Backend.cc', 'src/backend/ImageBackend.cc', 'src/backend/FBDevBackend.cc', 'src/Canvas.cc', From 1c26ac217f0591076a21c0c1c9e0efc7cbf65f6f Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Mon, 29 Jun 2015 17:20:52 +0200 Subject: [PATCH 029/183] removed install packages script --- install_packages.sh | 1 - 1 file changed, 1 deletion(-) delete mode 100644 install_packages.sh diff --git a/install_packages.sh b/install_packages.sh deleted file mode 100644 index 3698da63f..000000000 --- a/install_packages.sh +++ /dev/null @@ -1 +0,0 @@ -sudo apt-get install libcairo-dev libjpeg-dev libgif-dev libghc-pango-dev From 9227b9e27ce765e0fee40e432d412b3f97eda7eb Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Mon, 29 Jun 2015 17:21:05 +0200 Subject: [PATCH 030/183] fixed Backend.cc not being compiled --- shared.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/shared.gyp b/shared.gyp index 7053f907a..5132a167d 100644 --- a/shared.gyp +++ b/shared.gyp @@ -42,6 +42,7 @@ 'target_name': 'canvas', 'include_dirs': [" Date: Mon, 29 Jun 2015 17:21:48 +0200 Subject: [PATCH 031/183] removed main.cc and Makefile --- src/backend/Makefile | 8 -------- src/backend/main.cc | 29 ----------------------------- 2 files changed, 37 deletions(-) delete mode 100644 src/backend/Makefile delete mode 100644 src/backend/main.cc diff --git a/src/backend/Makefile b/src/backend/Makefile deleted file mode 100644 index 6126f78bc..000000000 --- a/src/backend/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -all: - g++ FBDevBackend.cc ImageBackend.cc main.cc -lcairo -o backendtest - -run: all - ./backendtest - -clean: - rm -Rf backendtest diff --git a/src/backend/main.cc b/src/backend/main.cc deleted file mode 100644 index b3b9356f5..000000000 --- a/src/backend/main.cc +++ /dev/null @@ -1,29 +0,0 @@ -#include "FBDevBackend.h" -#include "ImageBackend.h" - -#include - -void printBackendInfo(Backend *backend) { - cout << "Name: " << backend->getName() - << ", Surface Pointer: " << backend->getSurface() - << ", Size: " << backend->getWidth() << "x" << backend->getHeight() << endl; -} - -int main() { - Backend *backend = NULL; - - backend = new FBDevBackend("/dev/fb0"); - backend->createSurface(); - try { - backend->recreateSurface(); - } catch (BackendOperationNotAvailable bona) { - cerr << bona.what() << endl; - } - printBackendInfo(backend); - delete backend; - - backend = new ImageBackend(1920, 1080); - backend->createSurface(); - printBackendInfo(backend); - delete backend; -} From 131ca13c04853be7e6ba9b1c2b08aee1bf0deb37 Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Mon, 29 Jun 2015 17:23:20 +0200 Subject: [PATCH 032/183] removed binary executable --- src/backend/backendtest | Bin 29256 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 src/backend/backendtest diff --git a/src/backend/backendtest b/src/backend/backendtest deleted file mode 100755 index c75c3986fd355482b3fd152a876ad14e6ff28085..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 29256 zcmcJ23w%`7)$g7p1L2VnCnGOCKuj*URUl4H2lp*4vxvS4&%~`Lx;@p%ovssTa-nUu*AuX3xnS zwD*2@^UJKg{(J4U*IsA8&N=&RZY-}{m*H{=9Wumc1aZOBybQ@-A#T5#S%sB~Y~dC2 z#2I1&5I6q3oI+H_G#yl`HO*FXnV?w|&rm>yS4I>)LvkoV25lixDlZwlDk|v*iq%vI z52sT;vQ?BZ3mTLWMf2DgAx0*ubd`_HqkM%bU!juMG>-%jG}ZMZb@X?JNyW44IK8bqNehhc8Fv(&1eWdiJ4Frj!344)`?K;z?uASq^v$EY#m+KwmA9BD~JJ{LiP~UkD@-I2b zJJf5AgFRIa{@mkG?$ZwC_BfQ=?cg_`L%Eka$nST+?{>iNgZ~953UO`zmnjvu%!7i!$|bxkB{V@c#upGsF~e;?t?}b5*^(s@!~~?FE+4 z74H?L%D)Bu)PFs*Q}JflL;mz$8boT+pGC^fVVgYy^JQJAsXZd6$UtC6OQbc>5e>CR z0|61ZtShi7yrZcj8gBPBhdMgK9U@RsvmsC)ZdY*4248ceHCz*_Z4S${v?*LhprfP!=Y$6&=6@4)Q6&>Q^=%EBJI~U z)khmuD)h93qNs3tQ@zw`rfPdTkgKyJtcrxoI->P;OO}w&N<<*g7Hx!8^?_@`I|I@_ zfOXxWKtp>t90+&Uh1;S{kya7dwsC!R$N6#sA^YYD?6I53tLhsA#yEJ zs-tbq6?N6oqN2LSPp3xY+7Gkg3GvV zV|B;cB2tD}w6rPG5vUDygjZIyHbpJG!&ih%b;v@xAX>AfI=b32O=<~MlMKfr%^iqK zogKiD5v>CSP#c#hP_(WQ7i~v( zcc3lY-VtdHH8(|f2D%El)`qLr7AseGl!V&a!mah>vld8IM_1NGI-@L4?rTD<^;((I z+yR^Im$iHouoX%FvFB<6<<;j00Olh%Pf0UqW zPc2Db+iGqB>o!$KssrTo>L}{q*f!JDL|Lr7WVO?yMv%a~i zi-y-0IZPn7qYho4xFQkQ+P!o_Q^k)%h01<&O508OBE&2wJ=YU%4#ic%9U`0WpxU{lj zjW1AKP+V}n@NL~%wx%LbRImb;B^fERbt~lQwg&e+@?R$3Atm_?@RWinhN=9;gv>l~ zS&U~v!p(7cuSF7+kA5d`j5JGW+)Al`lkAU$dui(y8@!&ssTjHk)IqOr2xn)i1iii?{Cq78s^@RQ*BH27_YkgbsX0}zdk9}; z$OnBv=Ez1=*9wikAjb(O59`q83v!fjx}G|8`+^)LTwenMdVE15d@oF8>u|d-$WfA4 zE@OVTFUXW|`qSZlUy!4O;X+wqk1xn^!Y6Y~{_OPyIYKxtoE7%@f*dD&D#zr{(@9UyvgtU&b-{ z6ZZu0z?T~M5d&Xl;KK%9VBkj$e7S*-7v4M{o_zDB}_a4vo z_qofLd4&I#!Kgd_MI`!r4`&~eLSyG&fTXd77vXo>JTGFz(_OqsjEo^HEGC|Y#>6o5 z=MkSl{2=r5iKn43v5)z=#M2O%*u(q`;%Vqh>}Gy4@igQmdYI23ej@R0%zv;HJmwOS z2r~Z;@igQms+fP1_{qe3nSYgd8sZX#%>RM-slHaX8t_lX$VOSGC!Yq z8afjDn4e2L4H=0&%+Da6hKj^)<|h+RLqwv7`3&OECBBXM50-$ZE}jT7{|@ogwG&m$ zze)Ug#Cw^4m3ZpPi9+W8K>SkTJWYaG z=6^ywb-~0i^FJV-x?W2Ivy>5np@z#lu|e>#4N-}Q|DHy=emZE2gLwN0Bxdbs?ai=Qs= z2+=uxGcv|o;ehSWxE}@NdiM~G2M6-Y$goR9r~BAfkk3-~Hf0za-k!J)c_?0up=ORh zc0=4B>m2d-m4gn&uRzD*_>gE@;g!+eK@TPUMK_CP@~5&`yWu)oTK#1Vh& z8Gr0|@dmWiW6S-qLn;F+_yXL04E2>DGM7$9VX>p6XCX3Rl$&$q_CsV_SxvS7rsIPc z#r(0Kmr`2aEliXxT_|>d#x&&R8pdZrD0WbZ#j5gEtk0X@J32P)mT!`5|1H!52WYII zGH=3F)q4B4dUSHBsv6ff_A*J%hUEiSDEu2J`vB>P7Xqg0^q24P_kWdi`(rPX{3`Ma zq2!HM;s-IhNp>jSjHD-z=X=FK;Yu&ecqM)rX;IbduUe|2FnmC)6GGRo{)4eGs>!{B zy9TH2N>`nqn0k`c2`aN+g95*-j-R}ztMe=1vN|EMnya%fwK|QIwZD9ys?NI@yd^sn ze-KHj)%hZ6k=5z*E;TMmo`n_~=u8V;n?!fhos3TCA*OdUFS-UlH%{yw&5mw7R@*x| zCwhACsHbzQk{jwNgdBy$pYW4{QbJ`+-WjgUv%3{M$kkg)|bpp&fKwx~3E1)|W z6y+xsAv<%9z3o#;yG{2UQSMtiYPs+Ghz=Z6_);*^eFs^B+&7%+zGwfz?i*I_tHIiX zh0qZ{LQ<;xULq~Jx9uLL>gmRsKagQ`xOd1M{GzL+UK`A zTvB!)^&BOju47qjlm@a~wlI0ctL9i@UPQl2WAYQl3ox2d1ECxzDTi`OpLb581ga}y zhy6Sn4#itgvtyYAVC3^awlemboD<~WOe&tG+RJGn7j=`lG58F{mz%j?1(POsUo!VF z^vm4nT0`--|8A81aQfUElDY4(a-(Gp#sAIB-H<-_v}EoYEB6TH?lg1fr_cQx$f$bH zLT>*}hiL-5vh1qloY;HZgBkm1tn)t(%%L9nC}*J-^cIzJ7nR??`7Q7x1B+<>1~`{w z`pSjL>tq-QJI=FrH%A-d8BMwzo*xdo{_V+WP_qWo_>g!`=gkr`r1=5X0V&-nH4= zPr1?bz5}Z4{Q-=y*(;rUIm=qkEjEq4SQ-0s6ks!UkzwqYC|S8`2Gpe*TLr{0_Hw(i zBa|D)j)E#hYmf}3p z`(xu1ZsU4xQa(A-RzBpU}0nq+*>Xkb1)3Uxhn*lH#@D5>gNLS?L9; zLq102=_BcwxVgS9Idid|+ufzG~ z0-W=mK)#d(_+81WK8y^gYCaa=e069AE}K}~!HS2p6|iU>6lw2X#PR_D^DPutKn*1549#Z1eCywwkwZr2g9{#rwDBX>I4IC26(i0`J) zWer&vpye>N0Scsga&;;6qepk*!frl-I`akoEw94iZtm@v-;o9JBjn6GDITM7J??iA zL2e#(!Ys5InKs}?fZ$(~{J=5F%euAXQ}BkqR=|ehPqI#q-bkLJ+`WfO)t!2>MaZ$r z{?y=lXE{~<=bN#ryY4XbGwqYL+t~bVmDAXh!H-|>lSm&Q( z7$8+sxsm#vw6XAfYdp;!c$`-{L-9jz%Jja?e~$4`8pr4wtD2c&+pV2ny2ra7LjmF&bKjIMAN+MoulRe)XT$D0GUT~Ip(MmwpC5+x50_A@{=ZX zFX|g3Eh-B$qTw8%H<|ITq5wJcqfhb} z_b!luKT*qqm0e&eV}GM)AK`B+{PSSe#@-;jBM$rng|7oHZxyd1m^NRL%q7$&dAb^k zuYibbiwc+zK()ockQ`0kWmlDLH}4j_{-N?X-2A> zO^jePb{h;cYN<2!-Vhhj*-6Q4Q}Td^mWv;89S=QOif1(gJ+!2QN%S<1O|r@uUo^`2 zh#v2qvJ7rqiDM{;r^{F3%l|@`P2Z5p3O@x*-J!}_Uq&8~V?acj2Y>7%=N`tLPyC0; zr|5<7hZAb@tl2iQ1*CU`pbm}Mtij!mdj!+xa3$a zm(HB)2e0dnMC}KcEruGYOY<#wRt@UY=JlXqh_cU>#m36ERK(sd+guU*ZCOoa|H8&; z9z4SDU)BR!UAg%6qCfhd{xB21%#L6DXDGPkuhFyg^Zv@%o0YNm*FwkG%$NMVhg|;E z$2#9c8QE8Er`}rj`LY0B5m@gB-aUjyPVWHKD?i#LLc!A-iF!IZ+u9=S*f-{>-RY?f z)m?)PFdo`G(;lMzcplMETOaOX`MOXm<)Do}UKOZGy~SED-hcZcD`5 z!*cgxwcMr&WZeE$RUJ`YE0WPXQ7u9 zZddeSbsa_&{rpmyo|+r}R`qyErO#R><(%>t6<5$MT~)cHHtnCSN}sk%OAN0Ia&(VM zUuDzq$@=L=bjS-lVyQ>9Oixv$sTJKwV%R5(NViyy&bqvzwvY}6k0eZVz zh<%`YL7yQU`u+$y2g6S`?qarrc7yhSehYLD=yRZhp!K+gi-X2N^RRl##SM2M=ykZU z-wOH?Xb)%*k5l%7-U@mI^k<+aKwk%)gL3b{^D8gtC@AefI15kQj)2|^dIEG9G;e|s z8!^olg6;&}4Z0t6ALw(SRiG0vS+;@Fv+_bL8Wv#fwiom=+*u5R-UfOC^a0`__bBn8 z^nN1``17Da(Bq)A=xD>6pFBK+9|7G8N!i(z7V;2>vHE@Hf_qa**)TtxfhtX-e+ zS~|*mGcy{JdY(i23CJx1wPZrc^y7fvM>@U4x6&JBI+bw;{<6>(zee<4TRHtnxt}6E z3b|b*x7U!n^p4Eltc-4wq-!EkOEQ zwCP&Jvs{;?)_-f#u1d(&K#uLoGvsV`y$88{kaM!@UZm5Lof0Z9-_Y{~Sr%Zf-$m$K zhardQE9uYrq&+V|PXWe)2aue#+R#JS?VhAu7W6y>xtVCwSsM*G=?C{jh>{mpADLt{*@IlB?G4H3-?fVL8 zKc%llI^FeLj=0sXGAdbs?D;dw`31(T?;)P$Gs+=9Jec&uROnd?e>RicW}94Xvb>){ z?skXkNA~;&(qBWpE=Jt4hg+q*Zto#oz}|HImF&G2>GXuC3-PS5&5q`z9T#O`tb*Ky zkh99^N~T|h^v99@B{Mx^Ckv3B*CTxv#^xnvy3wB>KzbDE7ntdtN&P=V`khEm*N#d5 zOGu}Oy-t2OiS&<|NQRY>29blT))`DcT)e<>g; z|2>pHig;GH;pd9}%saAr-5GC6S;|iK{0RE4hCbd;s@q|Wlv#lEN~G5#{RYId?lSaI zJL^cwMIlFir8h!Z4;XUXk22?GK$Po0L5OzDkxu@*2i5xA4{p{@l{ui5qgg&AFvzxrJr9`D=1LYjWp6eobyR z&u0%qPY?9K+>|gj=9)Usyx{CAPUkqR#~YVJvgHD|?}PLuPA^5H|`z zzM(Ldd9iEN0{1U7T%U12l95^Mz9l2Geg507%x}6V`aRd_K%aHFzn+nK)I}11agp!~ z8Cner%f7%}CboQBIXSNE+3vGk=gN#^$@M?5y!4dj1M?hvAHDkPqzpWAZq^9%av&BYH)o^hf3PM6r|zCqAe zjXzWsaX?GmeJ-)yeH}J{p;su`+@)Yj{WrVB*Az1K9Cbm1vW%&7K`(G`=8q8Qx{bL$ zwI0y6YhG}P=O|NL<;>pfzDj%n0IqF?>yqVeyq&$+eJ}%s{v<ozf;E6Q^pMJbim%^7O3*g{hKQ-#4OlanRo{@)$u#S&;G5`Bw;! zqO|dof=8uOf2W|9k>c+kjYWtLW_aBc;4oX!yy;$!X}mE{^4jjbN^X*(x_mr$;`+p=NqIb? zVP4yT;gI=lDqUs&|4#II5cYx=&60MOD7sG3Es8cM+NJ2Nir%N_cNN{Q=rfAGsOTGt zzOU$n*|NM@iY`*LMA3DMZc(&B(Jn=ARrEeZzpLneMW0dhMMd9G^nFDqV9`%umZFOk zEm3rxqFWSgP_#?YTNS-e(eEm{U(sh2eNoXj6n$UO38$&@6kMvkB*KG}Vg&;u=F8jiR7_XDjqcicefQr3)WX(r2+I z6F^#fxH&`_RIIHzDhl|^wgP+*hd6)VR?r^d58MjEjrhzK&j$jH^~kF^D8PQCd998s|)9^c9^R-%{}jLXU%~_(YLz{K&+ps>hvF`APUfz-vMr z&%_s4dYm&8Gt+#}PU)GL4f0e!PL1~{3SY;cE6sIz9C*5VJgX6>!(ixqfiapg)afC@ZyAmp4aKw;;HPRH@g(HJ-XbO zT9@f^zpBdB>ot41gX(#)F88UADVJVAr7L%vS_kTK536$Z`p{l(c8Qnu=yItZ>FWD7 z5?ttaJ+}Te#`yU5MoQD^nSuqEON{RqX9K4%CGGvOSmE~mTh4mM_s5OEJ!$&a6~Jdu z5w_6nfZq+A&KuGFF<<3-%t8Jc;PcV0zMSu6$yz1vbWYBPO8%vVQl6guQCNnB;SA`Z zuWl$njKjsiN&lgXg3!d&g9D0^Oeh4Z*mnu8g08ghs zCx{m>DfDl2Z4JymiqJW z!1L0KV}~8||B3M&q2J3sqSR$zU?=GbS&!0FTvs+awIus0m!mtp~(PXFZ&_%*;uzkPhTm*sOr!4faKr%O5M zhYot4bHM-VpeHLwmTMnBXDZy@uk(SYtJg&ic&!6|9q@GLs@>=yj|ac(AH5Gj&%ghs zaQk}c1qVF|2i%=2_1ou{1;D8t_Ne)2p7Q^tN`AOdUKj0?5O9jy&w2a4(xdl3=<(`j ztVdY;5R`iHveKh@O;0-DbD@yhkKUi5`&XgD?fr2JaBZ{JO|%_2%@_9mxYI%YD+;%t z7xz=(??*TQfGY)fbeMl;AY0bV7U%m3+pA zlc%ECr6!-#)pxeE>_irW z8)~fs1l8e!ID9LxZDkP-`HEs+UL6zcqhgH_Tsz6}frm_v?f%1)O=>SK*~sqLa@MasTOI{Z&Mj!$b-HmS4La1LFyLtW5bYqmJ0@hNb2Rkrq7s`qvB!Gar4 zy%!OlOR4*|nu=3rfO|gvaL|+!F2`Ms)Ln$?u;LLG0p4uj><5zqZ9UD8p=`dJ2j1*UlTr*DH z`cvy$d2M4TO3t98boHE@dXO$3Zfgv+eAMRp@g>}=+e*# zXPswjzeegPRvXO6o!SnaO|?5v-w_EkV)cMGil#wnx@2-TQA-xvaE)dq=dRRx+B@57 zoDeLx==0UYFzv9X-85(XjD+#soXl($w=Z>8Ti*p>E|Kdjr=yZl?5Uf(u8@P>vIUvv zlwul8ohg(Byh+|#=h;t!{-h_ore055(=XCf{D0eFwyBPmu1u|napLv=!vW9#>Kv42 z;NsRl{uJPG4%6obr&jG_+X4Dxa{V-Zy^H*21Eu-NRsh?VdZxDBw$yfm5@}hV95(={ ziOX2l5hjnd_K3CB2U|;I+>>=+bTr8&UA!6ING77$N@t( zp$^+o>e3ABq~=spoF{fUkz+}E%5}2o!lFWW#9Vm%-yT72_XUmjrZeE#@dvA?ULmL6 zB+qb{E-?=8wmT)Yyid43A&;eA0t}VL>G1mCWn6iE5W20VX-*KgSyoe#Y8v_fUtVOQ zts_tBG1#e=q;sD>zdqS#)bM@En@&2#JXLq<0oO=V=T7rI&L?hcrD$vXrJCxt`kZ-N zS@4c^FG{Cx+mp$k<`V@zKwAl^&Q9lU+YsYOZTs}7JE~rftb(2NkrK@O?+LV{gI)pY z_q!s)3l2d6XGqTaRj-RI{v5>c%14V^`;PSg-{i3*WkkQ9(r^(XX8wyZyqrYeR!~?V ziS=vGzZNO@yeOjW4`z6Q(7sJ3qFEB`WRd}|Yf{2SaCii7**~1&1&8leRQ})uW(5(d zyUwql!)*bESISm?y)UW|?@1`={h*SQI&_@q=kZ5-F}3}A|I{`-=cI7EB$oYJPSb0U zPJ25wulHHSRsJ58pX?_)wfzbf*C9ea)%o>)EIzpv_+BMw_n)r+E|q_clFL*3Q}ghg zkiv+%V3Z%P5Ulcb{yTw@UzMA!{k$jCi@>=^GlNoRK{3S4{CXc)-YhA?-)>pb^lVxN zP45M3=GXfaf@)*KJ=#!PKE;Y}*z)WB$L~?YMo`T_GWfOIzXuqVul=vzSn5 zlbjG99Z{67kC|WZQ_Cxn0<>?)4EFN(Bhk#S_p{x!{CeNpuFuE} zT~@^;Z!iCOz<4FWZIdO+f=u)w<{rsezxMK9MhZ1`YTFd_z8z1QE^A^}am)|K92U-%h(xm#^F3DDs%)dwoG5LU?^lto|aoWdG56XrGsv z-|q{us9)uOoDz+o^JzK(>1KXwKVZ4cr0vuybUw{bMP|aZ|MWhkJe7ZsPEZ-VI-{b~ zRr!TBT<2eH!^u_(n$j?1D}vK2RQYqYAfw5Aie){vCdx^T>!ie9^^)Z*u(X#=*Iy3{ V)W6e}pLd1K->$|%$&D}nzW~*9O0)m~ From 00c48fc932f042ad2d7a0f390e71c0b656048240 Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Sat, 4 Jul 2015 19:38:32 +0200 Subject: [PATCH 033/183] reformatted code --- src/Canvas.cc | 636 ++++++++++++++++++------------------ src/Canvas.h | 2 +- src/backend/Backend.cc | 65 ++-- src/backend/Backend.h | 3 +- src/backend/FBDevBackend.cc | 192 +++++------ src/backend/ImageBackend.cc | 38 +-- 6 files changed, 463 insertions(+), 473 deletions(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index c3cc93baa..993f53f91 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -30,34 +30,34 @@ Persistent Canvas::constructor; void Canvas::Initialize(Handle target) { - NanScope(); - - // Constructor - Local ctor = NanNew(Canvas::New); - NanAssignPersistent(constructor, ctor); - ctor->InstanceTemplate()->SetInternalFieldCount(1); - ctor->SetClassName(NanNew("Canvas")); - - // Prototype - Local proto = ctor->PrototypeTemplate(); - NODE_SET_PROTOTYPE_METHOD(ctor, "toBuffer", ToBuffer); - NODE_SET_PROTOTYPE_METHOD(ctor, "streamPNGSync", StreamPNGSync); + NanScope(); + + // Constructor + Local ctor = NanNew(Canvas::New); + NanAssignPersistent(constructor, ctor); + ctor->InstanceTemplate()->SetInternalFieldCount(1); + ctor->SetClassName(NanNew("Canvas")); + + // Prototype + Local proto = ctor->PrototypeTemplate(); + NODE_SET_PROTOTYPE_METHOD(ctor, "toBuffer", ToBuffer); + NODE_SET_PROTOTYPE_METHOD(ctor, "streamPNGSync", StreamPNGSync); #ifdef HAVE_JPEG - NODE_SET_PROTOTYPE_METHOD(ctor, "streamJPEGSync", StreamJPEGSync); + NODE_SET_PROTOTYPE_METHOD(ctor, "streamJPEGSync", StreamJPEGSync); #endif - proto->SetAccessor(NanNew("type"), GetType); - proto->SetAccessor(NanNew("width"), GetWidth, SetWidth); - proto->SetAccessor(NanNew("height"), GetHeight, SetHeight); - - NanSetTemplate(proto, "PNG_NO_FILTERS", NanNew(PNG_NO_FILTERS)); - NanSetTemplate(proto, "PNG_FILTER_NONE", NanNew(PNG_FILTER_NONE)); - NanSetTemplate(proto, "PNG_FILTER_SUB", NanNew(PNG_FILTER_SUB)); - NanSetTemplate(proto, "PNG_FILTER_UP", NanNew(PNG_FILTER_UP)); - NanSetTemplate(proto, "PNG_FILTER_AVG", NanNew(PNG_FILTER_AVG)); - NanSetTemplate(proto, "PNG_FILTER_PAETH", NanNew(PNG_FILTER_PAETH)); - NanSetTemplate(proto, "PNG_ALL_FILTERS", NanNew(PNG_ALL_FILTERS)); - - target->Set(NanNew("Canvas"), ctor->GetFunction()); + proto->SetAccessor(NanNew("type"), GetType); + proto->SetAccessor(NanNew("width"), GetWidth, SetWidth); + proto->SetAccessor(NanNew("height"), GetHeight, SetHeight); + + NanSetTemplate(proto, "PNG_NO_FILTERS", NanNew(PNG_NO_FILTERS)); + NanSetTemplate(proto, "PNG_FILTER_NONE", NanNew(PNG_FILTER_NONE)); + NanSetTemplate(proto, "PNG_FILTER_SUB", NanNew(PNG_FILTER_SUB)); + NanSetTemplate(proto, "PNG_FILTER_UP", NanNew(PNG_FILTER_UP)); + NanSetTemplate(proto, "PNG_FILTER_AVG", NanNew(PNG_FILTER_AVG)); + NanSetTemplate(proto, "PNG_FILTER_PAETH", NanNew(PNG_FILTER_PAETH)); + NanSetTemplate(proto, "PNG_ALL_FILTERS", NanNew(PNG_ALL_FILTERS)); + + target->Set(NanNew("Canvas"), ctor->GetFunction()); } /* @@ -65,34 +65,34 @@ Canvas::Initialize(Handle target) { */ NAN_METHOD(Canvas::New) { - NanScope(); - Backend *backend = NULL; - int width = 0; - int height = 0; - if (args[0]->IsNumber()) width = args[0]->Uint32Value(); - if (args[1]->IsNumber()) height = args[1]->Uint32Value(); - if (args[2]->IsString()) { - v8::String::Utf8Value param2(args[2]->ToString()); - string type = std::string(*param2); - if (type == "image") { - backend = new ImageBackend(width, height); - } else if (type == "fbdev") { - string deviceName = "/dev/fb0"; - if (args[3]->IsString()) { - v8::String::Utf8Value param3(args[3]->ToString()); - deviceName = std::string(*param3); - } - backend = new FBDevBackend(deviceName); - } else { - backend = new ImageBackend(width, height); - } - } else { - backend = new ImageBackend(width, height); - } - - Canvas *canvas = new Canvas(backend); - canvas->Wrap(args.This()); - NanReturnValue(args.This()); + NanScope(); + Backend *backend = NULL; + int width = 0; + int height = 0; + if (args[0]->IsNumber()) width = args[0]->Uint32Value(); + if (args[1]->IsNumber()) height = args[1]->Uint32Value(); + if (args[2]->IsString()) { + v8::String::Utf8Value param2(args[2]->ToString()); + string type = std::string(*param2); + if (type == "image") { + backend = new ImageBackend(width, height); + } else if (type == "fbdev") { + string deviceName = "/dev/fb0"; + if (args[3]->IsString()) { + v8::String::Utf8Value param3(args[3]->ToString()); + deviceName = std::string(*param3); + } + backend = new FBDevBackend(deviceName); + } else { + backend = new ImageBackend(width, height); + } + } else { + backend = new ImageBackend(width, height); + } + + Canvas *canvas = new Canvas(backend); + canvas->Wrap(args.This()); + NanReturnValue(args.This()); } /* @@ -100,9 +100,9 @@ NAN_METHOD(Canvas::New) { */ NAN_GETTER(Canvas::GetType) { - NanScope(); - Canvas *canvas = ObjectWrap::Unwrap(args.This()); - NanReturnValue(NanNew(canvas->backend()->getName())); + NanScope(); + Canvas *canvas = ObjectWrap::Unwrap(args.This()); + NanReturnValue(NanNew(canvas->backend()->getName())); } /* @@ -110,9 +110,9 @@ NAN_GETTER(Canvas::GetType) { */ NAN_GETTER(Canvas::GetWidth) { - NanScope(); - Canvas *canvas = ObjectWrap::Unwrap(args.This()); - NanReturnValue(NanNew(canvas->getWidth())); + NanScope(); + Canvas *canvas = ObjectWrap::Unwrap(args.This()); + NanReturnValue(NanNew(canvas->getWidth())); } /* @@ -120,11 +120,11 @@ NAN_GETTER(Canvas::GetWidth) { */ NAN_SETTER(Canvas::SetWidth) { - NanScope(); - if (value->IsNumber()) { - Canvas *canvas = ObjectWrap::Unwrap(args.This()); - canvas->backend()->setWidth(value->Uint32Value()); - } + NanScope(); + if (value->IsNumber()) { + Canvas *canvas = ObjectWrap::Unwrap(args.This()); + canvas->backend()->setWidth(value->Uint32Value()); + } } /* @@ -132,9 +132,9 @@ NAN_SETTER(Canvas::SetWidth) { */ NAN_GETTER(Canvas::GetHeight) { - NanScope(); - Canvas *canvas = ObjectWrap::Unwrap(args.This()); - NanReturnValue(NanNew(canvas->getHeight())); + NanScope(); + Canvas *canvas = ObjectWrap::Unwrap(args.This()); + NanReturnValue(NanNew(canvas->getHeight())); } /* @@ -142,11 +142,11 @@ NAN_GETTER(Canvas::GetHeight) { */ NAN_SETTER(Canvas::SetHeight) { - NanScope(); - if (value->IsNumber()) { - Canvas *canvas = ObjectWrap::Unwrap(args.This()); - canvas->backend()->setHeight(value->Uint32Value()); - } + NanScope(); + if (value->IsNumber()) { + Canvas *canvas = ObjectWrap::Unwrap(args.This()); + canvas->backend()->setHeight(value->Uint32Value()); + } } /* @@ -155,26 +155,26 @@ NAN_SETTER(Canvas::SetHeight) { static cairo_status_t toBuffer(void *c, const uint8_t *data, unsigned len) { - closure_t *closure = (closure_t *) c; + closure_t *closure = (closure_t *) c; - if (closure->len + len > closure->max_len) { - uint8_t *data; - unsigned max = closure->max_len; + if (closure->len + len > closure->max_len) { + uint8_t *data; + unsigned max = closure->max_len; - do { - max *= 2; - } while (closure->len + len > max); + do { + max *= 2; + } while (closure->len + len > max); - data = (uint8_t *) realloc(closure->data, max); - if (!data) return CAIRO_STATUS_NO_MEMORY; - closure->data = data; - closure->max_len = max; - } + data = (uint8_t *) realloc(closure->data, max); + if (!data) return CAIRO_STATUS_NO_MEMORY; + closure->data = data; + closure->max_len = max; + } - memcpy(closure->data + closure->len, data, len); - closure->len += len; + memcpy(closure->data + closure->len, data, len); + closure->len += len; - return CAIRO_STATUS_SUCCESS; + return CAIRO_STATUS_SUCCESS; } /* @@ -183,12 +183,12 @@ toBuffer(void *c, const uint8_t *data, unsigned len) { void Canvas::ToBufferAsync(uv_work_t *req) { - closure_t *closure = (closure_t *) req->data; + closure_t *closure = (closure_t *) req->data; - closure->status = canvas_write_to_png_stream( - closure->canvas->surface() - , toBuffer - , closure); + closure->status = canvas_write_to_png_stream( + closure->canvas->surface() + , toBuffer + , closure); } /* @@ -197,24 +197,24 @@ Canvas::ToBufferAsync(uv_work_t *req) { void Canvas::ToBufferAsyncAfter(uv_work_t *req) { - NanScope(); - closure_t *closure = (closure_t *) req->data; - delete req; - - if (closure->status) { - Local argv[1] = { Canvas::Error(closure->status) }; - closure->pfn->Call(1, argv); - } else { - Local buf = NanNewBufferHandle((char*)closure->data, closure->len); - memcpy(Buffer::Data(buf), closure->data, closure->len); - Local argv[2] = { NanNew(NanNull()), buf }; - closure->pfn->Call(2, argv); - } - - closure->canvas->Unref(); - delete closure->pfn; - closure_destroy(closure); - free(closure); + NanScope(); + closure_t *closure = (closure_t *) req->data; + delete req; + + if (closure->status) { + Local argv[1] = { Canvas::Error(closure->status) }; + closure->pfn->Call(1, argv); + } else { + Local buf = NanNewBufferHandle((char*)closure->data, closure->len); + memcpy(Buffer::Data(buf), closure->data, closure->len); + Local argv[2] = { NanNew(NanNull()), buf }; + closure->pfn->Call(2, argv); + } + + closure->canvas->Unref(); + delete closure->pfn; + closure_destroy(closure); + free(closure); } /* @@ -223,97 +223,97 @@ Canvas::ToBufferAsyncAfter(uv_work_t *req) { */ NAN_METHOD(Canvas::ToBuffer) { - NanScope(); - cairo_status_t status; - uint32_t compression_level = 6; - uint32_t filter = PNG_ALL_FILTERS; - Canvas *canvas = ObjectWrap::Unwrap(args.This()); - - if (args.Length() > 1 && !(args[1]->StrictEquals(NanUndefined()) && args[2]->StrictEquals(NanUndefined()))) { - if (!args[1]->StrictEquals(NanUndefined())) { - bool good = true; - if (args[1]->IsNumber()) { - compression_level = args[1]->Uint32Value(); - } else if (args[1]->IsString()) { - if (args[1]->StrictEquals(NanNew("0"))) { - compression_level = 0; - } else { - uint32_t tmp = args[1]->Uint32Value(); - if (tmp == 0) { - good = false; - } else { - compression_level = tmp; - } - } - } else { - good = false; - } - - if (good) { - if (compression_level > 9) { - return NanThrowRangeError("Allowed compression levels lie in the range [0, 9]."); - } - } else { - return NanThrowTypeError("Compression level must be a number."); - } - } - - if (!args[2]->StrictEquals(NanUndefined())) { - if (args[2]->IsUint32()) { - filter = args[2]->Uint32Value(); - } else { - return NanThrowTypeError("Invalid filter value."); - } - } - } - - // Async - if (args[0]->IsFunction()) { - closure_t *closure = (closure_t *) malloc(sizeof(closure_t)); - status = closure_init(closure, canvas, compression_level, filter); - - // ensure closure is ok - if (status) { - closure_destroy(closure); - free(closure); - return NanThrowError(Canvas::Error(status)); - } - - // TODO: only one callback fn in closure - canvas->Ref(); - closure->pfn = new NanCallback(args[0].As()); - - uv_work_t* req = new uv_work_t; - req->data = closure; - uv_queue_work(uv_default_loop(), req, ToBufferAsync, (uv_after_work_cb)ToBufferAsyncAfter); - - NanReturnUndefined(); - // Sync - } else { - closure_t closure; - status = closure_init(&closure, canvas, compression_level, filter); - - // ensure closure is ok - if (status) { - closure_destroy(&closure); - return NanThrowError(Canvas::Error(status)); - } - - TryCatch try_catch; - status = canvas_write_to_png_stream(canvas->surface(), toBuffer, &closure); - - if (try_catch.HasCaught()) { - closure_destroy(&closure); - NanReturnValue(try_catch.ReThrow()); - } else if (status) { - closure_destroy(&closure); - return NanThrowError(Canvas::Error(status)); - } else { - Local buf = NanNewBufferHandle((char *)closure.data, closure.len); - closure_destroy(&closure); - NanReturnValue(buf); - } - } + NanScope(); + cairo_status_t status; + uint32_t compression_level = 6; + uint32_t filter = PNG_ALL_FILTERS; + Canvas *canvas = ObjectWrap::Unwrap(args.This()); + + if (args.Length() > 1 && !(args[1]->StrictEquals(NanUndefined()) && args[2]->StrictEquals(NanUndefined()))) { + if (!args[1]->StrictEquals(NanUndefined())) { + bool good = true; + if (args[1]->IsNumber()) { + compression_level = args[1]->Uint32Value(); + } else if (args[1]->IsString()) { + if (args[1]->StrictEquals(NanNew("0"))) { + compression_level = 0; + } else { + uint32_t tmp = args[1]->Uint32Value(); + if (tmp == 0) { + good = false; + } else { + compression_level = tmp; + } + } + } else { + good = false; + } + + if (good) { + if (compression_level > 9) { + return NanThrowRangeError("Allowed compression levels lie in the range [0, 9]."); + } + } else { + return NanThrowTypeError("Compression level must be a number."); + } + } + + if (!args[2]->StrictEquals(NanUndefined())) { + if (args[2]->IsUint32()) { + filter = args[2]->Uint32Value(); + } else { + return NanThrowTypeError("Invalid filter value."); + } + } + } + + // Async + if (args[0]->IsFunction()) { + closure_t *closure = (closure_t *) malloc(sizeof(closure_t)); + status = closure_init(closure, canvas, compression_level, filter); + + // ensure closure is ok + if (status) { + closure_destroy(closure); + free(closure); + return NanThrowError(Canvas::Error(status)); + } + + // TODO: only one callback fn in closure + canvas->Ref(); + closure->pfn = new NanCallback(args[0].As()); + + uv_work_t* req = new uv_work_t; + req->data = closure; + uv_queue_work(uv_default_loop(), req, ToBufferAsync, (uv_after_work_cb)ToBufferAsyncAfter); + + NanReturnUndefined(); + // Sync + } else { + closure_t closure; + status = closure_init(&closure, canvas, compression_level, filter); + + // ensure closure is ok + if (status) { + closure_destroy(&closure); + return NanThrowError(Canvas::Error(status)); + } + + TryCatch try_catch; + status = canvas_write_to_png_stream(canvas->surface(), toBuffer, &closure); + + if (try_catch.HasCaught()) { + closure_destroy(&closure); + NanReturnValue(try_catch.ReThrow()); + } else if (status) { + closure_destroy(&closure); + return NanThrowError(Canvas::Error(status)); + } else { + Local buf = NanNewBufferHandle((char *)closure.data, closure.len); + closure_destroy(&closure); + NanReturnValue(buf); + } + } } /* @@ -322,15 +322,16 @@ NAN_METHOD(Canvas::ToBuffer) { static cairo_status_t streamPNG(void *c, const uint8_t *data, unsigned len) { - NanScope(); - closure_t *closure = (closure_t *) c; - Local buf = NanNewBufferHandle((char *)data, len); - Local argv[3] = { - NanNew(NanNull()) - , buf - , NanNew(len) }; - NanMakeCallback(NanGetCurrentContext()->Global(), closure->fn, 3, argv); - return CAIRO_STATUS_SUCCESS; + NanScope(); + closure_t *closure = (closure_t *) c; + Local buf = NanNewBufferHandle((char *)data, len); + Local argv[3] = { + NanNew(NanNull()) + , buf + , NanNew(len) + }; + NanMakeCallback(NanGetCurrentContext()->Global(), closure->fn, 3, argv); + return CAIRO_STATUS_SUCCESS; } /* @@ -338,75 +339,76 @@ streamPNG(void *c, const uint8_t *data, unsigned len) { */ NAN_METHOD(Canvas::StreamPNGSync) { - NanScope(); - uint32_t compression_level = 6; - uint32_t filter = PNG_ALL_FILTERS; - // TODO: async as well - if (!args[0]->IsFunction()) - return NanThrowTypeError("callback function required"); - - if (args.Length() > 1 && !(args[1]->StrictEquals(NanUndefined()) && args[2]->StrictEquals(NanUndefined()))) { - if (!args[1]->StrictEquals(NanUndefined())) { - bool good = true; - if (args[1]->IsNumber()) { - compression_level = args[1]->Uint32Value(); - } else if (args[1]->IsString()) { - if (args[1]->StrictEquals(NanNew("0"))) { - compression_level = 0; - } else { - uint32_t tmp = args[1]->Uint32Value(); - if (tmp == 0) { - good = false; - } else { - compression_level = tmp; - } - } - } else { - good = false; - } - - if (good) { - if (compression_level > 9) { - return NanThrowRangeError("Allowed compression levels lie in the range [0, 9]."); - } - } else { - return NanThrowTypeError("Compression level must be a number."); - } - } - - if (!args[2]->StrictEquals(NanUndefined())) { - if (args[2]->IsUint32()) { - filter = args[2]->Uint32Value(); - } else { - return NanThrowTypeError("Invalid filter value."); - } - } - } - - - Canvas *canvas = ObjectWrap::Unwrap(args.This()); - closure_t closure; - closure.fn = Handle::Cast(args[0]); - closure.compression_level = compression_level; - closure.filter = filter; - - TryCatch try_catch; - - cairo_status_t status = canvas_write_to_png_stream(canvas->surface(), streamPNG, &closure); - - if (try_catch.HasCaught()) { - NanReturnValue(try_catch.ReThrow()); - } else if (status) { - Local argv[1] = { Canvas::Error(status) }; - NanMakeCallback(NanGetCurrentContext()->Global(), closure.fn, 1, argv); - } else { - Local argv[3] = { - NanNew(NanNull()) - , NanNew(NanNull()) - , NanNew(0) }; - NanMakeCallback(NanGetCurrentContext()->Global(), closure.fn, 1, argv); - } - NanReturnUndefined(); + NanScope(); + uint32_t compression_level = 6; + uint32_t filter = PNG_ALL_FILTERS; + // TODO: async as well + if (!args[0]->IsFunction()) + return NanThrowTypeError("callback function required"); + + if (args.Length() > 1 && !(args[1]->StrictEquals(NanUndefined()) && args[2]->StrictEquals(NanUndefined()))) { + if (!args[1]->StrictEquals(NanUndefined())) { + bool good = true; + if (args[1]->IsNumber()) { + compression_level = args[1]->Uint32Value(); + } else if (args[1]->IsString()) { + if (args[1]->StrictEquals(NanNew("0"))) { + compression_level = 0; + } else { + uint32_t tmp = args[1]->Uint32Value(); + if (tmp == 0) { + good = false; + } else { + compression_level = tmp; + } + } + } else { + good = false; + } + + if (good) { + if (compression_level > 9) { + return NanThrowRangeError("Allowed compression levels lie in the range [0, 9]."); + } + } else { + return NanThrowTypeError("Compression level must be a number."); + } + } + + if (!args[2]->StrictEquals(NanUndefined())) { + if (args[2]->IsUint32()) { + filter = args[2]->Uint32Value(); + } else { + return NanThrowTypeError("Invalid filter value."); + } + } + } + + + Canvas *canvas = ObjectWrap::Unwrap(args.This()); + closure_t closure; + closure.fn = Handle::Cast(args[0]); + closure.compression_level = compression_level; + closure.filter = filter; + + TryCatch try_catch; + + cairo_status_t status = canvas_write_to_png_stream(canvas->surface(), streamPNG, &closure); + + if (try_catch.HasCaught()) { + NanReturnValue(try_catch.ReThrow()); + } else if (status) { + Local argv[1] = { Canvas::Error(status) }; + NanMakeCallback(NanGetCurrentContext()->Global(), closure.fn, 1, argv); + } else { + Local argv[3] = { + NanNew(NanNull()) + , NanNew(NanNull()) + , NanNew(0) + }; + NanMakeCallback(NanGetCurrentContext()->Global(), closure.fn, 1, argv); + } + NanReturnUndefined(); } /* @@ -416,27 +418,27 @@ NAN_METHOD(Canvas::StreamPNGSync) { #ifdef HAVE_JPEG NAN_METHOD(Canvas::StreamJPEGSync) { - NanScope(); - // TODO: async as well - if (!args[0]->IsNumber()) - return NanThrowTypeError("buffer size required"); - if (!args[1]->IsNumber()) - return NanThrowTypeError("quality setting required"); - if (!args[2]->IsBoolean()) - return NanThrowTypeError("progressive setting required"); - if (!args[3]->IsFunction()) - return NanThrowTypeError("callback function required"); - - Canvas *canvas = ObjectWrap::Unwrap(args.This()); - closure_t closure; - closure.fn = Handle::Cast(args[3]); - - TryCatch try_catch; - write_to_jpeg_stream(canvas->surface(), args[0]->NumberValue(), args[1]->NumberValue(), args[2]->BooleanValue(), &closure); - - if (try_catch.HasCaught()) - NanReturnValue(try_catch.ReThrow()); - NanReturnUndefined(); + NanScope(); + // TODO: async as well + if (!args[0]->IsNumber()) + return NanThrowTypeError("buffer size required"); + if (!args[1]->IsNumber()) + return NanThrowTypeError("quality setting required"); + if (!args[2]->IsBoolean()) + return NanThrowTypeError("progressive setting required"); + if (!args[3]->IsFunction()) + return NanThrowTypeError("callback function required"); + + Canvas *canvas = ObjectWrap::Unwrap(args.This()); + closure_t closure; + closure.fn = Handle::Cast(args[3]); + + TryCatch try_catch; + write_to_jpeg_stream(canvas->surface(), args[0]->NumberValue(), args[1]->NumberValue(), args[2]->BooleanValue(), &closure); + + if (try_catch.HasCaught()) + NanReturnValue(try_catch.ReThrow()); + NanReturnUndefined(); } #endif @@ -445,9 +447,9 @@ NAN_METHOD(Canvas::StreamJPEGSync) { * Initialize cairo surface. */ -Canvas::Canvas(Backend* backend): ObjectWrap() { - _backend = backend; - this->backend()->createSurface(); +Canvas::Canvas(Backend* backend) : ObjectWrap() { + _backend = backend; + this->backend()->createSurface(); } /* @@ -455,7 +457,7 @@ Canvas::Canvas(Backend* backend): ObjectWrap() { */ Canvas::~Canvas() { - delete _backend; + delete _backend; } /* @@ -464,17 +466,17 @@ Canvas::~Canvas() { void Canvas::resurface(Handle canvas) { - NanScope(); - Handle context; - - backend()->recreateSurface(); - context = canvas->Get(NanNew("context")); - if (!context->IsUndefined()) { - Context2d *context2d = ObjectWrap::Unwrap(context->ToObject()); - cairo_t *prev = context2d->context(); - context2d->setContext(cairo_create(surface())); - cairo_destroy(prev); - } + NanScope(); + Handle context; + + backend()->recreateSurface(); + context = canvas->Get(NanNew("context")); + if (!context->IsUndefined()) { + Context2d *context2d = ObjectWrap::Unwrap(context->ToObject()); + cairo_t *prev = context2d->context(); + context2d->setContext(cairo_create(surface())); + cairo_destroy(prev); + } } /* @@ -483,5 +485,5 @@ Canvas::resurface(Handle canvas) { Local Canvas::Error(cairo_status_t status) { - return Exception::Error(NanNew(cairo_status_to_string(status))); + return Exception::Error(NanNew(cairo_status_to_string(status))); } diff --git a/src/Canvas.h b/src/Canvas.h index d3a46fdbd..0d76d51ad 100644 --- a/src/Canvas.h +++ b/src/Canvas.h @@ -53,7 +53,7 @@ class Canvas: public node::ObjectWrap { static NAN_METHOD(StreamPNGSync); static NAN_METHOD(StreamJPEGSync); static Local Error(cairo_status_t status); - + static void ToBufferAsync(uv_work_t *req); static void ToBufferAsyncAfter(uv_work_t *req); diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index b457f08d1..ce52a1066 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -1,58 +1,45 @@ #include "Backend.h" - -Backend::~Backend(){} - - -string Backend::getName() -{ - return name; +Backend::~Backend() { } -int Backend::getWidth() -{ - return this->width; +string Backend::getName() { + return name; } -void Backend::setWidth(int width) -{ - this->width = width; - this->recreateSurface(); +int Backend::getWidth() { + return this->width; } - -int Backend::getHeight() -{ - return this->height; +void Backend::setWidth(int width) { + this->width = width; + this->recreateSurface(); } -void Backend::setHeight(int height) -{ - this->height = height; - this->recreateSurface(); +int Backend::getHeight() { + return this->height; } - -cairo_surface_t* Backend::getSurface() -{ - return surface; +void Backend::setHeight(int height) { + this->height = height; + this->recreateSurface(); } +cairo_surface_t* Backend::getSurface() { + return surface; +} -BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend, - string operation_name) -{ - this->backend = backend; - this->operation_name = operation_name; +BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend, string operation_name) { + this->backend = backend; + this->operation_name = operation_name; }; -BackendOperationNotAvailable::~BackendOperationNotAvailable() throw() {}; - +BackendOperationNotAvailable::~BackendOperationNotAvailable() throw() { +}; -const char* BackendOperationNotAvailable::what() const throw() -{ - std::ostringstream o; +const char* BackendOperationNotAvailable::what() const throw() { + std::ostringstream o; - o << "operation " << this->operation_name; - o << " not supported by backend " + backend->getName(); + o << "operation " << this->operation_name; + o << " not supported by backend " + backend->getName(); - return o.str().c_str(); + return o.str().c_str(); }; diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 3becd3a2b..39ce8fb6b 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -14,8 +14,7 @@ using namespace std; -class Backend -{ +class Backend { protected: string name; diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index f576d9bf9..71d77ab2b 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -10,118 +10,120 @@ #include "FBDevBackend.h" FBDevBackend::FBDevBackend(string deviceName) { - this->name = "fbdev"; - this->fb_dn = deviceName; + this->name = "fbdev"; + this->fb_dn = deviceName; } cairo_surface_t * FBDevBackend::createSurface() { - // Open the file for reading and writing - this->fb_fd = open(this->fb_dn.c_str(), O_RDWR); - if (this->fb_fd == -1) { - std::ostringstream o; - o << "cannot open framebuffer device \"" << this->fb_dn << "\""; - throw FBDevBackendException(o.str()); - } - - // Get variable screen information - if (ioctl(this->fb_fd, FBIOGET_VSCREENINFO, &this->fb_vinfo) == -1) { - std::ostringstream o; - o << "error reading variable information from device \"" << this->fb_dn << "\""; - throw FBDevBackendException(o.str()); - } - - // set width, height and bpp according to the size of the fb device - this->width = this->fb_vinfo.xres; - this->height = this->fb_vinfo.yres; - this->bpp = this->fb_vinfo.bits_per_pixel; - - // switch through bpp and decide on which format for the cairo surface to use - switch (this->bpp) { - case 32: - this->format = CAIRO_FORMAT_ARGB32; - break; - case 24: - this->format = CAIRO_FORMAT_RGB24; - break; - case 16: - this->format = CAIRO_FORMAT_RGB16_565; - break; - case 8: - this->format = CAIRO_FORMAT_A8; - break; - default: - std::ostringstream o; - o << "could not determine color format of device \"" << this->fb_dn << "\""; - throw FBDevBackendException(o.str()); - } - - // Figure out the size of the screen in bytes - this->fb_screensize = this->width * this->height * this->bpp / 8; - - // Map the device to memory - this->fb_data = (unsigned char *) mmap( - 0, - this->fb_screensize, - PROT_READ | PROT_WRITE, - MAP_SHARED, - this->fb_fd, - 0 - ); - if (this->fb_data == MAP_FAILED) { - std::ostringstream o; - o << "failed to map framebuffer device \"" << this->fb_dn << "\" to memory"; - throw FBDevBackendException(o.str()); - } - - // Get fixed screen information - if (ioctl(this->fb_fd, FBIOGET_FSCREENINFO, &this->fb_finfo) == -1) { - std::ostringstream o; - o << "error reading fixed information from device \"" << this->fb_dn << "\""; - throw FBDevBackendException(o.str()); - } - - // TODO decide image format by bpp of fb device - this->surface = cairo_image_surface_create_for_data( - this->fb_data, - this->format, - this->width, - this->height, - cairo_format_stride_for_width(this->format, this->width) - ); - - // set destroy callback - cairo_surface_set_user_data( - this->surface, - NULL, - this, - &cairo_linuxfb_surface_destroy - ); - - return this->surface; + // Open the file for reading and writing + this->fb_fd = open(this->fb_dn.c_str(), O_RDWR); + if (this->fb_fd == -1) { + std::ostringstream o; + o << "cannot open framebuffer device \"" << this->fb_dn << "\""; + throw FBDevBackendException(o.str()); + } + + // Get variable screen information + if (ioctl(this->fb_fd, FBIOGET_VSCREENINFO, &this->fb_vinfo) == -1) { + std::ostringstream o; + o << "error reading variable information from device \"" << this->fb_dn << "\""; + throw FBDevBackendException(o.str()); + } + + // set width, height and bpp according to the size of the fb device + this->width = this->fb_vinfo.xres; + this->height = this->fb_vinfo.yres; + this->bpp = this->fb_vinfo.bits_per_pixel; + + // switch through bpp and decide on which format for the cairo surface to use + switch (this->bpp) { + case 32: + this->format = CAIRO_FORMAT_ARGB32; + break; + case 24: + this->format = CAIRO_FORMAT_RGB24; + break; + case 16: + this->format = CAIRO_FORMAT_RGB16_565; + break; + case 8: + this->format = CAIRO_FORMAT_A8; + break; + default: + std::ostringstream o; + o << "could not determine color format of device \"" << this->fb_dn << "\""; + throw FBDevBackendException(o.str()); + } + + // Figure out the size of the screen in bytes + this->fb_screensize = this->width * this->height * this->bpp / 8; + + // Map the device to memory + this->fb_data = (unsigned char *) mmap( + 0, + this->fb_screensize, + PROT_READ | PROT_WRITE, + MAP_SHARED, + this->fb_fd, + 0 + ); + + if (this->fb_data == MAP_FAILED) { + std::ostringstream o; + o << "failed to map framebuffer device \"" << this->fb_dn << "\" to memory"; + throw FBDevBackendException(o.str()); + } + + // Get fixed screen information + if (ioctl(this->fb_fd, FBIOGET_FSCREENINFO, &this->fb_finfo) == -1) { + std::ostringstream o; + o << "error reading fixed information from device \"" << this->fb_dn << "\""; + throw FBDevBackendException(o.str()); + } + + // TODO decide image format by bpp of fb device + this->surface = cairo_image_surface_create_for_data( + this->fb_data, + this->format, + this->width, + this->height, + cairo_format_stride_for_width(this->format, this->width) + ); + + // set destroy callback + cairo_surface_set_user_data( + this->surface, + NULL, + this, + &cairo_linuxfb_surface_destroy + ); + + return this->surface; } void FBDevBackend::setWidth(int width) { - throw BackendOperationNotAvailable(this, "setWidth()"); + throw BackendOperationNotAvailable(this, "setWidth()"); } void FBDevBackend::setHeight(int height) { - throw BackendOperationNotAvailable(this, "setHeight()"); + throw BackendOperationNotAvailable(this, "setHeight()"); } cairo_surface_t *FBDevBackend::recreateSurface() { - throw BackendOperationNotAvailable(this, "recreateSurface()"); + throw BackendOperationNotAvailable(this, "recreateSurface()"); } void FBDevBackend::destroySurface() { - cairo_surface_destroy(this->surface); + cairo_surface_destroy(this->surface); } void cairo_linuxfb_surface_destroy(void *device) { - FBDevBackend *backend = (FBDevBackend *) device; + FBDevBackend *backend = (FBDevBackend *) device; - if (backend == NULL) { - return; - } - munmap(backend->fb_data, backend->fb_screensize); - close(backend->fb_fd); + if (backend == NULL) { + return; + } + + munmap(backend->fb_data, backend->fb_screensize); + close(backend->fb_fd); } diff --git a/src/backend/ImageBackend.cc b/src/backend/ImageBackend.cc index 6530f9dc9..83aca2ce6 100644 --- a/src/backend/ImageBackend.cc +++ b/src/backend/ImageBackend.cc @@ -1,33 +1,33 @@ #include "ImageBackend.h" ImageBackend::ImageBackend(int width, int height) { - this->name = "image"; + this->name = "image"; - this->width = width; - this->height = height; + this->width = width; + this->height = height; } cairo_surface_t *ImageBackend::createSurface() { - this->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, this->width, this->height); - //NanAdjustExternalMemory(4 * this->width * this->height); - return this->surface; + this->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, this->width, this->height); + //NanAdjustExternalMemory(4 * this->width * this->height); + return this->surface; } cairo_surface_t *ImageBackend::recreateSurface() { - if (this->surface != NULL) { - //int old_width = cairo_image_surface_get_width(this->surface); - //int old_height = cairo_image_surface_get_height(this->surface); - cairo_surface_destroy(this->surface); - //NanAdjustExternalMemory(-4 * old_width * old_height); - } - this->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); - //NanAdjustExternalMemory(4 * (width * height - old_width * old_height)); - return this->surface; + if (this->surface != NULL) { + //int old_width = cairo_image_surface_get_width(this->surface); + //int old_height = cairo_image_surface_get_height(this->surface); + cairo_surface_destroy(this->surface); + //NanAdjustExternalMemory(-4 * old_width * old_height); + } + this->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); + //NanAdjustExternalMemory(4 * (width * height - old_width * old_height)); + return this->surface; } void ImageBackend::destroySurface() { - if (this->surface != NULL) { - cairo_surface_destroy(this->surface); - //NanAdjustExternalMemory(-4 * this->width * this->height); - } + if (this->surface != NULL) { + cairo_surface_destroy(this->surface); + //NanAdjustExternalMemory(-4 * this->width * this->height); + } } From fce293e89629380f7471beed970ede9349d2d5ae Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Sat, 4 Jul 2015 20:41:16 +0200 Subject: [PATCH 034/183] first work on better backend system --- examples/backends.js | 6 ++++++ lib/canvas.js | 3 +++ shared.gyp | 1 + src/Backends.cc | 10 ++++++++++ src/Backends.h | 25 +++++++++++++++++++++++++ src/backend/Backend.cc | 2 ++ src/init.cc | 4 +++- static.gyp | 1 + 8 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 examples/backends.js create mode 100644 src/Backends.cc create mode 100644 src/Backends.h diff --git a/examples/backends.js b/examples/backends.js new file mode 100644 index 000000000..339386771 --- /dev/null +++ b/examples/backends.js @@ -0,0 +1,6 @@ +var Canvas = require('..') + , canvas = new Canvas(320, 320) + , ctx = canvas.getContext('2d'); + +console.log(Canvas); +console.log(Canvas.Backends); diff --git a/lib/canvas.js b/lib/canvas.js index 5615521c6..8ac465df7 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -10,6 +10,7 @@ */ var canvas = require('./bindings') + , Backends = canvas.Backends , Canvas = canvas.Canvas , Image = canvas.Image , cairoVersion = canvas.cairoVersion @@ -27,6 +28,8 @@ var canvas = require('./bindings') var Canvas = exports = module.exports = Canvas; +exports.Backends = Backends; + /** * Library version. */ diff --git a/shared.gyp b/shared.gyp index 5132a167d..0d15caa50 100644 --- a/shared.gyp +++ b/shared.gyp @@ -45,6 +45,7 @@ 'src/backend/Backend.cc', 'src/backend/ImageBackend.cc', 'src/backend/FBDevBackend.cc', + 'src/Backends.cc', 'src/Canvas.cc', 'src/CanvasGradient.cc', 'src/CanvasPattern.cc', diff --git a/src/Backends.cc b/src/Backends.cc new file mode 100644 index 000000000..9c82352c6 --- /dev/null +++ b/src/Backends.cc @@ -0,0 +1,10 @@ +#include "Backends.h" + +void Backends::Initialize(Handle target) { + NanScope(); + + Local obj = NanNew(); + obj->Set(NanNew("Image"), NanNew("imagebackend")); + + target->Set(NanNew("Backends"), obj); +} diff --git a/src/Backends.h b/src/Backends.h new file mode 100644 index 000000000..1830f8ac9 --- /dev/null +++ b/src/Backends.h @@ -0,0 +1,25 @@ +#ifndef __NODE_BACKENDS_H__ +#define __NODE_BACKENDS_H__ + +#include +#include +#include +#include +#include + +#include "backend/Backend.h" + +using namespace v8; +using namespace node; + +using v8::FunctionTemplate; +using v8::Handle; +using v8::Object; +using v8::String; + +class Backends : public ObjectWrap { + public: + static void Initialize(Handle target); +}; + +#endif diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index ce52a1066..7e98bc0e2 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -10,6 +10,7 @@ string Backend::getName() { int Backend::getWidth() { return this->width; } + void Backend::setWidth(int width) { this->width = width; this->recreateSurface(); @@ -18,6 +19,7 @@ void Backend::setWidth(int width) { int Backend::getHeight() { return this->height; } + void Backend::setHeight(int height) { this->height = height; this->recreateSurface(); diff --git a/src/init.cc b/src/init.cc index 6628cee4c..d8b8f67a9 100755 --- a/src/init.cc +++ b/src/init.cc @@ -6,6 +6,7 @@ // #include +#include "Backends.h" #include "Canvas.h" #include "Image.h" #include "ImageData.h" @@ -21,6 +22,7 @@ extern "C" void init (Handle target) { NanScope(); + Backends::Initialize(target); Canvas::Initialize(target); Image::Initialize(target); ImageData::Initialize(target); @@ -71,4 +73,4 @@ init (Handle target) { #endif } -NODE_MODULE(canvas,init); +NODE_MODULE(canvas, init); diff --git a/static.gyp b/static.gyp index 930bf1a8b..8c37bec07 100644 --- a/static.gyp +++ b/static.gyp @@ -31,6 +31,7 @@ 'src/backend/Backend.cc', 'src/backend/ImageBackend.cc', 'src/backend/FBDevBackend.cc', + 'src/Backends.cc', 'src/Canvas.cc', 'src/CanvasGradient.cc', 'src/CanvasPattern.cc', From a99c3183c7dba68bcf8a6517ee89470c03c8e0ea Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Sun, 5 Jul 2015 12:48:19 +0200 Subject: [PATCH 035/183] instantiate backends in javascript --- examples/backends.js | 3 +++ src/Backends.cc | 6 +++++- src/Backends.h | 5 ----- src/backend/Backend.h | 15 ++++++++------- src/backend/FBDevBackend.cc | 26 ++++++++++++++++++++++++++ src/backend/FBDevBackend.h | 4 ++++ src/backend/ImageBackend.cc | 23 +++++++++++++++++++++++ src/backend/ImageBackend.h | 4 ++++ 8 files changed, 73 insertions(+), 13 deletions(-) diff --git a/examples/backends.js b/examples/backends.js index 339386771..3c8e78463 100644 --- a/examples/backends.js +++ b/examples/backends.js @@ -4,3 +4,6 @@ var Canvas = require('..') console.log(Canvas); console.log(Canvas.Backends); + +var imagebackend = new Canvas.Backends.ImageBackend(800, 600); +var fbdevbackend = new Canvas.Backends.FBDevBackend("/dev/fb1"); diff --git a/src/Backends.cc b/src/Backends.cc index 9c82352c6..2c1795a85 100644 --- a/src/Backends.cc +++ b/src/Backends.cc @@ -1,10 +1,14 @@ #include "Backends.h" +#include "backend/ImageBackend.h" +#include "backend/FBDevBackend.h" + void Backends::Initialize(Handle target) { NanScope(); Local obj = NanNew(); - obj->Set(NanNew("Image"), NanNew("imagebackend")); + ImageBackend::Initialize(obj); + FBDevBackend::Initialize(obj); target->Set(NanNew("Backends"), obj); } diff --git a/src/Backends.h b/src/Backends.h index 1830f8ac9..99af93d01 100644 --- a/src/Backends.h +++ b/src/Backends.h @@ -12,11 +12,6 @@ using namespace v8; using namespace node; -using v8::FunctionTemplate; -using v8::Handle; -using v8::Object; -using v8::String; - class Backends : public ObjectWrap { public: static void Initialize(Handle target); diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 39ce8fb6b..bad596ce4 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -5,16 +5,22 @@ #include #include #include - +#include +#include +#include +#include +#include #if HAVE_PANGO #include #else #include #endif +using namespace v8; +using namespace node; using namespace std; -class Backend { +class Backend : public ObjectWrap { protected: string name; @@ -24,19 +30,14 @@ class Backend { public: virtual ~Backend() = 0; - virtual cairo_surface_t *createSurface() = 0; virtual cairo_surface_t *recreateSurface() = 0; virtual void destroySurface() = 0; - string getName(); - int getWidth(); void setWidth(int width); - int getHeight(); void setHeight(int height); - cairo_surface_t* getSurface(); }; diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 71d77ab2b..5663eb06d 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -127,3 +127,29 @@ void cairo_linuxfb_surface_destroy(void *device) { munmap(backend->fb_data, backend->fb_screensize); close(backend->fb_fd); } + +Persistent FBDevBackend::constructor; + +void FBDevBackend::Initialize(Handle target) { + NanScope(); + Local ctor = NanNew(FBDevBackend::New); + NanAssignPersistent(FBDevBackend::constructor, ctor); + ctor->InstanceTemplate()->SetInternalFieldCount(1); + ctor->SetClassName(NanNew("FBDevBackend")); + Local proto = ctor->PrototypeTemplate(); + target->Set(NanNew("FBDevBackend"), ctor->GetFunction()); +} + +NAN_METHOD(FBDevBackend::New) { + FBDevBackend *backend = NULL; + + if (args[0]->IsString()) { + string fbDevice = *String::Utf8Value(args[0].As()); + backend = new FBDevBackend(fbDevice); + } else { + backend = new FBDevBackend("/dev/fb0"); + } + + backend->Wrap(args.This()); + NanReturnValue(args.This()); +} diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 73cdb2d66..b048bfd1d 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -29,6 +29,10 @@ class FBDevBackend : public Backend { FBDevBackend(string deviceName); ~FBDevBackend() { this->destroySurface(); } + + static Persistent constructor; + static void Initialize(Handle target); + static NAN_METHOD(New); }; void cairo_linuxfb_surface_destroy(void *device); diff --git a/src/backend/ImageBackend.cc b/src/backend/ImageBackend.cc index 83aca2ce6..d2677e31d 100644 --- a/src/backend/ImageBackend.cc +++ b/src/backend/ImageBackend.cc @@ -31,3 +31,26 @@ void ImageBackend::destroySurface() { //NanAdjustExternalMemory(-4 * this->width * this->height); } } + +Persistent ImageBackend::constructor; + +void ImageBackend::Initialize(Handle target) { + NanScope(); + Local ctor = NanNew(ImageBackend::New); + NanAssignPersistent(ImageBackend::constructor, ctor); + ctor->InstanceTemplate()->SetInternalFieldCount(1); + ctor->SetClassName(NanNew("ImageBackend")); + Local proto = ctor->PrototypeTemplate(); + target->Set(NanNew("ImageBackend"), ctor->GetFunction()); +} + +NAN_METHOD(ImageBackend::New) { + int width = 0; + int height = 0; + if (args[0]->IsNumber()) width = args[0]->Uint32Value(); + if (args[1]->IsNumber()) height = args[1]->Uint32Value(); + + ImageBackend *backend = new ImageBackend(width, height); + backend->Wrap(args.This()); + NanReturnValue(args.This()); +} diff --git a/src/backend/ImageBackend.h b/src/backend/ImageBackend.h index 25d003a9e..66d9a9d4d 100644 --- a/src/backend/ImageBackend.h +++ b/src/backend/ImageBackend.h @@ -16,6 +16,10 @@ class ImageBackend : public Backend { ImageBackend(int width, int height); ~ImageBackend() { this->destroySurface(); } + + static Persistent constructor; + static void Initialize(Handle target); + static NAN_METHOD(New); }; #endif From f480bf7f66cd156ae47e2bd55271f735ba6553a2 Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Sun, 5 Jul 2015 13:01:40 +0200 Subject: [PATCH 036/183] canvas now accepts backends fbdevice can now be set fixes #2 closes #3 --- examples/backends.js | 19 +++++++++++++------ examples/simple_fbdev.js | 5 +++-- src/Canvas.cc | 31 +++++++------------------------ 3 files changed, 23 insertions(+), 32 deletions(-) diff --git a/examples/backends.js b/examples/backends.js index 3c8e78463..97adc65c8 100644 --- a/examples/backends.js +++ b/examples/backends.js @@ -1,9 +1,16 @@ var Canvas = require('..') - , canvas = new Canvas(320, 320) - , ctx = canvas.getContext('2d'); - -console.log(Canvas); -console.log(Canvas.Backends); + , fs = require('fs'); var imagebackend = new Canvas.Backends.ImageBackend(800, 600); -var fbdevbackend = new Canvas.Backends.FBDevBackend("/dev/fb1"); + +var canvas = new Canvas(imagebackend); +var ctx = canvas.getContext('2d'); + +console.log("Width: " + canvas.width + ", Height: " + canvas.height); + +ctx.fillStyle = "#00FF00"; +ctx.fillRect(50, 50, 100, 100); + +var outPath = __dirname + '/rectangle.png'; + +canvas.createPNGStream().pipe(fs.createWriteStream(outPath)); diff --git a/examples/simple_fbdev.js b/examples/simple_fbdev.js index b9a281864..37885c69b 100644 --- a/examples/simple_fbdev.js +++ b/examples/simple_fbdev.js @@ -6,8 +6,9 @@ var fs = require('fs'); var Canvas = require('..'); -var canvas = new Canvas(0, 0, "fbdev") -var ctx = canvas.getContext('2d') +var backend = new Canvas.Backends.FBDevBackend("/dev/fb0"); +var canvas = new Canvas(backend); +var ctx = canvas.getContext('2d'); console.log("Width: " + canvas.width + ", Height: " + canvas.height); diff --git a/src/Canvas.cc b/src/Canvas.cc index 993f53f91..c7ef25b4e 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -66,31 +66,14 @@ Canvas::Initialize(Handle target) { NAN_METHOD(Canvas::New) { NanScope(); - Backend *backend = NULL; - int width = 0; - int height = 0; - if (args[0]->IsNumber()) width = args[0]->Uint32Value(); - if (args[1]->IsNumber()) height = args[1]->Uint32Value(); - if (args[2]->IsString()) { - v8::String::Utf8Value param2(args[2]->ToString()); - string type = std::string(*param2); - if (type == "image") { - backend = new ImageBackend(width, height); - } else if (type == "fbdev") { - string deviceName = "/dev/fb0"; - if (args[3]->IsString()) { - v8::String::Utf8Value param3(args[3]->ToString()); - deviceName = std::string(*param3); - } - backend = new FBDevBackend(deviceName); - } else { - backend = new ImageBackend(width, height); - } - } else { - backend = new ImageBackend(width, height); - } - Canvas *canvas = new Canvas(backend); + Canvas *canvas = NULL; + if (args[0]->IsNumber() && args[1]->IsNumber()) { + canvas = new Canvas(new ImageBackend(args[0]->Uint32Value(), args[1]->Uint32Value())); + } else if (args[0]->IsObject()) { + Backend* backend = ObjectWrap::Unwrap(args[0]->ToObject()); + canvas = new Canvas(backend); + } canvas->Wrap(args.This()); NanReturnValue(args.This()); } From c0381903c5fb0b371980a7c909050cad81ead221 Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Sun, 5 Jul 2015 14:01:25 +0200 Subject: [PATCH 037/183] fixed Canvas.backends being uppercase --- examples/backends.js | 2 +- examples/simple_fbdev.js | 2 +- lib/canvas.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/backends.js b/examples/backends.js index 97adc65c8..ec8e118cd 100644 --- a/examples/backends.js +++ b/examples/backends.js @@ -1,7 +1,7 @@ var Canvas = require('..') , fs = require('fs'); -var imagebackend = new Canvas.Backends.ImageBackend(800, 600); +var imagebackend = new Canvas.backends.ImageBackend(800, 600); var canvas = new Canvas(imagebackend); var ctx = canvas.getContext('2d'); diff --git a/examples/simple_fbdev.js b/examples/simple_fbdev.js index 37885c69b..48e3afdb9 100644 --- a/examples/simple_fbdev.js +++ b/examples/simple_fbdev.js @@ -6,7 +6,7 @@ var fs = require('fs'); var Canvas = require('..'); -var backend = new Canvas.Backends.FBDevBackend("/dev/fb0"); +var backend = new Canvas.backends.FBDevBackend("/dev/fb0"); var canvas = new Canvas(backend); var ctx = canvas.getContext('2d'); diff --git a/lib/canvas.js b/lib/canvas.js index 8ac465df7..c35cdafca 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -28,7 +28,7 @@ var canvas = require('./bindings') var Canvas = exports = module.exports = Canvas; -exports.Backends = Backends; +exports.backends = Backends; /** * Library version. From e6afa9ca8942a2c41fc2c0bb1b9491f8d725e81a Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Sun, 5 Jul 2015 15:48:29 +0200 Subject: [PATCH 038/183] ticking clock drawn to framebuffer --- examples/animated_clock.js | 107 +++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 examples/animated_clock.js diff --git a/examples/animated_clock.js b/examples/animated_clock.js new file mode 100644 index 000000000..893a1c84d --- /dev/null +++ b/examples/animated_clock.js @@ -0,0 +1,107 @@ +var fs = require('fs'); +var Canvas = require('..'); + +var backend = new Canvas.backends.FBDevBackend("/dev/fb0"); +var canvas = new Canvas(backend); +var ctx = canvas.getContext('2d'); + +function getX(angle) { + return -Math.sin(angle + Math.PI); +} + +function getY(angle) { + return Math.cos(angle + Math.PI); +} + +function clock(ctx) { + var now = new Date(); + ctx.clearRect(0, 0, canvas.width, canvas.height); + + ctx.save(); + ctx.translate(canvas.width / 2, canvas.height / 2); + ctx.beginPath(); + ctx.lineWidth = 14; + ctx.strokeStyle = '#325FA2'; + ctx.fillStyle = '#eeeeee'; + ctx.arc(0, 0, 142, 0, Math.PI * 2, true); + ctx.stroke(); + ctx.fill(); + + ctx.strokeStyle = '#000000'; + // Hour marks + ctx.lineWidth = 8; + for (var i = 0; i < 12; i++) { + var x = getX(Math.PI / 6 * i); + var y = getY(Math.PI / 6 * i); + ctx.beginPath(); + ctx.moveTo(x * 100, y * 100); + ctx.lineTo(x * 125, y * 125); + ctx.stroke(); + } + + // Minute marks + ctx.lineWidth = 5; + for (i = 0; i < 60; i++) { + if (i % 5 != 0) { + var x = getX(Math.PI / 30 * i); + var y = getY(Math.PI / 30 * i); + ctx.beginPath(); + ctx.moveTo(x * 117, y * 117); + ctx.lineTo(x * 125, y * 125); + ctx.stroke(); + } + } + + var sec = now.getSeconds(); + var min = now.getMinutes(); + var hr = now.getHours(); + hr = hr >= 12 ? hr - 12 : hr; + + ctx.fillStyle = "black"; + + // write Hours + var x = getX(hr * (Math.PI / 6) + (Math.PI / 360) * min + (Math.PI / 21600) * sec); + var y = getY(hr * (Math.PI / 6) + (Math.PI / 360) * min + (Math.PI / 21600) * sec); + ctx.lineWidth = 14; + ctx.beginPath(); + ctx.moveTo(x * -20, y * -20); + ctx.lineTo(x * 80, y * 80); + ctx.stroke(); + + // write Minutes + var x = getX((Math.PI / 30) * min + (Math.PI / 1800) * sec); + var y = getY((Math.PI / 30) * min + (Math.PI / 1800) * sec); + + ctx.lineWidth = 10; + ctx.beginPath(); + ctx.moveTo(x * -28, y * -28); + ctx.lineTo(x * 112, y * 112); + ctx.stroke(); + + // Write seconds + var x = getX(sec * Math.PI / 30); + var y = getY(sec * Math.PI / 30); + ctx.strokeStyle = "#D40000"; + ctx.fillStyle = "#D40000"; + ctx.lineWidth = 6; + ctx.beginPath(); + ctx.moveTo(x * -30, y * -30); + ctx.lineTo(x * 83, y * 83); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(0, 0, 10, 0, Math.PI * 2, true); + ctx.fill(); + ctx.beginPath(); + ctx.arc(x * 95, y * 95, 10, 0, Math.PI * 2, true); + ctx.stroke(); + ctx.fillStyle = "#555"; + ctx.arc(0, 0, 3, 0, Math.PI * 2, true); + ctx.fill(); + + ctx.restore(); +} + +clock(ctx); +setInterval(function() { + clock(ctx); +}, 1000); From ac6ce1c9a7bfdf1e28e2aa656eafcd9a33fe5010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sun, 5 Jul 2015 16:35:34 +0200 Subject: [PATCH 039/183] Allow to define FBDev device from command line --- examples/simple_fbdev.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) mode change 100644 => 100755 examples/simple_fbdev.js diff --git a/examples/simple_fbdev.js b/examples/simple_fbdev.js old mode 100644 new mode 100755 index 48e3afdb9..7dbd8e824 --- a/examples/simple_fbdev.js +++ b/examples/simple_fbdev.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node /** * Module dependencies. @@ -6,7 +7,9 @@ var fs = require('fs'); var Canvas = require('..'); -var backend = new Canvas.backends.FBDevBackend("/dev/fb0"); +var device = process.argv[2] || "/dev/fb0" + +var backend = new Canvas.backends.FBDevBackend(device); var canvas = new Canvas(backend); var ctx = canvas.getContext('2d'); From 83cf4cefb14c05f15b3c39bd3c4261e45b0db4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sun, 5 Jul 2015 16:36:05 +0200 Subject: [PATCH 040/183] Download fontconfig.h file & clean-up of includes --- static.gyp | 23 ++++++++++++----------- static/ensure_deps.sh | 6 ++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/static.gyp b/static.gyp index 8c37bec07..d945228d9 100644 --- a/static.gyp +++ b/static.gyp @@ -1,23 +1,24 @@ { 'includes': [ 'static/locations.gyp'], 'variables':{ - 'ensure_deps%': '> fontconfig/fontconfig.h || exit $? +fi + fetch $FREETYPE_URL freetype && fetch $GIFLIB_URL giflib && fetch $LIBJPEG_URL libjpeg && From 50348efa34818f1aa44765badadfcb5d7d681092 Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Sun, 5 Jul 2015 16:48:35 +0200 Subject: [PATCH 041/183] added experimental x11 backend trying to fix segfault in older node versions when gcing --- examples/animated_clock.js | 27 +++++++++++-- shared.gyp | 1 + src/Backends.cc | 2 + src/Canvas.cc | 5 ++- src/backend/FBDevBackend.cc | 1 + src/backend/X11Backend.cc | 76 +++++++++++++++++++++++++++++++++++++ src/backend/X11Backend.h | 43 +++++++++++++++++++++ static.gyp | 1 + 8 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 src/backend/X11Backend.cc create mode 100644 src/backend/X11Backend.h diff --git a/examples/animated_clock.js b/examples/animated_clock.js index 893a1c84d..7fb742e03 100644 --- a/examples/animated_clock.js +++ b/examples/animated_clock.js @@ -1,7 +1,9 @@ var fs = require('fs'); var Canvas = require('..'); -var backend = new Canvas.backends.FBDevBackend("/dev/fb0"); +//var backend = new Canvas.backends.FBDevBackend("/dev/fb0"); +var backend = new Canvas.backends.X11Backend(800, 600); + var canvas = new Canvas(backend); var ctx = canvas.getContext('2d'); @@ -101,7 +103,24 @@ function clock(ctx) { ctx.restore(); } -clock(ctx); -setInterval(function() { +var counter = 0; + +var loop = function() { + if (counter == 5) { + console.log("stopping loop"); + + ctx = null; + canvas = null; + backend = null; + return; + } else { + setTimeout(loop, 1000); + } clock(ctx); -}, 1000); + counter++; +} +loop(); + +setInterval(function() { + global.gc(); +}, 100); diff --git a/shared.gyp b/shared.gyp index 0d15caa50..587aa9a85 100644 --- a/shared.gyp +++ b/shared.gyp @@ -45,6 +45,7 @@ 'src/backend/Backend.cc', 'src/backend/ImageBackend.cc', 'src/backend/FBDevBackend.cc', + 'src/backend/X11Backend.cc', 'src/Backends.cc', 'src/Canvas.cc', 'src/CanvasGradient.cc', diff --git a/src/Backends.cc b/src/Backends.cc index 2c1795a85..e14e9c7f1 100644 --- a/src/Backends.cc +++ b/src/Backends.cc @@ -2,6 +2,7 @@ #include "backend/ImageBackend.h" #include "backend/FBDevBackend.h" +#include "backend/X11Backend.h" void Backends::Initialize(Handle target) { NanScope(); @@ -9,6 +10,7 @@ void Backends::Initialize(Handle target) { Local obj = NanNew(); ImageBackend::Initialize(obj); FBDevBackend::Initialize(obj); + X11Backend::Initialize(obj); target->Set(NanNew("Backends"), obj); } diff --git a/src/Canvas.cc b/src/Canvas.cc index c7ef25b4e..22763f39b 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -440,7 +440,10 @@ Canvas::Canvas(Backend* backend) : ObjectWrap() { */ Canvas::~Canvas() { - delete _backend; + printf("destroying canvas\n"); + if (_backend != NULL) { + delete _backend; + } } /* diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 5663eb06d..e577b1694 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -114,6 +114,7 @@ cairo_surface_t *FBDevBackend::recreateSurface() { } void FBDevBackend::destroySurface() { + printf("destroy"); cairo_surface_destroy(this->surface); } diff --git a/src/backend/X11Backend.cc b/src/backend/X11Backend.cc new file mode 100644 index 000000000..c25538a06 --- /dev/null +++ b/src/backend/X11Backend.cc @@ -0,0 +1,76 @@ +#include "X11Backend.h" + +X11Backend::X11Backend(int width, int height) { + this->name = "x11"; + + this->width = width; + this->height = height; +} + +cairo_surface_t *X11Backend::createSurface() { + display = XOpenDisplay(NULL); + if (display == NULL) { + std::ostringstream o; + o << "Can't open display. Is DISPLAY set?\n"; + throw X11BackendException(o.str()); + } + + this->window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, this->width, this->height, 0, 0, BlackPixel(display, 0)); + XSelectInput(display, this->window, StructureNotifyMask | ExposureMask); + XMapWindow(display, this->window); + + this->surface = cairo_xlib_surface_create(display, this->window, DefaultVisual(display, 0), this->width, this->height); + + // set destroy callback + cairo_surface_set_user_data( + this->surface, + NULL, + this, + &cairo_x11_surface_destroy + ); + + return this->surface; +} + +cairo_surface_t *X11Backend::recreateSurface() { + throw BackendOperationNotAvailable(this, "recreateSurface()"); +} + +void X11Backend::destroySurface() { + printf("destroying surface\n"); + if (this->surface != NULL) { + cairo_surface_destroy(this->surface); + } +} + +void cairo_x11_surface_destroy(void *backend) { + printf("destroying surface callback\n"); + if (backend == NULL) { + return; + } + X11Backend *x11backend = (X11Backend *) backend; + XCloseDisplay(x11backend->display); +} + +Persistent X11Backend::constructor; + +void X11Backend::Initialize(Handle target) { + NanScope(); + Local ctor = NanNew(X11Backend::New); + NanAssignPersistent(X11Backend::constructor, ctor); + ctor->InstanceTemplate()->SetInternalFieldCount(1); + ctor->SetClassName(NanNew("X11Backend")); + Local proto = ctor->PrototypeTemplate(); + target->Set(NanNew("X11Backend"), ctor->GetFunction()); +} + +NAN_METHOD(X11Backend::New) { + int width = 0; + int height = 0; + if (args[0]->IsNumber()) width = args[0]->Uint32Value(); + if (args[1]->IsNumber()) height = args[1]->Uint32Value(); + + X11Backend *backend = new X11Backend(width, height); + backend->Wrap(args.This()); + NanReturnValue(args.This()); +} diff --git a/src/backend/X11Backend.h b/src/backend/X11Backend.h new file mode 100644 index 000000000..9aa372cac --- /dev/null +++ b/src/backend/X11Backend.h @@ -0,0 +1,43 @@ +#ifndef __X11_BACKEND_H__ +#define __X11_BACKEND_H__ + +#include "Backend.h" +#include +#include + +using namespace std; + +class X11Backend : public Backend { + public: + virtual cairo_surface_t *createSurface(); + virtual cairo_surface_t *recreateSurface(); + virtual void destroySurface(); + + void setWidth(int width); + void setHeight(int height); + + X11Backend(int width, int height); + ~X11Backend() { printf("destroying backend\n"); this->destroySurface(); } + + Display *display; + Window window; + + static Persistent constructor; + static void Initialize(Handle target); + static NAN_METHOD(New); +}; + +void cairo_x11_surface_destroy(void *backend); + +class X11BackendException : public std::exception { + private: + string err_msg; + + public: + X11BackendException(const string msg) : err_msg(msg) {}; + ~X11BackendException() throw() {}; + const char *what() const throw() { return this->err_msg.c_str(); }; +}; + + +#endif diff --git a/static.gyp b/static.gyp index 8c37bec07..82bb79d44 100644 --- a/static.gyp +++ b/static.gyp @@ -31,6 +31,7 @@ 'src/backend/Backend.cc', 'src/backend/ImageBackend.cc', 'src/backend/FBDevBackend.cc', + 'src/backend/X11Backend.cc', 'src/Backends.cc', 'src/Canvas.cc', 'src/CanvasGradient.cc', From f7b99b9a8d6dd2ffc42c856b923067b6e446194e Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Sun, 5 Jul 2015 17:10:32 +0200 Subject: [PATCH 042/183] fixed seg fault during gc --- examples/animated_clock.js | 22 ++-------------------- src/Canvas.cc | 1 - src/backend/FBDevBackend.cc | 27 +++++---------------------- src/backend/FBDevBackend.h | 2 -- src/backend/ImageBackend.cc | 7 ------- src/backend/X11Backend.cc | 20 +------------------- src/backend/X11Backend.h | 4 +--- 7 files changed, 9 insertions(+), 74 deletions(-) diff --git a/examples/animated_clock.js b/examples/animated_clock.js index 7fb742e03..6e392c4dd 100644 --- a/examples/animated_clock.js +++ b/examples/animated_clock.js @@ -103,24 +103,6 @@ function clock(ctx) { ctx.restore(); } -var counter = 0; - -var loop = function() { - if (counter == 5) { - console.log("stopping loop"); - - ctx = null; - canvas = null; - backend = null; - return; - } else { - setTimeout(loop, 1000); - } - clock(ctx); - counter++; -} -loop(); - setInterval(function() { - global.gc(); -}, 100); + clock(ctx); +}, 1000); diff --git a/src/Canvas.cc b/src/Canvas.cc index 22763f39b..7795489e4 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -440,7 +440,6 @@ Canvas::Canvas(Backend* backend) : ObjectWrap() { */ Canvas::~Canvas() { - printf("destroying canvas\n"); if (_backend != NULL) { delete _backend; } diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index e577b1694..583a1c738 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -90,14 +90,6 @@ cairo_surface_t * FBDevBackend::createSurface() { cairo_format_stride_for_width(this->format, this->width) ); - // set destroy callback - cairo_surface_set_user_data( - this->surface, - NULL, - this, - &cairo_linuxfb_surface_destroy - ); - return this->surface; } @@ -114,19 +106,11 @@ cairo_surface_t *FBDevBackend::recreateSurface() { } void FBDevBackend::destroySurface() { - printf("destroy"); - cairo_surface_destroy(this->surface); -} - -void cairo_linuxfb_surface_destroy(void *device) { - FBDevBackend *backend = (FBDevBackend *) device; - - if (backend == NULL) { - return; + if (this->surface != NULL) { + cairo_surface_destroy(this->surface); + munmap(this->fb_data, this->fb_screensize); + close(this->fb_fd); } - - munmap(backend->fb_data, backend->fb_screensize); - close(backend->fb_fd); } Persistent FBDevBackend::constructor; @@ -137,7 +121,6 @@ void FBDevBackend::Initialize(Handle target) { NanAssignPersistent(FBDevBackend::constructor, ctor); ctor->InstanceTemplate()->SetInternalFieldCount(1); ctor->SetClassName(NanNew("FBDevBackend")); - Local proto = ctor->PrototypeTemplate(); target->Set(NanNew("FBDevBackend"), ctor->GetFunction()); } @@ -145,7 +128,7 @@ NAN_METHOD(FBDevBackend::New) { FBDevBackend *backend = NULL; if (args[0]->IsString()) { - string fbDevice = *String::Utf8Value(args[0].As()); + string fbDevice = *String::Utf8Value(args[0].As()); backend = new FBDevBackend(fbDevice); } else { backend = new FBDevBackend("/dev/fb0"); diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index b048bfd1d..5b0ce1bd3 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -35,8 +35,6 @@ class FBDevBackend : public Backend { static NAN_METHOD(New); }; -void cairo_linuxfb_surface_destroy(void *device); - class FBDevBackendException : public std::exception { private: string err_msg; diff --git a/src/backend/ImageBackend.cc b/src/backend/ImageBackend.cc index d2677e31d..d9aa7f091 100644 --- a/src/backend/ImageBackend.cc +++ b/src/backend/ImageBackend.cc @@ -9,26 +9,20 @@ ImageBackend::ImageBackend(int width, int height) { cairo_surface_t *ImageBackend::createSurface() { this->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, this->width, this->height); - //NanAdjustExternalMemory(4 * this->width * this->height); return this->surface; } cairo_surface_t *ImageBackend::recreateSurface() { if (this->surface != NULL) { - //int old_width = cairo_image_surface_get_width(this->surface); - //int old_height = cairo_image_surface_get_height(this->surface); cairo_surface_destroy(this->surface); - //NanAdjustExternalMemory(-4 * old_width * old_height); } this->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); - //NanAdjustExternalMemory(4 * (width * height - old_width * old_height)); return this->surface; } void ImageBackend::destroySurface() { if (this->surface != NULL) { cairo_surface_destroy(this->surface); - //NanAdjustExternalMemory(-4 * this->width * this->height); } } @@ -40,7 +34,6 @@ void ImageBackend::Initialize(Handle target) { NanAssignPersistent(ImageBackend::constructor, ctor); ctor->InstanceTemplate()->SetInternalFieldCount(1); ctor->SetClassName(NanNew("ImageBackend")); - Local proto = ctor->PrototypeTemplate(); target->Set(NanNew("ImageBackend"), ctor->GetFunction()); } diff --git a/src/backend/X11Backend.cc b/src/backend/X11Backend.cc index c25538a06..a1bc32ac1 100644 --- a/src/backend/X11Backend.cc +++ b/src/backend/X11Backend.cc @@ -21,14 +21,6 @@ cairo_surface_t *X11Backend::createSurface() { this->surface = cairo_xlib_surface_create(display, this->window, DefaultVisual(display, 0), this->width, this->height); - // set destroy callback - cairo_surface_set_user_data( - this->surface, - NULL, - this, - &cairo_x11_surface_destroy - ); - return this->surface; } @@ -37,21 +29,12 @@ cairo_surface_t *X11Backend::recreateSurface() { } void X11Backend::destroySurface() { - printf("destroying surface\n"); if (this->surface != NULL) { cairo_surface_destroy(this->surface); + XCloseDisplay(this->display); } } -void cairo_x11_surface_destroy(void *backend) { - printf("destroying surface callback\n"); - if (backend == NULL) { - return; - } - X11Backend *x11backend = (X11Backend *) backend; - XCloseDisplay(x11backend->display); -} - Persistent X11Backend::constructor; void X11Backend::Initialize(Handle target) { @@ -60,7 +43,6 @@ void X11Backend::Initialize(Handle target) { NanAssignPersistent(X11Backend::constructor, ctor); ctor->InstanceTemplate()->SetInternalFieldCount(1); ctor->SetClassName(NanNew("X11Backend")); - Local proto = ctor->PrototypeTemplate(); target->Set(NanNew("X11Backend"), ctor->GetFunction()); } diff --git a/src/backend/X11Backend.h b/src/backend/X11Backend.h index 9aa372cac..8eccf8768 100644 --- a/src/backend/X11Backend.h +++ b/src/backend/X11Backend.h @@ -17,7 +17,7 @@ class X11Backend : public Backend { void setHeight(int height); X11Backend(int width, int height); - ~X11Backend() { printf("destroying backend\n"); this->destroySurface(); } + ~X11Backend() { this->destroySurface(); } Display *display; Window window; @@ -27,8 +27,6 @@ class X11Backend : public Backend { static NAN_METHOD(New); }; -void cairo_x11_surface_destroy(void *backend); - class X11BackendException : public std::exception { private: string err_msg; From 78fffe268b0c7b2b1ac7754eb9a08b5f4fdc3e36 Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Sun, 5 Jul 2015 17:34:16 +0200 Subject: [PATCH 043/183] use diffrent code to figure out screensize --- src/backend/FBDevBackend.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 583a1c738..4774f2272 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -23,6 +23,13 @@ cairo_surface_t * FBDevBackend::createSurface() { throw FBDevBackendException(o.str()); } + // Get fixed screen information + if (ioctl(this->fb_fd, FBIOGET_FSCREENINFO, &this->fb_finfo) == -1) { + std::ostringstream o; + o << "error reading fixed information from device \"" << this->fb_dn << "\""; + throw FBDevBackendException(o.str()); + } + // Get variable screen information if (ioctl(this->fb_fd, FBIOGET_VSCREENINFO, &this->fb_vinfo) == -1) { std::ostringstream o; @@ -56,8 +63,8 @@ cairo_surface_t * FBDevBackend::createSurface() { } // Figure out the size of the screen in bytes - this->fb_screensize = this->width * this->height * this->bpp / 8; - + //this->fb_screensize = this->width * this->height * this->bpp / 8; + this->fb_screensize = this->fb_vinfo.yres_virtual * this->fb_finfo.line_length; // Map the device to memory this->fb_data = (unsigned char *) mmap( 0, @@ -74,13 +81,6 @@ cairo_surface_t * FBDevBackend::createSurface() { throw FBDevBackendException(o.str()); } - // Get fixed screen information - if (ioctl(this->fb_fd, FBIOGET_FSCREENINFO, &this->fb_finfo) == -1) { - std::ostringstream o; - o << "error reading fixed information from device \"" << this->fb_dn << "\""; - throw FBDevBackendException(o.str()); - } - // TODO decide image format by bpp of fb device this->surface = cairo_image_surface_create_for_data( this->fb_data, From fda7ec0f94c5e468019943814e0f59159ecc6c00 Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Mon, 6 Jul 2015 14:32:35 +0200 Subject: [PATCH 044/183] now using smem_len to get framebuffer size and not calculate it --- src/backend/FBDevBackend.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 4774f2272..1c07ff24b 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -64,7 +64,9 @@ cairo_surface_t * FBDevBackend::createSurface() { // Figure out the size of the screen in bytes //this->fb_screensize = this->width * this->height * this->bpp / 8; - this->fb_screensize = this->fb_vinfo.yres_virtual * this->fb_finfo.line_length; + //this->fb_screensize = this->fb_vinfo.yres_virtual * this->fb_finfo.line_length; + this->fb_screensize = this->fb_finfo.smem_len; + // Map the device to memory this->fb_data = (unsigned char *) mmap( 0, From f348fb4ca0f4007cbd9874148bd8e071e537ba9a Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Tue, 7 Jul 2015 15:40:14 +0200 Subject: [PATCH 045/183] still trying to fix broken fbdev backend on some devices --- src/backend/FBDevBackend.cc | 36 +++++++++++++++++------------------- src/backend/FBDevBackend.h | 2 ++ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 1c07ff24b..f4dec1344 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -14,6 +14,14 @@ FBDevBackend::FBDevBackend(string deviceName) { this->fb_dn = deviceName; } +void FBDevBackend:FbDevIoctlHelper(unsigned long request, void* data, char* errmsg) { + if (ioctl(this->fb_fd, request, data) == -1) { + std::ostringstream o; + o << errmsg << ", Framebuffer Device: \"" << this->fb_dn << "\""; + throw FBDevBackendException(o.str()); + } +} + cairo_surface_t * FBDevBackend::createSurface() { // Open the file for reading and writing this->fb_fd = open(this->fb_dn.c_str(), O_RDWR); @@ -23,24 +31,19 @@ cairo_surface_t * FBDevBackend::createSurface() { throw FBDevBackendException(o.str()); } - // Get fixed screen information - if (ioctl(this->fb_fd, FBIOGET_FSCREENINFO, &this->fb_finfo) == -1) { - std::ostringstream o; - o << "error reading fixed information from device \"" << this->fb_dn << "\""; - throw FBDevBackendException(o.str()); - } - - // Get variable screen information - if (ioctl(this->fb_fd, FBIOGET_VSCREENINFO, &this->fb_vinfo) == -1) { - std::ostringstream o; - o << "error reading variable information from device \"" << this->fb_dn << "\""; - throw FBDevBackendException(o.str()); - } + // read fixed info, read variable info, set bpp and disable grayscale + this->FbDevIoctlHelper(FBIOGET_FSCREENINFO, this->fb_finfo, "error reading fixed framebuffer information"); + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, this->fb_vinfo, "error reading variable framebuffer information"); + this->fb_vinfo.grayscale = 0; + this->fb_vinfovinfo.bits_per_pixel = 32; + this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, this->fb_finfo, "error setting variable framebuffer information"); + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, this->fb_vinfo, "error reading variable framebuffer information"); // set width, height and bpp according to the size of the fb device this->width = this->fb_vinfo.xres; this->height = this->fb_vinfo.yres; this->bpp = this->fb_vinfo.bits_per_pixel; + this->fb_screensize = this->fb_vinfo.yres_virtual * this->fb_finfo.line_length; // switch through bpp and decide on which format for the cairo surface to use switch (this->bpp) { @@ -62,11 +65,6 @@ cairo_surface_t * FBDevBackend::createSurface() { throw FBDevBackendException(o.str()); } - // Figure out the size of the screen in bytes - //this->fb_screensize = this->width * this->height * this->bpp / 8; - //this->fb_screensize = this->fb_vinfo.yres_virtual * this->fb_finfo.line_length; - this->fb_screensize = this->fb_finfo.smem_len; - // Map the device to memory this->fb_data = (unsigned char *) mmap( 0, @@ -83,7 +81,7 @@ cairo_surface_t * FBDevBackend::createSurface() { throw FBDevBackendException(o.str()); } - // TODO decide image format by bpp of fb device + // create cairo surface from data this->surface = cairo_image_surface_create_for_data( this->fb_data, this->format, diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 5b0ce1bd3..d27edae82 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -27,6 +27,8 @@ class FBDevBackend : public Backend { void setWidth(int width); void setHeight(int height); + void FBDevBackend:FbDevIoctlHelper(unsigned long request, void* data, char* errmsg); + FBDevBackend(string deviceName); ~FBDevBackend() { this->destroySurface(); } From b8b0a6a3184c6b2d8f3a7138c814d4699996e2d1 Mon Sep 17 00:00:00 2001 From: ReneHollander Date: Tue, 7 Jul 2015 16:48:35 +0200 Subject: [PATCH 046/183] fixed stupid syntax errors --- src/backend/FBDevBackend.cc | 12 ++++++------ src/backend/FBDevBackend.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index f4dec1344..34c607f56 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -14,7 +14,7 @@ FBDevBackend::FBDevBackend(string deviceName) { this->fb_dn = deviceName; } -void FBDevBackend:FbDevIoctlHelper(unsigned long request, void* data, char* errmsg) { +void FBDevBackend::FbDevIoctlHelper(unsigned long request, void* data, string errmsg) { if (ioctl(this->fb_fd, request, data) == -1) { std::ostringstream o; o << errmsg << ", Framebuffer Device: \"" << this->fb_dn << "\""; @@ -32,12 +32,12 @@ cairo_surface_t * FBDevBackend::createSurface() { } // read fixed info, read variable info, set bpp and disable grayscale - this->FbDevIoctlHelper(FBIOGET_FSCREENINFO, this->fb_finfo, "error reading fixed framebuffer information"); - this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, this->fb_vinfo, "error reading variable framebuffer information"); + this->FbDevIoctlHelper(FBIOGET_FSCREENINFO, &this->fb_finfo, "error reading fixed framebuffer information"); + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &this->fb_vinfo, "error reading variable framebuffer information"); this->fb_vinfo.grayscale = 0; - this->fb_vinfovinfo.bits_per_pixel = 32; - this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, this->fb_finfo, "error setting variable framebuffer information"); - this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, this->fb_vinfo, "error reading variable framebuffer information"); + this->fb_vinfo.bits_per_pixel = 32; + this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &this->fb_vinfo, "error setting variable framebuffer information"); + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &this->fb_vinfo, "error reading variable framebuffer information"); // set width, height and bpp according to the size of the fb device this->width = this->fb_vinfo.xres; diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index d27edae82..f522961f9 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -27,7 +27,7 @@ class FBDevBackend : public Backend { void setWidth(int width); void setHeight(int height); - void FBDevBackend:FbDevIoctlHelper(unsigned long request, void* data, char* errmsg); + void FbDevIoctlHelper(unsigned long request, void* data, string errmsg); FBDevBackend(string deviceName); ~FBDevBackend() { this->destroySurface(); } From da5d4ffb5c3a55c89861dba8c95c96460588488b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=27piranna?= Date: Wed, 8 Jul 2015 09:25:01 +0200 Subject: [PATCH 047/183] Put in common configuration of canvas for shared and static --- binding.gyp | 20 +-- canvas.gypi | 40 ++++++ shared.gyp | 345 ++++++++++++++++++++++++------------------------ src/Backends.cc | 14 +- static.gyp | 48 +++---- util/has_lib.sh | 3 +- 6 files changed, 251 insertions(+), 219 deletions(-) create mode 100644 canvas.gypi diff --git a/binding.gyp b/binding.gyp index 63244ba23..6dbecb6af 100755 --- a/binding.gyp +++ b/binding.gyp @@ -1,12 +1,16 @@ { - 'variables': { - 'has_cairo%': ' target) { NanScope(); Local obj = NanNew(); ImageBackend::Initialize(obj); - FBDevBackend::Initialize(obj); - X11Backend::Initialize(obj); + + #ifdef HAS_FBDEV + FBDevBackend::Initialize(obj); + #endif + #ifdef HAS_X11 + X11Backend::Initialize(obj); + #endif target->Set(NanNew("Backends"), obj); } diff --git a/static.gyp b/static.gyp index 3483a0433..51d0d6f6a 100644 --- a/static.gyp +++ b/static.gyp @@ -1,13 +1,14 @@ { - 'includes': [ 'static/locations.gyp'], - 'variables':{ + 'includes': ['static/locations.gyp'], + 'variables': + { 'ensure_deps%': ' Date: Wed, 8 Jul 2015 16:51:41 +0200 Subject: [PATCH 048/183] Use fb_vinfo.xres_virtual to calculate the stride --- src/backend/FBDevBackend.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 34c607f56..4180111c2 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -81,13 +81,15 @@ cairo_surface_t * FBDevBackend::createSurface() { throw FBDevBackendException(o.str()); } + int stride = cairo_format_stride_for_width(this->format, this->fb_vinfo.xres_virtual); + // create cairo surface from data this->surface = cairo_image_surface_create_for_data( this->fb_data, this->format, this->width, this->height, - cairo_format_stride_for_width(this->format, this->width) + stride ); return this->surface; From 69b72ce4870a4f7ec597e8bc13fb357af96f42b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=27piranna?= Date: Fri, 10 Jul 2015 00:27:59 +0200 Subject: [PATCH 049/183] Clean-up of backend classes --- src/backend/Backend.cc | 70 ++++++++++++----- src/backend/Backend.h | 37 ++++++--- src/backend/FBDevBackend.cc | 152 +++++++++++++++++------------------- src/backend/FBDevBackend.h | 26 +++--- src/backend/ImageBackend.cc | 38 ++++----- src/backend/ImageBackend.h | 14 ++-- src/backend/X11Backend.cc | 55 ++++++++----- src/backend/X11Backend.h | 18 ++--- 8 files changed, 227 insertions(+), 183 deletions(-) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 7e98bc0e2..7bb9a569a 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -1,43 +1,77 @@ #include "Backend.h" -Backend::~Backend() { + +Backend::Backend(string name) + : name(name) + , width(0) + , height(0) + , surface(NULL) +{} + +Backend::~Backend() +{ + this->destroySurface(); +} + + +void Backend::destroySurface() +{ + if(this->surface) + { + cairo_surface_destroy(this->surface); + this->surface = NULL; + } +} + +cairo_surface_t* Backend::recreateSurface() +{ + this->destroySurface(); + + return this->createSurface(); +} + +cairo_surface_t* Backend::getSurface() +{ + return surface; } -string Backend::getName() { + +string Backend::getName() +{ return name; } -int Backend::getWidth() { +int Backend::getWidth() +{ return this->width; } - -void Backend::setWidth(int width) { +void Backend::setWidth(int width) +{ this->width = width; this->recreateSurface(); } -int Backend::getHeight() { +int Backend::getHeight() +{ return this->height; } - -void Backend::setHeight(int height) { +void Backend::setHeight(int height) +{ this->height = height; this->recreateSurface(); } -cairo_surface_t* Backend::getSurface() { - return surface; -} -BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend, string operation_name) { - this->backend = backend; - this->operation_name = operation_name; -}; +BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend, + string operation_name) + : backend(backend) + , operation_name(operation_name) +{}; -BackendOperationNotAvailable::~BackendOperationNotAvailable() throw() { -}; +BackendOperationNotAvailable::~BackendOperationNotAvailable() throw() {}; -const char* BackendOperationNotAvailable::what() const throw() { +const char* BackendOperationNotAvailable::what() const throw() +{ std::ostringstream o; o << "operation " << this->operation_name; diff --git a/src/backend/Backend.h b/src/backend/Backend.h index bad596ce4..92ef83fe1 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -5,11 +5,13 @@ #include #include #include + #include #include #include #include #include + #if HAVE_PANGO #include #else @@ -20,28 +22,39 @@ using namespace v8; using namespace node; using namespace std; -class Backend : public ObjectWrap { - protected: - string name; +class Backend : public ObjectWrap +{ + private: + const string name; + protected: int width; int height; - cairo_surface_t *surface; + cairo_surface_t* surface; + + Backend(string name); public: - virtual ~Backend() = 0; - virtual cairo_surface_t *createSurface() = 0; - virtual cairo_surface_t *recreateSurface() = 0; - virtual void destroySurface() = 0; + virtual ~Backend(); + + virtual cairo_surface_t* createSurface() = 0; + virtual void destroySurface(); + + cairo_surface_t* recreateSurface(); + cairo_surface_t* getSurface(); + string getName(); + int getWidth(); - void setWidth(int width); + virtual void setWidth(int width); + int getHeight(); - void setHeight(int height); - cairo_surface_t* getSurface(); + virtual void setHeight(int height); }; -class BackendOperationNotAvailable : public exception { + +class BackendOperationNotAvailable: public exception +{ private: Backend* backend; string operation_name; diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 4180111c2..e9120f598 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -1,123 +1,116 @@ +#include +#include +#include + #include #include #include #include #include #include -#include -#include -#include + #include "FBDevBackend.h" -FBDevBackend::FBDevBackend(string deviceName) { - this->name = "fbdev"; - this->fb_dn = deviceName; -} -void FBDevBackend::FbDevIoctlHelper(unsigned long request, void* data, string errmsg) { - if (ioctl(this->fb_fd, request, data) == -1) { +FBDevBackend::FBDevBackend(string deviceName) + : Backend("fbdev") + , fb_dn(deviceName) +{} + + +void FBDevBackend::FbDevIoctlHelper(unsigned long request, void* data, + string errmsg) +{ + if(ioctl(this->fb_fd, request, data) == -1) + { std::ostringstream o; o << errmsg << ", Framebuffer Device: \"" << this->fb_dn << "\""; throw FBDevBackendException(o.str()); } } -cairo_surface_t * FBDevBackend::createSurface() { + +cairo_surface_t* FBDevBackend::createSurface() +{ // Open the file for reading and writing this->fb_fd = open(this->fb_dn.c_str(), O_RDWR); - if (this->fb_fd == -1) { + + if(this->fb_fd == -1) + { std::ostringstream o; o << "cannot open framebuffer device \"" << this->fb_dn << "\""; throw FBDevBackendException(o.str()); } - // read fixed info, read variable info, set bpp and disable grayscale + struct fb_var_screeninfo fb_vinfo; + this->FbDevIoctlHelper(FBIOGET_FSCREENINFO, &this->fb_finfo, "error reading fixed framebuffer information"); - this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &this->fb_vinfo, "error reading variable framebuffer information"); - this->fb_vinfo.grayscale = 0; - this->fb_vinfo.bits_per_pixel = 32; - this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &this->fb_vinfo, "error setting variable framebuffer information"); - this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &this->fb_vinfo, "error reading variable framebuffer information"); - - // set width, height and bpp according to the size of the fb device - this->width = this->fb_vinfo.xres; - this->height = this->fb_vinfo.yres; - this->bpp = this->fb_vinfo.bits_per_pixel; - this->fb_screensize = this->fb_vinfo.yres_virtual * this->fb_finfo.line_length; + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, "error reading variable framebuffer information"); + + this->width = fb_vinfo.xres; + this->height = fb_vinfo.yres; // switch through bpp and decide on which format for the cairo surface to use - switch (this->bpp) { - case 32: - this->format = CAIRO_FORMAT_ARGB32; - break; - case 24: - this->format = CAIRO_FORMAT_RGB24; - break; - case 16: - this->format = CAIRO_FORMAT_RGB16_565; - break; - case 8: - this->format = CAIRO_FORMAT_A8; - break; - default: - std::ostringstream o; - o << "could not determine color format of device \"" << this->fb_dn << "\""; - throw FBDevBackendException(o.str()); + cairo_format_t format; + switch(fb_vinfo.bits_per_pixel) + { + case 8: format = CAIRO_FORMAT_A8; break; + case 16: format = CAIRO_FORMAT_RGB16_565; break; + case 24: format = CAIRO_FORMAT_RGB24; break; + case 32: format = CAIRO_FORMAT_ARGB32; break; + + default: + std::ostringstream o; + o << "could not determine color format of device \"" << this->fb_dn << "\""; + throw FBDevBackendException(o.str()); } // Map the device to memory - this->fb_data = (unsigned char *) mmap( - 0, - this->fb_screensize, - PROT_READ | PROT_WRITE, - MAP_SHARED, - this->fb_fd, - 0 - ); - - if (this->fb_data == MAP_FAILED) { + this->fb_data = (unsigned char *) mmap(0, this->fb_finfo.smem_len, + PROT_READ | PROT_WRITE, MAP_SHARED, this->fb_fd, 0); + + if(this->fb_data == MAP_FAILED) + { std::ostringstream o; o << "failed to map framebuffer device \"" << this->fb_dn << "\" to memory"; throw FBDevBackendException(o.str()); } - int stride = cairo_format_stride_for_width(this->format, this->fb_vinfo.xres_virtual); + int stride = cairo_format_stride_for_width(format, fb_vinfo.xres_virtual); // create cairo surface from data - this->surface = cairo_image_surface_create_for_data( - this->fb_data, - this->format, - this->width, - this->height, - stride - ); + this->surface = cairo_image_surface_create_for_data(this->fb_data, format, + this->width, this->height, stride); return this->surface; } -void FBDevBackend::setWidth(int width) { - throw BackendOperationNotAvailable(this, "setWidth()"); -} +void FBDevBackend::destroySurface() +{ + if(this->surface) + { + Backend::destroySurface(); -void FBDevBackend::setHeight(int height) { - throw BackendOperationNotAvailable(this, "setHeight()"); + munmap(this->fb_data, this->fb_finfo.smem_len); + close(this->fb_fd); + } } -cairo_surface_t *FBDevBackend::recreateSurface() { - throw BackendOperationNotAvailable(this, "recreateSurface()"); -} -void FBDevBackend::destroySurface() { - if (this->surface != NULL) { - cairo_surface_destroy(this->surface); - munmap(this->fb_data, this->fb_screensize); - close(this->fb_fd); - } +void FBDevBackend::setWidth(int width) +{ + throw BackendOperationNotAvailable(this, "setWidth()"); } +void FBDevBackend::setHeight(int height) +{ + throw BackendOperationNotAvailable(this, "setHeight()"); +} + Persistent FBDevBackend::constructor; -void FBDevBackend::Initialize(Handle target) { +void FBDevBackend::Initialize(Handle target) +{ NanScope(); Local ctor = NanNew(FBDevBackend::New); NanAssignPersistent(FBDevBackend::constructor, ctor); @@ -126,15 +119,12 @@ void FBDevBackend::Initialize(Handle target) { target->Set(NanNew("FBDevBackend"), ctor->GetFunction()); } -NAN_METHOD(FBDevBackend::New) { - FBDevBackend *backend = NULL; +NAN_METHOD(FBDevBackend::New) +{ + string fbDevice = "/dev/fb0"; + if(args[0]->IsString()) fbDevice = *String::Utf8Value(args[0].As()); - if (args[0]->IsString()) { - string fbDevice = *String::Utf8Value(args[0].As()); - backend = new FBDevBackend(fbDevice); - } else { - backend = new FBDevBackend("/dev/fb0"); - } + FBDevBackend* backend = new FBDevBackend(fbDevice); backend->Wrap(args.This()); NanReturnValue(args.This()); diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index f522961f9..8d3e96703 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -3,40 +3,40 @@ #include #include + #include + #include "Backend.h" + using namespace std; -class FBDevBackend : public Backend { - public: +class FBDevBackend : public Backend +{ + private: string fb_dn; + int fb_fd; - struct fb_var_screeninfo fb_vinfo; struct fb_fix_screeninfo fb_finfo; - long fb_screensize; - unsigned char *fb_data; + unsigned char* fb_data; - cairo_format_t format; - int bpp; + void FbDevIoctlHelper(unsigned long request, void* data, string errmsg); - virtual cairo_surface_t *createSurface(); - virtual cairo_surface_t *recreateSurface(); - virtual void destroySurface(); + cairo_surface_t* createSurface(); + void destroySurface(); void setWidth(int width); void setHeight(int height); - void FbDevIoctlHelper(unsigned long request, void* data, string errmsg); - + public: FBDevBackend(string deviceName); - ~FBDevBackend() { this->destroySurface(); } static Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); }; + class FBDevBackendException : public std::exception { private: string err_msg; diff --git a/src/backend/ImageBackend.cc b/src/backend/ImageBackend.cc index d9aa7f091..b0c852a1d 100644 --- a/src/backend/ImageBackend.cc +++ b/src/backend/ImageBackend.cc @@ -1,34 +1,24 @@ #include "ImageBackend.h" -ImageBackend::ImageBackend(int width, int height) { - this->name = "image"; - - this->width = width; +ImageBackend::ImageBackend(int width, int height) +: Backend("image") +{ + this->width = width; this->height = height; } -cairo_surface_t *ImageBackend::createSurface() { - this->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, this->width, this->height); - return this->surface; -} - -cairo_surface_t *ImageBackend::recreateSurface() { - if (this->surface != NULL) { - cairo_surface_destroy(this->surface); - } +cairo_surface_t* ImageBackend::createSurface() +{ this->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); + return this->surface; } -void ImageBackend::destroySurface() { - if (this->surface != NULL) { - cairo_surface_destroy(this->surface); - } -} Persistent ImageBackend::constructor; -void ImageBackend::Initialize(Handle target) { +void ImageBackend::Initialize(Handle target) +{ NanScope(); Local ctor = NanNew(ImageBackend::New); NanAssignPersistent(ImageBackend::constructor, ctor); @@ -37,13 +27,15 @@ void ImageBackend::Initialize(Handle target) { target->Set(NanNew("ImageBackend"), ctor->GetFunction()); } -NAN_METHOD(ImageBackend::New) { - int width = 0; +NAN_METHOD(ImageBackend::New) +{ + int width = 0; int height = 0; - if (args[0]->IsNumber()) width = args[0]->Uint32Value(); + if (args[0]->IsNumber()) width = args[0]->Uint32Value(); if (args[1]->IsNumber()) height = args[1]->Uint32Value(); - ImageBackend *backend = new ImageBackend(width, height); + ImageBackend* backend = new ImageBackend(width, height); + backend->Wrap(args.This()); NanReturnValue(args.This()); } diff --git a/src/backend/ImageBackend.h b/src/backend/ImageBackend.h index 66d9a9d4d..80075ca02 100644 --- a/src/backend/ImageBackend.h +++ b/src/backend/ImageBackend.h @@ -5,17 +5,13 @@ using namespace std; -class ImageBackend : public Backend { - public: - virtual cairo_surface_t *createSurface(); - virtual cairo_surface_t *recreateSurface(); - virtual void destroySurface(); - - void setWidth(int width); - void setHeight(int height); +class ImageBackend : public Backend +{ + private: + cairo_surface_t* createSurface(); + public: ImageBackend(int width, int height); - ~ImageBackend() { this->destroySurface(); } static Persistent constructor; static void Initialize(Handle target); diff --git a/src/backend/X11Backend.cc b/src/backend/X11Backend.cc index a1bc32ac1..a119bdeba 100644 --- a/src/backend/X11Backend.cc +++ b/src/backend/X11Backend.cc @@ -1,43 +1,60 @@ #include "X11Backend.h" -X11Backend::X11Backend(int width, int height) { - this->name = "x11"; - +X11Backend::X11Backend(int width, int height) +: Backend("x11") +{ this->width = width; this->height = height; } -cairo_surface_t *X11Backend::createSurface() { + +cairo_surface_t* X11Backend::createSurface() +{ display = XOpenDisplay(NULL); - if (display == NULL) { + if(!display) + { std::ostringstream o; o << "Can't open display. Is DISPLAY set?\n"; throw X11BackendException(o.str()); } - this->window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, this->width, this->height, 0, 0, BlackPixel(display, 0)); + this->window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, + this->width, this->height, 0, 0, BlackPixel(display, 0)); + XSelectInput(display, this->window, StructureNotifyMask | ExposureMask); XMapWindow(display, this->window); - this->surface = cairo_xlib_surface_create(display, this->window, DefaultVisual(display, 0), this->width, this->height); + this->surface = cairo_xlib_surface_create(display, this->window, + DefaultVisual(display, 0), this->width, this->height); return this->surface; } -cairo_surface_t *X11Backend::recreateSurface() { - throw BackendOperationNotAvailable(this, "recreateSurface()"); -} +void X11Backend::destroySurface() +{ + if(this->surface) + { + Backend::destroySurface(); -void X11Backend::destroySurface() { - if (this->surface != NULL) { - cairo_surface_destroy(this->surface); XCloseDisplay(this->display); } } + +void X11Backend::setWidth(int width) +{ + throw BackendOperationNotAvailable(this, "setWidth()"); +} +void X11Backend::setHeight(int height) +{ + throw BackendOperationNotAvailable(this, "setHeight()"); +} + + Persistent X11Backend::constructor; -void X11Backend::Initialize(Handle target) { +void X11Backend::Initialize(Handle target) +{ NanScope(); Local ctor = NanNew(X11Backend::New); NanAssignPersistent(X11Backend::constructor, ctor); @@ -46,13 +63,15 @@ void X11Backend::Initialize(Handle target) { target->Set(NanNew("X11Backend"), ctor->GetFunction()); } -NAN_METHOD(X11Backend::New) { - int width = 0; +NAN_METHOD(X11Backend::New) +{ + int width = 0; int height = 0; - if (args[0]->IsNumber()) width = args[0]->Uint32Value(); - if (args[1]->IsNumber()) height = args[1]->Uint32Value(); + if(args[0]->IsNumber()) width = args[0]->Uint32Value(); + if(args[1]->IsNumber()) height = args[1]->Uint32Value(); X11Backend *backend = new X11Backend(width, height); + backend->Wrap(args.This()); NanReturnValue(args.This()); } diff --git a/src/backend/X11Backend.h b/src/backend/X11Backend.h index 8eccf8768..ee0d8c550 100644 --- a/src/backend/X11Backend.h +++ b/src/backend/X11Backend.h @@ -7,20 +7,20 @@ using namespace std; -class X11Backend : public Backend { - public: - virtual cairo_surface_t *createSurface(); - virtual cairo_surface_t *recreateSurface(); - virtual void destroySurface(); +class X11Backend : public Backend +{ + private: + Display* display; + Window window; + + cairo_surface_t* createSurface(); + void destroySurface(); void setWidth(int width); void setHeight(int height); + public: X11Backend(int width, int height); - ~X11Backend() { this->destroySurface(); } - - Display *display; - Window window; static Persistent constructor; static void Initialize(Handle target); From f725bea572d917513181bff79142308de432e295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=27piranna?= Date: Fri, 10 Jul 2015 12:06:21 +0200 Subject: [PATCH 050/183] Change resolution of FBDev & clean-up of API --- src/backend/Backend.cc | 24 +++++---- src/backend/Backend.h | 3 +- src/backend/FBDevBackend.cc | 99 ++++++++++++++++++++----------------- src/backend/FBDevBackend.h | 9 ++-- src/backend/ImageBackend.cc | 8 ++- src/backend/X11Backend.cc | 44 +++++++---------- src/backend/X11Backend.h | 3 ++ 7 files changed, 99 insertions(+), 91 deletions(-) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 7bb9a569a..81a3b9145 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -7,6 +7,12 @@ Backend::Backend(string name) , height(0) , surface(NULL) {} +Backend::Backend(string name, int width, int height) + : name(name) + , width(width) + , height(height) + , surface(NULL) +{} Backend::~Backend() { @@ -14,15 +20,6 @@ Backend::~Backend() } -void Backend::destroySurface() -{ - if(this->surface) - { - cairo_surface_destroy(this->surface); - this->surface = NULL; - } -} - cairo_surface_t* Backend::recreateSurface() { this->destroySurface(); @@ -35,6 +32,15 @@ cairo_surface_t* Backend::getSurface() return surface; } +void Backend::destroySurface() +{ + if(this->surface) + { + cairo_surface_destroy(this->surface); + this->surface = NULL; + } +} + string Backend::getName() { diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 92ef83fe1..6175ddaff 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -33,15 +33,16 @@ class Backend : public ObjectWrap cairo_surface_t* surface; Backend(string name); + Backend(string name, int width, int height); public: virtual ~Backend(); virtual cairo_surface_t* createSurface() = 0; - virtual void destroySurface(); cairo_surface_t* recreateSurface(); cairo_surface_t* getSurface(); + void destroySurface(); string getName(); diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index e9120f598..486b0d8a3 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -14,38 +14,51 @@ FBDevBackend::FBDevBackend(string deviceName) : Backend("fbdev") - , fb_dn(deviceName) -{} - - -void FBDevBackend::FbDevIoctlHelper(unsigned long request, void* data, - string errmsg) { - if(ioctl(this->fb_fd, request, data) == -1) + // Open the file for reading and writing + this->fb_fd = open(deviceName.c_str(), O_RDWR); + + if(this->fb_fd == -1) { std::ostringstream o; - o << errmsg << ", Framebuffer Device: \"" << this->fb_dn << "\""; + o << "cannot open framebuffer device \"" << deviceName << "\""; throw FBDevBackendException(o.str()); } + + this->FbDevIoctlHelper(FBIOGET_FSCREENINFO, &this->fb_finfo, + "Error reading fixed framebuffer information"); + + // Map the device to memory + this->fb_data = (unsigned char*) mmap(0, this->fb_finfo.smem_len, + PROT_READ | PROT_WRITE, MAP_SHARED, this->fb_fd, 0); + + if(this->fb_data == MAP_FAILED) + throw FBDevBackendException("Failed to map framebuffer device to memory"); } +FBDevBackend::~FBDevBackend() +{ + this->destroySurface(); -cairo_surface_t* FBDevBackend::createSurface() + munmap(this->fb_data, this->fb_finfo.smem_len); + close(this->fb_fd); +} + + +void FBDevBackend::FbDevIoctlHelper(unsigned long request, void* data, + string errmsg) { - // Open the file for reading and writing - this->fb_fd = open(this->fb_dn.c_str(), O_RDWR); + if(ioctl(this->fb_fd, request, data) == -1) + throw FBDevBackendException(errmsg.c_str()); +} - if(this->fb_fd == -1) - { - std::ostringstream o; - o << "cannot open framebuffer device \"" << this->fb_dn << "\""; - throw FBDevBackendException(o.str()); - } +cairo_surface_t* FBDevBackend::createSurface() +{ struct fb_var_screeninfo fb_vinfo; - this->FbDevIoctlHelper(FBIOGET_FSCREENINFO, &this->fb_finfo, "error reading fixed framebuffer information"); - this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, "error reading variable framebuffer information"); + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, + "Error reading variable framebuffer information"); this->width = fb_vinfo.xres; this->height = fb_vinfo.yres; @@ -60,20 +73,7 @@ cairo_surface_t* FBDevBackend::createSurface() case 32: format = CAIRO_FORMAT_ARGB32; break; default: - std::ostringstream o; - o << "could not determine color format of device \"" << this->fb_dn << "\""; - throw FBDevBackendException(o.str()); - } - - // Map the device to memory - this->fb_data = (unsigned char *) mmap(0, this->fb_finfo.smem_len, - PROT_READ | PROT_WRITE, MAP_SHARED, this->fb_fd, 0); - - if(this->fb_data == MAP_FAILED) - { - std::ostringstream o; - o << "failed to map framebuffer device \"" << this->fb_dn << "\" to memory"; - throw FBDevBackendException(o.str()); + throw FBDevBackendException("Could not determine color format"); } int stride = cairo_format_stride_for_width(format, fb_vinfo.xres_virtual); @@ -85,25 +85,34 @@ cairo_surface_t* FBDevBackend::createSurface() return this->surface; } -void FBDevBackend::destroySurface() + +void FBDevBackend::setWidth(int width) { - if(this->surface) - { - Backend::destroySurface(); + struct fb_var_screeninfo fb_vinfo; - munmap(this->fb_data, this->fb_finfo.smem_len); - close(this->fb_fd); - } -} + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, + "Error reading variable framebuffer information"); + fb_vinfo.xres = width; -void FBDevBackend::setWidth(int width) -{ - throw BackendOperationNotAvailable(this, "setWidth()"); + this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, + "Error setting variable framebuffer information"); + + Backend::setWidth(width); } void FBDevBackend::setHeight(int height) { - throw BackendOperationNotAvailable(this, "setHeight()"); + struct fb_var_screeninfo fb_vinfo; + + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, + "Error reading variable framebuffer information"); + + fb_vinfo.yres = height; + + this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, + "Error setting variable framebuffer information"); + + Backend::setHeight(width); } diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 8d3e96703..6a23c5cbd 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -14,16 +14,15 @@ using namespace std; class FBDevBackend : public Backend { private: - string fb_dn; - int fb_fd; struct fb_fix_screeninfo fb_finfo; unsigned char* fb_data; + ~FBDevBackend(); + void FbDevIoctlHelper(unsigned long request, void* data, string errmsg); cairo_surface_t* createSurface(); - void destroySurface(); void setWidth(int width); void setHeight(int height); @@ -37,13 +36,15 @@ class FBDevBackend : public Backend }; -class FBDevBackendException : public std::exception { +class FBDevBackendException : public std::exception +{ private: string err_msg; public: FBDevBackendException(const string msg) : err_msg(msg) {}; ~FBDevBackendException() throw() {}; + const char *what() const throw() { return this->err_msg.c_str(); }; }; diff --git a/src/backend/ImageBackend.cc b/src/backend/ImageBackend.cc index b0c852a1d..39d912bdb 100644 --- a/src/backend/ImageBackend.cc +++ b/src/backend/ImageBackend.cc @@ -1,11 +1,9 @@ #include "ImageBackend.h" ImageBackend::ImageBackend(int width, int height) -: Backend("image") -{ - this->width = width; - this->height = height; -} + : Backend("image", width, height) +{} + cairo_surface_t* ImageBackend::createSurface() { diff --git a/src/backend/X11Backend.cc b/src/backend/X11Backend.cc index a119bdeba..1d08efbc1 100644 --- a/src/backend/X11Backend.cc +++ b/src/backend/X11Backend.cc @@ -1,43 +1,33 @@ #include "X11Backend.h" X11Backend::X11Backend(int width, int height) -: Backend("x11") -{ - this->width = width; - this->height = height; -} - - -cairo_surface_t* X11Backend::createSurface() + : Backend("x11", width, height) { display = XOpenDisplay(NULL); - if(!display) - { - std::ostringstream o; - o << "Can't open display. Is DISPLAY set?\n"; - throw X11BackendException(o.str()); - } - - this->window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, + if(!display) + throw X11BackendException("Can't open display. Is DISPLAY set?\n"); + + this->window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, this->width, this->height, 0, 0, BlackPixel(display, 0)); - XSelectInput(display, this->window, StructureNotifyMask | ExposureMask); - XMapWindow(display, this->window); + XSelectInput(display, this->window, StructureNotifyMask | ExposureMask); + XMapWindow(display, this->window); +} - this->surface = cairo_xlib_surface_create(display, this->window, - DefaultVisual(display, 0), this->width, this->height); +X11Backend::~X11Backend() +{ + this->destroySurface(); - return this->surface; + XCloseDisplay(this->display); } -void X11Backend::destroySurface() + +cairo_surface_t* X11Backend::createSurface() { - if(this->surface) - { - Backend::destroySurface(); + this->surface = cairo_xlib_surface_create(display, this->window, + DefaultVisual(display, 0), this->width, this->height); - XCloseDisplay(this->display); - } + return this->surface; } diff --git a/src/backend/X11Backend.h b/src/backend/X11Backend.h index ee0d8c550..587004de2 100644 --- a/src/backend/X11Backend.h +++ b/src/backend/X11Backend.h @@ -13,6 +13,8 @@ class X11Backend : public Backend Display* display; Window window; + ~X11Backend(); + cairo_surface_t* createSurface(); void destroySurface(); @@ -27,6 +29,7 @@ class X11Backend : public Backend static NAN_METHOD(New); }; + class X11BackendException : public std::exception { private: string err_msg; From 4c41045897a870df2ca27e4831c19d04fb8b665e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sun, 12 Jul 2015 10:36:27 +0200 Subject: [PATCH 051/183] Fix for MacBook framebuffer & better FbDev example --- examples/simple_fbdev.js | 18 ++++++++++++++++-- src/backend/FBDevBackend.cc | 4 +--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/examples/simple_fbdev.js b/examples/simple_fbdev.js index 7dbd8e824..d77511a4f 100755 --- a/examples/simple_fbdev.js +++ b/examples/simple_fbdev.js @@ -7,16 +7,30 @@ var fs = require('fs'); var Canvas = require('..'); +const squareSize = 100 + var device = process.argv[2] || "/dev/fb0" var backend = new Canvas.backends.FBDevBackend(device); var canvas = new Canvas(backend); var ctx = canvas.getContext('2d'); -console.log("Width: " + canvas.width + ", Height: " + canvas.height); +var offsetX = canvas.width-squareSize +var offsetY = canvas.height-squareSize + +ctx.fillStyle = "#FF0000"; +ctx.fillRect(0, 0, squareSize, squareSize); ctx.fillStyle = "#00FF00"; -ctx.fillRect(50, 50, 100, 100); +ctx.fillRect(offsetX, 0, squareSize, squareSize); + +ctx.fillStyle = "#0000FF"; +ctx.fillRect(0, offsetY, squareSize, squareSize); + +ctx.fillStyle = "#FFFFFF"; +ctx.fillRect(offsetX, offsetY, squareSize, squareSize); + +console.log("Width: " + canvas.width + ", Height: " + canvas.height); var outPath = __dirname + '/rectangle.png'; diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 486b0d8a3..e33b4ccfe 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -76,11 +76,9 @@ cairo_surface_t* FBDevBackend::createSurface() throw FBDevBackendException("Could not determine color format"); } - int stride = cairo_format_stride_for_width(format, fb_vinfo.xres_virtual); - // create cairo surface from data this->surface = cairo_image_surface_create_for_data(this->fb_data, format, - this->width, this->height, stride); + this->width, this->height, fb_finfo.line_length); return this->surface; } From 1403e521b21d2c79de0448a9eaecd78262318989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=27piranna?= Date: Mon, 13 Jul 2015 15:10:46 +0200 Subject: [PATCH 052/183] Improved X11 backend (no draw) --- canvas.gypi | 8 +- examples/simple_x11.js | 22 ++ src/backend/X11Backend.cc | 8 +- static/cairo.gyp | 493 ++++++++++++++++++++------------------ 4 files changed, 294 insertions(+), 237 deletions(-) create mode 100755 examples/simple_x11.js diff --git a/canvas.gypi b/canvas.gypi index 4e4961373..29499f4c1 100644 --- a/canvas.gypi +++ b/canvas.gypi @@ -6,6 +6,10 @@ }, 'conditions': [ + ['OS=="win"', + { + 'sources': ['src/backend/Win32Backend.cc'] + }], ['has_FBDev=="true"', { 'defines': ['HAS_FBDEV'], @@ -14,7 +18,8 @@ ['has_X11=="true"', { 'defines': ['HAS_X11'], - 'sources': ['src/backend/X11Backend.cc'] + 'sources': ['src/backend/X11Backend.cc'], + 'libraries': ['-lX11', '-lXrender', '-lXext'] }] ], 'target_name': 'canvas', @@ -23,7 +28,6 @@ [ 'src/backend/Backend.cc', 'src/backend/ImageBackend.cc', - 'src/backend/FBDevBackend.cc', 'src/Backends.cc', 'src/Canvas.cc', 'src/CanvasGradient.cc', diff --git a/examples/simple_x11.js b/examples/simple_x11.js new file mode 100755 index 000000000..87190d6dc --- /dev/null +++ b/examples/simple_x11.js @@ -0,0 +1,22 @@ +#!/usr/bin/env node + +/** +* Module dependencies. +*/ + +var fs = require('fs'); +var Canvas = require('..'); + +var backend = new Canvas.backends.X11Backend(800, 600); +var canvas = new Canvas(backend); +var ctx = canvas.getContext('2d'); + +console.log("Width: " + canvas.width + ", Height: " + canvas.height); + +ctx.fillStyle = "#00FF00"; +ctx.fillRect(50, 50, 100, 100); + +setTimeout(function(){}, 10000) + +//var outPath = __dirname + '/rectangle.png'; +//canvas.createPNGStream().pipe(fs.createWriteStream(outPath)); diff --git a/src/backend/X11Backend.cc b/src/backend/X11Backend.cc index 1d08efbc1..e95dfc3b7 100644 --- a/src/backend/X11Backend.cc +++ b/src/backend/X11Backend.cc @@ -33,11 +33,15 @@ cairo_surface_t* X11Backend::createSurface() void X11Backend::setWidth(int width) { - throw BackendOperationNotAvailable(this, "setWidth()"); + XResizeWindow(this->display, this->window, width, this->height); + + Backend::setWidth(width); } void X11Backend::setHeight(int height) { - throw BackendOperationNotAvailable(this, "setHeight()"); + XResizeWindow(this->display, this->window, this->width, height); + + Backend::setHeight(height); } diff --git a/static/cairo.gyp b/static/cairo.gyp index 47dc5347d..38ac39bca 100644 --- a/static/cairo.gyp +++ b/static/cairo.gyp @@ -1,17 +1,56 @@ { - - 'includes': [ 'common.gyp', 'locations.gyp' ], - - - 'targets': [ - { - 'variables': { - 'cairo_src%': "<(cairo_root)cairo/", - }, - 'target_name': 'cairo', - 'type': 'static_library', - - 'include_dirs': [ + 'includes': ['common.gyp', 'locations.gyp'], + 'conditions': + [ + ['OS!="win"', + { + 'variables': + { + 'cairo_src%': "<(cairo_root)cairo/", + 'has_X11%': ' Date: Thu, 23 Jul 2015 15:20:40 +0200 Subject: [PATCH 053/183] Conditionally compile Xlib backend --- static/cairo.gyp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/static/cairo.gyp b/static/cairo.gyp index 38ac39bca..70cc6bc36 100644 --- a/static/cairo.gyp +++ b/static/cairo.gyp @@ -42,7 +42,16 @@ { 'sources': [ - "<(cairo_src)cairo-xlib-surface.c" + "<(cairo_src)cairo-xlib-core-compositor.c", + "<(cairo_src)cairo-xlib-display.c", + "<(cairo_src)cairo-xlib-fallback-compositor.c", + "<(cairo_src)cairo-xlib-render-compositor.c", + "<(cairo_src)cairo-xlib-screen.c", + "<(cairo_src)cairo-xlib-source.c", + "<(cairo_src)cairo-xlib-surface.c", + "<(cairo_src)cairo-xlib-surface-shm.c", + "<(cairo_src)cairo-xlib-visual.c", + "<(cairo_src)cairo-xlib-xcb-surface.c" ], 'libraries': ['-lX11'] }] @@ -234,15 +243,6 @@ # "<(cairo_src)cairo-xcb-surface.c", # "<(cairo_src)cairo-xcb-surface-core.c", # "<(cairo_src)cairo-xcb-surface-render.c", - "<(cairo_src)cairo-xlib-core-compositor.c", - "<(cairo_src)cairo-xlib-display.c", - "<(cairo_src)cairo-xlib-fallback-compositor.c", - "<(cairo_src)cairo-xlib-render-compositor.c", - "<(cairo_src)cairo-xlib-screen.c", - "<(cairo_src)cairo-xlib-source.c", - "<(cairo_src)cairo-xlib-surface-shm.c", - "<(cairo_src)cairo-xlib-visual.c", - "<(cairo_src)cairo-xlib-xcb-surface.c", #"<(cairo_src)cairo-xml-surface.c", #"<(cairo_src)check-has-hidden-symbols.c", "<(cairo_src)check-link.c", From 5cca798ffb190fc8dd4029e261313a2310f11469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sun, 26 Jul 2015 16:04:58 +0200 Subject: [PATCH 054/183] Removed FbDev formats not available on Cairo 24 bits could be added by using two buffers and a conversion function, but would have a performance penalty --- src/backend/FBDevBackend.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index e33b4ccfe..060d50631 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -67,13 +67,11 @@ cairo_surface_t* FBDevBackend::createSurface() cairo_format_t format; switch(fb_vinfo.bits_per_pixel) { - case 8: format = CAIRO_FORMAT_A8; break; case 16: format = CAIRO_FORMAT_RGB16_565; break; - case 24: format = CAIRO_FORMAT_RGB24; break; case 32: format = CAIRO_FORMAT_ARGB32; break; default: - throw FBDevBackendException("Could not determine color format"); + throw FBDevBackendException("Only valid formats are RGB16_565 & ARGB32"); } // create cairo surface from data From 09aaed008fcc72a6124230268988f80506bf5407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro?= Date: Sat, 14 May 2016 18:40:30 +0200 Subject: [PATCH 055/183] Updated version of libpng --- static/ensure_deps.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/ensure_deps.sh b/static/ensure_deps.sh index 162c41b77..4a82bbd01 100755 --- a/static/ensure_deps.sh +++ b/static/ensure_deps.sh @@ -4,7 +4,7 @@ CAIRO_VERSION=1.12.18 FREETYPE_VERSION=2.6 GIFLIB_VERSION=4.2.3 LIBJPEG_VERSION=1.2.1 -LIBPNG_VERSION=1.2.53 +LIBPNG_VERSION=1.2.56 PIXMAN_VERSION=0.32.6 ZLIB_VERSION=1.2.8 From 7f774d9bb78b0def5f9d901456228cd517419c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Fri, 20 May 2016 22:01:38 +0200 Subject: [PATCH 056/183] Fixed file permissions --- binding.gyp | 0 src/CanvasRenderingContext2d.cc | 0 src/FontFace.cc | 0 src/init.cc | 0 4 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 binding.gyp mode change 100755 => 100644 src/CanvasRenderingContext2d.cc mode change 100755 => 100644 src/FontFace.cc mode change 100755 => 100644 src/init.cc diff --git a/binding.gyp b/binding.gyp old mode 100755 new mode 100644 diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc old mode 100755 new mode 100644 diff --git a/src/FontFace.cc b/src/FontFace.cc old mode 100755 new mode 100644 diff --git a/src/init.cc b/src/init.cc old mode 100755 new mode 100644 From 8bcf82bfc2b6e78f9c3e749519cbd67ad747c91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sun, 11 Sep 2016 04:16:16 +0200 Subject: [PATCH 057/183] Fix rebase to 1.3.15 --- shared.gyp | 56 ++++++++++++--------------------- src/Backends.cc | 8 +++-- src/Backends.h | 10 ++---- src/Canvas.cc | 35 +++++++++++---------- src/Canvas.h | 11 ++++--- src/CanvasRenderingContext2d.cc | 6 ++-- src/backend/Backend.h | 8 +---- src/backend/FBDevBackend.cc | 22 +++++++------ src/backend/FBDevBackend.h | 6 ++-- src/backend/ImageBackend.cc | 23 ++++++++------ src/backend/ImageBackend.h | 6 ++-- src/backend/X11Backend.cc | 23 ++++++++------ src/backend/X11Backend.h | 12 ++++--- static.gyp | 2 +- util/has_lib.sh | 12 +++++-- 15 files changed, 123 insertions(+), 117 deletions(-) diff --git a/shared.gyp b/shared.gyp index 096f7ab05..92323c0c8 100644 --- a/shared.gyp +++ b/shared.gyp @@ -1,18 +1,16 @@ { 'conditions': [ - ['OS=="win"', - { + ['OS=="win"', { 'variables': { - 'GTK_Root%': 'C:/GTK', # Set the location of GTK all-in-one bundle + 'GTK_Root%': 'C:/GTK', # Set the location of GTK all-in-one bundle 'with_jpeg%': 'false', 'with_gif%': 'false', 'with_pango%': 'false', 'with_freetype%': 'false' } - }, - { # 'OS!="win"' + }, { # OS!="win"' 'variables': { 'with_jpeg%': ' target) { - NanScope(); + Nan::HandleScope scope; - Local obj = NanNew(); + Local obj = Nan::New(); ImageBackend::Initialize(obj); #ifdef HAS_FBDEV @@ -22,5 +24,5 @@ void Backends::Initialize(Handle target) { X11Backend::Initialize(obj); #endif - target->Set(NanNew("Backends"), obj); + target->Set(Nan::New("Backends").ToLocalChecked(), obj); } diff --git a/src/Backends.h b/src/Backends.h index 99af93d01..1519883d1 100644 --- a/src/Backends.h +++ b/src/Backends.h @@ -1,20 +1,14 @@ #ifndef __NODE_BACKENDS_H__ #define __NODE_BACKENDS_H__ -#include -#include -#include -#include #include #include "backend/Backend.h" -using namespace v8; -using namespace node; -class Backends : public ObjectWrap { +class Backends : public Nan::ObjectWrap { public: - static void Initialize(Handle target); + static void Initialize(v8::Handle target); }; #endif diff --git a/src/Canvas.cc b/src/Canvas.cc index 82456dd2d..31ff15261 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -70,14 +70,17 @@ NAN_METHOD(Canvas::New) { return Nan::ThrowTypeError("Class constructors cannot be invoked without 'new'"); } + Backend* backend; Canvas *canvas = NULL; - if (args[0]->IsNumber() && args[1]->IsNumber()) { - canvas = new Canvas(new ImageBackend(args[0]->Uint32Value(), args[1]->Uint32Value())); - } else if (args[0]->IsObject()) { - Backend* backend = ObjectWrap::Unwrap(args[0]->ToObject()); - canvas = new Canvas(backend); + if (info[0]->IsNumber() && info[1]->IsNumber()) { + backend = new ImageBackend(info[0]->Uint32Value(), info[1]->Uint32Value()); } + else if (info[0]->IsObject()) { + backend = Nan::ObjectWrap::Unwrap(info[0]->ToObject()); + } + canvas = new Canvas(backend); canvas->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); } @@ -87,7 +90,7 @@ NAN_METHOD(Canvas::New) { NAN_GETTER(Canvas::GetType) { Canvas *canvas = Nan::ObjectWrap::Unwrap(info.This()); - info.GetReturnValue().Set(Nan::New(canvas->backend()->getName()); + info.GetReturnValue().Set(Nan::New(canvas->backend()->getName()).ToLocalChecked()); } /* @@ -178,7 +181,7 @@ Canvas::ToBufferAsync(uv_work_t *req) { * EIO after toBuffer callback. */ -#if !NODE_VERSION_AT_LEAST(0, 6, 0) +#if NODE_VERSION_AT_LEAST(0, 6, 0) void Canvas::ToBufferAsyncAfter(uv_work_t *req) { #else @@ -225,15 +228,15 @@ NAN_METHOD(Canvas::ToBuffer) { uint32_t filter = PNG_ALL_FILTERS; Canvas *canvas = Nan::ObjectWrap::Unwrap(info.This()); - // TODO: async / move this out - if (canvas->isPDF() || canvas->isSVG()) { - cairo_surface_finish(canvas->surface()); - closure_t *closure = (closure_t *) canvas->closure(); - - Local buf = Nan::CopyBuffer((char*) closure->data, closure->len).ToLocalChecked(); - info.GetReturnValue().Set(buf); - return; - } + // // TODO: async / move this out + // if (canvas->isPDF() || canvas->isSVG()) { + // cairo_surface_finish(canvas->surface()); + // closure_t *closure = (closure_t *) canvas->closure(); + // + // Local buf = Nan::CopyBuffer((char*) closure->data, closure->len).ToLocalChecked(); + // info.GetReturnValue().Set(buf); + // return; + // } if (info.Length() > 1 && !(info[1]->IsUndefined() && info[2]->IsUndefined())) { if (!info[1]->IsUndefined()) { diff --git a/src/Canvas.h b/src/Canvas.h index 1b9c291f7..acc2e3179 100644 --- a/src/Canvas.h +++ b/src/Canvas.h @@ -41,7 +41,6 @@ using namespace node; class Canvas: public Nan::ObjectWrap { public: - canvas_type_t type; static Nan::Persistent constructor; static void Initialize(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target); static NAN_METHOD(New); @@ -56,13 +55,17 @@ class Canvas: public Nan::ObjectWrap { static Local Error(cairo_status_t status); static void ToBufferAsync(uv_work_t *req); + #if NODE_VERSION_AT_LEAST(0, 6, 0) static void ToBufferAsyncAfter(uv_work_t *req); + #else + static int EIO_AfterToBuffer(eio_req *req); + #endif inline Backend *backend() { return _backend; } inline cairo_surface_t *surface(){ return backend()->getSurface(); } inline void *closure(){ return _closure; } - inline uint8_t *data(){ return cairo_image_surface_get_data(backend()->getSurface()); } - inline int stride(){ return cairo_image_surface_get_stride(backend()->getSurface()); } + inline uint8_t *data(){ return cairo_image_surface_get_data(surface()); } + inline int stride(){ return cairo_image_surface_get_stride(surface()); } inline int getWidth() { return backend()->getWidth(); } inline int getHeight() { return backend()->getHeight(); } @@ -70,8 +73,6 @@ class Canvas: public Nan::ObjectWrap { Canvas(Backend *backend); void resurface(Local canvas); - inline void *closure(){ return _closure; } - private: ~Canvas(); Backend *_backend; diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 1c078c8ef..7235a8d0e 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -713,8 +713,10 @@ NAN_METHOD(Context2d::GetImageData) { sh = -sh; } - if (sx + sw > canvas->width) sw = canvas->width - sx; - if (sy + sh > canvas->height) sh = canvas->height - sy; + int width = canvas->getWidth(); + int height = canvas->getHeight(); + if (sx + sw > width ) sw = width - sx; + if (sy + sh > height) sh = height - sy; // WebKit/moz functionality. node-canvas used to return in either case. if (sw <= 0) sw = 1; diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 6175ddaff..8cca142a3 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -6,10 +6,6 @@ #include #include -#include -#include -#include -#include #include #if HAVE_PANGO @@ -18,11 +14,9 @@ #include #endif -using namespace v8; -using namespace node; using namespace std; -class Backend : public ObjectWrap +class Backend : public Nan::ObjectWrap { private: const string name; diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 060d50631..581be177c 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -12,6 +12,9 @@ #include "FBDevBackend.h" +using namespace v8; + + FBDevBackend::FBDevBackend(string deviceName) : Backend("fbdev") { @@ -112,25 +115,26 @@ void FBDevBackend::setHeight(int height) } -Persistent FBDevBackend::constructor; +Nan::Persistent FBDevBackend::constructor; void FBDevBackend::Initialize(Handle target) { - NanScope(); - Local ctor = NanNew(FBDevBackend::New); - NanAssignPersistent(FBDevBackend::constructor, ctor); + Nan::HandleScope scope; + + Local ctor = Nan::New(FBDevBackend::New); + FBDevBackend::constructor.Reset(ctor); ctor->InstanceTemplate()->SetInternalFieldCount(1); - ctor->SetClassName(NanNew("FBDevBackend")); - target->Set(NanNew("FBDevBackend"), ctor->GetFunction()); + ctor->SetClassName(Nan::New("FBDevBackend").ToLocalChecked()); + target->Set(Nan::New("FBDevBackend").ToLocalChecked(), ctor->GetFunction()); } NAN_METHOD(FBDevBackend::New) { string fbDevice = "/dev/fb0"; - if(args[0]->IsString()) fbDevice = *String::Utf8Value(args[0].As()); + if(info[0]->IsString()) fbDevice = *String::Utf8Value(info[0].As()); FBDevBackend* backend = new FBDevBackend(fbDevice); - backend->Wrap(args.This()); - NanReturnValue(args.This()); + backend->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); } diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 6a23c5cbd..4f769ac64 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -6,6 +6,8 @@ #include +#include + #include "Backend.h" @@ -30,8 +32,8 @@ class FBDevBackend : public Backend public: FBDevBackend(string deviceName); - static Persistent constructor; - static void Initialize(Handle target); + static Nan::Persistent constructor; + static void Initialize(v8::Handle target); static NAN_METHOD(New); }; diff --git a/src/backend/ImageBackend.cc b/src/backend/ImageBackend.cc index 39d912bdb..2be7a0fd2 100644 --- a/src/backend/ImageBackend.cc +++ b/src/backend/ImageBackend.cc @@ -1,5 +1,7 @@ #include "ImageBackend.h" +using namespace v8; + ImageBackend::ImageBackend(int width, int height) : Backend("image", width, height) {} @@ -13,27 +15,28 @@ cairo_surface_t* ImageBackend::createSurface() } -Persistent ImageBackend::constructor; +Nan::Persistent ImageBackend::constructor; void ImageBackend::Initialize(Handle target) { - NanScope(); - Local ctor = NanNew(ImageBackend::New); - NanAssignPersistent(ImageBackend::constructor, ctor); + Nan::HandleScope scope; + + Local ctor = Nan::New(ImageBackend::New); + ImageBackend::constructor.Reset(ctor); ctor->InstanceTemplate()->SetInternalFieldCount(1); - ctor->SetClassName(NanNew("ImageBackend")); - target->Set(NanNew("ImageBackend"), ctor->GetFunction()); + ctor->SetClassName(Nan::New("ImageBackend").ToLocalChecked()); + target->Set(Nan::New("ImageBackend").ToLocalChecked(), ctor->GetFunction()); } NAN_METHOD(ImageBackend::New) { int width = 0; int height = 0; - if (args[0]->IsNumber()) width = args[0]->Uint32Value(); - if (args[1]->IsNumber()) height = args[1]->Uint32Value(); + if (info[0]->IsNumber()) width = info[0]->Uint32Value(); + if (info[1]->IsNumber()) height = info[1]->Uint32Value(); ImageBackend* backend = new ImageBackend(width, height); - backend->Wrap(args.This()); - NanReturnValue(args.This()); + backend->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); } diff --git a/src/backend/ImageBackend.h b/src/backend/ImageBackend.h index 80075ca02..3ff3d485d 100644 --- a/src/backend/ImageBackend.h +++ b/src/backend/ImageBackend.h @@ -1,6 +1,8 @@ #ifndef __IMAGE_BACKEND_H__ #define __IMAGE_BACKEND_H__ +#include + #include "Backend.h" using namespace std; @@ -13,8 +15,8 @@ class ImageBackend : public Backend public: ImageBackend(int width, int height); - static Persistent constructor; - static void Initialize(Handle target); + static Nan::Persistent constructor; + static void Initialize(v8::Handle target); static NAN_METHOD(New); }; diff --git a/src/backend/X11Backend.cc b/src/backend/X11Backend.cc index e95dfc3b7..2c4714a9a 100644 --- a/src/backend/X11Backend.cc +++ b/src/backend/X11Backend.cc @@ -1,5 +1,7 @@ #include "X11Backend.h" +using namespace v8; + X11Backend::X11Backend(int width, int height) : Backend("x11", width, height) { @@ -45,27 +47,28 @@ void X11Backend::setHeight(int height) } -Persistent X11Backend::constructor; +Nan::Persistent X11Backend::constructor; void X11Backend::Initialize(Handle target) { - NanScope(); - Local ctor = NanNew(X11Backend::New); - NanAssignPersistent(X11Backend::constructor, ctor); + Nan::HandleScope scope; + + Local ctor = Nan::New(X11Backend::New); + X11Backend::constructor.Reset(ctor); ctor->InstanceTemplate()->SetInternalFieldCount(1); - ctor->SetClassName(NanNew("X11Backend")); - target->Set(NanNew("X11Backend"), ctor->GetFunction()); + ctor->SetClassName(Nan::New("X11Backend").ToLocalChecked()); + target->Set(Nan::New("X11Backend").ToLocalChecked(), ctor->GetFunction()); } NAN_METHOD(X11Backend::New) { int width = 0; int height = 0; - if(args[0]->IsNumber()) width = args[0]->Uint32Value(); - if(args[1]->IsNumber()) height = args[1]->Uint32Value(); + if(info[0]->IsNumber()) width = info[0]->Uint32Value(); + if(info[1]->IsNumber()) height = info[1]->Uint32Value(); X11Backend *backend = new X11Backend(width, height); - backend->Wrap(args.This()); - NanReturnValue(args.This()); + backend->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); } diff --git a/src/backend/X11Backend.h b/src/backend/X11Backend.h index 587004de2..b4be0cc61 100644 --- a/src/backend/X11Backend.h +++ b/src/backend/X11Backend.h @@ -1,12 +1,16 @@ #ifndef __X11_BACKEND_H__ #define __X11_BACKEND_H__ -#include "Backend.h" -#include +#include + #include +#include "Backend.h" + + using namespace std; + class X11Backend : public Backend { private: @@ -24,8 +28,8 @@ class X11Backend : public Backend public: X11Backend(int width, int height); - static Persistent constructor; - static void Initialize(Handle target); + static Nan::Persistent constructor; + static void Initialize(v8::Handle target); static NAN_METHOD(New); }; diff --git a/static.gyp b/static.gyp index 51d0d6f6a..42de18de4 100644 --- a/static.gyp +++ b/static.gyp @@ -29,6 +29,6 @@ 'static/gif.gyp:gif', ], 'sources': ['src/FontFace.cc'], - 'defines': ['HAVE_FREETYPE', 'HAVE_JPEG' ,'HAVE_GIF'], + 'defines': ['HAVE_FREETYPE', 'HAVE_JPEG', 'HAVE_GIF'], }] } diff --git a/util/has_lib.sh b/util/has_lib.sh index effdc13ed..5d97d08a6 100755 --- a/util/has_lib.sh +++ b/util/has_lib.sh @@ -36,6 +36,14 @@ has_pkgconfig_lib() { } case "$1" in + cairo) + has_system_lib "cairo" > /dev/null + result=$? + ;; + freetype) + has_freetype > /dev/null + result=$? + ;; gif) has_system_lib "gif" > /dev/null result=$? @@ -48,8 +56,8 @@ case "$1" in has_pkgconfig_lib "pango" > /dev/null result=$? ;; - freetype) - has_freetype > /dev/null + X11) + has_system_lib "X11" > /dev/null result=$? ;; *) From c65bfb94caf91ff55235650e84b5770fb3de2894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sun, 18 Sep 2016 13:23:59 +0200 Subject: [PATCH 058/183] Static build Extracted code for static build from #571 to make it easier to review and approve. It's a squashed version with the final code, for references on the development history and commit logs go to the original issue. --- .gitignore | 2 + .npmignore | 1 + binding.gyp | 176 +------- canvas.gypi | 17 + shared.gyp | 171 ++++++++ src/CanvasRenderingContext2d.cc | 0 src/FontFace.cc | 0 src/init.cc | 0 static.gyp | 34 ++ static/cairo.gyp | 231 +++++++++++ static/common.gyp | 41 ++ static/custom-include/cairo/cairo-features.h | 31 ++ static/custom-include/cairo/config.h | 414 +++++++++++++++++++ static/custom-include/jpeg/config.h | 130 ++++++ static/custom-include/jpeg/jconfig.h | 58 +++ static/custom-include/pixman/config.h | 174 ++++++++ static/custom-include/png/pnglibconf.h | 211 ++++++++++ static/ensure_deps.sh | 68 +++ static/freetype.gyp | 240 +++++++++++ static/gif.gyp | 22 + static/jpeg.gyp | 117 ++++++ static/libpng.gyp | 69 ++++ static/locations.gyp | 11 + static/pixman.gyp | 60 +++ static/zlib.gyp | 60 +++ test/canvas.test.js | 10 +- test/image.test.js | 2 +- test/server.js | 2 +- util/has_lib.sh | 15 +- 29 files changed, 2190 insertions(+), 177 deletions(-) mode change 100755 => 100644 binding.gyp create mode 100644 canvas.gypi create mode 100644 shared.gyp mode change 100755 => 100644 src/CanvasRenderingContext2d.cc mode change 100755 => 100644 src/FontFace.cc mode change 100755 => 100644 src/init.cc create mode 100644 static.gyp create mode 100644 static/cairo.gyp create mode 100644 static/common.gyp create mode 100644 static/custom-include/cairo/cairo-features.h create mode 100644 static/custom-include/cairo/config.h create mode 100644 static/custom-include/jpeg/config.h create mode 100644 static/custom-include/jpeg/jconfig.h create mode 100644 static/custom-include/pixman/config.h create mode 100644 static/custom-include/png/pnglibconf.h create mode 100755 static/ensure_deps.sh create mode 100644 static/freetype.gyp create mode 100644 static/gif.gyp create mode 100644 static/jpeg.gyp create mode 100644 static/libpng.gyp create mode 100644 static/locations.gyp create mode 100644 static/pixman.gyp create mode 100644 static/zlib.gyp diff --git a/.gitignore b/.gitignore index 130894492..cb875df99 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ out.pdf out.svg .pomo node_modules +deps/ +npm-debug.log # Vim cruft *.swp diff --git a/.npmignore b/.npmignore index e91e1490a..acdcedf90 100644 --- a/.npmignore +++ b/.npmignore @@ -4,3 +4,4 @@ benchmarks examples support test +deps diff --git a/binding.gyp b/binding.gyp old mode 100755 new mode 100644 index 66f0115ed..63b95cc94 --- a/binding.gyp +++ b/binding.gyp @@ -1,170 +1,16 @@ { - 'conditions': [ - ['OS=="win"', { - 'variables': { - 'GTK_Root%': 'C:/GTK', # Set the location of GTK all-in-one bundle - 'with_jpeg%': 'false', - 'with_gif%': 'false', - 'with_pango%': 'false', - 'with_freetype%': 'false' - } - }, { # 'OS!="win"' - 'variables': { - 'with_jpeg%': ' header file. */ +#define HAVE_BYTESWAP_H 1 + +/* Define to 1 if you have the `clock_gettime' function. */ +#define HAVE_CLOCK_GETTIME 1 + +/* Define to 1 if you have the `ctime_r' function. */ +#define HAVE_CTIME_R 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `drand48' function. */ +#define HAVE_DRAND48 1 + +/* Define to 1 if you have the `FcFini' function. */ +#define HAVE_FCFINI 1 + +/* Define to 1 if you have the `FcInit' function. */ +#define HAVE_FCINIT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `feclearexcept' function. */ +#define HAVE_FECLEAREXCEPT 1 + +/* Define to 1 if you have the `fedisableexcept' function. */ +#define HAVE_FEDISABLEEXCEPT 1 + +/* Define to 1 if you have the `feenableexcept' function. */ +#define HAVE_FEENABLEEXCEPT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FENV_H 1 + +/* Define to 1 if you have the `flockfile' function. */ +#define HAVE_FLOCKFILE 1 + +/* Define to 1 if you have the `fork' function. */ +#define HAVE_FORK 1 + +/* Define to 1 if you have the `FT_Get_X11_Font_Format' function. */ +#define HAVE_FT_GET_X11_FONT_FORMAT 1 + +/* Define to 1 if you have the `FT_GlyphSlot_Embolden' function. */ +#define HAVE_FT_GLYPHSLOT_EMBOLDEN 1 + +/* Define to 1 if you have the `FT_GlyphSlot_Oblique' function. */ +#define HAVE_FT_GLYPHSLOT_OBLIQUE 1 + +/* Define to 1 if you have the `FT_Library_SetLcdFilter' function. */ +#define HAVE_FT_LIBRARY_SETLCDFILTER 1 + +/* Define to 1 if you have the `FT_Load_Sfnt_Table' function. */ +#define HAVE_FT_LOAD_SFNT_TABLE 1 + +/* Define to 1 if you have the `funlockfile' function. */ +#define HAVE_FUNLOCKFILE 1 + +/* Whether you have gcov */ +/* #undef HAVE_GCOV */ + +/* Define to 1 if you have the `getline' function. */ +#define HAVE_GETLINE 1 + +/* Enable if your compiler supports the Intel __sync_* atomic primitives */ +#define HAVE_INTEL_ATOMIC_PRIMITIVES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_IO_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LIBGEN_H 1 + +/* Define to 1 if you have the `rt' library (-lrt). */ +#define HAVE_LIBRT 1 + +/* Enable if you have libatomic-ops-dev installed */ +/* #undef HAVE_LIB_ATOMIC_OPS */ + +/* Define to 1 if you have the `link' function. */ +#define HAVE_LINK 1 + +/* Define to 1 if you have the Valgrind lockdep tool */ +/* #undef HAVE_LOCKDEP */ + +/* Define to 1 if you have lzo available */ +/* #undef HAVE_LZO */ + +/* Define to 1 if you have the Valgrind memfault tool */ +/* #undef HAVE_MEMFAULT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to non-zero if your system has mkdir, and to 2 if your version of + mkdir requires a mode parameter */ +#define HAVE_MKDIR 2 + +/* Define to 1 if you have the `mmap' function. */ +#define HAVE_MMAP 1 + +/* Enable if you have MacOS X atomic operations */ +/* #undef HAVE_OS_ATOMIC_OPS */ + +/* Define to 1 if you have the `poppler_page_render' function. */ +/* #undef HAVE_POPPLER_PAGE_RENDER */ + +/* Define to 1 if you have the `raise' function. */ +#define HAVE_RAISE 1 + +/* Define to 1 if you have the `rsvg_pixbuf_from_file' function. */ +/* #undef HAVE_RSVG_PIXBUF_FROM_FILE */ + +/* Define to 1 if you have the `sched_getaffinity' function. */ +#define HAVE_SCHED_GETAFFINITY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SCHED_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SETJMP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strndup' function. */ +#define HAVE_STRNDUP 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_INT_TYPES_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_MMAN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_POLL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_WAIT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TIME_H 1 + +/* Define to 1 if the system has the type `uint128_t'. */ +/* #undef HAVE_UINT128_T */ + +/* Define to 1 if the system has the type `uint64_t'. */ +#define HAVE_UINT64_T 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have Valgrind */ +/* #undef HAVE_VALGRIND */ + +/* Define to 1 if you have the `waitpid' function. */ +#define HAVE_WAITPID 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_X11_EXTENSIONS_SHMPROTO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_X11_EXTENSIONS_SHMSTR_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_X11_EXTENSIONS_XSHM_H 1 + +/* Define to 1 if you have the `XRenderCreateConicalGradient' function. */ +#define HAVE_XRENDERCREATECONICALGRADIENT 1 + +/* Define to 1 if you have the `XRenderCreateLinearGradient' function. */ +#define HAVE_XRENDERCREATELINEARGRADIENT 1 + +/* Define to 1 if you have the `XRenderCreateRadialGradient' function. */ +#define HAVE_XRENDERCREATERADIALGRADIENT 1 + +/* Define to 1 if you have zlib available */ +#define HAVE_ZLIB 1 + +/* Define to 1 if the system has the type `__uint128_t'. */ +#define HAVE___UINT128_T 1 + +/* Define to 1 if shared memory segments are released deferred. */ +#define IPC_RMID_DEFERRED_RELEASE 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "http://bugs.freedesktop.org/enter_bug.cgi?product=cairo" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME USE_cairo_INSTEAD + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING USE_cairo_version_OR_cairo_version_string_INSTEAD + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME USE_cairo_INSTEAD + +/* Define to the home page for this package. */ +#define PACKAGE_URL "http://cairographics.org/" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION USE_cairo_version_OR_cairo_version_string_INSTEAD + +/* Shared library file extension */ +#define SHARED_LIB_EXT "so" + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 8 + +/* The size of `long long', as computed by sizeof. */ +#define SIZEOF_LONG_LONG 8 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 8 + +/* The size of `void *', as computed by sizeof. */ +#define SIZEOF_VOID_P 8 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif + + +/* Define to the value your compiler uses to support the warn-unused-result + attribute */ +#define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + + +/* Deal with multiple architecture compiles on Mac OS X */ +#ifdef __APPLE_CC__ +#ifdef __BIG_ENDIAN__ +#define WORDS_BIGENDIAN 1 +#define FLOAT_WORDS_BIGENDIAN 1 +#else +/* #undef WORDS_BIGENDIAN */ +/* #undef FLOAT_WORDS_BIGENDIAN */ +#endif +#endif + + +/* Define to 1 if the X Window System is missing or not being used. */ +/* #undef X_DISPLAY_MISSING */ + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to 1 if on MINIX. */ +/* #undef _MINIX */ + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +/* #undef _POSIX_1_SOURCE */ + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +/* #undef _POSIX_SOURCE */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif diff --git a/static/custom-include/jpeg/config.h b/static/custom-include/jpeg/config.h new file mode 100644 index 000000000..4eb5767b0 --- /dev/null +++ b/static/custom-include/jpeg/config.h @@ -0,0 +1,130 @@ +/* config.h. Generated by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Build number */ +#define BUILD "20131027" + +/* Support arithmetic encoding */ +#define C_ARITH_CODING_SUPPORTED 1 + +/* Support arithmetic decoding */ +#define D_ARITH_CODING_SUPPORTED 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_JNI_H */ + +/* Define to 1 if you have the `memcpy' function. */ +#define HAVE_MEMCPY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `memset' function. */ +#define HAVE_MEMSET 1 + +/* Define if your compiler supports prototypes */ +#define HAVE_PROTOTYPES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDDEF_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if the system has the type `unsigned char'. */ +#define HAVE_UNSIGNED_CHAR 1 + +/* Define to 1 if the system has the type `unsigned short'. */ +#define HAVE_UNSIGNED_SHORT 1 + +/* Compiler does not support pointers to undefined structures. */ +/* #undef INCOMPLETE_TYPES_BROKEN */ + +/* How to obtain function inlining. */ +#define INLINE __attribute__((always_inline)) + +/* libjpeg API version */ +#define JPEG_LIB_VERSION 62 + +/* libjpeg-turbo version */ +#define LIBJPEG_TURBO_VERSION 1.2.1 + +/* Define if you have BSD-like bzero and bcopy */ +/* #undef NEED_BSD_STRINGS */ + +/* Define if you need short function names */ +/* #undef NEED_SHORT_EXTERNAL_NAMES */ + +/* Define if you have sys/types.h */ +#define NEED_SYS_TYPES_H 1 + +/* Name of package */ +#define PACKAGE "libjpeg-turbo" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "libjpeg-turbo" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "libjpeg-turbo 1.2.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "libjpeg-turbo" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.2.1" + +/* Define if shift is unsigned */ +/* #undef RIGHT_SHIFT_IS_UNSIGNED */ + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "1.2.1" + +/* Use accelerated SIMD routines. */ +/* #undef WITH_SIMD */ + +/* Define to 1 if type `char' is unsigned and you are not using gcc. */ +#ifndef __CHAR_UNSIGNED__ +/* # undef __CHAR_UNSIGNED__ */ +#endif + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to `unsigned' if does not define. */ +/* #undef size_t */ diff --git a/static/custom-include/jpeg/jconfig.h b/static/custom-include/jpeg/jconfig.h new file mode 100644 index 000000000..07676e4e2 --- /dev/null +++ b/static/custom-include/jpeg/jconfig.h @@ -0,0 +1,58 @@ +/* jconfig.h. Generated by configure. */ +/* Version ID for the JPEG library. + * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60". + */ +#define JPEG_LIB_VERSION 62 + +/* libjpeg-turbo version */ +#define LIBJPEG_TURBO_VERSION 1.2.1 + +/* Support arithmetic encoding */ +#define C_ARITH_CODING_SUPPORTED 1 + +/* Support arithmetic decoding */ +#define D_ARITH_CODING_SUPPORTED 1 + +/* Compiler supports function prototypes. */ +#define HAVE_PROTOTYPES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDDEF_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Compiler supports 'unsigned char'. */ +#define HAVE_UNSIGNED_CHAR 1 + +/* Compiler supports 'unsigned short'. */ +#define HAVE_UNSIGNED_SHORT 1 + +/* Compiler does not support pointers to unspecified structures. */ +/* #undef INCOMPLETE_TYPES_BROKEN */ + +/* Compiler has rather than standard . */ +/* #undef NEED_BSD_STRINGS */ + +/* Linker requires that global names be unique in first 15 characters. */ +/* #undef NEED_SHORT_EXTERNAL_NAMES */ + +/* Need to include in order to obtain size_t. */ +#define NEED_SYS_TYPES_H 1 + +/* Broken compiler shifts signed values as an unsigned shift. */ +/* #undef RIGHT_SHIFT_IS_UNSIGNED */ + +/* Use accelerated SIMD routines. */ +/* #undef WITH_SIMD */ + +/* Define to 1 if type `char' is unsigned and you are not using gcc. */ +#ifndef __CHAR_UNSIGNED__ +/* # undef __CHAR_UNSIGNED__ */ +#endif + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ diff --git a/static/custom-include/pixman/config.h b/static/custom-include/pixman/config.h new file mode 100644 index 000000000..a6d2c02ef --- /dev/null +++ b/static/custom-include/pixman/config.h @@ -0,0 +1,174 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* Whether we have alarm() */ +#define HAVE_ALARM 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Whether we have feenableexcept() */ +#define HAVE_FEENABLEEXCEPT 1 + +/* Define to 1 if we have */ +#define HAVE_FENV_H 1 + +/* Whether the tool chain supports __float128 */ +#define HAVE_FLOAT128 /**/ + +/* Define to 1 if you have the `getisax' function. */ +/* #undef HAVE_GETISAX */ + +/* Whether we have getpagesize() */ +#define HAVE_GETPAGESIZE 1 + +/* Whether we have gettimeofday() */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `pixman-1' library (-lpixman-1). */ +/* #undef HAVE_LIBPIXMAN_1 */ + +/* Whether we have libpng */ +#define HAVE_LIBPNG 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Whether we have mmap() */ +#define HAVE_MMAP 1 + +/* Whether we have mprotect() */ +#define HAVE_MPROTECT 1 + +/* Whether we have posix_memalign() */ +#define HAVE_POSIX_MEMALIGN 1 + +/* Whether pthread_setspecific() is supported */ +/* #undef HAVE_PTHREAD_SETSPECIFIC */ + +/* Whether we have sigaction() */ +#define HAVE_SIGACTION 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if we have */ +#define HAVE_SYS_MMAN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "pixman" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "pixman@lists.freedesktop.org" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "pixman" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "pixman 0.30.2" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "pixman" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "0.30.2" + +/* enable TIMER_BEGIN/TIMER_END macros */ +/* #undef PIXMAN_TIMERS */ + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 8 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* The compiler supported TLS storage class */ +#define TLS __thread + +/* Whether the tool chain supports __attribute__((constructor)) */ +#define TOOLCHAIN_SUPPORTS_ATTRIBUTE_CONSTRUCTOR /**/ + +/* use ARM IWMMXT compiler intrinsics */ +/* #undef USE_ARM_IWMMXT */ + +/* use ARM NEON assembly optimizations */ +/* #undef USE_ARM_NEON */ + +/* use ARM SIMD assembly optimizations */ +/* #undef USE_ARM_SIMD */ + +/* use GNU-style inline assembler */ +#define USE_GCC_INLINE_ASM 1 + +/* use Loongson Multimedia Instructions */ +/* #undef USE_LOONGSON_MMI */ + +/* use MIPS DSPr2 assembly optimizations */ +/* #undef USE_MIPS_DSPR2 */ + +/* use OpenMP in the test suite */ +#define USE_OPENMP 1 + +/* use SSE2 compiler intrinsics */ +#define USE_SSE2 1 + +/* use VMX compiler intrinsics */ +/* #undef USE_VMX */ + +/* use x86 MMX compiler intrinsics */ +#define USE_X86_MMX 1 + +/* Version number of package */ +#define VERSION "0.30.2" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to sqrt if you do not have the `sqrtf' function. */ +/* #undef sqrtf */ diff --git a/static/custom-include/png/pnglibconf.h b/static/custom-include/png/pnglibconf.h new file mode 100644 index 000000000..e31ff3dec --- /dev/null +++ b/static/custom-include/png/pnglibconf.h @@ -0,0 +1,211 @@ +/* libpng 1.6.6 STANDARD API DEFINITION */ + +/* pnglibconf.h - library build configuration */ + +/* Libpng version 1.6.6 - September 16, 2013 */ + +/* Copyright (c) 1998-2013 Glenn Randers-Pehrson */ + +/* This code is released under the libpng license. */ +/* For conditions of distribution and use, see the disclaimer */ +/* and license in png.h */ + +/* pnglibconf.h */ +/* Machine generated file: DO NOT EDIT */ +/* Derived from: scripts/pnglibconf.dfa */ +#ifndef PNGLCONF_H +#define PNGLCONF_H +/* options */ +#define PNG_16BIT_SUPPORTED +#define PNG_ALIGNED_MEMORY_SUPPORTED +/*#undef PNG_ARM_NEON_API_SUPPORTED*/ +/*#undef PNG_ARM_NEON_CHECK_SUPPORTED*/ +#define PNG_BENIGN_ERRORS_SUPPORTED +#define PNG_BENIGN_READ_ERRORS_SUPPORTED +/*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/ +#define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED +#define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED +#define PNG_COLORSPACE_SUPPORTED +#define PNG_CONSOLE_IO_SUPPORTED +#define PNG_CONVERT_tIME_SUPPORTED +#define PNG_EASY_ACCESS_SUPPORTED +/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/ +#define PNG_ERROR_TEXT_SUPPORTED +#define PNG_FIXED_POINT_SUPPORTED +#define PNG_FLOATING_ARITHMETIC_SUPPORTED +#define PNG_FLOATING_POINT_SUPPORTED +#define PNG_FORMAT_AFIRST_SUPPORTED +#define PNG_FORMAT_BGR_SUPPORTED +#define PNG_GAMMA_SUPPORTED +#define PNG_GET_PALETTE_MAX_SUPPORTED +#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED +#define PNG_INCH_CONVERSIONS_SUPPORTED +#define PNG_INFO_IMAGE_SUPPORTED +#define PNG_IO_STATE_SUPPORTED +#define PNG_MNG_FEATURES_SUPPORTED +#define PNG_POINTER_INDEXING_SUPPORTED +#define PNG_PROGRESSIVE_READ_SUPPORTED +#define PNG_READ_16BIT_SUPPORTED +#define PNG_READ_ALPHA_MODE_SUPPORTED +#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED +#define PNG_READ_BACKGROUND_SUPPORTED +#define PNG_READ_BGR_SUPPORTED +#define PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED +#define PNG_READ_COMPOSITE_NODIV_SUPPORTED +#define PNG_READ_COMPRESSED_TEXT_SUPPORTED +#define PNG_READ_EXPAND_16_SUPPORTED +#define PNG_READ_EXPAND_SUPPORTED +#define PNG_READ_FILLER_SUPPORTED +#define PNG_READ_GAMMA_SUPPORTED +#define PNG_READ_GET_PALETTE_MAX_SUPPORTED +#define PNG_READ_GRAY_TO_RGB_SUPPORTED +#define PNG_READ_INTERLACING_SUPPORTED +#define PNG_READ_INT_FUNCTIONS_SUPPORTED +#define PNG_READ_INVERT_ALPHA_SUPPORTED +#define PNG_READ_INVERT_SUPPORTED +#define PNG_READ_OPT_PLTE_SUPPORTED +#define PNG_READ_PACKSWAP_SUPPORTED +#define PNG_READ_PACK_SUPPORTED +#define PNG_READ_QUANTIZE_SUPPORTED +#define PNG_READ_RGB_TO_GRAY_SUPPORTED +#define PNG_READ_SCALE_16_TO_8_SUPPORTED +#define PNG_READ_SHIFT_SUPPORTED +#define PNG_READ_STRIP_16_TO_8_SUPPORTED +#define PNG_READ_STRIP_ALPHA_SUPPORTED +#define PNG_READ_SUPPORTED +#define PNG_READ_SWAP_ALPHA_SUPPORTED +#define PNG_READ_SWAP_SUPPORTED +#define PNG_READ_TEXT_SUPPORTED +#define PNG_READ_TRANSFORMS_SUPPORTED +#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_READ_USER_CHUNKS_SUPPORTED +#define PNG_READ_USER_TRANSFORM_SUPPORTED +#define PNG_READ_bKGD_SUPPORTED +#define PNG_READ_cHRM_SUPPORTED +#define PNG_READ_gAMA_SUPPORTED +#define PNG_READ_hIST_SUPPORTED +#define PNG_READ_iCCP_SUPPORTED +#define PNG_READ_iTXt_SUPPORTED +#define PNG_READ_oFFs_SUPPORTED +#define PNG_READ_pCAL_SUPPORTED +#define PNG_READ_pHYs_SUPPORTED +#define PNG_READ_sBIT_SUPPORTED +#define PNG_READ_sCAL_SUPPORTED +#define PNG_READ_sPLT_SUPPORTED +#define PNG_READ_sRGB_SUPPORTED +#define PNG_READ_tEXt_SUPPORTED +#define PNG_READ_tIME_SUPPORTED +#define PNG_READ_tRNS_SUPPORTED +#define PNG_READ_zTXt_SUPPORTED +/*#undef PNG_SAFE_LIMITS_SUPPORTED*/ +#define PNG_SAVE_INT_32_SUPPORTED +#define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_SEQUENTIAL_READ_SUPPORTED +#define PNG_SETJMP_SUPPORTED +#define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED +#define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED +#define PNG_SET_OPTION_SUPPORTED +#define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_SET_USER_LIMITS_SUPPORTED +#define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED +#define PNG_SIMPLIFIED_READ_BGR_SUPPORTED +#define PNG_SIMPLIFIED_READ_SUPPORTED +#define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED +#define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED +#define PNG_SIMPLIFIED_WRITE_SUPPORTED +#define PNG_STDIO_SUPPORTED +#define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_TEXT_SUPPORTED +#define PNG_TIME_RFC1123_SUPPORTED +#define PNG_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_USER_CHUNKS_SUPPORTED +#define PNG_USER_LIMITS_SUPPORTED +#define PNG_USER_MEM_SUPPORTED +#define PNG_USER_TRANSFORM_INFO_SUPPORTED +#define PNG_USER_TRANSFORM_PTR_SUPPORTED +#define PNG_WARNINGS_SUPPORTED +#define PNG_WRITE_16BIT_SUPPORTED +#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED +#define PNG_WRITE_BGR_SUPPORTED +#define PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED +#define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED +#define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED +#define PNG_WRITE_FILLER_SUPPORTED +#define PNG_WRITE_FILTER_SUPPORTED +#define PNG_WRITE_FLUSH_SUPPORTED +#define PNG_WRITE_GET_PALETTE_MAX_SUPPORTED +#define PNG_WRITE_INTERLACING_SUPPORTED +#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED +#define PNG_WRITE_INVERT_ALPHA_SUPPORTED +#define PNG_WRITE_INVERT_SUPPORTED +#define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED +#define PNG_WRITE_PACKSWAP_SUPPORTED +#define PNG_WRITE_PACK_SUPPORTED +#define PNG_WRITE_SHIFT_SUPPORTED +#define PNG_WRITE_SUPPORTED +#define PNG_WRITE_SWAP_ALPHA_SUPPORTED +#define PNG_WRITE_SWAP_SUPPORTED +#define PNG_WRITE_TEXT_SUPPORTED +#define PNG_WRITE_TRANSFORMS_SUPPORTED +#define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED +#define PNG_WRITE_USER_TRANSFORM_SUPPORTED +#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED +#define PNG_WRITE_bKGD_SUPPORTED +#define PNG_WRITE_cHRM_SUPPORTED +#define PNG_WRITE_gAMA_SUPPORTED +#define PNG_WRITE_hIST_SUPPORTED +#define PNG_WRITE_iCCP_SUPPORTED +#define PNG_WRITE_iTXt_SUPPORTED +#define PNG_WRITE_oFFs_SUPPORTED +#define PNG_WRITE_pCAL_SUPPORTED +#define PNG_WRITE_pHYs_SUPPORTED +#define PNG_WRITE_sBIT_SUPPORTED +#define PNG_WRITE_sCAL_SUPPORTED +#define PNG_WRITE_sPLT_SUPPORTED +#define PNG_WRITE_sRGB_SUPPORTED +#define PNG_WRITE_tEXt_SUPPORTED +#define PNG_WRITE_tIME_SUPPORTED +#define PNG_WRITE_tRNS_SUPPORTED +#define PNG_WRITE_zTXt_SUPPORTED +#define PNG_bKGD_SUPPORTED +#define PNG_cHRM_SUPPORTED +#define PNG_gAMA_SUPPORTED +#define PNG_hIST_SUPPORTED +#define PNG_iCCP_SUPPORTED +#define PNG_iTXt_SUPPORTED +#define PNG_oFFs_SUPPORTED +#define PNG_pCAL_SUPPORTED +#define PNG_pHYs_SUPPORTED +#define PNG_sBIT_SUPPORTED +#define PNG_sCAL_SUPPORTED +#define PNG_sPLT_SUPPORTED +#define PNG_sRGB_SUPPORTED +#define PNG_tEXt_SUPPORTED +#define PNG_tIME_SUPPORTED +#define PNG_tRNS_SUPPORTED +#define PNG_zTXt_SUPPORTED +/* end of options */ +/* settings */ +#define PNG_API_RULE 0 +#define PNG_CALLOC_SUPPORTED +#define PNG_COST_SHIFT 3 +#define PNG_DEFAULT_READ_MACROS 1 +#define PNG_GAMMA_THRESHOLD_FIXED 5000 +#define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE +#define PNG_INFLATE_BUF_SIZE 1024 +#define PNG_MAX_GAMMA_8 11 +#define PNG_QUANTIZE_BLUE_BITS 5 +#define PNG_QUANTIZE_GREEN_BITS 5 +#define PNG_QUANTIZE_RED_BITS 5 +#define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1) +#define PNG_TEXT_Z_DEFAULT_STRATEGY 0 +#define PNG_WEIGHT_SHIFT 8 +#define PNG_ZBUF_SIZE 8192 +#define PNG_ZLIB_VERNUM 0 /* unknown */ +#define PNG_Z_DEFAULT_COMPRESSION (-1) +#define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0 +#define PNG_Z_DEFAULT_STRATEGY 1 +#define PNG_sCAL_PRECISION 5 +#define PNG_sRGB_PROFILE_CHECKS 2 +/* end of settings */ +#endif /* PNGLCONF_H */ diff --git a/static/ensure_deps.sh b/static/ensure_deps.sh new file mode 100755 index 000000000..4a82bbd01 --- /dev/null +++ b/static/ensure_deps.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +CAIRO_VERSION=1.12.18 +FREETYPE_VERSION=2.6 +GIFLIB_VERSION=4.2.3 +LIBJPEG_VERSION=1.2.1 +LIBPNG_VERSION=1.2.56 +PIXMAN_VERSION=0.32.6 +ZLIB_VERSION=1.2.8 + +CAIRO_URL=http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz +FONTCONFIG_URL=http://cgit.freedesktop.org/fontconfig/plain/fontconfig/fontconfig.h +FREETYPE_URL=http://download.savannah.gnu.org/releases/freetype/freetype-$FREETYPE_VERSION.tar.gz +GIFLIB_URL=http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-$GIFLIB_VERSION.tar.gz +LIBJPEG_URL=http://downloads.sourceforge.net/project/libjpeg-turbo/$LIBJPEG_VERSION/libjpeg-turbo-$LIBJPEG_VERSION.tar.gz +LIBPNG_URL=http://sourceforge.net/projects/libpng/files/libpng12/$LIBPNG_VERSION/libpng-$LIBPNG_VERSION.tar.xz +PIXMAN_URL=http://cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz +ZLIB_URL=http://zlib.net/zlib-$ZLIB_VERSION.tar.gz + + +DEPS="$(dirname $0)/../deps" + +mkdir -p $DEPS +cd $DEPS + + +fetch() +{ + if [ ! -d $2 ]; then + mkdir -p $2 && + curl -s -L $1 | tar xzf - -C $2 --strip-components=1 || exit $? + fi +} + +fetch_xz() +{ + if [ ! -d $2 ]; then + mkdir -p $2 && + curl -s -L $1 | tar xJf - -C $2 --strip-components=1 || exit $? + fi +} + + +if [ ! -d cairo ]; then + fetch_xz $CAIRO_URL cairo && + mv cairo/src cairo/cairo || exit $? +fi + +if [ ! -d fontconfig ]; then + mkdir -p fontconfig && + curl -s -L $FONTCONFIG_URL >> fontconfig/fontconfig.h || exit $? +fi + +fetch $FREETYPE_URL freetype && +fetch $GIFLIB_URL giflib && +fetch $LIBJPEG_URL libjpeg && +fetch_xz $LIBPNG_URL libpng && +fetch $PIXMAN_URL pixman && +fetch $ZLIB_URL zlib || exit $? + + +if [ ! -d "cairo" ] || [ ! -d "freetype" ] || [ ! -d "giflib" ] \ +|| [ ! -d "libjpeg" ] || [ ! -d "libpng" ] || [ ! -d "pixman" ] \ +|| [ ! -d "zlib" ]; then + echo false +else + echo true +fi diff --git a/static/freetype.gyp b/static/freetype.gyp new file mode 100644 index 000000000..ed176039e --- /dev/null +++ b/static/freetype.gyp @@ -0,0 +1,240 @@ +{ + 'includes': [ 'common.gyp' , 'locations.gyp'], + 'targets': [ + { + 'target_name': 'freetype', + 'type': 'static_library', + 'include_dirs': [ '<(freetype_root)include/'], + + 'defines': [ 'FT2_BUILD_LIBRARY' ], + 'sources': [ + #"<(freetype_root)src/autofit/afangles.c", + #"<(freetype_root)src/autofit/afcjk.c", + #"<(freetype_root)src/autofit/afdummy.c", + #"<(freetype_root)src/autofit/afglobal.c", + #"<(freetype_root)src/autofit/afhints.c", + #"<(freetype_root)src/autofit/afindic.c", + #"<(freetype_root)src/autofit/aflatin2.c", + #"<(freetype_root)src/autofit/aflatin.c", + #"<(freetype_root)src/autofit/afloader.c", + #"<(freetype_root)src/autofit/afmodule.c", + #"<(freetype_root)src/autofit/afpic.c", + #"<(freetype_root)src/autofit/afwarp.c", + "<(freetype_root)src/autofit/autofit.c", + + #"<(freetype_root)src/base/basepic.c", + #"<(freetype_root)src/base/ftadvanc.c", + #"<(freetype_root)src/base/ftapi.c", + "<(freetype_root)src/base/ftbase.c", + #"<(freetype_root)src/base/ftbbox.c", + "<(freetype_root)src/base/ftbitmap.c", + #"<(freetype_root)src/base/ftcalc.c", + #"<(freetype_root)src/base/ftcid.c", + #"<(freetype_root)src/base/ftdbgmem.c", + #"<(freetype_root)src/base/ftdebug.c", + "<(freetype_root)src/base/ftfntfmt.c", + #"<(freetype_root)src/base/ftfstype.c", + #"<(freetype_root)src/base/ftgasp.c", + #"<(freetype_root)src/base/ftgloadr.c", + #"<(freetype_root)src/base/ftglyph.c", + #"<(freetype_root)src/base/ftgxval.c", + "<(freetype_root)src/base/ftinit.c", + "<(freetype_root)src/base/ftlcdfil.c", + #"<(freetype_root)src/base/ftmac.c", + #"<(freetype_root)src/base/ftmm.c", + #"<(freetype_root)src/base/ftobjs.c", + #"<(freetype_root)src/base/ftotval.c", + #"<(freetype_root)src/base/ftoutln.c", + #"<(freetype_root)src/base/ftpatent.c", + #"<(freetype_root)src/base/ftpfr.c", + #"<(freetype_root)src/base/ftpic.c", + #"<(freetype_root)src/base/ftrfork.c", + #"<(freetype_root)src/base/ftsnames.c", + #"<(freetype_root)src/base/ftstream.c", + #"<(freetype_root)src/base/ftstroke.c", + "<(freetype_root)src/base/ftsynth.c", + "<(freetype_root)src/base/ftsystem.c", + #"<(freetype_root)src/base/fttrigon.c", + #"<(freetype_root)src/base/fttype1.c", + #"<(freetype_root)src/base/ftutil.c", + #"<(freetype_root)src/base/ftwinfnt.c", + #"<(freetype_root)src/base/ftxf86.c", + #"<(freetype_root)src/base/md5.c", + + "<(freetype_root)src/bdf/bdf.c", + #"<(freetype_root)src/bdf/bdfdrivr.c", + #"<(freetype_root)src/bdf/bdflib.c", + + "<(freetype_root)src/bzip2/ftbzip2.c", + + "<(freetype_root)src/cache/ftcache.c", + #"<(freetype_root)src/cache/ftcbasic.c", + #"<(freetype_root)src/cache/ftccache.c", + #"<(freetype_root)src/cache/ftccmap.c", + #"<(freetype_root)src/cache/ftcglyph.c", + #"<(freetype_root)src/cache/ftcimage.c", + #"<(freetype_root)src/cache/ftcmanag.c", + #"<(freetype_root)src/cache/ftcmru.c", + #"<(freetype_root)src/cache/ftcsbits.c", + + #"<(freetype_root)src/cff/cf2arrst.c", + #"<(freetype_root)src/cff/cf2blues.c", + #"<(freetype_root)src/cff/cf2error.c", + #"<(freetype_root)src/cff/cf2font.c", + #"<(freetype_root)src/cff/cf2ft.c", + #"<(freetype_root)src/cff/cf2hints.c", + #"<(freetype_root)src/cff/cf2intrp.c", + #"<(freetype_root)src/cff/cf2read.c", + #"<(freetype_root)src/cff/cf2stack.c", + "<(freetype_root)src/cff/cff.c", + #"<(freetype_root)src/cff/cffcmap.c", + #"<(freetype_root)src/cff/cffdrivr.c", + #"<(freetype_root)src/cff/cffgload.c", + #"<(freetype_root)src/cff/cffload.c", + #"<(freetype_root)src/cff/cffobjs.c", + #"<(freetype_root)src/cff/cffparse.c", + #"<(freetype_root)src/cff/cffpic.c", + + #"<(freetype_root)src/cid/cidgload.c", + #"<(freetype_root)src/cid/cidload.c", + #"<(freetype_root)src/cid/cidobjs.c", + #"<(freetype_root)src/cid/cidparse.c", + #"<(freetype_root)src/cid/cidriver.c", + "<(freetype_root)src/cid/type1cid.c", + + "<(freetype_root)src/gxvalid/gxvalid.c", + #"<(freetype_root)src/gxvalid/gxvbsln.c", + #"<(freetype_root)src/gxvalid/gxvcommn.c", + #"<(freetype_root)src/gxvalid/gxvfeat.c", + #"<(freetype_root)src/gxvalid/gxvfgen.c", + #"<(freetype_root)src/gxvalid/gxvjust.c", + #"<(freetype_root)src/gxvalid/gxvkern.c", + #"<(freetype_root)src/gxvalid/gxvlcar.c", + #"<(freetype_root)src/gxvalid/gxvmod.c", + #"<(freetype_root)src/gxvalid/gxvmort0.c", + #"<(freetype_root)src/gxvalid/gxvmort1.c", + #"<(freetype_root)src/gxvalid/gxvmort2.c", + #"<(freetype_root)src/gxvalid/gxvmort4.c", + #"<(freetype_root)src/gxvalid/gxvmort5.c", + #"<(freetype_root)src/gxvalid/gxvmort.c", + #"<(freetype_root)src/gxvalid/gxvmorx0.c", + #"<(freetype_root)src/gxvalid/gxvmorx1.c", + #"<(freetype_root)src/gxvalid/gxvmorx2.c", + #"<(freetype_root)src/gxvalid/gxvmorx4.c", + #"<(freetype_root)src/gxvalid/gxvmorx5.c", + #"<(freetype_root)src/gxvalid/gxvmorx.c", + #"<(freetype_root)src/gxvalid/gxvopbd.c", + #"<(freetype_root)src/gxvalid/gxvprop.c", + #"<(freetype_root)src/gxvalid/gxvtrak.c", + + #"<(freetype_root)src/gzip/adler32.c", + "<(freetype_root)src/gzip/ftgzip.c", + #"<(freetype_root)src/gzip/infblock.c", + #"<(freetype_root)src/gzip/infcodes.c", + #"<(freetype_root)src/gzip/inflate.c", + #"<(freetype_root)src/gzip/inftrees.c", + #"<(freetype_root)src/gzip/infutil.c", + #"<(freetype_root)src/gzip/zutil.c", + + "<(freetype_root)src/lzw/ftlzw.c", + #"<(freetype_root)src/lzw/ftzopen.c", + + "<(freetype_root)src/otvalid/otvalid.c", + #"<(freetype_root)src/otvalid/otvbase.c", + #"<(freetype_root)src/otvalid/otvcommn.c", + #"<(freetype_root)src/otvalid/otvgdef.c", + #"<(freetype_root)src/otvalid/otvgpos.c", + #"<(freetype_root)src/otvalid/otvgsub.c", + #"<(freetype_root)src/otvalid/otvjstf.c", + #"<(freetype_root)src/otvalid/otvmath.c", + #"<(freetype_root)src/otvalid/otvmod.c", + + "<(freetype_root)src/pcf/pcf.c", + #"<(freetype_root)src/pcf/pcfdrivr.c", + #"<(freetype_root)src/pcf/pcfread.c", + #"<(freetype_root)src/pcf/pcfutil.c", + + "<(freetype_root)src/pfr/pfr.c", + #"<(freetype_root)src/pfr/pfrcmap.c", + #"<(freetype_root)src/pfr/pfrdrivr.c", + #"<(freetype_root)src/pfr/pfrgload.c", + #"<(freetype_root)src/pfr/pfrload.c", + #"<(freetype_root)src/pfr/pfrobjs.c", + #"<(freetype_root)src/pfr/pfrsbit.c", + + #"<(freetype_root)src/psaux/afmparse.c", + "<(freetype_root)src/psaux/psaux.c", + #"<(freetype_root)src/psaux/psauxmod.c", + #"<(freetype_root)src/psaux/psconv.c", + #"<(freetype_root)src/psaux/psobjs.c", + #"<(freetype_root)src/psaux/t1cmap.c", + #"<(freetype_root)src/psaux/t1decode.c", + + #"<(freetype_root)src/pshinter/pshalgo.c", + #"<(freetype_root)src/pshinter/pshglob.c", + "<(freetype_root)src/pshinter/pshinter.c", + #"<(freetype_root)src/pshinter/pshmod.c", + #"<(freetype_root)src/pshinter/pshpic.c", + #"<(freetype_root)src/pshinter/pshrec.c", + + #"<(freetype_root)src/psnames/psmodule.c", + "<(freetype_root)src/psnames/psnames.c", + #"<(freetype_root)src/psnames/pspic.c", + + #"<(freetype_root)src/raster/ftraster.c", + #"<(freetype_root)src/raster/ftrend1.c", + "<(freetype_root)src/raster/raster.c", + #"<(freetype_root)src/raster/rastpic.c", + + #"<(freetype_root)src/sfnt/pngshim.c", + #"<(freetype_root)src/sfnt/sfdriver.c", + "<(freetype_root)src/sfnt/sfnt.c", + #"<(freetype_root)src/sfnt/sfntpic.c", + #"<(freetype_root)src/sfnt/sfobjs.c", + #"<(freetype_root)src/sfnt/ttbdf.c", + #"<(freetype_root)src/sfnt/ttcmap.c", + #"<(freetype_root)src/sfnt/ttkern.c", + #"<(freetype_root)src/sfnt/ttload.c", + #"<(freetype_root)src/sfnt/ttmtx.c", + #"<(freetype_root)src/sfnt/ttpost.c", + #"<(freetype_root)src/sfnt/ttsbit.c", + + #"<(freetype_root)src/smooth/ftgrays.c", + #"<(freetype_root)src/smooth/ftsmooth.c", + #"<(freetype_root)src/smooth/ftspic.c", + "<(freetype_root)src/smooth/smooth.c", + + "<(freetype_root)src/tools/apinames.c", + "<(freetype_root)src/tools/ftrandom/ftrandom.c", + "<(freetype_root)src/tools/test_afm.c", + "<(freetype_root)src/tools/test_bbox.c", + "<(freetype_root)src/tools/test_trig.c", + + "<(freetype_root)src/truetype/truetype.c", + #"<(freetype_root)src/truetype/ttdriver.c", + #"<(freetype_root)src/truetype/ttgload.c", + #"<(freetype_root)src/truetype/ttgxvar.c", + #"<(freetype_root)src/truetype/ttinterp.c", + #"<(freetype_root)src/truetype/ttobjs.c", + #"<(freetype_root)src/truetype/ttpic.c", + #"<(freetype_root)src/truetype/ttpload.c", + #"<(freetype_root)src/truetype/ttsubpix.c", + + #"<(freetype_root)src/type1/t1afm.c", + #"<(freetype_root)src/type1/t1driver.c", + #"<(freetype_root)src/type1/t1gload.c", + #"<(freetype_root)src/type1/t1load.c", + #"<(freetype_root)src/type1/t1objs.c", + #"<(freetype_root)src/type1/t1parse.c", + "<(freetype_root)src/type1/type1.c", + + #"<(freetype_root)src/type42/t42drivr.c", + #"<(freetype_root)src/type42/t42objs.c", + #"<(freetype_root)src/type42/t42parse.c", + "<(freetype_root)src/type42/type42.c", + + "<(freetype_root)src/winfonts/winfnt.c", + ], + }, + ] +} diff --git a/static/gif.gyp b/static/gif.gyp new file mode 100644 index 000000000..cf94f6684 --- /dev/null +++ b/static/gif.gyp @@ -0,0 +1,22 @@ +{ + + 'includes': [ 'common.gyp' , 'locations.gyp'], + 'targets': [ + { + 'target_name': 'gif', + 'type': 'static_library', + 'include_dirs': [ '<(gif_root)lib/'], + 'libraries': [ + ], + 'defines': [ ], + 'sources': [ + "<(gif_root)lib/dgif_lib.c", + "<(gif_root)lib/egif_lib.c", + "<(gif_root)lib/gifalloc.c", + "<(gif_root)lib/gif_err.c", + "<(gif_root)lib/gif_font.c", + "<(gif_root)lib/gif_hash.c", + ], + }, + ] +} diff --git a/static/jpeg.gyp b/static/jpeg.gyp new file mode 100644 index 000000000..bd235245e --- /dev/null +++ b/static/jpeg.gyp @@ -0,0 +1,117 @@ +{ + + 'includes': [ 'common.gyp' , 'locations.gyp'], + 'targets': [ + { + 'target_name': 'libjpeg', + 'type': 'static_library', + 'include_dirs': [ + '../static/custom-include/jpeg/', + '<(jpeg_root)' , + ], + + 'dependencies': [], + 'defines': [], + 'sources': [ + + #"<(jpeg_root)ansi2knr.c", + #"<(jpeg_root)cdjpeg.c", + #"<(jpeg_root)cjpeg.c", + #"<(jpeg_root)ckconfig.c", + #"<(jpeg_root)djpeg.c", + #"<(jpeg_root)example.c", + + "<(jpeg_root)jsimd_none.c", + + "<(jpeg_root)jaricom.c", + "<(jpeg_root)jcapimin.c", + "<(jpeg_root)jcapistd.c", + "<(jpeg_root)jcarith.c", + "<(jpeg_root)jccoefct.c", + "<(jpeg_root)jccolor.c", + "<(jpeg_root)jcdctmgr.c", + "<(jpeg_root)jchuff.c", + "<(jpeg_root)jchuff.h", + "<(jpeg_root)jcinit.c", + "<(jpeg_root)jcmainct.c", + "<(jpeg_root)jcmarker.c", + "<(jpeg_root)jcmaster.c", + "<(jpeg_root)jcomapi.c", + "../static/custom-include/jpeg/jconfig.h", + "<(jpeg_root)jcparam.c", + "<(jpeg_root)jcphuff.c", + "<(jpeg_root)jcprepct.c", + "<(jpeg_root)jcsample.c", + #"<(jpeg_root)jctrans.c", + "<(jpeg_root)jdapimin.c", + "<(jpeg_root)jdapistd.c", + "<(jpeg_root)jdarith.c", + "<(jpeg_root)jdatadst.c", + "<(jpeg_root)jdatasrc.c", + "<(jpeg_root)jdcoefct.c", + "<(jpeg_root)jdcolor.c", + "<(jpeg_root)jdct.h", + "<(jpeg_root)jddctmgr.c", + "<(jpeg_root)jdhuff.c", + "<(jpeg_root)jdhuff.h", + "<(jpeg_root)jdinput.c", + "<(jpeg_root)jdmainct.c", + "<(jpeg_root)jdmarker.c", + "<(jpeg_root)jdmaster.c", + "<(jpeg_root)jdmerge.c", + "<(jpeg_root)jdphuff.c", + "<(jpeg_root)jdpostct.c", + "<(jpeg_root)jdsample.c", + #"<(jpeg_root)jdtrans.c", + "<(jpeg_root)jerror.c", + "<(jpeg_root)jerror.h", + "<(jpeg_root)jfdctflt.c", + "<(jpeg_root)jfdctfst.c", + "<(jpeg_root)jfdctint.c", + "<(jpeg_root)jidctflt.c", + "<(jpeg_root)jidctfst.c", + "<(jpeg_root)jidctint.c", + "<(jpeg_root)jinclude.h", + + "<(jpeg_root)jidctred.c", + + #"<(jpeg_root)jmemansi.c", + #"<(jpeg_root)jmemdos.c", + #"<(jpeg_root)jmemmac.c", + + "<(jpeg_root)jmemmgr.c", + + #"<(jpeg_root)jmemname.c", + "<(jpeg_root)jmemnobs.c", + #"<(jpeg_root)jpegtran.c", + + "<(jpeg_root)jquant1.c", + "<(jpeg_root)jquant2.c", + + "<(jpeg_root)jmemsys.h", + "<(jpeg_root)jmorecfg.h", + "<(jpeg_root)jpegint.h", + "<(jpeg_root)jpeglib.h", + + "<(jpeg_root)jutils.c", + "<(jpeg_root)jversion.h", + + #"<(jpeg_root)rdbmp.c", + #"<(jpeg_root)rdcolmap.c", + #"<(jpeg_root)rdgif.c", + #"<(jpeg_root)rdjpgcom.c", + #"<(jpeg_root)rdppm.c", + #"<(jpeg_root)rdrle.c", + #"<(jpeg_root)rdswitch.c", + #"<(jpeg_root)rdtarga.c", + #"<(jpeg_root)transupp.c", + #"<(jpeg_root)wrbmp.c", + #"<(jpeg_root)wrgif.c", + #"<(jpeg_root)wrjpgcom.c", + #"<(jpeg_root)wrppm.c", + #"<(jpeg_root)wrrle.c", + #"<(jpeg_root)wrtarga.c", + ], + }, + ] +} diff --git a/static/libpng.gyp b/static/libpng.gyp new file mode 100644 index 000000000..ddff885ec --- /dev/null +++ b/static/libpng.gyp @@ -0,0 +1,69 @@ +{ + + 'includes': [ 'common.gyp' , 'locations.gyp'], + 'targets': [ + { + 'target_name': 'png', + 'type': 'static_library', + 'include_dirs': [ + '<(libpng_root)' , + '../static/custom-include/png/', + '<(zlib_root)', + ], + + 'dependencies': [ + 'zlib.gyp:zlib' + ], + 'defines': [], + 'sources': [ + #"<(libpng_root)arm/arm_init.c", + #"<(libpng_root)contrib/examples/iccfrompng.c", + #"<(libpng_root)contrib/examples/pngpixel.c", + #"<(libpng_root)contrib/examples/pngtopng.c", + #"<(libpng_root)contrib/gregbook/readpng2.c", + #"<(libpng_root)contrib/gregbook/readpng.c", + #"<(libpng_root)contrib/gregbook/readppm.c", + #"<(libpng_root)contrib/gregbook/rpng2-win.c", + #"<(libpng_root)contrib/gregbook/rpng2-x.c", + #"<(libpng_root)contrib/gregbook/rpng-win.c", + #"<(libpng_root)contrib/gregbook/rpng-x.c", + #"<(libpng_root)contrib/gregbook/wpng.c", + #"<(libpng_root)contrib/gregbook/writepng.c", + #"<(libpng_root)contrib/libtests/fakepng.c", + #"<(libpng_root)contrib/libtests/makepng.c", + #"<(libpng_root)contrib/libtests/pngstest.c", + #"<(libpng_root)contrib/libtests/pngunknown.c", + #"<(libpng_root)contrib/libtests/pngvalid.c", + #"<(libpng_root)contrib/libtests/readpng.c", + #"<(libpng_root)contrib/libtests/tarith.c", + #"<(libpng_root)contrib/libtests/timepng.c", + #"<(libpng_root)contrib/pngminus/png2pnm.c", + #"<(libpng_root)contrib/pngminus/pnm2png.c", + #"<(libpng_root)contrib/tools/checksum-icc.c", + #"<(libpng_root)contrib/tools/cvtcolor.c", + #"<(libpng_root)contrib/tools/makesRGB.c", + #"<(libpng_root)contrib/tools/pngfix.c", + #"<(libpng_root)contrib/tools/png-fix-itxt.c", + #"<(libpng_root)contrib/visupng/PngFile.c", + #"<(libpng_root)contrib/visupng/VisualPng.c", + #"<(libpng_root)example.c", + "<(libpng_root)png.c", + "<(libpng_root)pngerror.c", + "<(libpng_root)pngget.c", + "<(libpng_root)pngmem.c", + "<(libpng_root)pngpread.c", + "<(libpng_root)pngread.c", + "<(libpng_root)pngrio.c", + "<(libpng_root)pngrtran.c", + "<(libpng_root)pngrutil.c", + "<(libpng_root)pngset.c", + "<(libpng_root)pngtest.c", + "<(libpng_root)pngtrans.c", + "<(libpng_root)pngwio.c", + "<(libpng_root)pngwrite.c", + "<(libpng_root)pngwtran.c", + "<(libpng_root)pngwutil.c", + ], + }, + ] +} diff --git a/static/locations.gyp b/static/locations.gyp new file mode 100644 index 000000000..aa1f98413 --- /dev/null +++ b/static/locations.gyp @@ -0,0 +1,11 @@ +{ + 'variables': { + 'cairo_root%': "../deps/cairo/", + 'freetype_root%': "../deps/freetype/", + 'gif_root%': "../deps/giflib/", + 'jpeg_root%': "../deps/libjpeg/", + 'libpng_root%': "../deps/libpng/", + 'pixman_root%': "../deps/pixman/", + 'zlib_root%': "../deps/zlib/", + } +} diff --git a/static/pixman.gyp b/static/pixman.gyp new file mode 100644 index 000000000..a198d19ee --- /dev/null +++ b/static/pixman.gyp @@ -0,0 +1,60 @@ +{ + + 'includes': [ 'common.gyp' , 'locations.gyp'], + 'targets': [ + { + 'target_name': 'pixman', + 'type': 'static_library', + 'include_dirs': [ + '../static/custom-include/pixman/', + '<(pixman_root)', + '<(pixman_root)pixman', + ], + + 'libraries': [ + + ] + , + 'defines': [ 'HAVE_CONFIG_H' ], + 'sources': [ + "<(pixman_root)pixman/pixman-access-accessors.c", + "<(pixman_root)pixman/pixman-access.c", + "<(pixman_root)pixman/pixman-arm.c", + "<(pixman_root)pixman/pixman-arm-neon.c", + "<(pixman_root)pixman/pixman-arm-simd.c", + "<(pixman_root)pixman/pixman-bits-image.c", + "<(pixman_root)pixman/pixman.c", + "<(pixman_root)pixman/pixman-combine32.c", + "<(pixman_root)pixman/pixman-combine-float.c", + "<(pixman_root)pixman/pixman-conical-gradient.c", + "<(pixman_root)pixman/pixman-edge-accessors.c", + "<(pixman_root)pixman/pixman-edge.c", + "<(pixman_root)pixman/pixman-fast-path.c", + "<(pixman_root)pixman/pixman-filter.c", + "<(pixman_root)pixman/pixman-general.c", + "<(pixman_root)pixman/pixman-glyph.c", + "<(pixman_root)pixman/pixman-gradient-walker.c", + "<(pixman_root)pixman/pixman-image.c", + "<(pixman_root)pixman/pixman-implementation.c", + "<(pixman_root)pixman/pixman-linear-gradient.c", + "<(pixman_root)pixman/pixman-matrix.c", + "<(pixman_root)pixman/pixman-mips.c", + "<(pixman_root)pixman/pixman-mips-dspr2.c", + "<(pixman_root)pixman/pixman-mmx.c", + "<(pixman_root)pixman/pixman-noop.c", + "<(pixman_root)pixman/pixman-ppc.c", + "<(pixman_root)pixman/pixman-radial-gradient.c", + "<(pixman_root)pixman/pixman-region16.c", + "<(pixman_root)pixman/pixman-region32.c", + #"<(pixman_root)pixman/pixman-region.c", + "<(pixman_root)pixman/pixman-solid-fill.c", + "<(pixman_root)pixman/pixman-sse2.c", + "<(pixman_root)pixman/pixman-timer.c", + "<(pixman_root)pixman/pixman-trap.c", + "<(pixman_root)pixman/pixman-utils.c", + #"<(pixman_root)pixman/pixman-vmx.c", + "<(pixman_root)pixman/pixman-x86.c", + ], + }, + ] +} diff --git a/static/zlib.gyp b/static/zlib.gyp new file mode 100644 index 000000000..3b2a0bd4f --- /dev/null +++ b/static/zlib.gyp @@ -0,0 +1,60 @@ +{ + + 'includes': [ 'common.gyp' , 'locations.gyp'], + 'targets': [ + { + 'target_name': 'zlib', + 'type': 'static_library', + 'include_dirs': [ '<(zlib_root)' ], + + 'libraries': [ + + ], + 'defines': [ ], + 'sources': [ + "<(zlib_root)adler32.c", + "<(zlib_root)compress.c", + "<(zlib_root)contrib/blast/blast.c", + "<(zlib_root)contrib/infback9/infback9.c", + "<(zlib_root)contrib/infback9/inftree9.c", + "<(zlib_root)contrib/inflate86/inffas86.c", + "<(zlib_root)contrib/masmx64/inffas8664.c", + #"<(zlib_root)contrib/minizip/ioapi.c", + #"<(zlib_root)contrib/minizip/iowin32.c", + #"<(zlib_root)contrib/minizip/miniunz.c", + #"<(zlib_root)contrib/minizip/minizip.c", + #"<(zlib_root)contrib/minizip/mztools.c", + #"<(zlib_root)contrib/minizip/unzip.c", + #"<(zlib_root)contrib/minizip/zip.c", + #"<(zlib_root)contrib/puff/puff.c", + #"<(zlib_root)contrib/puff/pufftest.c", + #"<(zlib_root)contrib/testzlib/testzlib.c", + #"<(zlib_root)contrib/untgz/untgz.c", + "<(zlib_root)crc32.c", + "<(zlib_root)deflate.c", + #"<(zlib_root)examples/enough.c", + #"<(zlib_root)examples/fitblk.c", + #"<(zlib_root)examples/gun.c", + #"<(zlib_root)examples/gzappend.c", + #"<(zlib_root)examples/gzjoin.c", + #"<(zlib_root)examples/gzlog.c", + #"<(zlib_root)examples/zpipe.c", + #"<(zlib_root)examples/zran.c", + "<(zlib_root)gzclose.c", + "<(zlib_root)gzlib.c", + "<(zlib_root)gzread.c", + "<(zlib_root)gzwrite.c", + "<(zlib_root)infback.c", + "<(zlib_root)inffast.c", + "<(zlib_root)inflate.c", + "<(zlib_root)inftrees.c", + #"<(zlib_root)test/example.c", + #"<(zlib_root)test/infcover.c", + #"<(zlib_root)test/minigzip.c", + "<(zlib_root)trees.c", + "<(zlib_root)uncompr.c", + "<(zlib_root)zutil.c", + ], + }, + ] +} diff --git a/test/canvas.test.js b/test/canvas.test.js index 3574ab2c1..f11f2fc8f 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -2,7 +2,7 @@ * Module dependencies. */ -var Canvas = require('../') +var Canvas = require('..') , assert = require('assert') , parseFont = Canvas.Context2d.parseFont , fs = require('fs'); @@ -214,13 +214,13 @@ describe('Canvas', function () { it('Canvas#type', function () { var canvas = new Canvas(10, 10); - assert('image' == canvas.type); + assert.equal(canvas.type, 'image'); var canvas = new Canvas(10, 10, 'pdf'); - assert('pdf' == canvas.type); + assert.equal(canvas.type, 'pdf'); var canvas = new Canvas(10, 10, 'svg'); - assert('svg' == canvas.type); + assert.equal(canvas.type, 'svg'); var canvas = new Canvas(10, 10, 'hey'); - assert('image' == canvas.type); + assert.equal(canvas.type, 'image'); }); it('Canvas#getContext("2d")', function () { diff --git a/test/image.test.js b/test/image.test.js index ae39d6207..15ed88d80 100644 --- a/test/image.test.js +++ b/test/image.test.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var Canvas = require('../') +var Canvas = require('..') , Image = Canvas.Image , assert = require('assert'); diff --git a/test/server.js b/test/server.js index 31ee9ed05..0f7fa156c 100644 --- a/test/server.js +++ b/test/server.js @@ -4,7 +4,7 @@ */ var express = require('express') - , Canvas = require('../lib/canvas') + , Canvas = require('..') , Image = Canvas.Image , bodyParser = require('body-parser') , app = express(); diff --git a/util/has_lib.sh b/util/has_lib.sh index 31ef1298f..84dff3d5b 100755 --- a/util/has_lib.sh +++ b/util/has_lib.sh @@ -19,7 +19,8 @@ has_system_lib() { fi # Try just checking common library locations - for dir in /lib /usr/lib /usr/local/lib /opt/local/lib /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu; do + for dir in /lib /usr/lib /usr/local/lib /opt/local/lib \ + /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu; do test -d $dir && ls $dir | grep -E "$regex" && return 0 done @@ -35,6 +36,14 @@ has_pkgconfig_lib() { } case "$1" in + cairo) + has_system_lib "cairo" > /dev/null + result=$? + ;; + freetype) + has_freetype > /dev/null + result=$? + ;; gif) has_system_lib "gif" > /dev/null result=$? @@ -47,10 +56,6 @@ case "$1" in has_pkgconfig_lib "pango" > /dev/null result=$? ;; - freetype) - has_freetype > /dev/null - result=$? - ;; *) >&2 echo "Unknown library: $1" exit 1 From 70a4d3888993f01d0428471cfef0ac22b626a741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 24 Jan 2017 17:02:09 +0100 Subject: [PATCH 059/183] Download ZLIB from SourceForge --- static/ensure_deps.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/ensure_deps.sh b/static/ensure_deps.sh index 4a82bbd01..895a09d6d 100755 --- a/static/ensure_deps.sh +++ b/static/ensure_deps.sh @@ -6,7 +6,7 @@ GIFLIB_VERSION=4.2.3 LIBJPEG_VERSION=1.2.1 LIBPNG_VERSION=1.2.56 PIXMAN_VERSION=0.32.6 -ZLIB_VERSION=1.2.8 +ZLIB_VERSION=1.2.11 CAIRO_URL=http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz FONTCONFIG_URL=http://cgit.freedesktop.org/fontconfig/plain/fontconfig/fontconfig.h @@ -15,7 +15,7 @@ GIFLIB_URL=http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-$GIFLI LIBJPEG_URL=http://downloads.sourceforge.net/project/libjpeg-turbo/$LIBJPEG_VERSION/libjpeg-turbo-$LIBJPEG_VERSION.tar.gz LIBPNG_URL=http://sourceforge.net/projects/libpng/files/libpng12/$LIBPNG_VERSION/libpng-$LIBPNG_VERSION.tar.xz PIXMAN_URL=http://cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz -ZLIB_URL=http://zlib.net/zlib-$ZLIB_VERSION.tar.gz +ZLIB_URL=https://sourceforge.net/projects/libpng/files/zlib/$ZLIB_VERSION/zlib-$ZLIB_VERSION.tar.gz DEPS="$(dirname $0)/../deps" From 48e53b46d5305870bc115ad66625633f3532a57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 24 Jan 2017 17:02:33 +0100 Subject: [PATCH 060/183] Add missing libraries (due to Pango?) --- canvas.gypi | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/canvas.gypi b/canvas.gypi index c617cd54d..3f5899568 100644 --- a/canvas.gypi +++ b/canvas.gypi @@ -1,6 +1,13 @@ { 'target_name': 'canvas', - 'include_dirs': [" Date: Sat, 11 Feb 2017 13:51:38 +0100 Subject: [PATCH 061/183] Use statically linked Pango (and dynamic dependencies) --- canvas.gypi | 7 +- static.gyp | 12 +- static/custom-include/cairo/cairo-features.h | 2 +- static/custom-include/pango/config.h | 149 +++++++++++++++++++ static/ensure_deps.sh | 7 +- static/locations.gyp | 1 + static/pango.gyp | 91 +++++++++++ 7 files changed, 258 insertions(+), 11 deletions(-) create mode 100644 static/custom-include/pango/config.h create mode 100644 static/pango.gyp diff --git a/canvas.gypi b/canvas.gypi index 3f5899568..7c8287af0 100644 --- a/canvas.gypi +++ b/canvas.gypi @@ -1,12 +1,7 @@ { 'target_name': 'canvas', - 'libraries': [ - ' header file, and it defines `DIR'. + */ +#define HAVE_DIRENT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `FcWeightFromOpenType' function. */ +#define HAVE_FCWEIGHTFROMOPENTYPE 1 + +/* Define to 1 if you have the `flockfile' function. */ +#define HAVE_FLOCKFILE 1 + +/* Have FreeType 2 library */ +#define HAVE_FREETYPE 1 + +/* Define to 1 if you have the `getpagesize' function. */ +#define HAVE_GETPAGESIZE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Whether libthai is available */ +/* #undef HAVE_LIBTHAI */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. */ +/* #undef HAVE_NDIR_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strtok_r' function. */ +#define HAVE_STRTOK_R 1 + +/* Define to 1 if you have the `sysconf' function. */ +#define HAVE_SYSCONF 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_DIR_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_MMAN_H 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_NDIR_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Have Xft library */ +/* #undef HAVE_XFT */ + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "pango" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "http://bugzilla.gnome.org/enter_bug.cgi?product=pango" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "pango" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "pango 1.40.3" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "pango" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.40.3" + +/* PANGO binary age */ +#define PANGO_BINARY_AGE 4003 + +/* PANGO interface age */ +#define PANGO_INTERFACE_AGE 3 + +/* PANGO major version */ +#define PANGO_VERSION_MAJOR 1 + +/* PANGO micro version */ +#define PANGO_VERSION_MICRO 3 + +/* PANGO minor version */ +#define PANGO_VERSION_MINOR 40 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "1.40.3" + +/* defines how to decorate public symbols while building */ +#define _PANGO_EXTERN __attribute__((visibility("default"))) extern diff --git a/static/ensure_deps.sh b/static/ensure_deps.sh index 895a09d6d..0ebcca7bf 100755 --- a/static/ensure_deps.sh +++ b/static/ensure_deps.sh @@ -5,6 +5,7 @@ FREETYPE_VERSION=2.6 GIFLIB_VERSION=4.2.3 LIBJPEG_VERSION=1.2.1 LIBPNG_VERSION=1.2.56 +PANGO_VERSION=1.40.3 PIXMAN_VERSION=0.32.6 ZLIB_VERSION=1.2.11 @@ -14,6 +15,7 @@ FREETYPE_URL=http://download.savannah.gnu.org/releases/freetype/freetype-$FREETY GIFLIB_URL=http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-$GIFLIB_VERSION.tar.gz LIBJPEG_URL=http://downloads.sourceforge.net/project/libjpeg-turbo/$LIBJPEG_VERSION/libjpeg-turbo-$LIBJPEG_VERSION.tar.gz LIBPNG_URL=http://sourceforge.net/projects/libpng/files/libpng12/$LIBPNG_VERSION/libpng-$LIBPNG_VERSION.tar.xz +PANGO_URL=http://ftp.gnome.org/pub/GNOME/sources/pango/1.40/pango-$PANGO_VERSION.tar.xz PIXMAN_URL=http://cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz ZLIB_URL=https://sourceforge.net/projects/libpng/files/zlib/$ZLIB_VERSION/zlib-$ZLIB_VERSION.tar.gz @@ -55,13 +57,14 @@ fetch $FREETYPE_URL freetype && fetch $GIFLIB_URL giflib && fetch $LIBJPEG_URL libjpeg && fetch_xz $LIBPNG_URL libpng && +fetch_xz $PANGO_URL pango && fetch $PIXMAN_URL pixman && fetch $ZLIB_URL zlib || exit $? if [ ! -d "cairo" ] || [ ! -d "freetype" ] || [ ! -d "giflib" ] \ -|| [ ! -d "libjpeg" ] || [ ! -d "libpng" ] || [ ! -d "pixman" ] \ -|| [ ! -d "zlib" ]; then +|| [ ! -d "libjpeg" ] || [ ! -d "libpng" ] || [ ! -d "pango" ] \ +|| [ ! -d "pixman" ] || [ ! -d "zlib" ]; then echo false else echo true diff --git a/static/locations.gyp b/static/locations.gyp index aa1f98413..365f82f21 100644 --- a/static/locations.gyp +++ b/static/locations.gyp @@ -5,6 +5,7 @@ 'gif_root%': "../deps/giflib/", 'jpeg_root%': "../deps/libjpeg/", 'libpng_root%': "../deps/libpng/", + 'pango_root%': "../deps/pango/", 'pixman_root%': "../deps/pixman/", 'zlib_root%': "../deps/zlib/", } diff --git a/static/pango.gyp b/static/pango.gyp new file mode 100644 index 000000000..cfb0e4d52 --- /dev/null +++ b/static/pango.gyp @@ -0,0 +1,91 @@ +{ + 'includes': ['common.gyp', 'locations.gyp'], + 'targets': [{ + 'target_name': 'pango/mini-fribidi', + 'type': 'static_library', + 'include_dirs': [ + ' Date: Sat, 11 Feb 2017 15:29:02 +0100 Subject: [PATCH 062/183] Use static `harfbuzz` library --- static/custom-include/harfbuzz/config.h | 203 ++++++++++++++++++++++++ static/ensure_deps.sh | 31 ++-- static/harfbuzz.gyp | 62 ++++++++ static/locations.gyp | 1 + static/pango.gyp | 3 +- 5 files changed, 289 insertions(+), 11 deletions(-) create mode 100644 static/custom-include/harfbuzz/config.h create mode 100644 static/harfbuzz.gyp diff --git a/static/custom-include/harfbuzz/config.h b/static/custom-include/harfbuzz/config.h new file mode 100644 index 000000000..adbffa9b9 --- /dev/null +++ b/static/custom-include/harfbuzz/config.h @@ -0,0 +1,203 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* The normal alignment of `struct{char;}', in bytes. */ +#define ALIGNOF_STRUCT_CHAR__ 1 + +/* Define to 1 if you have the `atexit' function. */ +#define HAVE_ATEXIT 1 + +/* Have cairo graphics library */ +#define HAVE_CAIRO 1 + +/* Have cairo-ft support in cairo graphics library */ +#define HAVE_CAIRO_FT 1 + +/* Have Core Text backend */ +/* #undef HAVE_CORETEXT */ + +/* Have DirectWrite library */ +/* #undef HAVE_DIRECTWRITE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_DWRITE_H */ + +/* Have simple TrueType Layout backend */ +#define HAVE_FALLBACK 1 + +/* Have fontconfig library */ +#define HAVE_FONTCONFIG 1 + +/* Have FreeType 2 library */ +#define HAVE_FREETYPE 1 + +/* Define to 1 if you have the `FT_Get_Var_Blend_Coordinates' function. */ +/* #undef HAVE_FT_GET_VAR_BLEND_COORDINATES */ + +/* Define to 1 if you have the `getpagesize' function. */ +#define HAVE_GETPAGESIZE 1 + +/* Have glib2 library */ +#define HAVE_GLIB 1 + +/* Have gobject2 library */ +/* #undef HAVE_GOBJECT */ + +/* Have Graphite2 library */ +/* #undef HAVE_GRAPHITE2 */ + +/* Have ICU library */ +#define HAVE_ICU 1 + +/* Use hb-icu Unicode callbacks */ +/* #undef HAVE_ICU_BUILTIN */ + +/* Have Intel __sync_* atomic primitives */ +#define HAVE_INTEL_ATOMIC_PRIMITIVES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `isatty' function. */ +#define HAVE_ISATTY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `mmap' function. */ +#define HAVE_MMAP 1 + +/* Define to 1 if you have the `mprotect' function. */ +#define HAVE_MPROTECT 1 + +/* Have native OpenType Layout backend */ +#define HAVE_OT 1 + +/* Have POSIX threads */ +#define HAVE_PTHREAD 1 + +/* Have PTHREAD_PRIO_INHERIT. */ +#define HAVE_PTHREAD_PRIO_INHERIT 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SCHED_H */ + +/* Have sched_yield */ +/* #undef HAVE_SCHED_YIELD */ + +/* Have Solaris __machine_*_barrier and atomic_* operations */ +/* #undef HAVE_SOLARIS_ATOMIC_OPS */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `sysconf' function. */ +#define HAVE_SYSCONF 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_MMAN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Have UCDN Unicode functions */ +#define HAVE_UCDN 1 + +/* Have Uniscribe library */ +/* #undef HAVE_UNISCRIBE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_USP10_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "https://github.com/behdad/harfbuzz/issues/new" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "HarfBuzz" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "HarfBuzz 1.4.2" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "harfbuzz" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "http://harfbuzz.org/" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.4.2" + +/* Define to necessary symbol if this constant uses a non-standard name on + your system. */ +/* #undef PTHREAD_CREATE_JOINABLE */ + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif + + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to 1 if on MINIX. */ +/* #undef _MINIX */ + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +/* #undef _POSIX_1_SOURCE */ + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +/* #undef _POSIX_SOURCE */ diff --git a/static/ensure_deps.sh b/static/ensure_deps.sh index 0ebcca7bf..3f87e8e7e 100755 --- a/static/ensure_deps.sh +++ b/static/ensure_deps.sh @@ -3,6 +3,7 @@ CAIRO_VERSION=1.12.18 FREETYPE_VERSION=2.6 GIFLIB_VERSION=4.2.3 +HARFBUZZ_VERSION=1.4.2 LIBJPEG_VERSION=1.2.1 LIBPNG_VERSION=1.2.56 PANGO_VERSION=1.40.3 @@ -13,6 +14,7 @@ CAIRO_URL=http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz FONTCONFIG_URL=http://cgit.freedesktop.org/fontconfig/plain/fontconfig/fontconfig.h FREETYPE_URL=http://download.savannah.gnu.org/releases/freetype/freetype-$FREETYPE_VERSION.tar.gz GIFLIB_URL=http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-$GIFLIB_VERSION.tar.gz +HARFBUZZ_URL=https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-$HARFBUZZ_VERSION.tar.bz2 LIBJPEG_URL=http://downloads.sourceforge.net/project/libjpeg-turbo/$LIBJPEG_VERSION/libjpeg-turbo-$LIBJPEG_VERSION.tar.gz LIBPNG_URL=http://sourceforge.net/projects/libpng/files/libpng12/$LIBPNG_VERSION/libpng-$LIBPNG_VERSION.tar.xz PANGO_URL=http://ftp.gnome.org/pub/GNOME/sources/pango/1.40/pango-$PANGO_VERSION.tar.xz @@ -34,6 +36,14 @@ fetch() fi } +fetch_bz2() +{ + if [ ! -d $2 ]; then + mkdir -p $2 && + curl -s -L $1 | tar xjf - -C $2 --strip-components=1 || exit $? + fi +} + fetch_xz() { if [ ! -d $2 ]; then @@ -53,18 +63,19 @@ if [ ! -d fontconfig ]; then curl -s -L $FONTCONFIG_URL >> fontconfig/fontconfig.h || exit $? fi -fetch $FREETYPE_URL freetype && -fetch $GIFLIB_URL giflib && -fetch $LIBJPEG_URL libjpeg && -fetch_xz $LIBPNG_URL libpng && -fetch_xz $PANGO_URL pango && -fetch $PIXMAN_URL pixman && -fetch $ZLIB_URL zlib || exit $? +fetch $FREETYPE_URL freetype && +fetch $GIFLIB_URL giflib && +fetch_bz2 $HARFBUZZ_URL harfbuzz && +fetch $LIBJPEG_URL libjpeg && +fetch_xz $LIBPNG_URL libpng && +fetch_xz $PANGO_URL pango && +fetch $PIXMAN_URL pixman && +fetch $ZLIB_URL zlib || exit $? -if [ ! -d "cairo" ] || [ ! -d "freetype" ] || [ ! -d "giflib" ] \ -|| [ ! -d "libjpeg" ] || [ ! -d "libpng" ] || [ ! -d "pango" ] \ -|| [ ! -d "pixman" ] || [ ! -d "zlib" ]; then +if [ ! -d "cairo" ] || [ ! -d "freetype" ] || [ ! -d "giflib" ] \ +|| [ ! -d "harfbuzz" ] || [ ! -d "libjpeg" ] || [ ! -d "libpng" ] \ +|| [ ! -d "pango" ] || [ ! -d "pixman" ] || [ ! -d "zlib" ]; then echo false else echo true diff --git a/static/harfbuzz.gyp b/static/harfbuzz.gyp new file mode 100644 index 000000000..91a912769 --- /dev/null +++ b/static/harfbuzz.gyp @@ -0,0 +1,62 @@ +{ + 'includes': ['common.gyp', 'locations.gyp'], + 'targets': [{ + 'target_name': 'hb-ucdn', + 'type': 'static_library', + 'include_dirs': ['<(harfbuzz_root)src/hb-ucdn'], + 'defines': ['HAVE_CONFIG_H'], + 'sources': [ + "<(harfbuzz_root)src/hb-ucdn/ucdn.c" + ] + }, { + 'target_name': 'harfbuzz', + 'type': 'static_library', + 'include_dirs': [ + ' Date: Sun, 12 Feb 2017 13:29:44 +0100 Subject: [PATCH 063/183] Use static `glib` library --- static.gyp | 8 +- static/custom-include/glib/config.h | 795 ++++++++++++++++++++++++ static/custom-include/glib/glibconfig.h | 196 ++++++ static/ensure_deps.sh | 10 +- static/glib.gyp | 195 ++++++ static/harfbuzz.gyp | 7 +- static/locations.gyp | 1 + static/pango.gyp | 8 +- 8 files changed, 1211 insertions(+), 9 deletions(-) create mode 100644 static/custom-include/glib/config.h create mode 100644 static/custom-include/glib/glibconfig.h create mode 100644 static/glib.gyp diff --git a/static.gyp b/static.gyp index 8995d880a..14984686b 100644 --- a/static.gyp +++ b/static.gyp @@ -9,7 +9,7 @@ 'includes': ['canvas.gypi'], 'libraries': [ ' and it should be used (not on Ultrix). + */ +#define HAVE_ALLOCA_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_ATTR_XATTR_H */ + +/* Define to 1 if you have the `bind_textdomain_codeset' function. */ +#define HAVE_BIND_TEXTDOMAIN_CODESET 1 + +/* Define if you have a version of the snprintf function with semantics as + specified by the ISO C99 standard. */ +#define HAVE_C99_SNPRINTF 1 + +/* Define if you have a version of the vsnprintf function with semantics as + specified by the ISO C99 standard. */ +#define HAVE_C99_VSNPRINTF 1 + +/* define to 1 if Carbon is available */ +/* #undef HAVE_CARBON */ + +/* Define to 1 if you have the `clock_gettime' function. */ +#define HAVE_CLOCK_GETTIME 1 + +/* define to 1 if Cocoa is available */ +/* #undef HAVE_COCOA */ + +/* Have nl_langinfo (CODESET) */ +#define HAVE_CODESET 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_CRT_EXTERNS_H */ + +/* Define if dbus-1 is available */ +/* #undef HAVE_DBUS1 */ + +/* Define to 1 if you have the `dcgettext' function. */ +#define HAVE_DCGETTEXT 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +#define HAVE_DIRENT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if using dtrace probes. */ +/* #undef HAVE_DTRACE */ + +/* Define to 1 if you have the `endmntent' function. */ +#define HAVE_ENDMNTENT 1 + +/* Define to 1 if you have the `endservent' function. */ +#define HAVE_ENDSERVENT 1 + +/* we have the eventfd(2) system call */ +#define HAVE_EVENTFD 1 + +/* Define to 1 if you have the `fallocate' function. */ +#define HAVE_FALLOCATE 1 + +/* Define if we have FAM */ +/* #undef HAVE_FAM */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_FAM_H */ + +/* Define if we have FAMNoExists in fam */ +/* #undef HAVE_FAM_NO_EXISTS */ + +/* Define to 1 if you have the `fchmod' function. */ +#define HAVE_FCHMOD 1 + +/* Define to 1 if you have the `fchown' function. */ +#define HAVE_FCHOWN 1 + +/* Define to 1 if you have the `fdwalk' function. */ +/* #undef HAVE_FDWALK */ + +/* Define to 1 if you have the header file. */ +#define HAVE_FSTAB_H 1 + +/* Define to 1 if you have the `fsync' function. */ +#define HAVE_FSYNC 1 + +/* we have the futex(2) system call */ +#define HAVE_FUTEX 1 + +/* Define to 1 if you have the `getc_unlocked' function. */ +#define HAVE_GETC_UNLOCKED 1 + +/* Define to 1 if you have the `getfsstat' function. */ +/* #undef HAVE_GETFSSTAT */ + +/* Define to 1 if you have the `getgrgid_r' function. */ +#define HAVE_GETGRGID_R 1 + +/* Define to 1 if you have the `getmntent_r' function. */ +#define HAVE_GETMNTENT_R 1 + +/* Define to 1 if you have the `getprotobyname_r' function. */ +#define HAVE_GETPROTOBYNAME_R 1 + +/* Define to 1 if you have the `getpwuid_r' function. */ +#define HAVE_GETPWUID_R 1 + +/* Define to 1 if you have the `getresuid' function. */ +#define HAVE_GETRESUID 1 + +/* Define if the GNU gettext() function is already present or preinstalled. */ +#define HAVE_GETTEXT 1 + +/* Define to 1 if you have the `getvfsstat' function. */ +/* #undef HAVE_GETVFSSTAT */ + +/* Define to 1 if you have the `gmtime_r' function. */ +#define HAVE_GMTIME_R 1 + +/* define to use system printf */ +#define HAVE_GOOD_PRINTF 1 + +/* Define to 1 if you have the `hasmntopt' function. */ +#define HAVE_HASMNTOPT 1 + +/* Define to 1 if you have the `if_indextoname' function. */ +#define HAVE_IF_INDEXTONAME 1 + +/* Define to 1 if you have the `if_nametoindex' function. */ +#define HAVE_IF_NAMETOINDEX 1 + +/* Define to 1 if you have the `inotify_init1' function. */ +#define HAVE_INOTIFY_INIT1 1 + +/* define to support printing 64-bit integers with format I64 */ +/* #undef HAVE_INT64_AND_I64 */ + +/* Define if you have the 'intmax_t' type in or . */ +#define HAVE_INTMAX_T 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define if exists, doesn't clash with , and + declares uintmax_t. */ +#define HAVE_INTTYPES_H_WITH_UINTMAX 1 + +/* Define if we have struct ip_mreqn */ +#define HAVE_IP_MREQN /**/ + +/* Define to 1 if you have the `issetugid' function. */ +/* #undef HAVE_ISSETUGID */ + +/* Define to 1 if you have the `kevent' function. */ +/* #undef HAVE_KEVENT */ + +/* Define to 1 if you have the `kqueue' function. */ +/* #undef HAVE_KQUEUE */ + +/* Define if you have and nl_langinfo(CODESET). */ +#define HAVE_LANGINFO_CODESET 1 + +/* Have nl_langinfo (_NL_CTYPE_OUTDIGITn_MB) */ +#define HAVE_LANGINFO_OUTDIGIT 1 + +/* Have nl_langinfo (PM_STR) */ +#define HAVE_LANGINFO_TIME 1 + +/* Define to 1 if you have the `lchmod' function. */ +/* #undef HAVE_LCHMOD */ + +/* Define to 1 if you have the `lchown' function. */ +#define HAVE_LCHOWN 1 + +/* Define if your file defines LC_MESSAGES. */ +#define HAVE_LC_MESSAGES 1 + +/* Define if you have the __libc_enable_secure variable (GNU libc, eglibc) */ +#define HAVE_LIBC_ENABLE_SECURE 1 + +/* Define if libelf is available */ +/* #undef HAVE_LIBELF */ + +/* Define if libmount is available */ +/* #undef HAVE_LIBMOUNT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LINUX_MAGIC_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LOCALE_H 1 + +/* Define to 1 if you have the `localtime_r' function. */ +#define HAVE_LOCALTIME_R 1 + +/* Define if you have the 'long double' type. */ +#define HAVE_LONG_DOUBLE 1 + +/* Define if you have the 'long long' type. */ +#define HAVE_LONG_LONG 1 + +/* define if system printf can print long long */ +#define HAVE_LONG_LONG_FORMAT 1 + +/* Define to 1 if you have the `lstat' function. */ +#define HAVE_LSTAT 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_MACH_MACH_TIME_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MALLOC_H 1 + +/* Define to 1 if you have the `mbrtowc' function. */ +#define HAVE_MBRTOWC 1 + +/* Define to 1 if you have the `memalign' function. */ +#define HAVE_MEMALIGN 1 + +/* Define to 1 if you have the `memmem' function. */ +#define HAVE_MEMMEM 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `mmap' function. */ +#define HAVE_MMAP 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MNTENT_H 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. */ +/* #undef HAVE_NDIR_H */ + +/* We have AF_NETLINK sockets */ +#define HAVE_NETLINK 1 + +/* Define to 1 if you have the `newlocale' function. */ +#define HAVE_NEWLOCALE 1 + +/* open option O_DIRECTORY */ +#define HAVE_OPEN_O_DIRECTORY 1 + +/* Define to 1 if you have the `pipe2' function. */ +#define HAVE_PIPE2 1 + +/* Define to 1 if you have the `poll' function. */ +#define HAVE_POLL 1 + +/* Define to 1 if you have the `posix_memalign' function. */ +#define HAVE_POSIX_MEMALIGN 1 + +/* Define to 1 if you have the `prlimit' function. */ +#define HAVE_PRLIMIT 1 + +/* Have function pthread_attr_setstacksize */ +#define HAVE_PTHREAD_ATTR_SETSTACKSIZE 1 + +/* Have function pthread_condattr_setclock */ +#define HAVE_PTHREAD_CONDATTR_SETCLOCK 1 + +/* Have function pthread_cond_timedwait_relative_np */ +/* #undef HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP */ + +/* Have function pthread_setname_np(const char*) */ +/* #undef HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID */ + +/* Have function pthread_setname_np(pthread_t, const char*) */ +#define HAVE_PTHREAD_SETNAME_NP_WITH_TID 1 + +/* Define to 1 if the system has the type `ptrdiff_t'. */ +#define HAVE_PTRDIFF_T 1 + +/* Define to 1 if you have the `readlink' function. */ +#define HAVE_READLINK 1 + +/* Define to 1 if you have the `recvmmsg' function. */ +#define HAVE_RECVMMSG 1 + +/* Define to 1 if you have the 'res_init' function. */ +#define HAVE_RES_INIT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SCHED_H 1 + +/* Define to 1 if libselinux is available */ +#define HAVE_SELINUX 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SELINUX_SELINUX_H 1 + +/* Define to 1 if you have the `sendmmsg' function. */ +#define HAVE_SENDMMSG 1 + +/* Define to 1 if you have the `setenv' function. */ +#define HAVE_SETENV 1 + +/* Define to 1 if you have the `setmntent' function. */ +#define HAVE_SETMNTENT 1 + +/* Define if you have the 'sig_atomic_t' type. */ +#define HAVE_SIG_ATOMIC_T 1 + +/* Define to 1 if you have the `snprintf' function. */ +#define HAVE_SNPRINTF 1 + +/* Define to 1 if you have the `splice' function. */ +#define HAVE_SPLICE 1 + +/* Define to 1 if you have the `statfs' function. */ +#define HAVE_STATFS 1 + +/* Define to 1 if you have the `statvfs' function. */ +#define HAVE_STATVFS 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define if exists, doesn't clash with , and declares + uintmax_t. */ +#define HAVE_STDINT_H_WITH_UINTMAX 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `stpcpy' function. */ +#define HAVE_STPCPY 1 + +/* Define to 1 if you have the `strcasecmp' function. */ +#define HAVE_STRCASECMP 1 + +/* Define to 1 if you have the `strerror_r' function. */ +#define HAVE_STRERROR_R 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Have functions strlcpy and strlcat */ +/* #undef HAVE_STRLCPY */ + +/* Define to 1 if you have the `strncasecmp' function. */ +#define HAVE_STRNCASECMP 1 + +/* Define to 1 if you have the `strnlen' function. */ +#define HAVE_STRNLEN 1 + +/* Define to 1 if you have the `strsignal' function. */ +#define HAVE_STRSIGNAL 1 + +/* Define to 1 if you have the `strtod_l' function. */ +#define HAVE_STRTOD_L 1 + +/* Define to 1 if you have the `strtoll_l' function. */ +#define HAVE_STRTOLL_L 1 + +/* Define to 1 if you have the `strtoull_l' function. */ +#define HAVE_STRTOULL_L 1 + +/* Define to 1 if `d_type' is a member of `struct dirent'. */ +#define HAVE_STRUCT_DIRENT_D_TYPE 1 + +/* Define to 1 if `f_bavail' is a member of `struct statfs'. */ +#define HAVE_STRUCT_STATFS_F_BAVAIL 1 + +/* Define to 1 if `f_fstypename' is a member of `struct statfs'. */ +/* #undef HAVE_STRUCT_STATFS_F_FSTYPENAME */ + +/* Define to 1 if `f_basetype' is a member of `struct statvfs'. */ +/* #undef HAVE_STRUCT_STATVFS_F_BASETYPE */ + +/* Define to 1 if `f_fstypename' is a member of `struct statvfs'. */ +/* #undef HAVE_STRUCT_STATVFS_F_FSTYPENAME */ + +/* Define to 1 if `st_atimensec' is a member of `struct stat'. */ +/* #undef HAVE_STRUCT_STAT_ST_ATIMENSEC */ + +/* Define to 1 if `st_atim.tv_nsec' is a member of `struct stat'. */ +#define HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC 1 + +/* Define to 1 if `st_birthtim' is a member of `struct stat'. */ +/* #undef HAVE_STRUCT_STAT_ST_BIRTHTIM */ + +/* Define to 1 if `st_birthtime' is a member of `struct stat'. */ +/* #undef HAVE_STRUCT_STAT_ST_BIRTHTIME */ + +/* Define to 1 if `st_birthtimensec' is a member of `struct stat'. */ +/* #undef HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC */ + +/* Define to 1 if `st_birthtim.tv_nsec' is a member of `struct stat'. */ +/* #undef HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC */ + +/* Define to 1 if `st_blksize' is a member of `struct stat'. */ +#define HAVE_STRUCT_STAT_ST_BLKSIZE 1 + +/* Define to 1 if `st_blocks' is a member of `struct stat'. */ +#define HAVE_STRUCT_STAT_ST_BLOCKS 1 + +/* Define to 1 if `st_ctimensec' is a member of `struct stat'. */ +/* #undef HAVE_STRUCT_STAT_ST_CTIMENSEC */ + +/* Define to 1 if `st_ctim.tv_nsec' is a member of `struct stat'. */ +#define HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC 1 + +/* Define to 1 if `st_mtimensec' is a member of `struct stat'. */ +/* #undef HAVE_STRUCT_STAT_ST_MTIMENSEC */ + +/* Define to 1 if `st_mtim.tv_nsec' is a member of `struct stat'. */ +#define HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 1 + +/* Define to 1 if `tm_gmtoff' is a member of `struct tm'. */ +#define HAVE_STRUCT_TM_TM_GMTOFF 1 + +/* Define to 1 if `__tm_gmtoff' is a member of `struct tm'. */ +/* #undef HAVE_STRUCT_TM___TM_GMTOFF */ + +/* Define to 1 if you have the `symlink' function. */ +#define HAVE_SYMLINK 1 + +/* Define to 1 if you have the `sysctlbyname' function. */ +/* #undef HAVE_SYSCTLBYNAME */ + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_DIR_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_EVENT_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_FILIO_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_INOTIFY_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_MNTCTL_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_MNTTAB_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_MOUNT_H 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_NDIR_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_RESOURCE_H 1 + +/* found fd_set in sys/select.h */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STATFS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STATVFS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SYSCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_VFSTAB_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_VFS_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_VMOUNT_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_XATTR_H 1 + +/* Define to 1 if you have the `timegm' function. */ +#define HAVE_TIMEGM 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define if your printf function family supports positional parameters as + specified by Unix98. */ +#define HAVE_UNIX98_PRINTF 1 + +/* Define to 1 if you have the `unsetenv' function. */ +#define HAVE_UNSETENV 1 + +/* Define to 1 if you have the `uselocale' function. */ +#define HAVE_USELOCALE 1 + +/* Define to 1 if you have the `utimes' function. */ +#define HAVE_UTIMES 1 + +/* Define to 1 if you have the `valloc' function. */ +#define HAVE_VALLOC 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_VALUES_H 1 + +/* Define to 1 if you have the `vasprintf' function. */ +#define HAVE_VASPRINTF 1 + +/* Define to 1 if you have the `vsnprintf' function. */ +#define HAVE_VSNPRINTF 1 + +/* Define if you have the 'wchar_t' type. */ +#define HAVE_WCHAR_T 1 + +/* Define to 1 if you have the `wcrtomb' function. */ +#define HAVE_WCRTOMB 1 + +/* Define to 1 if you have the `wcslen' function. */ +#define HAVE_WCSLEN 1 + +/* Define to 1 if you have the `wcsnlen' function. */ +#define HAVE_WCSNLEN 1 + +/* Define if you have the 'wint_t' type. */ +#define HAVE_WINT_T 1 + +/* Define to 1 if xattr is available */ +#define HAVE_XATTR 1 + +/* Define to 1 if xattr API uses XATTR_NOFOLLOW */ +/* #undef HAVE_XATTR_NOFOLLOW */ + +/* Define to 1 if you have the header file. */ +#define HAVE_XLOCALE_H 1 + +/* Define to 1 if you have the `_NSGetEnviron' function. */ +/* #undef HAVE__NSGETENVIRON */ + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Define to 1 if `major', `minor', and `makedev' are declared in . + */ +/* #undef MAJOR_IN_MKDEV */ + +/* Define to 1 if `major', `minor', and `makedev' are declared in + . */ +/* #undef MAJOR_IN_SYSMACROS */ + +/* didn't find fd_set */ +/* #undef NO_FD_SET */ + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "http://bugzilla.gnome.org/enter_bug.cgi?product=glib" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "glib" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "glib 2.50.2" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "glib" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "2.50.2" + +/* define if posix_memalign() can allocate any size */ +#define POSIX_MEMALIGN_WITH_COMPLIANT_ALLOCS 1 + +/* The size of `char', as computed by sizeof. */ +#define SIZEOF_CHAR 1 + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 8 + +/* The size of `long long', as computed by sizeof. */ +#define SIZEOF_LONG_LONG 8 + +/* The size of `short', as computed by sizeof. */ +#define SIZEOF_SHORT 2 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 8 + +/* The size of `ssize_t', as computed by sizeof. */ +#define SIZEOF_SSIZE_T 8 + +/* The size of `void *', as computed by sizeof. */ +#define SIZEOF_VOID_P 8 + +/* The size of `__int64', as computed by sizeof. */ +#define SIZEOF___INT64 0 + +/* If using the C implementation of alloca, define if you know the + direction of stack growth for your system; otherwise it will be + automatically deduced at runtime. + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ +/* #undef STACK_DIRECTION */ + +/* Number of arguments to statfs() */ +#define STATFS_ARGS 2 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Use no threads */ +/* #undef THREADS_NONE */ + +/* Use pthreads */ +#define THREADS_POSIX 1 + +/* Use w32 threads */ +/* #undef THREADS_WIN32 */ + +/* Using GNU libiconv */ +/* #undef USE_LIBICONV_GNU */ + +/* Using a native implementation of iconv in a separate library */ +/* #undef USE_LIBICONV_NATIVE */ + +/* Define to use statfs() */ +#define USE_STATFS 1 + +/* Define to use statvfs() */ +/* #undef USE_STATVFS */ + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif + + +/* using the system-supplied PCRE library */ +/* #undef USE_SYSTEM_PCRE */ + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* defines how to decorate public symbols while building */ +#define _GLIB_EXTERN __attribute__((visibility("default"))) extern + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to 1 if on MINIX. */ +/* #undef _MINIX */ + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +/* #undef _POSIX_1_SOURCE */ + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +/* #undef _POSIX_SOURCE */ + +/* Target the Windows XP API */ +/* #undef _WIN32_WINNT */ + +/* Needed to get declarations for msg_control and msg_controllen on Solaris */ +/* #undef _XOPEN_SOURCE */ + +/* Needed to get declarations for msg_control and msg_controllen on Solaris */ +/* #undef _XOPEN_SOURCE_EXTENDED */ + +/* Needed to get declarations for msg_control and msg_controllen on Solaris */ +#define __EXTENSIONS__ 1 + +/* compiler supports atomic operations */ +/* #undef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to long or long long if and don't define. */ +/* #undef intmax_t */ + +/* Define to empty if the C compiler doesn't support this keyword. */ +/* #undef signed */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ diff --git a/static/custom-include/glib/glibconfig.h b/static/custom-include/glib/glibconfig.h new file mode 100644 index 000000000..33377c3e6 --- /dev/null +++ b/static/custom-include/glib/glibconfig.h @@ -0,0 +1,196 @@ +/* glibconfig.h + * + * This is a generated file. Please modify 'configure.ac' + */ + +#ifndef __GLIBCONFIG_H__ +#define __GLIBCONFIG_H__ + +#include + +#include +#include +#define GLIB_HAVE_ALLOCA_H + +/* Specifies that GLib's g_print*() functions wrap the + * system printf functions. This is useful to know, for example, + * when using glibc's register_printf_function(). + */ +#define GLIB_USING_SYSTEM_PRINTF + +G_BEGIN_DECLS + +#define G_MINFLOAT FLT_MIN +#define G_MAXFLOAT FLT_MAX +#define G_MINDOUBLE DBL_MIN +#define G_MAXDOUBLE DBL_MAX +#define G_MINSHORT SHRT_MIN +#define G_MAXSHORT SHRT_MAX +#define G_MAXUSHORT USHRT_MAX +#define G_MININT INT_MIN +#define G_MAXINT INT_MAX +#define G_MAXUINT UINT_MAX +#define G_MINLONG LONG_MIN +#define G_MAXLONG LONG_MAX +#define G_MAXULONG ULONG_MAX + +typedef signed char gint8; +typedef unsigned char guint8; +typedef signed short gint16; +typedef unsigned short guint16; +#define G_GINT16_MODIFIER "h" +#define G_GINT16_FORMAT "hi" +#define G_GUINT16_FORMAT "hu" +typedef signed int gint32; +typedef unsigned int guint32; +#define G_GINT32_MODIFIER "" +#define G_GINT32_FORMAT "i" +#define G_GUINT32_FORMAT "u" +#define G_HAVE_GINT64 1 /* deprecated, always true */ + +typedef signed long gint64; +typedef unsigned long guint64; + +#define G_GINT64_CONSTANT(val) (val##L) +#define G_GUINT64_CONSTANT(val) (val##UL) +#define G_GINT64_MODIFIER "l" +#define G_GINT64_FORMAT "li" +#define G_GUINT64_FORMAT "lu" + +#define GLIB_SIZEOF_VOID_P 8 +#define GLIB_SIZEOF_LONG 8 +#define GLIB_SIZEOF_SIZE_T 8 +#define GLIB_SIZEOF_SSIZE_T 8 + +typedef signed long gssize; +typedef unsigned long gsize; +#define G_GSIZE_MODIFIER "l" +#define G_GSSIZE_MODIFIER "l" +#define G_GSIZE_FORMAT "lu" +#define G_GSSIZE_FORMAT "li" + +#define G_MAXSIZE G_MAXULONG +#define G_MINSSIZE G_MINLONG +#define G_MAXSSIZE G_MAXLONG + +typedef gint64 goffset; +#define G_MINOFFSET G_MININT64 +#define G_MAXOFFSET G_MAXINT64 + +#define G_GOFFSET_MODIFIER G_GINT64_MODIFIER +#define G_GOFFSET_FORMAT G_GINT64_FORMAT +#define G_GOFFSET_CONSTANT(val) G_GINT64_CONSTANT(val) + +#define G_POLLFD_FORMAT "%d" + + +#define GPOINTER_TO_INT(p) ((gint) (glong) (p)) +#define GPOINTER_TO_UINT(p) ((guint) (gulong) (p)) + +#define GINT_TO_POINTER(i) ((gpointer) (glong) (i)) +#define GUINT_TO_POINTER(u) ((gpointer) (gulong) (u)) + +typedef signed long gintptr; +typedef unsigned long guintptr; + +#define G_GINTPTR_MODIFIER "l" +#define G_GINTPTR_FORMAT "li" +#define G_GUINTPTR_FORMAT "lu" +#ifndef G_DISABLE_DEPRECATED +#define g_ATEXIT(proc) (atexit (proc)) +#define g_memmove(dest,src,len) G_STMT_START { memmove ((dest), (src), (len)); } G_STMT_END +#endif + +#define GLIB_MAJOR_VERSION 2 +#define GLIB_MINOR_VERSION 50 +#define GLIB_MICRO_VERSION 2 + +#define G_OS_UNIX + + +#define G_VA_COPY va_copy +#define G_VA_COPY_AS_ARRAY 1 + +#ifndef __cplusplus +# define G_HAVE_ISO_VARARGS 1 +#endif +#ifdef __cplusplus +# define G_HAVE_ISO_VARARGS 1 +#endif + +/* gcc-2.95.x supports both gnu style and ISO varargs, but if -ansi + * is passed ISO vararg support is turned off, and there is no work + * around to turn it on, so we unconditionally turn it off. + */ +#if __GNUC__ == 2 && __GNUC_MINOR__ == 95 +# undef G_HAVE_ISO_VARARGS +#endif + +#define G_HAVE_GNUC_VARARGS 1 +#define G_HAVE_GROWING_STACK 0 + +#define G_HAVE_GNUC_VISIBILITY 1 +#if defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) +#define G_GNUC_INTERNAL __attribute__((visibility("hidden"))) +#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) +#define G_GNUC_INTERNAL __hidden +#elif defined (__GNUC__) && defined (G_HAVE_GNUC_VISIBILITY) +#define G_GNUC_INTERNAL __attribute__((visibility("hidden"))) +#else +#define G_GNUC_INTERNAL +#endif + +#define G_THREADS_ENABLED +#define G_THREADS_IMPL_POSIX + +#define G_ATOMIC_LOCK_FREE + +#define GINT16_TO_LE(val) ((gint16) (val)) +#define GUINT16_TO_LE(val) ((guint16) (val)) +#define GINT16_TO_BE(val) ((gint16) GUINT16_SWAP_LE_BE (val)) +#define GUINT16_TO_BE(val) (GUINT16_SWAP_LE_BE (val)) +#define GINT32_TO_LE(val) ((gint32) (val)) +#define GUINT32_TO_LE(val) ((guint32) (val)) +#define GINT32_TO_BE(val) ((gint32) GUINT32_SWAP_LE_BE (val)) +#define GUINT32_TO_BE(val) (GUINT32_SWAP_LE_BE (val)) +#define GINT64_TO_LE(val) ((gint64) (val)) +#define GUINT64_TO_LE(val) ((guint64) (val)) +#define GINT64_TO_BE(val) ((gint64) GUINT64_SWAP_LE_BE (val)) +#define GUINT64_TO_BE(val) (GUINT64_SWAP_LE_BE (val)) +#define GLONG_TO_LE(val) ((glong) GINT64_TO_LE (val)) +#define GULONG_TO_LE(val) ((gulong) GUINT64_TO_LE (val)) +#define GLONG_TO_BE(val) ((glong) GINT64_TO_BE (val)) +#define GULONG_TO_BE(val) ((gulong) GUINT64_TO_BE (val)) +#define GINT_TO_LE(val) ((gint) GINT32_TO_LE (val)) +#define GUINT_TO_LE(val) ((guint) GUINT32_TO_LE (val)) +#define GINT_TO_BE(val) ((gint) GINT32_TO_BE (val)) +#define GUINT_TO_BE(val) ((guint) GUINT32_TO_BE (val)) +#define GSIZE_TO_LE(val) ((gsize) GUINT64_TO_LE (val)) +#define GSSIZE_TO_LE(val) ((gssize) GINT64_TO_LE (val)) +#define GSIZE_TO_BE(val) ((gsize) GUINT64_TO_BE (val)) +#define GSSIZE_TO_BE(val) ((gssize) GINT64_TO_BE (val)) +#define G_BYTE_ORDER G_LITTLE_ENDIAN + +#define GLIB_SYSDEF_POLLIN =1 +#define GLIB_SYSDEF_POLLOUT =4 +#define GLIB_SYSDEF_POLLPRI =2 +#define GLIB_SYSDEF_POLLHUP =16 +#define GLIB_SYSDEF_POLLERR =8 +#define GLIB_SYSDEF_POLLNVAL =32 + +#define G_MODULE_SUFFIX "so" + +typedef int GPid; +#define G_PID_FORMAT "i" + +#define GLIB_SYSDEF_AF_UNIX 1 +#define GLIB_SYSDEF_AF_INET 2 +#define GLIB_SYSDEF_AF_INET6 10 + +#define GLIB_SYSDEF_MSG_OOB 1 +#define GLIB_SYSDEF_MSG_PEEK 2 +#define GLIB_SYSDEF_MSG_DONTROUTE 4 + +G_END_DECLS + +#endif /* __GLIBCONFIG_H__ */ diff --git a/static/ensure_deps.sh b/static/ensure_deps.sh index 3f87e8e7e..8b7c8c47e 100755 --- a/static/ensure_deps.sh +++ b/static/ensure_deps.sh @@ -3,6 +3,7 @@ CAIRO_VERSION=1.12.18 FREETYPE_VERSION=2.6 GIFLIB_VERSION=4.2.3 +GLIB_VERSION=2.50.2 HARFBUZZ_VERSION=1.4.2 LIBJPEG_VERSION=1.2.1 LIBPNG_VERSION=1.2.56 @@ -14,6 +15,7 @@ CAIRO_URL=http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz FONTCONFIG_URL=http://cgit.freedesktop.org/fontconfig/plain/fontconfig/fontconfig.h FREETYPE_URL=http://download.savannah.gnu.org/releases/freetype/freetype-$FREETYPE_VERSION.tar.gz GIFLIB_URL=http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-$GIFLIB_VERSION.tar.gz +GLIB_URL=https://download.gnome.org/sources/glib/2.50/glib-$GLIB_VERSION.tar.xz HARFBUZZ_URL=https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-$HARFBUZZ_VERSION.tar.bz2 LIBJPEG_URL=http://downloads.sourceforge.net/project/libjpeg-turbo/$LIBJPEG_VERSION/libjpeg-turbo-$LIBJPEG_VERSION.tar.gz LIBPNG_URL=http://sourceforge.net/projects/libpng/files/libpng12/$LIBPNG_VERSION/libpng-$LIBPNG_VERSION.tar.xz @@ -65,6 +67,7 @@ fi fetch $FREETYPE_URL freetype && fetch $GIFLIB_URL giflib && +fetch_xz $GLIB_URL glib && fetch_bz2 $HARFBUZZ_URL harfbuzz && fetch $LIBJPEG_URL libjpeg && fetch_xz $LIBPNG_URL libpng && @@ -73,9 +76,10 @@ fetch $PIXMAN_URL pixman && fetch $ZLIB_URL zlib || exit $? -if [ ! -d "cairo" ] || [ ! -d "freetype" ] || [ ! -d "giflib" ] \ -|| [ ! -d "harfbuzz" ] || [ ! -d "libjpeg" ] || [ ! -d "libpng" ] \ -|| [ ! -d "pango" ] || [ ! -d "pixman" ] || [ ! -d "zlib" ]; then +if [ ! -d "cairo" ] || [ ! -d "freetype" ] || [ ! -d "giflib" ] \ +|| [ ! -d "glib" ] || [ ! -d "harfbuzz" ] || [ ! -d "libjpeg" ] \ +|| [ ! -d "libpng" ] || [ ! -d "pango" ] || [ ! -d "pixman" ] \ +|| [ ! -d "zlib" ] ; then echo false else echo true diff --git a/static/glib.gyp b/static/glib.gyp new file mode 100644 index 000000000..9403afffc --- /dev/null +++ b/static/glib.gyp @@ -0,0 +1,195 @@ +{ + 'includes': ['common.gyp', 'locations.gyp'], + 'targets': [{ + 'target_name': 'glib/libcharset', + 'type': 'static_library', + 'include_dirs': [ + '<(glib_root)', + '<(glib_root)/glib', + '<(glib_root)/glib/libcharset', + 'custom-include/glib' + ], + 'defines': [ + 'HAVE_CONFIG_H', 'LIBDIR=\"/usr/local/lib\"' + ], + 'sources': [ + "<(glib_root)glib/libcharset/localcharset.c", + ] + }, { + 'target_name': 'glib/pcre', + 'type': 'static_library', + 'include_dirs': [ + '<(glib_root)', + '<(glib_root)/glib', + '<(glib_root)/glib/pcre', + 'custom-include/glib' + ], + 'defines': [ + 'HAVE_CONFIG_H', 'LIBDIR=\"/usr/local/lib\"', + 'G_LOG_DOMAIN=\"GLib-GRegex\"', 'HAVE_MEMMOVE', 'SUPPORT_UCP', + 'SUPPORT_UTF', 'SUPPORT_UTF8', 'NEWLINE=-1', + 'MATCH_LIMIT=10000000', 'MATCH_LIMIT_RECURSION=8192', + 'MAX_NAME_SIZE=32', 'MAX_NAME_COUNT=10000', 'MAX_DUPLENGTH=30000', + 'LINK_SIZE=2', 'POSIX_MALLOC_THRESHOLD=10', 'PCRE_STATIC' + ], + 'sources': [ + "<(glib_root)glib/pcre/pcre_byte_order.c", + "<(glib_root)glib/pcre/pcre_chartables.c", + "<(glib_root)glib/pcre/pcre_compile.c", + "<(glib_root)glib/pcre/pcre_config.c", + "<(glib_root)glib/pcre/pcre_dfa_exec.c", + "<(glib_root)glib/pcre/pcre_exec.c", + "<(glib_root)glib/pcre/pcre_fullinfo.c", + "<(glib_root)glib/pcre/pcre_get.c", + "<(glib_root)glib/pcre/pcre_globals.c", + "<(glib_root)glib/pcre/pcre_jit_compile.c", + "<(glib_root)glib/pcre/pcre_newline.c", + "<(glib_root)glib/pcre/pcre_ord2utf8.c", + "<(glib_root)glib/pcre/pcre_string_utils.c", + "<(glib_root)glib/pcre/pcre_study.c", + "<(glib_root)glib/pcre/pcre_tables.c", + "<(glib_root)glib/pcre/pcre_valid_utf8.c", + "<(glib_root)glib/pcre/pcre_version.c", + "<(glib_root)glib/pcre/pcre_xclass.c" + ] + }, { + 'target_name': 'glib', + 'type': 'static_library', + 'include_dirs': [ + '<(glib_root)', + '<(glib_root)/glib', + '<(glib_root)/glib/libcharset', + '<(glib_root)/glib/pcre', + 'custom-include/glib' + ], + 'defines': [ + 'HAVE_CONFIG_H', 'G_LOG_DOMAIN=\"GLib\"', 'G_DISABLE_CAST_CHECKS', + 'GLIB_COMPILATION', 'PCRE_STATIC' + ], + 'dependencies': [ + 'glib/libcharset', + 'glib/pcre' + ], + 'sources': [ + "<(glib_root)glib/deprecated/gallocator.c", + "<(glib_root)glib/deprecated/gcache.c", + "<(glib_root)glib/deprecated/gcompletion.c", + "<(glib_root)glib/deprecated/grel.c", + "<(glib_root)glib/deprecated/gthread-deprecated.c", + "<(glib_root)glib/garray.c", + "<(glib_root)glib/gasyncqueue.c", + "<(glib_root)glib/gatomic.c", + "<(glib_root)glib/gbacktrace.c", + "<(glib_root)glib/gbase64.c", + "<(glib_root)glib/gbitlock.c", + "<(glib_root)glib/gbookmarkfile.c", + "<(glib_root)glib/gbytes.c", + "<(glib_root)glib/gcharset.c", + "<(glib_root)glib/gchecksum.c", + "<(glib_root)glib/gconvert.c", + "<(glib_root)glib/gdataset.c", + "<(glib_root)glib/gdate.c", + "<(glib_root)glib/gdatetime.c", + "<(glib_root)glib/gdir.c", + "<(glib_root)glib/genviron.c", + "<(glib_root)glib/gerror.c", + "<(glib_root)glib/gfileutils.c", + "<(glib_root)glib/ggettext.c", + "<(glib_root)glib/ghash.c", + "<(glib_root)glib/ghmac.c", + "<(glib_root)glib/ghook.c", + "<(glib_root)glib/ghostutils.c", + "<(glib_root)glib/giochannel.c", + "<(glib_root)glib/gkeyfile.c", + "<(glib_root)glib/glib-init.c", + "<(glib_root)glib/glib-private.c", + "<(glib_root)glib/glist.c", + "<(glib_root)glib/gmain.c", + "<(glib_root)glib/gmappedfile.c", + "<(glib_root)glib/gmarkup.c", + "<(glib_root)glib/gmem.c", + "<(glib_root)glib/gmessages.c", + "<(glib_root)glib/gnode.c", + "<(glib_root)glib/goption.c", + "<(glib_root)glib/gpattern.c", + "<(glib_root)glib/gpoll.c", + "<(glib_root)glib/gprimes.c", + "<(glib_root)glib/gqsort.c", + "<(glib_root)glib/gquark.c", + "<(glib_root)glib/gqueue.c", + "<(glib_root)glib/grand.c", + "<(glib_root)glib/gregex.c", + "<(glib_root)glib/gscanner.c", + "<(glib_root)glib/gsequence.c", + "<(glib_root)glib/gshell.c", + "<(glib_root)glib/gslice.c", + "<(glib_root)glib/gslist.c", + "<(glib_root)glib/gstdio.c", + "<(glib_root)glib/gstrfuncs.c", + "<(glib_root)glib/gstring.c", + "<(glib_root)glib/gstdio.c", + "<(glib_root)glib/gstringchunk.c", + "<(glib_root)glib/gtestutils.c", + "<(glib_root)glib/gthread.c", + "<(glib_root)glib/gthreadpool.c", + "<(glib_root)glib/gtimer.c", + "<(glib_root)glib/gtimezone.c", + "<(glib_root)glib/gtranslit.c", + "<(glib_root)glib/gtrashstack.c", + "<(glib_root)glib/gtree.c", + "<(glib_root)glib/guniprop.c", + "<(glib_root)glib/gutf8.c", + "<(glib_root)glib/gunibreak.c", + "<(glib_root)glib/gunicollate.c", + "<(glib_root)glib/gunidecomp.c", + "<(glib_root)glib/gurifuncs.c", + "<(glib_root)glib/gutils.c", + "<(glib_root)glib/gvariant.c", + "<(glib_root)glib/gvariant-core.c", + "<(glib_root)glib/gvariant-parser.c", + "<(glib_root)glib/gvariant-serialiser.c", + "<(glib_root)glib/gvarianttypeinfo.c", + "<(glib_root)glib/gvarianttype.c", + "<(glib_root)glib/gversion.c", + "<(glib_root)glib/gwakeup.c", + "<(glib_root)glib/gprintf.c", + "<(glib_root)glib/glib-unix.c", + "<(glib_root)glib/gthread-posix.c", + "<(glib_root)glib/giounix.c", + "<(glib_root)glib/gspawn.c" + ] + }, { + 'target_name': 'gobject', + 'type': 'static_library', + 'include_dirs': [ + '<(glib_root)', + '<(glib_root)/glib', + '<(glib_root)/gobject', + 'custom-include/glib' + ], + 'defines': [ + 'HAVE_CONFIG_H', 'G_LOG_DOMAIN=\"GLib-GObject\"', + 'G_DISABLE_CAST_CHECKS', 'GOBJECT_COMPILATION' + ], + 'sources': [ + "<(glib_root)gobject/gatomicarray.c", + "<(glib_root)gobject/gbinding.c", + "<(glib_root)gobject/gboxed.c", + "<(glib_root)gobject/gclosure.c", + "<(glib_root)gobject/genums.c", + "<(glib_root)gobject/gmarshal.c", + "<(glib_root)gobject/gobject.c", + "<(glib_root)gobject/gparam.c", + "<(glib_root)gobject/gparamspecs.c", + "<(glib_root)gobject/gsignal.c", + "<(glib_root)gobject/gsourceclosure.c", + "<(glib_root)gobject/gtype.c", + "<(glib_root)gobject/gtypemodule.c", + "<(glib_root)gobject/gtypeplugin.c", + "<(glib_root)gobject/gvalue.c", + "<(glib_root)gobject/gvaluearray.c", + "<(glib_root)gobject/gvaluetransform.c", + "<(glib_root)gobject/gvaluetypes.c" + ] + }] +} diff --git a/static/harfbuzz.gyp b/static/harfbuzz.gyp index 91a912769..0211b5dcf 100644 --- a/static/harfbuzz.gyp +++ b/static/harfbuzz.gyp @@ -12,11 +12,14 @@ 'target_name': 'harfbuzz', 'type': 'static_library', 'include_dirs': [ - ' Date: Sun, 12 Feb 2017 19:00:13 +0100 Subject: [PATCH 064/183] Use static `fontconfig` library --- static.gyp | 5 +- static/custom-include/fontconfig/config.h | 360 ++++++++++++++ static/custom-include/fontconfig/fcalias.h | 410 ++++++++++++++++ .../custom-include/fontconfig/fcaliastail.h | 464 ++++++++++++++++++ static/custom-include/fontconfig/fcftalias.h | 12 + .../custom-include/fontconfig/fcftaliastail.h | 20 + static/ensure_deps.sh | 35 +- static/fontconfig.gyp | 51 ++ static/freetype.gyp | 3 +- static/locations.gyp | 1 + 10 files changed, 1340 insertions(+), 21 deletions(-) create mode 100644 static/custom-include/fontconfig/config.h create mode 100644 static/custom-include/fontconfig/fcalias.h create mode 100644 static/custom-include/fontconfig/fcaliastail.h create mode 100644 static/custom-include/fontconfig/fcftalias.h create mode 100644 static/custom-include/fontconfig/fcftaliastail.h create mode 100644 static/fontconfig.gyp diff --git a/static.gyp b/static.gyp index 14984686b..6ef4fe500 100644 --- a/static.gyp +++ b/static.gyp @@ -8,7 +8,7 @@ [{ 'includes': ['canvas.gypi'], 'libraries': [ - ' header file, and it defines `DIR'. + */ +#define HAVE_DIRENT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ +/* #undef HAVE_DOPRNT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `fstatfs' function. */ +#define HAVE_FSTATFS 1 + +/* Define to 1 if you have the `fstatvfs' function. */ +#define HAVE_FSTATVFS 1 + +/* FT_Bitmap_Size structure includes y_ppem field */ +#define HAVE_FT_BITMAP_SIZE_Y_PPEM 1 + +/* Define to 1 if you have the `FT_Get_BDF_Property' function. */ +#define HAVE_FT_GET_BDF_PROPERTY 1 + +/* Define to 1 if you have the `FT_Get_Next_Char' function. */ +#define HAVE_FT_GET_NEXT_CHAR 1 + +/* Define to 1 if you have the `FT_Get_PS_Font_Info' function. */ +#define HAVE_FT_GET_PS_FONT_INFO 1 + +/* Define to 1 if you have the `FT_Get_X11_Font_Format' function. */ +#define HAVE_FT_GET_X11_FONT_FORMAT 1 + +/* Define to 1 if you have the `FT_Has_PS_Glyph_Names' function. */ +#define HAVE_FT_HAS_PS_GLYPH_NAMES 1 + +/* Define to 1 if you have the `FT_Select_Size' function. */ +#define HAVE_FT_SELECT_SIZE 1 + +/* Define to 1 if you have the `getexecname' function. */ +/* #undef HAVE_GETEXECNAME */ + +/* Define to 1 if you have the `getopt' function. */ +#define HAVE_GETOPT 1 + +/* Define to 1 if you have the `getopt_long' function. */ +#define HAVE_GETOPT_LONG 1 + +/* Define to 1 if you have the `getpagesize' function. */ +#define HAVE_GETPAGESIZE 1 + +/* Define to 1 if you have the `getprogname' function. */ +/* #undef HAVE_GETPROGNAME */ + +/* Have Intel __sync_* atomic primitives */ +#define HAVE_INTEL_ATOMIC_PRIMITIVES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `link' function. */ +#define HAVE_LINK 1 + +/* Define to 1 if you have the `lrand48' function. */ +#define HAVE_LRAND48 1 + +/* Define to 1 if you have the `lstat' function. */ +#define HAVE_LSTAT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `mkdtemp' function. */ +#define HAVE_MKDTEMP 1 + +/* Define to 1 if you have the `mkostemp' function. */ +#define HAVE_MKOSTEMP 1 + +/* Define to 1 if you have the `mkstemp' function. */ +#define HAVE_MKSTEMP 1 + +/* Define to 1 if you have a working `mmap' system call. */ +#define HAVE_MMAP 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. */ +/* #undef HAVE_NDIR_H */ + +/* Define to 1 if you have the 'posix_fadvise' function. */ +#define HAVE_POSIX_FADVISE 1 + +/* Have POSIX threads */ +#define HAVE_PTHREAD 1 + +/* Have PTHREAD_PRIO_INHERIT. */ +#define HAVE_PTHREAD_PRIO_INHERIT 1 + +/* Define to 1 if you have the `rand' function. */ +#define HAVE_RAND 1 + +/* Define to 1 if you have the `random' function. */ +#define HAVE_RANDOM 1 + +/* Define to 1 if you have the `random_r' function. */ +#define HAVE_RANDOM_R 1 + +/* Define to 1 if you have the `rand_r' function. */ +#define HAVE_RAND_R 1 + +/* Define to 1 if you have the `readlink' function. */ +#define HAVE_READLINK 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SCHED_H */ + +/* Have sched_yield */ +/* #undef HAVE_SCHED_YIELD */ + +/* Have Solaris __machine_*_barrier and atomic_* operations */ +/* #undef HAVE_SOLARIS_ATOMIC_OPS */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if `d_type' is a member of `struct dirent'. */ +#define HAVE_STRUCT_DIRENT_D_TYPE 1 + +/* Define to 1 if `f_flags' is a member of `struct statfs'. */ +#define HAVE_STRUCT_STATFS_F_FLAGS 1 + +/* Define to 1 if `f_fstypename' is a member of `struct statfs'. */ +/* #undef HAVE_STRUCT_STATFS_F_FSTYPENAME */ + +/* Define to 1 if `f_basetype' is a member of `struct statvfs'. */ +/* #undef HAVE_STRUCT_STATVFS_F_BASETYPE */ + +/* Define to 1 if `f_fstypename' is a member of `struct statvfs'. */ +/* #undef HAVE_STRUCT_STATVFS_F_FSTYPENAME */ + +/* Define to 1 if `st_mtim' is a member of `struct stat'. */ +#define HAVE_STRUCT_STAT_ST_MTIM 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_DIR_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_MOUNT_H 1 + +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_NDIR_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STATFS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STATVFS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_VFS_H 1 + +/* Define to 1 if `usLowerOpticalPointSize' is a member of `TT_OS2'. */ +#define HAVE_TT_OS2_USLOWEROPTICALPOINTSIZE 1 + +/* Define to 1 if `usUpperOpticalPointSize' is a member of `TT_OS2'. */ +#define HAVE_TT_OS2_USUPPEROPTICALPOINTSIZE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `vprintf' function. */ +#define HAVE_VPRINTF 1 + +/* Can use #warning in C files */ +#define HAVE_WARNING_CPP_DIRECTIVE 1 + +/* Use xmlparse.h instead of expat.h */ +/* #undef HAVE_XMLPARSE_H */ + +/* Define to 1 if you have the `XML_SetDoctypeDeclHandler' function. */ +#define HAVE_XML_SETDOCTYPEDECLHANDLER 1 + +/* Define to 1 if you have the `_mktemp_s' function. */ +/* #undef HAVE__MKTEMP_S */ + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "fontconfig" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "https://bugs.freedesktop.org/enter_bug.cgi?product=fontconfig" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "fontconfig" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "fontconfig 2.12.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "fontconfig" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "2.12.1" + +/* Define to necessary symbol if this constant uses a non-standard name on + your system. */ +/* #undef PTHREAD_CREATE_JOINABLE */ + +/* The size of `char', as computed by sizeof. */ +/* #undef SIZEOF_CHAR */ + +/* The size of `int', as computed by sizeof. */ +/* #undef SIZEOF_INT */ + +/* The size of `long', as computed by sizeof. */ +/* #undef SIZEOF_LONG */ + +/* The size of `short', as computed by sizeof. */ +/* #undef SIZEOF_SHORT */ + +/* The size of `void*', as computed by sizeof. */ +/* #undef SIZEOF_VOIDP */ + +/* The size of `void *', as computed by sizeof. */ +#define SIZEOF_VOID_P 8 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Use iconv. */ +#define USE_ICONV 0 + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif + + +/* Version number of package */ +#define VERSION "2.12.1" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to 1 if on MINIX. */ +/* #undef _MINIX */ + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +/* #undef _POSIX_1_SOURCE */ + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +/* #undef _POSIX_SOURCE */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to `int' if does not define. */ +/* #undef pid_t */ + +#include "config-fixups.h" diff --git a/static/custom-include/fontconfig/fcalias.h b/static/custom-include/fontconfig/fcalias.h new file mode 100644 index 000000000..06d47ed73 --- /dev/null +++ b/static/custom-include/fontconfig/fcalias.h @@ -0,0 +1,410 @@ +extern __typeof (FcBlanksCreate) IA__FcBlanksCreate __attribute((visibility("hidden"))); +#define FcBlanksCreate IA__FcBlanksCreate +extern __typeof (FcBlanksDestroy) IA__FcBlanksDestroy __attribute((visibility("hidden"))); +#define FcBlanksDestroy IA__FcBlanksDestroy +extern __typeof (FcBlanksAdd) IA__FcBlanksAdd __attribute((visibility("hidden"))); +#define FcBlanksAdd IA__FcBlanksAdd +extern __typeof (FcBlanksIsMember) IA__FcBlanksIsMember __attribute((visibility("hidden"))); +#define FcBlanksIsMember IA__FcBlanksIsMember +extern __typeof (FcCacheCopySet) IA__FcCacheCopySet __attribute((visibility("hidden"))); +#define FcCacheCopySet IA__FcCacheCopySet +extern __typeof (FcCacheNumSubdir) IA__FcCacheNumSubdir __attribute((visibility("hidden"))); +#define FcCacheNumSubdir IA__FcCacheNumSubdir +extern __typeof (FcCacheNumFont) IA__FcCacheNumFont __attribute((visibility("hidden"))); +#define FcCacheNumFont IA__FcCacheNumFont +extern __typeof (FcDirCacheUnlink) IA__FcDirCacheUnlink __attribute((visibility("hidden"))); +#define FcDirCacheUnlink IA__FcDirCacheUnlink +extern __typeof (FcDirCacheValid) IA__FcDirCacheValid __attribute((visibility("hidden"))); +#define FcDirCacheValid IA__FcDirCacheValid +extern __typeof (FcDirCacheClean) IA__FcDirCacheClean __attribute((visibility("hidden"))); +#define FcDirCacheClean IA__FcDirCacheClean +extern __typeof (FcCacheCreateTagFile) IA__FcCacheCreateTagFile __attribute((visibility("hidden"))); +#define FcCacheCreateTagFile IA__FcCacheCreateTagFile +extern __typeof (FcConfigHome) IA__FcConfigHome __attribute((visibility("hidden"))); +#define FcConfigHome IA__FcConfigHome +extern __typeof (FcConfigEnableHome) IA__FcConfigEnableHome __attribute((visibility("hidden"))); +#define FcConfigEnableHome IA__FcConfigEnableHome +extern __typeof (FcConfigFilename) IA__FcConfigFilename __attribute((visibility("hidden"))); +#define FcConfigFilename IA__FcConfigFilename +extern __typeof (FcConfigCreate) IA__FcConfigCreate __attribute((visibility("hidden"))); +#define FcConfigCreate IA__FcConfigCreate +extern __typeof (FcConfigReference) IA__FcConfigReference __attribute((visibility("hidden"))); +#define FcConfigReference IA__FcConfigReference +extern __typeof (FcConfigDestroy) IA__FcConfigDestroy __attribute((visibility("hidden"))); +#define FcConfigDestroy IA__FcConfigDestroy +extern __typeof (FcConfigSetCurrent) IA__FcConfigSetCurrent __attribute((visibility("hidden"))); +#define FcConfigSetCurrent IA__FcConfigSetCurrent +extern __typeof (FcConfigGetCurrent) IA__FcConfigGetCurrent __attribute((visibility("hidden"))); +#define FcConfigGetCurrent IA__FcConfigGetCurrent +extern __typeof (FcConfigUptoDate) IA__FcConfigUptoDate __attribute((visibility("hidden"))); +#define FcConfigUptoDate IA__FcConfigUptoDate +extern __typeof (FcConfigBuildFonts) IA__FcConfigBuildFonts __attribute((visibility("hidden"))); +#define FcConfigBuildFonts IA__FcConfigBuildFonts +extern __typeof (FcConfigGetFontDirs) IA__FcConfigGetFontDirs __attribute((visibility("hidden"))); +#define FcConfigGetFontDirs IA__FcConfigGetFontDirs +extern __typeof (FcConfigGetConfigDirs) IA__FcConfigGetConfigDirs __attribute((visibility("hidden"))); +#define FcConfigGetConfigDirs IA__FcConfigGetConfigDirs +extern __typeof (FcConfigGetConfigFiles) IA__FcConfigGetConfigFiles __attribute((visibility("hidden"))); +#define FcConfigGetConfigFiles IA__FcConfigGetConfigFiles +extern __typeof (FcConfigGetCache) IA__FcConfigGetCache __attribute((visibility("hidden"))); +#define FcConfigGetCache IA__FcConfigGetCache +extern __typeof (FcConfigGetBlanks) IA__FcConfigGetBlanks __attribute((visibility("hidden"))); +#define FcConfigGetBlanks IA__FcConfigGetBlanks +extern __typeof (FcConfigGetCacheDirs) IA__FcConfigGetCacheDirs __attribute((visibility("hidden"))); +#define FcConfigGetCacheDirs IA__FcConfigGetCacheDirs +extern __typeof (FcConfigGetRescanInterval) IA__FcConfigGetRescanInterval __attribute((visibility("hidden"))); +#define FcConfigGetRescanInterval IA__FcConfigGetRescanInterval +extern __typeof (FcConfigSetRescanInterval) IA__FcConfigSetRescanInterval __attribute((visibility("hidden"))); +#define FcConfigSetRescanInterval IA__FcConfigSetRescanInterval +extern __typeof (FcConfigGetFonts) IA__FcConfigGetFonts __attribute((visibility("hidden"))); +#define FcConfigGetFonts IA__FcConfigGetFonts +extern __typeof (FcConfigAppFontAddFile) IA__FcConfigAppFontAddFile __attribute((visibility("hidden"))); +#define FcConfigAppFontAddFile IA__FcConfigAppFontAddFile +extern __typeof (FcConfigAppFontAddDir) IA__FcConfigAppFontAddDir __attribute((visibility("hidden"))); +#define FcConfigAppFontAddDir IA__FcConfigAppFontAddDir +extern __typeof (FcConfigAppFontClear) IA__FcConfigAppFontClear __attribute((visibility("hidden"))); +#define FcConfigAppFontClear IA__FcConfigAppFontClear +extern __typeof (FcConfigSubstituteWithPat) IA__FcConfigSubstituteWithPat __attribute((visibility("hidden"))); +#define FcConfigSubstituteWithPat IA__FcConfigSubstituteWithPat +extern __typeof (FcConfigSubstitute) IA__FcConfigSubstitute __attribute((visibility("hidden"))); +#define FcConfigSubstitute IA__FcConfigSubstitute +extern __typeof (FcConfigGetSysRoot) IA__FcConfigGetSysRoot __attribute((visibility("hidden"))); +#define FcConfigGetSysRoot IA__FcConfigGetSysRoot +extern __typeof (FcConfigSetSysRoot) IA__FcConfigSetSysRoot __attribute((visibility("hidden"))); +#define FcConfigSetSysRoot IA__FcConfigSetSysRoot +extern __typeof (FcCharSetCreate) IA__FcCharSetCreate __attribute((visibility("hidden"))); +#define FcCharSetCreate IA__FcCharSetCreate +extern __typeof (FcCharSetNew) IA__FcCharSetNew __attribute((visibility("hidden"))); +#define FcCharSetNew IA__FcCharSetNew +extern __typeof (FcCharSetDestroy) IA__FcCharSetDestroy __attribute((visibility("hidden"))); +#define FcCharSetDestroy IA__FcCharSetDestroy +extern __typeof (FcCharSetAddChar) IA__FcCharSetAddChar __attribute((visibility("hidden"))); +#define FcCharSetAddChar IA__FcCharSetAddChar +extern __typeof (FcCharSetDelChar) IA__FcCharSetDelChar __attribute((visibility("hidden"))); +#define FcCharSetDelChar IA__FcCharSetDelChar +extern __typeof (FcCharSetCopy) IA__FcCharSetCopy __attribute((visibility("hidden"))); +#define FcCharSetCopy IA__FcCharSetCopy +extern __typeof (FcCharSetEqual) IA__FcCharSetEqual __attribute((visibility("hidden"))); +#define FcCharSetEqual IA__FcCharSetEqual +extern __typeof (FcCharSetIntersect) IA__FcCharSetIntersect __attribute((visibility("hidden"))); +#define FcCharSetIntersect IA__FcCharSetIntersect +extern __typeof (FcCharSetUnion) IA__FcCharSetUnion __attribute((visibility("hidden"))); +#define FcCharSetUnion IA__FcCharSetUnion +extern __typeof (FcCharSetSubtract) IA__FcCharSetSubtract __attribute((visibility("hidden"))); +#define FcCharSetSubtract IA__FcCharSetSubtract +extern __typeof (FcCharSetMerge) IA__FcCharSetMerge __attribute((visibility("hidden"))); +#define FcCharSetMerge IA__FcCharSetMerge +extern __typeof (FcCharSetHasChar) IA__FcCharSetHasChar __attribute((visibility("hidden"))); +#define FcCharSetHasChar IA__FcCharSetHasChar +extern __typeof (FcCharSetCount) IA__FcCharSetCount __attribute((visibility("hidden"))); +#define FcCharSetCount IA__FcCharSetCount +extern __typeof (FcCharSetIntersectCount) IA__FcCharSetIntersectCount __attribute((visibility("hidden"))); +#define FcCharSetIntersectCount IA__FcCharSetIntersectCount +extern __typeof (FcCharSetSubtractCount) IA__FcCharSetSubtractCount __attribute((visibility("hidden"))); +#define FcCharSetSubtractCount IA__FcCharSetSubtractCount +extern __typeof (FcCharSetIsSubset) IA__FcCharSetIsSubset __attribute((visibility("hidden"))); +#define FcCharSetIsSubset IA__FcCharSetIsSubset +extern __typeof (FcCharSetFirstPage) IA__FcCharSetFirstPage __attribute((visibility("hidden"))); +#define FcCharSetFirstPage IA__FcCharSetFirstPage +extern __typeof (FcCharSetNextPage) IA__FcCharSetNextPage __attribute((visibility("hidden"))); +#define FcCharSetNextPage IA__FcCharSetNextPage +extern __typeof (FcCharSetCoverage) IA__FcCharSetCoverage __attribute((visibility("hidden"))); +#define FcCharSetCoverage IA__FcCharSetCoverage +extern __typeof (FcValuePrint) IA__FcValuePrint __attribute((visibility("hidden"))); +#define FcValuePrint IA__FcValuePrint +extern __typeof (FcPatternPrint) IA__FcPatternPrint __attribute((visibility("hidden"))); +#define FcPatternPrint IA__FcPatternPrint +extern __typeof (FcFontSetPrint) IA__FcFontSetPrint __attribute((visibility("hidden"))); +#define FcFontSetPrint IA__FcFontSetPrint +extern __typeof (FcGetDefaultLangs) IA__FcGetDefaultLangs __attribute((visibility("hidden"))); +#define FcGetDefaultLangs IA__FcGetDefaultLangs +extern __typeof (FcDefaultSubstitute) IA__FcDefaultSubstitute __attribute((visibility("hidden"))); +#define FcDefaultSubstitute IA__FcDefaultSubstitute +extern __typeof (FcFileIsDir) IA__FcFileIsDir __attribute((visibility("hidden"))); +#define FcFileIsDir IA__FcFileIsDir +extern __typeof (FcFileScan) IA__FcFileScan __attribute((visibility("hidden"))); +#define FcFileScan IA__FcFileScan +extern __typeof (FcDirScan) IA__FcDirScan __attribute((visibility("hidden"))); +#define FcDirScan IA__FcDirScan +extern __typeof (FcDirSave) IA__FcDirSave __attribute((visibility("hidden"))); +#define FcDirSave IA__FcDirSave +extern __typeof (FcDirCacheLoad) IA__FcDirCacheLoad __attribute((visibility("hidden"))); +#define FcDirCacheLoad IA__FcDirCacheLoad +extern __typeof (FcDirCacheRescan) IA__FcDirCacheRescan __attribute((visibility("hidden"))); +#define FcDirCacheRescan IA__FcDirCacheRescan +extern __typeof (FcDirCacheRead) IA__FcDirCacheRead __attribute((visibility("hidden"))); +#define FcDirCacheRead IA__FcDirCacheRead +extern __typeof (FcDirCacheLoadFile) IA__FcDirCacheLoadFile __attribute((visibility("hidden"))); +#define FcDirCacheLoadFile IA__FcDirCacheLoadFile +extern __typeof (FcDirCacheUnload) IA__FcDirCacheUnload __attribute((visibility("hidden"))); +#define FcDirCacheUnload IA__FcDirCacheUnload +extern __typeof (FcFreeTypeQuery) IA__FcFreeTypeQuery __attribute((visibility("hidden"))); +#define FcFreeTypeQuery IA__FcFreeTypeQuery +extern __typeof (FcFontSetCreate) IA__FcFontSetCreate __attribute((visibility("hidden"))); +#define FcFontSetCreate IA__FcFontSetCreate +extern __typeof (FcFontSetDestroy) IA__FcFontSetDestroy __attribute((visibility("hidden"))); +#define FcFontSetDestroy IA__FcFontSetDestroy +extern __typeof (FcFontSetAdd) IA__FcFontSetAdd __attribute((visibility("hidden"))); +#define FcFontSetAdd IA__FcFontSetAdd +extern __typeof (FcInitLoadConfig) IA__FcInitLoadConfig __attribute((visibility("hidden"))); +#define FcInitLoadConfig IA__FcInitLoadConfig +extern __typeof (FcInitLoadConfigAndFonts) IA__FcInitLoadConfigAndFonts __attribute((visibility("hidden"))); +#define FcInitLoadConfigAndFonts IA__FcInitLoadConfigAndFonts +extern __typeof (FcInit) IA__FcInit __attribute((visibility("hidden"))); +#define FcInit IA__FcInit +extern __typeof (FcFini) IA__FcFini __attribute((visibility("hidden"))); +#define FcFini IA__FcFini +extern __typeof (FcGetVersion) IA__FcGetVersion __attribute((visibility("hidden"))); +#define FcGetVersion IA__FcGetVersion +extern __typeof (FcInitReinitialize) IA__FcInitReinitialize __attribute((visibility("hidden"))); +#define FcInitReinitialize IA__FcInitReinitialize +extern __typeof (FcInitBringUptoDate) IA__FcInitBringUptoDate __attribute((visibility("hidden"))); +#define FcInitBringUptoDate IA__FcInitBringUptoDate +extern __typeof (FcGetLangs) IA__FcGetLangs __attribute((visibility("hidden"))); +#define FcGetLangs IA__FcGetLangs +extern __typeof (FcLangNormalize) IA__FcLangNormalize __attribute((visibility("hidden"))); +#define FcLangNormalize IA__FcLangNormalize +extern __typeof (FcLangGetCharSet) IA__FcLangGetCharSet __attribute((visibility("hidden"))); +#define FcLangGetCharSet IA__FcLangGetCharSet +extern __typeof (FcLangSetCreate) IA__FcLangSetCreate __attribute((visibility("hidden"))); +#define FcLangSetCreate IA__FcLangSetCreate +extern __typeof (FcLangSetDestroy) IA__FcLangSetDestroy __attribute((visibility("hidden"))); +#define FcLangSetDestroy IA__FcLangSetDestroy +extern __typeof (FcLangSetCopy) IA__FcLangSetCopy __attribute((visibility("hidden"))); +#define FcLangSetCopy IA__FcLangSetCopy +extern __typeof (FcLangSetAdd) IA__FcLangSetAdd __attribute((visibility("hidden"))); +#define FcLangSetAdd IA__FcLangSetAdd +extern __typeof (FcLangSetDel) IA__FcLangSetDel __attribute((visibility("hidden"))); +#define FcLangSetDel IA__FcLangSetDel +extern __typeof (FcLangSetHasLang) IA__FcLangSetHasLang __attribute((visibility("hidden"))); +#define FcLangSetHasLang IA__FcLangSetHasLang +extern __typeof (FcLangSetCompare) IA__FcLangSetCompare __attribute((visibility("hidden"))); +#define FcLangSetCompare IA__FcLangSetCompare +extern __typeof (FcLangSetContains) IA__FcLangSetContains __attribute((visibility("hidden"))); +#define FcLangSetContains IA__FcLangSetContains +extern __typeof (FcLangSetEqual) IA__FcLangSetEqual __attribute((visibility("hidden"))); +#define FcLangSetEqual IA__FcLangSetEqual +extern __typeof (FcLangSetHash) IA__FcLangSetHash __attribute((visibility("hidden"))); +#define FcLangSetHash IA__FcLangSetHash +extern __typeof (FcLangSetGetLangs) IA__FcLangSetGetLangs __attribute((visibility("hidden"))); +#define FcLangSetGetLangs IA__FcLangSetGetLangs +extern __typeof (FcLangSetUnion) IA__FcLangSetUnion __attribute((visibility("hidden"))); +#define FcLangSetUnion IA__FcLangSetUnion +extern __typeof (FcLangSetSubtract) IA__FcLangSetSubtract __attribute((visibility("hidden"))); +#define FcLangSetSubtract IA__FcLangSetSubtract +extern __typeof (FcObjectSetCreate) IA__FcObjectSetCreate __attribute((visibility("hidden"))); +#define FcObjectSetCreate IA__FcObjectSetCreate +extern __typeof (FcObjectSetAdd) IA__FcObjectSetAdd __attribute((visibility("hidden"))); +#define FcObjectSetAdd IA__FcObjectSetAdd +extern __typeof (FcObjectSetDestroy) IA__FcObjectSetDestroy __attribute((visibility("hidden"))); +#define FcObjectSetDestroy IA__FcObjectSetDestroy +extern __typeof (FcObjectSetVaBuild) IA__FcObjectSetVaBuild __attribute((visibility("hidden"))); +#define FcObjectSetVaBuild IA__FcObjectSetVaBuild +extern __typeof (FcObjectSetBuild) IA__FcObjectSetBuild __attribute((visibility("hidden"))); +#define FcObjectSetBuild IA__FcObjectSetBuild +extern __typeof (FcFontSetList) IA__FcFontSetList __attribute((visibility("hidden"))); +#define FcFontSetList IA__FcFontSetList +extern __typeof (FcFontList) IA__FcFontList __attribute((visibility("hidden"))); +#define FcFontList IA__FcFontList +extern __typeof (FcAtomicCreate) IA__FcAtomicCreate __attribute((visibility("hidden"))); +#define FcAtomicCreate IA__FcAtomicCreate +extern __typeof (FcAtomicLock) IA__FcAtomicLock __attribute((visibility("hidden"))); +#define FcAtomicLock IA__FcAtomicLock +extern __typeof (FcAtomicNewFile) IA__FcAtomicNewFile __attribute((visibility("hidden"))); +#define FcAtomicNewFile IA__FcAtomicNewFile +extern __typeof (FcAtomicOrigFile) IA__FcAtomicOrigFile __attribute((visibility("hidden"))); +#define FcAtomicOrigFile IA__FcAtomicOrigFile +extern __typeof (FcAtomicReplaceOrig) IA__FcAtomicReplaceOrig __attribute((visibility("hidden"))); +#define FcAtomicReplaceOrig IA__FcAtomicReplaceOrig +extern __typeof (FcAtomicDeleteNew) IA__FcAtomicDeleteNew __attribute((visibility("hidden"))); +#define FcAtomicDeleteNew IA__FcAtomicDeleteNew +extern __typeof (FcAtomicUnlock) IA__FcAtomicUnlock __attribute((visibility("hidden"))); +#define FcAtomicUnlock IA__FcAtomicUnlock +extern __typeof (FcAtomicDestroy) IA__FcAtomicDestroy __attribute((visibility("hidden"))); +#define FcAtomicDestroy IA__FcAtomicDestroy +extern __typeof (FcFontSetMatch) IA__FcFontSetMatch __attribute((visibility("hidden"))); +#define FcFontSetMatch IA__FcFontSetMatch +extern __typeof (FcFontMatch) IA__FcFontMatch __attribute((visibility("hidden"))); +#define FcFontMatch IA__FcFontMatch +extern __typeof (FcFontRenderPrepare) IA__FcFontRenderPrepare __attribute((visibility("hidden"))); +#define FcFontRenderPrepare IA__FcFontRenderPrepare +extern __typeof (FcFontSetSort) IA__FcFontSetSort __attribute((visibility("hidden"))); +#define FcFontSetSort IA__FcFontSetSort +extern __typeof (FcFontSort) IA__FcFontSort __attribute((visibility("hidden"))); +#define FcFontSort IA__FcFontSort +extern __typeof (FcFontSetSortDestroy) IA__FcFontSetSortDestroy __attribute((visibility("hidden"))); +#define FcFontSetSortDestroy IA__FcFontSetSortDestroy +extern __typeof (FcMatrixCopy) IA__FcMatrixCopy __attribute((visibility("hidden"))); +#define FcMatrixCopy IA__FcMatrixCopy +extern __typeof (FcMatrixEqual) IA__FcMatrixEqual __attribute((visibility("hidden"))); +#define FcMatrixEqual IA__FcMatrixEqual +extern __typeof (FcMatrixMultiply) IA__FcMatrixMultiply __attribute((visibility("hidden"))); +#define FcMatrixMultiply IA__FcMatrixMultiply +extern __typeof (FcMatrixRotate) IA__FcMatrixRotate __attribute((visibility("hidden"))); +#define FcMatrixRotate IA__FcMatrixRotate +extern __typeof (FcMatrixScale) IA__FcMatrixScale __attribute((visibility("hidden"))); +#define FcMatrixScale IA__FcMatrixScale +extern __typeof (FcMatrixShear) IA__FcMatrixShear __attribute((visibility("hidden"))); +#define FcMatrixShear IA__FcMatrixShear +extern __typeof (FcNameRegisterObjectTypes) IA__FcNameRegisterObjectTypes __attribute((visibility("hidden"))); +#define FcNameRegisterObjectTypes IA__FcNameRegisterObjectTypes +extern __typeof (FcNameUnregisterObjectTypes) IA__FcNameUnregisterObjectTypes __attribute((visibility("hidden"))); +#define FcNameUnregisterObjectTypes IA__FcNameUnregisterObjectTypes +extern __typeof (FcNameGetObjectType) IA__FcNameGetObjectType __attribute((visibility("hidden"))); +#define FcNameGetObjectType IA__FcNameGetObjectType +extern __typeof (FcNameRegisterConstants) IA__FcNameRegisterConstants __attribute((visibility("hidden"))); +#define FcNameRegisterConstants IA__FcNameRegisterConstants +extern __typeof (FcNameUnregisterConstants) IA__FcNameUnregisterConstants __attribute((visibility("hidden"))); +#define FcNameUnregisterConstants IA__FcNameUnregisterConstants +extern __typeof (FcNameGetConstant) IA__FcNameGetConstant __attribute((visibility("hidden"))); +#define FcNameGetConstant IA__FcNameGetConstant +extern __typeof (FcNameConstant) IA__FcNameConstant __attribute((visibility("hidden"))); +#define FcNameConstant IA__FcNameConstant +extern __typeof (FcNameParse) IA__FcNameParse __attribute((visibility("hidden"))); +#define FcNameParse IA__FcNameParse +extern __typeof (FcNameUnparse) IA__FcNameUnparse __attribute((visibility("hidden"))); +#define FcNameUnparse IA__FcNameUnparse +extern __typeof (FcPatternCreate) IA__FcPatternCreate __attribute((visibility("hidden"))); +#define FcPatternCreate IA__FcPatternCreate +extern __typeof (FcPatternDuplicate) IA__FcPatternDuplicate __attribute((visibility("hidden"))); +#define FcPatternDuplicate IA__FcPatternDuplicate +extern __typeof (FcPatternReference) IA__FcPatternReference __attribute((visibility("hidden"))); +#define FcPatternReference IA__FcPatternReference +extern __typeof (FcPatternFilter) IA__FcPatternFilter __attribute((visibility("hidden"))); +#define FcPatternFilter IA__FcPatternFilter +extern __typeof (FcValueDestroy) IA__FcValueDestroy __attribute((visibility("hidden"))); +#define FcValueDestroy IA__FcValueDestroy +extern __typeof (FcValueEqual) IA__FcValueEqual __attribute((visibility("hidden"))); +#define FcValueEqual IA__FcValueEqual +extern __typeof (FcValueSave) IA__FcValueSave __attribute((visibility("hidden"))); +#define FcValueSave IA__FcValueSave +extern __typeof (FcPatternDestroy) IA__FcPatternDestroy __attribute((visibility("hidden"))); +#define FcPatternDestroy IA__FcPatternDestroy +extern __typeof (FcPatternEqual) IA__FcPatternEqual __attribute((visibility("hidden"))); +#define FcPatternEqual IA__FcPatternEqual +extern __typeof (FcPatternEqualSubset) IA__FcPatternEqualSubset __attribute((visibility("hidden"))); +#define FcPatternEqualSubset IA__FcPatternEqualSubset +extern __typeof (FcPatternHash) IA__FcPatternHash __attribute((visibility("hidden"))); +#define FcPatternHash IA__FcPatternHash +extern __typeof (FcPatternAdd) IA__FcPatternAdd __attribute((visibility("hidden"))); +#define FcPatternAdd IA__FcPatternAdd +extern __typeof (FcPatternAddWeak) IA__FcPatternAddWeak __attribute((visibility("hidden"))); +#define FcPatternAddWeak IA__FcPatternAddWeak +extern __typeof (FcPatternGet) IA__FcPatternGet __attribute((visibility("hidden"))); +#define FcPatternGet IA__FcPatternGet +extern __typeof (FcPatternDel) IA__FcPatternDel __attribute((visibility("hidden"))); +#define FcPatternDel IA__FcPatternDel +extern __typeof (FcPatternRemove) IA__FcPatternRemove __attribute((visibility("hidden"))); +#define FcPatternRemove IA__FcPatternRemove +extern __typeof (FcPatternAddInteger) IA__FcPatternAddInteger __attribute((visibility("hidden"))); +#define FcPatternAddInteger IA__FcPatternAddInteger +extern __typeof (FcPatternAddDouble) IA__FcPatternAddDouble __attribute((visibility("hidden"))); +#define FcPatternAddDouble IA__FcPatternAddDouble +extern __typeof (FcPatternAddString) IA__FcPatternAddString __attribute((visibility("hidden"))); +#define FcPatternAddString IA__FcPatternAddString +extern __typeof (FcPatternAddMatrix) IA__FcPatternAddMatrix __attribute((visibility("hidden"))); +#define FcPatternAddMatrix IA__FcPatternAddMatrix +extern __typeof (FcPatternAddCharSet) IA__FcPatternAddCharSet __attribute((visibility("hidden"))); +#define FcPatternAddCharSet IA__FcPatternAddCharSet +extern __typeof (FcPatternAddBool) IA__FcPatternAddBool __attribute((visibility("hidden"))); +#define FcPatternAddBool IA__FcPatternAddBool +extern __typeof (FcPatternAddLangSet) IA__FcPatternAddLangSet __attribute((visibility("hidden"))); +#define FcPatternAddLangSet IA__FcPatternAddLangSet +extern __typeof (FcPatternAddRange) IA__FcPatternAddRange __attribute((visibility("hidden"))); +#define FcPatternAddRange IA__FcPatternAddRange +extern __typeof (FcPatternGetInteger) IA__FcPatternGetInteger __attribute((visibility("hidden"))); +#define FcPatternGetInteger IA__FcPatternGetInteger +extern __typeof (FcPatternGetDouble) IA__FcPatternGetDouble __attribute((visibility("hidden"))); +#define FcPatternGetDouble IA__FcPatternGetDouble +extern __typeof (FcPatternGetString) IA__FcPatternGetString __attribute((visibility("hidden"))); +#define FcPatternGetString IA__FcPatternGetString +extern __typeof (FcPatternGetMatrix) IA__FcPatternGetMatrix __attribute((visibility("hidden"))); +#define FcPatternGetMatrix IA__FcPatternGetMatrix +extern __typeof (FcPatternGetCharSet) IA__FcPatternGetCharSet __attribute((visibility("hidden"))); +#define FcPatternGetCharSet IA__FcPatternGetCharSet +extern __typeof (FcPatternGetBool) IA__FcPatternGetBool __attribute((visibility("hidden"))); +#define FcPatternGetBool IA__FcPatternGetBool +extern __typeof (FcPatternGetLangSet) IA__FcPatternGetLangSet __attribute((visibility("hidden"))); +#define FcPatternGetLangSet IA__FcPatternGetLangSet +extern __typeof (FcPatternGetRange) IA__FcPatternGetRange __attribute((visibility("hidden"))); +#define FcPatternGetRange IA__FcPatternGetRange +extern __typeof (FcPatternVaBuild) IA__FcPatternVaBuild __attribute((visibility("hidden"))); +#define FcPatternVaBuild IA__FcPatternVaBuild +extern __typeof (FcPatternBuild) IA__FcPatternBuild __attribute((visibility("hidden"))); +#define FcPatternBuild IA__FcPatternBuild +extern __typeof (FcPatternFormat) IA__FcPatternFormat __attribute((visibility("hidden"))); +#define FcPatternFormat IA__FcPatternFormat +extern __typeof (FcRangeCreateDouble) IA__FcRangeCreateDouble __attribute((visibility("hidden"))); +#define FcRangeCreateDouble IA__FcRangeCreateDouble +extern __typeof (FcRangeCreateInteger) IA__FcRangeCreateInteger __attribute((visibility("hidden"))); +#define FcRangeCreateInteger IA__FcRangeCreateInteger +extern __typeof (FcRangeDestroy) IA__FcRangeDestroy __attribute((visibility("hidden"))); +#define FcRangeDestroy IA__FcRangeDestroy +extern __typeof (FcRangeCopy) IA__FcRangeCopy __attribute((visibility("hidden"))); +#define FcRangeCopy IA__FcRangeCopy +extern __typeof (FcRangeGetDouble) IA__FcRangeGetDouble __attribute((visibility("hidden"))); +#define FcRangeGetDouble IA__FcRangeGetDouble +extern __typeof (FcWeightFromOpenType) IA__FcWeightFromOpenType __attribute((visibility("hidden"))); +#define FcWeightFromOpenType IA__FcWeightFromOpenType +extern __typeof (FcWeightToOpenType) IA__FcWeightToOpenType __attribute((visibility("hidden"))); +#define FcWeightToOpenType IA__FcWeightToOpenType +extern __typeof (FcStrCopy) IA__FcStrCopy __attribute((visibility("hidden"))); +#define FcStrCopy IA__FcStrCopy +extern __typeof (FcStrCopyFilename) IA__FcStrCopyFilename __attribute((visibility("hidden"))); +#define FcStrCopyFilename IA__FcStrCopyFilename +extern __typeof (FcStrPlus) IA__FcStrPlus __attribute((visibility("hidden"))); +#define FcStrPlus IA__FcStrPlus +extern __typeof (FcStrFree) IA__FcStrFree __attribute((visibility("hidden"))); +#define FcStrFree IA__FcStrFree +extern __typeof (FcStrDowncase) IA__FcStrDowncase __attribute((visibility("hidden"))); +#define FcStrDowncase IA__FcStrDowncase +extern __typeof (FcStrCmpIgnoreCase) IA__FcStrCmpIgnoreCase __attribute((visibility("hidden"))); +#define FcStrCmpIgnoreCase IA__FcStrCmpIgnoreCase +extern __typeof (FcStrCmp) IA__FcStrCmp __attribute((visibility("hidden"))); +#define FcStrCmp IA__FcStrCmp +extern __typeof (FcStrStrIgnoreCase) IA__FcStrStrIgnoreCase __attribute((visibility("hidden"))); +#define FcStrStrIgnoreCase IA__FcStrStrIgnoreCase +extern __typeof (FcStrStr) IA__FcStrStr __attribute((visibility("hidden"))); +#define FcStrStr IA__FcStrStr +extern __typeof (FcUtf8ToUcs4) IA__FcUtf8ToUcs4 __attribute((visibility("hidden"))); +#define FcUtf8ToUcs4 IA__FcUtf8ToUcs4 +extern __typeof (FcUtf8Len) IA__FcUtf8Len __attribute((visibility("hidden"))); +#define FcUtf8Len IA__FcUtf8Len +extern __typeof (FcUcs4ToUtf8) IA__FcUcs4ToUtf8 __attribute((visibility("hidden"))); +#define FcUcs4ToUtf8 IA__FcUcs4ToUtf8 +extern __typeof (FcUtf16ToUcs4) IA__FcUtf16ToUcs4 __attribute((visibility("hidden"))); +#define FcUtf16ToUcs4 IA__FcUtf16ToUcs4 +extern __typeof (FcUtf16Len) IA__FcUtf16Len __attribute((visibility("hidden"))); +#define FcUtf16Len IA__FcUtf16Len +extern __typeof (FcStrDirname) IA__FcStrDirname __attribute((visibility("hidden"))); +#define FcStrDirname IA__FcStrDirname +extern __typeof (FcStrBasename) IA__FcStrBasename __attribute((visibility("hidden"))); +#define FcStrBasename IA__FcStrBasename +extern __typeof (FcStrSetCreate) IA__FcStrSetCreate __attribute((visibility("hidden"))); +#define FcStrSetCreate IA__FcStrSetCreate +extern __typeof (FcStrSetMember) IA__FcStrSetMember __attribute((visibility("hidden"))); +#define FcStrSetMember IA__FcStrSetMember +extern __typeof (FcStrSetEqual) IA__FcStrSetEqual __attribute((visibility("hidden"))); +#define FcStrSetEqual IA__FcStrSetEqual +extern __typeof (FcStrSetAdd) IA__FcStrSetAdd __attribute((visibility("hidden"))); +#define FcStrSetAdd IA__FcStrSetAdd +extern __typeof (FcStrSetAddFilename) IA__FcStrSetAddFilename __attribute((visibility("hidden"))); +#define FcStrSetAddFilename IA__FcStrSetAddFilename +extern __typeof (FcStrSetDel) IA__FcStrSetDel __attribute((visibility("hidden"))); +#define FcStrSetDel IA__FcStrSetDel +extern __typeof (FcStrSetDestroy) IA__FcStrSetDestroy __attribute((visibility("hidden"))); +#define FcStrSetDestroy IA__FcStrSetDestroy +extern __typeof (FcStrListCreate) IA__FcStrListCreate __attribute((visibility("hidden"))); +#define FcStrListCreate IA__FcStrListCreate +extern __typeof (FcStrListFirst) IA__FcStrListFirst __attribute((visibility("hidden"))); +#define FcStrListFirst IA__FcStrListFirst +extern __typeof (FcStrListNext) IA__FcStrListNext __attribute((visibility("hidden"))); +#define FcStrListNext IA__FcStrListNext +extern __typeof (FcStrListDone) IA__FcStrListDone __attribute((visibility("hidden"))); +#define FcStrListDone IA__FcStrListDone +extern __typeof (FcConfigParseAndLoad) IA__FcConfigParseAndLoad __attribute((visibility("hidden"))); +#define FcConfigParseAndLoad IA__FcConfigParseAndLoad +extern __typeof (FcConfigGetRescanInverval) IA__FcConfigGetRescanInverval __attribute((visibility("hidden"))); +#define FcConfigGetRescanInverval IA__FcConfigGetRescanInverval +extern __typeof (FcConfigSetRescanInverval) IA__FcConfigSetRescanInverval __attribute((visibility("hidden"))); +#define FcConfigSetRescanInverval IA__FcConfigSetRescanInverval diff --git a/static/custom-include/fontconfig/fcaliastail.h b/static/custom-include/fontconfig/fcaliastail.h new file mode 100644 index 000000000..13e5f50b8 --- /dev/null +++ b/static/custom-include/fontconfig/fcaliastail.h @@ -0,0 +1,464 @@ +#if HAVE_GNUC_ATTRIBUTE +#ifdef __fcblanks__ +# undef FcBlanksCreate +extern __typeof (FcBlanksCreate) FcBlanksCreate __attribute((alias("IA__FcBlanksCreate"), visibility("default"))); +# undef FcBlanksDestroy +extern __typeof (FcBlanksDestroy) FcBlanksDestroy __attribute((alias("IA__FcBlanksDestroy"), visibility("default"))); +# undef FcBlanksAdd +extern __typeof (FcBlanksAdd) FcBlanksAdd __attribute((alias("IA__FcBlanksAdd"), visibility("default"))); +# undef FcBlanksIsMember +extern __typeof (FcBlanksIsMember) FcBlanksIsMember __attribute((alias("IA__FcBlanksIsMember"), visibility("default"))); +#endif /* __fcblanks__ */ +#ifdef __fccache__ +# undef FcCacheCopySet +extern __typeof (FcCacheCopySet) FcCacheCopySet __attribute((alias("IA__FcCacheCopySet"), visibility("default"))); +# undef FcCacheNumSubdir +extern __typeof (FcCacheNumSubdir) FcCacheNumSubdir __attribute((alias("IA__FcCacheNumSubdir"), visibility("default"))); +# undef FcCacheNumFont +extern __typeof (FcCacheNumFont) FcCacheNumFont __attribute((alias("IA__FcCacheNumFont"), visibility("default"))); +# undef FcDirCacheUnlink +extern __typeof (FcDirCacheUnlink) FcDirCacheUnlink __attribute((alias("IA__FcDirCacheUnlink"), visibility("default"))); +# undef FcDirCacheValid +extern __typeof (FcDirCacheValid) FcDirCacheValid __attribute((alias("IA__FcDirCacheValid"), visibility("default"))); +# undef FcDirCacheClean +extern __typeof (FcDirCacheClean) FcDirCacheClean __attribute((alias("IA__FcDirCacheClean"), visibility("default"))); +# undef FcCacheCreateTagFile +extern __typeof (FcCacheCreateTagFile) FcCacheCreateTagFile __attribute((alias("IA__FcCacheCreateTagFile"), visibility("default"))); +#endif /* __fccache__ */ +#ifdef __fccfg__ +# undef FcConfigHome +extern __typeof (FcConfigHome) FcConfigHome __attribute((alias("IA__FcConfigHome"), visibility("default"))); +# undef FcConfigEnableHome +extern __typeof (FcConfigEnableHome) FcConfigEnableHome __attribute((alias("IA__FcConfigEnableHome"), visibility("default"))); +# undef FcConfigFilename +extern __typeof (FcConfigFilename) FcConfigFilename __attribute((alias("IA__FcConfigFilename"), visibility("default"))); +# undef FcConfigCreate +extern __typeof (FcConfigCreate) FcConfigCreate __attribute((alias("IA__FcConfigCreate"), visibility("default"))); +# undef FcConfigReference +extern __typeof (FcConfigReference) FcConfigReference __attribute((alias("IA__FcConfigReference"), visibility("default"))); +# undef FcConfigDestroy +extern __typeof (FcConfigDestroy) FcConfigDestroy __attribute((alias("IA__FcConfigDestroy"), visibility("default"))); +# undef FcConfigSetCurrent +extern __typeof (FcConfigSetCurrent) FcConfigSetCurrent __attribute((alias("IA__FcConfigSetCurrent"), visibility("default"))); +# undef FcConfigGetCurrent +extern __typeof (FcConfigGetCurrent) FcConfigGetCurrent __attribute((alias("IA__FcConfigGetCurrent"), visibility("default"))); +# undef FcConfigUptoDate +extern __typeof (FcConfigUptoDate) FcConfigUptoDate __attribute((alias("IA__FcConfigUptoDate"), visibility("default"))); +# undef FcConfigBuildFonts +extern __typeof (FcConfigBuildFonts) FcConfigBuildFonts __attribute((alias("IA__FcConfigBuildFonts"), visibility("default"))); +# undef FcConfigGetFontDirs +extern __typeof (FcConfigGetFontDirs) FcConfigGetFontDirs __attribute((alias("IA__FcConfigGetFontDirs"), visibility("default"))); +# undef FcConfigGetConfigDirs +extern __typeof (FcConfigGetConfigDirs) FcConfigGetConfigDirs __attribute((alias("IA__FcConfigGetConfigDirs"), visibility("default"))); +# undef FcConfigGetConfigFiles +extern __typeof (FcConfigGetConfigFiles) FcConfigGetConfigFiles __attribute((alias("IA__FcConfigGetConfigFiles"), visibility("default"))); +# undef FcConfigGetCache +extern __typeof (FcConfigGetCache) FcConfigGetCache __attribute((alias("IA__FcConfigGetCache"), visibility("default"))); +# undef FcConfigGetBlanks +extern __typeof (FcConfigGetBlanks) FcConfigGetBlanks __attribute((alias("IA__FcConfigGetBlanks"), visibility("default"))); +# undef FcConfigGetCacheDirs +extern __typeof (FcConfigGetCacheDirs) FcConfigGetCacheDirs __attribute((alias("IA__FcConfigGetCacheDirs"), visibility("default"))); +# undef FcConfigGetRescanInterval +extern __typeof (FcConfigGetRescanInterval) FcConfigGetRescanInterval __attribute((alias("IA__FcConfigGetRescanInterval"), visibility("default"))); +# undef FcConfigSetRescanInterval +extern __typeof (FcConfigSetRescanInterval) FcConfigSetRescanInterval __attribute((alias("IA__FcConfigSetRescanInterval"), visibility("default"))); +# undef FcConfigGetFonts +extern __typeof (FcConfigGetFonts) FcConfigGetFonts __attribute((alias("IA__FcConfigGetFonts"), visibility("default"))); +# undef FcConfigAppFontAddFile +extern __typeof (FcConfigAppFontAddFile) FcConfigAppFontAddFile __attribute((alias("IA__FcConfigAppFontAddFile"), visibility("default"))); +# undef FcConfigAppFontAddDir +extern __typeof (FcConfigAppFontAddDir) FcConfigAppFontAddDir __attribute((alias("IA__FcConfigAppFontAddDir"), visibility("default"))); +# undef FcConfigAppFontClear +extern __typeof (FcConfigAppFontClear) FcConfigAppFontClear __attribute((alias("IA__FcConfigAppFontClear"), visibility("default"))); +# undef FcConfigSubstituteWithPat +extern __typeof (FcConfigSubstituteWithPat) FcConfigSubstituteWithPat __attribute((alias("IA__FcConfigSubstituteWithPat"), visibility("default"))); +# undef FcConfigSubstitute +extern __typeof (FcConfigSubstitute) FcConfigSubstitute __attribute((alias("IA__FcConfigSubstitute"), visibility("default"))); +# undef FcConfigGetSysRoot +extern __typeof (FcConfigGetSysRoot) FcConfigGetSysRoot __attribute((alias("IA__FcConfigGetSysRoot"), visibility("default"))); +# undef FcConfigSetSysRoot +extern __typeof (FcConfigSetSysRoot) FcConfigSetSysRoot __attribute((alias("IA__FcConfigSetSysRoot"), visibility("default"))); +#endif /* __fccfg__ */ +#ifdef __fccharset__ +# undef FcCharSetCreate +extern __typeof (FcCharSetCreate) FcCharSetCreate __attribute((alias("IA__FcCharSetCreate"), visibility("default"))); +# undef FcCharSetNew +extern __typeof (FcCharSetNew) FcCharSetNew __attribute((alias("IA__FcCharSetNew"), visibility("default"))); +# undef FcCharSetDestroy +extern __typeof (FcCharSetDestroy) FcCharSetDestroy __attribute((alias("IA__FcCharSetDestroy"), visibility("default"))); +# undef FcCharSetAddChar +extern __typeof (FcCharSetAddChar) FcCharSetAddChar __attribute((alias("IA__FcCharSetAddChar"), visibility("default"))); +# undef FcCharSetDelChar +extern __typeof (FcCharSetDelChar) FcCharSetDelChar __attribute((alias("IA__FcCharSetDelChar"), visibility("default"))); +# undef FcCharSetCopy +extern __typeof (FcCharSetCopy) FcCharSetCopy __attribute((alias("IA__FcCharSetCopy"), visibility("default"))); +# undef FcCharSetEqual +extern __typeof (FcCharSetEqual) FcCharSetEqual __attribute((alias("IA__FcCharSetEqual"), visibility("default"))); +# undef FcCharSetIntersect +extern __typeof (FcCharSetIntersect) FcCharSetIntersect __attribute((alias("IA__FcCharSetIntersect"), visibility("default"))); +# undef FcCharSetUnion +extern __typeof (FcCharSetUnion) FcCharSetUnion __attribute((alias("IA__FcCharSetUnion"), visibility("default"))); +# undef FcCharSetSubtract +extern __typeof (FcCharSetSubtract) FcCharSetSubtract __attribute((alias("IA__FcCharSetSubtract"), visibility("default"))); +# undef FcCharSetMerge +extern __typeof (FcCharSetMerge) FcCharSetMerge __attribute((alias("IA__FcCharSetMerge"), visibility("default"))); +# undef FcCharSetHasChar +extern __typeof (FcCharSetHasChar) FcCharSetHasChar __attribute((alias("IA__FcCharSetHasChar"), visibility("default"))); +# undef FcCharSetCount +extern __typeof (FcCharSetCount) FcCharSetCount __attribute((alias("IA__FcCharSetCount"), visibility("default"))); +# undef FcCharSetIntersectCount +extern __typeof (FcCharSetIntersectCount) FcCharSetIntersectCount __attribute((alias("IA__FcCharSetIntersectCount"), visibility("default"))); +# undef FcCharSetSubtractCount +extern __typeof (FcCharSetSubtractCount) FcCharSetSubtractCount __attribute((alias("IA__FcCharSetSubtractCount"), visibility("default"))); +# undef FcCharSetIsSubset +extern __typeof (FcCharSetIsSubset) FcCharSetIsSubset __attribute((alias("IA__FcCharSetIsSubset"), visibility("default"))); +# undef FcCharSetFirstPage +extern __typeof (FcCharSetFirstPage) FcCharSetFirstPage __attribute((alias("IA__FcCharSetFirstPage"), visibility("default"))); +# undef FcCharSetNextPage +extern __typeof (FcCharSetNextPage) FcCharSetNextPage __attribute((alias("IA__FcCharSetNextPage"), visibility("default"))); +# undef FcCharSetCoverage +extern __typeof (FcCharSetCoverage) FcCharSetCoverage __attribute((alias("IA__FcCharSetCoverage"), visibility("default"))); +#endif /* __fccharset__ */ +#ifdef __fcdbg__ +# undef FcValuePrint +extern __typeof (FcValuePrint) FcValuePrint __attribute((alias("IA__FcValuePrint"), visibility("default"))); +# undef FcPatternPrint +extern __typeof (FcPatternPrint) FcPatternPrint __attribute((alias("IA__FcPatternPrint"), visibility("default"))); +# undef FcFontSetPrint +extern __typeof (FcFontSetPrint) FcFontSetPrint __attribute((alias("IA__FcFontSetPrint"), visibility("default"))); +#endif /* __fcdbg__ */ +#ifdef __fcdefault__ +# undef FcGetDefaultLangs +extern __typeof (FcGetDefaultLangs) FcGetDefaultLangs __attribute((alias("IA__FcGetDefaultLangs"), visibility("default"))); +# undef FcDefaultSubstitute +extern __typeof (FcDefaultSubstitute) FcDefaultSubstitute __attribute((alias("IA__FcDefaultSubstitute"), visibility("default"))); +#endif /* __fcdefault__ */ +#ifdef __fcdir__ +# undef FcFileIsDir +extern __typeof (FcFileIsDir) FcFileIsDir __attribute((alias("IA__FcFileIsDir"), visibility("default"))); +# undef FcFileScan +extern __typeof (FcFileScan) FcFileScan __attribute((alias("IA__FcFileScan"), visibility("default"))); +# undef FcDirScan +extern __typeof (FcDirScan) FcDirScan __attribute((alias("IA__FcDirScan"), visibility("default"))); +# undef FcDirSave +extern __typeof (FcDirSave) FcDirSave __attribute((alias("IA__FcDirSave"), visibility("default"))); +#endif /* __fcdir__ */ +#ifdef __fccache__ +# undef FcDirCacheLoad +extern __typeof (FcDirCacheLoad) FcDirCacheLoad __attribute((alias("IA__FcDirCacheLoad"), visibility("default"))); +#endif /* __fccache__ */ +#ifdef __fcdir__ +# undef FcDirCacheRescan +extern __typeof (FcDirCacheRescan) FcDirCacheRescan __attribute((alias("IA__FcDirCacheRescan"), visibility("default"))); +# undef FcDirCacheRead +extern __typeof (FcDirCacheRead) FcDirCacheRead __attribute((alias("IA__FcDirCacheRead"), visibility("default"))); +#endif /* __fcdir__ */ +#ifdef __fccache__ +# undef FcDirCacheLoadFile +extern __typeof (FcDirCacheLoadFile) FcDirCacheLoadFile __attribute((alias("IA__FcDirCacheLoadFile"), visibility("default"))); +# undef FcDirCacheUnload +extern __typeof (FcDirCacheUnload) FcDirCacheUnload __attribute((alias("IA__FcDirCacheUnload"), visibility("default"))); +#endif /* __fccache__ */ +#ifdef __fcfreetype__ +# undef FcFreeTypeQuery +extern __typeof (FcFreeTypeQuery) FcFreeTypeQuery __attribute((alias("IA__FcFreeTypeQuery"), visibility("default"))); +#endif /* __fcfreetype__ */ +#ifdef __fcfs__ +# undef FcFontSetCreate +extern __typeof (FcFontSetCreate) FcFontSetCreate __attribute((alias("IA__FcFontSetCreate"), visibility("default"))); +# undef FcFontSetDestroy +extern __typeof (FcFontSetDestroy) FcFontSetDestroy __attribute((alias("IA__FcFontSetDestroy"), visibility("default"))); +# undef FcFontSetAdd +extern __typeof (FcFontSetAdd) FcFontSetAdd __attribute((alias("IA__FcFontSetAdd"), visibility("default"))); +#endif /* __fcfs__ */ +#ifdef __fcinit__ +# undef FcInitLoadConfig +extern __typeof (FcInitLoadConfig) FcInitLoadConfig __attribute((alias("IA__FcInitLoadConfig"), visibility("default"))); +# undef FcInitLoadConfigAndFonts +extern __typeof (FcInitLoadConfigAndFonts) FcInitLoadConfigAndFonts __attribute((alias("IA__FcInitLoadConfigAndFonts"), visibility("default"))); +# undef FcInit +extern __typeof (FcInit) FcInit __attribute((alias("IA__FcInit"), visibility("default"))); +# undef FcFini +extern __typeof (FcFini) FcFini __attribute((alias("IA__FcFini"), visibility("default"))); +# undef FcGetVersion +extern __typeof (FcGetVersion) FcGetVersion __attribute((alias("IA__FcGetVersion"), visibility("default"))); +# undef FcInitReinitialize +extern __typeof (FcInitReinitialize) FcInitReinitialize __attribute((alias("IA__FcInitReinitialize"), visibility("default"))); +# undef FcInitBringUptoDate +extern __typeof (FcInitBringUptoDate) FcInitBringUptoDate __attribute((alias("IA__FcInitBringUptoDate"), visibility("default"))); +#endif /* __fcinit__ */ +#ifdef __fclang__ +# undef FcGetLangs +extern __typeof (FcGetLangs) FcGetLangs __attribute((alias("IA__FcGetLangs"), visibility("default"))); +# undef FcLangNormalize +extern __typeof (FcLangNormalize) FcLangNormalize __attribute((alias("IA__FcLangNormalize"), visibility("default"))); +# undef FcLangGetCharSet +extern __typeof (FcLangGetCharSet) FcLangGetCharSet __attribute((alias("IA__FcLangGetCharSet"), visibility("default"))); +# undef FcLangSetCreate +extern __typeof (FcLangSetCreate) FcLangSetCreate __attribute((alias("IA__FcLangSetCreate"), visibility("default"))); +# undef FcLangSetDestroy +extern __typeof (FcLangSetDestroy) FcLangSetDestroy __attribute((alias("IA__FcLangSetDestroy"), visibility("default"))); +# undef FcLangSetCopy +extern __typeof (FcLangSetCopy) FcLangSetCopy __attribute((alias("IA__FcLangSetCopy"), visibility("default"))); +# undef FcLangSetAdd +extern __typeof (FcLangSetAdd) FcLangSetAdd __attribute((alias("IA__FcLangSetAdd"), visibility("default"))); +# undef FcLangSetDel +extern __typeof (FcLangSetDel) FcLangSetDel __attribute((alias("IA__FcLangSetDel"), visibility("default"))); +# undef FcLangSetHasLang +extern __typeof (FcLangSetHasLang) FcLangSetHasLang __attribute((alias("IA__FcLangSetHasLang"), visibility("default"))); +# undef FcLangSetCompare +extern __typeof (FcLangSetCompare) FcLangSetCompare __attribute((alias("IA__FcLangSetCompare"), visibility("default"))); +# undef FcLangSetContains +extern __typeof (FcLangSetContains) FcLangSetContains __attribute((alias("IA__FcLangSetContains"), visibility("default"))); +# undef FcLangSetEqual +extern __typeof (FcLangSetEqual) FcLangSetEqual __attribute((alias("IA__FcLangSetEqual"), visibility("default"))); +# undef FcLangSetHash +extern __typeof (FcLangSetHash) FcLangSetHash __attribute((alias("IA__FcLangSetHash"), visibility("default"))); +# undef FcLangSetGetLangs +extern __typeof (FcLangSetGetLangs) FcLangSetGetLangs __attribute((alias("IA__FcLangSetGetLangs"), visibility("default"))); +# undef FcLangSetUnion +extern __typeof (FcLangSetUnion) FcLangSetUnion __attribute((alias("IA__FcLangSetUnion"), visibility("default"))); +# undef FcLangSetSubtract +extern __typeof (FcLangSetSubtract) FcLangSetSubtract __attribute((alias("IA__FcLangSetSubtract"), visibility("default"))); +#endif /* __fclang__ */ +#ifdef __fclist__ +# undef FcObjectSetCreate +extern __typeof (FcObjectSetCreate) FcObjectSetCreate __attribute((alias("IA__FcObjectSetCreate"), visibility("default"))); +# undef FcObjectSetAdd +extern __typeof (FcObjectSetAdd) FcObjectSetAdd __attribute((alias("IA__FcObjectSetAdd"), visibility("default"))); +# undef FcObjectSetDestroy +extern __typeof (FcObjectSetDestroy) FcObjectSetDestroy __attribute((alias("IA__FcObjectSetDestroy"), visibility("default"))); +# undef FcObjectSetVaBuild +extern __typeof (FcObjectSetVaBuild) FcObjectSetVaBuild __attribute((alias("IA__FcObjectSetVaBuild"), visibility("default"))); +# undef FcObjectSetBuild +extern __typeof (FcObjectSetBuild) FcObjectSetBuild __attribute((alias("IA__FcObjectSetBuild"), visibility("default"))); +# undef FcFontSetList +extern __typeof (FcFontSetList) FcFontSetList __attribute((alias("IA__FcFontSetList"), visibility("default"))); +# undef FcFontList +extern __typeof (FcFontList) FcFontList __attribute((alias("IA__FcFontList"), visibility("default"))); +#endif /* __fclist__ */ +#ifdef __fcatomic__ +# undef FcAtomicCreate +extern __typeof (FcAtomicCreate) FcAtomicCreate __attribute((alias("IA__FcAtomicCreate"), visibility("default"))); +# undef FcAtomicLock +extern __typeof (FcAtomicLock) FcAtomicLock __attribute((alias("IA__FcAtomicLock"), visibility("default"))); +# undef FcAtomicNewFile +extern __typeof (FcAtomicNewFile) FcAtomicNewFile __attribute((alias("IA__FcAtomicNewFile"), visibility("default"))); +# undef FcAtomicOrigFile +extern __typeof (FcAtomicOrigFile) FcAtomicOrigFile __attribute((alias("IA__FcAtomicOrigFile"), visibility("default"))); +# undef FcAtomicReplaceOrig +extern __typeof (FcAtomicReplaceOrig) FcAtomicReplaceOrig __attribute((alias("IA__FcAtomicReplaceOrig"), visibility("default"))); +# undef FcAtomicDeleteNew +extern __typeof (FcAtomicDeleteNew) FcAtomicDeleteNew __attribute((alias("IA__FcAtomicDeleteNew"), visibility("default"))); +# undef FcAtomicUnlock +extern __typeof (FcAtomicUnlock) FcAtomicUnlock __attribute((alias("IA__FcAtomicUnlock"), visibility("default"))); +# undef FcAtomicDestroy +extern __typeof (FcAtomicDestroy) FcAtomicDestroy __attribute((alias("IA__FcAtomicDestroy"), visibility("default"))); +#endif /* __fcatomic__ */ +#ifdef __fcmatch__ +# undef FcFontSetMatch +extern __typeof (FcFontSetMatch) FcFontSetMatch __attribute((alias("IA__FcFontSetMatch"), visibility("default"))); +# undef FcFontMatch +extern __typeof (FcFontMatch) FcFontMatch __attribute((alias("IA__FcFontMatch"), visibility("default"))); +# undef FcFontRenderPrepare +extern __typeof (FcFontRenderPrepare) FcFontRenderPrepare __attribute((alias("IA__FcFontRenderPrepare"), visibility("default"))); +# undef FcFontSetSort +extern __typeof (FcFontSetSort) FcFontSetSort __attribute((alias("IA__FcFontSetSort"), visibility("default"))); +# undef FcFontSort +extern __typeof (FcFontSort) FcFontSort __attribute((alias("IA__FcFontSort"), visibility("default"))); +# undef FcFontSetSortDestroy +extern __typeof (FcFontSetSortDestroy) FcFontSetSortDestroy __attribute((alias("IA__FcFontSetSortDestroy"), visibility("default"))); +#endif /* __fcmatch__ */ +#ifdef __fcmatrix__ +# undef FcMatrixCopy +extern __typeof (FcMatrixCopy) FcMatrixCopy __attribute((alias("IA__FcMatrixCopy"), visibility("default"))); +# undef FcMatrixEqual +extern __typeof (FcMatrixEqual) FcMatrixEqual __attribute((alias("IA__FcMatrixEqual"), visibility("default"))); +# undef FcMatrixMultiply +extern __typeof (FcMatrixMultiply) FcMatrixMultiply __attribute((alias("IA__FcMatrixMultiply"), visibility("default"))); +# undef FcMatrixRotate +extern __typeof (FcMatrixRotate) FcMatrixRotate __attribute((alias("IA__FcMatrixRotate"), visibility("default"))); +# undef FcMatrixScale +extern __typeof (FcMatrixScale) FcMatrixScale __attribute((alias("IA__FcMatrixScale"), visibility("default"))); +# undef FcMatrixShear +extern __typeof (FcMatrixShear) FcMatrixShear __attribute((alias("IA__FcMatrixShear"), visibility("default"))); +#endif /* __fcmatrix__ */ +#ifdef __fcname__ +# undef FcNameRegisterObjectTypes +extern __typeof (FcNameRegisterObjectTypes) FcNameRegisterObjectTypes __attribute((alias("IA__FcNameRegisterObjectTypes"), visibility("default"))); +# undef FcNameUnregisterObjectTypes +extern __typeof (FcNameUnregisterObjectTypes) FcNameUnregisterObjectTypes __attribute((alias("IA__FcNameUnregisterObjectTypes"), visibility("default"))); +# undef FcNameGetObjectType +extern __typeof (FcNameGetObjectType) FcNameGetObjectType __attribute((alias("IA__FcNameGetObjectType"), visibility("default"))); +# undef FcNameRegisterConstants +extern __typeof (FcNameRegisterConstants) FcNameRegisterConstants __attribute((alias("IA__FcNameRegisterConstants"), visibility("default"))); +# undef FcNameUnregisterConstants +extern __typeof (FcNameUnregisterConstants) FcNameUnregisterConstants __attribute((alias("IA__FcNameUnregisterConstants"), visibility("default"))); +# undef FcNameGetConstant +extern __typeof (FcNameGetConstant) FcNameGetConstant __attribute((alias("IA__FcNameGetConstant"), visibility("default"))); +# undef FcNameConstant +extern __typeof (FcNameConstant) FcNameConstant __attribute((alias("IA__FcNameConstant"), visibility("default"))); +# undef FcNameParse +extern __typeof (FcNameParse) FcNameParse __attribute((alias("IA__FcNameParse"), visibility("default"))); +# undef FcNameUnparse +extern __typeof (FcNameUnparse) FcNameUnparse __attribute((alias("IA__FcNameUnparse"), visibility("default"))); +#endif /* __fcname__ */ +#ifdef __fcpat__ +# undef FcPatternCreate +extern __typeof (FcPatternCreate) FcPatternCreate __attribute((alias("IA__FcPatternCreate"), visibility("default"))); +# undef FcPatternDuplicate +extern __typeof (FcPatternDuplicate) FcPatternDuplicate __attribute((alias("IA__FcPatternDuplicate"), visibility("default"))); +# undef FcPatternReference +extern __typeof (FcPatternReference) FcPatternReference __attribute((alias("IA__FcPatternReference"), visibility("default"))); +# undef FcPatternFilter +extern __typeof (FcPatternFilter) FcPatternFilter __attribute((alias("IA__FcPatternFilter"), visibility("default"))); +# undef FcValueDestroy +extern __typeof (FcValueDestroy) FcValueDestroy __attribute((alias("IA__FcValueDestroy"), visibility("default"))); +# undef FcValueEqual +extern __typeof (FcValueEqual) FcValueEqual __attribute((alias("IA__FcValueEqual"), visibility("default"))); +# undef FcValueSave +extern __typeof (FcValueSave) FcValueSave __attribute((alias("IA__FcValueSave"), visibility("default"))); +# undef FcPatternDestroy +extern __typeof (FcPatternDestroy) FcPatternDestroy __attribute((alias("IA__FcPatternDestroy"), visibility("default"))); +# undef FcPatternEqual +extern __typeof (FcPatternEqual) FcPatternEqual __attribute((alias("IA__FcPatternEqual"), visibility("default"))); +# undef FcPatternEqualSubset +extern __typeof (FcPatternEqualSubset) FcPatternEqualSubset __attribute((alias("IA__FcPatternEqualSubset"), visibility("default"))); +# undef FcPatternHash +extern __typeof (FcPatternHash) FcPatternHash __attribute((alias("IA__FcPatternHash"), visibility("default"))); +# undef FcPatternAdd +extern __typeof (FcPatternAdd) FcPatternAdd __attribute((alias("IA__FcPatternAdd"), visibility("default"))); +# undef FcPatternAddWeak +extern __typeof (FcPatternAddWeak) FcPatternAddWeak __attribute((alias("IA__FcPatternAddWeak"), visibility("default"))); +# undef FcPatternGet +extern __typeof (FcPatternGet) FcPatternGet __attribute((alias("IA__FcPatternGet"), visibility("default"))); +# undef FcPatternDel +extern __typeof (FcPatternDel) FcPatternDel __attribute((alias("IA__FcPatternDel"), visibility("default"))); +# undef FcPatternRemove +extern __typeof (FcPatternRemove) FcPatternRemove __attribute((alias("IA__FcPatternRemove"), visibility("default"))); +# undef FcPatternAddInteger +extern __typeof (FcPatternAddInteger) FcPatternAddInteger __attribute((alias("IA__FcPatternAddInteger"), visibility("default"))); +# undef FcPatternAddDouble +extern __typeof (FcPatternAddDouble) FcPatternAddDouble __attribute((alias("IA__FcPatternAddDouble"), visibility("default"))); +# undef FcPatternAddString +extern __typeof (FcPatternAddString) FcPatternAddString __attribute((alias("IA__FcPatternAddString"), visibility("default"))); +# undef FcPatternAddMatrix +extern __typeof (FcPatternAddMatrix) FcPatternAddMatrix __attribute((alias("IA__FcPatternAddMatrix"), visibility("default"))); +# undef FcPatternAddCharSet +extern __typeof (FcPatternAddCharSet) FcPatternAddCharSet __attribute((alias("IA__FcPatternAddCharSet"), visibility("default"))); +# undef FcPatternAddBool +extern __typeof (FcPatternAddBool) FcPatternAddBool __attribute((alias("IA__FcPatternAddBool"), visibility("default"))); +# undef FcPatternAddLangSet +extern __typeof (FcPatternAddLangSet) FcPatternAddLangSet __attribute((alias("IA__FcPatternAddLangSet"), visibility("default"))); +# undef FcPatternAddRange +extern __typeof (FcPatternAddRange) FcPatternAddRange __attribute((alias("IA__FcPatternAddRange"), visibility("default"))); +# undef FcPatternGetInteger +extern __typeof (FcPatternGetInteger) FcPatternGetInteger __attribute((alias("IA__FcPatternGetInteger"), visibility("default"))); +# undef FcPatternGetDouble +extern __typeof (FcPatternGetDouble) FcPatternGetDouble __attribute((alias("IA__FcPatternGetDouble"), visibility("default"))); +# undef FcPatternGetString +extern __typeof (FcPatternGetString) FcPatternGetString __attribute((alias("IA__FcPatternGetString"), visibility("default"))); +# undef FcPatternGetMatrix +extern __typeof (FcPatternGetMatrix) FcPatternGetMatrix __attribute((alias("IA__FcPatternGetMatrix"), visibility("default"))); +# undef FcPatternGetCharSet +extern __typeof (FcPatternGetCharSet) FcPatternGetCharSet __attribute((alias("IA__FcPatternGetCharSet"), visibility("default"))); +# undef FcPatternGetBool +extern __typeof (FcPatternGetBool) FcPatternGetBool __attribute((alias("IA__FcPatternGetBool"), visibility("default"))); +# undef FcPatternGetLangSet +extern __typeof (FcPatternGetLangSet) FcPatternGetLangSet __attribute((alias("IA__FcPatternGetLangSet"), visibility("default"))); +# undef FcPatternGetRange +extern __typeof (FcPatternGetRange) FcPatternGetRange __attribute((alias("IA__FcPatternGetRange"), visibility("default"))); +# undef FcPatternVaBuild +extern __typeof (FcPatternVaBuild) FcPatternVaBuild __attribute((alias("IA__FcPatternVaBuild"), visibility("default"))); +# undef FcPatternBuild +extern __typeof (FcPatternBuild) FcPatternBuild __attribute((alias("IA__FcPatternBuild"), visibility("default"))); +#endif /* __fcpat__ */ +#ifdef __fcformat__ +# undef FcPatternFormat +extern __typeof (FcPatternFormat) FcPatternFormat __attribute((alias("IA__FcPatternFormat"), visibility("default"))); +#endif /* __fcformat__ */ +#ifdef __fcrange__ +# undef FcRangeCreateDouble +extern __typeof (FcRangeCreateDouble) FcRangeCreateDouble __attribute((alias("IA__FcRangeCreateDouble"), visibility("default"))); +# undef FcRangeCreateInteger +extern __typeof (FcRangeCreateInteger) FcRangeCreateInteger __attribute((alias("IA__FcRangeCreateInteger"), visibility("default"))); +# undef FcRangeDestroy +extern __typeof (FcRangeDestroy) FcRangeDestroy __attribute((alias("IA__FcRangeDestroy"), visibility("default"))); +# undef FcRangeCopy +extern __typeof (FcRangeCopy) FcRangeCopy __attribute((alias("IA__FcRangeCopy"), visibility("default"))); +# undef FcRangeGetDouble +extern __typeof (FcRangeGetDouble) FcRangeGetDouble __attribute((alias("IA__FcRangeGetDouble"), visibility("default"))); +#endif /* __fcrange__ */ +#ifdef __fcweight__ +# undef FcWeightFromOpenType +extern __typeof (FcWeightFromOpenType) FcWeightFromOpenType __attribute((alias("IA__FcWeightFromOpenType"), visibility("default"))); +# undef FcWeightToOpenType +extern __typeof (FcWeightToOpenType) FcWeightToOpenType __attribute((alias("IA__FcWeightToOpenType"), visibility("default"))); +#endif /* __fcweight__ */ +#ifdef __fcstr__ +# undef FcStrCopy +extern __typeof (FcStrCopy) FcStrCopy __attribute((alias("IA__FcStrCopy"), visibility("default"))); +# undef FcStrCopyFilename +extern __typeof (FcStrCopyFilename) FcStrCopyFilename __attribute((alias("IA__FcStrCopyFilename"), visibility("default"))); +# undef FcStrPlus +extern __typeof (FcStrPlus) FcStrPlus __attribute((alias("IA__FcStrPlus"), visibility("default"))); +# undef FcStrFree +extern __typeof (FcStrFree) FcStrFree __attribute((alias("IA__FcStrFree"), visibility("default"))); +# undef FcStrDowncase +extern __typeof (FcStrDowncase) FcStrDowncase __attribute((alias("IA__FcStrDowncase"), visibility("default"))); +# undef FcStrCmpIgnoreCase +extern __typeof (FcStrCmpIgnoreCase) FcStrCmpIgnoreCase __attribute((alias("IA__FcStrCmpIgnoreCase"), visibility("default"))); +# undef FcStrCmp +extern __typeof (FcStrCmp) FcStrCmp __attribute((alias("IA__FcStrCmp"), visibility("default"))); +# undef FcStrStrIgnoreCase +extern __typeof (FcStrStrIgnoreCase) FcStrStrIgnoreCase __attribute((alias("IA__FcStrStrIgnoreCase"), visibility("default"))); +# undef FcStrStr +extern __typeof (FcStrStr) FcStrStr __attribute((alias("IA__FcStrStr"), visibility("default"))); +# undef FcUtf8ToUcs4 +extern __typeof (FcUtf8ToUcs4) FcUtf8ToUcs4 __attribute((alias("IA__FcUtf8ToUcs4"), visibility("default"))); +# undef FcUtf8Len +extern __typeof (FcUtf8Len) FcUtf8Len __attribute((alias("IA__FcUtf8Len"), visibility("default"))); +# undef FcUcs4ToUtf8 +extern __typeof (FcUcs4ToUtf8) FcUcs4ToUtf8 __attribute((alias("IA__FcUcs4ToUtf8"), visibility("default"))); +# undef FcUtf16ToUcs4 +extern __typeof (FcUtf16ToUcs4) FcUtf16ToUcs4 __attribute((alias("IA__FcUtf16ToUcs4"), visibility("default"))); +# undef FcUtf16Len +extern __typeof (FcUtf16Len) FcUtf16Len __attribute((alias("IA__FcUtf16Len"), visibility("default"))); +# undef FcStrDirname +extern __typeof (FcStrDirname) FcStrDirname __attribute((alias("IA__FcStrDirname"), visibility("default"))); +# undef FcStrBasename +extern __typeof (FcStrBasename) FcStrBasename __attribute((alias("IA__FcStrBasename"), visibility("default"))); +# undef FcStrSetCreate +extern __typeof (FcStrSetCreate) FcStrSetCreate __attribute((alias("IA__FcStrSetCreate"), visibility("default"))); +# undef FcStrSetMember +extern __typeof (FcStrSetMember) FcStrSetMember __attribute((alias("IA__FcStrSetMember"), visibility("default"))); +# undef FcStrSetEqual +extern __typeof (FcStrSetEqual) FcStrSetEqual __attribute((alias("IA__FcStrSetEqual"), visibility("default"))); +# undef FcStrSetAdd +extern __typeof (FcStrSetAdd) FcStrSetAdd __attribute((alias("IA__FcStrSetAdd"), visibility("default"))); +# undef FcStrSetAddFilename +extern __typeof (FcStrSetAddFilename) FcStrSetAddFilename __attribute((alias("IA__FcStrSetAddFilename"), visibility("default"))); +# undef FcStrSetDel +extern __typeof (FcStrSetDel) FcStrSetDel __attribute((alias("IA__FcStrSetDel"), visibility("default"))); +# undef FcStrSetDestroy +extern __typeof (FcStrSetDestroy) FcStrSetDestroy __attribute((alias("IA__FcStrSetDestroy"), visibility("default"))); +# undef FcStrListCreate +extern __typeof (FcStrListCreate) FcStrListCreate __attribute((alias("IA__FcStrListCreate"), visibility("default"))); +# undef FcStrListFirst +extern __typeof (FcStrListFirst) FcStrListFirst __attribute((alias("IA__FcStrListFirst"), visibility("default"))); +# undef FcStrListNext +extern __typeof (FcStrListNext) FcStrListNext __attribute((alias("IA__FcStrListNext"), visibility("default"))); +# undef FcStrListDone +extern __typeof (FcStrListDone) FcStrListDone __attribute((alias("IA__FcStrListDone"), visibility("default"))); +#endif /* __fcstr__ */ +#ifdef __fcxml__ +# undef FcConfigParseAndLoad +extern __typeof (FcConfigParseAndLoad) FcConfigParseAndLoad __attribute((alias("IA__FcConfigParseAndLoad"), visibility("default"))); +#endif /* __fcxml__ */ +#ifdef __fccfg__ +# undef FcConfigGetRescanInverval +extern __typeof (FcConfigGetRescanInverval) FcConfigGetRescanInverval __attribute((alias("IA__FcConfigGetRescanInverval"), visibility("default"))); +# undef FcConfigSetRescanInverval +extern __typeof (FcConfigSetRescanInverval) FcConfigSetRescanInverval __attribute((alias("IA__FcConfigSetRescanInverval"), visibility("default"))); +#endif /* */ +#endif /* HAVE_GNUC_ATTRIBUTE */ diff --git a/static/custom-include/fontconfig/fcftalias.h b/static/custom-include/fontconfig/fcftalias.h new file mode 100644 index 000000000..884eb4b2e --- /dev/null +++ b/static/custom-include/fontconfig/fcftalias.h @@ -0,0 +1,12 @@ +extern __typeof (FcFreeTypeCharIndex) IA__FcFreeTypeCharIndex __attribute((visibility("hidden"))); +#define FcFreeTypeCharIndex IA__FcFreeTypeCharIndex +extern __typeof (FcFreeTypeCharSetAndSpacing) IA__FcFreeTypeCharSetAndSpacing __attribute((visibility("hidden"))); +#define FcFreeTypeCharSetAndSpacing IA__FcFreeTypeCharSetAndSpacing +extern __typeof (FcFreeTypeCharSet) IA__FcFreeTypeCharSet __attribute((visibility("hidden"))); +#define FcFreeTypeCharSet IA__FcFreeTypeCharSet +extern __typeof (FcPatternGetFTFace) IA__FcPatternGetFTFace __attribute((visibility("hidden"))); +#define FcPatternGetFTFace IA__FcPatternGetFTFace +extern __typeof (FcPatternAddFTFace) IA__FcPatternAddFTFace __attribute((visibility("hidden"))); +#define FcPatternAddFTFace IA__FcPatternAddFTFace +extern __typeof (FcFreeTypeQueryFace) IA__FcFreeTypeQueryFace __attribute((visibility("hidden"))); +#define FcFreeTypeQueryFace IA__FcFreeTypeQueryFace diff --git a/static/custom-include/fontconfig/fcftaliastail.h b/static/custom-include/fontconfig/fcftaliastail.h new file mode 100644 index 000000000..f5a537d9c --- /dev/null +++ b/static/custom-include/fontconfig/fcftaliastail.h @@ -0,0 +1,20 @@ +#if HAVE_GNUC_ATTRIBUTE +#ifdef __fcfreetype__ +# undef FcFreeTypeCharIndex +extern __typeof (FcFreeTypeCharIndex) FcFreeTypeCharIndex __attribute((alias("IA__FcFreeTypeCharIndex"), visibility("default"))); +# undef FcFreeTypeCharSetAndSpacing +extern __typeof (FcFreeTypeCharSetAndSpacing) FcFreeTypeCharSetAndSpacing __attribute((alias("IA__FcFreeTypeCharSetAndSpacing"), visibility("default"))); +# undef FcFreeTypeCharSet +extern __typeof (FcFreeTypeCharSet) FcFreeTypeCharSet __attribute((alias("IA__FcFreeTypeCharSet"), visibility("default"))); +#endif /* __fcfreetype__ */ +#ifdef __fcpat__ +# undef FcPatternGetFTFace +extern __typeof (FcPatternGetFTFace) FcPatternGetFTFace __attribute((alias("IA__FcPatternGetFTFace"), visibility("default"))); +# undef FcPatternAddFTFace +extern __typeof (FcPatternAddFTFace) FcPatternAddFTFace __attribute((alias("IA__FcPatternAddFTFace"), visibility("default"))); +#endif /* __fcpat__ */ +#ifdef __fcfreetype__ +# undef FcFreeTypeQueryFace +extern __typeof (FcFreeTypeQueryFace) FcFreeTypeQueryFace __attribute((alias("IA__FcFreeTypeQueryFace"), visibility("default"))); +#endif /* */ +#endif /* HAVE_GNUC_ATTRIBUTE */ diff --git a/static/ensure_deps.sh b/static/ensure_deps.sh index 8b7c8c47e..581f494dc 100755 --- a/static/ensure_deps.sh +++ b/static/ensure_deps.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash CAIRO_VERSION=1.12.18 +FONTCONFIG_VERSION=2.12.1 FREETYPE_VERSION=2.6 GIFLIB_VERSION=4.2.3 GLIB_VERSION=2.50.2 @@ -12,7 +13,7 @@ PIXMAN_VERSION=0.32.6 ZLIB_VERSION=1.2.11 CAIRO_URL=http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz -FONTCONFIG_URL=http://cgit.freedesktop.org/fontconfig/plain/fontconfig/fontconfig.h +FONTCONFIG_URL=https://www.freedesktop.org/software/fontconfig/release/fontconfig-$FONTCONFIG_VERSION.tar.bz2 FREETYPE_URL=http://download.savannah.gnu.org/releases/freetype/freetype-$FREETYPE_VERSION.tar.gz GIFLIB_URL=http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-$GIFLIB_VERSION.tar.gz GLIB_URL=https://download.gnome.org/sources/glib/2.50/glib-$GLIB_VERSION.tar.xz @@ -60,26 +61,22 @@ if [ ! -d cairo ]; then mv cairo/src cairo/cairo || exit $? fi -if [ ! -d fontconfig ]; then - mkdir -p fontconfig && - curl -s -L $FONTCONFIG_URL >> fontconfig/fontconfig.h || exit $? -fi - -fetch $FREETYPE_URL freetype && -fetch $GIFLIB_URL giflib && -fetch_xz $GLIB_URL glib && -fetch_bz2 $HARFBUZZ_URL harfbuzz && -fetch $LIBJPEG_URL libjpeg && -fetch_xz $LIBPNG_URL libpng && -fetch_xz $PANGO_URL pango && -fetch $PIXMAN_URL pixman && -fetch $ZLIB_URL zlib || exit $? +fetch_bz2 $FONTCONFIG_URL fontconfig && +fetch $FREETYPE_URL freetype && +fetch $GIFLIB_URL giflib && +fetch_xz $GLIB_URL glib && +fetch_bz2 $HARFBUZZ_URL harfbuzz && +fetch $LIBJPEG_URL libjpeg && +fetch_xz $LIBPNG_URL libpng && +fetch_xz $PANGO_URL pango && +fetch $PIXMAN_URL pixman && +fetch $ZLIB_URL zlib || exit $? -if [ ! -d "cairo" ] || [ ! -d "freetype" ] || [ ! -d "giflib" ] \ -|| [ ! -d "glib" ] || [ ! -d "harfbuzz" ] || [ ! -d "libjpeg" ] \ -|| [ ! -d "libpng" ] || [ ! -d "pango" ] || [ ! -d "pixman" ] \ -|| [ ! -d "zlib" ] ; then +if [ ! -d "cairo" ] || [ ! -d "fontconfig" ] || [ ! -d "freetype" ] \ +|| [ ! -d "giflib" ] || [ ! -d "glib" ] || [ ! -d "harfbuzz" ] \ +|| [ ! -d "libjpeg" ] || [ ! -d "libpng" ] || [ ! -d "pango" ] \ +|| [ ! -d "pixman" ] || [ ! -d "zlib" ] ; then echo false else echo true diff --git a/static/fontconfig.gyp b/static/fontconfig.gyp new file mode 100644 index 000000000..d042b2546 --- /dev/null +++ b/static/fontconfig.gyp @@ -0,0 +1,51 @@ +{ + 'includes': ['common.gyp', 'locations.gyp'], + 'targets': [{ + 'target_name': 'fontconfig', + 'type': 'static_library', + 'include_dirs': [ + '<(fontconfig_root)', + '<(fontconfig_root)src', + 'custom-include/fontconfig', + '<(freetype_root)/include', + ], + 'defines': [ + 'HAVE_CONFIG_H', 'FC_CACHEDIR=\"/var/cache/fontconfig\"', + 'FONTCONFIG_PATH=\"/etc/fonts\"' + ], + 'sources': + [ + "<(fontconfig_root)src/fcatomic.c", + "<(fontconfig_root)src/fcblanks.c", + "<(fontconfig_root)src/fccache.c", + "<(fontconfig_root)src/fccfg.c", + "<(fontconfig_root)src/fccharset.c", + "<(fontconfig_root)src/fccompat.c", + "<(fontconfig_root)src/fcdbg.c", + "<(fontconfig_root)src/fcdefault.c", + "<(fontconfig_root)src/fcdir.c", + "<(fontconfig_root)src/fcformat.c", + "<(fontconfig_root)src/fcfreetype.c", + "<(fontconfig_root)src/fcfs.c", + "<(fontconfig_root)src/fcinit.c", + "<(fontconfig_root)src/fclang.c", + "<(fontconfig_root)src/fclist.c", + "<(fontconfig_root)src/fcmatch.c", + "<(fontconfig_root)src/fcmatch.c", + "<(fontconfig_root)src/fcmatrix.c", + "<(fontconfig_root)src/fcname.c", + "<(fontconfig_root)src/fcobjs.c", + "<(fontconfig_root)src/fcpat.c", + "<(fontconfig_root)src/fcrange.c", + "<(fontconfig_root)src/fcserialize.c", + "<(fontconfig_root)src/fcstat.c", + "<(fontconfig_root)src/fcstr.c", + "<(fontconfig_root)src/fcweight.c", + "<(fontconfig_root)src/fcxml.c", + "<(fontconfig_root)src/ftglue.c", + "<(fontconfig_root)src/fcxml.c", + "<(fontconfig_root)src/fcxml.c", + "<(fontconfig_root)src/fcxml.c", + ] + }] +} diff --git a/static/freetype.gyp b/static/freetype.gyp index ed176039e..cf83322de 100644 --- a/static/freetype.gyp +++ b/static/freetype.gyp @@ -27,6 +27,7 @@ #"<(freetype_root)src/base/ftapi.c", "<(freetype_root)src/base/ftbase.c", #"<(freetype_root)src/base/ftbbox.c", + "<(freetype_root)src/base/ftbdf.c", "<(freetype_root)src/base/ftbitmap.c", #"<(freetype_root)src/base/ftcalc.c", #"<(freetype_root)src/base/ftcid.c", @@ -55,7 +56,7 @@ "<(freetype_root)src/base/ftsynth.c", "<(freetype_root)src/base/ftsystem.c", #"<(freetype_root)src/base/fttrigon.c", - #"<(freetype_root)src/base/fttype1.c", + "<(freetype_root)src/base/fttype1.c", #"<(freetype_root)src/base/ftutil.c", #"<(freetype_root)src/base/ftwinfnt.c", #"<(freetype_root)src/base/ftxf86.c", diff --git a/static/locations.gyp b/static/locations.gyp index d12d124c8..a3f7c3ca0 100644 --- a/static/locations.gyp +++ b/static/locations.gyp @@ -1,6 +1,7 @@ { 'variables': { 'cairo_root%': "../deps/cairo/", + 'fontconfig_root%': "../deps/fontconfig/", 'freetype_root%': "../deps/freetype/", 'gif_root%': "../deps/giflib/", 'glib_root%': "../deps/glib/", From e1d1d798dcb3589555ca339857a8f77b39954146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 12 Feb 2017 19:33:54 +0100 Subject: [PATCH 065/183] Use static `expat` library --- static.gyp | 2 +- static/custom-include/expat/expat_config.h | 102 +++++++++++++++++++++ static/ensure_deps.sh | 11 ++- static/expat.gyp | 22 +++++ static/fontconfig.gyp | 2 + static/locations.gyp | 1 + 6 files changed, 135 insertions(+), 5 deletions(-) create mode 100644 static/custom-include/expat/expat_config.h create mode 100644 static/expat.gyp diff --git a/static.gyp b/static.gyp index 6ef4fe500..c47af3bf8 100644 --- a/static.gyp +++ b/static.gyp @@ -8,7 +8,6 @@ [{ 'includes': ['canvas.gypi'], 'libraries': [ - ' header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `getpagesize' function. */ +#define HAVE_GETPAGESIZE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have a working `mmap' system call. */ +#define HAVE_MMAP 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "expat-bugs@libexpat.org" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "expat" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "expat 2.2.0" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "expat" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "2.2.0" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* whether byteorder is bigendian */ +/* #undef WORDS_BIGENDIAN */ + +/* Define to specify how much context to retain around the current parse + point. */ +#define XML_CONTEXT_BYTES 1024 + +/* Define to make parameter entity parsing functionality available. */ +#define XML_DTD 1 + +/* Define to make XML Namespaces functionality available. */ +#define XML_NS 1 + +/* Define to __FUNCTION__ or "" if `__func__' does not conform to ANSI C. */ +/* #undef __func__ */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `long int' if does not define. */ +/* #undef off_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ diff --git a/static/ensure_deps.sh b/static/ensure_deps.sh index 581f494dc..a2fb2933c 100755 --- a/static/ensure_deps.sh +++ b/static/ensure_deps.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash CAIRO_VERSION=1.12.18 +EXPAT_VERSION=2.2.0 FONTCONFIG_VERSION=2.12.1 FREETYPE_VERSION=2.6 GIFLIB_VERSION=4.2.3 @@ -13,6 +14,7 @@ PIXMAN_VERSION=0.32.6 ZLIB_VERSION=1.2.11 CAIRO_URL=http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz +EXPAT_URL=https://downloads.sourceforge.net/project/expat/expat/$EXPAT_VERSION/expat-$EXPAT_VERSION.tar.bz2 FONTCONFIG_URL=https://www.freedesktop.org/software/fontconfig/release/fontconfig-$FONTCONFIG_VERSION.tar.bz2 FREETYPE_URL=http://download.savannah.gnu.org/releases/freetype/freetype-$FREETYPE_VERSION.tar.gz GIFLIB_URL=http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-$GIFLIB_VERSION.tar.gz @@ -61,6 +63,7 @@ if [ ! -d cairo ]; then mv cairo/src cairo/cairo || exit $? fi +fetch_bz2 $EXPAT_URL expat && fetch_bz2 $FONTCONFIG_URL fontconfig && fetch $FREETYPE_URL freetype && fetch $GIFLIB_URL giflib && @@ -73,10 +76,10 @@ fetch $PIXMAN_URL pixman && fetch $ZLIB_URL zlib || exit $? -if [ ! -d "cairo" ] || [ ! -d "fontconfig" ] || [ ! -d "freetype" ] \ -|| [ ! -d "giflib" ] || [ ! -d "glib" ] || [ ! -d "harfbuzz" ] \ -|| [ ! -d "libjpeg" ] || [ ! -d "libpng" ] || [ ! -d "pango" ] \ -|| [ ! -d "pixman" ] || [ ! -d "zlib" ] ; then +if [ ! -d "cairo" ] || [ ! -d "expat" ] || [ ! -d "fontconfig" ] \ +|| [ ! -d "freetype" ] || [ ! -d "giflib" ] || [ ! -d "glib" ] \ +|| [ ! -d "harfbuzz" ] || [ ! -d "libjpeg" ] || [ ! -d "libpng" ] \ +|| [ ! -d "pango" ] || [ ! -d "pixman" ] || [ ! -d "zlib" ] ; then echo false else echo true diff --git a/static/expat.gyp b/static/expat.gyp new file mode 100644 index 000000000..4d26abcc7 --- /dev/null +++ b/static/expat.gyp @@ -0,0 +1,22 @@ +{ + 'includes': ['common.gyp', 'locations.gyp'], + 'targets': [{ + 'target_name': 'expat', + 'type': 'static_library', + 'include_dirs': [ + '<(expat_root)lib/', + '<(expat_root)xmlwf/', + 'custom-include/expat' + ], + 'defines': ['HAVE_EXPAT_CONFIG_H'], + 'sources': [ + "<(expat_root)lib/xmlparse.c", + "<(expat_root)lib/xmltok.c", + "<(expat_root)lib/xmlrole.c", + "<(expat_root)xmlwf/xmlwf.c", + "<(expat_root)xmlwf/xmlfile.c", + "<(expat_root)xmlwf/codepage.c", + "<(expat_root)xmlwf/unixfilemap.c" + ] + }] +} diff --git a/static/fontconfig.gyp b/static/fontconfig.gyp index d042b2546..7b741f1c0 100644 --- a/static/fontconfig.gyp +++ b/static/fontconfig.gyp @@ -7,6 +7,8 @@ '<(fontconfig_root)', '<(fontconfig_root)src', 'custom-include/fontconfig', + + '<(expat_root)/lib', '<(freetype_root)/include', ], 'defines': [ diff --git a/static/locations.gyp b/static/locations.gyp index a3f7c3ca0..0e3f153e2 100644 --- a/static/locations.gyp +++ b/static/locations.gyp @@ -1,6 +1,7 @@ { 'variables': { 'cairo_root%': "../deps/cairo/", + 'expat_root%': "../deps/expat/", 'fontconfig_root%': "../deps/fontconfig/", 'freetype_root%': "../deps/freetype/", 'gif_root%': "../deps/giflib/", From 13a203078651c1674a5f685957e46737b261c911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 12 Feb 2017 20:40:47 +0100 Subject: [PATCH 066/183] Use static `ffi` library --- static.gyp | 4 +- static/custom-include/ffi/fficonfig.h | 214 ++++++++++++++++++++++++++ static/ensure_deps.sh | 12 +- static/ffi.gyp | 23 +++ static/locations.gyp | 1 + 5 files changed, 247 insertions(+), 7 deletions(-) create mode 100644 static/custom-include/ffi/fficonfig.h create mode 100644 static/ffi.gyp diff --git a/static.gyp b/static.gyp index c47af3bf8..0cdfd386c 100644 --- a/static.gyp +++ b/static.gyp @@ -7,9 +7,6 @@ 'targets': [{ 'includes': ['canvas.gypi'], - 'libraries': [ - ' and it should be used (not on Ultrix). + */ +#define HAVE_ALLOCA_H 1 + +/* Define if your assembler supports .ascii. */ +#define HAVE_AS_ASCII_PSEUDO_OP 1 + +/* Define if your assembler supports .cfi_* directives. */ +#define HAVE_AS_CFI_PSEUDO_OP 1 + +/* Define if your assembler supports .register. */ +/* #undef HAVE_AS_REGISTER_PSEUDO_OP */ + +/* Define if your assembler and linker support unaligned PC relative relocs. + */ +/* #undef HAVE_AS_SPARC_UA_PCREL */ + +/* Define if your assembler supports .string. */ +#define HAVE_AS_STRING_PSEUDO_OP 1 + +/* Define if your assembler supports unwind section type. */ +#define HAVE_AS_X86_64_UNWIND_SECTION_TYPE 1 + +/* Define if your assembler supports PC relative relocs. */ +#define HAVE_AS_X86_PCREL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define if __attribute__((visibility("hidden"))) is supported. */ +#define HAVE_HIDDEN_VISIBILITY_ATTRIBUTE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define if you have the long double type and it is bigger than a double */ +#define HAVE_LONG_DOUBLE 1 + +/* Define if you support more than one size of the long double type */ +/* #undef HAVE_LONG_DOUBLE_VARIANT */ + +/* Define to 1 if you have the `memcpy' function. */ +#define HAVE_MEMCPY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `mkostemp' function. */ +#define HAVE_MKOSTEMP 1 + +/* Define to 1 if you have the `mmap' function. */ +#define HAVE_MMAP 1 + +/* Define if mmap with MAP_ANON(YMOUS) works. */ +#define HAVE_MMAP_ANON 1 + +/* Define if mmap of /dev/zero works. */ +#define HAVE_MMAP_DEV_ZERO 1 + +/* Define if read-only mmap of a plain file works. */ +#define HAVE_MMAP_FILE 1 + +/* Define if .eh_frame sections should be read-only. */ +#define HAVE_RO_EH_FRAME 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_MMAN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* Name of package */ +#define PACKAGE "libffi" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "http://github.com/atgreen/libffi/issues" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "libffi" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "libffi 3.2.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "libffi" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "3.2.1" + +/* The size of `double', as computed by sizeof. */ +#define SIZEOF_DOUBLE 8 + +/* The size of `long double', as computed by sizeof. */ +#define SIZEOF_LONG_DOUBLE 16 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 8 + +/* If using the C implementation of alloca, define if you know the + direction of stack growth for your system; otherwise it will be + automatically deduced at runtime. + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ +/* #undef STACK_DIRECTION */ + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define if symbols are underscored. */ +/* #undef SYMBOL_UNDERSCORE */ + +/* Define this if you are using Purify and want to suppress spurious messages. + */ +/* #undef USING_PURIFY */ + +/* Version number of package */ +#define VERSION "3.2.1" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + + +#ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE +#ifdef LIBFFI_ASM +#define FFI_HIDDEN(name) .hidden name +#else +#define FFI_HIDDEN __attribute__ ((visibility ("hidden"))) +#endif +#else +#ifdef LIBFFI_ASM +#define FFI_HIDDEN(name) +#else +#define FFI_HIDDEN +#endif +#endif diff --git a/static/ensure_deps.sh b/static/ensure_deps.sh index a2fb2933c..181098f81 100755 --- a/static/ensure_deps.sh +++ b/static/ensure_deps.sh @@ -2,6 +2,7 @@ CAIRO_VERSION=1.12.18 EXPAT_VERSION=2.2.0 +FFI_VERSION=3.2.1 FONTCONFIG_VERSION=2.12.1 FREETYPE_VERSION=2.6 GIFLIB_VERSION=4.2.3 @@ -15,6 +16,7 @@ ZLIB_VERSION=1.2.11 CAIRO_URL=http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz EXPAT_URL=https://downloads.sourceforge.net/project/expat/expat/$EXPAT_VERSION/expat-$EXPAT_VERSION.tar.bz2 +FFI_URL=ftp://sourceware.org/pub/libffi/libffi-$FFI_VERSION.tar.gz FONTCONFIG_URL=https://www.freedesktop.org/software/fontconfig/release/fontconfig-$FONTCONFIG_VERSION.tar.bz2 FREETYPE_URL=http://download.savannah.gnu.org/releases/freetype/freetype-$FREETYPE_VERSION.tar.gz GIFLIB_URL=http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-$GIFLIB_VERSION.tar.gz @@ -64,6 +66,7 @@ if [ ! -d cairo ]; then fi fetch_bz2 $EXPAT_URL expat && +fetch $FFI_URL ffi && fetch_bz2 $FONTCONFIG_URL fontconfig && fetch $FREETYPE_URL freetype && fetch $GIFLIB_URL giflib && @@ -76,10 +79,11 @@ fetch $PIXMAN_URL pixman && fetch $ZLIB_URL zlib || exit $? -if [ ! -d "cairo" ] || [ ! -d "expat" ] || [ ! -d "fontconfig" ] \ -|| [ ! -d "freetype" ] || [ ! -d "giflib" ] || [ ! -d "glib" ] \ -|| [ ! -d "harfbuzz" ] || [ ! -d "libjpeg" ] || [ ! -d "libpng" ] \ -|| [ ! -d "pango" ] || [ ! -d "pixman" ] || [ ! -d "zlib" ] ; then +if [ ! -d "cairo" ] || [ ! -d "expat" ] || [ ! -d "ffi" ] \ +|| [ ! -d "fontconfig" ] || [ ! -d "freetype" ] || [ ! -d "giflib" ] \ +|| [ ! -d "glib" ] || [ ! -d "harfbuzz" ] || [ ! -d "libjpeg" ] \ +|| [ ! -d "libpng" ] || [ ! -d "pango" ] || [ ! -d "pixman" ] \ +|| [ ! -d "zlib" ] ; then echo false else echo true diff --git a/static/ffi.gyp b/static/ffi.gyp new file mode 100644 index 000000000..297eb0e2a --- /dev/null +++ b/static/ffi.gyp @@ -0,0 +1,23 @@ +{ + 'includes': ['common.gyp', 'locations.gyp'], + 'targets': [{ + 'target_name': 'ffi', + 'type': 'static_library', + 'include_dirs': [ + '<(ffi_root)include/', + 'custom-include/ffi' + ], + 'defines': ['HAVE_CONFIG_H'], + 'sources': [ + "<(ffi_root)src/prep_cif.c", + "<(ffi_root)src/types.c", + "<(ffi_root)src/raw_api.c", + "<(ffi_root)src/java_raw_api.c", + "<(ffi_root)src/closures.c", + "<(ffi_root)src/x86/ffi64.c", + "<(ffi_root)src/x86/unix64.S", + "<(ffi_root)src/x86/ffi.c", + "<(ffi_root)src/x86/sysv.S" + ] + }] +} diff --git a/static/locations.gyp b/static/locations.gyp index 0e3f153e2..03743a3c6 100644 --- a/static/locations.gyp +++ b/static/locations.gyp @@ -2,6 +2,7 @@ 'variables': { 'cairo_root%': "../deps/cairo/", 'expat_root%': "../deps/expat/", + 'ffi_root%': "../deps/ffi/", 'fontconfig_root%': "../deps/fontconfig/", 'freetype_root%': "../deps/freetype/", 'gif_root%': "../deps/giflib/", From 5520bbc4046536e8ad6f2b0e39eee7e334fc6d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 13 Feb 2017 11:40:38 +0100 Subject: [PATCH 067/183] Add missing headers --- static.gyp | 1 + static/cairo.gyp | 9 +- static/custom-include/ffi/ffi.h | 487 ++++++++++++++++++++++++++++++++ static/ffi.gyp | 1 + static/glib.gyp | 5 +- static/pango.gyp | 1 + 6 files changed, 496 insertions(+), 8 deletions(-) create mode 100644 static/custom-include/ffi/ffi.h diff --git a/static.gyp b/static.gyp index 0cdfd386c..2e6685284 100644 --- a/static.gyp +++ b/static.gyp @@ -15,6 +15,7 @@ 'static/custom-include/cairo', 'deps/<(fontconfig_root)/src', 'static/custom-include/fontconfig', + 'deps/<(fontconfig_root)', 'deps/<(freetype_root)/include', 'deps/<(gif_root)/lib', 'deps/<(glib_root)', diff --git a/static/cairo.gyp b/static/cairo.gyp index cd3d557f8..0257149c1 100644 --- a/static/cairo.gyp +++ b/static/cairo.gyp @@ -2,8 +2,7 @@ 'includes': ['common.gyp', 'locations.gyp'], 'conditions': [ - ['OS!="win"', - { + ['OS!="win"', { 'variables': { 'cairo_src%': "<(cairo_root)cairo/" @@ -19,17 +18,13 @@ 'custom-include/cairo', '<(cairo_root)', '<(cairo_src)', + '<(fontconfig_root)', '<(freetype_root)include', '<(libpng_root)', 'custom-include/png', '<(pixman_root)', '<(pixman_root)pixman', '<(zlib_root)', - - # ' + +#ifndef LIBFFI_ASM + +#if defined(_MSC_VER) && !defined(__clang__) +#define __attribute__(X) +#endif + +#include +#include + +/* LONG_LONG_MAX is not always defined (not if STRICT_ANSI, for example). + But we can find it either under the correct ANSI name, or under GNU + C's internal name. */ + +#define FFI_64_BIT_MAX 9223372036854775807 + +#ifdef LONG_LONG_MAX +# define FFI_LONG_LONG_MAX LONG_LONG_MAX +#else +# ifdef LLONG_MAX +# define FFI_LONG_LONG_MAX LLONG_MAX +# ifdef _AIX52 /* or newer has C99 LLONG_MAX */ +# undef FFI_64_BIT_MAX +# define FFI_64_BIT_MAX 9223372036854775807LL +# endif /* _AIX52 or newer */ +# else +# ifdef __GNUC__ +# define FFI_LONG_LONG_MAX __LONG_LONG_MAX__ +# endif +# ifdef _AIX /* AIX 5.1 and earlier have LONGLONG_MAX */ +# ifndef __PPC64__ +# if defined (__IBMC__) || defined (__IBMCPP__) +# define FFI_LONG_LONG_MAX LONGLONG_MAX +# endif +# endif /* __PPC64__ */ +# undef FFI_64_BIT_MAX +# define FFI_64_BIT_MAX 9223372036854775807LL +# endif +# endif +#endif + +/* The closure code assumes that this works on pointers, i.e. a size_t */ +/* can hold a pointer. */ + +typedef struct _ffi_type +{ + size_t size; + unsigned short alignment; + unsigned short type; + struct _ffi_type **elements; +} ffi_type; + +#ifndef LIBFFI_HIDE_BASIC_TYPES +#if SCHAR_MAX == 127 +# define ffi_type_uchar ffi_type_uint8 +# define ffi_type_schar ffi_type_sint8 +#else + #error "char size not supported" +#endif + +#if SHRT_MAX == 32767 +# define ffi_type_ushort ffi_type_uint16 +# define ffi_type_sshort ffi_type_sint16 +#elif SHRT_MAX == 2147483647 +# define ffi_type_ushort ffi_type_uint32 +# define ffi_type_sshort ffi_type_sint32 +#else + #error "short size not supported" +#endif + +#if INT_MAX == 32767 +# define ffi_type_uint ffi_type_uint16 +# define ffi_type_sint ffi_type_sint16 +#elif INT_MAX == 2147483647 +# define ffi_type_uint ffi_type_uint32 +# define ffi_type_sint ffi_type_sint32 +#elif INT_MAX == 9223372036854775807 +# define ffi_type_uint ffi_type_uint64 +# define ffi_type_sint ffi_type_sint64 +#else + #error "int size not supported" +#endif + +#if LONG_MAX == 2147483647 +# if FFI_LONG_LONG_MAX != FFI_64_BIT_MAX + #error "no 64-bit data type supported" +# endif +#elif LONG_MAX != FFI_64_BIT_MAX + #error "long size not supported" +#endif + +#if LONG_MAX == 2147483647 +# define ffi_type_ulong ffi_type_uint32 +# define ffi_type_slong ffi_type_sint32 +#elif LONG_MAX == FFI_64_BIT_MAX +# define ffi_type_ulong ffi_type_uint64 +# define ffi_type_slong ffi_type_sint64 +#else + #error "long size not supported" +#endif + +/* Need minimal decorations for DLLs to works on Windows. */ +/* GCC has autoimport and autoexport. Rely on Libtool to */ +/* help MSVC export from a DLL, but always declare data */ +/* to be imported for MSVC clients. This costs an extra */ +/* indirection for MSVC clients using the static version */ +/* of the library, but don't worry about that. Besides, */ +/* as a workaround, they can define FFI_BUILDING if they */ +/* *know* they are going to link with the static library. */ +#if defined _MSC_VER && !defined FFI_BUILDING +#define FFI_EXTERN extern __declspec(dllimport) +#else +#define FFI_EXTERN extern +#endif + +/* These are defined in types.c */ +FFI_EXTERN ffi_type ffi_type_void; +FFI_EXTERN ffi_type ffi_type_uint8; +FFI_EXTERN ffi_type ffi_type_sint8; +FFI_EXTERN ffi_type ffi_type_uint16; +FFI_EXTERN ffi_type ffi_type_sint16; +FFI_EXTERN ffi_type ffi_type_uint32; +FFI_EXTERN ffi_type ffi_type_sint32; +FFI_EXTERN ffi_type ffi_type_uint64; +FFI_EXTERN ffi_type ffi_type_sint64; +FFI_EXTERN ffi_type ffi_type_float; +FFI_EXTERN ffi_type ffi_type_double; +FFI_EXTERN ffi_type ffi_type_pointer; + +#if 1 +FFI_EXTERN ffi_type ffi_type_longdouble; +#else +#define ffi_type_longdouble ffi_type_double +#endif + +#ifdef FFI_TARGET_HAS_COMPLEX_TYPE +FFI_EXTERN ffi_type ffi_type_complex_float; +FFI_EXTERN ffi_type ffi_type_complex_double; +#if 1 +FFI_EXTERN ffi_type ffi_type_complex_longdouble; +#else +#define ffi_type_complex_longdouble ffi_type_complex_double +#endif +#endif +#endif /* LIBFFI_HIDE_BASIC_TYPES */ + +typedef enum { + FFI_OK = 0, + FFI_BAD_TYPEDEF, + FFI_BAD_ABI +} ffi_status; + +typedef unsigned FFI_TYPE; + +typedef struct { + ffi_abi abi; + unsigned nargs; + ffi_type **arg_types; + ffi_type *rtype; + unsigned bytes; + unsigned flags; +#ifdef FFI_EXTRA_CIF_FIELDS + FFI_EXTRA_CIF_FIELDS; +#endif +} ffi_cif; + +#if 0 +/* Used to adjust size/alignment of ffi types. */ +void ffi_prep_types (ffi_abi abi); +#endif + +/* Used internally, but overridden by some architectures */ +ffi_status ffi_prep_cif_core(ffi_cif *cif, + ffi_abi abi, + unsigned int isvariadic, + unsigned int nfixedargs, + unsigned int ntotalargs, + ffi_type *rtype, + ffi_type **atypes); + +/* ---- Definitions for the raw API -------------------------------------- */ + +#ifndef FFI_SIZEOF_ARG +# if LONG_MAX == 2147483647 +# define FFI_SIZEOF_ARG 4 +# elif LONG_MAX == FFI_64_BIT_MAX +# define FFI_SIZEOF_ARG 8 +# endif +#endif + +#ifndef FFI_SIZEOF_JAVA_RAW +# define FFI_SIZEOF_JAVA_RAW FFI_SIZEOF_ARG +#endif + +typedef union { + ffi_sarg sint; + ffi_arg uint; + float flt; + char data[FFI_SIZEOF_ARG]; + void* ptr; +} ffi_raw; + +#if FFI_SIZEOF_JAVA_RAW == 4 && FFI_SIZEOF_ARG == 8 +/* This is a special case for mips64/n32 ABI (and perhaps others) where + sizeof(void *) is 4 and FFI_SIZEOF_ARG is 8. */ +typedef union { + signed int sint; + unsigned int uint; + float flt; + char data[FFI_SIZEOF_JAVA_RAW]; + void* ptr; +} ffi_java_raw; +#else +typedef ffi_raw ffi_java_raw; +#endif + + +void ffi_raw_call (ffi_cif *cif, + void (*fn)(void), + void *rvalue, + ffi_raw *avalue); + +void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw); +void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args); +size_t ffi_raw_size (ffi_cif *cif); + +/* This is analogous to the raw API, except it uses Java parameter */ +/* packing, even on 64-bit machines. I.e. on 64-bit machines */ +/* longs and doubles are followed by an empty 64-bit word. */ + +void ffi_java_raw_call (ffi_cif *cif, + void (*fn)(void), + void *rvalue, + ffi_java_raw *avalue); + +void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw); +void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args); +size_t ffi_java_raw_size (ffi_cif *cif); + +/* ---- Definitions for closures ----------------------------------------- */ + +#if FFI_CLOSURES + +#ifdef _MSC_VER +__declspec(align(8)) +#endif +typedef struct { +#if 0 + void *trampoline_table; + void *trampoline_table_entry; +#else + char tramp[FFI_TRAMPOLINE_SIZE]; +#endif + ffi_cif *cif; + void (*fun)(ffi_cif*,void*,void**,void*); + void *user_data; +#ifdef __GNUC__ +} ffi_closure __attribute__((aligned (8))); +#else +} ffi_closure; +# ifdef __sgi +# pragma pack 0 +# endif +#endif + +void *ffi_closure_alloc (size_t size, void **code); +void ffi_closure_free (void *); + +ffi_status +ffi_prep_closure (ffi_closure*, + ffi_cif *, + void (*fun)(ffi_cif*,void*,void**,void*), + void *user_data); + +ffi_status +ffi_prep_closure_loc (ffi_closure*, + ffi_cif *, + void (*fun)(ffi_cif*,void*,void**,void*), + void *user_data, + void*codeloc); + +#ifdef __sgi +# pragma pack 8 +#endif +typedef struct { +#if 0 + void *trampoline_table; + void *trampoline_table_entry; +#else + char tramp[FFI_TRAMPOLINE_SIZE]; +#endif + ffi_cif *cif; + +#if !FFI_NATIVE_RAW_API + + /* if this is enabled, then a raw closure has the same layout + as a regular closure. We use this to install an intermediate + handler to do the transaltion, void** -> ffi_raw*. */ + + void (*translate_args)(ffi_cif*,void*,void**,void*); + void *this_closure; + +#endif + + void (*fun)(ffi_cif*,void*,ffi_raw*,void*); + void *user_data; + +} ffi_raw_closure; + +typedef struct { +#if 0 + void *trampoline_table; + void *trampoline_table_entry; +#else + char tramp[FFI_TRAMPOLINE_SIZE]; +#endif + + ffi_cif *cif; + +#if !FFI_NATIVE_RAW_API + + /* if this is enabled, then a raw closure has the same layout + as a regular closure. We use this to install an intermediate + handler to do the transaltion, void** -> ffi_raw*. */ + + void (*translate_args)(ffi_cif*,void*,void**,void*); + void *this_closure; + +#endif + + void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*); + void *user_data; + +} ffi_java_raw_closure; + +ffi_status +ffi_prep_raw_closure (ffi_raw_closure*, + ffi_cif *cif, + void (*fun)(ffi_cif*,void*,ffi_raw*,void*), + void *user_data); + +ffi_status +ffi_prep_raw_closure_loc (ffi_raw_closure*, + ffi_cif *cif, + void (*fun)(ffi_cif*,void*,ffi_raw*,void*), + void *user_data, + void *codeloc); + +ffi_status +ffi_prep_java_raw_closure (ffi_java_raw_closure*, + ffi_cif *cif, + void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), + void *user_data); + +ffi_status +ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*, + ffi_cif *cif, + void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), + void *user_data, + void *codeloc); + +#endif /* FFI_CLOSURES */ + +/* ---- Public interface definition -------------------------------------- */ + +ffi_status ffi_prep_cif(ffi_cif *cif, + ffi_abi abi, + unsigned int nargs, + ffi_type *rtype, + ffi_type **atypes); + +ffi_status ffi_prep_cif_var(ffi_cif *cif, + ffi_abi abi, + unsigned int nfixedargs, + unsigned int ntotalargs, + ffi_type *rtype, + ffi_type **atypes); + +void ffi_call(ffi_cif *cif, + void (*fn)(void), + void *rvalue, + void **avalue); + +/* Useful for eliminating compiler warnings */ +#define FFI_FN(f) ((void (*)(void))f) + +/* ---- Definitions shared with assembly code ---------------------------- */ + +#endif + +/* If these change, update src/mips/ffitarget.h. */ +#define FFI_TYPE_VOID 0 +#define FFI_TYPE_INT 1 +#define FFI_TYPE_FLOAT 2 +#define FFI_TYPE_DOUBLE 3 +#if 1 +#define FFI_TYPE_LONGDOUBLE 4 +#else +#define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE +#endif +#define FFI_TYPE_UINT8 5 +#define FFI_TYPE_SINT8 6 +#define FFI_TYPE_UINT16 7 +#define FFI_TYPE_SINT16 8 +#define FFI_TYPE_UINT32 9 +#define FFI_TYPE_SINT32 10 +#define FFI_TYPE_UINT64 11 +#define FFI_TYPE_SINT64 12 +#define FFI_TYPE_STRUCT 13 +#define FFI_TYPE_POINTER 14 +#define FFI_TYPE_COMPLEX 15 + +/* This should always refer to the last type code (for sanity checks) */ +#define FFI_TYPE_LAST FFI_TYPE_COMPLEX + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/static/ffi.gyp b/static/ffi.gyp index 297eb0e2a..d95845d7e 100644 --- a/static/ffi.gyp +++ b/static/ffi.gyp @@ -5,6 +5,7 @@ 'type': 'static_library', 'include_dirs': [ '<(ffi_root)include/', + '<(ffi_root)src/x86', 'custom-include/ffi' ], 'defines': ['HAVE_CONFIG_H'], diff --git a/static/glib.gyp b/static/glib.gyp index 9403afffc..5dbfe21b7 100644 --- a/static/glib.gyp +++ b/static/glib.gyp @@ -165,7 +165,10 @@ '<(glib_root)', '<(glib_root)/glib', '<(glib_root)/gobject', - 'custom-include/glib' + 'custom-include/glib', + + '<(ffi_root)src/x86', + 'custom-include/ffi' ], 'defines': [ 'HAVE_CONFIG_H', 'G_LOG_DOMAIN=\"GLib-GObject\"', diff --git a/static/pango.gyp b/static/pango.gyp index eec11099e..54dadd2bd 100644 --- a/static/pango.gyp +++ b/static/pango.gyp @@ -28,6 +28,7 @@ 'custom-include/pango', '<(cairo_root)cairo', 'custom-include/cairo', + '<(fontconfig_root)', '<(freetype_root)/include', '<(glib_root)', '<(glib_root)/glib', From 7a71fec7a513b9a961440946ea3d42fb13a527f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Thu, 16 Feb 2017 13:42:32 +0100 Subject: [PATCH 068/183] Changed extension of all include files from `.gyp` to `.gypi` --- binding.gyp | 10 ++++----- shared.gyp => shared.gypi | 0 static.gyp => static.gypi | 26 +++++++++++----------- static/cairo.gyp | 6 ++--- static/{common.gyp => common.gypi} | 0 static/ensure_deps.sh | 1 + static/{expat.gyp => expat.gypi} | 2 +- static/{ffi.gyp => ffi.gypi} | 2 +- static/{fontconfig.gyp => fontconfig.gypi} | 2 +- static/{freetype.gyp => freetype.gypi} | 6 ++--- static/{gif.gyp => gif.gypi} | 5 ++--- static/{glib.gyp => glib.gypi} | 2 +- static/{harfbuzz.gyp => harfbuzz.gypi} | 2 +- static/{jpeg.gyp => jpeg.gypi} | 4 ++-- static/{libpng.gyp => libpng.gypi} | 6 ++--- static/{locations.gyp => locations.gypi} | 0 static/{pango.gyp => pango.gypi} | 8 +++---- static/{pixman.gyp => pixman.gypi} | 22 +++++++----------- static/{zlib.gyp => zlib.gypi} | 10 ++------- 19 files changed, 50 insertions(+), 64 deletions(-) rename shared.gyp => shared.gypi (100%) rename static.gyp => static.gypi (62%) rename static/{common.gyp => common.gypi} (100%) rename static/{expat.gyp => expat.gypi} (92%) rename static/{ffi.gyp => ffi.gypi} (92%) rename static/{fontconfig.gyp => fontconfig.gypi} (97%) rename static/{freetype.gyp => freetype.gypi} (98%) rename static/{gif.gyp => gif.gypi} (77%) rename static/{glib.gyp => glib.gypi} (99%) rename static/{harfbuzz.gyp => harfbuzz.gypi} (98%) rename static/{jpeg.gyp => jpeg.gypi} (97%) rename static/{libpng.gyp => libpng.gypi} (95%) rename static/{locations.gyp => locations.gypi} (100%) rename static/{pango.gyp => pango.gypi} (95%) rename static/{pixman.gyp => pixman.gypi} (87%) rename static/{zlib.gyp => zlib.gypi} (92%) diff --git a/binding.gyp b/binding.gyp index 63b95cc94..69ef2eeb9 100644 --- a/binding.gyp +++ b/binding.gyp @@ -5,12 +5,10 @@ }, 'conditions': [ - ['has_cairo=="true"', - { - 'includes': ['shared.gyp'] - }, - { - 'includes': ['static.gyp'] + ['has_cairo=="true"', { + 'includes': ['shared.gypi'] + }, { + 'includes': ['static.gypi'] }] ] } diff --git a/shared.gyp b/shared.gypi similarity index 100% rename from shared.gyp rename to shared.gypi diff --git a/static.gyp b/static.gypi similarity index 62% rename from static.gyp rename to static.gypi index 2e6685284..d873757c1 100644 --- a/static.gyp +++ b/static.gypi @@ -1,8 +1,8 @@ { - 'includes': ['static/locations.gyp'], + 'includes': ['static/locations.gypi'], 'variables': { - 'ensure_deps%': ' Date: Sun, 26 Feb 2017 21:43:25 +0100 Subject: [PATCH 069/183] Renamed `static/cairo.gyp` to `static/cairo.gypi` --- static/{cairo.gyp => cairo.gypi} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename static/{cairo.gyp => cairo.gypi} (100%) diff --git a/static/cairo.gyp b/static/cairo.gypi similarity index 100% rename from static/cairo.gyp rename to static/cairo.gypi From 107be5939c6150c6691f6c25a0aeeea43494aa3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Thu, 4 May 2017 22:57:39 +0200 Subject: [PATCH 070/183] Applied @zbjornson patch https://github.com/Automattic/node-canvas/pull/813#issuecomment-296480055 --- binding.gyp | 2 +- shared.gypi | 1 - util/has_lib.js | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/binding.gyp b/binding.gyp index f28af38b5..93487c9d4 100644 --- a/binding.gyp +++ b/binding.gyp @@ -5,7 +5,7 @@ }, 'conditions': [ - ['has_cairo=="true"', { + ['has_cairo=="true" or OS=="win"', { 'includes': ['shared.gypi'] }, { 'includes': ['static.gypi'] diff --git a/shared.gypi b/shared.gypi index 1876fac97..cb56548e6 100644 --- a/shared.gypi +++ b/shared.gypi @@ -90,7 +90,6 @@ ], 'defines': [ - 'snprintf=_snprintf', '_USE_MATH_DEFINES' # for M_PI ], 'configurations': diff --git a/util/has_lib.js b/util/has_lib.js index 9df6b9d0b..d357b29e3 100644 --- a/util/has_lib.js +++ b/util/has_lib.js @@ -53,7 +53,7 @@ function hasLdconfig () { try { // Add /sbin to path as ldconfig is located there on some systems -- e.g. // Debian (and it can still be used by unprivileged users): - childProcess.execSync('export PATH="$PATH:/sbin"') + childProcess.execSync('export PATH="$PATH:/sbin"', {stdio: 'ignore'}) process.env.PATH = '...' // execSync throws on nonzero exit childProcess.execSync('hash ldconfig 2>/dev/null') From ef51cbfffbde054f7c58b0033d7d3606e3d25b53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 4 Aug 2017 11:00:05 +0200 Subject: [PATCH 071/183] Check that all shared libraries are available before doing static compile --- binding.gyp | 4 ++-- util/has_lib.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/binding.gyp b/binding.gyp index 93487c9d4..c46e9fcaf 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,11 +1,11 @@ { 'variables': { - 'has_cairo%': ' Date: Fri, 4 Aug 2017 11:00:28 +0200 Subject: [PATCH 072/183] Minor clean-up of `has_lib.js` --- util/has_lib.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/util/has_lib.js b/util/has_lib.js index 8249b7d88..84414b751 100644 --- a/util/has_lib.js +++ b/util/has_lib.js @@ -1,6 +1,5 @@ -var query = process.argv[2] -var fs = require('fs') var childProcess = require('child_process') +var fs = require('fs') var SYSTEM_PATHS = [ '/lib', @@ -24,7 +23,8 @@ function hasSystemLib (lib) { // Try using ldconfig on linux systems if (hasLdconfig()) { try { - if (childProcess.execSync('ldconfig -p 2>/dev/null | grep -E "' + libName + '"').length) { + if (childProcess.execSync('ldconfig -p 2>/dev/null | grep -E "' + + libName + '"').length) { return true } } catch (err) { @@ -69,13 +69,13 @@ function hasLdconfig () { */ function hasFreetype () { try { - if (childProcess.execSync('pkg-config cairo --cflags-only-I 2>/dev/null | grep freetype2').length) { + if (childProcess.execSync('pkg-config cairo --cflags-only-I 2>/dev/null | ' + + 'grep freetype2').length) { return true } } catch (err) { - // noop + return false } - return false } /** @@ -118,4 +118,4 @@ function main (query) { } } -process.stdout.write(main(query).toString()) +process.stdout.write(main(process.argv[2]).toString()) From 6fe4a2868a557287b162718f552462f126d2a7bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 5 Aug 2017 19:46:50 +0200 Subject: [PATCH 073/183] Unified and simplified checking functions at `has_lib.js` --- util/has_lib.js | 64 +++++++++++++++---------------------------------- 1 file changed, 19 insertions(+), 45 deletions(-) diff --git a/util/has_lib.js b/util/has_lib.js index 84414b751..db64e56b3 100644 --- a/util/has_lib.js +++ b/util/has_lib.js @@ -1,4 +1,4 @@ -var childProcess = require('child_process') +var execSync = require('child_process').execSync var fs = require('fs') var SYSTEM_PATHS = [ @@ -10,6 +10,16 @@ var SYSTEM_PATHS = [ '/usr/lib/i386-linux-gnu' ] +function _hasQuery (query) { + try { + // execSync throws on nonzero exit + execSync(query) + return true + } catch (err) { + return false + } +} + /** * Checks for lib using ldconfig if present, or searching SYSTEM_PATHS * otherwise. @@ -18,21 +28,15 @@ var SYSTEM_PATHS = [ */ function hasSystemLib (lib) { var libName = 'lib' + lib + '.+(so|dylib)' - var libNameRegex = new RegExp(libName) // Try using ldconfig on linux systems - if (hasLdconfig()) { - try { - if (childProcess.execSync('ldconfig -p 2>/dev/null | grep -E "' + - libName + '"').length) { - return true - } - } catch (err) { - // noop -- proceed to other search methods - } + if (_hasQuery('ldconfig -p 2>/dev/null | grep -E "' + libName + '"')) { + return true } - // Try checking common library locations + // Try checking common library locations + var libNameRegex = new RegExp(libName) + return SYSTEM_PATHS.some(function (systemPath) { try { var dirListing = fs.readdirSync(systemPath) @@ -45,37 +49,13 @@ function hasSystemLib (lib) { }) } -/** - * Checks for ldconfig on the path and /sbin - * @return Boolean exists - */ -function hasLdconfig () { - try { - // Add /sbin to path as ldconfig is located there on some systems -- e.g. - // Debian (and it can still be used by unprivileged users): - childProcess.execSync('export PATH="$PATH:/sbin"', {stdio: 'ignore'}) - process.env.PATH = '...' - // execSync throws on nonzero exit - childProcess.execSync('hash ldconfig 2>/dev/null') - return true - } catch (err) { - return false - } -} - /** * Checks for freetype2 with --cflags-only-I * @return Boolean exists */ function hasFreetype () { - try { - if (childProcess.execSync('pkg-config cairo --cflags-only-I 2>/dev/null | ' + - 'grep freetype2').length) { - return true - } - } catch (err) { - return false - } + return _hasQuery('pkg-config cairo --cflags-only-I 2>/dev/null | ' + + 'grep freetype2') } /** @@ -84,13 +64,7 @@ function hasFreetype () { * @return Boolean exists */ function hasPkgconfigLib (lib) { - try { - // execSync throws on nonzero exit - childProcess.execSync('pkg-config --exists "' + lib + '" 2>/dev/null') - return true - } catch (err) { - return false - } + return _hasQuery('pkg-config --exists "' + lib + '" 2>/dev/null') } function main (query) { From 569f5b8732f83ff9b4e0a64b52825275a570546c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 5 Aug 2017 19:47:07 +0200 Subject: [PATCH 074/183] Fixed lint errors on `shared.gypi` --- shared.gypi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/shared.gypi b/shared.gypi index 61cddc591..b53eab1db 100644 --- a/shared.gypi +++ b/shared.gypi @@ -9,7 +9,7 @@ 'with_gif%': 'false', 'with_rsvg%': 'false', 'variables': { # Nest jpeg_root to evaluate it before with_jpeg - 'jpeg_root%': ' Date: Mon, 19 Nov 2018 12:43:54 +0100 Subject: [PATCH 075/183] Fixed linting --- benchmarks/run.js | 10 +- examples/animated_clock.js | 169 +-- examples/simple_fbdev.js | 40 +- examples/simple_x11.js | 21 +- lib/DOMMatrix.js | 96 +- lib/bindings.js | 4 +- lib/canvas.js | 86 +- lib/context2d.js | 152 +-- lib/image.js | 56 +- lib/jpegstream.js | 42 +- lib/parse-font.js | 19 +- lib/pdfstream.js | 38 +- lib/pngstream.js | 42 +- test/canvas.test.js | 2397 ++++++++++++++++++------------------ test/dommatrix.test.js | 20 +- test/image.test.js | 180 +-- test/imageData.test.js | 14 +- util/has_lib.js | 2 +- util/win_jpeg_lookup.js | 6 +- 19 files changed, 1712 insertions(+), 1682 deletions(-) diff --git a/benchmarks/run.js b/benchmarks/run.js index e088e0692..4914ea97b 100644 --- a/benchmarks/run.js +++ b/benchmarks/run.js @@ -65,8 +65,8 @@ function done (benchmark, times, start, isAsync) { // node-canvas bm('fillStyle= name', function () { - ctx.fillStyle = "transparent"; -}); + ctx.fillStyle = 'transparent' +}) bm('lineTo()', function () { ctx.lineTo(0, 50) @@ -138,11 +138,11 @@ bm('moveTo() / arc() / stroke()', function () { ctx.beginPath() ctx.arc(75, 75, 50, 0, Math.PI * 2, true) // Outer circle ctx.moveTo(110, 75) - ctx.arc(75, 75, 35, 0, Math.PI, false) // Mouth + ctx.arc(75, 75, 35, 0, Math.PI, false) // Mouth ctx.moveTo(65, 65) - ctx.arc(60, 65, 5, 0, Math.PI * 2, true) // Left eye + ctx.arc(60, 65, 5, 0, Math.PI * 2, true) // Left eye ctx.moveTo(95, 65) - ctx.arc(90, 65, 5, 0, Math.PI * 2, true) // Right eye + ctx.arc(90, 65, 5, 0, Math.PI * 2, true) // Right eye ctx.stroke() }) diff --git a/examples/animated_clock.js b/examples/animated_clock.js index 6e392c4dd..2e6126e8f 100644 --- a/examples/animated_clock.js +++ b/examples/animated_clock.js @@ -1,108 +1,111 @@ -var fs = require('fs'); -var Canvas = require('..'); +var Canvas = require('..') -//var backend = new Canvas.backends.FBDevBackend("/dev/fb0"); -var backend = new Canvas.backends.X11Backend(800, 600); +// var backend = new Canvas.backends.FBDevBackend("/dev/fb0"); +var backend = new Canvas.backends.X11Backend(800, 600) -var canvas = new Canvas(backend); -var ctx = canvas.getContext('2d'); +var canvas = new Canvas(backend) +var ctx = canvas.getContext('2d') -function getX(angle) { - return -Math.sin(angle + Math.PI); +function getX (angle) { + return -Math.sin(angle + Math.PI) } -function getY(angle) { - return Math.cos(angle + Math.PI); +function getY (angle) { + return Math.cos(angle + Math.PI) } -function clock(ctx) { - var now = new Date(); - ctx.clearRect(0, 0, canvas.width, canvas.height); - - ctx.save(); - ctx.translate(canvas.width / 2, canvas.height / 2); - ctx.beginPath(); - ctx.lineWidth = 14; - ctx.strokeStyle = '#325FA2'; - ctx.fillStyle = '#eeeeee'; - ctx.arc(0, 0, 142, 0, Math.PI * 2, true); - ctx.stroke(); - ctx.fill(); - - ctx.strokeStyle = '#000000'; +function clock (ctx) { + var now = new Date() + ctx.clearRect(0, 0, canvas.width, canvas.height) + + ctx.save() + ctx.translate(canvas.width / 2, canvas.height / 2) + ctx.beginPath() + ctx.lineWidth = 14 + ctx.strokeStyle = '#325FA2' + ctx.fillStyle = '#eeeeee' + ctx.arc(0, 0, 142, 0, Math.PI * 2, true) + ctx.stroke() + ctx.fill() + + ctx.strokeStyle = '#000000' // Hour marks - ctx.lineWidth = 8; + ctx.lineWidth = 8 for (var i = 0; i < 12; i++) { - var x = getX(Math.PI / 6 * i); - var y = getY(Math.PI / 6 * i); - ctx.beginPath(); - ctx.moveTo(x * 100, y * 100); - ctx.lineTo(x * 125, y * 125); - ctx.stroke(); + const x = getX(Math.PI / 6 * i) + const y = getY(Math.PI / 6 * i) + ctx.beginPath() + ctx.moveTo(x * 100, y * 100) + ctx.lineTo(x * 125, y * 125) + ctx.stroke() } // Minute marks - ctx.lineWidth = 5; + ctx.lineWidth = 5 for (i = 0; i < 60; i++) { - if (i % 5 != 0) { - var x = getX(Math.PI / 30 * i); - var y = getY(Math.PI / 30 * i); - ctx.beginPath(); - ctx.moveTo(x * 117, y * 117); - ctx.lineTo(x * 125, y * 125); - ctx.stroke(); + if (i % 5) { + const x = getX(Math.PI / 30 * i) + const y = getY(Math.PI / 30 * i) + ctx.beginPath() + ctx.moveTo(x * 117, y * 117) + ctx.lineTo(x * 125, y * 125) + ctx.stroke() } } - var sec = now.getSeconds(); - var min = now.getMinutes(); - var hr = now.getHours(); - hr = hr >= 12 ? hr - 12 : hr; + var sec = now.getSeconds() + var min = now.getMinutes() + var hr = now.getHours() + hr = hr >= 12 ? hr - 12 : hr - ctx.fillStyle = "black"; + ctx.fillStyle = 'black' // write Hours - var x = getX(hr * (Math.PI / 6) + (Math.PI / 360) * min + (Math.PI / 21600) * sec); - var y = getY(hr * (Math.PI / 6) + (Math.PI / 360) * min + (Math.PI / 21600) * sec); - ctx.lineWidth = 14; - ctx.beginPath(); - ctx.moveTo(x * -20, y * -20); - ctx.lineTo(x * 80, y * 80); - ctx.stroke(); + { + const x = getX(hr * (Math.PI / 6) + (Math.PI / 360) * min + (Math.PI / 21600) * sec) + const y = getY(hr * (Math.PI / 6) + (Math.PI / 360) * min + (Math.PI / 21600) * sec) + ctx.lineWidth = 14 + ctx.beginPath() + ctx.moveTo(x * -20, y * -20) + ctx.lineTo(x * 80, y * 80) + ctx.stroke() + } // write Minutes - var x = getX((Math.PI / 30) * min + (Math.PI / 1800) * sec); - var y = getY((Math.PI / 30) * min + (Math.PI / 1800) * sec); - - ctx.lineWidth = 10; - ctx.beginPath(); - ctx.moveTo(x * -28, y * -28); - ctx.lineTo(x * 112, y * 112); - ctx.stroke(); + { + const x = getX((Math.PI / 30) * min + (Math.PI / 1800) * sec) + const y = getY((Math.PI / 30) * min + (Math.PI / 1800) * sec) + + ctx.lineWidth = 10 + ctx.beginPath() + ctx.moveTo(x * -28, y * -28) + ctx.lineTo(x * 112, y * 112) + ctx.stroke() + } // Write seconds - var x = getX(sec * Math.PI / 30); - var y = getY(sec * Math.PI / 30); - ctx.strokeStyle = "#D40000"; - ctx.fillStyle = "#D40000"; - ctx.lineWidth = 6; - ctx.beginPath(); - ctx.moveTo(x * -30, y * -30); - ctx.lineTo(x * 83, y * 83); - ctx.stroke(); - ctx.beginPath(); - ctx.arc(0, 0, 10, 0, Math.PI * 2, true); - ctx.fill(); - ctx.beginPath(); - ctx.arc(x * 95, y * 95, 10, 0, Math.PI * 2, true); - ctx.stroke(); - ctx.fillStyle = "#555"; - ctx.arc(0, 0, 3, 0, Math.PI * 2, true); - ctx.fill(); - - ctx.restore(); + var x = getX(sec * Math.PI / 30) + var y = getY(sec * Math.PI / 30) + ctx.strokeStyle = '#D40000' + ctx.fillStyle = '#D40000' + ctx.lineWidth = 6 + ctx.beginPath() + ctx.moveTo(x * -30, y * -30) + ctx.lineTo(x * 83, y * 83) + ctx.stroke() + ctx.beginPath() + ctx.arc(0, 0, 10, 0, Math.PI * 2, true) + ctx.fill() + ctx.beginPath() + ctx.arc(x * 95, y * 95, 10, 0, Math.PI * 2, true) + ctx.stroke() + ctx.fillStyle = '#555' + ctx.arc(0, 0, 3, 0, Math.PI * 2, true) + ctx.fill() + + ctx.restore() } -setInterval(function() { - clock(ctx); -}, 1000); +setInterval(function () { + clock(ctx) +}, 1000) diff --git a/examples/simple_fbdev.js b/examples/simple_fbdev.js index d77511a4f..66f8f2906 100755 --- a/examples/simple_fbdev.js +++ b/examples/simple_fbdev.js @@ -4,34 +4,36 @@ * Module dependencies. */ -var fs = require('fs'); -var Canvas = require('..'); +const fs = require('fs') +const { join } = require('path') + +var Canvas = require('..') const squareSize = 100 -var device = process.argv[2] || "/dev/fb0" +var device = process.argv[2] || '/dev/fb0' -var backend = new Canvas.backends.FBDevBackend(device); -var canvas = new Canvas(backend); -var ctx = canvas.getContext('2d'); +var backend = new Canvas.backends.FBDevBackend(device) +var canvas = new Canvas(backend) +var ctx = canvas.getContext('2d') -var offsetX = canvas.width-squareSize -var offsetY = canvas.height-squareSize +var offsetX = canvas.width - squareSize +var offsetY = canvas.height - squareSize -ctx.fillStyle = "#FF0000"; -ctx.fillRect(0, 0, squareSize, squareSize); +ctx.fillStyle = '#FF0000' +ctx.fillRect(0, 0, squareSize, squareSize) -ctx.fillStyle = "#00FF00"; -ctx.fillRect(offsetX, 0, squareSize, squareSize); +ctx.fillStyle = '#00FF00' +ctx.fillRect(offsetX, 0, squareSize, squareSize) -ctx.fillStyle = "#0000FF"; -ctx.fillRect(0, offsetY, squareSize, squareSize); +ctx.fillStyle = '#0000FF' +ctx.fillRect(0, offsetY, squareSize, squareSize) -ctx.fillStyle = "#FFFFFF"; -ctx.fillRect(offsetX, offsetY, squareSize, squareSize); +ctx.fillStyle = '#FFFFFF' +ctx.fillRect(offsetX, offsetY, squareSize, squareSize) -console.log("Width: " + canvas.width + ", Height: " + canvas.height); +console.log('Width: ' + canvas.width + ', Height: ' + canvas.height) -var outPath = __dirname + '/rectangle.png'; +var outPath = join(__dirname, 'rectangle.png') -canvas.createPNGStream().pipe(fs.createWriteStream(outPath)); +canvas.createPNGStream().pipe(fs.createWriteStream(outPath)) diff --git a/examples/simple_x11.js b/examples/simple_x11.js index 87190d6dc..0cfe2be6d 100755 --- a/examples/simple_x11.js +++ b/examples/simple_x11.js @@ -4,19 +4,18 @@ * Module dependencies. */ -var fs = require('fs'); -var Canvas = require('..'); +var Canvas = require('..') -var backend = new Canvas.backends.X11Backend(800, 600); -var canvas = new Canvas(backend); -var ctx = canvas.getContext('2d'); +var backend = new Canvas.backends.X11Backend(800, 600) +var canvas = new Canvas(backend) +var ctx = canvas.getContext('2d') -console.log("Width: " + canvas.width + ", Height: " + canvas.height); +console.log('Width: ' + canvas.width + ', Height: ' + canvas.height) -ctx.fillStyle = "#00FF00"; -ctx.fillRect(50, 50, 100, 100); +ctx.fillStyle = '#00FF00' +ctx.fillRect(50, 50, 100, 100) -setTimeout(function(){}, 10000) +setTimeout(function () {}, 10000) -//var outPath = __dirname + '/rectangle.png'; -//canvas.createPNGStream().pipe(fs.createWriteStream(outPath)); +// var outPath = __dirname + '/rectangle.png'; +// canvas.createPNGStream().pipe(fs.createWriteStream(outPath)); diff --git a/lib/DOMMatrix.js b/lib/DOMMatrix.js index 3c5262449..cf4485395 100644 --- a/lib/DOMMatrix.js +++ b/lib/DOMMatrix.js @@ -2,7 +2,7 @@ // DOMMatrix per https://drafts.fxtf.org/geometry/#DOMMatrix -function DOMPoint(x, y, z, w) { +function DOMPoint (x, y, z, w) { if (!(this instanceof DOMPoint)) { throw new TypeError("Class constructors cannot be invoked without 'new'") } @@ -20,15 +20,15 @@ function DOMPoint(x, y, z, w) { } // Constants to index into _values (col-major) -const M11 = 0, M12 = 1, M13 = 2, M14 = 3 -const M21 = 4, M22 = 5, M23 = 6, M24 = 7 -const M31 = 8, M32 = 9, M33 = 10, M34 = 11 -const M41 = 12, M42 = 13, M43 = 14, M44 = 15 +const M11 = 0; const M12 = 1; const M13 = 2; const M14 = 3 +const M21 = 4; const M22 = 5; const M23 = 6; const M24 = 7 +const M31 = 8; const M32 = 9; const M33 = 10; const M34 = 11 +const M41 = 12; const M42 = 13; const M43 = 14; const M44 = 15 const DEGREE_PER_RAD = 180 / Math.PI const RAD_PER_DEGREE = Math.PI / 180 -function parseMatrix(init) { +function parseMatrix (init) { var parsed = init.replace(/matrix\(/, '') parsed = parsed.split(/,/, 7) // 6 + 1 to handle too many params if (parsed.length !== 6) throw new Error(`Failed to parse ${init}`) @@ -41,14 +41,14 @@ function parseMatrix(init) { ] } -function parseMatrix3d(init) { +function parseMatrix3d (init) { var parsed = init.replace(/matrix3d\(/, '') parsed = parsed.split(/,/, 17) // 16 + 1 to handle too many params if (parsed.length !== 16) throw new Error(`Failed to parse ${init}`) return parsed.map(parseFloat) } -function parseTransform(tform) { +function parseTransform (tform) { var type = tform.split(/\(/, 1)[0] switch (type) { case 'matrix': @@ -158,15 +158,15 @@ DOMMatrix.prototype.inspect = function (depth, options) { } DOMMatrix.prototype.toString = function () { - return this.is2D ? - `matrix(${this.a}, ${this.b}, ${this.c}, ${this.d}, ${this.e}, ${this.f})` : - `matrix3d(${this._values.join(', ')})` + return this.is2D + ? `matrix(${this.a}, ${this.b}, ${this.c}, ${this.d}, ${this.e}, ${this.f})` + : `matrix3d(${this._values.join(', ')})` } /** * Checks that `value` is a number and sets the value. */ -function setNumber2D(receiver, index, value) { +function setNumber2D (receiver, index, value) { if (typeof value !== 'number') throw new TypeError('Expected number') return receiver._values[index] = value } @@ -175,7 +175,7 @@ function setNumber2D(receiver, index, value) { * Checks that `value` is a number, sets `_is2D = false` if necessary and sets * the value. */ -function setNumber3D(receiver, index, value) { +function setNumber3D (receiver, index, value) { if (typeof value !== 'number') throw new TypeError('Expected number') if (index === M33 || index === M44) { if (value !== 1) receiver._is2D = false @@ -184,31 +184,31 @@ function setNumber3D(receiver, index, value) { } Object.defineProperties(DOMMatrix.prototype, { - m11: {get: function () { return this._values[M11] }, set: function (v) { return setNumber2D(this, M11, v) }}, - m12: {get: function () { return this._values[M12] }, set: function (v) { return setNumber2D(this, M12, v) }}, - m13: {get: function () { return this._values[M13] }, set: function (v) { return setNumber3D(this, M13, v) }}, - m14: {get: function () { return this._values[M14] }, set: function (v) { return setNumber3D(this, M14, v) }}, - m21: {get: function () { return this._values[M21] }, set: function (v) { return setNumber2D(this, M21, v) }}, - m22: {get: function () { return this._values[M22] }, set: function (v) { return setNumber2D(this, M22, v) }}, - m23: {get: function () { return this._values[M23] }, set: function (v) { return setNumber3D(this, M23, v) }}, - m24: {get: function () { return this._values[M24] }, set: function (v) { return setNumber3D(this, M24, v) }}, - m31: {get: function () { return this._values[M31] }, set: function (v) { return setNumber3D(this, M31, v) }}, - m32: {get: function () { return this._values[M32] }, set: function (v) { return setNumber3D(this, M32, v) }}, - m33: {get: function () { return this._values[M33] }, set: function (v) { return setNumber3D(this, M33, v) }}, - m34: {get: function () { return this._values[M34] }, set: function (v) { return setNumber3D(this, M34, v) }}, - m41: {get: function () { return this._values[M41] }, set: function (v) { return setNumber2D(this, M41, v) }}, - m42: {get: function () { return this._values[M42] }, set: function (v) { return setNumber2D(this, M42, v) }}, - m43: {get: function () { return this._values[M43] }, set: function (v) { return setNumber3D(this, M43, v) }}, - m44: {get: function () { return this._values[M44] }, set: function (v) { return setNumber3D(this, M44, v) }}, - - a: {get: function () { return this.m11 }, set: function (v) { return this.m11 = v }}, - b: {get: function () { return this.m12 }, set: function (v) { return this.m12 = v }}, - c: {get: function () { return this.m21 }, set: function (v) { return this.m21 = v }}, - d: {get: function () { return this.m22 }, set: function (v) { return this.m22 = v }}, - e: {get: function () { return this.m41 }, set: function (v) { return this.m41 = v }}, - f: {get: function () { return this.m42 }, set: function (v) { return this.m42 = v }}, - - is2D: {get: function () { return this._is2D }}, // read-only + m11: { get: function () { return this._values[M11] }, set: function (v) { return setNumber2D(this, M11, v) } }, + m12: { get: function () { return this._values[M12] }, set: function (v) { return setNumber2D(this, M12, v) } }, + m13: { get: function () { return this._values[M13] }, set: function (v) { return setNumber3D(this, M13, v) } }, + m14: { get: function () { return this._values[M14] }, set: function (v) { return setNumber3D(this, M14, v) } }, + m21: { get: function () { return this._values[M21] }, set: function (v) { return setNumber2D(this, M21, v) } }, + m22: { get: function () { return this._values[M22] }, set: function (v) { return setNumber2D(this, M22, v) } }, + m23: { get: function () { return this._values[M23] }, set: function (v) { return setNumber3D(this, M23, v) } }, + m24: { get: function () { return this._values[M24] }, set: function (v) { return setNumber3D(this, M24, v) } }, + m31: { get: function () { return this._values[M31] }, set: function (v) { return setNumber3D(this, M31, v) } }, + m32: { get: function () { return this._values[M32] }, set: function (v) { return setNumber3D(this, M32, v) } }, + m33: { get: function () { return this._values[M33] }, set: function (v) { return setNumber3D(this, M33, v) } }, + m34: { get: function () { return this._values[M34] }, set: function (v) { return setNumber3D(this, M34, v) } }, + m41: { get: function () { return this._values[M41] }, set: function (v) { return setNumber2D(this, M41, v) } }, + m42: { get: function () { return this._values[M42] }, set: function (v) { return setNumber2D(this, M42, v) } }, + m43: { get: function () { return this._values[M43] }, set: function (v) { return setNumber3D(this, M43, v) } }, + m44: { get: function () { return this._values[M44] }, set: function (v) { return setNumber3D(this, M44, v) } }, + + a: { get: function () { return this.m11 }, set: function (v) { return this.m11 = v } }, + b: { get: function () { return this.m12 }, set: function (v) { return this.m12 = v } }, + c: { get: function () { return this.m21 }, set: function (v) { return this.m21 = v } }, + d: { get: function () { return this.m22 }, set: function (v) { return this.m22 = v } }, + e: { get: function () { return this.m41 }, set: function (v) { return this.m41 = v } }, + f: { get: function () { return this.m42 }, set: function (v) { return this.m42 = v } }, + + is2D: { get: function () { return this._is2D } }, // read-only isIdentity: { get: function () { @@ -226,7 +226,7 @@ Object.defineProperties(DOMMatrix.prototype, { * @param {Float64Array} values Value to assign to `_values`. This is assigned * without copying (okay because all usages are followed by a multiply). */ -function newInstance(values) { +function newInstance (values) { var instance = Object.create(DOMMatrix.prototype) instance.constructor = DOMMatrix instance._is2D = true @@ -234,7 +234,7 @@ function newInstance(values) { return instance } -function multiply(A, B) { +function multiply (A, B) { var dest = new Float64Array(16) for (var i = 0; i < 4; i++) { for (var j = 0; j < 4; j++) { @@ -383,10 +383,10 @@ DOMMatrix.prototype.rotateAxisAngleSelf = function (x, y, z, angle) { // NB: This is the generic transform. If the axis is a major axis, there are // faster transforms. this._values = multiply([ - tx * x + c, tx * y + s * z, tx * z - s * y, 0, - tx * y - s * z, ty * y + c, ty * z + s * x, 0, - tx * z + s * y, ty * z - s * x, t * z * z + c, 0, - 0, 0, 0, 1 + tx * x + c, tx * y + s * z, tx * z - s * y, 0, + tx * y - s * z, ty * y + c, ty * z + s * x, 0, + tx * z + s * y, ty * z - s * x, t * z * z + c, 0, + 0, 0, 0, 1 ], this._values) if (x !== 0 || y !== 0) this._is2D = false return this @@ -422,7 +422,7 @@ DOMMatrix.prototype.skewYSelf = function (sy) { return this } -DOMMatrix.prototype.flipX = function () { +DOMMatrix.prototype.flipX = function () { return newInstance(multiply([ -1, 0, 0, 0, 0, 1, 0, 0, @@ -468,12 +468,12 @@ DOMMatrix.prototype.transformPoint = function (point) { return new DOMPoint(nx, ny, nz, nw) } -DOMMatrix.prototype.toFloat32Array = function () { +DOMMatrix.prototype.toFloat32Array = function () { return Float32Array.from(this._values) } -DOMMatrix.prototype.toFloat64Array = function () { +DOMMatrix.prototype.toFloat64Array = function () { return this._values.slice(0) } -module.exports = {DOMMatrix, DOMPoint} +module.exports = { DOMMatrix, DOMPoint } diff --git a/lib/bindings.js b/lib/bindings.js index c0afc9841..95ee914f3 100644 --- a/lib/bindings.js +++ b/lib/bindings.js @@ -1,3 +1,3 @@ -'use strict'; +'use strict' -module.exports = require('../build/Release/canvas.node'); +module.exports = require('../build/Release/canvas.node') diff --git a/lib/canvas.js b/lib/canvas.js index ec16b92ea..72a729366 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict' /*! * Canvas @@ -25,9 +25,9 @@ const FORMATS = ['image/png', 'image/jpeg'] * @api public */ -Canvas.prototype.inspect = function(){ - return '[Canvas ' + this.width + 'x' + this.height + ']'; -}; +Canvas.prototype.inspect = function () { + return '[Canvas ' + this.width + 'x' + this.height + ']' +} /** * Get a context object. @@ -39,13 +39,13 @@ Canvas.prototype.inspect = function(){ */ Canvas.prototype.getContext = function (contextType, contextAttributes) { - if ('2d' == contextType) { - var ctx = this._context2d || (this._context2d = new Context2d(this, contextAttributes)); - this.context = ctx; - ctx.canvas = this; - return ctx; + if (contextType == '2d') { + var ctx = this._context2d || (this._context2d = new Context2d(this, contextAttributes)) + this.context = ctx + ctx.canvas = this + return ctx } -}; +} /** * Create a `PNGStream` for `this` canvas. @@ -66,9 +66,9 @@ Canvas.prototype.getContext = function (contextType, contextAttributes) { * @public */ Canvas.prototype.pngStream = -Canvas.prototype.createPNGStream = function(options){ - return new PNGStream(this, options); -}; +Canvas.prototype.createPNGStream = function (options) { + return new PNGStream(this, options) +} /** * Create a `PDFStream` for `this` canvas. @@ -77,9 +77,9 @@ Canvas.prototype.createPNGStream = function(options){ * @public */ Canvas.prototype.pdfStream = -Canvas.prototype.createPDFStream = function(){ - return new PDFStream(this); -}; +Canvas.prototype.createPDFStream = function () { + return new PDFStream(this) +} /** * Create a `JPEGStream` for `this` canvas. @@ -94,9 +94,9 @@ Canvas.prototype.createPDFStream = function(){ * @public */ Canvas.prototype.jpegStream = -Canvas.prototype.createJPEGStream = function(options){ - return new JPEGStream(this, options); -}; +Canvas.prototype.createJPEGStream = function (options) { + return new JPEGStream(this, options) +} /** * Returns a data URI. Pass a function for async operation (non-standard). @@ -110,7 +110,7 @@ Canvas.prototype.createJPEGStream = function(options){ * @return {String} data URL if synchronous (callback omitted) * @api public */ -Canvas.prototype.toDataURL = function(a1, a2, a3){ +Canvas.prototype.toDataURL = function (a1, a2, a3) { // valid arg patterns (args -> [type, opts, fn]): // [] -> ['image/png', null, null] // [qual] -> ['image/png', null, null] @@ -129,51 +129,51 @@ Canvas.prototype.toDataURL = function(a1, a2, a3){ // ['image/jpeg', opts] -> ['image/jpeg', opts, fn] // ['image/jpeg', qual] -> ['image/jpeg', {quality: qual}, fn] - var type = 'image/png'; - var opts = {}; - var fn; + var type = 'image/png' + var opts = {} + var fn - if ('function' === typeof a1) { - fn = a1; + if (typeof a1 === 'function') { + fn = a1 } else { - if ('string' === typeof a1 && FORMATS.includes(a1.toLowerCase())) { - type = a1.toLowerCase(); + if (typeof a1 === 'string' && FORMATS.includes(a1.toLowerCase())) { + type = a1.toLowerCase() } - if ('function' === typeof a2) { - fn = a2; + if (typeof a2 === 'function') { + fn = a2 } else { - if ('object' === typeof a2) { - opts = a2; - } else if ('number' === typeof a2) { - opts = {quality: Math.max(0, Math.min(1, a2))}; + if (typeof a2 === 'object') { + opts = a2 + } else if (typeof a2 === 'number') { + opts = { quality: Math.max(0, Math.min(1, a2)) } } - if ('function' === typeof a3) { - fn = a3; + if (typeof a3 === 'function') { + fn = a3 } else if (undefined !== a3) { - throw new TypeError(typeof a3 + ' is not a function'); + throw new TypeError(typeof a3 + ' is not a function') } } } if (this.width === 0 || this.height === 0) { // Per spec, if the bitmap has no pixels, return this string: - var str = "data:,"; + var str = 'data:,' if (fn) { - setTimeout(() => fn(null, str)); - return; + setTimeout(() => fn(null, str)) + return } else { - return str; + return str } } if (fn) { this.toBuffer((err, buf) => { - if (err) return fn(err); - fn(null, `data:${type};base64,${buf.toString('base64')}`); + if (err) return fn(err) + fn(null, `data:${type};base64,${buf.toString('base64')}`) }, type, opts) } else { return `data:${type};base64,${this.toBuffer(type).toString('base64')}` } -}; +} diff --git a/lib/context2d.js b/lib/context2d.js index b9c28e6ea..b5237593c 100644 --- a/lib/context2d.js +++ b/lib/context2d.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict' /*! * Canvas - Context2d @@ -22,7 +22,7 @@ const DOMMatrix = require('./DOMMatrix').DOMMatrix * Text baselines. */ -var baselines = ['alphabetic', 'top', 'bottom', 'middle', 'ideographic', 'hanging']; +var baselines = ['alphabetic', 'top', 'bottom', 'middle', 'ideographic', 'hanging'] /** * Create a pattern from `Image` or `Canvas`. @@ -33,9 +33,9 @@ var baselines = ['alphabetic', 'top', 'bottom', 'middle', 'ideographic', 'hangin * @api public */ -Context2d.prototype.createPattern = function(image, repetition){ - return new CanvasPattern(image, repetition || 'repeat'); -}; +Context2d.prototype.createPattern = function (image, repetition) { + return new CanvasPattern(image, repetition || 'repeat') +} /** * Create a linear gradient at the given point `(x0, y0)` and `(x1, y1)`. @@ -48,9 +48,9 @@ Context2d.prototype.createPattern = function(image, repetition){ * @api public */ -Context2d.prototype.createLinearGradient = function(x0, y0, x1, y1){ - return new CanvasGradient(x0, y0, x1, y1); -}; +Context2d.prototype.createLinearGradient = function (x0, y0, x1, y1) { + return new CanvasGradient(x0, y0, x1, y1) +} /** * Create a radial gradient at the given point `(x0, y0)` and `(x1, y1)` @@ -66,9 +66,9 @@ Context2d.prototype.createLinearGradient = function(x0, y0, x1, y1){ * @api public */ -Context2d.prototype.createRadialGradient = function(x0, y0, r0, x1, y1, r1){ - return new CanvasGradient(x0, y0, r0, x1, y1, r1); -}; +Context2d.prototype.createRadialGradient = function (x0, y0, r0, x1, y1, r1) { + return new CanvasGradient(x0, y0, r0, x1, y1, r1) +} /** * Reset transform matrix to identity, then apply the given args. @@ -77,10 +77,10 @@ Context2d.prototype.createRadialGradient = function(x0, y0, r0, x1, y1, r1){ * @api public */ -Context2d.prototype.setTransform = function(){ - this.resetTransform(); - this.transform.apply(this, arguments); -}; +Context2d.prototype.setTransform = function () { + this.resetTransform() + this.transform.apply(this, arguments) +} Object.defineProperty(Context2d.prototype, 'currentTransform', { get: function () { @@ -103,16 +103,16 @@ Object.defineProperty(Context2d.prototype, 'currentTransform', { * @api public */ -Context2d.prototype.__defineSetter__('fillStyle', function(val){ - if (val instanceof CanvasGradient - || val instanceof CanvasPattern) { - this.lastFillStyle = val; - this._setFillPattern(val); +Context2d.prototype.__defineSetter__('fillStyle', function (val) { + if (val instanceof CanvasGradient || + val instanceof CanvasPattern) { + this.lastFillStyle = val + this._setFillPattern(val) } else { - this.lastFillStyle = undefined; - this._setFillColor(String(val)); + this.lastFillStyle = undefined + this._setFillColor(String(val)) } -}); +}) /** * Get previous fill style. @@ -121,9 +121,9 @@ Context2d.prototype.__defineSetter__('fillStyle', function(val){ * @api public */ -Context2d.prototype.__defineGetter__('fillStyle', function(){ - return this.lastFillStyle || this.fillColor; -}); +Context2d.prototype.__defineGetter__('fillStyle', function () { + return this.lastFillStyle || this.fillColor +}) /** * Set the stroke style with the given css color string. @@ -131,15 +131,15 @@ Context2d.prototype.__defineGetter__('fillStyle', function(){ * @api public */ -Context2d.prototype.__defineSetter__('strokeStyle', function(val){ - if (val instanceof CanvasGradient - || val instanceof CanvasPattern) { - this.lastStrokeStyle = val; - this._setStrokePattern(val); +Context2d.prototype.__defineSetter__('strokeStyle', function (val) { + if (val instanceof CanvasGradient || + val instanceof CanvasPattern) { + this.lastStrokeStyle = val + this._setStrokePattern(val) } else { - this._setStrokeColor(String(val)); + this._setStrokeColor(String(val)) } -}); +}) /** * Get previous stroke style. @@ -148,9 +148,9 @@ Context2d.prototype.__defineSetter__('strokeStyle', function(val){ * @api public */ -Context2d.prototype.__defineGetter__('strokeStyle', function(){ - return this.lastStrokeStyle || this.strokeColor; -}); +Context2d.prototype.__defineGetter__('strokeStyle', function () { + return this.lastStrokeStyle || this.strokeColor +}) /** * Set font. @@ -159,21 +159,21 @@ Context2d.prototype.__defineGetter__('strokeStyle', function(){ * @api public */ -Context2d.prototype.__defineSetter__('font', function(val){ - if (!val) return; - if ('string' == typeof val) { - var font; +Context2d.prototype.__defineSetter__('font', function (val) { + if (!val) return + if (typeof val === 'string') { + var font if (font = parseFont(val)) { - this.lastFontString = val; + this.lastFontString = val this._setFont( - font.weight + font.weight , font.style , font.size , font.unit - , font.family); + , font.family) } } -}); +}) /** * Get the current font. @@ -181,9 +181,9 @@ Context2d.prototype.__defineSetter__('font', function(val){ * @api public */ -Context2d.prototype.__defineGetter__('font', function(){ - return this.lastFontString || '10px sans-serif'; -}); +Context2d.prototype.__defineGetter__('font', function () { + return this.lastFontString || '10px sans-serif' +}) /** * Set text baseline. @@ -191,14 +191,14 @@ Context2d.prototype.__defineGetter__('font', function(){ * @api public */ -Context2d.prototype.__defineSetter__('textBaseline', function(val){ - if (!val) return; - var n = baselines.indexOf(val); +Context2d.prototype.__defineSetter__('textBaseline', function (val) { + if (!val) return + var n = baselines.indexOf(val) if (~n) { - this.lastBaseline = val; - this._setTextBaseline(n); + this.lastBaseline = val + this._setTextBaseline(n) } -}); +}) /** * Get the current baseline setting. @@ -206,9 +206,9 @@ Context2d.prototype.__defineSetter__('textBaseline', function(val){ * @api public */ -Context2d.prototype.__defineGetter__('textBaseline', function(){ - return this.lastBaseline || 'alphabetic'; -}); +Context2d.prototype.__defineGetter__('textBaseline', function () { + return this.lastBaseline || 'alphabetic' +}) /** * Set text alignment. @@ -216,24 +216,24 @@ Context2d.prototype.__defineGetter__('textBaseline', function(){ * @api public */ -Context2d.prototype.__defineSetter__('textAlign', function(val){ +Context2d.prototype.__defineSetter__('textAlign', function (val) { switch (val) { case 'center': - this._setTextAlignment(0); - this.lastTextAlignment = val; - break; + this._setTextAlignment(0) + this.lastTextAlignment = val + break case 'left': case 'start': - this._setTextAlignment(-1); - this.lastTextAlignment = val; - break; + this._setTextAlignment(-1) + this.lastTextAlignment = val + break case 'right': case 'end': - this._setTextAlignment(1); - this.lastTextAlignment = val; - break; + this._setTextAlignment(1) + this.lastTextAlignment = val + break } -}); +}) /** * Get the current font. @@ -242,9 +242,9 @@ Context2d.prototype.__defineSetter__('textAlign', function(val){ * @api public */ -Context2d.prototype.__defineGetter__('textAlign', function(){ - return this.lastTextAlignment || 'start'; -}); +Context2d.prototype.__defineGetter__('textAlign', function () { + return this.lastTextAlignment || 'start' +}) /** * Create `ImageData` with the given dimensions or @@ -261,13 +261,13 @@ Context2d.prototype.createImageData = function (width, height) { height = width.height width = width.width } - var Bpp = this.canvas.stride / this.canvas.width; + var Bpp = this.canvas.stride / this.canvas.width var nBytes = Bpp * width * height - var arr; - if (this.pixelFormat === "RGB16_565") { - arr = new Uint16Array(nBytes / 2); + var arr + if (this.pixelFormat === 'RGB16_565') { + arr = new Uint16Array(nBytes / 2) } else { - arr = new Uint8ClampedArray(nBytes); + arr = new Uint8ClampedArray(nBytes) } - return new ImageData(arr, width, height); + return new ImageData(arr, width, height) } diff --git a/lib/image.js b/lib/image.js index ff84f2b24..a64b7796d 100644 --- a/lib/image.js +++ b/lib/image.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict' /*! * Canvas - Image @@ -12,15 +12,15 @@ const bindings = require('./bindings') const Image = module.exports = bindings.Image -const http = require("http") -const https = require("https") +const http = require('http') +const https = require('https') -const proto = Image.prototype; -const _getSource = proto.getSource; -const _setSource = proto.setSource; +const proto = Image.prototype +const _getSource = proto.getSource +const _setSource = proto.setSource -delete proto.getSource; -delete proto.setSource; +delete proto.getSource +delete proto.setSource Object.defineProperty(Image.prototype, 'src', { /** @@ -33,14 +33,14 @@ Object.defineProperty(Image.prototype, 'src', { * @param {String|Buffer} val filename, buffer, data URI, URL * @api public */ - set(val) { + set (val) { if (typeof val === 'string') { if (/^\s*data:/.test(val)) { // data: URI const commaI = val.indexOf(',') // 'base64' must come before the comma const isBase64 = val.lastIndexOf('base64', commaI) !== -1 const content = val.slice(commaI + 1) - setSource(this, Buffer.from(content, isBase64 ? 'base64' : 'utf8'), val); + setSource(this, Buffer.from(content, isBase64 ? 'base64' : 'utf8'), val) } else if (/^\s*https?:\/\//.test(val)) { // remote URL const onerror = err => { if (typeof this.onerror === 'function') { @@ -58,24 +58,24 @@ Object.defineProperty(Image.prototype, 'src', { const buffers = [] res.on('data', buffer => buffers.push(buffer)) res.on('end', () => { - setSource(this, Buffer.concat(buffers)); + setSource(this, Buffer.concat(buffers)) }) }).on('error', onerror) } else { // local file path assumed - setSource(this, val); + setSource(this, val) } } else if (Buffer.isBuffer(val)) { - setSource(this, val); + setSource(this, val) } }, - get() { + get () { // TODO https://github.com/Automattic/node-canvas/issues/118 - return getSource(this); + return getSource(this) }, configurable: true -}); +}) /** * Inspect image. @@ -86,19 +86,19 @@ Object.defineProperty(Image.prototype, 'src', { * @api public */ -Image.prototype.inspect = function(){ - return '[Image' - + (this.complete ? ':' + this.width + 'x' + this.height : '') - + (this.src ? ' ' + this.src : '') - + (this.complete ? ' complete' : '') - + ']'; -}; +Image.prototype.inspect = function () { + return '[Image' + + (this.complete ? ':' + this.width + 'x' + this.height : '') + + (this.src ? ' ' + this.src : '') + + (this.complete ? ' complete' : '') + + ']' +} -function getSource(img){ - return img._originalSource || _getSource.call(img); +function getSource (img) { + return img._originalSource || _getSource.call(img) } -function setSource(img, src, origSrc){ - _setSource.call(img, src); - img._originalSource = origSrc; +function setSource (img, src, origSrc) { + _setSource.call(img, src) + img._originalSource = origSrc } diff --git a/lib/jpegstream.js b/lib/jpegstream.js index e44ed4c65..92c5df80b 100644 --- a/lib/jpegstream.js +++ b/lib/jpegstream.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict' /*! * Canvas - JPEGStream @@ -10,8 +10,8 @@ * Module dependencies. */ -var Readable = require('stream').Readable; -var util = require('util'); +var Readable = require('stream').Readable +var util = require('util') /** * Initialize a `JPEGStream` with the given `canvas`. @@ -29,37 +29,37 @@ var util = require('util'); * @private */ -var JPEGStream = module.exports = function JPEGStream(canvas, options) { +var JPEGStream = module.exports = function JPEGStream (canvas, options) { if (!(this instanceof JPEGStream)) { - throw new TypeError("Class constructors cannot be invoked without 'new'"); + throw new TypeError("Class constructors cannot be invoked without 'new'") } if (canvas.streamJPEGSync === undefined) { - throw new Error("node-canvas was built without JPEG support."); + throw new Error('node-canvas was built without JPEG support.') } - Readable.call(this); + Readable.call(this) - this.options = options; - this.canvas = canvas; -}; + this.options = options + this.canvas = canvas +} -util.inherits(JPEGStream, Readable); +util.inherits(JPEGStream, Readable) -function noop() {} +function noop () {} -JPEGStream.prototype._read = function _read() { +JPEGStream.prototype._read = function _read () { // For now we're not controlling the c++ code's data emission, so we only // call canvas.streamJPEGSync once and let it emit data at will. - this._read = noop; - var self = this; - self.canvas.streamJPEGSync(this.options, function(err, chunk){ + this._read = noop + var self = this + self.canvas.streamJPEGSync(this.options, function (err, chunk) { if (err) { - self.emit('error', err); + self.emit('error', err) } else if (chunk) { - self.push(chunk); + self.push(chunk) } else { - self.push(null); + self.push(null) } - }); -}; + }) +} diff --git a/lib/parse-font.js b/lib/parse-font.js index a149c709c..8fb9551a7 100644 --- a/lib/parse-font.js +++ b/lib/parse-font.js @@ -5,11 +5,16 @@ */ const weights = 'bold|bolder|lighter|[1-9]00' - , styles = 'italic|oblique' - , variants = 'small-caps' - , stretches = 'ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded' - , units = 'px|pt|pc|in|cm|mm|%|em|ex|ch|rem|q' - , string = '\'([^\']+)\'|"([^"]+)"|[\\w\\s-]+' + +const styles = 'italic|oblique' + +const variants = 'small-caps' + +const stretches = 'ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded' + +const units = 'px|pt|pc|in|cm|mm|%|em|ex|ch|rem|q' + +const string = '\'([^\']+)\'|"([^"]+)"|[\\w\\s-]+' // [ [ <‘font-style’> || || <‘font-weight’> || <‘font-stretch’> ]? // <‘font-size’> [ / <‘line-height’> ]? <‘font-family’> ] @@ -19,8 +24,8 @@ const styleRe = new RegExp(`(${styles}) +`, 'i') const variantRe = new RegExp(`(${variants}) +`, 'i') const stretchRe = new RegExp(`(${stretches}) +`, 'i') const sizeFamilyRe = new RegExp( - '([\\d\\.]+)(' + units + ') *' - + '((?:' + string + ')( *, *(?:' + string + '))*)') + '([\\d\\.]+)(' + units + ') *' + + '((?:' + string + ')( *, *(?:' + string + '))*)') /** * Cache font parsing. diff --git a/lib/pdfstream.js b/lib/pdfstream.js index 837a034c3..b056c6e47 100644 --- a/lib/pdfstream.js +++ b/lib/pdfstream.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict' /*! * Canvas - PDFStream @@ -8,8 +8,8 @@ * Module dependencies. */ -var Readable = require('stream').Readable; -var util = require('util'); +var Readable = require('stream').Readable +var util = require('util') /** * Initialize a `PDFStream` with the given `canvas`. @@ -27,32 +27,32 @@ var util = require('util'); * @api public */ -var PDFStream = module.exports = function PDFStream(canvas) { +var PDFStream = module.exports = function PDFStream (canvas) { if (!(this instanceof PDFStream)) { - throw new TypeError("Class constructors cannot be invoked without 'new'"); + throw new TypeError("Class constructors cannot be invoked without 'new'") } - Readable.call(this); + Readable.call(this) - this.canvas = canvas; -}; + this.canvas = canvas +} -util.inherits(PDFStream, Readable); +util.inherits(PDFStream, Readable) -function noop() {} +function noop () {} -PDFStream.prototype._read = function _read() { +PDFStream.prototype._read = function _read () { // For now we're not controlling the c++ code's data emission, so we only // call canvas.streamPDFSync once and let it emit data at will. - this._read = noop; - var self = this; - self.canvas.streamPDFSync(function(err, chunk, len){ + this._read = noop + var self = this + self.canvas.streamPDFSync(function (err, chunk, len) { if (err) { - self.emit('error', err); + self.emit('error', err) } else if (len) { - self.push(chunk); + self.push(chunk) } else { - self.push(null); + self.push(null) } - }); -}; + }) +} diff --git a/lib/pngstream.js b/lib/pngstream.js index 3a03c78c7..7fac31129 100644 --- a/lib/pngstream.js +++ b/lib/pngstream.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict' /*! * Canvas - PNGStream @@ -10,46 +10,46 @@ * Module dependencies. */ -var Readable = require('stream').Readable; -var util = require('util'); +var Readable = require('stream').Readable +var util = require('util') /** * @param {Canvas} canvas * @param {Object} options * @private */ -var PNGStream = module.exports = function PNGStream(canvas, options) { +var PNGStream = module.exports = function PNGStream (canvas, options) { if (!(this instanceof PNGStream)) { - throw new TypeError("Class constructors cannot be invoked without 'new'"); + throw new TypeError("Class constructors cannot be invoked without 'new'") } - Readable.call(this); + Readable.call(this) if (options && options.palette instanceof Uint8ClampedArray && options.palette.length % 4 !== 0) { - throw new Error("Palette length must be a multiple of 4."); + throw new Error('Palette length must be a multiple of 4.') } - this.canvas = canvas; - this.options = options || {}; -}; + this.canvas = canvas + this.options = options || {} +} -util.inherits(PNGStream, Readable); +util.inherits(PNGStream, Readable) -function noop() {} +function noop () {} -PNGStream.prototype._read = function _read() { +PNGStream.prototype._read = function _read () { // For now we're not controlling the c++ code's data emission, so we only // call canvas.streamPNGSync once and let it emit data at will. - this._read = noop; - var self = this; - self.canvas.streamPNGSync(function(err, chunk, len){ + this._read = noop + var self = this + self.canvas.streamPNGSync(function (err, chunk, len) { if (err) { - self.emit('error', err); + self.emit('error', err) } else if (len) { - self.push(chunk); + self.push(chunk) } else { - self.push(null); + self.push(null) } - }, self.options); -}; + }, self.options) +} diff --git a/test/canvas.test.js b/test/canvas.test.js index 77e012648..3239d1b85 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -18,136 +18,140 @@ const Readable = require('stream').Readable describe('Canvas', function () { it('Prototype and ctor are well-shaped, don\'t hit asserts on accessors (GH-803)', function () { - const Canvas = require('../').Canvas; - var c = new Canvas(10, 10); - assert.throws(function () { Canvas.prototype.width; }, /incompatible receiver/); - assert(!c.hasOwnProperty('width')); - assert('width' in c); - assert(Canvas.prototype.hasOwnProperty('width')); - }); + const Canvas = require('../').Canvas + var c = new Canvas(10, 10) + assert.throws(function () { Canvas.prototype.width }, /incompatible receiver/) + assert(!c.hasOwnProperty('width')) + assert('width' in c) + assert(Canvas.prototype.hasOwnProperty('width')) + }) it('.parseFont()', function () { var tests = [ - '20px Arial' - , { size: 20, unit: 'px', family: 'Arial' } - , '20pt Arial' - , { size: 26.666666666666668, unit: 'pt', family: 'Arial' } - , '20.5pt Arial' - , { size: 27.333333333333332, unit: 'pt', family: 'Arial' } - , '20% Arial' - , { size: 20, unit: '%', family: 'Arial' } // TODO I think this is a bad assertion - ZB 23-Jul-2017 - , '20mm Arial' - , { size: 75.59055118110237, unit: 'mm', family: 'Arial' } - , '20px serif' - , { size: 20, unit: 'px', family: 'serif' } - , '20px sans-serif' - , { size: 20, unit: 'px', family: 'sans-serif' } - , '20px monospace' - , { size: 20, unit: 'px', family: 'monospace' } - , '50px Arial, sans-serif' - , { size: 50, unit: 'px', family: 'Arial,sans-serif' } - , 'bold italic 50px Arial, sans-serif' - , { style: 'italic', weight: 'bold', size: 50, unit: 'px', family: 'Arial,sans-serif' } - , '50px Helvetica , Arial, sans-serif' - , { size: 50, unit: 'px', family: 'Helvetica,Arial,sans-serif' } - , '50px "Helvetica Neue", sans-serif' - , { size: 50, unit: 'px', family: 'Helvetica Neue,sans-serif' } - , '50px "Helvetica Neue", "foo bar baz" , sans-serif' - , { size: 50, unit: 'px', family: 'Helvetica Neue,foo bar baz,sans-serif' } - , "50px 'Helvetica Neue'" - , { size: 50, unit: 'px', family: 'Helvetica Neue' } - , 'italic 20px Arial' - , { size: 20, unit: 'px', style: 'italic', family: 'Arial' } - , 'oblique 20px Arial' - , { size: 20, unit: 'px', style: 'oblique', family: 'Arial' } - , 'normal 20px Arial' - , { size: 20, unit: 'px', style: 'normal', family: 'Arial' } - , '300 20px Arial' - , { size: 20, unit: 'px', weight: '300', family: 'Arial' } - , '800 20px Arial' - , { size: 20, unit: 'px', weight: '800', family: 'Arial' } - , 'bolder 20px Arial' - , { size: 20, unit: 'px', weight: 'bolder', family: 'Arial' } - , 'lighter 20px Arial' - , { size: 20, unit: 'px', weight: 'lighter', family: 'Arial' } - , 'normal normal normal 16px Impact' - , { size: 16, unit: 'px', weight: 'normal', family: 'Impact', style: 'normal', variant: 'normal' } - , 'italic small-caps bolder 16px cursive' - , { size: 16, unit: 'px', style: 'italic', variant: 'small-caps', weight: 'bolder', family: 'cursive' } - , '20px "new century schoolbook", serif' - , { size: 20, unit: 'px', family: 'new century schoolbook,serif' } - , '20px "Arial bold 300"' // synthetic case with weight keyword inside family - , { size: 20, unit: 'px', family: 'Arial bold 300', variant: 'normal' } - ]; + '20px Arial', + { size: 20, unit: 'px', family: 'Arial' }, + '20pt Arial', + { size: 26.666666666666668, unit: 'pt', family: 'Arial' }, + '20.5pt Arial', + { size: 27.333333333333332, unit: 'pt', family: 'Arial' }, + '20% Arial', + { size: 20, unit: '%', family: 'Arial' }, // TODO I think this is a bad assertion - ZB 23-Jul-2017 + '20mm Arial', + { size: 75.59055118110237, unit: 'mm', family: 'Arial' }, + '20px serif', + { size: 20, unit: 'px', family: 'serif' }, + '20px sans-serif', + { size: 20, unit: 'px', family: 'sans-serif' }, + '20px monospace', + { size: 20, unit: 'px', family: 'monospace' }, + '50px Arial, sans-serif', + { size: 50, unit: 'px', family: 'Arial,sans-serif' }, + 'bold italic 50px Arial, sans-serif', + { style: 'italic', weight: 'bold', size: 50, unit: 'px', family: 'Arial,sans-serif' }, + '50px Helvetica , Arial, sans-serif', + { size: 50, unit: 'px', family: 'Helvetica,Arial,sans-serif' }, + '50px "Helvetica Neue", sans-serif', + { size: 50, unit: 'px', family: 'Helvetica Neue,sans-serif' }, + '50px "Helvetica Neue", "foo bar baz" , sans-serif', + { size: 50, unit: 'px', family: 'Helvetica Neue,foo bar baz,sans-serif' }, + "50px 'Helvetica Neue'", + { size: 50, unit: 'px', family: 'Helvetica Neue' }, + 'italic 20px Arial', + { size: 20, unit: 'px', style: 'italic', family: 'Arial' }, + 'oblique 20px Arial', + { size: 20, unit: 'px', style: 'oblique', family: 'Arial' }, + 'normal 20px Arial', + { size: 20, unit: 'px', style: 'normal', family: 'Arial' }, + '300 20px Arial', + { size: 20, unit: 'px', weight: '300', family: 'Arial' }, + '800 20px Arial', + { size: 20, unit: 'px', weight: '800', family: 'Arial' }, + 'bolder 20px Arial', + { size: 20, unit: 'px', weight: 'bolder', family: 'Arial' }, + 'lighter 20px Arial', + { size: 20, unit: 'px', weight: 'lighter', family: 'Arial' }, + 'normal normal normal 16px Impact', + { size: 16, unit: 'px', weight: 'normal', family: 'Impact', style: 'normal', variant: 'normal' }, + 'italic small-caps bolder 16px cursive', + { size: 16, unit: 'px', style: 'italic', variant: 'small-caps', weight: 'bolder', family: 'cursive' }, + '20px "new century schoolbook", serif', + { size: 20, unit: 'px', family: 'new century schoolbook,serif' }, + '20px "Arial bold 300"', // synthetic case with weight keyword inside family + { size: 20, unit: 'px', family: 'Arial bold 300', variant: 'normal' } + ] for (var i = 0, len = tests.length; i < len; ++i) { var str = tests[i++] - , expected = tests[i] - , actual = parseFont(str); - if (!expected.style) expected.style = 'normal'; - if (!expected.weight) expected.weight = 'normal'; - if (!expected.stretch) expected.stretch = 'normal'; - if (!expected.variant) expected.variant = 'normal'; + var expected = tests[i] - assert.deepEqual(actual, expected, 'Failed to parse: ' + str); + var actual = parseFont(str) + + if (!expected.style) expected.style = 'normal' + if (!expected.weight) expected.weight = 'normal' + if (!expected.stretch) expected.stretch = 'normal' + if (!expected.variant) expected.variant = 'normal' + + assert.deepEqual(actual, expected, 'Failed to parse: ' + str) } - }); + }) it('registerFont', function () { // Minimal test to make sure nothing is thrown - registerFont('./examples/pfennigFont/Pfennig.ttf', {family: 'Pfennig'}) - registerFont('./examples/pfennigFont/PfennigBold.ttf', {family: 'Pfennig', weight: 'bold'}) - }); + registerFont('./examples/pfennigFont/Pfennig.ttf', { family: 'Pfennig' }) + registerFont('./examples/pfennigFont/PfennigBold.ttf', { family: 'Pfennig', weight: 'bold' }) + }) it('color serialization', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - ['fillStyle', 'strokeStyle', 'shadowColor'].forEach(function(prop){ - ctx[prop] = '#FFFFFF'; - assert.equal('#ffffff', ctx[prop], prop + ' #FFFFFF -> #ffffff, got ' + ctx[prop]); + var ctx = canvas.getContext('2d'); + + ['fillStyle', 'strokeStyle', 'shadowColor'].forEach(function (prop) { + ctx[prop] = '#FFFFFF' + assert.equal('#ffffff', ctx[prop], prop + ' #FFFFFF -> #ffffff, got ' + ctx[prop]) - ctx[prop] = '#FFF'; - assert.equal('#ffffff', ctx[prop], prop + ' #FFF -> #ffffff, got ' + ctx[prop]); + ctx[prop] = '#FFF' + assert.equal('#ffffff', ctx[prop], prop + ' #FFF -> #ffffff, got ' + ctx[prop]) - ctx[prop] = 'rgba(128, 200, 128, 1)'; - assert.equal('#80c880', ctx[prop], prop + ' rgba(128, 200, 128, 1) -> #80c880, got ' + ctx[prop]); + ctx[prop] = 'rgba(128, 200, 128, 1)' + assert.equal('#80c880', ctx[prop], prop + ' rgba(128, 200, 128, 1) -> #80c880, got ' + ctx[prop]) - ctx[prop] = 'rgba(128,80,0,0.5)'; - assert.equal('rgba(128, 80, 0, 0.50)', ctx[prop], prop + ' rgba(128,80,0,0.5) -> rgba(128, 80, 0, 0.5), got ' + ctx[prop]); + ctx[prop] = 'rgba(128,80,0,0.5)' + assert.equal('rgba(128, 80, 0, 0.50)', ctx[prop], prop + ' rgba(128,80,0,0.5) -> rgba(128, 80, 0, 0.5), got ' + ctx[prop]) - ctx[prop] = 'rgba(128,80,0,0.75)'; - assert.equal('rgba(128, 80, 0, 0.75)', ctx[prop], prop + ' rgba(128,80,0,0.75) -> rgba(128, 80, 0, 0.75), got ' + ctx[prop]); + ctx[prop] = 'rgba(128,80,0,0.75)' + assert.equal('rgba(128, 80, 0, 0.75)', ctx[prop], prop + ' rgba(128,80,0,0.75) -> rgba(128, 80, 0, 0.75), got ' + ctx[prop]) - if ('shadowColor' == prop) return; + if (prop == 'shadowColor') return - var grad = ctx.createLinearGradient(0,0,0,150); - ctx[prop] = grad; - assert.strictEqual(grad, ctx[prop], prop + ' pattern getter failed'); - }); - }); + var grad = ctx.createLinearGradient(0, 0, 0, 150) + ctx[prop] = grad + assert.strictEqual(grad, ctx[prop], prop + ' pattern getter failed') + }) + }) it('color parser', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - ctx.fillStyle = '#ffccaa'; - assert.equal('#ffccaa', ctx.fillStyle); + var ctx = canvas.getContext('2d') + + ctx.fillStyle = '#ffccaa' + assert.equal('#ffccaa', ctx.fillStyle) - ctx.fillStyle = '#FFCCAA'; - assert.equal('#ffccaa', ctx.fillStyle); + ctx.fillStyle = '#FFCCAA' + assert.equal('#ffccaa', ctx.fillStyle) - ctx.fillStyle = '#FCA'; - assert.equal('#ffccaa', ctx.fillStyle); + ctx.fillStyle = '#FCA' + assert.equal('#ffccaa', ctx.fillStyle) - ctx.fillStyle = '#fff'; - ctx.fillStyle = '#FGG'; - assert.equal('#ff0000', ctx.fillStyle); + ctx.fillStyle = '#fff' + ctx.fillStyle = '#FGG' + assert.equal('#ff0000', ctx.fillStyle) - ctx.fillStyle = '#fff'; - ctx.fillStyle = 'afasdfasdf'; - assert.equal('#ffffff', ctx.fillStyle); + ctx.fillStyle = '#fff' + ctx.fillStyle = 'afasdfasdf' + assert.equal('#ffffff', ctx.fillStyle) // #rgba and #rrggbbaa ctx.fillStyle = '#ffccaa80' @@ -159,108 +163,109 @@ describe('Canvas', function () { ctx.fillStyle = '#BEAD' assert.equal('rgba(187, 238, 170, 0.87)', ctx.fillStyle) - ctx.fillStyle = 'rgb(255,255,255)'; - assert.equal('#ffffff', ctx.fillStyle); + ctx.fillStyle = 'rgb(255,255,255)' + assert.equal('#ffffff', ctx.fillStyle) - ctx.fillStyle = 'rgb(0,0,0)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'rgb(0,0,0)' + assert.equal('#000000', ctx.fillStyle) - ctx.fillStyle = 'rgb( 0 , 0 , 0)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'rgb( 0 , 0 , 0)' + assert.equal('#000000', ctx.fillStyle) - ctx.fillStyle = 'rgba( 0 , 0 , 0, 1)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'rgba( 0 , 0 , 0, 1)' + assert.equal('#000000', ctx.fillStyle) - ctx.fillStyle = 'rgba( 255, 200, 90, 0.5)'; - assert.equal('rgba(255, 200, 90, 0.50)', ctx.fillStyle); + ctx.fillStyle = 'rgba( 255, 200, 90, 0.5)' + assert.equal('rgba(255, 200, 90, 0.50)', ctx.fillStyle) - ctx.fillStyle = 'rgba( 255, 200, 90, 0.75)'; - assert.equal('rgba(255, 200, 90, 0.75)', ctx.fillStyle); + ctx.fillStyle = 'rgba( 255, 200, 90, 0.75)' + assert.equal('rgba(255, 200, 90, 0.75)', ctx.fillStyle) - ctx.fillStyle = 'rgba( 255, 200, 90, 0.7555)'; - assert.equal('rgba(255, 200, 90, 0.75)', ctx.fillStyle); + ctx.fillStyle = 'rgba( 255, 200, 90, 0.7555)' + assert.equal('rgba(255, 200, 90, 0.75)', ctx.fillStyle) - ctx.fillStyle = 'rgba( 255, 200, 90, .7555)'; - assert.equal('rgba(255, 200, 90, 0.75)', ctx.fillStyle); + ctx.fillStyle = 'rgba( 255, 200, 90, .7555)' + assert.equal('rgba(255, 200, 90, 0.75)', ctx.fillStyle) - ctx.fillStyle = 'rgb(0, 0, 9000)'; - assert.equal('#0000ff', ctx.fillStyle); + ctx.fillStyle = 'rgb(0, 0, 9000)' + assert.equal('#0000ff', ctx.fillStyle) - ctx.fillStyle = 'rgba(0, 0, 0, 42.42)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'rgba(0, 0, 0, 42.42)' + assert.equal('#000000', ctx.fillStyle) // hsl / hsla tests - ctx.fillStyle = 'hsl(0, 0%, 0%)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'hsl(0, 0%, 0%)' + assert.equal('#000000', ctx.fillStyle) - ctx.fillStyle = 'hsl(3600, -10%, -10%)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'hsl(3600, -10%, -10%)' + assert.equal('#000000', ctx.fillStyle) - ctx.fillStyle = 'hsl(10, 100%, 42%)'; - assert.equal('#d62400', ctx.fillStyle); + ctx.fillStyle = 'hsl(10, 100%, 42%)' + assert.equal('#d62400', ctx.fillStyle) - ctx.fillStyle = 'hsl(370, 120%, 42%)'; - assert.equal('#d62400', ctx.fillStyle); + ctx.fillStyle = 'hsl(370, 120%, 42%)' + assert.equal('#d62400', ctx.fillStyle) - ctx.fillStyle = 'hsl(0, 100%, 100%)'; - assert.equal('#ffffff', ctx.fillStyle); + ctx.fillStyle = 'hsl(0, 100%, 100%)' + assert.equal('#ffffff', ctx.fillStyle) - ctx.fillStyle = 'hsl(0, 150%, 150%)'; - assert.equal('#ffffff', ctx.fillStyle); + ctx.fillStyle = 'hsl(0, 150%, 150%)' + assert.equal('#ffffff', ctx.fillStyle) - ctx.fillStyle = 'hsl(237, 76%, 25%)'; - assert.equal('#0f1470', ctx.fillStyle); + ctx.fillStyle = 'hsl(237, 76%, 25%)' + assert.equal('#0f1470', ctx.fillStyle) - ctx.fillStyle = 'hsl(240, 73%, 25%)'; - assert.equal('#11116e', ctx.fillStyle); + ctx.fillStyle = 'hsl(240, 73%, 25%)' + assert.equal('#11116e', ctx.fillStyle) - ctx.fillStyle = 'hsl(262, 32%, 42%)'; - assert.equal('#62498d', ctx.fillStyle); + ctx.fillStyle = 'hsl(262, 32%, 42%)' + assert.equal('#62498d', ctx.fillStyle) - ctx.fillStyle = 'hsla(0, 0%, 0%, 1)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'hsla(0, 0%, 0%, 1)' + assert.equal('#000000', ctx.fillStyle) - ctx.fillStyle = 'hsla(0, 100%, 100%, 1)'; - assert.equal('#ffffff', ctx.fillStyle); + ctx.fillStyle = 'hsla(0, 100%, 100%, 1)' + assert.equal('#ffffff', ctx.fillStyle) - ctx.fillStyle = 'hsla(120, 25%, 75%, 0.5)'; - assert.equal('rgba(175, 207, 175, 0.50)', ctx.fillStyle); + ctx.fillStyle = 'hsla(120, 25%, 75%, 0.5)' + assert.equal('rgba(175, 207, 175, 0.50)', ctx.fillStyle) - ctx.fillStyle = 'hsla(240, 75%, 25%, 0.75)'; - assert.equal('rgba(16, 16, 112, 0.75)', ctx.fillStyle); + ctx.fillStyle = 'hsla(240, 75%, 25%, 0.75)' + assert.equal('rgba(16, 16, 112, 0.75)', ctx.fillStyle) - ctx.fillStyle = 'hsla(172.0, 33.00000e0%, 42%, 1)'; - assert.equal('#488e85', ctx.fillStyle); + ctx.fillStyle = 'hsla(172.0, 33.00000e0%, 42%, 1)' + assert.equal('#488e85', ctx.fillStyle) - ctx.fillStyle = 'hsl(124.5, 76.1%, 47.6%)'; - assert.equal('#1dd62b', ctx.fillStyle); + ctx.fillStyle = 'hsl(124.5, 76.1%, 47.6%)' + assert.equal('#1dd62b', ctx.fillStyle) - ctx.fillStyle = 'hsl(1.24e2, 760e-1%, 4.7e1%)'; - assert.equal('#1dd329', ctx.fillStyle); + ctx.fillStyle = 'hsl(1.24e2, 760e-1%, 4.7e1%)' + assert.equal('#1dd329', ctx.fillStyle) // case-insensitive (#235) - ctx.fillStyle = "sILveR"; - assert.equal(ctx.fillStyle, "#c0c0c0"); - }); + ctx.fillStyle = 'sILveR' + assert.equal(ctx.fillStyle, '#c0c0c0') + }) it('Canvas#type', function () { - var canvas = createCanvas(10, 10); - assert.equal(canvas.type, 'image'); - var canvas = createCanvas(10, 10, 'pdf'); - assert.equal(canvas.type, 'pdf'); - var canvas = createCanvas(10, 10, 'svg'); - assert.equal(canvas.type, 'svg'); - var canvas = createCanvas(10, 10, 'hey'); - assert.equal(canvas.type, 'image'); - }); + var canvas = createCanvas(10, 10) + assert.equal(canvas.type, 'image') + var canvas = createCanvas(10, 10, 'pdf') + assert.equal(canvas.type, 'pdf') + var canvas = createCanvas(10, 10, 'svg') + assert.equal(canvas.type, 'svg') + var canvas = createCanvas(10, 10, 'hey') + assert.equal(canvas.type, 'image') + }) it('Canvas#getContext("2d")', function () { var canvas = createCanvas(200, 300) - , ctx = canvas.getContext('2d'); - assert.ok('object' == typeof ctx); - assert.equal(canvas, ctx.canvas, 'context.canvas is not canvas'); - assert.equal(ctx, canvas.context, 'canvas.context is not context'); + + var ctx = canvas.getContext('2d') + assert.ok(typeof ctx === 'object') + assert.equal(canvas, ctx.canvas, 'context.canvas is not canvas') + assert.equal(ctx, canvas.context, 'canvas.context is not context') const MAX_IMAGE_SIZE = 32767; @@ -275,332 +280,342 @@ describe('Canvas', function () { [Math.pow(2, 30), 0, 3], [Math.pow(2, 30), 1, 3], [Math.pow(2, 32), 0, 1], - [Math.pow(2, 32), 1, 1], + [Math.pow(2, 32), 1, 1] ].forEach(params => { - var width = params[0]; - var height = params[1]; - var errorLevel = params[2]; + var width = params[0] + var height = params[1] + var errorLevel = params[2] - var level = 3; + var level = 3 try { - var canvas = createCanvas(width, height); - level--; + var canvas = createCanvas(width, height) + level-- - var ctx = canvas.getContext('2d'); - level--; + var ctx = canvas.getContext('2d') + level-- - ctx.getImageData(0, 0, 1, 1); - level--; + ctx.getImageData(0, 0, 1, 1) + level-- } catch (err) {} - if (errorLevel !== null) - assert.strictEqual(level, errorLevel); - }); - }); + if (errorLevel !== null) { assert.strictEqual(level, errorLevel) } + }) + }) it('Canvas#getContext("2d", {pixelFormat: string})', function () { - var canvas, context; + var canvas, context // default: - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "RGBA32"}); - assert.equal(context.pixelFormat, "RGBA32"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'RGBA32' }) + assert.equal(context.pixelFormat, 'RGBA32') - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "RGBA32"}); - assert.equal(context.pixelFormat, "RGBA32"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'RGBA32' }) + assert.equal(context.pixelFormat, 'RGBA32') - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "RGB24"}); - assert.equal(context.pixelFormat, "RGB24"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'RGB24' }) + assert.equal(context.pixelFormat, 'RGB24') - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "A8"}); - assert.equal(context.pixelFormat, "A8"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'A8' }) + assert.equal(context.pixelFormat, 'A8') - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "A1"}); - assert.equal(context.pixelFormat, "A1"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'A1' }) + assert.equal(context.pixelFormat, 'A1') - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "RGB16_565"}); - assert.equal(context.pixelFormat, "RGB16_565"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'RGB16_565' }) + assert.equal(context.pixelFormat, 'RGB16_565') // Not tested: RGB30 - }); + }) it('Canvas#getContext("2d", {alpha: boolean})', function () { - var canvas, context; + var canvas, context - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {alpha: true}); - assert.equal(context.pixelFormat, "RGBA32"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { alpha: true }) + assert.equal(context.pixelFormat, 'RGBA32') - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {alpha: false}); - assert.equal(context.pixelFormat, "RGB24"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { alpha: false }) + assert.equal(context.pixelFormat, 'RGB24') // alpha takes priority: - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "RGBA32", alpha: false}); - assert.equal(context.pixelFormat, "RGB24"); - }); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'RGBA32', alpha: false }) + assert.equal(context.pixelFormat, 'RGB24') + }) it('Canvas#{width,height}=', function () { - var context, canvas = createCanvas(100, 200); + var context; var canvas = createCanvas(100, 200) - assert.equal(100, canvas.width); - assert.equal(200, canvas.height); + assert.equal(100, canvas.width) + assert.equal(200, canvas.height) - canvas = createCanvas(); - context = canvas.getContext("2d"); - assert.equal(0, canvas.width); - assert.equal(0, canvas.height); + canvas = createCanvas() + context = canvas.getContext('2d') + assert.equal(0, canvas.width) + assert.equal(0, canvas.height) - canvas.width = 50; - canvas.height = 50; - assert.equal(50, canvas.width); - assert.equal(50, canvas.height); - assert.equal(1, context.lineWidth); // #1095 - }); + canvas.width = 50 + canvas.height = 50 + assert.equal(50, canvas.width) + assert.equal(50, canvas.height) + assert.equal(1, context.lineWidth) // #1095 + }) - it('Canvas#stride', function() { - var canvas = createCanvas(24, 10); - assert.ok(canvas.stride >= 24, 'canvas.stride is too short'); - assert.ok(canvas.stride < 1024, 'canvas.stride seems too long'); + it('Canvas#stride', function () { + var canvas = createCanvas(24, 10) + assert.ok(canvas.stride >= 24, 'canvas.stride is too short') + assert.ok(canvas.stride < 1024, 'canvas.stride seems too long') // TODO test stride on other formats - }); + }) it('Canvas#getContext("invalid")', function () { - assert.equal(null, createCanvas(200, 300).getContext('invalid')); - }); + assert.equal(null, createCanvas(200, 300).getContext('invalid')) + }) it('Context2d#patternQuality', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - assert.equal('good', ctx.patternQuality); - ctx.patternQuality = 'best'; - assert.equal('best', ctx.patternQuality); - ctx.patternQuality = 'invalid'; - assert.equal('best', ctx.patternQuality); - }); + var ctx = canvas.getContext('2d') + + assert.equal('good', ctx.patternQuality) + ctx.patternQuality = 'best' + assert.equal('best', ctx.patternQuality) + ctx.patternQuality = 'invalid' + assert.equal('best', ctx.patternQuality) + }) it('Context2d#imageSmoothingEnabled', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - assert.equal(true, ctx.imageSmoothingEnabled); - ctx.imageSmoothingEnabled = false; - assert.equal('good', ctx.patternQuality); - assert.equal(false, ctx.imageSmoothingEnabled); - assert.equal('good', ctx.patternQuality); - }); + var ctx = canvas.getContext('2d') + + assert.equal(true, ctx.imageSmoothingEnabled) + ctx.imageSmoothingEnabled = false + assert.equal('good', ctx.patternQuality) + assert.equal(false, ctx.imageSmoothingEnabled) + assert.equal('good', ctx.patternQuality) + }) it('Context2d#font=', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - assert.equal('10px sans-serif', ctx.font); - ctx.font = '15px Arial, sans-serif'; - assert.equal('15px Arial, sans-serif', ctx.font); - }); + var ctx = canvas.getContext('2d') + + assert.equal('10px sans-serif', ctx.font) + ctx.font = '15px Arial, sans-serif' + assert.equal('15px Arial, sans-serif', ctx.font) + }) it('Context2d#lineWidth=', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - - ctx.lineWidth = 10.0; - assert.equal(10, ctx.lineWidth); - ctx.lineWidth = Infinity; - assert.equal(10, ctx.lineWidth); - ctx.lineWidth = -Infinity; - assert.equal(10, ctx.lineWidth); - ctx.lineWidth = -5; - assert.equal(10, ctx.lineWidth); - ctx.lineWidth = 0; - assert.equal(10, ctx.lineWidth); - }); + + var ctx = canvas.getContext('2d') + + ctx.lineWidth = 10.0 + assert.equal(10, ctx.lineWidth) + ctx.lineWidth = Infinity + assert.equal(10, ctx.lineWidth) + ctx.lineWidth = -Infinity + assert.equal(10, ctx.lineWidth) + ctx.lineWidth = -5 + assert.equal(10, ctx.lineWidth) + ctx.lineWidth = 0 + assert.equal(10, ctx.lineWidth) + }) it('Context2d#antiAlias=', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - - assert.equal('default', ctx.antialias); - ctx.antialias = 'none'; - assert.equal('none', ctx.antialias); - ctx.antialias = 'gray'; - assert.equal('gray', ctx.antialias); - ctx.antialias = 'subpixel'; - assert.equal('subpixel', ctx.antialias); - ctx.antialias = 'invalid'; - assert.equal('subpixel', ctx.antialias); - ctx.antialias = 1; - assert.equal('subpixel', ctx.antialias); - }); + + var ctx = canvas.getContext('2d') + + assert.equal('default', ctx.antialias) + ctx.antialias = 'none' + assert.equal('none', ctx.antialias) + ctx.antialias = 'gray' + assert.equal('gray', ctx.antialias) + ctx.antialias = 'subpixel' + assert.equal('subpixel', ctx.antialias) + ctx.antialias = 'invalid' + assert.equal('subpixel', ctx.antialias) + ctx.antialias = 1 + assert.equal('subpixel', ctx.antialias) + }) it('Context2d#lineCap=', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - assert.equal('butt', ctx.lineCap); - ctx.lineCap = 'round'; - assert.equal('round', ctx.lineCap); - }); + var ctx = canvas.getContext('2d') + + assert.equal('butt', ctx.lineCap) + ctx.lineCap = 'round' + assert.equal('round', ctx.lineCap) + }) it('Context2d#lineJoin=', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - assert.equal('miter', ctx.lineJoin); - ctx.lineJoin = 'round'; - assert.equal('round', ctx.lineJoin); - }); + var ctx = canvas.getContext('2d') + + assert.equal('miter', ctx.lineJoin) + ctx.lineJoin = 'round' + assert.equal('round', ctx.lineJoin) + }) it('Context2d#globalAlpha=', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - assert.equal(1, ctx.globalAlpha); + var ctx = canvas.getContext('2d') + + assert.equal(1, ctx.globalAlpha) ctx.globalAlpha = 0.5 - assert.equal(0.5, ctx.globalAlpha); - }); + assert.equal(0.5, ctx.globalAlpha) + }) it('Context2d#isPointInPath()', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - - ctx.rect(5,5,100,100); - ctx.rect(50,100,10,10); - assert.ok(ctx.isPointInPath(10,10)); - assert.ok(ctx.isPointInPath(10,50)); - assert.ok(ctx.isPointInPath(100,100)); - assert.ok(ctx.isPointInPath(105,105)); - assert.ok(!ctx.isPointInPath(106,105)); - assert.ok(!ctx.isPointInPath(150,150)); - - assert.ok(ctx.isPointInPath(50,110)); - assert.ok(ctx.isPointInPath(60,110)); - assert.ok(!ctx.isPointInPath(70,110)); - assert.ok(!ctx.isPointInPath(50,120)); - }); + + var ctx = canvas.getContext('2d') + + ctx.rect(5, 5, 100, 100) + ctx.rect(50, 100, 10, 10) + assert.ok(ctx.isPointInPath(10, 10)) + assert.ok(ctx.isPointInPath(10, 50)) + assert.ok(ctx.isPointInPath(100, 100)) + assert.ok(ctx.isPointInPath(105, 105)) + assert.ok(!ctx.isPointInPath(106, 105)) + assert.ok(!ctx.isPointInPath(150, 150)) + + assert.ok(ctx.isPointInPath(50, 110)) + assert.ok(ctx.isPointInPath(60, 110)) + assert.ok(!ctx.isPointInPath(70, 110)) + assert.ok(!ctx.isPointInPath(50, 120)) + }) it('Context2d#textAlign', function () { - var canvas = createCanvas(200,200) - , ctx = canvas.getContext('2d'); - - assert.equal('start', ctx.textAlign); - ctx.textAlign = 'center'; - assert.equal('center', ctx.textAlign); - ctx.textAlign = 'right'; - assert.equal('right', ctx.textAlign); - ctx.textAlign = 'end'; - assert.equal('end', ctx.textAlign); - ctx.textAlign = 'fail'; - assert.equal('end', ctx.textAlign); - }); + var canvas = createCanvas(200, 200) + + var ctx = canvas.getContext('2d') + + assert.equal('start', ctx.textAlign) + ctx.textAlign = 'center' + assert.equal('center', ctx.textAlign) + ctx.textAlign = 'right' + assert.equal('right', ctx.textAlign) + ctx.textAlign = 'end' + assert.equal('end', ctx.textAlign) + ctx.textAlign = 'fail' + assert.equal('end', ctx.textAlign) + }) describe('#toBuffer', function () { it('Canvas#toBuffer()', function () { - var buf = createCanvas(200,200).toBuffer(); - assert.equal('PNG', buf.slice(1,4).toString()); - }); + var buf = createCanvas(200, 200).toBuffer() + assert.equal('PNG', buf.slice(1, 4).toString()) + }) it('Canvas#toBuffer("image/png")', function () { - var buf = createCanvas(200,200).toBuffer('image/png'); - assert.equal('PNG', buf.slice(1,4).toString()); - }); + var buf = createCanvas(200, 200).toBuffer('image/png') + assert.equal('PNG', buf.slice(1, 4).toString()) + }) it('Canvas#toBuffer("image/png", {resolution: 96})', function () { - const buf = createCanvas(200, 200).toBuffer('image/png', {resolution: 96}); + const buf = createCanvas(200, 200).toBuffer('image/png', { resolution: 96 }) // 3780 ppm ~= 96 ppi for (let i = 0; i < buf.length - 12; i++) { if (buf[i] === 0x70 && buf[i + 1] === 0x48 && buf[i + 2] === 0x59 && buf[i + 3] === 0x73) { // pHYs - assert.equal(buf[i + 4], 0); - assert.equal(buf[i + 5], 0); - assert.equal(buf[i + 6], 0x0e); - assert.equal(buf[i + 7], 0xc4); // x - assert.equal(buf[i + 8], 0); - assert.equal(buf[i + 9], 0); - assert.equal(buf[i + 10], 0x0e); - assert.equal(buf[i + 11], 0xc4); // y + assert.equal(buf[i + 4], 0) + assert.equal(buf[i + 5], 0) + assert.equal(buf[i + 6], 0x0e) + assert.equal(buf[i + 7], 0xc4) // x + assert.equal(buf[i + 8], 0) + assert.equal(buf[i + 9], 0) + assert.equal(buf[i + 10], 0x0e) + assert.equal(buf[i + 11], 0xc4) // y } } }) it('Canvas#toBuffer("image/png", {compressionLevel: 5})', function () { - var buf = createCanvas(200,200).toBuffer('image/png', {compressionLevel: 5}); - assert.equal('PNG', buf.slice(1,4).toString()); - }); + var buf = createCanvas(200, 200).toBuffer('image/png', { compressionLevel: 5 }) + assert.equal('PNG', buf.slice(1, 4).toString()) + }) it('Canvas#toBuffer("image/jpeg")', function () { - var buf = createCanvas(200,200).toBuffer('image/jpeg'); - assert.equal(buf[0], 0xff); - assert.equal(buf[1], 0xd8); - assert.equal(buf[buf.byteLength - 2], 0xff); - assert.equal(buf[buf.byteLength - 1], 0xd9); - }); + var buf = createCanvas(200, 200).toBuffer('image/jpeg') + assert.equal(buf[0], 0xff) + assert.equal(buf[1], 0xd8) + assert.equal(buf[buf.byteLength - 2], 0xff) + assert.equal(buf[buf.byteLength - 1], 0xd9) + }) it('Canvas#toBuffer("image/jpeg", {quality: 0.95})', function () { - var buf = createCanvas(200,200).toBuffer('image/jpeg', {quality: 0.95}); - assert.equal(buf[0], 0xff); - assert.equal(buf[1], 0xd8); - assert.equal(buf[buf.byteLength - 2], 0xff); - assert.equal(buf[buf.byteLength - 1], 0xd9); - }); + var buf = createCanvas(200, 200).toBuffer('image/jpeg', { quality: 0.95 }) + assert.equal(buf[0], 0xff) + assert.equal(buf[1], 0xd8) + assert.equal(buf[buf.byteLength - 2], 0xff) + assert.equal(buf[buf.byteLength - 1], 0xd9) + }) it('Canvas#toBuffer(callback)', function (done) { - createCanvas(200, 200).toBuffer(function(err, buf){ - assert.ok(!err); - assert.equal('PNG', buf.slice(1,4).toString()); - done(); - }); - }); + createCanvas(200, 200).toBuffer(function (err, buf) { + assert.ok(!err) + assert.equal('PNG', buf.slice(1, 4).toString()) + done() + }) + }) it('Canvas#toBuffer(callback, "image/jpeg")', function (done) { - createCanvas(200,200).toBuffer(function (err, buf) { - assert.ok(!err); - assert.equal(buf[0], 0xff); - assert.equal(buf[1], 0xd8); - assert.equal(buf[buf.byteLength - 2], 0xff); - assert.equal(buf[buf.byteLength - 1], 0xd9); - done(); - }, 'image/jpeg'); - }); + createCanvas(200, 200).toBuffer(function (err, buf) { + assert.ok(!err) + assert.equal(buf[0], 0xff) + assert.equal(buf[1], 0xd8) + assert.equal(buf[buf.byteLength - 2], 0xff) + assert.equal(buf[buf.byteLength - 1], 0xd9) + done() + }, 'image/jpeg') + }) it('Canvas#toBuffer(callback, "image/jpeg", {quality: 0.95})', function (done) { - createCanvas(200,200).toBuffer(function (err, buf) { - assert.ok(!err); - assert.equal(buf[0], 0xff); - assert.equal(buf[1], 0xd8); - assert.equal(buf[buf.byteLength - 2], 0xff); - assert.equal(buf[buf.byteLength - 1], 0xd9); - done(); - }, 'image/jpeg', {quality: 0.95}); - }); - - describe('#toBuffer("raw")', function() { + createCanvas(200, 200).toBuffer(function (err, buf) { + assert.ok(!err) + assert.equal(buf[0], 0xff) + assert.equal(buf[1], 0xd8) + assert.equal(buf[buf.byteLength - 2], 0xff) + assert.equal(buf[buf.byteLength - 1], 0xd9) + done() + }, 'image/jpeg', { quality: 0.95 }) + }) + + describe('#toBuffer("raw")', function () { var canvas = createCanvas(11, 10) - , ctx = canvas.getContext('2d'); - ctx.clearRect(0, 0, 11, 10); + var ctx = canvas.getContext('2d') + + ctx.clearRect(0, 0, 11, 10) - ctx.fillStyle = 'rgba(200, 200, 200, 0.505)'; - ctx.fillRect(0, 0, 5, 5); + ctx.fillStyle = 'rgba(200, 200, 200, 0.505)' + ctx.fillRect(0, 0, 5, 5) - ctx.fillStyle = 'red'; - ctx.fillRect(5, 0, 5, 5); + ctx.fillStyle = 'red' + ctx.fillRect(5, 0, 5, 5) - ctx.fillStyle = '#00ff00'; - ctx.fillRect(0, 5, 5, 5); + ctx.fillStyle = '#00ff00' + ctx.fillRect(0, 5, 5, 5) - ctx.fillStyle = 'black'; - ctx.fillRect(5, 5, 4, 5); + ctx.fillStyle = 'black' + ctx.fillRect(5, 5, 4, 5) /** Output: * *****RRRRR- @@ -615,284 +630,291 @@ describe('Canvas', function () { * GGGGGBBBB-- */ - var buf = canvas.toBuffer('raw'); - var stride = canvas.stride; + var buf = canvas.toBuffer('raw') + var stride = canvas.stride - var endianness = os.endianness(); + var endianness = os.endianness() - function assertPixel(u32, x, y, message) { - var expected = '0x' + u32.toString(16); + function assertPixel (u32, x, y, message) { + var expected = '0x' + u32.toString(16) // Buffer doesn't have readUInt32(): it only has readUInt32LE() and // readUInt32BE(). - var px = buf['readUInt32' + endianness](y * stride + x * 4); - var actual = '0x' + px.toString(16); + var px = buf['readUInt32' + endianness](y * stride + x * 4) + var actual = '0x' + px.toString(16) - assert.equal(actual, expected, message); + assert.equal(actual, expected, message) } - it('should have the correct size', function() { - assert.equal(buf.length, stride * 10); - }); - - it('does not premultiply alpha', function() { - assertPixel(0x80646464, 0, 0, 'first semitransparent pixel'); - assertPixel(0x80646464, 4, 4, 'last semitransparent pixel'); - }); - - it('draws red', function() { - assertPixel(0xffff0000, 5, 0, 'first red pixel'); - assertPixel(0xffff0000, 9, 4, 'last red pixel'); - }); - - it('draws green', function() { - assertPixel(0xff00ff00, 0, 5, 'first green pixel'); - assertPixel(0xff00ff00, 4, 9, 'last green pixel'); - }); - - it('draws black', function() { - assertPixel(0xff000000, 5, 5, 'first black pixel'); - assertPixel(0xff000000, 8, 9, 'last black pixel'); - }); - - it('leaves undrawn pixels black, transparent', function() { - assertPixel(0x0, 9, 5, 'first undrawn pixel'); - assertPixel(0x0, 9, 9, 'last undrawn pixel'); - }); - - it('is immutable', function() { - ctx.fillStyle = 'white'; - ctx.fillRect(0, 0, 10, 10); - canvas.toBuffer('raw'); // (side-effect: flushes canvas) - assertPixel(0xffff0000, 5, 0, 'first red pixel'); - }); - }); - }); + it('should have the correct size', function () { + assert.equal(buf.length, stride * 10) + }) + + it('does not premultiply alpha', function () { + assertPixel(0x80646464, 0, 0, 'first semitransparent pixel') + assertPixel(0x80646464, 4, 4, 'last semitransparent pixel') + }) + + it('draws red', function () { + assertPixel(0xffff0000, 5, 0, 'first red pixel') + assertPixel(0xffff0000, 9, 4, 'last red pixel') + }) + + it('draws green', function () { + assertPixel(0xff00ff00, 0, 5, 'first green pixel') + assertPixel(0xff00ff00, 4, 9, 'last green pixel') + }) + + it('draws black', function () { + assertPixel(0xff000000, 5, 5, 'first black pixel') + assertPixel(0xff000000, 8, 9, 'last black pixel') + }) + + it('leaves undrawn pixels black, transparent', function () { + assertPixel(0x0, 9, 5, 'first undrawn pixel') + assertPixel(0x0, 9, 9, 'last undrawn pixel') + }) + + it('is immutable', function () { + ctx.fillStyle = 'white' + ctx.fillRect(0, 0, 10, 10) + canvas.toBuffer('raw') // (side-effect: flushes canvas) + assertPixel(0xffff0000, 5, 0, 'first red pixel') + }) + }) + }) describe('#toDataURL()', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - ctx.fillRect(0,0,100,100); - ctx.fillStyle = 'red'; - ctx.fillRect(100,0,100,100); + var ctx = canvas.getContext('2d') + + ctx.fillRect(0, 0, 100, 100) + ctx.fillStyle = 'red' + ctx.fillRect(100, 0, 100, 100) it('toDataURL() works and defaults to PNG', function () { - assert.ok(canvas.toDataURL().startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL().startsWith('data:image/png;base64,')) + }) it('toDataURL(0.5) works and defaults to PNG', function () { - assert.ok(canvas.toDataURL(0.5).startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL(0.5).startsWith('data:image/png;base64,')) + }) it('toDataURL(undefined) works and defaults to PNG', function () { - assert.ok(canvas.toDataURL(undefined).startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL(undefined).startsWith('data:image/png;base64,')) + }) it('toDataURL("image/png") works', function () { - assert.ok(canvas.toDataURL('image/png').startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL('image/png').startsWith('data:image/png;base64,')) + }) it('toDataURL("image/png", 0.5) works', function () { - assert.ok(canvas.toDataURL('image/png').startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL('image/png').startsWith('data:image/png;base64,')) + }) it('toDataURL("iMaGe/PNg") works', function () { - assert.ok(canvas.toDataURL('iMaGe/PNg').startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL('iMaGe/PNg').startsWith('data:image/png;base64,')) + }) it('toDataURL("image/jpeg") works', function () { - assert.ok(canvas.toDataURL('image/jpeg').startsWith('data:image/jpeg;base64,')); - }); + assert.ok(canvas.toDataURL('image/jpeg').startsWith('data:image/jpeg;base64,')) + }) it('toDataURL(function (err, str) {...}) works and defaults to PNG', function (done) { - createCanvas(200,200).toDataURL(function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/png;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL(function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/png;base64,') === 0) + done() + }) + }) it('toDataURL(function (err, str) {...}) is async even with no canvas data', function (done) { - createCanvas().toDataURL(function(err, str){ - assert.ifError(err); - assert.ok('data:,' === str); - done(); - }); - }); + createCanvas().toDataURL(function (err, str) { + assert.ifError(err) + assert.ok(str === 'data:,') + done() + }) + }) it('toDataURL(0.5, function (err, str) {...}) works and defaults to PNG', function (done) { - createCanvas(200,200).toDataURL(0.5, function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/png;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL(0.5, function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/png;base64,') === 0) + done() + }) + }) it('toDataURL(undefined, function (err, str) {...}) works and defaults to PNG', function (done) { - createCanvas(200,200).toDataURL(undefined, function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/png;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL(undefined, function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/png;base64,') === 0) + done() + }) + }) it('toDataURL("image/png", function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('image/png', function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/png;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL('image/png', function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/png;base64,') === 0) + done() + }) + }) it('toDataURL("image/png", 0.5, function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('image/png', 0.5, function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/png;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL('image/png', 0.5, function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/png;base64,') === 0) + done() + }) + }) it('toDataURL("image/png", {}) works', function () { - assert.ok(canvas.toDataURL('image/png', {}).startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL('image/png', {}).startsWith('data:image/png;base64,')) + }) it('toDataURL("image/jpeg", {}) works', function () { - assert.ok(canvas.toDataURL('image/jpeg', {}).startsWith('data:image/jpeg;base64,')); - }); + assert.ok(canvas.toDataURL('image/jpeg', {}).startsWith('data:image/jpeg;base64,')) + }) it('toDataURL("image/jpeg", function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('image/jpeg', function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/jpeg;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL('image/jpeg', function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/jpeg;base64,') === 0) + done() + }) + }) it('toDataURL("iMAge/JPEG", function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('iMAge/JPEG', function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/jpeg;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL('iMAge/JPEG', function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/jpeg;base64,') === 0) + done() + }) + }) it('toDataURL("image/jpeg", undefined, function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('image/jpeg', undefined, function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/jpeg;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL('image/jpeg', undefined, function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/jpeg;base64,') === 0) + done() + }) + }) it('toDataURL("image/jpeg", 0.5, function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('image/jpeg', 0.5, function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/jpeg;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL('image/jpeg', 0.5, function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/jpeg;base64,') === 0) + done() + }) + }) it('toDataURL("image/jpeg", opts, function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('image/jpeg', {quality: 100}, function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/jpeg;base64,')); - done(); - }); - }); - }); + createCanvas(200, 200).toDataURL('image/jpeg', { quality: 100 }, function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/jpeg;base64,') === 0) + done() + }) + }) + }) describe('Context2d#createImageData(width, height)', function () { - it("works", function () { + it('works', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d'); - var imageData = ctx.createImageData(2,6); - assert.equal(2, imageData.width); - assert.equal(6, imageData.height); - assert.equal(2 * 6 * 4, imageData.data.length); + var ctx = canvas.getContext('2d') + + var imageData = ctx.createImageData(2, 6) + assert.equal(2, imageData.width) + assert.equal(6, imageData.height) + assert.equal(2 * 6 * 4, imageData.data.length) - assert.equal(0, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(0, imageData.data[3]); - }); + assert.equal(0, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(0, imageData.data[3]) + }) - it("works, A8 format", function () { + it('works, A8 format', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d', {pixelFormat: "A8"}); - var imageData = ctx.createImageData(2,6); - assert.equal(2, imageData.width); - assert.equal(6, imageData.height); - assert.equal(2 * 6 * 1, imageData.data.length); + var ctx = canvas.getContext('2d', { pixelFormat: 'A8' }) - assert.equal(0, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(0, imageData.data[3]); - }); + var imageData = ctx.createImageData(2, 6) + assert.equal(2, imageData.width) + assert.equal(6, imageData.height) + assert.equal(2 * 6 * 1, imageData.data.length) + + assert.equal(0, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(0, imageData.data[3]) + }) - it("works, A1 format", function () { + it('works, A1 format', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d', {pixelFormat: "A1"}); - var imageData = ctx.createImageData(2,6); - assert.equal(2, imageData.width); - assert.equal(6, imageData.height); - assert.equal(Math.ceil(2 * 6 / 8), imageData.data.length); + var ctx = canvas.getContext('2d', { pixelFormat: 'A1' }) - assert.equal(0, imageData.data[0]); - assert.equal(0, imageData.data[1]); - }); + var imageData = ctx.createImageData(2, 6) + assert.equal(2, imageData.width) + assert.equal(6, imageData.height) + assert.equal(Math.ceil(2 * 6 / 8), imageData.data.length) - it("works, RGB24 format", function () { + assert.equal(0, imageData.data[0]) + assert.equal(0, imageData.data[1]) + }) + + it('works, RGB24 format', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d', {pixelFormat: "RGB24"}); - var imageData = ctx.createImageData(2,6); - assert.equal(2, imageData.width); - assert.equal(6, imageData.height); - assert.equal(2 * 6 * 4, imageData.data.length); + var ctx = canvas.getContext('2d', { pixelFormat: 'RGB24' }) - assert.equal(0, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(0, imageData.data[3]); - }); + var imageData = ctx.createImageData(2, 6) + assert.equal(2, imageData.width) + assert.equal(6, imageData.height) + assert.equal(2 * 6 * 4, imageData.data.length) - it("works, RGB16_565 format", function () { + assert.equal(0, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(0, imageData.data[3]) + }) + + it('works, RGB16_565 format', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d', {pixelFormat: "RGB16_565"}); - var imageData = ctx.createImageData(2,6); - assert(imageData.data instanceof Uint16Array); - assert.equal(2, imageData.width); - assert.equal(6, imageData.height); - assert.equal(2 * 6, imageData.data.length); + var ctx = canvas.getContext('2d', { pixelFormat: 'RGB16_565' }) + + var imageData = ctx.createImageData(2, 6) + assert(imageData.data instanceof Uint16Array) + assert.equal(2, imageData.width) + assert.equal(6, imageData.height) + assert.equal(2 * 6, imageData.data.length) - assert.equal(0, imageData.data[0]); - assert.equal(0, imageData.data[1]); - }); - }); + assert.equal(0, imageData.data[0]) + assert.equal(0, imageData.data[1]) + }) + }) describe('Context2d#measureText()', function () { it('Context2d#measureText().width', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d'); - assert.ok(ctx.measureText('foo').width); - assert.ok(ctx.measureText('foo').width != ctx.measureText('foobar').width); - assert.ok(ctx.measureText('foo').width != ctx.measureText(' foo').width); - }); + var ctx = canvas.getContext('2d') + + assert.ok(ctx.measureText('foo').width) + assert.ok(ctx.measureText('foo').width != ctx.measureText('foobar').width) + assert.ok(ctx.measureText('foo').width != ctx.measureText(' foo').width) + }) it('works', function () { var canvas = createCanvas(20, 20) var ctx = canvas.getContext('2d') - ctx.font = "20px Arial" + ctx.font = '20px Arial' - ctx.textBaseline = "alphabetic" - var metrics = ctx.measureText("Alphabet") + ctx.textBaseline = 'alphabetic' + var metrics = ctx.measureText('Alphabet') // Zero if the given baseline is the alphabetic baseline assert.equal(metrics.alphabeticBaseline, 0) // Positive = going up from the baseline @@ -900,807 +922,806 @@ describe('Canvas', function () { // Positive = going down from the baseline assert.ok(metrics.actualBoundingBoxDescent > 0) // ~4-5 - ctx.textBaseline = "bottom" - metrics = ctx.measureText("Alphabet") + ctx.textBaseline = 'bottom' + metrics = ctx.measureText('Alphabet') assert.ok(metrics.alphabeticBaseline > 0) // ~4-5 assert.ok(metrics.actualBoundingBoxAscent > 0) // On the baseline or slightly above assert.ok(metrics.actualBoundingBoxDescent <= 0) - }); - }); + }) + }) it('Context2d#currentTransform', function () { - var canvas = createCanvas(20, 20); - var ctx = canvas.getContext('2d'); - - ctx.scale(0.1, 0.3); - var actual = ctx.currentTransform; - assert.equal(actual.a, 0.1); - assert.equal(actual.b, 0); - assert.equal(actual.c, 0); - assert.equal(actual.d, 0.3); - assert.equal(actual.e, 0); - assert.equal(actual.f, 0); - }); + var canvas = createCanvas(20, 20) + var ctx = canvas.getContext('2d') + + ctx.scale(0.1, 0.3) + var actual = ctx.currentTransform + assert.equal(actual.a, 0.1) + assert.equal(actual.b, 0) + assert.equal(actual.c, 0) + assert.equal(actual.d, 0.3) + assert.equal(actual.e, 0) + assert.equal(actual.f, 0) + }) it('Context2d#createImageData(ImageData)', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d'); - var imageData = ctx.createImageData(ctx.createImageData(2, 6)); - assert.equal(2, imageData.width); - assert.equal(6, imageData.height); - assert.equal(2 * 6 * 4, imageData.data.length); - }); + var ctx = canvas.getContext('2d') + + var imageData = ctx.createImageData(ctx.createImageData(2, 6)) + assert.equal(2, imageData.width) + assert.equal(6, imageData.height) + assert.equal(2 * 6 * 4, imageData.data.length) + }) describe('Context2d#getImageData()', function () { - function createTestCanvas(useAlpha, attributes) { - var canvas = createCanvas(3, 6); - var ctx = canvas.getContext('2d', attributes); + function createTestCanvas (useAlpha, attributes) { + var canvas = createCanvas(3, 6) + var ctx = canvas.getContext('2d', attributes) - ctx.fillStyle = useAlpha ? 'rgba(255,0,0,0.25)' : '#f00'; - ctx.fillRect(0,0,1,6); + ctx.fillStyle = useAlpha ? 'rgba(255,0,0,0.25)' : '#f00' + ctx.fillRect(0, 0, 1, 6) - ctx.fillStyle = useAlpha ? 'rgba(0,255,0,0.5)' : '#0f0'; - ctx.fillRect(1,0,1,6); + ctx.fillStyle = useAlpha ? 'rgba(0,255,0,0.5)' : '#0f0' + ctx.fillRect(1, 0, 1, 6) - ctx.fillStyle = useAlpha ? 'rgba(0,0,255,0.75)' : '#00f'; - ctx.fillRect(2,0,1,6); + ctx.fillStyle = useAlpha ? 'rgba(0,0,255,0.75)' : '#00f' + ctx.fillRect(2, 0, 1, 6) - return ctx; + return ctx } - it("works, full width, RGBA32", function () { - var ctx = createTestCanvas(); - var imageData = ctx.getImageData(0,0,3,6); - - assert.equal(3, imageData.width); - assert.equal(6, imageData.height); - assert.equal(3 * 6 * 4, imageData.data.length); - - assert.equal(255, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(255, imageData.data[3]); - - assert.equal(0, imageData.data[4]); - assert.equal(255, imageData.data[5]); - assert.equal(0, imageData.data[6]); - assert.equal(255, imageData.data[7]); - - assert.equal(0, imageData.data[8]); - assert.equal(0, imageData.data[9]); - assert.equal(255, imageData.data[10]); - assert.equal(255, imageData.data[11]); - }); - - it("works, full width, RGB24", function () { - var ctx = createTestCanvas(false, {pixelFormat: "RGB24"}); - var imageData = ctx.getImageData(0,0,3,6); - assert.equal(3, imageData.width); - assert.equal(6, imageData.height); - assert.equal(3 * 6 * 4, imageData.data.length); - - assert.equal(255, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(255, imageData.data[3]); - - assert.equal(0, imageData.data[4]); - assert.equal(255, imageData.data[5]); - assert.equal(0, imageData.data[6]); - assert.equal(255, imageData.data[7]); - - assert.equal(0, imageData.data[8]); - assert.equal(0, imageData.data[9]); - assert.equal(255, imageData.data[10]); - assert.equal(255, imageData.data[11]); - }); - - it("works, full width, RGB16_565", function () { - var ctx = createTestCanvas(false, {pixelFormat: "RGB16_565"}); - var imageData = ctx.getImageData(0,0,3,6); - assert.equal(3, imageData.width); - assert.equal(6, imageData.height); - assert.equal(3 * 6 * 2, imageData.data.length); - - assert.equal((255 & 0b11111) << 11, imageData.data[0]); - assert.equal((255 & 0b111111) << 5, imageData.data[1]); - assert.equal((255 & 0b11111), imageData.data[2]); - - assert.equal((255 & 0b11111) << 11, imageData.data[3]); - assert.equal((255 & 0b111111) << 5, imageData.data[4]); - assert.equal((255 & 0b11111), imageData.data[5]); - }); - - it("works, full width, A8", function () { - var ctx = createTestCanvas(true, {pixelFormat: "A8"}); - var imageData = ctx.getImageData(0,0,3,6); - assert.equal(3, imageData.width); - assert.equal(6, imageData.height); - assert.equal(3 * 6, imageData.data.length); - - assert.equal(63, imageData.data[0]); - assert.equal(127, imageData.data[1]); - assert.equal(191, imageData.data[2]); - - assert.equal(63, imageData.data[3]); - assert.equal(127, imageData.data[4]); - assert.equal(191, imageData.data[5]); - }); - - it("works, full width, A1"); - - it("works, full width, RGB30"); - - it("works, slice, RGBA32", function () { - var ctx = createTestCanvas(); - var imageData = ctx.getImageData(0,0,2,1); - assert.equal(2, imageData.width); - assert.equal(1, imageData.height); - assert.equal(8, imageData.data.length); - - assert.equal(255, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(255, imageData.data[3]); - - assert.equal(0, imageData.data[4]); - assert.equal(255, imageData.data[5]); - assert.equal(0, imageData.data[6]); - assert.equal(255, imageData.data[7]); - }); - - it("works, slice, RGB24", function () { - var ctx = createTestCanvas(false, {pixelFormat: "RGB24"}); - var imageData = ctx.getImageData(0,0,2,1); - assert.equal(2, imageData.width); - assert.equal(1, imageData.height); - assert.equal(8, imageData.data.length); - - assert.equal(255, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(255, imageData.data[3]); - - assert.equal(0, imageData.data[4]); - assert.equal(255, imageData.data[5]); - assert.equal(0, imageData.data[6]); - assert.equal(255, imageData.data[7]); - }); - - it("works, slice, RGB16_565", function () { - var ctx = createTestCanvas(false, {pixelFormat: "RGB16_565"}); - var imageData = ctx.getImageData(0,0,2,1); - assert.equal(2, imageData.width); - assert.equal(1, imageData.height); - assert.equal(2 * 1 * 2, imageData.data.length); - - assert.equal((255 & 0b11111) << 11, imageData.data[0]); - assert.equal((255 & 0b111111) << 5, imageData.data[1]); - }); - - it("works, slice, A8", function () { - var ctx = createTestCanvas(true, {pixelFormat: "A8"}); - var imageData = ctx.getImageData(0,0,2,1); - assert.equal(2, imageData.width); - assert.equal(1, imageData.height); - assert.equal(2 * 1, imageData.data.length); - - assert.equal(63, imageData.data[0]); - assert.equal(127, imageData.data[1]); - }); - - it("works, slice, A1"); - - it("works, slice, RGB30"); - - it("works, assignment", function () { - var ctx = createTestCanvas(); - var data = ctx.getImageData(0,0,5,5).data; - data[0] = 50; - assert.equal(50, data[0]); - data[0] = 280; - assert.equal(255, data[0]); - data[0] = -4444; - assert.equal(0, data[0]); - }); - - it("throws if indexes are invalid", function () { - var ctx = createTestCanvas(); - assert.throws(function () { ctx.getImageData(0, 0, 0, 0); }, /IndexSizeError/); - }); - }); + it('works, full width, RGBA32', function () { + var ctx = createTestCanvas() + var imageData = ctx.getImageData(0, 0, 3, 6) + + assert.equal(3, imageData.width) + assert.equal(6, imageData.height) + assert.equal(3 * 6 * 4, imageData.data.length) + + assert.equal(255, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(255, imageData.data[3]) + + assert.equal(0, imageData.data[4]) + assert.equal(255, imageData.data[5]) + assert.equal(0, imageData.data[6]) + assert.equal(255, imageData.data[7]) + + assert.equal(0, imageData.data[8]) + assert.equal(0, imageData.data[9]) + assert.equal(255, imageData.data[10]) + assert.equal(255, imageData.data[11]) + }) + + it('works, full width, RGB24', function () { + var ctx = createTestCanvas(false, { pixelFormat: 'RGB24' }) + var imageData = ctx.getImageData(0, 0, 3, 6) + assert.equal(3, imageData.width) + assert.equal(6, imageData.height) + assert.equal(3 * 6 * 4, imageData.data.length) + + assert.equal(255, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(255, imageData.data[3]) + + assert.equal(0, imageData.data[4]) + assert.equal(255, imageData.data[5]) + assert.equal(0, imageData.data[6]) + assert.equal(255, imageData.data[7]) + + assert.equal(0, imageData.data[8]) + assert.equal(0, imageData.data[9]) + assert.equal(255, imageData.data[10]) + assert.equal(255, imageData.data[11]) + }) + + it('works, full width, RGB16_565', function () { + var ctx = createTestCanvas(false, { pixelFormat: 'RGB16_565' }) + var imageData = ctx.getImageData(0, 0, 3, 6) + assert.equal(3, imageData.width) + assert.equal(6, imageData.height) + assert.equal(3 * 6 * 2, imageData.data.length) + + assert.equal((255 & 0b11111) << 11, imageData.data[0]) + assert.equal((255 & 0b111111) << 5, imageData.data[1]) + assert.equal((255 & 0b11111), imageData.data[2]) + + assert.equal((255 & 0b11111) << 11, imageData.data[3]) + assert.equal((255 & 0b111111) << 5, imageData.data[4]) + assert.equal((255 & 0b11111), imageData.data[5]) + }) + + it('works, full width, A8', function () { + var ctx = createTestCanvas(true, { pixelFormat: 'A8' }) + var imageData = ctx.getImageData(0, 0, 3, 6) + assert.equal(3, imageData.width) + assert.equal(6, imageData.height) + assert.equal(3 * 6, imageData.data.length) + + assert.equal(63, imageData.data[0]) + assert.equal(127, imageData.data[1]) + assert.equal(191, imageData.data[2]) + + assert.equal(63, imageData.data[3]) + assert.equal(127, imageData.data[4]) + assert.equal(191, imageData.data[5]) + }) + + it('works, full width, A1') + + it('works, full width, RGB30') + + it('works, slice, RGBA32', function () { + var ctx = createTestCanvas() + var imageData = ctx.getImageData(0, 0, 2, 1) + assert.equal(2, imageData.width) + assert.equal(1, imageData.height) + assert.equal(8, imageData.data.length) + + assert.equal(255, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(255, imageData.data[3]) + + assert.equal(0, imageData.data[4]) + assert.equal(255, imageData.data[5]) + assert.equal(0, imageData.data[6]) + assert.equal(255, imageData.data[7]) + }) + + it('works, slice, RGB24', function () { + var ctx = createTestCanvas(false, { pixelFormat: 'RGB24' }) + var imageData = ctx.getImageData(0, 0, 2, 1) + assert.equal(2, imageData.width) + assert.equal(1, imageData.height) + assert.equal(8, imageData.data.length) + + assert.equal(255, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(255, imageData.data[3]) + + assert.equal(0, imageData.data[4]) + assert.equal(255, imageData.data[5]) + assert.equal(0, imageData.data[6]) + assert.equal(255, imageData.data[7]) + }) + + it('works, slice, RGB16_565', function () { + var ctx = createTestCanvas(false, { pixelFormat: 'RGB16_565' }) + var imageData = ctx.getImageData(0, 0, 2, 1) + assert.equal(2, imageData.width) + assert.equal(1, imageData.height) + assert.equal(2 * 1 * 2, imageData.data.length) + + assert.equal((255 & 0b11111) << 11, imageData.data[0]) + assert.equal((255 & 0b111111) << 5, imageData.data[1]) + }) + + it('works, slice, A8', function () { + var ctx = createTestCanvas(true, { pixelFormat: 'A8' }) + var imageData = ctx.getImageData(0, 0, 2, 1) + assert.equal(2, imageData.width) + assert.equal(1, imageData.height) + assert.equal(2 * 1, imageData.data.length) + + assert.equal(63, imageData.data[0]) + assert.equal(127, imageData.data[1]) + }) + + it('works, slice, A1') + + it('works, slice, RGB30') + + it('works, assignment', function () { + var ctx = createTestCanvas() + var data = ctx.getImageData(0, 0, 5, 5).data + data[0] = 50 + assert.equal(50, data[0]) + data[0] = 280 + assert.equal(255, data[0]) + data[0] = -4444 + assert.equal(0, data[0]) + }) + + it('throws if indexes are invalid', function () { + var ctx = createTestCanvas() + assert.throws(function () { ctx.getImageData(0, 0, 0, 0) }, /IndexSizeError/) + }) + }) it('Context2d#createPattern(Canvas)', function () { - var pattern = createCanvas(2,2) - , checkers = pattern.getContext('2d'); + var pattern = createCanvas(2, 2) + + var checkers = pattern.getContext('2d') // white - checkers.fillStyle = '#fff'; - checkers.fillRect(0,0,2,2); + checkers.fillStyle = '#fff' + checkers.fillRect(0, 0, 2, 2) // black - checkers.fillStyle = '#000'; - checkers.fillRect(0,0,1,1); - checkers.fillRect(1,1,1,1); + checkers.fillStyle = '#000' + checkers.fillRect(0, 0, 1, 1) + checkers.fillRect(1, 1, 1, 1) - var imageData = checkers.getImageData(0,0,2,2); - assert.equal(2, imageData.width); - assert.equal(2, imageData.height); - assert.equal(16, imageData.data.length); + var imageData = checkers.getImageData(0, 0, 2, 2) + assert.equal(2, imageData.width) + assert.equal(2, imageData.height) + assert.equal(16, imageData.data.length) // (0,0) black - assert.equal(0, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(255, imageData.data[3]); + assert.equal(0, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(255, imageData.data[3]) // (1,0) white - assert.equal(255, imageData.data[4]); - assert.equal(255, imageData.data[5]); - assert.equal(255, imageData.data[6]); - assert.equal(255, imageData.data[7]); + assert.equal(255, imageData.data[4]) + assert.equal(255, imageData.data[5]) + assert.equal(255, imageData.data[6]) + assert.equal(255, imageData.data[7]) // (0,1) white - assert.equal(255, imageData.data[8]); - assert.equal(255, imageData.data[9]); - assert.equal(255, imageData.data[10]); - assert.equal(255, imageData.data[11]); + assert.equal(255, imageData.data[8]) + assert.equal(255, imageData.data[9]) + assert.equal(255, imageData.data[10]) + assert.equal(255, imageData.data[11]) // (1,1) black - assert.equal(0, imageData.data[12]); - assert.equal(0, imageData.data[13]); - assert.equal(0, imageData.data[14]); - assert.equal(255, imageData.data[15]); + assert.equal(0, imageData.data[12]) + assert.equal(0, imageData.data[13]) + assert.equal(0, imageData.data[14]) + assert.equal(255, imageData.data[15]) var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d') - , pattern = ctx.createPattern(pattern); - - ctx.fillStyle = pattern; - ctx.fillRect(0,0,20,20); - - var imageData = ctx.getImageData(0,0,20,20); - assert.equal(20, imageData.width); - assert.equal(20, imageData.height); - assert.equal(1600, imageData.data.length); - - var i=0, b = true; - while(i { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d') - , pattern = ctx.createPattern(img); - ctx.fillStyle = pattern; - ctx.fillRect(0,0,20,20); + var ctx = canvas.getContext('2d') + + var pattern = ctx.createPattern(img) + + ctx.fillStyle = pattern + ctx.fillRect(0, 0, 20, 20) - var imageData = ctx.getImageData(0,0,20,20); - assert.equal(20, imageData.width); - assert.equal(20, imageData.height); - assert.equal(1600, imageData.data.length); + var imageData = ctx.getImageData(0, 0, 20, 20) + assert.equal(20, imageData.width) + assert.equal(20, imageData.height) + assert.equal(1600, imageData.data.length) - var i=0, b = true; - while (i= 6) - obj[Symbol.toPrimitive] = function () { return 0.89; }; - else - obj.valueOf = function () { return 0.89; }; - ctx.resetTransform(); - testAngle(obj, 0.89); + var obj = Object.create(null) + if (+process.version.match(/\d+/) >= 6) { obj[Symbol.toPrimitive] = function () { return 0.89 } } else { obj.valueOf = function () { return 0.89 } } + ctx.resetTransform() + testAngle(obj, 0.89) // NaN - ctx.resetTransform(); - ctx.rotate(0.91); - testAngle(NaN, 0.91); + ctx.resetTransform() + ctx.rotate(0.91) + testAngle(NaN, 0.91) // Infinite value - ctx.resetTransform(); - ctx.rotate(0.94); - testAngle(-Infinity, 0.94); + ctx.resetTransform() + ctx.rotate(0.94) + testAngle(-Infinity, 0.94) - function testAngle(angle, expected){ - ctx.rotate(angle); + function testAngle (angle, expected) { + ctx.rotate(angle) - var mat = ctx.currentTransform; - var sin = Math.sin(expected); - var cos = Math.cos(expected); + var mat = ctx.currentTransform + var sin = Math.sin(expected) + var cos = Math.cos(expected) - assert.ok(Math.abs(mat.m11 - cos) < Number.EPSILON); - assert.ok(Math.abs(mat.m12 - sin) < Number.EPSILON); - assert.ok(Math.abs(mat.m21 + sin) < Number.EPSILON); - assert.ok(Math.abs(mat.m22 - cos) < Number.EPSILON); + assert.ok(Math.abs(mat.m11 - cos) < Number.EPSILON) + assert.ok(Math.abs(mat.m12 - sin) < Number.EPSILON) + assert.ok(Math.abs(mat.m21 + sin) < Number.EPSILON) + assert.ok(Math.abs(mat.m22 - cos) < Number.EPSILON) } - }); + }) it('Context2d#drawImage()', function () { - var canvas = createCanvas(500, 500); - var ctx = canvas.getContext('2d'); + var canvas = createCanvas(500, 500) + var ctx = canvas.getContext('2d') // Drawing canvas to itself - ctx.fillStyle = 'white'; - ctx.fillRect(0, 0, 500, 500); - ctx.fillStyle = 'black'; - ctx.fillRect(5, 5, 10, 10); - ctx.drawImage(canvas, 20, 20); - - var imgd = ctx.getImageData(0, 0, 500, 500); - var data = imgd.data; - var count = 0; - - for(var i = 0; i < 500 * 500 * 4; i += 4){ - if(data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0) - count++; + ctx.fillStyle = 'white' + ctx.fillRect(0, 0, 500, 500) + ctx.fillStyle = 'black' + ctx.fillRect(5, 5, 10, 10) + ctx.drawImage(canvas, 20, 20) + + var imgd = ctx.getImageData(0, 0, 500, 500) + var data = imgd.data + var count = 0 + + for (var i = 0; i < 500 * 500 * 4; i += 4) { + if (data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0) { count++ } } - assert.strictEqual(count, 10 * 10 * 2); + assert.strictEqual(count, 10 * 10 * 2) // Drawing zero-width image - ctx.drawImage(canvas, 0, 0, 0, 0, 0, 0, 0, 0); - ctx.drawImage(canvas, 0, 0, 0, 0, 1, 1, 1, 1); - ctx.drawImage(canvas, 1, 1, 1, 1, 0, 0, 0, 0); - ctx.fillStyle = 'white'; - ctx.fillRect(0, 0, 500, 500); - - imgd = ctx.getImageData(0, 0, 500, 500); - data = imgd.data; - count = 0; - - for(i = 0; i < 500 * 500 * 4; i += 4){ - if(data[i] === 255 && data[i + 1] === 255 && data[i + 2] === 255) - count++; + ctx.drawImage(canvas, 0, 0, 0, 0, 0, 0, 0, 0) + ctx.drawImage(canvas, 0, 0, 0, 0, 1, 1, 1, 1) + ctx.drawImage(canvas, 1, 1, 1, 1, 0, 0, 0, 0) + ctx.fillStyle = 'white' + ctx.fillRect(0, 0, 500, 500) + + imgd = ctx.getImageData(0, 0, 500, 500) + data = imgd.data + count = 0 + + for (i = 0; i < 500 * 500 * 4; i += 4) { + if (data[i] === 255 && data[i + 1] === 255 && data[i + 2] === 255) { count++ } } - assert.strictEqual(count, 500 * 500); - }); + assert.strictEqual(count, 500 * 500) + }) it('Context2d#SetFillColor()', function () { - var canvas = createCanvas(2, 2); - var ctx = canvas.getContext('2d'); + var canvas = createCanvas(2, 2) + var ctx = canvas.getContext('2d') - ctx.fillStyle = ['#808080']; - ctx.fillRect(0, 0, 2, 2); - var data = ctx.getImageData(0, 0, 2, 2).data; + ctx.fillStyle = ['#808080'] + ctx.fillRect(0, 0, 2, 2) + var data = ctx.getImageData(0, 0, 2, 2).data data.forEach(function (byte, index) { - if (index + 1 & 3) - assert.strictEqual(byte, 128); - else - assert.strictEqual(byte, 255); - }); + if (index + 1 & 3) { assert.strictEqual(byte, 128) } else { assert.strictEqual(byte, 255) } + }) assert.throws(function () { - ctx.fillStyle = Object.create(null); - }); - }); - -}); + ctx.fillStyle = Object.create(null) + }) + }) +}) diff --git a/test/dommatrix.test.js b/test/dommatrix.test.js index 212ce40a4..0386417b7 100644 --- a/test/dommatrix.test.js +++ b/test/dommatrix.test.js @@ -9,22 +9,22 @@ const assert = require('assert') // This doesn't need to be precise; we're not testing the engine's trig // implementations. const TOLERANCE = 0.001 -function assertApprox(actual, expected, tolerance) { +function assertApprox (actual, expected, tolerance) { if (typeof tolerance !== 'number') tolerance = TOLERANCE assert.ok(expected > actual - tolerance && expected < actual + tolerance, `Expected ${expected} to equal ${actual} +/- ${tolerance}`) } -function assertApproxDeep(actual, expected, tolerance) { +function assertApproxDeep (actual, expected, tolerance) { expected.forEach(function (value, index) { assertApprox(actual[index], value) }) } describe('DOMMatrix', function () { - var Avals = [4,5,1,8, 0,3,6,1, 3,5,0,9, 2,4,6,1] - var Bvals = [1,5,1,0, 0,3,6,1, 3,5,7,2, 2,0,6,1] - var AxB = [7,25,31,22, 20,43,24,58, 37,73,45,94, 28,44,8,71] - var BxA = [23,40,89,15, 20,39,66,16, 21,30,87,14, 22,52,74,17] + var Avals = [4, 5, 1, 8, 0, 3, 6, 1, 3, 5, 0, 9, 2, 4, 6, 1] + var Bvals = [1, 5, 1, 0, 0, 3, 6, 1, 3, 5, 7, 2, 2, 0, 6, 1] + var AxB = [7, 25, 31, 22, 20, 43, 24, 58, 37, 73, 45, 94, 28, 44, 8, 71] + var BxA = [23, 40, 89, 15, 20, 39, 66, 16, 21, 30, 87, 14, 22, 52, 74, 17] describe('constructor, general', function () { it('aliases a,b,c,d,e,f properly', function () { @@ -374,7 +374,7 @@ describe('DOMMatrix', function () { }) describe('skewYSelf', function () {}) - + describe('flipX', function () { it('works', function () { var x = new DOMMatrix() @@ -409,14 +409,14 @@ describe('DOMMatrix', function () { describe('transformPoint', function () { it('works', function () { var x = new DOMMatrix() - var r = x.transformPoint({x: 1, y: 2, z: 3}) + var r = x.transformPoint({ x: 1, y: 2, z: 3 }) assert.strictEqual(r.x, 1) assert.strictEqual(r.y, 2) assert.strictEqual(r.z, 3) assert.strictEqual(r.w, 1) x.rotateSelf(70) - r = x.transformPoint({x: 2, y: 3, z: 4}) + r = x.transformPoint({ x: 2, y: 3, z: 4 }) assertApprox(r.x, -2.13503) assertApprox(r.y, 2.905445) assert.strictEqual(r.z, 4) @@ -437,7 +437,7 @@ describe('DOMMatrix', function () { ]) }) }) - + describe('toFloat64Array', function () { it('works', function () { var x = new DOMMatrix() diff --git a/test/image.test.js b/test/image.test.js index 8e79cae2f..e06642c65 100644 --- a/test/image.test.js +++ b/test/image.test.js @@ -6,7 +6,7 @@ * Module dependencies. */ -const {createCanvas, loadImage} = require('../'); +const { createCanvas, loadImage } = require('../') const Image = require('../').Image const assert = require('assert') @@ -23,12 +23,12 @@ const bmp_dir = `${__dirname}/fixtures/bmp` describe('Image', function () { it('Prototype and ctor are well-shaped, don\'t hit asserts on accessors (GH-803)', function () { - var img = new Image(); - assert.throws(function () { Image.prototype.width; }, /incompatible receiver/); - assert(!img.hasOwnProperty('width')); - assert('width' in img); - assert(Image.prototype.hasOwnProperty('width')); - }); + var img = new Image() + assert.throws(function () { Image.prototype.width }, /incompatible receiver/) + assert(!img.hasOwnProperty('width')) + assert('width' in img) + assert(Image.prototype.hasOwnProperty('width')) + }) it('loads JPEG image', function () { return loadImage(jpg_face).then((img) => { @@ -87,7 +87,7 @@ describe('Image', function () { it('loads SVG data URL base64', function () { const base64Enc = fs.readFileSync(svg_tree, 'base64') const dataURL = `data:image/svg+xml;base64,${base64Enc}` - return loadImage(dataURL).then((img) => { + return loadImage(dataURL).then((img) => { assert.strictEqual(img.onerror, null) assert.strictEqual(img.onload, null) assert.strictEqual(img.width, 200) @@ -99,7 +99,7 @@ describe('Image', function () { it('loads SVG data URL utf8', function () { const utf8Encoded = fs.readFileSync(svg_tree, 'utf8') const dataURL = `data:image/svg+xml;utf8,${utf8Encoded}` - return loadImage(dataURL).then((img) => { + return loadImage(dataURL).then((img) => { assert.strictEqual(img.onerror, null) assert.strictEqual(img.onload, null) assert.strictEqual(img.width, 200) @@ -154,7 +154,7 @@ describe('Image', function () { it('captures errors from libjpeg', function (done) { const img = new Image() img.onerror = err => { - assert.equal(err.message, "JPEG datastream contains no image") + assert.equal(err.message, 'JPEG datastream contains no image') done() } img.src = `${__dirname}/fixtures/159-crash1.jpg` @@ -213,7 +213,7 @@ describe('Image', function () { }) }) - it('should unbind Image#onload', function() { + it('should unbind Image#onload', function () { return loadImage(png_clock).then((img) => { let onloadCalled = 0 @@ -240,7 +240,7 @@ describe('Image', function () { }) }) - it('should unbind Image#onerror', function() { + it('should unbind Image#onerror', function () { return loadImage(png_clock).then((img) => { let onloadCalled = 0 let onerrorCalled = 0 @@ -297,53 +297,53 @@ describe('Image', function () { }) it('does not contain `source` property', function () { - var keys = Reflect.ownKeys(Image.prototype); - assert.ok(!keys.includes('source')); - assert.ok(!keys.includes('getSource')); - assert.ok(!keys.includes('setSource')); - }); + var keys = Reflect.ownKeys(Image.prototype) + assert.ok(!keys.includes('source')) + assert.ok(!keys.includes('getSource')) + assert.ok(!keys.includes('setSource')) + }) describe('supports BMP', function () { it('parses 1-bit image', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - assert.strictEqual(img.width, 111); - assert.strictEqual(img.height, 72); - done(); - }; + assert.strictEqual(img.width, 111) + assert.strictEqual(img.height, 72) + done() + } - img.onerror = err => { throw err; }; - img.src = path.join(bmp_dir, '1-bit.bmp'); - }); + img.onerror = err => { throw err } + img.src = path.join(bmp_dir, '1-bit.bmp') + }) it('parses 24-bit image', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - assert.strictEqual(img.width, 2); - assert.strictEqual(img.height, 2); + assert.strictEqual(img.width, 2) + assert.strictEqual(img.height, 2) testImgd(img, [ 0, 0, 255, 255, 0, 255, 0, 255, 255, 0, 0, 255, - 255, 255, 255, 255, - ]); + 255, 255, 255, 255 + ]) - done(); - }; + done() + } - img.onerror = err => { throw err; }; - img.src = path.join(bmp_dir, '24-bit.bmp'); - }); + img.onerror = err => { throw err } + img.src = path.join(bmp_dir, '24-bit.bmp') + }) it('parses 32-bit image', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - assert.strictEqual(img.width, 4); - assert.strictEqual(img.height, 2); + assert.strictEqual(img.width, 4) + assert.strictEqual(img.height, 2) testImgd(img, [ 0, 0, 255, 255, @@ -353,88 +353,88 @@ describe('Image', function () { 0, 0, 255, 127, 0, 255, 0, 127, 255, 0, 0, 127, - 255, 255, 255, 127, - ]); - - done(); - }; + 255, 255, 255, 127 + ]) - img.onerror = err => { throw err; }; - img.src = fs.readFileSync(path.join(bmp_dir, '32-bit.bmp')); // Also tests loading from buffer - }); + done() + } + + img.onerror = err => { throw err } + img.src = fs.readFileSync(path.join(bmp_dir, '32-bit.bmp')) // Also tests loading from buffer + }) it('parses minimal BMP', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - assert.strictEqual(img.width, 1); - assert.strictEqual(img.height, 1); + assert.strictEqual(img.width, 1) + assert.strictEqual(img.height, 1) testImgd(img, [ - 255, 0, 0, 255, - ]); - - done(); - }; + 255, 0, 0, 255 + ]) + + done() + } - img.onerror = err => { throw err; }; - img.src = path.join(bmp_dir, 'min.bmp'); - }); + img.onerror = err => { throw err } + img.src = path.join(bmp_dir, 'min.bmp') + }) it('properly handles negative height', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - assert.strictEqual(img.width, 1); - assert.strictEqual(img.height, 2); + assert.strictEqual(img.width, 1) + assert.strictEqual(img.height, 2) testImgd(img, [ 255, 0, 0, 255, - 0, 255, 0, 255, - ]); - - done(); - }; + 0, 255, 0, 255 + ]) - img.onerror = err => { throw err; }; - img.src = path.join(bmp_dir, 'negative-height.bmp'); - }); + done() + } + + img.onerror = err => { throw err } + img.src = path.join(bmp_dir, 'negative-height.bmp') + }) it('catches BMP errors', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - throw new Error('Invalid image should not be loaded properly'); - }; + throw new Error('Invalid image should not be loaded properly') + } img.onerror = err => { - let msg = 'Error while processing file header - unexpected end of file'; - assert.strictEqual(err.message, msg); - done(); - }; + let msg = 'Error while processing file header - unexpected end of file' + assert.strictEqual(err.message, msg) + done() + } - img.src = Buffer.from('BM'); - }); + img.src = Buffer.from('BM') + }) it('BMP bomb', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - throw new Error('Invalid image should not be loaded properly'); - }; + throw new Error('Invalid image should not be loaded properly') + } img.onerror = err => { - done(); - }; + done() + } - img.src = path.join(bmp_dir, 'bomb.bmp'); - }); + img.src = path.join(bmp_dir, 'bomb.bmp') + }) - function testImgd(img, data){ - let ctx = createCanvas(img.width, img.height).getContext('2d'); - ctx.drawImage(img, 0, 0); - var actualData = ctx.getImageData(0, 0, img.width, img.height).data; - assert.strictEqual(String(actualData), String(data)); + function testImgd (img, data) { + let ctx = createCanvas(img.width, img.height).getContext('2d') + ctx.drawImage(img, 0, 0) + var actualData = ctx.getImageData(0, 0, img.width, img.height).data + assert.strictEqual(String(actualData), String(data)) } - }); + }) }) diff --git a/test/imageData.test.js b/test/imageData.test.js index cfffe9aaf..26acd61f4 100644 --- a/test/imageData.test.js +++ b/test/imageData.test.js @@ -3,14 +3,14 @@ 'use strict' const createImageData = require('../').createImageData -const ImageData = require('../').ImageData; +const ImageData = require('../').ImageData const assert = require('assert') describe('ImageData', function () { it('Prototype and ctor are well-shaped, don\'t hit asserts on accessors (GH-803)', function () { - assert.throws(function () { ImageData.prototype.width; }, /incompatible receiver/); - }); + assert.throws(function () { ImageData.prototype.width }, /incompatible receiver/) + }) it('should throw with invalid numeric arguments', function () { assert.throws(() => { createImageData(0, 0) }, /width is zero/) @@ -33,7 +33,7 @@ describe('ImageData', function () { assert.throws(() => { createImageData(new Uint8ClampedArray(3), 0) }, /source width is zero/) // Note: Some errors thrown by browsers are not thrown by node-canvas // because our ImageData can support different BPPs. - }); + }) it('should construct with Uint8ClampedArray', function () { let data, imageData @@ -51,7 +51,7 @@ describe('ImageData', function () { assert.strictEqual(imageData.height, 4) assert(imageData.data instanceof Uint8ClampedArray) assert.strictEqual(imageData.data.length, 48) - }); + }) it('should construct with Uint16Array', function () { let data = new Uint16Array(2 * 3 * 2) @@ -67,5 +67,5 @@ describe('ImageData', function () { assert.strictEqual(imagedata.height, 4) assert(imagedata.data instanceof Uint16Array) assert.strictEqual(imagedata.data.length, 24) - }); -}); + }) +}) diff --git a/util/has_lib.js b/util/has_lib.js index e0e042433..7eb4d361a 100644 --- a/util/has_lib.js +++ b/util/has_lib.js @@ -32,7 +32,7 @@ function _hasQuery (query) { function hasSystemLib (lib) { var libName = 'lib' + lib + '.+(so|dylib)' - // Try using ldconfig on linux systems + // Try using ldconfig on linux systems if (_hasQuery('ldconfig -p 2>/dev/null | grep -E "' + libName + '"')) { return true } diff --git a/util/win_jpeg_lookup.js b/util/win_jpeg_lookup.js index 82869945a..40a1e03cf 100644 --- a/util/win_jpeg_lookup.js +++ b/util/win_jpeg_lookup.js @@ -5,17 +5,17 @@ if (process.arch === 'x64') { paths.unshift('C:/libjpeg-turbo64') } -paths.forEach(function(path){ +paths.forEach(function (path) { if (exists(path)) { process.stdout.write(path) process.exit() } }) -function exists(path) { +function exists (path) { try { return fs.lstatSync(path).isDirectory() - } catch(e) { + } catch (e) { return false } } From fc2c12b78c0feabc9bc96e89b890c89aab23e863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 19 Nov 2018 13:27:43 +0100 Subject: [PATCH 076/183] Updated code and restore back FbDev support (X11 is buggy and disabled) --- examples/simple_fbdev.js | 4 ++-- src/Canvas.cc | 11 ++++++----- src/backend/Backend.cc | 1 - 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/simple_fbdev.js b/examples/simple_fbdev.js index 66f8f2906..a1f28df5c 100755 --- a/examples/simple_fbdev.js +++ b/examples/simple_fbdev.js @@ -7,13 +7,13 @@ const fs = require('fs') const { join } = require('path') -var Canvas = require('..') +const { backends: { FBDevBackend }, Canvas } = require('..') const squareSize = 100 var device = process.argv[2] || '/dev/fb0' -var backend = new Canvas.backends.FBDevBackend(device) +var backend = new FBDevBackend(device) var canvas = new Canvas(backend) var ctx = canvas.getContext('2d') diff --git a/src/Canvas.cc b/src/Canvas.cc index eb68462a7..05ef86429 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -105,7 +105,8 @@ NAN_METHOD(Canvas::New) { backend = new ImageBackend(width, height); } else if (info[0]->IsObject()) { - if (Nan::New(ImageBackend::constructor)->HasInstance(info[0]) || + if (Nan::New(FBDevBackend::constructor)->HasInstance(info[0]) || + Nan::New(ImageBackend::constructor)->HasInstance(info[0]) || Nan::New(PdfBackend::constructor)->HasInstance(info[0]) || Nan::New(SvgBackend::constructor)->HasInstance(info[0])) { backend = Nan::ObjectWrap::Unwrap(Nan::To(info[0]).ToLocalChecked()); @@ -272,7 +273,7 @@ static void parsePNGArgs(Local arg, PngClosure& pngargs) { static void parseJPEGArgs(Local arg, JpegClosure& jpegargs) { // "If Type(quality) is not Number, or if quality is outside that range, the - // user agent must use its default quality value, as if the quality argument + // user agent must use its default quality value, as if the quality argument // had not been given." - 4.12.5.5 if (arg->IsObject()) { Local obj = Nan::To(arg).ToLocalChecked(); @@ -451,9 +452,9 @@ NAN_METHOD(Canvas::ToBuffer) { Nan::ThrowError(Canvas::Error(ex)); return; } - + parseJPEGArgs(info[1], *closure); - + // TODO: only one callback fn in closure // TODO what does this comment mean? canvas->Ref(); closure->pfn = new Nan::Callback(info[0].As()); @@ -495,7 +496,7 @@ streamPNG(void *c, const uint8_t *data, unsigned len) { NAN_METHOD(Canvas::StreamPNGSync) { if (!info[0]->IsFunction()) return Nan::ThrowTypeError("callback function required"); - + Canvas *canvas = Nan::ObjectWrap::Unwrap(info.This()); PngClosure closure(canvas); diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 2f58c8a72..0b4c533d2 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -7,7 +7,6 @@ Backend::Backend(string name) , height(0) , surface(NULL) , canvas(NULL) - , _closure(NULL) {} Backend::Backend(string name, int width, int height) : name(name) From ad0a41f41e394f85ee94c8b17b470f0350fa1ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 19 Nov 2018 16:24:55 +0100 Subject: [PATCH 077/183] Extracted code for FbDev support from #571 to make it easier to review and approve. It's a squashed version with the final code, for references on the development history and commit logs go to the original issue. --- binding.gyp | 10 ++- examples/simple_fbdev.js | 39 ++++++++++ src/Backends.cc | 8 +++ src/Canvas.cc | 4 +- src/backend/Backend.cc | 7 ++ src/backend/Backend.h | 1 + src/backend/FBDevBackend.cc | 140 ++++++++++++++++++++++++++++++++++++ src/backend/FBDevBackend.h | 35 +++++++++ 8 files changed, 242 insertions(+), 2 deletions(-) create mode 100644 examples/simple_fbdev.js create mode 100644 src/backend/FBDevBackend.cc create mode 100644 src/backend/FBDevBackend.h diff --git a/binding.gyp b/binding.gyp index e770b86c7..5d11e00d1 100644 --- a/binding.gyp +++ b/binding.gyp @@ -145,6 +145,11 @@ 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES' } }], + ['has_FBDev=="true"', + { + 'defines': ['HAS_FBDEV'], + 'sources': ['src/backend/FBDevBackend.cc'] + }], ['with_jpeg=="true"', { 'defines': [ 'HAVE_JPEG' @@ -216,7 +221,10 @@ }] ] }] - ] + ], + 'variables': { + 'has_FBDev%': 'true', + } } ] } diff --git a/examples/simple_fbdev.js b/examples/simple_fbdev.js new file mode 100644 index 000000000..a1f28df5c --- /dev/null +++ b/examples/simple_fbdev.js @@ -0,0 +1,39 @@ +#!/usr/bin/env node + +/** +* Module dependencies. +*/ + +const fs = require('fs') +const { join } = require('path') + +const { backends: { FBDevBackend }, Canvas } = require('..') + +const squareSize = 100 + +var device = process.argv[2] || '/dev/fb0' + +var backend = new FBDevBackend(device) +var canvas = new Canvas(backend) +var ctx = canvas.getContext('2d') + +var offsetX = canvas.width - squareSize +var offsetY = canvas.height - squareSize + +ctx.fillStyle = '#FF0000' +ctx.fillRect(0, 0, squareSize, squareSize) + +ctx.fillStyle = '#00FF00' +ctx.fillRect(offsetX, 0, squareSize, squareSize) + +ctx.fillStyle = '#0000FF' +ctx.fillRect(0, offsetY, squareSize, squareSize) + +ctx.fillStyle = '#FFFFFF' +ctx.fillRect(offsetX, offsetY, squareSize, squareSize) + +console.log('Width: ' + canvas.width + ', Height: ' + canvas.height) + +var outPath = join(__dirname, 'rectangle.png') + +canvas.createPNGStream().pipe(fs.createWriteStream(outPath)) diff --git a/src/Backends.cc b/src/Backends.cc index 6490ab6e0..880ae076d 100644 --- a/src/Backends.cc +++ b/src/Backends.cc @@ -4,6 +4,10 @@ #include "backend/PdfBackend.h" #include "backend/SvgBackend.h" +#ifdef HAS_FBDEV +#include "backend/FBDevBackend.h" +#endif + using namespace v8; void Backends::Initialize(Handle target) { @@ -14,5 +18,9 @@ void Backends::Initialize(Handle target) { PdfBackend::Initialize(obj); SvgBackend::Initialize(obj); + #ifdef HAS_FBDEV + FBDevBackend::Initialize(obj); + #endif + target->Set(Nan::New("Backends").ToLocalChecked(), obj); } diff --git a/src/Canvas.cc b/src/Canvas.cc index 1ffed6b3d..e7d97259b 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -25,6 +25,7 @@ #include "JPEGStream.h" #endif +#include "backend/FBDevBackend.h" #include "backend/ImageBackend.h" #include "backend/PdfBackend.h" #include "backend/SvgBackend.h" @@ -104,7 +105,8 @@ NAN_METHOD(Canvas::New) { backend = new ImageBackend(width, height); } else if (info[0]->IsObject()) { - if (Nan::New(ImageBackend::constructor)->HasInstance(info[0]) || + if (Nan::New(FBDevBackend::constructor)->HasInstance(info[0]) || + Nan::New(ImageBackend::constructor)->HasInstance(info[0]) || Nan::New(PdfBackend::constructor)->HasInstance(info[0]) || Nan::New(SvgBackend::constructor)->HasInstance(info[0])) { backend = Nan::ObjectWrap::Unwrap(Nan::To(info[0]).ToLocalChecked()); diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 34ef541f5..0ea3b7af2 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -1,6 +1,13 @@ #include "Backend.h" +Backend::Backend(string name) + : name(name) + , width(0) + , height(0) + , surface(NULL) + , canvas(NULL) +{} Backend::Backend(string name, int width, int height) : name(name) , width(width) diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 75ae37aad..5bbc80f4e 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -28,6 +28,7 @@ class Backend : public Nan::ObjectWrap cairo_surface_t* surface; Canvas* canvas; + Backend(string name); Backend(string name, int width, int height); static void init(const Nan::FunctionCallbackInfo &info); static Backend *construct(int width, int height){ return nullptr; } diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc new file mode 100644 index 000000000..581be177c --- /dev/null +++ b/src/backend/FBDevBackend.cc @@ -0,0 +1,140 @@ +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "FBDevBackend.h" + + +using namespace v8; + + +FBDevBackend::FBDevBackend(string deviceName) + : Backend("fbdev") +{ + // Open the file for reading and writing + this->fb_fd = open(deviceName.c_str(), O_RDWR); + + if(this->fb_fd == -1) + { + std::ostringstream o; + o << "cannot open framebuffer device \"" << deviceName << "\""; + throw FBDevBackendException(o.str()); + } + + this->FbDevIoctlHelper(FBIOGET_FSCREENINFO, &this->fb_finfo, + "Error reading fixed framebuffer information"); + + // Map the device to memory + this->fb_data = (unsigned char*) mmap(0, this->fb_finfo.smem_len, + PROT_READ | PROT_WRITE, MAP_SHARED, this->fb_fd, 0); + + if(this->fb_data == MAP_FAILED) + throw FBDevBackendException("Failed to map framebuffer device to memory"); +} + +FBDevBackend::~FBDevBackend() +{ + this->destroySurface(); + + munmap(this->fb_data, this->fb_finfo.smem_len); + close(this->fb_fd); +} + + +void FBDevBackend::FbDevIoctlHelper(unsigned long request, void* data, + string errmsg) +{ + if(ioctl(this->fb_fd, request, data) == -1) + throw FBDevBackendException(errmsg.c_str()); +} + + +cairo_surface_t* FBDevBackend::createSurface() +{ + struct fb_var_screeninfo fb_vinfo; + + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, + "Error reading variable framebuffer information"); + + this->width = fb_vinfo.xres; + this->height = fb_vinfo.yres; + + // switch through bpp and decide on which format for the cairo surface to use + cairo_format_t format; + switch(fb_vinfo.bits_per_pixel) + { + case 16: format = CAIRO_FORMAT_RGB16_565; break; + case 32: format = CAIRO_FORMAT_ARGB32; break; + + default: + throw FBDevBackendException("Only valid formats are RGB16_565 & ARGB32"); + } + + // create cairo surface from data + this->surface = cairo_image_surface_create_for_data(this->fb_data, format, + this->width, this->height, fb_finfo.line_length); + + return this->surface; +} + + +void FBDevBackend::setWidth(int width) +{ + struct fb_var_screeninfo fb_vinfo; + + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, + "Error reading variable framebuffer information"); + + fb_vinfo.xres = width; + + this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, + "Error setting variable framebuffer information"); + + Backend::setWidth(width); +} +void FBDevBackend::setHeight(int height) +{ + struct fb_var_screeninfo fb_vinfo; + + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, + "Error reading variable framebuffer information"); + + fb_vinfo.yres = height; + + this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, + "Error setting variable framebuffer information"); + + Backend::setHeight(width); +} + + +Nan::Persistent FBDevBackend::constructor; + +void FBDevBackend::Initialize(Handle target) +{ + Nan::HandleScope scope; + + Local ctor = Nan::New(FBDevBackend::New); + FBDevBackend::constructor.Reset(ctor); + ctor->InstanceTemplate()->SetInternalFieldCount(1); + ctor->SetClassName(Nan::New("FBDevBackend").ToLocalChecked()); + target->Set(Nan::New("FBDevBackend").ToLocalChecked(), ctor->GetFunction()); +} + +NAN_METHOD(FBDevBackend::New) +{ + string fbDevice = "/dev/fb0"; + if(info[0]->IsString()) fbDevice = *String::Utf8Value(info[0].As()); + + FBDevBackend* backend = new FBDevBackend(fbDevice); + + backend->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); +} diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h new file mode 100644 index 000000000..55e90e51c --- /dev/null +++ b/src/backend/FBDevBackend.h @@ -0,0 +1,35 @@ +#ifndef __FBDEV_BACKEND_H__ +#define __FBDEV_BACKEND_H__ + #include +#include + #include + #include + #include "Backend.h" + using namespace std; + class FBDevBackend : public Backend +{ + private: + int fb_fd; + struct fb_fix_screeninfo fb_finfo; + unsigned char* fb_data; + ~FBDevBackend(); + void FbDevIoctlHelper(unsigned long request, void* data, string errmsg); + cairo_surface_t* createSurface(); + void setWidth(int width); + void setHeight(int height); + public: + FBDevBackend(string deviceName); + static Nan::Persistent constructor; + static void Initialize(v8::Handle target); + static NAN_METHOD(New); +}; + class FBDevBackendException : public std::exception +{ + private: + string err_msg; + public: + FBDevBackendException(const string msg) : err_msg(msg) {}; + ~FBDevBackendException() throw() {}; + const char *what() const throw() { return this->err_msg.c_str(); }; +}; + #endif From 3a1d55d6e8313731a296f447a712ad6877c67bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 20 Nov 2018 02:01:53 +0100 Subject: [PATCH 078/183] Fix linting --- benchmarks/run.js | 10 +- lib/DOMMatrix.js | 96 +- lib/bindings.js | 4 +- lib/canvas.js | 86 +- lib/context2d.js | 152 +-- lib/image.js | 56 +- lib/jpegstream.js | 42 +- lib/parse-font.js | 19 +- lib/pdfstream.js | 38 +- lib/pngstream.js | 42 +- test/canvas.test.js | 2397 ++++++++++++++++++++------------------- test/dommatrix.test.js | 20 +- test/image.test.js | 180 +-- test/imageData.test.js | 14 +- util/win_jpeg_lookup.js | 6 +- 15 files changed, 1594 insertions(+), 1568 deletions(-) diff --git a/benchmarks/run.js b/benchmarks/run.js index e088e0692..4914ea97b 100644 --- a/benchmarks/run.js +++ b/benchmarks/run.js @@ -65,8 +65,8 @@ function done (benchmark, times, start, isAsync) { // node-canvas bm('fillStyle= name', function () { - ctx.fillStyle = "transparent"; -}); + ctx.fillStyle = 'transparent' +}) bm('lineTo()', function () { ctx.lineTo(0, 50) @@ -138,11 +138,11 @@ bm('moveTo() / arc() / stroke()', function () { ctx.beginPath() ctx.arc(75, 75, 50, 0, Math.PI * 2, true) // Outer circle ctx.moveTo(110, 75) - ctx.arc(75, 75, 35, 0, Math.PI, false) // Mouth + ctx.arc(75, 75, 35, 0, Math.PI, false) // Mouth ctx.moveTo(65, 65) - ctx.arc(60, 65, 5, 0, Math.PI * 2, true) // Left eye + ctx.arc(60, 65, 5, 0, Math.PI * 2, true) // Left eye ctx.moveTo(95, 65) - ctx.arc(90, 65, 5, 0, Math.PI * 2, true) // Right eye + ctx.arc(90, 65, 5, 0, Math.PI * 2, true) // Right eye ctx.stroke() }) diff --git a/lib/DOMMatrix.js b/lib/DOMMatrix.js index 3c5262449..cf4485395 100644 --- a/lib/DOMMatrix.js +++ b/lib/DOMMatrix.js @@ -2,7 +2,7 @@ // DOMMatrix per https://drafts.fxtf.org/geometry/#DOMMatrix -function DOMPoint(x, y, z, w) { +function DOMPoint (x, y, z, w) { if (!(this instanceof DOMPoint)) { throw new TypeError("Class constructors cannot be invoked without 'new'") } @@ -20,15 +20,15 @@ function DOMPoint(x, y, z, w) { } // Constants to index into _values (col-major) -const M11 = 0, M12 = 1, M13 = 2, M14 = 3 -const M21 = 4, M22 = 5, M23 = 6, M24 = 7 -const M31 = 8, M32 = 9, M33 = 10, M34 = 11 -const M41 = 12, M42 = 13, M43 = 14, M44 = 15 +const M11 = 0; const M12 = 1; const M13 = 2; const M14 = 3 +const M21 = 4; const M22 = 5; const M23 = 6; const M24 = 7 +const M31 = 8; const M32 = 9; const M33 = 10; const M34 = 11 +const M41 = 12; const M42 = 13; const M43 = 14; const M44 = 15 const DEGREE_PER_RAD = 180 / Math.PI const RAD_PER_DEGREE = Math.PI / 180 -function parseMatrix(init) { +function parseMatrix (init) { var parsed = init.replace(/matrix\(/, '') parsed = parsed.split(/,/, 7) // 6 + 1 to handle too many params if (parsed.length !== 6) throw new Error(`Failed to parse ${init}`) @@ -41,14 +41,14 @@ function parseMatrix(init) { ] } -function parseMatrix3d(init) { +function parseMatrix3d (init) { var parsed = init.replace(/matrix3d\(/, '') parsed = parsed.split(/,/, 17) // 16 + 1 to handle too many params if (parsed.length !== 16) throw new Error(`Failed to parse ${init}`) return parsed.map(parseFloat) } -function parseTransform(tform) { +function parseTransform (tform) { var type = tform.split(/\(/, 1)[0] switch (type) { case 'matrix': @@ -158,15 +158,15 @@ DOMMatrix.prototype.inspect = function (depth, options) { } DOMMatrix.prototype.toString = function () { - return this.is2D ? - `matrix(${this.a}, ${this.b}, ${this.c}, ${this.d}, ${this.e}, ${this.f})` : - `matrix3d(${this._values.join(', ')})` + return this.is2D + ? `matrix(${this.a}, ${this.b}, ${this.c}, ${this.d}, ${this.e}, ${this.f})` + : `matrix3d(${this._values.join(', ')})` } /** * Checks that `value` is a number and sets the value. */ -function setNumber2D(receiver, index, value) { +function setNumber2D (receiver, index, value) { if (typeof value !== 'number') throw new TypeError('Expected number') return receiver._values[index] = value } @@ -175,7 +175,7 @@ function setNumber2D(receiver, index, value) { * Checks that `value` is a number, sets `_is2D = false` if necessary and sets * the value. */ -function setNumber3D(receiver, index, value) { +function setNumber3D (receiver, index, value) { if (typeof value !== 'number') throw new TypeError('Expected number') if (index === M33 || index === M44) { if (value !== 1) receiver._is2D = false @@ -184,31 +184,31 @@ function setNumber3D(receiver, index, value) { } Object.defineProperties(DOMMatrix.prototype, { - m11: {get: function () { return this._values[M11] }, set: function (v) { return setNumber2D(this, M11, v) }}, - m12: {get: function () { return this._values[M12] }, set: function (v) { return setNumber2D(this, M12, v) }}, - m13: {get: function () { return this._values[M13] }, set: function (v) { return setNumber3D(this, M13, v) }}, - m14: {get: function () { return this._values[M14] }, set: function (v) { return setNumber3D(this, M14, v) }}, - m21: {get: function () { return this._values[M21] }, set: function (v) { return setNumber2D(this, M21, v) }}, - m22: {get: function () { return this._values[M22] }, set: function (v) { return setNumber2D(this, M22, v) }}, - m23: {get: function () { return this._values[M23] }, set: function (v) { return setNumber3D(this, M23, v) }}, - m24: {get: function () { return this._values[M24] }, set: function (v) { return setNumber3D(this, M24, v) }}, - m31: {get: function () { return this._values[M31] }, set: function (v) { return setNumber3D(this, M31, v) }}, - m32: {get: function () { return this._values[M32] }, set: function (v) { return setNumber3D(this, M32, v) }}, - m33: {get: function () { return this._values[M33] }, set: function (v) { return setNumber3D(this, M33, v) }}, - m34: {get: function () { return this._values[M34] }, set: function (v) { return setNumber3D(this, M34, v) }}, - m41: {get: function () { return this._values[M41] }, set: function (v) { return setNumber2D(this, M41, v) }}, - m42: {get: function () { return this._values[M42] }, set: function (v) { return setNumber2D(this, M42, v) }}, - m43: {get: function () { return this._values[M43] }, set: function (v) { return setNumber3D(this, M43, v) }}, - m44: {get: function () { return this._values[M44] }, set: function (v) { return setNumber3D(this, M44, v) }}, - - a: {get: function () { return this.m11 }, set: function (v) { return this.m11 = v }}, - b: {get: function () { return this.m12 }, set: function (v) { return this.m12 = v }}, - c: {get: function () { return this.m21 }, set: function (v) { return this.m21 = v }}, - d: {get: function () { return this.m22 }, set: function (v) { return this.m22 = v }}, - e: {get: function () { return this.m41 }, set: function (v) { return this.m41 = v }}, - f: {get: function () { return this.m42 }, set: function (v) { return this.m42 = v }}, - - is2D: {get: function () { return this._is2D }}, // read-only + m11: { get: function () { return this._values[M11] }, set: function (v) { return setNumber2D(this, M11, v) } }, + m12: { get: function () { return this._values[M12] }, set: function (v) { return setNumber2D(this, M12, v) } }, + m13: { get: function () { return this._values[M13] }, set: function (v) { return setNumber3D(this, M13, v) } }, + m14: { get: function () { return this._values[M14] }, set: function (v) { return setNumber3D(this, M14, v) } }, + m21: { get: function () { return this._values[M21] }, set: function (v) { return setNumber2D(this, M21, v) } }, + m22: { get: function () { return this._values[M22] }, set: function (v) { return setNumber2D(this, M22, v) } }, + m23: { get: function () { return this._values[M23] }, set: function (v) { return setNumber3D(this, M23, v) } }, + m24: { get: function () { return this._values[M24] }, set: function (v) { return setNumber3D(this, M24, v) } }, + m31: { get: function () { return this._values[M31] }, set: function (v) { return setNumber3D(this, M31, v) } }, + m32: { get: function () { return this._values[M32] }, set: function (v) { return setNumber3D(this, M32, v) } }, + m33: { get: function () { return this._values[M33] }, set: function (v) { return setNumber3D(this, M33, v) } }, + m34: { get: function () { return this._values[M34] }, set: function (v) { return setNumber3D(this, M34, v) } }, + m41: { get: function () { return this._values[M41] }, set: function (v) { return setNumber2D(this, M41, v) } }, + m42: { get: function () { return this._values[M42] }, set: function (v) { return setNumber2D(this, M42, v) } }, + m43: { get: function () { return this._values[M43] }, set: function (v) { return setNumber3D(this, M43, v) } }, + m44: { get: function () { return this._values[M44] }, set: function (v) { return setNumber3D(this, M44, v) } }, + + a: { get: function () { return this.m11 }, set: function (v) { return this.m11 = v } }, + b: { get: function () { return this.m12 }, set: function (v) { return this.m12 = v } }, + c: { get: function () { return this.m21 }, set: function (v) { return this.m21 = v } }, + d: { get: function () { return this.m22 }, set: function (v) { return this.m22 = v } }, + e: { get: function () { return this.m41 }, set: function (v) { return this.m41 = v } }, + f: { get: function () { return this.m42 }, set: function (v) { return this.m42 = v } }, + + is2D: { get: function () { return this._is2D } }, // read-only isIdentity: { get: function () { @@ -226,7 +226,7 @@ Object.defineProperties(DOMMatrix.prototype, { * @param {Float64Array} values Value to assign to `_values`. This is assigned * without copying (okay because all usages are followed by a multiply). */ -function newInstance(values) { +function newInstance (values) { var instance = Object.create(DOMMatrix.prototype) instance.constructor = DOMMatrix instance._is2D = true @@ -234,7 +234,7 @@ function newInstance(values) { return instance } -function multiply(A, B) { +function multiply (A, B) { var dest = new Float64Array(16) for (var i = 0; i < 4; i++) { for (var j = 0; j < 4; j++) { @@ -383,10 +383,10 @@ DOMMatrix.prototype.rotateAxisAngleSelf = function (x, y, z, angle) { // NB: This is the generic transform. If the axis is a major axis, there are // faster transforms. this._values = multiply([ - tx * x + c, tx * y + s * z, tx * z - s * y, 0, - tx * y - s * z, ty * y + c, ty * z + s * x, 0, - tx * z + s * y, ty * z - s * x, t * z * z + c, 0, - 0, 0, 0, 1 + tx * x + c, tx * y + s * z, tx * z - s * y, 0, + tx * y - s * z, ty * y + c, ty * z + s * x, 0, + tx * z + s * y, ty * z - s * x, t * z * z + c, 0, + 0, 0, 0, 1 ], this._values) if (x !== 0 || y !== 0) this._is2D = false return this @@ -422,7 +422,7 @@ DOMMatrix.prototype.skewYSelf = function (sy) { return this } -DOMMatrix.prototype.flipX = function () { +DOMMatrix.prototype.flipX = function () { return newInstance(multiply([ -1, 0, 0, 0, 0, 1, 0, 0, @@ -468,12 +468,12 @@ DOMMatrix.prototype.transformPoint = function (point) { return new DOMPoint(nx, ny, nz, nw) } -DOMMatrix.prototype.toFloat32Array = function () { +DOMMatrix.prototype.toFloat32Array = function () { return Float32Array.from(this._values) } -DOMMatrix.prototype.toFloat64Array = function () { +DOMMatrix.prototype.toFloat64Array = function () { return this._values.slice(0) } -module.exports = {DOMMatrix, DOMPoint} +module.exports = { DOMMatrix, DOMPoint } diff --git a/lib/bindings.js b/lib/bindings.js index c0afc9841..95ee914f3 100644 --- a/lib/bindings.js +++ b/lib/bindings.js @@ -1,3 +1,3 @@ -'use strict'; +'use strict' -module.exports = require('../build/Release/canvas.node'); +module.exports = require('../build/Release/canvas.node') diff --git a/lib/canvas.js b/lib/canvas.js index ec16b92ea..72a729366 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict' /*! * Canvas @@ -25,9 +25,9 @@ const FORMATS = ['image/png', 'image/jpeg'] * @api public */ -Canvas.prototype.inspect = function(){ - return '[Canvas ' + this.width + 'x' + this.height + ']'; -}; +Canvas.prototype.inspect = function () { + return '[Canvas ' + this.width + 'x' + this.height + ']' +} /** * Get a context object. @@ -39,13 +39,13 @@ Canvas.prototype.inspect = function(){ */ Canvas.prototype.getContext = function (contextType, contextAttributes) { - if ('2d' == contextType) { - var ctx = this._context2d || (this._context2d = new Context2d(this, contextAttributes)); - this.context = ctx; - ctx.canvas = this; - return ctx; + if (contextType == '2d') { + var ctx = this._context2d || (this._context2d = new Context2d(this, contextAttributes)) + this.context = ctx + ctx.canvas = this + return ctx } -}; +} /** * Create a `PNGStream` for `this` canvas. @@ -66,9 +66,9 @@ Canvas.prototype.getContext = function (contextType, contextAttributes) { * @public */ Canvas.prototype.pngStream = -Canvas.prototype.createPNGStream = function(options){ - return new PNGStream(this, options); -}; +Canvas.prototype.createPNGStream = function (options) { + return new PNGStream(this, options) +} /** * Create a `PDFStream` for `this` canvas. @@ -77,9 +77,9 @@ Canvas.prototype.createPNGStream = function(options){ * @public */ Canvas.prototype.pdfStream = -Canvas.prototype.createPDFStream = function(){ - return new PDFStream(this); -}; +Canvas.prototype.createPDFStream = function () { + return new PDFStream(this) +} /** * Create a `JPEGStream` for `this` canvas. @@ -94,9 +94,9 @@ Canvas.prototype.createPDFStream = function(){ * @public */ Canvas.prototype.jpegStream = -Canvas.prototype.createJPEGStream = function(options){ - return new JPEGStream(this, options); -}; +Canvas.prototype.createJPEGStream = function (options) { + return new JPEGStream(this, options) +} /** * Returns a data URI. Pass a function for async operation (non-standard). @@ -110,7 +110,7 @@ Canvas.prototype.createJPEGStream = function(options){ * @return {String} data URL if synchronous (callback omitted) * @api public */ -Canvas.prototype.toDataURL = function(a1, a2, a3){ +Canvas.prototype.toDataURL = function (a1, a2, a3) { // valid arg patterns (args -> [type, opts, fn]): // [] -> ['image/png', null, null] // [qual] -> ['image/png', null, null] @@ -129,51 +129,51 @@ Canvas.prototype.toDataURL = function(a1, a2, a3){ // ['image/jpeg', opts] -> ['image/jpeg', opts, fn] // ['image/jpeg', qual] -> ['image/jpeg', {quality: qual}, fn] - var type = 'image/png'; - var opts = {}; - var fn; + var type = 'image/png' + var opts = {} + var fn - if ('function' === typeof a1) { - fn = a1; + if (typeof a1 === 'function') { + fn = a1 } else { - if ('string' === typeof a1 && FORMATS.includes(a1.toLowerCase())) { - type = a1.toLowerCase(); + if (typeof a1 === 'string' && FORMATS.includes(a1.toLowerCase())) { + type = a1.toLowerCase() } - if ('function' === typeof a2) { - fn = a2; + if (typeof a2 === 'function') { + fn = a2 } else { - if ('object' === typeof a2) { - opts = a2; - } else if ('number' === typeof a2) { - opts = {quality: Math.max(0, Math.min(1, a2))}; + if (typeof a2 === 'object') { + opts = a2 + } else if (typeof a2 === 'number') { + opts = { quality: Math.max(0, Math.min(1, a2)) } } - if ('function' === typeof a3) { - fn = a3; + if (typeof a3 === 'function') { + fn = a3 } else if (undefined !== a3) { - throw new TypeError(typeof a3 + ' is not a function'); + throw new TypeError(typeof a3 + ' is not a function') } } } if (this.width === 0 || this.height === 0) { // Per spec, if the bitmap has no pixels, return this string: - var str = "data:,"; + var str = 'data:,' if (fn) { - setTimeout(() => fn(null, str)); - return; + setTimeout(() => fn(null, str)) + return } else { - return str; + return str } } if (fn) { this.toBuffer((err, buf) => { - if (err) return fn(err); - fn(null, `data:${type};base64,${buf.toString('base64')}`); + if (err) return fn(err) + fn(null, `data:${type};base64,${buf.toString('base64')}`) }, type, opts) } else { return `data:${type};base64,${this.toBuffer(type).toString('base64')}` } -}; +} diff --git a/lib/context2d.js b/lib/context2d.js index b9c28e6ea..b5237593c 100644 --- a/lib/context2d.js +++ b/lib/context2d.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict' /*! * Canvas - Context2d @@ -22,7 +22,7 @@ const DOMMatrix = require('./DOMMatrix').DOMMatrix * Text baselines. */ -var baselines = ['alphabetic', 'top', 'bottom', 'middle', 'ideographic', 'hanging']; +var baselines = ['alphabetic', 'top', 'bottom', 'middle', 'ideographic', 'hanging'] /** * Create a pattern from `Image` or `Canvas`. @@ -33,9 +33,9 @@ var baselines = ['alphabetic', 'top', 'bottom', 'middle', 'ideographic', 'hangin * @api public */ -Context2d.prototype.createPattern = function(image, repetition){ - return new CanvasPattern(image, repetition || 'repeat'); -}; +Context2d.prototype.createPattern = function (image, repetition) { + return new CanvasPattern(image, repetition || 'repeat') +} /** * Create a linear gradient at the given point `(x0, y0)` and `(x1, y1)`. @@ -48,9 +48,9 @@ Context2d.prototype.createPattern = function(image, repetition){ * @api public */ -Context2d.prototype.createLinearGradient = function(x0, y0, x1, y1){ - return new CanvasGradient(x0, y0, x1, y1); -}; +Context2d.prototype.createLinearGradient = function (x0, y0, x1, y1) { + return new CanvasGradient(x0, y0, x1, y1) +} /** * Create a radial gradient at the given point `(x0, y0)` and `(x1, y1)` @@ -66,9 +66,9 @@ Context2d.prototype.createLinearGradient = function(x0, y0, x1, y1){ * @api public */ -Context2d.prototype.createRadialGradient = function(x0, y0, r0, x1, y1, r1){ - return new CanvasGradient(x0, y0, r0, x1, y1, r1); -}; +Context2d.prototype.createRadialGradient = function (x0, y0, r0, x1, y1, r1) { + return new CanvasGradient(x0, y0, r0, x1, y1, r1) +} /** * Reset transform matrix to identity, then apply the given args. @@ -77,10 +77,10 @@ Context2d.prototype.createRadialGradient = function(x0, y0, r0, x1, y1, r1){ * @api public */ -Context2d.prototype.setTransform = function(){ - this.resetTransform(); - this.transform.apply(this, arguments); -}; +Context2d.prototype.setTransform = function () { + this.resetTransform() + this.transform.apply(this, arguments) +} Object.defineProperty(Context2d.prototype, 'currentTransform', { get: function () { @@ -103,16 +103,16 @@ Object.defineProperty(Context2d.prototype, 'currentTransform', { * @api public */ -Context2d.prototype.__defineSetter__('fillStyle', function(val){ - if (val instanceof CanvasGradient - || val instanceof CanvasPattern) { - this.lastFillStyle = val; - this._setFillPattern(val); +Context2d.prototype.__defineSetter__('fillStyle', function (val) { + if (val instanceof CanvasGradient || + val instanceof CanvasPattern) { + this.lastFillStyle = val + this._setFillPattern(val) } else { - this.lastFillStyle = undefined; - this._setFillColor(String(val)); + this.lastFillStyle = undefined + this._setFillColor(String(val)) } -}); +}) /** * Get previous fill style. @@ -121,9 +121,9 @@ Context2d.prototype.__defineSetter__('fillStyle', function(val){ * @api public */ -Context2d.prototype.__defineGetter__('fillStyle', function(){ - return this.lastFillStyle || this.fillColor; -}); +Context2d.prototype.__defineGetter__('fillStyle', function () { + return this.lastFillStyle || this.fillColor +}) /** * Set the stroke style with the given css color string. @@ -131,15 +131,15 @@ Context2d.prototype.__defineGetter__('fillStyle', function(){ * @api public */ -Context2d.prototype.__defineSetter__('strokeStyle', function(val){ - if (val instanceof CanvasGradient - || val instanceof CanvasPattern) { - this.lastStrokeStyle = val; - this._setStrokePattern(val); +Context2d.prototype.__defineSetter__('strokeStyle', function (val) { + if (val instanceof CanvasGradient || + val instanceof CanvasPattern) { + this.lastStrokeStyle = val + this._setStrokePattern(val) } else { - this._setStrokeColor(String(val)); + this._setStrokeColor(String(val)) } -}); +}) /** * Get previous stroke style. @@ -148,9 +148,9 @@ Context2d.prototype.__defineSetter__('strokeStyle', function(val){ * @api public */ -Context2d.prototype.__defineGetter__('strokeStyle', function(){ - return this.lastStrokeStyle || this.strokeColor; -}); +Context2d.prototype.__defineGetter__('strokeStyle', function () { + return this.lastStrokeStyle || this.strokeColor +}) /** * Set font. @@ -159,21 +159,21 @@ Context2d.prototype.__defineGetter__('strokeStyle', function(){ * @api public */ -Context2d.prototype.__defineSetter__('font', function(val){ - if (!val) return; - if ('string' == typeof val) { - var font; +Context2d.prototype.__defineSetter__('font', function (val) { + if (!val) return + if (typeof val === 'string') { + var font if (font = parseFont(val)) { - this.lastFontString = val; + this.lastFontString = val this._setFont( - font.weight + font.weight , font.style , font.size , font.unit - , font.family); + , font.family) } } -}); +}) /** * Get the current font. @@ -181,9 +181,9 @@ Context2d.prototype.__defineSetter__('font', function(val){ * @api public */ -Context2d.prototype.__defineGetter__('font', function(){ - return this.lastFontString || '10px sans-serif'; -}); +Context2d.prototype.__defineGetter__('font', function () { + return this.lastFontString || '10px sans-serif' +}) /** * Set text baseline. @@ -191,14 +191,14 @@ Context2d.prototype.__defineGetter__('font', function(){ * @api public */ -Context2d.prototype.__defineSetter__('textBaseline', function(val){ - if (!val) return; - var n = baselines.indexOf(val); +Context2d.prototype.__defineSetter__('textBaseline', function (val) { + if (!val) return + var n = baselines.indexOf(val) if (~n) { - this.lastBaseline = val; - this._setTextBaseline(n); + this.lastBaseline = val + this._setTextBaseline(n) } -}); +}) /** * Get the current baseline setting. @@ -206,9 +206,9 @@ Context2d.prototype.__defineSetter__('textBaseline', function(val){ * @api public */ -Context2d.prototype.__defineGetter__('textBaseline', function(){ - return this.lastBaseline || 'alphabetic'; -}); +Context2d.prototype.__defineGetter__('textBaseline', function () { + return this.lastBaseline || 'alphabetic' +}) /** * Set text alignment. @@ -216,24 +216,24 @@ Context2d.prototype.__defineGetter__('textBaseline', function(){ * @api public */ -Context2d.prototype.__defineSetter__('textAlign', function(val){ +Context2d.prototype.__defineSetter__('textAlign', function (val) { switch (val) { case 'center': - this._setTextAlignment(0); - this.lastTextAlignment = val; - break; + this._setTextAlignment(0) + this.lastTextAlignment = val + break case 'left': case 'start': - this._setTextAlignment(-1); - this.lastTextAlignment = val; - break; + this._setTextAlignment(-1) + this.lastTextAlignment = val + break case 'right': case 'end': - this._setTextAlignment(1); - this.lastTextAlignment = val; - break; + this._setTextAlignment(1) + this.lastTextAlignment = val + break } -}); +}) /** * Get the current font. @@ -242,9 +242,9 @@ Context2d.prototype.__defineSetter__('textAlign', function(val){ * @api public */ -Context2d.prototype.__defineGetter__('textAlign', function(){ - return this.lastTextAlignment || 'start'; -}); +Context2d.prototype.__defineGetter__('textAlign', function () { + return this.lastTextAlignment || 'start' +}) /** * Create `ImageData` with the given dimensions or @@ -261,13 +261,13 @@ Context2d.prototype.createImageData = function (width, height) { height = width.height width = width.width } - var Bpp = this.canvas.stride / this.canvas.width; + var Bpp = this.canvas.stride / this.canvas.width var nBytes = Bpp * width * height - var arr; - if (this.pixelFormat === "RGB16_565") { - arr = new Uint16Array(nBytes / 2); + var arr + if (this.pixelFormat === 'RGB16_565') { + arr = new Uint16Array(nBytes / 2) } else { - arr = new Uint8ClampedArray(nBytes); + arr = new Uint8ClampedArray(nBytes) } - return new ImageData(arr, width, height); + return new ImageData(arr, width, height) } diff --git a/lib/image.js b/lib/image.js index ff84f2b24..a64b7796d 100644 --- a/lib/image.js +++ b/lib/image.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict' /*! * Canvas - Image @@ -12,15 +12,15 @@ const bindings = require('./bindings') const Image = module.exports = bindings.Image -const http = require("http") -const https = require("https") +const http = require('http') +const https = require('https') -const proto = Image.prototype; -const _getSource = proto.getSource; -const _setSource = proto.setSource; +const proto = Image.prototype +const _getSource = proto.getSource +const _setSource = proto.setSource -delete proto.getSource; -delete proto.setSource; +delete proto.getSource +delete proto.setSource Object.defineProperty(Image.prototype, 'src', { /** @@ -33,14 +33,14 @@ Object.defineProperty(Image.prototype, 'src', { * @param {String|Buffer} val filename, buffer, data URI, URL * @api public */ - set(val) { + set (val) { if (typeof val === 'string') { if (/^\s*data:/.test(val)) { // data: URI const commaI = val.indexOf(',') // 'base64' must come before the comma const isBase64 = val.lastIndexOf('base64', commaI) !== -1 const content = val.slice(commaI + 1) - setSource(this, Buffer.from(content, isBase64 ? 'base64' : 'utf8'), val); + setSource(this, Buffer.from(content, isBase64 ? 'base64' : 'utf8'), val) } else if (/^\s*https?:\/\//.test(val)) { // remote URL const onerror = err => { if (typeof this.onerror === 'function') { @@ -58,24 +58,24 @@ Object.defineProperty(Image.prototype, 'src', { const buffers = [] res.on('data', buffer => buffers.push(buffer)) res.on('end', () => { - setSource(this, Buffer.concat(buffers)); + setSource(this, Buffer.concat(buffers)) }) }).on('error', onerror) } else { // local file path assumed - setSource(this, val); + setSource(this, val) } } else if (Buffer.isBuffer(val)) { - setSource(this, val); + setSource(this, val) } }, - get() { + get () { // TODO https://github.com/Automattic/node-canvas/issues/118 - return getSource(this); + return getSource(this) }, configurable: true -}); +}) /** * Inspect image. @@ -86,19 +86,19 @@ Object.defineProperty(Image.prototype, 'src', { * @api public */ -Image.prototype.inspect = function(){ - return '[Image' - + (this.complete ? ':' + this.width + 'x' + this.height : '') - + (this.src ? ' ' + this.src : '') - + (this.complete ? ' complete' : '') - + ']'; -}; +Image.prototype.inspect = function () { + return '[Image' + + (this.complete ? ':' + this.width + 'x' + this.height : '') + + (this.src ? ' ' + this.src : '') + + (this.complete ? ' complete' : '') + + ']' +} -function getSource(img){ - return img._originalSource || _getSource.call(img); +function getSource (img) { + return img._originalSource || _getSource.call(img) } -function setSource(img, src, origSrc){ - _setSource.call(img, src); - img._originalSource = origSrc; +function setSource (img, src, origSrc) { + _setSource.call(img, src) + img._originalSource = origSrc } diff --git a/lib/jpegstream.js b/lib/jpegstream.js index e44ed4c65..92c5df80b 100644 --- a/lib/jpegstream.js +++ b/lib/jpegstream.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict' /*! * Canvas - JPEGStream @@ -10,8 +10,8 @@ * Module dependencies. */ -var Readable = require('stream').Readable; -var util = require('util'); +var Readable = require('stream').Readable +var util = require('util') /** * Initialize a `JPEGStream` with the given `canvas`. @@ -29,37 +29,37 @@ var util = require('util'); * @private */ -var JPEGStream = module.exports = function JPEGStream(canvas, options) { +var JPEGStream = module.exports = function JPEGStream (canvas, options) { if (!(this instanceof JPEGStream)) { - throw new TypeError("Class constructors cannot be invoked without 'new'"); + throw new TypeError("Class constructors cannot be invoked without 'new'") } if (canvas.streamJPEGSync === undefined) { - throw new Error("node-canvas was built without JPEG support."); + throw new Error('node-canvas was built without JPEG support.') } - Readable.call(this); + Readable.call(this) - this.options = options; - this.canvas = canvas; -}; + this.options = options + this.canvas = canvas +} -util.inherits(JPEGStream, Readable); +util.inherits(JPEGStream, Readable) -function noop() {} +function noop () {} -JPEGStream.prototype._read = function _read() { +JPEGStream.prototype._read = function _read () { // For now we're not controlling the c++ code's data emission, so we only // call canvas.streamJPEGSync once and let it emit data at will. - this._read = noop; - var self = this; - self.canvas.streamJPEGSync(this.options, function(err, chunk){ + this._read = noop + var self = this + self.canvas.streamJPEGSync(this.options, function (err, chunk) { if (err) { - self.emit('error', err); + self.emit('error', err) } else if (chunk) { - self.push(chunk); + self.push(chunk) } else { - self.push(null); + self.push(null) } - }); -}; + }) +} diff --git a/lib/parse-font.js b/lib/parse-font.js index a149c709c..8fb9551a7 100644 --- a/lib/parse-font.js +++ b/lib/parse-font.js @@ -5,11 +5,16 @@ */ const weights = 'bold|bolder|lighter|[1-9]00' - , styles = 'italic|oblique' - , variants = 'small-caps' - , stretches = 'ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded' - , units = 'px|pt|pc|in|cm|mm|%|em|ex|ch|rem|q' - , string = '\'([^\']+)\'|"([^"]+)"|[\\w\\s-]+' + +const styles = 'italic|oblique' + +const variants = 'small-caps' + +const stretches = 'ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded' + +const units = 'px|pt|pc|in|cm|mm|%|em|ex|ch|rem|q' + +const string = '\'([^\']+)\'|"([^"]+)"|[\\w\\s-]+' // [ [ <‘font-style’> || || <‘font-weight’> || <‘font-stretch’> ]? // <‘font-size’> [ / <‘line-height’> ]? <‘font-family’> ] @@ -19,8 +24,8 @@ const styleRe = new RegExp(`(${styles}) +`, 'i') const variantRe = new RegExp(`(${variants}) +`, 'i') const stretchRe = new RegExp(`(${stretches}) +`, 'i') const sizeFamilyRe = new RegExp( - '([\\d\\.]+)(' + units + ') *' - + '((?:' + string + ')( *, *(?:' + string + '))*)') + '([\\d\\.]+)(' + units + ') *' + + '((?:' + string + ')( *, *(?:' + string + '))*)') /** * Cache font parsing. diff --git a/lib/pdfstream.js b/lib/pdfstream.js index 837a034c3..b056c6e47 100644 --- a/lib/pdfstream.js +++ b/lib/pdfstream.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict' /*! * Canvas - PDFStream @@ -8,8 +8,8 @@ * Module dependencies. */ -var Readable = require('stream').Readable; -var util = require('util'); +var Readable = require('stream').Readable +var util = require('util') /** * Initialize a `PDFStream` with the given `canvas`. @@ -27,32 +27,32 @@ var util = require('util'); * @api public */ -var PDFStream = module.exports = function PDFStream(canvas) { +var PDFStream = module.exports = function PDFStream (canvas) { if (!(this instanceof PDFStream)) { - throw new TypeError("Class constructors cannot be invoked without 'new'"); + throw new TypeError("Class constructors cannot be invoked without 'new'") } - Readable.call(this); + Readable.call(this) - this.canvas = canvas; -}; + this.canvas = canvas +} -util.inherits(PDFStream, Readable); +util.inherits(PDFStream, Readable) -function noop() {} +function noop () {} -PDFStream.prototype._read = function _read() { +PDFStream.prototype._read = function _read () { // For now we're not controlling the c++ code's data emission, so we only // call canvas.streamPDFSync once and let it emit data at will. - this._read = noop; - var self = this; - self.canvas.streamPDFSync(function(err, chunk, len){ + this._read = noop + var self = this + self.canvas.streamPDFSync(function (err, chunk, len) { if (err) { - self.emit('error', err); + self.emit('error', err) } else if (len) { - self.push(chunk); + self.push(chunk) } else { - self.push(null); + self.push(null) } - }); -}; + }) +} diff --git a/lib/pngstream.js b/lib/pngstream.js index 3a03c78c7..7fac31129 100644 --- a/lib/pngstream.js +++ b/lib/pngstream.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict' /*! * Canvas - PNGStream @@ -10,46 +10,46 @@ * Module dependencies. */ -var Readable = require('stream').Readable; -var util = require('util'); +var Readable = require('stream').Readable +var util = require('util') /** * @param {Canvas} canvas * @param {Object} options * @private */ -var PNGStream = module.exports = function PNGStream(canvas, options) { +var PNGStream = module.exports = function PNGStream (canvas, options) { if (!(this instanceof PNGStream)) { - throw new TypeError("Class constructors cannot be invoked without 'new'"); + throw new TypeError("Class constructors cannot be invoked without 'new'") } - Readable.call(this); + Readable.call(this) if (options && options.palette instanceof Uint8ClampedArray && options.palette.length % 4 !== 0) { - throw new Error("Palette length must be a multiple of 4."); + throw new Error('Palette length must be a multiple of 4.') } - this.canvas = canvas; - this.options = options || {}; -}; + this.canvas = canvas + this.options = options || {} +} -util.inherits(PNGStream, Readable); +util.inherits(PNGStream, Readable) -function noop() {} +function noop () {} -PNGStream.prototype._read = function _read() { +PNGStream.prototype._read = function _read () { // For now we're not controlling the c++ code's data emission, so we only // call canvas.streamPNGSync once and let it emit data at will. - this._read = noop; - var self = this; - self.canvas.streamPNGSync(function(err, chunk, len){ + this._read = noop + var self = this + self.canvas.streamPNGSync(function (err, chunk, len) { if (err) { - self.emit('error', err); + self.emit('error', err) } else if (len) { - self.push(chunk); + self.push(chunk) } else { - self.push(null); + self.push(null) } - }, self.options); -}; + }, self.options) +} diff --git a/test/canvas.test.js b/test/canvas.test.js index 77e012648..3239d1b85 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -18,136 +18,140 @@ const Readable = require('stream').Readable describe('Canvas', function () { it('Prototype and ctor are well-shaped, don\'t hit asserts on accessors (GH-803)', function () { - const Canvas = require('../').Canvas; - var c = new Canvas(10, 10); - assert.throws(function () { Canvas.prototype.width; }, /incompatible receiver/); - assert(!c.hasOwnProperty('width')); - assert('width' in c); - assert(Canvas.prototype.hasOwnProperty('width')); - }); + const Canvas = require('../').Canvas + var c = new Canvas(10, 10) + assert.throws(function () { Canvas.prototype.width }, /incompatible receiver/) + assert(!c.hasOwnProperty('width')) + assert('width' in c) + assert(Canvas.prototype.hasOwnProperty('width')) + }) it('.parseFont()', function () { var tests = [ - '20px Arial' - , { size: 20, unit: 'px', family: 'Arial' } - , '20pt Arial' - , { size: 26.666666666666668, unit: 'pt', family: 'Arial' } - , '20.5pt Arial' - , { size: 27.333333333333332, unit: 'pt', family: 'Arial' } - , '20% Arial' - , { size: 20, unit: '%', family: 'Arial' } // TODO I think this is a bad assertion - ZB 23-Jul-2017 - , '20mm Arial' - , { size: 75.59055118110237, unit: 'mm', family: 'Arial' } - , '20px serif' - , { size: 20, unit: 'px', family: 'serif' } - , '20px sans-serif' - , { size: 20, unit: 'px', family: 'sans-serif' } - , '20px monospace' - , { size: 20, unit: 'px', family: 'monospace' } - , '50px Arial, sans-serif' - , { size: 50, unit: 'px', family: 'Arial,sans-serif' } - , 'bold italic 50px Arial, sans-serif' - , { style: 'italic', weight: 'bold', size: 50, unit: 'px', family: 'Arial,sans-serif' } - , '50px Helvetica , Arial, sans-serif' - , { size: 50, unit: 'px', family: 'Helvetica,Arial,sans-serif' } - , '50px "Helvetica Neue", sans-serif' - , { size: 50, unit: 'px', family: 'Helvetica Neue,sans-serif' } - , '50px "Helvetica Neue", "foo bar baz" , sans-serif' - , { size: 50, unit: 'px', family: 'Helvetica Neue,foo bar baz,sans-serif' } - , "50px 'Helvetica Neue'" - , { size: 50, unit: 'px', family: 'Helvetica Neue' } - , 'italic 20px Arial' - , { size: 20, unit: 'px', style: 'italic', family: 'Arial' } - , 'oblique 20px Arial' - , { size: 20, unit: 'px', style: 'oblique', family: 'Arial' } - , 'normal 20px Arial' - , { size: 20, unit: 'px', style: 'normal', family: 'Arial' } - , '300 20px Arial' - , { size: 20, unit: 'px', weight: '300', family: 'Arial' } - , '800 20px Arial' - , { size: 20, unit: 'px', weight: '800', family: 'Arial' } - , 'bolder 20px Arial' - , { size: 20, unit: 'px', weight: 'bolder', family: 'Arial' } - , 'lighter 20px Arial' - , { size: 20, unit: 'px', weight: 'lighter', family: 'Arial' } - , 'normal normal normal 16px Impact' - , { size: 16, unit: 'px', weight: 'normal', family: 'Impact', style: 'normal', variant: 'normal' } - , 'italic small-caps bolder 16px cursive' - , { size: 16, unit: 'px', style: 'italic', variant: 'small-caps', weight: 'bolder', family: 'cursive' } - , '20px "new century schoolbook", serif' - , { size: 20, unit: 'px', family: 'new century schoolbook,serif' } - , '20px "Arial bold 300"' // synthetic case with weight keyword inside family - , { size: 20, unit: 'px', family: 'Arial bold 300', variant: 'normal' } - ]; + '20px Arial', + { size: 20, unit: 'px', family: 'Arial' }, + '20pt Arial', + { size: 26.666666666666668, unit: 'pt', family: 'Arial' }, + '20.5pt Arial', + { size: 27.333333333333332, unit: 'pt', family: 'Arial' }, + '20% Arial', + { size: 20, unit: '%', family: 'Arial' }, // TODO I think this is a bad assertion - ZB 23-Jul-2017 + '20mm Arial', + { size: 75.59055118110237, unit: 'mm', family: 'Arial' }, + '20px serif', + { size: 20, unit: 'px', family: 'serif' }, + '20px sans-serif', + { size: 20, unit: 'px', family: 'sans-serif' }, + '20px monospace', + { size: 20, unit: 'px', family: 'monospace' }, + '50px Arial, sans-serif', + { size: 50, unit: 'px', family: 'Arial,sans-serif' }, + 'bold italic 50px Arial, sans-serif', + { style: 'italic', weight: 'bold', size: 50, unit: 'px', family: 'Arial,sans-serif' }, + '50px Helvetica , Arial, sans-serif', + { size: 50, unit: 'px', family: 'Helvetica,Arial,sans-serif' }, + '50px "Helvetica Neue", sans-serif', + { size: 50, unit: 'px', family: 'Helvetica Neue,sans-serif' }, + '50px "Helvetica Neue", "foo bar baz" , sans-serif', + { size: 50, unit: 'px', family: 'Helvetica Neue,foo bar baz,sans-serif' }, + "50px 'Helvetica Neue'", + { size: 50, unit: 'px', family: 'Helvetica Neue' }, + 'italic 20px Arial', + { size: 20, unit: 'px', style: 'italic', family: 'Arial' }, + 'oblique 20px Arial', + { size: 20, unit: 'px', style: 'oblique', family: 'Arial' }, + 'normal 20px Arial', + { size: 20, unit: 'px', style: 'normal', family: 'Arial' }, + '300 20px Arial', + { size: 20, unit: 'px', weight: '300', family: 'Arial' }, + '800 20px Arial', + { size: 20, unit: 'px', weight: '800', family: 'Arial' }, + 'bolder 20px Arial', + { size: 20, unit: 'px', weight: 'bolder', family: 'Arial' }, + 'lighter 20px Arial', + { size: 20, unit: 'px', weight: 'lighter', family: 'Arial' }, + 'normal normal normal 16px Impact', + { size: 16, unit: 'px', weight: 'normal', family: 'Impact', style: 'normal', variant: 'normal' }, + 'italic small-caps bolder 16px cursive', + { size: 16, unit: 'px', style: 'italic', variant: 'small-caps', weight: 'bolder', family: 'cursive' }, + '20px "new century schoolbook", serif', + { size: 20, unit: 'px', family: 'new century schoolbook,serif' }, + '20px "Arial bold 300"', // synthetic case with weight keyword inside family + { size: 20, unit: 'px', family: 'Arial bold 300', variant: 'normal' } + ] for (var i = 0, len = tests.length; i < len; ++i) { var str = tests[i++] - , expected = tests[i] - , actual = parseFont(str); - if (!expected.style) expected.style = 'normal'; - if (!expected.weight) expected.weight = 'normal'; - if (!expected.stretch) expected.stretch = 'normal'; - if (!expected.variant) expected.variant = 'normal'; + var expected = tests[i] - assert.deepEqual(actual, expected, 'Failed to parse: ' + str); + var actual = parseFont(str) + + if (!expected.style) expected.style = 'normal' + if (!expected.weight) expected.weight = 'normal' + if (!expected.stretch) expected.stretch = 'normal' + if (!expected.variant) expected.variant = 'normal' + + assert.deepEqual(actual, expected, 'Failed to parse: ' + str) } - }); + }) it('registerFont', function () { // Minimal test to make sure nothing is thrown - registerFont('./examples/pfennigFont/Pfennig.ttf', {family: 'Pfennig'}) - registerFont('./examples/pfennigFont/PfennigBold.ttf', {family: 'Pfennig', weight: 'bold'}) - }); + registerFont('./examples/pfennigFont/Pfennig.ttf', { family: 'Pfennig' }) + registerFont('./examples/pfennigFont/PfennigBold.ttf', { family: 'Pfennig', weight: 'bold' }) + }) it('color serialization', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - ['fillStyle', 'strokeStyle', 'shadowColor'].forEach(function(prop){ - ctx[prop] = '#FFFFFF'; - assert.equal('#ffffff', ctx[prop], prop + ' #FFFFFF -> #ffffff, got ' + ctx[prop]); + var ctx = canvas.getContext('2d'); + + ['fillStyle', 'strokeStyle', 'shadowColor'].forEach(function (prop) { + ctx[prop] = '#FFFFFF' + assert.equal('#ffffff', ctx[prop], prop + ' #FFFFFF -> #ffffff, got ' + ctx[prop]) - ctx[prop] = '#FFF'; - assert.equal('#ffffff', ctx[prop], prop + ' #FFF -> #ffffff, got ' + ctx[prop]); + ctx[prop] = '#FFF' + assert.equal('#ffffff', ctx[prop], prop + ' #FFF -> #ffffff, got ' + ctx[prop]) - ctx[prop] = 'rgba(128, 200, 128, 1)'; - assert.equal('#80c880', ctx[prop], prop + ' rgba(128, 200, 128, 1) -> #80c880, got ' + ctx[prop]); + ctx[prop] = 'rgba(128, 200, 128, 1)' + assert.equal('#80c880', ctx[prop], prop + ' rgba(128, 200, 128, 1) -> #80c880, got ' + ctx[prop]) - ctx[prop] = 'rgba(128,80,0,0.5)'; - assert.equal('rgba(128, 80, 0, 0.50)', ctx[prop], prop + ' rgba(128,80,0,0.5) -> rgba(128, 80, 0, 0.5), got ' + ctx[prop]); + ctx[prop] = 'rgba(128,80,0,0.5)' + assert.equal('rgba(128, 80, 0, 0.50)', ctx[prop], prop + ' rgba(128,80,0,0.5) -> rgba(128, 80, 0, 0.5), got ' + ctx[prop]) - ctx[prop] = 'rgba(128,80,0,0.75)'; - assert.equal('rgba(128, 80, 0, 0.75)', ctx[prop], prop + ' rgba(128,80,0,0.75) -> rgba(128, 80, 0, 0.75), got ' + ctx[prop]); + ctx[prop] = 'rgba(128,80,0,0.75)' + assert.equal('rgba(128, 80, 0, 0.75)', ctx[prop], prop + ' rgba(128,80,0,0.75) -> rgba(128, 80, 0, 0.75), got ' + ctx[prop]) - if ('shadowColor' == prop) return; + if (prop == 'shadowColor') return - var grad = ctx.createLinearGradient(0,0,0,150); - ctx[prop] = grad; - assert.strictEqual(grad, ctx[prop], prop + ' pattern getter failed'); - }); - }); + var grad = ctx.createLinearGradient(0, 0, 0, 150) + ctx[prop] = grad + assert.strictEqual(grad, ctx[prop], prop + ' pattern getter failed') + }) + }) it('color parser', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - ctx.fillStyle = '#ffccaa'; - assert.equal('#ffccaa', ctx.fillStyle); + var ctx = canvas.getContext('2d') + + ctx.fillStyle = '#ffccaa' + assert.equal('#ffccaa', ctx.fillStyle) - ctx.fillStyle = '#FFCCAA'; - assert.equal('#ffccaa', ctx.fillStyle); + ctx.fillStyle = '#FFCCAA' + assert.equal('#ffccaa', ctx.fillStyle) - ctx.fillStyle = '#FCA'; - assert.equal('#ffccaa', ctx.fillStyle); + ctx.fillStyle = '#FCA' + assert.equal('#ffccaa', ctx.fillStyle) - ctx.fillStyle = '#fff'; - ctx.fillStyle = '#FGG'; - assert.equal('#ff0000', ctx.fillStyle); + ctx.fillStyle = '#fff' + ctx.fillStyle = '#FGG' + assert.equal('#ff0000', ctx.fillStyle) - ctx.fillStyle = '#fff'; - ctx.fillStyle = 'afasdfasdf'; - assert.equal('#ffffff', ctx.fillStyle); + ctx.fillStyle = '#fff' + ctx.fillStyle = 'afasdfasdf' + assert.equal('#ffffff', ctx.fillStyle) // #rgba and #rrggbbaa ctx.fillStyle = '#ffccaa80' @@ -159,108 +163,109 @@ describe('Canvas', function () { ctx.fillStyle = '#BEAD' assert.equal('rgba(187, 238, 170, 0.87)', ctx.fillStyle) - ctx.fillStyle = 'rgb(255,255,255)'; - assert.equal('#ffffff', ctx.fillStyle); + ctx.fillStyle = 'rgb(255,255,255)' + assert.equal('#ffffff', ctx.fillStyle) - ctx.fillStyle = 'rgb(0,0,0)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'rgb(0,0,0)' + assert.equal('#000000', ctx.fillStyle) - ctx.fillStyle = 'rgb( 0 , 0 , 0)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'rgb( 0 , 0 , 0)' + assert.equal('#000000', ctx.fillStyle) - ctx.fillStyle = 'rgba( 0 , 0 , 0, 1)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'rgba( 0 , 0 , 0, 1)' + assert.equal('#000000', ctx.fillStyle) - ctx.fillStyle = 'rgba( 255, 200, 90, 0.5)'; - assert.equal('rgba(255, 200, 90, 0.50)', ctx.fillStyle); + ctx.fillStyle = 'rgba( 255, 200, 90, 0.5)' + assert.equal('rgba(255, 200, 90, 0.50)', ctx.fillStyle) - ctx.fillStyle = 'rgba( 255, 200, 90, 0.75)'; - assert.equal('rgba(255, 200, 90, 0.75)', ctx.fillStyle); + ctx.fillStyle = 'rgba( 255, 200, 90, 0.75)' + assert.equal('rgba(255, 200, 90, 0.75)', ctx.fillStyle) - ctx.fillStyle = 'rgba( 255, 200, 90, 0.7555)'; - assert.equal('rgba(255, 200, 90, 0.75)', ctx.fillStyle); + ctx.fillStyle = 'rgba( 255, 200, 90, 0.7555)' + assert.equal('rgba(255, 200, 90, 0.75)', ctx.fillStyle) - ctx.fillStyle = 'rgba( 255, 200, 90, .7555)'; - assert.equal('rgba(255, 200, 90, 0.75)', ctx.fillStyle); + ctx.fillStyle = 'rgba( 255, 200, 90, .7555)' + assert.equal('rgba(255, 200, 90, 0.75)', ctx.fillStyle) - ctx.fillStyle = 'rgb(0, 0, 9000)'; - assert.equal('#0000ff', ctx.fillStyle); + ctx.fillStyle = 'rgb(0, 0, 9000)' + assert.equal('#0000ff', ctx.fillStyle) - ctx.fillStyle = 'rgba(0, 0, 0, 42.42)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'rgba(0, 0, 0, 42.42)' + assert.equal('#000000', ctx.fillStyle) // hsl / hsla tests - ctx.fillStyle = 'hsl(0, 0%, 0%)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'hsl(0, 0%, 0%)' + assert.equal('#000000', ctx.fillStyle) - ctx.fillStyle = 'hsl(3600, -10%, -10%)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'hsl(3600, -10%, -10%)' + assert.equal('#000000', ctx.fillStyle) - ctx.fillStyle = 'hsl(10, 100%, 42%)'; - assert.equal('#d62400', ctx.fillStyle); + ctx.fillStyle = 'hsl(10, 100%, 42%)' + assert.equal('#d62400', ctx.fillStyle) - ctx.fillStyle = 'hsl(370, 120%, 42%)'; - assert.equal('#d62400', ctx.fillStyle); + ctx.fillStyle = 'hsl(370, 120%, 42%)' + assert.equal('#d62400', ctx.fillStyle) - ctx.fillStyle = 'hsl(0, 100%, 100%)'; - assert.equal('#ffffff', ctx.fillStyle); + ctx.fillStyle = 'hsl(0, 100%, 100%)' + assert.equal('#ffffff', ctx.fillStyle) - ctx.fillStyle = 'hsl(0, 150%, 150%)'; - assert.equal('#ffffff', ctx.fillStyle); + ctx.fillStyle = 'hsl(0, 150%, 150%)' + assert.equal('#ffffff', ctx.fillStyle) - ctx.fillStyle = 'hsl(237, 76%, 25%)'; - assert.equal('#0f1470', ctx.fillStyle); + ctx.fillStyle = 'hsl(237, 76%, 25%)' + assert.equal('#0f1470', ctx.fillStyle) - ctx.fillStyle = 'hsl(240, 73%, 25%)'; - assert.equal('#11116e', ctx.fillStyle); + ctx.fillStyle = 'hsl(240, 73%, 25%)' + assert.equal('#11116e', ctx.fillStyle) - ctx.fillStyle = 'hsl(262, 32%, 42%)'; - assert.equal('#62498d', ctx.fillStyle); + ctx.fillStyle = 'hsl(262, 32%, 42%)' + assert.equal('#62498d', ctx.fillStyle) - ctx.fillStyle = 'hsla(0, 0%, 0%, 1)'; - assert.equal('#000000', ctx.fillStyle); + ctx.fillStyle = 'hsla(0, 0%, 0%, 1)' + assert.equal('#000000', ctx.fillStyle) - ctx.fillStyle = 'hsla(0, 100%, 100%, 1)'; - assert.equal('#ffffff', ctx.fillStyle); + ctx.fillStyle = 'hsla(0, 100%, 100%, 1)' + assert.equal('#ffffff', ctx.fillStyle) - ctx.fillStyle = 'hsla(120, 25%, 75%, 0.5)'; - assert.equal('rgba(175, 207, 175, 0.50)', ctx.fillStyle); + ctx.fillStyle = 'hsla(120, 25%, 75%, 0.5)' + assert.equal('rgba(175, 207, 175, 0.50)', ctx.fillStyle) - ctx.fillStyle = 'hsla(240, 75%, 25%, 0.75)'; - assert.equal('rgba(16, 16, 112, 0.75)', ctx.fillStyle); + ctx.fillStyle = 'hsla(240, 75%, 25%, 0.75)' + assert.equal('rgba(16, 16, 112, 0.75)', ctx.fillStyle) - ctx.fillStyle = 'hsla(172.0, 33.00000e0%, 42%, 1)'; - assert.equal('#488e85', ctx.fillStyle); + ctx.fillStyle = 'hsla(172.0, 33.00000e0%, 42%, 1)' + assert.equal('#488e85', ctx.fillStyle) - ctx.fillStyle = 'hsl(124.5, 76.1%, 47.6%)'; - assert.equal('#1dd62b', ctx.fillStyle); + ctx.fillStyle = 'hsl(124.5, 76.1%, 47.6%)' + assert.equal('#1dd62b', ctx.fillStyle) - ctx.fillStyle = 'hsl(1.24e2, 760e-1%, 4.7e1%)'; - assert.equal('#1dd329', ctx.fillStyle); + ctx.fillStyle = 'hsl(1.24e2, 760e-1%, 4.7e1%)' + assert.equal('#1dd329', ctx.fillStyle) // case-insensitive (#235) - ctx.fillStyle = "sILveR"; - assert.equal(ctx.fillStyle, "#c0c0c0"); - }); + ctx.fillStyle = 'sILveR' + assert.equal(ctx.fillStyle, '#c0c0c0') + }) it('Canvas#type', function () { - var canvas = createCanvas(10, 10); - assert.equal(canvas.type, 'image'); - var canvas = createCanvas(10, 10, 'pdf'); - assert.equal(canvas.type, 'pdf'); - var canvas = createCanvas(10, 10, 'svg'); - assert.equal(canvas.type, 'svg'); - var canvas = createCanvas(10, 10, 'hey'); - assert.equal(canvas.type, 'image'); - }); + var canvas = createCanvas(10, 10) + assert.equal(canvas.type, 'image') + var canvas = createCanvas(10, 10, 'pdf') + assert.equal(canvas.type, 'pdf') + var canvas = createCanvas(10, 10, 'svg') + assert.equal(canvas.type, 'svg') + var canvas = createCanvas(10, 10, 'hey') + assert.equal(canvas.type, 'image') + }) it('Canvas#getContext("2d")', function () { var canvas = createCanvas(200, 300) - , ctx = canvas.getContext('2d'); - assert.ok('object' == typeof ctx); - assert.equal(canvas, ctx.canvas, 'context.canvas is not canvas'); - assert.equal(ctx, canvas.context, 'canvas.context is not context'); + + var ctx = canvas.getContext('2d') + assert.ok(typeof ctx === 'object') + assert.equal(canvas, ctx.canvas, 'context.canvas is not canvas') + assert.equal(ctx, canvas.context, 'canvas.context is not context') const MAX_IMAGE_SIZE = 32767; @@ -275,332 +280,342 @@ describe('Canvas', function () { [Math.pow(2, 30), 0, 3], [Math.pow(2, 30), 1, 3], [Math.pow(2, 32), 0, 1], - [Math.pow(2, 32), 1, 1], + [Math.pow(2, 32), 1, 1] ].forEach(params => { - var width = params[0]; - var height = params[1]; - var errorLevel = params[2]; + var width = params[0] + var height = params[1] + var errorLevel = params[2] - var level = 3; + var level = 3 try { - var canvas = createCanvas(width, height); - level--; + var canvas = createCanvas(width, height) + level-- - var ctx = canvas.getContext('2d'); - level--; + var ctx = canvas.getContext('2d') + level-- - ctx.getImageData(0, 0, 1, 1); - level--; + ctx.getImageData(0, 0, 1, 1) + level-- } catch (err) {} - if (errorLevel !== null) - assert.strictEqual(level, errorLevel); - }); - }); + if (errorLevel !== null) { assert.strictEqual(level, errorLevel) } + }) + }) it('Canvas#getContext("2d", {pixelFormat: string})', function () { - var canvas, context; + var canvas, context // default: - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "RGBA32"}); - assert.equal(context.pixelFormat, "RGBA32"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'RGBA32' }) + assert.equal(context.pixelFormat, 'RGBA32') - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "RGBA32"}); - assert.equal(context.pixelFormat, "RGBA32"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'RGBA32' }) + assert.equal(context.pixelFormat, 'RGBA32') - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "RGB24"}); - assert.equal(context.pixelFormat, "RGB24"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'RGB24' }) + assert.equal(context.pixelFormat, 'RGB24') - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "A8"}); - assert.equal(context.pixelFormat, "A8"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'A8' }) + assert.equal(context.pixelFormat, 'A8') - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "A1"}); - assert.equal(context.pixelFormat, "A1"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'A1' }) + assert.equal(context.pixelFormat, 'A1') - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "RGB16_565"}); - assert.equal(context.pixelFormat, "RGB16_565"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'RGB16_565' }) + assert.equal(context.pixelFormat, 'RGB16_565') // Not tested: RGB30 - }); + }) it('Canvas#getContext("2d", {alpha: boolean})', function () { - var canvas, context; + var canvas, context - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {alpha: true}); - assert.equal(context.pixelFormat, "RGBA32"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { alpha: true }) + assert.equal(context.pixelFormat, 'RGBA32') - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {alpha: false}); - assert.equal(context.pixelFormat, "RGB24"); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { alpha: false }) + assert.equal(context.pixelFormat, 'RGB24') // alpha takes priority: - canvas = createCanvas(10, 10); - context = canvas.getContext("2d", {pixelFormat: "RGBA32", alpha: false}); - assert.equal(context.pixelFormat, "RGB24"); - }); + canvas = createCanvas(10, 10) + context = canvas.getContext('2d', { pixelFormat: 'RGBA32', alpha: false }) + assert.equal(context.pixelFormat, 'RGB24') + }) it('Canvas#{width,height}=', function () { - var context, canvas = createCanvas(100, 200); + var context; var canvas = createCanvas(100, 200) - assert.equal(100, canvas.width); - assert.equal(200, canvas.height); + assert.equal(100, canvas.width) + assert.equal(200, canvas.height) - canvas = createCanvas(); - context = canvas.getContext("2d"); - assert.equal(0, canvas.width); - assert.equal(0, canvas.height); + canvas = createCanvas() + context = canvas.getContext('2d') + assert.equal(0, canvas.width) + assert.equal(0, canvas.height) - canvas.width = 50; - canvas.height = 50; - assert.equal(50, canvas.width); - assert.equal(50, canvas.height); - assert.equal(1, context.lineWidth); // #1095 - }); + canvas.width = 50 + canvas.height = 50 + assert.equal(50, canvas.width) + assert.equal(50, canvas.height) + assert.equal(1, context.lineWidth) // #1095 + }) - it('Canvas#stride', function() { - var canvas = createCanvas(24, 10); - assert.ok(canvas.stride >= 24, 'canvas.stride is too short'); - assert.ok(canvas.stride < 1024, 'canvas.stride seems too long'); + it('Canvas#stride', function () { + var canvas = createCanvas(24, 10) + assert.ok(canvas.stride >= 24, 'canvas.stride is too short') + assert.ok(canvas.stride < 1024, 'canvas.stride seems too long') // TODO test stride on other formats - }); + }) it('Canvas#getContext("invalid")', function () { - assert.equal(null, createCanvas(200, 300).getContext('invalid')); - }); + assert.equal(null, createCanvas(200, 300).getContext('invalid')) + }) it('Context2d#patternQuality', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - assert.equal('good', ctx.patternQuality); - ctx.patternQuality = 'best'; - assert.equal('best', ctx.patternQuality); - ctx.patternQuality = 'invalid'; - assert.equal('best', ctx.patternQuality); - }); + var ctx = canvas.getContext('2d') + + assert.equal('good', ctx.patternQuality) + ctx.patternQuality = 'best' + assert.equal('best', ctx.patternQuality) + ctx.patternQuality = 'invalid' + assert.equal('best', ctx.patternQuality) + }) it('Context2d#imageSmoothingEnabled', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - assert.equal(true, ctx.imageSmoothingEnabled); - ctx.imageSmoothingEnabled = false; - assert.equal('good', ctx.patternQuality); - assert.equal(false, ctx.imageSmoothingEnabled); - assert.equal('good', ctx.patternQuality); - }); + var ctx = canvas.getContext('2d') + + assert.equal(true, ctx.imageSmoothingEnabled) + ctx.imageSmoothingEnabled = false + assert.equal('good', ctx.patternQuality) + assert.equal(false, ctx.imageSmoothingEnabled) + assert.equal('good', ctx.patternQuality) + }) it('Context2d#font=', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - assert.equal('10px sans-serif', ctx.font); - ctx.font = '15px Arial, sans-serif'; - assert.equal('15px Arial, sans-serif', ctx.font); - }); + var ctx = canvas.getContext('2d') + + assert.equal('10px sans-serif', ctx.font) + ctx.font = '15px Arial, sans-serif' + assert.equal('15px Arial, sans-serif', ctx.font) + }) it('Context2d#lineWidth=', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - - ctx.lineWidth = 10.0; - assert.equal(10, ctx.lineWidth); - ctx.lineWidth = Infinity; - assert.equal(10, ctx.lineWidth); - ctx.lineWidth = -Infinity; - assert.equal(10, ctx.lineWidth); - ctx.lineWidth = -5; - assert.equal(10, ctx.lineWidth); - ctx.lineWidth = 0; - assert.equal(10, ctx.lineWidth); - }); + + var ctx = canvas.getContext('2d') + + ctx.lineWidth = 10.0 + assert.equal(10, ctx.lineWidth) + ctx.lineWidth = Infinity + assert.equal(10, ctx.lineWidth) + ctx.lineWidth = -Infinity + assert.equal(10, ctx.lineWidth) + ctx.lineWidth = -5 + assert.equal(10, ctx.lineWidth) + ctx.lineWidth = 0 + assert.equal(10, ctx.lineWidth) + }) it('Context2d#antiAlias=', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - - assert.equal('default', ctx.antialias); - ctx.antialias = 'none'; - assert.equal('none', ctx.antialias); - ctx.antialias = 'gray'; - assert.equal('gray', ctx.antialias); - ctx.antialias = 'subpixel'; - assert.equal('subpixel', ctx.antialias); - ctx.antialias = 'invalid'; - assert.equal('subpixel', ctx.antialias); - ctx.antialias = 1; - assert.equal('subpixel', ctx.antialias); - }); + + var ctx = canvas.getContext('2d') + + assert.equal('default', ctx.antialias) + ctx.antialias = 'none' + assert.equal('none', ctx.antialias) + ctx.antialias = 'gray' + assert.equal('gray', ctx.antialias) + ctx.antialias = 'subpixel' + assert.equal('subpixel', ctx.antialias) + ctx.antialias = 'invalid' + assert.equal('subpixel', ctx.antialias) + ctx.antialias = 1 + assert.equal('subpixel', ctx.antialias) + }) it('Context2d#lineCap=', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - assert.equal('butt', ctx.lineCap); - ctx.lineCap = 'round'; - assert.equal('round', ctx.lineCap); - }); + var ctx = canvas.getContext('2d') + + assert.equal('butt', ctx.lineCap) + ctx.lineCap = 'round' + assert.equal('round', ctx.lineCap) + }) it('Context2d#lineJoin=', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - assert.equal('miter', ctx.lineJoin); - ctx.lineJoin = 'round'; - assert.equal('round', ctx.lineJoin); - }); + var ctx = canvas.getContext('2d') + + assert.equal('miter', ctx.lineJoin) + ctx.lineJoin = 'round' + assert.equal('round', ctx.lineJoin) + }) it('Context2d#globalAlpha=', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - assert.equal(1, ctx.globalAlpha); + var ctx = canvas.getContext('2d') + + assert.equal(1, ctx.globalAlpha) ctx.globalAlpha = 0.5 - assert.equal(0.5, ctx.globalAlpha); - }); + assert.equal(0.5, ctx.globalAlpha) + }) it('Context2d#isPointInPath()', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - - ctx.rect(5,5,100,100); - ctx.rect(50,100,10,10); - assert.ok(ctx.isPointInPath(10,10)); - assert.ok(ctx.isPointInPath(10,50)); - assert.ok(ctx.isPointInPath(100,100)); - assert.ok(ctx.isPointInPath(105,105)); - assert.ok(!ctx.isPointInPath(106,105)); - assert.ok(!ctx.isPointInPath(150,150)); - - assert.ok(ctx.isPointInPath(50,110)); - assert.ok(ctx.isPointInPath(60,110)); - assert.ok(!ctx.isPointInPath(70,110)); - assert.ok(!ctx.isPointInPath(50,120)); - }); + + var ctx = canvas.getContext('2d') + + ctx.rect(5, 5, 100, 100) + ctx.rect(50, 100, 10, 10) + assert.ok(ctx.isPointInPath(10, 10)) + assert.ok(ctx.isPointInPath(10, 50)) + assert.ok(ctx.isPointInPath(100, 100)) + assert.ok(ctx.isPointInPath(105, 105)) + assert.ok(!ctx.isPointInPath(106, 105)) + assert.ok(!ctx.isPointInPath(150, 150)) + + assert.ok(ctx.isPointInPath(50, 110)) + assert.ok(ctx.isPointInPath(60, 110)) + assert.ok(!ctx.isPointInPath(70, 110)) + assert.ok(!ctx.isPointInPath(50, 120)) + }) it('Context2d#textAlign', function () { - var canvas = createCanvas(200,200) - , ctx = canvas.getContext('2d'); - - assert.equal('start', ctx.textAlign); - ctx.textAlign = 'center'; - assert.equal('center', ctx.textAlign); - ctx.textAlign = 'right'; - assert.equal('right', ctx.textAlign); - ctx.textAlign = 'end'; - assert.equal('end', ctx.textAlign); - ctx.textAlign = 'fail'; - assert.equal('end', ctx.textAlign); - }); + var canvas = createCanvas(200, 200) + + var ctx = canvas.getContext('2d') + + assert.equal('start', ctx.textAlign) + ctx.textAlign = 'center' + assert.equal('center', ctx.textAlign) + ctx.textAlign = 'right' + assert.equal('right', ctx.textAlign) + ctx.textAlign = 'end' + assert.equal('end', ctx.textAlign) + ctx.textAlign = 'fail' + assert.equal('end', ctx.textAlign) + }) describe('#toBuffer', function () { it('Canvas#toBuffer()', function () { - var buf = createCanvas(200,200).toBuffer(); - assert.equal('PNG', buf.slice(1,4).toString()); - }); + var buf = createCanvas(200, 200).toBuffer() + assert.equal('PNG', buf.slice(1, 4).toString()) + }) it('Canvas#toBuffer("image/png")', function () { - var buf = createCanvas(200,200).toBuffer('image/png'); - assert.equal('PNG', buf.slice(1,4).toString()); - }); + var buf = createCanvas(200, 200).toBuffer('image/png') + assert.equal('PNG', buf.slice(1, 4).toString()) + }) it('Canvas#toBuffer("image/png", {resolution: 96})', function () { - const buf = createCanvas(200, 200).toBuffer('image/png', {resolution: 96}); + const buf = createCanvas(200, 200).toBuffer('image/png', { resolution: 96 }) // 3780 ppm ~= 96 ppi for (let i = 0; i < buf.length - 12; i++) { if (buf[i] === 0x70 && buf[i + 1] === 0x48 && buf[i + 2] === 0x59 && buf[i + 3] === 0x73) { // pHYs - assert.equal(buf[i + 4], 0); - assert.equal(buf[i + 5], 0); - assert.equal(buf[i + 6], 0x0e); - assert.equal(buf[i + 7], 0xc4); // x - assert.equal(buf[i + 8], 0); - assert.equal(buf[i + 9], 0); - assert.equal(buf[i + 10], 0x0e); - assert.equal(buf[i + 11], 0xc4); // y + assert.equal(buf[i + 4], 0) + assert.equal(buf[i + 5], 0) + assert.equal(buf[i + 6], 0x0e) + assert.equal(buf[i + 7], 0xc4) // x + assert.equal(buf[i + 8], 0) + assert.equal(buf[i + 9], 0) + assert.equal(buf[i + 10], 0x0e) + assert.equal(buf[i + 11], 0xc4) // y } } }) it('Canvas#toBuffer("image/png", {compressionLevel: 5})', function () { - var buf = createCanvas(200,200).toBuffer('image/png', {compressionLevel: 5}); - assert.equal('PNG', buf.slice(1,4).toString()); - }); + var buf = createCanvas(200, 200).toBuffer('image/png', { compressionLevel: 5 }) + assert.equal('PNG', buf.slice(1, 4).toString()) + }) it('Canvas#toBuffer("image/jpeg")', function () { - var buf = createCanvas(200,200).toBuffer('image/jpeg'); - assert.equal(buf[0], 0xff); - assert.equal(buf[1], 0xd8); - assert.equal(buf[buf.byteLength - 2], 0xff); - assert.equal(buf[buf.byteLength - 1], 0xd9); - }); + var buf = createCanvas(200, 200).toBuffer('image/jpeg') + assert.equal(buf[0], 0xff) + assert.equal(buf[1], 0xd8) + assert.equal(buf[buf.byteLength - 2], 0xff) + assert.equal(buf[buf.byteLength - 1], 0xd9) + }) it('Canvas#toBuffer("image/jpeg", {quality: 0.95})', function () { - var buf = createCanvas(200,200).toBuffer('image/jpeg', {quality: 0.95}); - assert.equal(buf[0], 0xff); - assert.equal(buf[1], 0xd8); - assert.equal(buf[buf.byteLength - 2], 0xff); - assert.equal(buf[buf.byteLength - 1], 0xd9); - }); + var buf = createCanvas(200, 200).toBuffer('image/jpeg', { quality: 0.95 }) + assert.equal(buf[0], 0xff) + assert.equal(buf[1], 0xd8) + assert.equal(buf[buf.byteLength - 2], 0xff) + assert.equal(buf[buf.byteLength - 1], 0xd9) + }) it('Canvas#toBuffer(callback)', function (done) { - createCanvas(200, 200).toBuffer(function(err, buf){ - assert.ok(!err); - assert.equal('PNG', buf.slice(1,4).toString()); - done(); - }); - }); + createCanvas(200, 200).toBuffer(function (err, buf) { + assert.ok(!err) + assert.equal('PNG', buf.slice(1, 4).toString()) + done() + }) + }) it('Canvas#toBuffer(callback, "image/jpeg")', function (done) { - createCanvas(200,200).toBuffer(function (err, buf) { - assert.ok(!err); - assert.equal(buf[0], 0xff); - assert.equal(buf[1], 0xd8); - assert.equal(buf[buf.byteLength - 2], 0xff); - assert.equal(buf[buf.byteLength - 1], 0xd9); - done(); - }, 'image/jpeg'); - }); + createCanvas(200, 200).toBuffer(function (err, buf) { + assert.ok(!err) + assert.equal(buf[0], 0xff) + assert.equal(buf[1], 0xd8) + assert.equal(buf[buf.byteLength - 2], 0xff) + assert.equal(buf[buf.byteLength - 1], 0xd9) + done() + }, 'image/jpeg') + }) it('Canvas#toBuffer(callback, "image/jpeg", {quality: 0.95})', function (done) { - createCanvas(200,200).toBuffer(function (err, buf) { - assert.ok(!err); - assert.equal(buf[0], 0xff); - assert.equal(buf[1], 0xd8); - assert.equal(buf[buf.byteLength - 2], 0xff); - assert.equal(buf[buf.byteLength - 1], 0xd9); - done(); - }, 'image/jpeg', {quality: 0.95}); - }); - - describe('#toBuffer("raw")', function() { + createCanvas(200, 200).toBuffer(function (err, buf) { + assert.ok(!err) + assert.equal(buf[0], 0xff) + assert.equal(buf[1], 0xd8) + assert.equal(buf[buf.byteLength - 2], 0xff) + assert.equal(buf[buf.byteLength - 1], 0xd9) + done() + }, 'image/jpeg', { quality: 0.95 }) + }) + + describe('#toBuffer("raw")', function () { var canvas = createCanvas(11, 10) - , ctx = canvas.getContext('2d'); - ctx.clearRect(0, 0, 11, 10); + var ctx = canvas.getContext('2d') + + ctx.clearRect(0, 0, 11, 10) - ctx.fillStyle = 'rgba(200, 200, 200, 0.505)'; - ctx.fillRect(0, 0, 5, 5); + ctx.fillStyle = 'rgba(200, 200, 200, 0.505)' + ctx.fillRect(0, 0, 5, 5) - ctx.fillStyle = 'red'; - ctx.fillRect(5, 0, 5, 5); + ctx.fillStyle = 'red' + ctx.fillRect(5, 0, 5, 5) - ctx.fillStyle = '#00ff00'; - ctx.fillRect(0, 5, 5, 5); + ctx.fillStyle = '#00ff00' + ctx.fillRect(0, 5, 5, 5) - ctx.fillStyle = 'black'; - ctx.fillRect(5, 5, 4, 5); + ctx.fillStyle = 'black' + ctx.fillRect(5, 5, 4, 5) /** Output: * *****RRRRR- @@ -615,284 +630,291 @@ describe('Canvas', function () { * GGGGGBBBB-- */ - var buf = canvas.toBuffer('raw'); - var stride = canvas.stride; + var buf = canvas.toBuffer('raw') + var stride = canvas.stride - var endianness = os.endianness(); + var endianness = os.endianness() - function assertPixel(u32, x, y, message) { - var expected = '0x' + u32.toString(16); + function assertPixel (u32, x, y, message) { + var expected = '0x' + u32.toString(16) // Buffer doesn't have readUInt32(): it only has readUInt32LE() and // readUInt32BE(). - var px = buf['readUInt32' + endianness](y * stride + x * 4); - var actual = '0x' + px.toString(16); + var px = buf['readUInt32' + endianness](y * stride + x * 4) + var actual = '0x' + px.toString(16) - assert.equal(actual, expected, message); + assert.equal(actual, expected, message) } - it('should have the correct size', function() { - assert.equal(buf.length, stride * 10); - }); - - it('does not premultiply alpha', function() { - assertPixel(0x80646464, 0, 0, 'first semitransparent pixel'); - assertPixel(0x80646464, 4, 4, 'last semitransparent pixel'); - }); - - it('draws red', function() { - assertPixel(0xffff0000, 5, 0, 'first red pixel'); - assertPixel(0xffff0000, 9, 4, 'last red pixel'); - }); - - it('draws green', function() { - assertPixel(0xff00ff00, 0, 5, 'first green pixel'); - assertPixel(0xff00ff00, 4, 9, 'last green pixel'); - }); - - it('draws black', function() { - assertPixel(0xff000000, 5, 5, 'first black pixel'); - assertPixel(0xff000000, 8, 9, 'last black pixel'); - }); - - it('leaves undrawn pixels black, transparent', function() { - assertPixel(0x0, 9, 5, 'first undrawn pixel'); - assertPixel(0x0, 9, 9, 'last undrawn pixel'); - }); - - it('is immutable', function() { - ctx.fillStyle = 'white'; - ctx.fillRect(0, 0, 10, 10); - canvas.toBuffer('raw'); // (side-effect: flushes canvas) - assertPixel(0xffff0000, 5, 0, 'first red pixel'); - }); - }); - }); + it('should have the correct size', function () { + assert.equal(buf.length, stride * 10) + }) + + it('does not premultiply alpha', function () { + assertPixel(0x80646464, 0, 0, 'first semitransparent pixel') + assertPixel(0x80646464, 4, 4, 'last semitransparent pixel') + }) + + it('draws red', function () { + assertPixel(0xffff0000, 5, 0, 'first red pixel') + assertPixel(0xffff0000, 9, 4, 'last red pixel') + }) + + it('draws green', function () { + assertPixel(0xff00ff00, 0, 5, 'first green pixel') + assertPixel(0xff00ff00, 4, 9, 'last green pixel') + }) + + it('draws black', function () { + assertPixel(0xff000000, 5, 5, 'first black pixel') + assertPixel(0xff000000, 8, 9, 'last black pixel') + }) + + it('leaves undrawn pixels black, transparent', function () { + assertPixel(0x0, 9, 5, 'first undrawn pixel') + assertPixel(0x0, 9, 9, 'last undrawn pixel') + }) + + it('is immutable', function () { + ctx.fillStyle = 'white' + ctx.fillRect(0, 0, 10, 10) + canvas.toBuffer('raw') // (side-effect: flushes canvas) + assertPixel(0xffff0000, 5, 0, 'first red pixel') + }) + }) + }) describe('#toDataURL()', function () { var canvas = createCanvas(200, 200) - , ctx = canvas.getContext('2d'); - ctx.fillRect(0,0,100,100); - ctx.fillStyle = 'red'; - ctx.fillRect(100,0,100,100); + var ctx = canvas.getContext('2d') + + ctx.fillRect(0, 0, 100, 100) + ctx.fillStyle = 'red' + ctx.fillRect(100, 0, 100, 100) it('toDataURL() works and defaults to PNG', function () { - assert.ok(canvas.toDataURL().startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL().startsWith('data:image/png;base64,')) + }) it('toDataURL(0.5) works and defaults to PNG', function () { - assert.ok(canvas.toDataURL(0.5).startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL(0.5).startsWith('data:image/png;base64,')) + }) it('toDataURL(undefined) works and defaults to PNG', function () { - assert.ok(canvas.toDataURL(undefined).startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL(undefined).startsWith('data:image/png;base64,')) + }) it('toDataURL("image/png") works', function () { - assert.ok(canvas.toDataURL('image/png').startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL('image/png').startsWith('data:image/png;base64,')) + }) it('toDataURL("image/png", 0.5) works', function () { - assert.ok(canvas.toDataURL('image/png').startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL('image/png').startsWith('data:image/png;base64,')) + }) it('toDataURL("iMaGe/PNg") works', function () { - assert.ok(canvas.toDataURL('iMaGe/PNg').startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL('iMaGe/PNg').startsWith('data:image/png;base64,')) + }) it('toDataURL("image/jpeg") works', function () { - assert.ok(canvas.toDataURL('image/jpeg').startsWith('data:image/jpeg;base64,')); - }); + assert.ok(canvas.toDataURL('image/jpeg').startsWith('data:image/jpeg;base64,')) + }) it('toDataURL(function (err, str) {...}) works and defaults to PNG', function (done) { - createCanvas(200,200).toDataURL(function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/png;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL(function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/png;base64,') === 0) + done() + }) + }) it('toDataURL(function (err, str) {...}) is async even with no canvas data', function (done) { - createCanvas().toDataURL(function(err, str){ - assert.ifError(err); - assert.ok('data:,' === str); - done(); - }); - }); + createCanvas().toDataURL(function (err, str) { + assert.ifError(err) + assert.ok(str === 'data:,') + done() + }) + }) it('toDataURL(0.5, function (err, str) {...}) works and defaults to PNG', function (done) { - createCanvas(200,200).toDataURL(0.5, function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/png;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL(0.5, function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/png;base64,') === 0) + done() + }) + }) it('toDataURL(undefined, function (err, str) {...}) works and defaults to PNG', function (done) { - createCanvas(200,200).toDataURL(undefined, function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/png;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL(undefined, function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/png;base64,') === 0) + done() + }) + }) it('toDataURL("image/png", function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('image/png', function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/png;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL('image/png', function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/png;base64,') === 0) + done() + }) + }) it('toDataURL("image/png", 0.5, function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('image/png', 0.5, function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/png;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL('image/png', 0.5, function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/png;base64,') === 0) + done() + }) + }) it('toDataURL("image/png", {}) works', function () { - assert.ok(canvas.toDataURL('image/png', {}).startsWith('data:image/png;base64,')); - }); + assert.ok(canvas.toDataURL('image/png', {}).startsWith('data:image/png;base64,')) + }) it('toDataURL("image/jpeg", {}) works', function () { - assert.ok(canvas.toDataURL('image/jpeg', {}).startsWith('data:image/jpeg;base64,')); - }); + assert.ok(canvas.toDataURL('image/jpeg', {}).startsWith('data:image/jpeg;base64,')) + }) it('toDataURL("image/jpeg", function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('image/jpeg', function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/jpeg;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL('image/jpeg', function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/jpeg;base64,') === 0) + done() + }) + }) it('toDataURL("iMAge/JPEG", function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('iMAge/JPEG', function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/jpeg;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL('iMAge/JPEG', function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/jpeg;base64,') === 0) + done() + }) + }) it('toDataURL("image/jpeg", undefined, function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('image/jpeg', undefined, function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/jpeg;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL('image/jpeg', undefined, function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/jpeg;base64,') === 0) + done() + }) + }) it('toDataURL("image/jpeg", 0.5, function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('image/jpeg', 0.5, function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/jpeg;base64,')); - done(); - }); - }); + createCanvas(200, 200).toDataURL('image/jpeg', 0.5, function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/jpeg;base64,') === 0) + done() + }) + }) it('toDataURL("image/jpeg", opts, function (err, str) {...}) works', function (done) { - createCanvas(200,200).toDataURL('image/jpeg', {quality: 100}, function(err, str){ - assert.ifError(err); - assert.ok(0 === str.indexOf('data:image/jpeg;base64,')); - done(); - }); - }); - }); + createCanvas(200, 200).toDataURL('image/jpeg', { quality: 100 }, function (err, str) { + assert.ifError(err) + assert.ok(str.indexOf('data:image/jpeg;base64,') === 0) + done() + }) + }) + }) describe('Context2d#createImageData(width, height)', function () { - it("works", function () { + it('works', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d'); - var imageData = ctx.createImageData(2,6); - assert.equal(2, imageData.width); - assert.equal(6, imageData.height); - assert.equal(2 * 6 * 4, imageData.data.length); + var ctx = canvas.getContext('2d') + + var imageData = ctx.createImageData(2, 6) + assert.equal(2, imageData.width) + assert.equal(6, imageData.height) + assert.equal(2 * 6 * 4, imageData.data.length) - assert.equal(0, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(0, imageData.data[3]); - }); + assert.equal(0, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(0, imageData.data[3]) + }) - it("works, A8 format", function () { + it('works, A8 format', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d', {pixelFormat: "A8"}); - var imageData = ctx.createImageData(2,6); - assert.equal(2, imageData.width); - assert.equal(6, imageData.height); - assert.equal(2 * 6 * 1, imageData.data.length); + var ctx = canvas.getContext('2d', { pixelFormat: 'A8' }) - assert.equal(0, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(0, imageData.data[3]); - }); + var imageData = ctx.createImageData(2, 6) + assert.equal(2, imageData.width) + assert.equal(6, imageData.height) + assert.equal(2 * 6 * 1, imageData.data.length) + + assert.equal(0, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(0, imageData.data[3]) + }) - it("works, A1 format", function () { + it('works, A1 format', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d', {pixelFormat: "A1"}); - var imageData = ctx.createImageData(2,6); - assert.equal(2, imageData.width); - assert.equal(6, imageData.height); - assert.equal(Math.ceil(2 * 6 / 8), imageData.data.length); + var ctx = canvas.getContext('2d', { pixelFormat: 'A1' }) - assert.equal(0, imageData.data[0]); - assert.equal(0, imageData.data[1]); - }); + var imageData = ctx.createImageData(2, 6) + assert.equal(2, imageData.width) + assert.equal(6, imageData.height) + assert.equal(Math.ceil(2 * 6 / 8), imageData.data.length) - it("works, RGB24 format", function () { + assert.equal(0, imageData.data[0]) + assert.equal(0, imageData.data[1]) + }) + + it('works, RGB24 format', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d', {pixelFormat: "RGB24"}); - var imageData = ctx.createImageData(2,6); - assert.equal(2, imageData.width); - assert.equal(6, imageData.height); - assert.equal(2 * 6 * 4, imageData.data.length); + var ctx = canvas.getContext('2d', { pixelFormat: 'RGB24' }) - assert.equal(0, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(0, imageData.data[3]); - }); + var imageData = ctx.createImageData(2, 6) + assert.equal(2, imageData.width) + assert.equal(6, imageData.height) + assert.equal(2 * 6 * 4, imageData.data.length) - it("works, RGB16_565 format", function () { + assert.equal(0, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(0, imageData.data[3]) + }) + + it('works, RGB16_565 format', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d', {pixelFormat: "RGB16_565"}); - var imageData = ctx.createImageData(2,6); - assert(imageData.data instanceof Uint16Array); - assert.equal(2, imageData.width); - assert.equal(6, imageData.height); - assert.equal(2 * 6, imageData.data.length); + var ctx = canvas.getContext('2d', { pixelFormat: 'RGB16_565' }) + + var imageData = ctx.createImageData(2, 6) + assert(imageData.data instanceof Uint16Array) + assert.equal(2, imageData.width) + assert.equal(6, imageData.height) + assert.equal(2 * 6, imageData.data.length) - assert.equal(0, imageData.data[0]); - assert.equal(0, imageData.data[1]); - }); - }); + assert.equal(0, imageData.data[0]) + assert.equal(0, imageData.data[1]) + }) + }) describe('Context2d#measureText()', function () { it('Context2d#measureText().width', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d'); - assert.ok(ctx.measureText('foo').width); - assert.ok(ctx.measureText('foo').width != ctx.measureText('foobar').width); - assert.ok(ctx.measureText('foo').width != ctx.measureText(' foo').width); - }); + var ctx = canvas.getContext('2d') + + assert.ok(ctx.measureText('foo').width) + assert.ok(ctx.measureText('foo').width != ctx.measureText('foobar').width) + assert.ok(ctx.measureText('foo').width != ctx.measureText(' foo').width) + }) it('works', function () { var canvas = createCanvas(20, 20) var ctx = canvas.getContext('2d') - ctx.font = "20px Arial" + ctx.font = '20px Arial' - ctx.textBaseline = "alphabetic" - var metrics = ctx.measureText("Alphabet") + ctx.textBaseline = 'alphabetic' + var metrics = ctx.measureText('Alphabet') // Zero if the given baseline is the alphabetic baseline assert.equal(metrics.alphabeticBaseline, 0) // Positive = going up from the baseline @@ -900,807 +922,806 @@ describe('Canvas', function () { // Positive = going down from the baseline assert.ok(metrics.actualBoundingBoxDescent > 0) // ~4-5 - ctx.textBaseline = "bottom" - metrics = ctx.measureText("Alphabet") + ctx.textBaseline = 'bottom' + metrics = ctx.measureText('Alphabet') assert.ok(metrics.alphabeticBaseline > 0) // ~4-5 assert.ok(metrics.actualBoundingBoxAscent > 0) // On the baseline or slightly above assert.ok(metrics.actualBoundingBoxDescent <= 0) - }); - }); + }) + }) it('Context2d#currentTransform', function () { - var canvas = createCanvas(20, 20); - var ctx = canvas.getContext('2d'); - - ctx.scale(0.1, 0.3); - var actual = ctx.currentTransform; - assert.equal(actual.a, 0.1); - assert.equal(actual.b, 0); - assert.equal(actual.c, 0); - assert.equal(actual.d, 0.3); - assert.equal(actual.e, 0); - assert.equal(actual.f, 0); - }); + var canvas = createCanvas(20, 20) + var ctx = canvas.getContext('2d') + + ctx.scale(0.1, 0.3) + var actual = ctx.currentTransform + assert.equal(actual.a, 0.1) + assert.equal(actual.b, 0) + assert.equal(actual.c, 0) + assert.equal(actual.d, 0.3) + assert.equal(actual.e, 0) + assert.equal(actual.f, 0) + }) it('Context2d#createImageData(ImageData)', function () { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d'); - var imageData = ctx.createImageData(ctx.createImageData(2, 6)); - assert.equal(2, imageData.width); - assert.equal(6, imageData.height); - assert.equal(2 * 6 * 4, imageData.data.length); - }); + var ctx = canvas.getContext('2d') + + var imageData = ctx.createImageData(ctx.createImageData(2, 6)) + assert.equal(2, imageData.width) + assert.equal(6, imageData.height) + assert.equal(2 * 6 * 4, imageData.data.length) + }) describe('Context2d#getImageData()', function () { - function createTestCanvas(useAlpha, attributes) { - var canvas = createCanvas(3, 6); - var ctx = canvas.getContext('2d', attributes); + function createTestCanvas (useAlpha, attributes) { + var canvas = createCanvas(3, 6) + var ctx = canvas.getContext('2d', attributes) - ctx.fillStyle = useAlpha ? 'rgba(255,0,0,0.25)' : '#f00'; - ctx.fillRect(0,0,1,6); + ctx.fillStyle = useAlpha ? 'rgba(255,0,0,0.25)' : '#f00' + ctx.fillRect(0, 0, 1, 6) - ctx.fillStyle = useAlpha ? 'rgba(0,255,0,0.5)' : '#0f0'; - ctx.fillRect(1,0,1,6); + ctx.fillStyle = useAlpha ? 'rgba(0,255,0,0.5)' : '#0f0' + ctx.fillRect(1, 0, 1, 6) - ctx.fillStyle = useAlpha ? 'rgba(0,0,255,0.75)' : '#00f'; - ctx.fillRect(2,0,1,6); + ctx.fillStyle = useAlpha ? 'rgba(0,0,255,0.75)' : '#00f' + ctx.fillRect(2, 0, 1, 6) - return ctx; + return ctx } - it("works, full width, RGBA32", function () { - var ctx = createTestCanvas(); - var imageData = ctx.getImageData(0,0,3,6); - - assert.equal(3, imageData.width); - assert.equal(6, imageData.height); - assert.equal(3 * 6 * 4, imageData.data.length); - - assert.equal(255, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(255, imageData.data[3]); - - assert.equal(0, imageData.data[4]); - assert.equal(255, imageData.data[5]); - assert.equal(0, imageData.data[6]); - assert.equal(255, imageData.data[7]); - - assert.equal(0, imageData.data[8]); - assert.equal(0, imageData.data[9]); - assert.equal(255, imageData.data[10]); - assert.equal(255, imageData.data[11]); - }); - - it("works, full width, RGB24", function () { - var ctx = createTestCanvas(false, {pixelFormat: "RGB24"}); - var imageData = ctx.getImageData(0,0,3,6); - assert.equal(3, imageData.width); - assert.equal(6, imageData.height); - assert.equal(3 * 6 * 4, imageData.data.length); - - assert.equal(255, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(255, imageData.data[3]); - - assert.equal(0, imageData.data[4]); - assert.equal(255, imageData.data[5]); - assert.equal(0, imageData.data[6]); - assert.equal(255, imageData.data[7]); - - assert.equal(0, imageData.data[8]); - assert.equal(0, imageData.data[9]); - assert.equal(255, imageData.data[10]); - assert.equal(255, imageData.data[11]); - }); - - it("works, full width, RGB16_565", function () { - var ctx = createTestCanvas(false, {pixelFormat: "RGB16_565"}); - var imageData = ctx.getImageData(0,0,3,6); - assert.equal(3, imageData.width); - assert.equal(6, imageData.height); - assert.equal(3 * 6 * 2, imageData.data.length); - - assert.equal((255 & 0b11111) << 11, imageData.data[0]); - assert.equal((255 & 0b111111) << 5, imageData.data[1]); - assert.equal((255 & 0b11111), imageData.data[2]); - - assert.equal((255 & 0b11111) << 11, imageData.data[3]); - assert.equal((255 & 0b111111) << 5, imageData.data[4]); - assert.equal((255 & 0b11111), imageData.data[5]); - }); - - it("works, full width, A8", function () { - var ctx = createTestCanvas(true, {pixelFormat: "A8"}); - var imageData = ctx.getImageData(0,0,3,6); - assert.equal(3, imageData.width); - assert.equal(6, imageData.height); - assert.equal(3 * 6, imageData.data.length); - - assert.equal(63, imageData.data[0]); - assert.equal(127, imageData.data[1]); - assert.equal(191, imageData.data[2]); - - assert.equal(63, imageData.data[3]); - assert.equal(127, imageData.data[4]); - assert.equal(191, imageData.data[5]); - }); - - it("works, full width, A1"); - - it("works, full width, RGB30"); - - it("works, slice, RGBA32", function () { - var ctx = createTestCanvas(); - var imageData = ctx.getImageData(0,0,2,1); - assert.equal(2, imageData.width); - assert.equal(1, imageData.height); - assert.equal(8, imageData.data.length); - - assert.equal(255, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(255, imageData.data[3]); - - assert.equal(0, imageData.data[4]); - assert.equal(255, imageData.data[5]); - assert.equal(0, imageData.data[6]); - assert.equal(255, imageData.data[7]); - }); - - it("works, slice, RGB24", function () { - var ctx = createTestCanvas(false, {pixelFormat: "RGB24"}); - var imageData = ctx.getImageData(0,0,2,1); - assert.equal(2, imageData.width); - assert.equal(1, imageData.height); - assert.equal(8, imageData.data.length); - - assert.equal(255, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(255, imageData.data[3]); - - assert.equal(0, imageData.data[4]); - assert.equal(255, imageData.data[5]); - assert.equal(0, imageData.data[6]); - assert.equal(255, imageData.data[7]); - }); - - it("works, slice, RGB16_565", function () { - var ctx = createTestCanvas(false, {pixelFormat: "RGB16_565"}); - var imageData = ctx.getImageData(0,0,2,1); - assert.equal(2, imageData.width); - assert.equal(1, imageData.height); - assert.equal(2 * 1 * 2, imageData.data.length); - - assert.equal((255 & 0b11111) << 11, imageData.data[0]); - assert.equal((255 & 0b111111) << 5, imageData.data[1]); - }); - - it("works, slice, A8", function () { - var ctx = createTestCanvas(true, {pixelFormat: "A8"}); - var imageData = ctx.getImageData(0,0,2,1); - assert.equal(2, imageData.width); - assert.equal(1, imageData.height); - assert.equal(2 * 1, imageData.data.length); - - assert.equal(63, imageData.data[0]); - assert.equal(127, imageData.data[1]); - }); - - it("works, slice, A1"); - - it("works, slice, RGB30"); - - it("works, assignment", function () { - var ctx = createTestCanvas(); - var data = ctx.getImageData(0,0,5,5).data; - data[0] = 50; - assert.equal(50, data[0]); - data[0] = 280; - assert.equal(255, data[0]); - data[0] = -4444; - assert.equal(0, data[0]); - }); - - it("throws if indexes are invalid", function () { - var ctx = createTestCanvas(); - assert.throws(function () { ctx.getImageData(0, 0, 0, 0); }, /IndexSizeError/); - }); - }); + it('works, full width, RGBA32', function () { + var ctx = createTestCanvas() + var imageData = ctx.getImageData(0, 0, 3, 6) + + assert.equal(3, imageData.width) + assert.equal(6, imageData.height) + assert.equal(3 * 6 * 4, imageData.data.length) + + assert.equal(255, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(255, imageData.data[3]) + + assert.equal(0, imageData.data[4]) + assert.equal(255, imageData.data[5]) + assert.equal(0, imageData.data[6]) + assert.equal(255, imageData.data[7]) + + assert.equal(0, imageData.data[8]) + assert.equal(0, imageData.data[9]) + assert.equal(255, imageData.data[10]) + assert.equal(255, imageData.data[11]) + }) + + it('works, full width, RGB24', function () { + var ctx = createTestCanvas(false, { pixelFormat: 'RGB24' }) + var imageData = ctx.getImageData(0, 0, 3, 6) + assert.equal(3, imageData.width) + assert.equal(6, imageData.height) + assert.equal(3 * 6 * 4, imageData.data.length) + + assert.equal(255, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(255, imageData.data[3]) + + assert.equal(0, imageData.data[4]) + assert.equal(255, imageData.data[5]) + assert.equal(0, imageData.data[6]) + assert.equal(255, imageData.data[7]) + + assert.equal(0, imageData.data[8]) + assert.equal(0, imageData.data[9]) + assert.equal(255, imageData.data[10]) + assert.equal(255, imageData.data[11]) + }) + + it('works, full width, RGB16_565', function () { + var ctx = createTestCanvas(false, { pixelFormat: 'RGB16_565' }) + var imageData = ctx.getImageData(0, 0, 3, 6) + assert.equal(3, imageData.width) + assert.equal(6, imageData.height) + assert.equal(3 * 6 * 2, imageData.data.length) + + assert.equal((255 & 0b11111) << 11, imageData.data[0]) + assert.equal((255 & 0b111111) << 5, imageData.data[1]) + assert.equal((255 & 0b11111), imageData.data[2]) + + assert.equal((255 & 0b11111) << 11, imageData.data[3]) + assert.equal((255 & 0b111111) << 5, imageData.data[4]) + assert.equal((255 & 0b11111), imageData.data[5]) + }) + + it('works, full width, A8', function () { + var ctx = createTestCanvas(true, { pixelFormat: 'A8' }) + var imageData = ctx.getImageData(0, 0, 3, 6) + assert.equal(3, imageData.width) + assert.equal(6, imageData.height) + assert.equal(3 * 6, imageData.data.length) + + assert.equal(63, imageData.data[0]) + assert.equal(127, imageData.data[1]) + assert.equal(191, imageData.data[2]) + + assert.equal(63, imageData.data[3]) + assert.equal(127, imageData.data[4]) + assert.equal(191, imageData.data[5]) + }) + + it('works, full width, A1') + + it('works, full width, RGB30') + + it('works, slice, RGBA32', function () { + var ctx = createTestCanvas() + var imageData = ctx.getImageData(0, 0, 2, 1) + assert.equal(2, imageData.width) + assert.equal(1, imageData.height) + assert.equal(8, imageData.data.length) + + assert.equal(255, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(255, imageData.data[3]) + + assert.equal(0, imageData.data[4]) + assert.equal(255, imageData.data[5]) + assert.equal(0, imageData.data[6]) + assert.equal(255, imageData.data[7]) + }) + + it('works, slice, RGB24', function () { + var ctx = createTestCanvas(false, { pixelFormat: 'RGB24' }) + var imageData = ctx.getImageData(0, 0, 2, 1) + assert.equal(2, imageData.width) + assert.equal(1, imageData.height) + assert.equal(8, imageData.data.length) + + assert.equal(255, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(255, imageData.data[3]) + + assert.equal(0, imageData.data[4]) + assert.equal(255, imageData.data[5]) + assert.equal(0, imageData.data[6]) + assert.equal(255, imageData.data[7]) + }) + + it('works, slice, RGB16_565', function () { + var ctx = createTestCanvas(false, { pixelFormat: 'RGB16_565' }) + var imageData = ctx.getImageData(0, 0, 2, 1) + assert.equal(2, imageData.width) + assert.equal(1, imageData.height) + assert.equal(2 * 1 * 2, imageData.data.length) + + assert.equal((255 & 0b11111) << 11, imageData.data[0]) + assert.equal((255 & 0b111111) << 5, imageData.data[1]) + }) + + it('works, slice, A8', function () { + var ctx = createTestCanvas(true, { pixelFormat: 'A8' }) + var imageData = ctx.getImageData(0, 0, 2, 1) + assert.equal(2, imageData.width) + assert.equal(1, imageData.height) + assert.equal(2 * 1, imageData.data.length) + + assert.equal(63, imageData.data[0]) + assert.equal(127, imageData.data[1]) + }) + + it('works, slice, A1') + + it('works, slice, RGB30') + + it('works, assignment', function () { + var ctx = createTestCanvas() + var data = ctx.getImageData(0, 0, 5, 5).data + data[0] = 50 + assert.equal(50, data[0]) + data[0] = 280 + assert.equal(255, data[0]) + data[0] = -4444 + assert.equal(0, data[0]) + }) + + it('throws if indexes are invalid', function () { + var ctx = createTestCanvas() + assert.throws(function () { ctx.getImageData(0, 0, 0, 0) }, /IndexSizeError/) + }) + }) it('Context2d#createPattern(Canvas)', function () { - var pattern = createCanvas(2,2) - , checkers = pattern.getContext('2d'); + var pattern = createCanvas(2, 2) + + var checkers = pattern.getContext('2d') // white - checkers.fillStyle = '#fff'; - checkers.fillRect(0,0,2,2); + checkers.fillStyle = '#fff' + checkers.fillRect(0, 0, 2, 2) // black - checkers.fillStyle = '#000'; - checkers.fillRect(0,0,1,1); - checkers.fillRect(1,1,1,1); + checkers.fillStyle = '#000' + checkers.fillRect(0, 0, 1, 1) + checkers.fillRect(1, 1, 1, 1) - var imageData = checkers.getImageData(0,0,2,2); - assert.equal(2, imageData.width); - assert.equal(2, imageData.height); - assert.equal(16, imageData.data.length); + var imageData = checkers.getImageData(0, 0, 2, 2) + assert.equal(2, imageData.width) + assert.equal(2, imageData.height) + assert.equal(16, imageData.data.length) // (0,0) black - assert.equal(0, imageData.data[0]); - assert.equal(0, imageData.data[1]); - assert.equal(0, imageData.data[2]); - assert.equal(255, imageData.data[3]); + assert.equal(0, imageData.data[0]) + assert.equal(0, imageData.data[1]) + assert.equal(0, imageData.data[2]) + assert.equal(255, imageData.data[3]) // (1,0) white - assert.equal(255, imageData.data[4]); - assert.equal(255, imageData.data[5]); - assert.equal(255, imageData.data[6]); - assert.equal(255, imageData.data[7]); + assert.equal(255, imageData.data[4]) + assert.equal(255, imageData.data[5]) + assert.equal(255, imageData.data[6]) + assert.equal(255, imageData.data[7]) // (0,1) white - assert.equal(255, imageData.data[8]); - assert.equal(255, imageData.data[9]); - assert.equal(255, imageData.data[10]); - assert.equal(255, imageData.data[11]); + assert.equal(255, imageData.data[8]) + assert.equal(255, imageData.data[9]) + assert.equal(255, imageData.data[10]) + assert.equal(255, imageData.data[11]) // (1,1) black - assert.equal(0, imageData.data[12]); - assert.equal(0, imageData.data[13]); - assert.equal(0, imageData.data[14]); - assert.equal(255, imageData.data[15]); + assert.equal(0, imageData.data[12]) + assert.equal(0, imageData.data[13]) + assert.equal(0, imageData.data[14]) + assert.equal(255, imageData.data[15]) var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d') - , pattern = ctx.createPattern(pattern); - - ctx.fillStyle = pattern; - ctx.fillRect(0,0,20,20); - - var imageData = ctx.getImageData(0,0,20,20); - assert.equal(20, imageData.width); - assert.equal(20, imageData.height); - assert.equal(1600, imageData.data.length); - - var i=0, b = true; - while(i { var canvas = createCanvas(20, 20) - , ctx = canvas.getContext('2d') - , pattern = ctx.createPattern(img); - ctx.fillStyle = pattern; - ctx.fillRect(0,0,20,20); + var ctx = canvas.getContext('2d') + + var pattern = ctx.createPattern(img) + + ctx.fillStyle = pattern + ctx.fillRect(0, 0, 20, 20) - var imageData = ctx.getImageData(0,0,20,20); - assert.equal(20, imageData.width); - assert.equal(20, imageData.height); - assert.equal(1600, imageData.data.length); + var imageData = ctx.getImageData(0, 0, 20, 20) + assert.equal(20, imageData.width) + assert.equal(20, imageData.height) + assert.equal(1600, imageData.data.length) - var i=0, b = true; - while (i= 6) - obj[Symbol.toPrimitive] = function () { return 0.89; }; - else - obj.valueOf = function () { return 0.89; }; - ctx.resetTransform(); - testAngle(obj, 0.89); + var obj = Object.create(null) + if (+process.version.match(/\d+/) >= 6) { obj[Symbol.toPrimitive] = function () { return 0.89 } } else { obj.valueOf = function () { return 0.89 } } + ctx.resetTransform() + testAngle(obj, 0.89) // NaN - ctx.resetTransform(); - ctx.rotate(0.91); - testAngle(NaN, 0.91); + ctx.resetTransform() + ctx.rotate(0.91) + testAngle(NaN, 0.91) // Infinite value - ctx.resetTransform(); - ctx.rotate(0.94); - testAngle(-Infinity, 0.94); + ctx.resetTransform() + ctx.rotate(0.94) + testAngle(-Infinity, 0.94) - function testAngle(angle, expected){ - ctx.rotate(angle); + function testAngle (angle, expected) { + ctx.rotate(angle) - var mat = ctx.currentTransform; - var sin = Math.sin(expected); - var cos = Math.cos(expected); + var mat = ctx.currentTransform + var sin = Math.sin(expected) + var cos = Math.cos(expected) - assert.ok(Math.abs(mat.m11 - cos) < Number.EPSILON); - assert.ok(Math.abs(mat.m12 - sin) < Number.EPSILON); - assert.ok(Math.abs(mat.m21 + sin) < Number.EPSILON); - assert.ok(Math.abs(mat.m22 - cos) < Number.EPSILON); + assert.ok(Math.abs(mat.m11 - cos) < Number.EPSILON) + assert.ok(Math.abs(mat.m12 - sin) < Number.EPSILON) + assert.ok(Math.abs(mat.m21 + sin) < Number.EPSILON) + assert.ok(Math.abs(mat.m22 - cos) < Number.EPSILON) } - }); + }) it('Context2d#drawImage()', function () { - var canvas = createCanvas(500, 500); - var ctx = canvas.getContext('2d'); + var canvas = createCanvas(500, 500) + var ctx = canvas.getContext('2d') // Drawing canvas to itself - ctx.fillStyle = 'white'; - ctx.fillRect(0, 0, 500, 500); - ctx.fillStyle = 'black'; - ctx.fillRect(5, 5, 10, 10); - ctx.drawImage(canvas, 20, 20); - - var imgd = ctx.getImageData(0, 0, 500, 500); - var data = imgd.data; - var count = 0; - - for(var i = 0; i < 500 * 500 * 4; i += 4){ - if(data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0) - count++; + ctx.fillStyle = 'white' + ctx.fillRect(0, 0, 500, 500) + ctx.fillStyle = 'black' + ctx.fillRect(5, 5, 10, 10) + ctx.drawImage(canvas, 20, 20) + + var imgd = ctx.getImageData(0, 0, 500, 500) + var data = imgd.data + var count = 0 + + for (var i = 0; i < 500 * 500 * 4; i += 4) { + if (data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0) { count++ } } - assert.strictEqual(count, 10 * 10 * 2); + assert.strictEqual(count, 10 * 10 * 2) // Drawing zero-width image - ctx.drawImage(canvas, 0, 0, 0, 0, 0, 0, 0, 0); - ctx.drawImage(canvas, 0, 0, 0, 0, 1, 1, 1, 1); - ctx.drawImage(canvas, 1, 1, 1, 1, 0, 0, 0, 0); - ctx.fillStyle = 'white'; - ctx.fillRect(0, 0, 500, 500); - - imgd = ctx.getImageData(0, 0, 500, 500); - data = imgd.data; - count = 0; - - for(i = 0; i < 500 * 500 * 4; i += 4){ - if(data[i] === 255 && data[i + 1] === 255 && data[i + 2] === 255) - count++; + ctx.drawImage(canvas, 0, 0, 0, 0, 0, 0, 0, 0) + ctx.drawImage(canvas, 0, 0, 0, 0, 1, 1, 1, 1) + ctx.drawImage(canvas, 1, 1, 1, 1, 0, 0, 0, 0) + ctx.fillStyle = 'white' + ctx.fillRect(0, 0, 500, 500) + + imgd = ctx.getImageData(0, 0, 500, 500) + data = imgd.data + count = 0 + + for (i = 0; i < 500 * 500 * 4; i += 4) { + if (data[i] === 255 && data[i + 1] === 255 && data[i + 2] === 255) { count++ } } - assert.strictEqual(count, 500 * 500); - }); + assert.strictEqual(count, 500 * 500) + }) it('Context2d#SetFillColor()', function () { - var canvas = createCanvas(2, 2); - var ctx = canvas.getContext('2d'); + var canvas = createCanvas(2, 2) + var ctx = canvas.getContext('2d') - ctx.fillStyle = ['#808080']; - ctx.fillRect(0, 0, 2, 2); - var data = ctx.getImageData(0, 0, 2, 2).data; + ctx.fillStyle = ['#808080'] + ctx.fillRect(0, 0, 2, 2) + var data = ctx.getImageData(0, 0, 2, 2).data data.forEach(function (byte, index) { - if (index + 1 & 3) - assert.strictEqual(byte, 128); - else - assert.strictEqual(byte, 255); - }); + if (index + 1 & 3) { assert.strictEqual(byte, 128) } else { assert.strictEqual(byte, 255) } + }) assert.throws(function () { - ctx.fillStyle = Object.create(null); - }); - }); - -}); + ctx.fillStyle = Object.create(null) + }) + }) +}) diff --git a/test/dommatrix.test.js b/test/dommatrix.test.js index 212ce40a4..0386417b7 100644 --- a/test/dommatrix.test.js +++ b/test/dommatrix.test.js @@ -9,22 +9,22 @@ const assert = require('assert') // This doesn't need to be precise; we're not testing the engine's trig // implementations. const TOLERANCE = 0.001 -function assertApprox(actual, expected, tolerance) { +function assertApprox (actual, expected, tolerance) { if (typeof tolerance !== 'number') tolerance = TOLERANCE assert.ok(expected > actual - tolerance && expected < actual + tolerance, `Expected ${expected} to equal ${actual} +/- ${tolerance}`) } -function assertApproxDeep(actual, expected, tolerance) { +function assertApproxDeep (actual, expected, tolerance) { expected.forEach(function (value, index) { assertApprox(actual[index], value) }) } describe('DOMMatrix', function () { - var Avals = [4,5,1,8, 0,3,6,1, 3,5,0,9, 2,4,6,1] - var Bvals = [1,5,1,0, 0,3,6,1, 3,5,7,2, 2,0,6,1] - var AxB = [7,25,31,22, 20,43,24,58, 37,73,45,94, 28,44,8,71] - var BxA = [23,40,89,15, 20,39,66,16, 21,30,87,14, 22,52,74,17] + var Avals = [4, 5, 1, 8, 0, 3, 6, 1, 3, 5, 0, 9, 2, 4, 6, 1] + var Bvals = [1, 5, 1, 0, 0, 3, 6, 1, 3, 5, 7, 2, 2, 0, 6, 1] + var AxB = [7, 25, 31, 22, 20, 43, 24, 58, 37, 73, 45, 94, 28, 44, 8, 71] + var BxA = [23, 40, 89, 15, 20, 39, 66, 16, 21, 30, 87, 14, 22, 52, 74, 17] describe('constructor, general', function () { it('aliases a,b,c,d,e,f properly', function () { @@ -374,7 +374,7 @@ describe('DOMMatrix', function () { }) describe('skewYSelf', function () {}) - + describe('flipX', function () { it('works', function () { var x = new DOMMatrix() @@ -409,14 +409,14 @@ describe('DOMMatrix', function () { describe('transformPoint', function () { it('works', function () { var x = new DOMMatrix() - var r = x.transformPoint({x: 1, y: 2, z: 3}) + var r = x.transformPoint({ x: 1, y: 2, z: 3 }) assert.strictEqual(r.x, 1) assert.strictEqual(r.y, 2) assert.strictEqual(r.z, 3) assert.strictEqual(r.w, 1) x.rotateSelf(70) - r = x.transformPoint({x: 2, y: 3, z: 4}) + r = x.transformPoint({ x: 2, y: 3, z: 4 }) assertApprox(r.x, -2.13503) assertApprox(r.y, 2.905445) assert.strictEqual(r.z, 4) @@ -437,7 +437,7 @@ describe('DOMMatrix', function () { ]) }) }) - + describe('toFloat64Array', function () { it('works', function () { var x = new DOMMatrix() diff --git a/test/image.test.js b/test/image.test.js index 8e79cae2f..e06642c65 100644 --- a/test/image.test.js +++ b/test/image.test.js @@ -6,7 +6,7 @@ * Module dependencies. */ -const {createCanvas, loadImage} = require('../'); +const { createCanvas, loadImage } = require('../') const Image = require('../').Image const assert = require('assert') @@ -23,12 +23,12 @@ const bmp_dir = `${__dirname}/fixtures/bmp` describe('Image', function () { it('Prototype and ctor are well-shaped, don\'t hit asserts on accessors (GH-803)', function () { - var img = new Image(); - assert.throws(function () { Image.prototype.width; }, /incompatible receiver/); - assert(!img.hasOwnProperty('width')); - assert('width' in img); - assert(Image.prototype.hasOwnProperty('width')); - }); + var img = new Image() + assert.throws(function () { Image.prototype.width }, /incompatible receiver/) + assert(!img.hasOwnProperty('width')) + assert('width' in img) + assert(Image.prototype.hasOwnProperty('width')) + }) it('loads JPEG image', function () { return loadImage(jpg_face).then((img) => { @@ -87,7 +87,7 @@ describe('Image', function () { it('loads SVG data URL base64', function () { const base64Enc = fs.readFileSync(svg_tree, 'base64') const dataURL = `data:image/svg+xml;base64,${base64Enc}` - return loadImage(dataURL).then((img) => { + return loadImage(dataURL).then((img) => { assert.strictEqual(img.onerror, null) assert.strictEqual(img.onload, null) assert.strictEqual(img.width, 200) @@ -99,7 +99,7 @@ describe('Image', function () { it('loads SVG data URL utf8', function () { const utf8Encoded = fs.readFileSync(svg_tree, 'utf8') const dataURL = `data:image/svg+xml;utf8,${utf8Encoded}` - return loadImage(dataURL).then((img) => { + return loadImage(dataURL).then((img) => { assert.strictEqual(img.onerror, null) assert.strictEqual(img.onload, null) assert.strictEqual(img.width, 200) @@ -154,7 +154,7 @@ describe('Image', function () { it('captures errors from libjpeg', function (done) { const img = new Image() img.onerror = err => { - assert.equal(err.message, "JPEG datastream contains no image") + assert.equal(err.message, 'JPEG datastream contains no image') done() } img.src = `${__dirname}/fixtures/159-crash1.jpg` @@ -213,7 +213,7 @@ describe('Image', function () { }) }) - it('should unbind Image#onload', function() { + it('should unbind Image#onload', function () { return loadImage(png_clock).then((img) => { let onloadCalled = 0 @@ -240,7 +240,7 @@ describe('Image', function () { }) }) - it('should unbind Image#onerror', function() { + it('should unbind Image#onerror', function () { return loadImage(png_clock).then((img) => { let onloadCalled = 0 let onerrorCalled = 0 @@ -297,53 +297,53 @@ describe('Image', function () { }) it('does not contain `source` property', function () { - var keys = Reflect.ownKeys(Image.prototype); - assert.ok(!keys.includes('source')); - assert.ok(!keys.includes('getSource')); - assert.ok(!keys.includes('setSource')); - }); + var keys = Reflect.ownKeys(Image.prototype) + assert.ok(!keys.includes('source')) + assert.ok(!keys.includes('getSource')) + assert.ok(!keys.includes('setSource')) + }) describe('supports BMP', function () { it('parses 1-bit image', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - assert.strictEqual(img.width, 111); - assert.strictEqual(img.height, 72); - done(); - }; + assert.strictEqual(img.width, 111) + assert.strictEqual(img.height, 72) + done() + } - img.onerror = err => { throw err; }; - img.src = path.join(bmp_dir, '1-bit.bmp'); - }); + img.onerror = err => { throw err } + img.src = path.join(bmp_dir, '1-bit.bmp') + }) it('parses 24-bit image', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - assert.strictEqual(img.width, 2); - assert.strictEqual(img.height, 2); + assert.strictEqual(img.width, 2) + assert.strictEqual(img.height, 2) testImgd(img, [ 0, 0, 255, 255, 0, 255, 0, 255, 255, 0, 0, 255, - 255, 255, 255, 255, - ]); + 255, 255, 255, 255 + ]) - done(); - }; + done() + } - img.onerror = err => { throw err; }; - img.src = path.join(bmp_dir, '24-bit.bmp'); - }); + img.onerror = err => { throw err } + img.src = path.join(bmp_dir, '24-bit.bmp') + }) it('parses 32-bit image', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - assert.strictEqual(img.width, 4); - assert.strictEqual(img.height, 2); + assert.strictEqual(img.width, 4) + assert.strictEqual(img.height, 2) testImgd(img, [ 0, 0, 255, 255, @@ -353,88 +353,88 @@ describe('Image', function () { 0, 0, 255, 127, 0, 255, 0, 127, 255, 0, 0, 127, - 255, 255, 255, 127, - ]); - - done(); - }; + 255, 255, 255, 127 + ]) - img.onerror = err => { throw err; }; - img.src = fs.readFileSync(path.join(bmp_dir, '32-bit.bmp')); // Also tests loading from buffer - }); + done() + } + + img.onerror = err => { throw err } + img.src = fs.readFileSync(path.join(bmp_dir, '32-bit.bmp')) // Also tests loading from buffer + }) it('parses minimal BMP', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - assert.strictEqual(img.width, 1); - assert.strictEqual(img.height, 1); + assert.strictEqual(img.width, 1) + assert.strictEqual(img.height, 1) testImgd(img, [ - 255, 0, 0, 255, - ]); - - done(); - }; + 255, 0, 0, 255 + ]) + + done() + } - img.onerror = err => { throw err; }; - img.src = path.join(bmp_dir, 'min.bmp'); - }); + img.onerror = err => { throw err } + img.src = path.join(bmp_dir, 'min.bmp') + }) it('properly handles negative height', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - assert.strictEqual(img.width, 1); - assert.strictEqual(img.height, 2); + assert.strictEqual(img.width, 1) + assert.strictEqual(img.height, 2) testImgd(img, [ 255, 0, 0, 255, - 0, 255, 0, 255, - ]); - - done(); - }; + 0, 255, 0, 255 + ]) - img.onerror = err => { throw err; }; - img.src = path.join(bmp_dir, 'negative-height.bmp'); - }); + done() + } + + img.onerror = err => { throw err } + img.src = path.join(bmp_dir, 'negative-height.bmp') + }) it('catches BMP errors', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - throw new Error('Invalid image should not be loaded properly'); - }; + throw new Error('Invalid image should not be loaded properly') + } img.onerror = err => { - let msg = 'Error while processing file header - unexpected end of file'; - assert.strictEqual(err.message, msg); - done(); - }; + let msg = 'Error while processing file header - unexpected end of file' + assert.strictEqual(err.message, msg) + done() + } - img.src = Buffer.from('BM'); - }); + img.src = Buffer.from('BM') + }) it('BMP bomb', function (done) { - let img = new Image(); + let img = new Image() img.onload = () => { - throw new Error('Invalid image should not be loaded properly'); - }; + throw new Error('Invalid image should not be loaded properly') + } img.onerror = err => { - done(); - }; + done() + } - img.src = path.join(bmp_dir, 'bomb.bmp'); - }); + img.src = path.join(bmp_dir, 'bomb.bmp') + }) - function testImgd(img, data){ - let ctx = createCanvas(img.width, img.height).getContext('2d'); - ctx.drawImage(img, 0, 0); - var actualData = ctx.getImageData(0, 0, img.width, img.height).data; - assert.strictEqual(String(actualData), String(data)); + function testImgd (img, data) { + let ctx = createCanvas(img.width, img.height).getContext('2d') + ctx.drawImage(img, 0, 0) + var actualData = ctx.getImageData(0, 0, img.width, img.height).data + assert.strictEqual(String(actualData), String(data)) } - }); + }) }) diff --git a/test/imageData.test.js b/test/imageData.test.js index cfffe9aaf..26acd61f4 100644 --- a/test/imageData.test.js +++ b/test/imageData.test.js @@ -3,14 +3,14 @@ 'use strict' const createImageData = require('../').createImageData -const ImageData = require('../').ImageData; +const ImageData = require('../').ImageData const assert = require('assert') describe('ImageData', function () { it('Prototype and ctor are well-shaped, don\'t hit asserts on accessors (GH-803)', function () { - assert.throws(function () { ImageData.prototype.width; }, /incompatible receiver/); - }); + assert.throws(function () { ImageData.prototype.width }, /incompatible receiver/) + }) it('should throw with invalid numeric arguments', function () { assert.throws(() => { createImageData(0, 0) }, /width is zero/) @@ -33,7 +33,7 @@ describe('ImageData', function () { assert.throws(() => { createImageData(new Uint8ClampedArray(3), 0) }, /source width is zero/) // Note: Some errors thrown by browsers are not thrown by node-canvas // because our ImageData can support different BPPs. - }); + }) it('should construct with Uint8ClampedArray', function () { let data, imageData @@ -51,7 +51,7 @@ describe('ImageData', function () { assert.strictEqual(imageData.height, 4) assert(imageData.data instanceof Uint8ClampedArray) assert.strictEqual(imageData.data.length, 48) - }); + }) it('should construct with Uint16Array', function () { let data = new Uint16Array(2 * 3 * 2) @@ -67,5 +67,5 @@ describe('ImageData', function () { assert.strictEqual(imagedata.height, 4) assert(imagedata.data instanceof Uint16Array) assert.strictEqual(imagedata.data.length, 24) - }); -}); + }) +}) diff --git a/util/win_jpeg_lookup.js b/util/win_jpeg_lookup.js index 82869945a..40a1e03cf 100644 --- a/util/win_jpeg_lookup.js +++ b/util/win_jpeg_lookup.js @@ -5,17 +5,17 @@ if (process.arch === 'x64') { paths.unshift('C:/libjpeg-turbo64') } -paths.forEach(function(path){ +paths.forEach(function (path) { if (exists(path)) { process.stdout.write(path) process.exit() } }) -function exists(path) { +function exists (path) { try { return fs.lstatSync(path).isDirectory() - } catch(e) { + } catch (e) { return false } } From 9ebb62487988b4660ed844e10e186fac9ead0c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 20 Nov 2018 05:47:16 +0100 Subject: [PATCH 079/183] Move `getFormat()` implementation out of header file --- src/backend/Backend.cc | 6 ++++++ src/backend/Backend.h | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 0ea3b7af2..28e7fc95d 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -3,6 +3,7 @@ Backend::Backend(string name) : name(name) + , format(CAIRO_FORMAT_INVALID) , width(0) , height(0) , surface(NULL) @@ -10,6 +11,7 @@ Backend::Backend(string name) {} Backend::Backend(string name, int width, int height) : name(name) + , format(CAIRO_FORMAT_INVALID) , width(width) , height(height) , surface(NULL) @@ -86,6 +88,10 @@ void Backend::setHeight(int height_) this->recreateSurface(); } +cairo_format_t Backend::getFormat() +{ + return this->format; +} bool Backend::isSurfaceValid(){ bool hadSurface = surface != NULL; bool isValid = true; diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 5bbc80f4e..31a67d57d 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -21,6 +21,7 @@ class Backend : public Nan::ObjectWrap private: const string name; const char* error = NULL; + cairo_format_t format; protected: int width; @@ -53,9 +54,7 @@ class Backend : public Nan::ObjectWrap virtual void setHeight(int height); // Overridden by ImageBackend. SVG and PDF thus always return INVALID. - virtual cairo_format_t getFormat() { - return CAIRO_FORMAT_INVALID; - } + virtual cairo_format_t getFormat(); bool isSurfaceValid(); inline const char* getError(){ return error; } From b37d64813ce44ad91be05083c6c852668158afa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 20 Nov 2018 05:47:59 +0100 Subject: [PATCH 080/183] Added `Backend::setFormat()` method --- src/backend/Backend.cc | 6 ++++++ src/backend/Backend.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 28e7fc95d..1379a9339 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -92,6 +92,12 @@ cairo_format_t Backend::getFormat() { return this->format; } +void Backend::setFormat(cairo_format_t format) +{ + this->format = format; + this->recreateSurface(); +} + bool Backend::isSurfaceValid(){ bool hadSurface = surface != NULL; bool isValid = true; diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 31a67d57d..ddb74c985 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -55,6 +55,7 @@ class Backend : public Nan::ObjectWrap // Overridden by ImageBackend. SVG and PDF thus always return INVALID. virtual cairo_format_t getFormat(); + virtual void setFormat(cairo_format_t format); bool isSurfaceValid(); inline const char* getError(){ return error; } From 2aa765cbc42086ce04c3e1fc3cca8311ea71b394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 20 Nov 2018 05:49:48 +0100 Subject: [PATCH 081/183] Added `FBDevBackend::setFormat()` method --- src/backend/FBDevBackend.cc | 21 +++++++++++++++++++++ src/backend/FBDevBackend.h | 1 + 2 files changed, 22 insertions(+) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 581be177c..b1cc44829 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -113,6 +113,27 @@ void FBDevBackend::setHeight(int height) Backend::setHeight(width); } +void FBDevBackend::setFormat(cairo_format_t format) +{ + struct fb_var_screeninfo fb_vinfo; + + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, + "Error reading variable framebuffer information"); + + switch(format) + { + case CAIRO_FORMAT_RGB16_565: fb_vinfo.bits_per_pixel = 16; break; + case CAIRO_FORMAT_ARGB32: fb_vinfo.bits_per_pixel = 32; break; + + default: + throw FBDevBackendException("Only valid formats are RGB16_565 & ARGB32"); + } + + this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, + "Error setting variable framebuffer information"); + + Backend::setFormat(format); +} Nan::Persistent FBDevBackend::constructor; diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 55e90e51c..51d51400b 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -17,6 +17,7 @@ cairo_surface_t* createSurface(); void setWidth(int width); void setHeight(int height); + void setFormat(cairo_format_t format); public: FBDevBackend(string deviceName); static Nan::Persistent constructor; From 2e60f78beaa21a1a85e49574b176bc340cae1a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 20 Nov 2018 05:51:53 +0100 Subject: [PATCH 082/183] [FBDevBackend] Get `width` and `height` in constructor --- src/backend/FBDevBackend.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index b1cc44829..723a0ebb3 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -37,6 +37,14 @@ FBDevBackend::FBDevBackend(string deviceName) if(this->fb_data == MAP_FAILED) throw FBDevBackendException("Failed to map framebuffer device to memory"); + + struct fb_var_screeninfo fb_vinfo; + + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, + "Error reading variable framebuffer information"); + + Backend::setWidth(fb_vinfo.xres); + Backend::setHeight(fb_vinfo.yres); } FBDevBackend::~FBDevBackend() @@ -63,9 +71,6 @@ cairo_surface_t* FBDevBackend::createSurface() this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, "Error reading variable framebuffer information"); - this->width = fb_vinfo.xres; - this->height = fb_vinfo.yres; - // switch through bpp and decide on which format for the cairo surface to use cairo_format_t format; switch(fb_vinfo.bits_per_pixel) From c29ef89113130e100f203dbd48e4850cb24df5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 20 Nov 2018 05:52:58 +0100 Subject: [PATCH 083/183] [FBDevBackend] Set `format` in constructor --- src/backend/FBDevBackend.cc | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 723a0ebb3..1c6b19a2c 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -15,6 +15,20 @@ using namespace v8; +// switch through bpp and decide on which format for the cairo surface to use +cairo_format_t bits2format(__u32 bits_per_pixel) +{ + switch(bits_per_pixel) + { + case 16: return CAIRO_FORMAT_RGB16_565; + case 32: return CAIRO_FORMAT_ARGB32; + + default: + throw FBDevBackendException("Only valid formats are RGB16_565 & ARGB32"); + } +} + + FBDevBackend::FBDevBackend(string deviceName) : Backend("fbdev") { @@ -45,6 +59,7 @@ FBDevBackend::FBDevBackend(string deviceName) Backend::setWidth(fb_vinfo.xres); Backend::setHeight(fb_vinfo.yres); + Backend::setFormat(bits2format(fb_vinfo.bits_per_pixel)); } FBDevBackend::~FBDevBackend() @@ -71,20 +86,10 @@ cairo_surface_t* FBDevBackend::createSurface() this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, "Error reading variable framebuffer information"); - // switch through bpp and decide on which format for the cairo surface to use - cairo_format_t format; - switch(fb_vinfo.bits_per_pixel) - { - case 16: format = CAIRO_FORMAT_RGB16_565; break; - case 32: format = CAIRO_FORMAT_ARGB32; break; - - default: - throw FBDevBackendException("Only valid formats are RGB16_565 & ARGB32"); - } - // create cairo surface from data - this->surface = cairo_image_surface_create_for_data(this->fb_data, format, - this->width, this->height, fb_finfo.line_length); + this->surface = cairo_image_surface_create_for_data(this->fb_data, + bits2format(fb_vinfo.bits_per_pixel), fb_vinfo.xres, fb_vinfo.yres, + fb_finfo.line_length); return this->surface; } From 851ffb208602e2596e1fd7e0b828c639a645e0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 20 Nov 2018 05:54:18 +0100 Subject: [PATCH 084/183] [FBDevBackend][fix] Wrongly copy&pasted variable --- src/backend/FBDevBackend.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 1c6b19a2c..601696464 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -121,7 +121,7 @@ void FBDevBackend::setHeight(int height) this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, "Error setting variable framebuffer information"); - Backend::setHeight(width); + Backend::setHeight(height); } void FBDevBackend::setFormat(cairo_format_t format) { From ad2ddc011398fdfd7f8faa15a1c441f4a256961c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Wed, 28 Nov 2018 20:26:59 +0100 Subject: [PATCH 085/183] [FbDev] Set default FbDev device as constant --- examples/simple_fbdev.js | 2 +- src/backend/FBDevBackend.cc | 2 +- src/backend/FBDevBackend.h | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/simple_fbdev.js b/examples/simple_fbdev.js index a1f28df5c..6c8832495 100644 --- a/examples/simple_fbdev.js +++ b/examples/simple_fbdev.js @@ -11,7 +11,7 @@ const { backends: { FBDevBackend }, Canvas } = require('..') const squareSize = 100 -var device = process.argv[2] || '/dev/fb0' +var device = process.argv[2] var backend = new FBDevBackend(device) var canvas = new Canvas(backend) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 601696464..7042572c2 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -161,7 +161,7 @@ void FBDevBackend::Initialize(Handle target) NAN_METHOD(FBDevBackend::New) { - string fbDevice = "/dev/fb0"; + string fbDevice = DEFAULT_DEVICE; if(info[0]->IsString()) fbDevice = *String::Utf8Value(info[0].As()); FBDevBackend* backend = new FBDevBackend(fbDevice); diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 51d51400b..17b6a686f 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -6,7 +6,12 @@ #include #include "Backend.h" using namespace std; - class FBDevBackend : public Backend + + +const string DEFAULT_DEVICE = "/dev/fb0"; + + +class FBDevBackend : public Backend { private: int fb_fd; From 3e4f681a74b14391e1578107735b163f38ce3c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Wed, 28 Nov 2018 20:33:22 +0100 Subject: [PATCH 086/183] [FbDev] Move initialization of framebuffer device to `initFbDev()` method --- src/backend/FBDevBackend.cc | 36 +++++++++++++++++++++--------------- src/backend/FBDevBackend.h | 11 +++++++---- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 7042572c2..e82e32a51 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -31,6 +31,26 @@ cairo_format_t bits2format(__u32 bits_per_pixel) FBDevBackend::FBDevBackend(string deviceName) : Backend("fbdev") +{ + struct fb_var_screeninfo fb_vinfo; + + this->initFbDev(deviceName, &fb_vinfo); + + Backend::setWidth(fb_vinfo.xres); + Backend::setHeight(fb_vinfo.yres); + Backend::setFormat(bits2format(fb_vinfo.bits_per_pixel)); +} + +FBDevBackend::~FBDevBackend() +{ + this->destroySurface(); + + munmap(this->fb_data, this->fb_finfo.smem_len); + close(this->fb_fd); +} + + +void FBDevBackend::initFbDev(string deviceName, struct fb_var_screeninfo* fb_vinfo) { // Open the file for reading and writing this->fb_fd = open(deviceName.c_str(), O_RDWR); @@ -52,22 +72,8 @@ FBDevBackend::FBDevBackend(string deviceName) if(this->fb_data == MAP_FAILED) throw FBDevBackendException("Failed to map framebuffer device to memory"); - struct fb_var_screeninfo fb_vinfo; - - this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, fb_vinfo, "Error reading variable framebuffer information"); - - Backend::setWidth(fb_vinfo.xres); - Backend::setHeight(fb_vinfo.yres); - Backend::setFormat(bits2format(fb_vinfo.bits_per_pixel)); -} - -FBDevBackend::~FBDevBackend() -{ - this->destroySurface(); - - munmap(this->fb_data, this->fb_finfo.smem_len); - close(this->fb_fd); } diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 17b6a686f..962d703d0 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -17,10 +17,13 @@ class FBDevBackend : public Backend int fb_fd; struct fb_fix_screeninfo fb_finfo; unsigned char* fb_data; - ~FBDevBackend(); - void FbDevIoctlHelper(unsigned long request, void* data, string errmsg); - cairo_surface_t* createSurface(); - void setWidth(int width); + + ~FBDevBackend(); + + void initFbDev(string deviceName, struct fb_var_screeninfo* fb_vinfo); + void FbDevIoctlHelper(unsigned long request, void* data, string errmsg); + cairo_surface_t* createSurface(); + void setWidth(int width); void setHeight(int height); void setFormat(cairo_format_t format); public: From cf99d46d7817a92660dce9a2efa71354dfe79c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Wed, 28 Nov 2018 20:38:37 +0100 Subject: [PATCH 087/183] [FbDev] Allow to define framebuffer device from `Canvas` constructor --- src/Canvas.cc | 8 +++++++- src/backend/FBDevBackend.cc | 10 ++++++++++ src/backend/FBDevBackend.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index 549705ad9..58727c5a2 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -94,7 +94,13 @@ NAN_METHOD(Canvas::New) { if (info[1]->IsNumber()) height = Nan::To(info[1]).FromMaybe(0); if (info[2]->IsString()) { - if (0 == strcmp("pdf", *Nan::Utf8String(info[2]))) + if (0 == strcmp("fbdev", *Nan::Utf8String(info[2]))) { + if (info[3]->IsString()) + backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3])); + else + backend = new FBDevBackend(width, height); + } + else if (0 == strcmp("pdf", *Nan::Utf8String(info[2]))) backend = new PdfBackend(width, height); else if (0 == strcmp("svg", *Nan::Utf8String(info[2]))) backend = new SvgBackend(width, height); diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index e82e32a51..65bda45a0 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -29,6 +29,16 @@ cairo_format_t bits2format(__u32 bits_per_pixel) } +FBDevBackend::FBDevBackend(int width, int height, string deviceName) + : Backend("fbdev", width, height) +{ + struct fb_var_screeninfo fb_vinfo; + + this->initFbDev(deviceName, &fb_vinfo); + + Backend::setFormat(bits2format(fb_vinfo.bits_per_pixel)); +} + FBDevBackend::FBDevBackend(string deviceName) : Backend("fbdev") { diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 962d703d0..3ed436333 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -27,6 +27,7 @@ class FBDevBackend : public Backend void setHeight(int height); void setFormat(cairo_format_t format); public: + FBDevBackend(int width, int height, string deviceName = DEFAULT_DEVICE); FBDevBackend(string deviceName); static Nan::Persistent constructor; static void Initialize(v8::Handle target); From 5cc863151b64b12ebfcda667ee6838dc1b1cf226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Wed, 28 Nov 2018 21:02:39 +0100 Subject: [PATCH 088/183] [FbDev] Don't regenerate surface on creation for non-standard color modes --- src/backend/Backend.h | 2 +- src/backend/FBDevBackend.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/Backend.h b/src/backend/Backend.h index ddb74c985..12debc196 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -21,11 +21,11 @@ class Backend : public Nan::ObjectWrap private: const string name; const char* error = NULL; - cairo_format_t format; protected: int width; int height; + cairo_format_t format; cairo_surface_t* surface; Canvas* canvas; diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 65bda45a0..44dc285ce 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -36,7 +36,6 @@ FBDevBackend::FBDevBackend(int width, int height, string deviceName) this->initFbDev(deviceName, &fb_vinfo); - Backend::setFormat(bits2format(fb_vinfo.bits_per_pixel)); } FBDevBackend::FBDevBackend(string deviceName) @@ -48,7 +47,6 @@ FBDevBackend::FBDevBackend(string deviceName) Backend::setWidth(fb_vinfo.xres); Backend::setHeight(fb_vinfo.yres); - Backend::setFormat(bits2format(fb_vinfo.bits_per_pixel)); } FBDevBackend::~FBDevBackend() @@ -84,6 +82,8 @@ void FBDevBackend::initFbDev(string deviceName, struct fb_var_screeninfo* fb_vin this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, fb_vinfo, "Error reading variable framebuffer information"); + + this->format = bits2format(fb_vinfo->bits_per_pixel); } From 9a583f369ea8d47f71964af40d53600c7af8edb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Wed, 28 Nov 2018 21:03:43 +0100 Subject: [PATCH 089/183] [FbDev] Don't regenerate surface on creation to define the width and height --- src/backend/FBDevBackend.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 44dc285ce..9a1e725b9 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -45,8 +45,8 @@ FBDevBackend::FBDevBackend(string deviceName) this->initFbDev(deviceName, &fb_vinfo); - Backend::setWidth(fb_vinfo.xres); - Backend::setHeight(fb_vinfo.yres); + this->width = fb_vinfo.xres; + this->height = fb_vinfo.yres; } FBDevBackend::~FBDevBackend() From 58382524c9be869588aab9fa1770d4c2ac09e043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Wed, 28 Nov 2018 21:04:32 +0100 Subject: [PATCH 090/183] [FbDev][fix] Set framebuffer dimensions if specified --- src/backend/FBDevBackend.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 9a1e725b9..450c2bd56 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -36,6 +36,11 @@ FBDevBackend::FBDevBackend(int width, int height, string deviceName) this->initFbDev(deviceName, &fb_vinfo); + fb_vinfo.xres = width; + fb_vinfo.yres = height; + + this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, + "Error setting variable framebuffer information"); } FBDevBackend::FBDevBackend(string deviceName) From 497f03d6764a9d47d82c5a6824a735d93042c116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 30 Nov 2018 13:59:16 +0100 Subject: [PATCH 091/183] [Backends] Call to virtual `onPaint()` method after all painting operations Painting operations are `fill()`, `stroke()`, `addPage()`, `putImageData()` and `drawImage()`. --- src/CanvasRenderingContext2d.cc | 16 +++++++++++++++- src/backend/Backend.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index a4e32522a..77866f7fb 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -426,6 +426,9 @@ Context2d::fill(bool preserve) { ? shadow(cairo_fill) : cairo_fill(_context); } + + // Notify backend that the Cairo surface has got a painting operation + canvas()->backend()->onPaint(); } /* @@ -480,6 +483,9 @@ Context2d::stroke(bool preserve) { ? shadow(cairo_stroke) : cairo_stroke(_context); } + + // Notify backend that the Cairo surface has got a painting operation + canvas()->backend()->onPaint(); } /* @@ -756,7 +762,9 @@ NAN_METHOD(Context2d::AddPage) { return Nan::ThrowError("only PDF canvases support .nextPage()"); } cairo_show_page(context->context()); - return; + + // Notify backend that the Cairo surface has got a painting operation + context->canvas()->backend()->onPaint(); } /* @@ -946,6 +954,9 @@ NAN_METHOD(Context2d::PutImageData) { , dy , cols , rows); + + // Notify backend that the Cairo surface has got a painting operation + context->canvas()->backend()->onPaint(); } /* @@ -1343,6 +1354,9 @@ NAN_METHOD(Context2d::DrawImage) { cairo_destroy(ctxTemp); cairo_surface_destroy(surfTemp); } + + // Notify backend that the Cairo surface has got a painting operation + context->canvas()->backend()->onPaint(); } /* diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 75ae37aad..1fc2545f4 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -58,6 +58,8 @@ class Backend : public Nan::ObjectWrap bool isSurfaceValid(); inline const char* getError(){ return error; } + + virtual void onPaint(){}; }; From 7601bf9fd68526faab1e721c3bcec0c90d98a4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 30 Nov 2018 14:49:32 +0100 Subject: [PATCH 092/183] [FbDev] Basic implementation of `onPaint()` method --- src/backend/FBDevBackend.cc | 6 ++++++ src/backend/FBDevBackend.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 450c2bd56..81e5cc9ef 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -167,6 +167,12 @@ void FBDevBackend::setFormat(cairo_format_t format) } +void FBDevBackend::onPaint() +{ + std::cout << "onPaint" << std::endl; +} + + Nan::Persistent FBDevBackend::constructor; void FBDevBackend::Initialize(Handle target) diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 3ed436333..2b3f73779 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -26,6 +26,9 @@ class FBDevBackend : public Backend void setWidth(int width); void setHeight(int height); void setFormat(cairo_format_t format); + + void onPaint(); + public: FBDevBackend(int width, int height, string deviceName = DEFAULT_DEVICE); FBDevBackend(string deviceName); From 848ab2e09e5d72550d3ac2c6fa2109fbf4ffede0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 1 Dec 2018 11:32:51 +0100 Subject: [PATCH 093/183] [Backend] Use default arguments to remove duplicated constructor --- src/backend/Backend.cc | 8 -------- src/backend/Backend.h | 3 +-- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 1379a9339..a4991c69c 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -1,14 +1,6 @@ #include "Backend.h" -Backend::Backend(string name) - : name(name) - , format(CAIRO_FORMAT_INVALID) - , width(0) - , height(0) - , surface(NULL) - , canvas(NULL) -{} Backend::Backend(string name, int width, int height) : name(name) , format(CAIRO_FORMAT_INVALID) diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 12debc196..c53b9daae 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -29,8 +29,7 @@ class Backend : public Nan::ObjectWrap cairo_surface_t* surface; Canvas* canvas; - Backend(string name); - Backend(string name, int width, int height); + Backend(string name, int width = 0, int height = 0); static void init(const Nan::FunctionCallbackInfo &info); static Backend *construct(int width, int height){ return nullptr; } From a4c906564fb6a68684c80b709225ddc2fa2f1152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 30 Nov 2018 22:34:38 +0100 Subject: [PATCH 094/183] [Backend] Dispatch thread at `onPaint()` to wait for VSync and swap buffers --- src/backend/Backend.cc | 37 +++++++++++++++++++++++++++++++++++++ src/backend/Backend.h | 6 +++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 34ef541f5..b924f5975 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -1,12 +1,39 @@ +#include + #include "Backend.h" +using Nan::AsyncQueueWorker; +using Nan::AsyncWorker; +using Nan::Callback; + + +class WaitVSync: public AsyncWorker +{ + public: + WaitVSync(Callback* callback, Backend* backend) + : AsyncWorker(callback, "Backend:WaitVSync") + , backend(backend) + {} + + void Execute() + { + backend->waitVSync(); + backend->swapBuffers(); + } + + private: + Backend* backend; +}; + + Backend::Backend(string name, int width, int height) : name(name) , width(width) , height(height) , surface(NULL) , canvas(NULL) + , waitingVSync(true) {} Backend::~Backend() @@ -96,6 +123,16 @@ bool Backend::isSurfaceValid(){ return isValid; } +void Backend::onPaint() +{ + if(waitingVSync) return; + + waitingVSync = true; + + // Dispatch thread to wait for VSync + AsyncQueueWorker(new WaitVSync(NULL, this)); +} + BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend, string operation_name) diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 1fc2545f4..5d86e5f92 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -27,6 +27,7 @@ class Backend : public Nan::ObjectWrap int height; cairo_surface_t* surface; Canvas* canvas; + bool waitingVSync; Backend(string name, int width, int height); static void init(const Nan::FunctionCallbackInfo &info); @@ -59,7 +60,10 @@ class Backend : public Nan::ObjectWrap bool isSurfaceValid(); inline const char* getError(){ return error; } - virtual void onPaint(){}; + void onPaint(); + + virtual void waitVSync(){}; + virtual void swapBuffers(){}; }; From e3984e39d15cf44c6bb9bffc99e220a7ce407f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 1 Dec 2018 14:31:55 +0100 Subject: [PATCH 095/183] [Backend] Replaced usage of `AsyncWorker` class for `uv_thread_create()` --- src/backend/Backend.cc | 36 ++++++++++++------------------------ src/backend/Backend.h | 5 ++++- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index b924f5975..be187ca8e 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -3,28 +3,16 @@ #include "Backend.h" -using Nan::AsyncQueueWorker; -using Nan::AsyncWorker; -using Nan::Callback; +void WaitVSync(void* arg) +{ + Backend* backend = (Backend*)arg; + backend->waitVSync(); + backend->swapBuffers(); -class WaitVSync: public AsyncWorker -{ - public: - WaitVSync(Callback* callback, Backend* backend) - : AsyncWorker(callback, "Backend:WaitVSync") - , backend(backend) - {} - - void Execute() - { - backend->waitVSync(); - backend->swapBuffers(); - } - - private: - Backend* backend; -}; + // Listen new `onDraw()` requests + backend->listenOnDraw = true; +} Backend::Backend(string name, int width, int height) @@ -33,7 +21,7 @@ Backend::Backend(string name, int width, int height) , height(height) , surface(NULL) , canvas(NULL) - , waitingVSync(true) + , listenOnDraw(false) {} Backend::~Backend() @@ -125,12 +113,12 @@ bool Backend::isSurfaceValid(){ void Backend::onPaint() { - if(waitingVSync) return; + if(!listenOnDraw) return; - waitingVSync = true; + listenOnDraw = false; // Dispatch thread to wait for VSync - AsyncQueueWorker(new WaitVSync(NULL, this)); + uv_thread_create(&vSyncThread, WaitVSync, this); } diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 5d86e5f92..7e4a9582f 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -22,18 +22,21 @@ class Backend : public Nan::ObjectWrap const string name; const char* error = NULL; + uv_thread_t vSyncThread; + protected: int width; int height; cairo_surface_t* surface; Canvas* canvas; - bool waitingVSync; Backend(string name, int width, int height); static void init(const Nan::FunctionCallbackInfo &info); static Backend *construct(int width, int height){ return nullptr; } public: + bool listenOnDraw; + virtual ~Backend(); void setCanvas(Canvas* canvas); From 5f1866bf4e6ffa1d7deea7cea4f9d686295d5552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 1 Dec 2018 15:00:54 +0100 Subject: [PATCH 096/183] [FBDevBackend] Wait for framebuffer VSync --- src/backend/FBDevBackend.cc | 13 +++++++++++-- src/backend/FBDevBackend.h | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 81e5cc9ef..35d4d1a9e 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -32,6 +32,9 @@ cairo_format_t bits2format(__u32 bits_per_pixel) FBDevBackend::FBDevBackend(int width, int height, string deviceName) : Backend("fbdev", width, height) { + // Allow VSync requests by default + listenOnDraw = true; + struct fb_var_screeninfo fb_vinfo; this->initFbDev(deviceName, &fb_vinfo); @@ -46,6 +49,9 @@ FBDevBackend::FBDevBackend(int width, int height, string deviceName) FBDevBackend::FBDevBackend(string deviceName) : Backend("fbdev") { + // Allow VSync requests by default + listenOnDraw = true; + struct fb_var_screeninfo fb_vinfo; this->initFbDev(deviceName, &fb_vinfo); @@ -167,9 +173,12 @@ void FBDevBackend::setFormat(cairo_format_t format) } -void FBDevBackend::onPaint() +void FBDevBackend::waitVSync() { - std::cout << "onPaint" << std::endl; + int arg = 0; + + this->FbDevIoctlHelper(FBIO_WAITFORVSYNC, &arg, + "Error waiting for framebuffer VSync"); } diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 2b3f73779..7c6fe3e5e 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -27,7 +27,7 @@ class FBDevBackend : public Backend void setHeight(int height); void setFormat(cairo_format_t format); - void onPaint(); + void waitVSync(); public: FBDevBackend(int width, int height, string deviceName = DEFAULT_DEVICE); From 4b866cadf0bb8abb93b9a7c6f8a7d9ee69ff6508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 1 Dec 2018 19:33:43 +0100 Subject: [PATCH 097/183] [FBDevBackend] Enable double buffering --- src/backend/FBDevBackend.cc | 68 +++++++++++++++++++++++++++++++++---- src/backend/FBDevBackend.h | 5 +++ 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 35d4d1a9e..ae22e7f12 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -32,9 +32,6 @@ cairo_format_t bits2format(__u32 bits_per_pixel) FBDevBackend::FBDevBackend(int width, int height, string deviceName) : Backend("fbdev", width, height) { - // Allow VSync requests by default - listenOnDraw = true; - struct fb_var_screeninfo fb_vinfo; this->initFbDev(deviceName, &fb_vinfo); @@ -44,26 +41,29 @@ FBDevBackend::FBDevBackend(int width, int height, string deviceName) this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, "Error setting variable framebuffer information"); + + this->enableDoubleBuffer(height, &fb_vinfo); } FBDevBackend::FBDevBackend(string deviceName) : Backend("fbdev") { - // Allow VSync requests by default - listenOnDraw = true; - struct fb_var_screeninfo fb_vinfo; this->initFbDev(deviceName, &fb_vinfo); this->width = fb_vinfo.xres; this->height = fb_vinfo.yres; + + this->enableDoubleBuffer(height, &fb_vinfo); } FBDevBackend::~FBDevBackend() { this->destroySurface(); + if(useCopyBuffer) free(fb_data_surface); + munmap(this->fb_data, this->fb_finfo.smem_len); close(this->fb_fd); } @@ -97,6 +97,26 @@ void FBDevBackend::initFbDev(string deviceName, struct fb_var_screeninfo* fb_vin this->format = bits2format(fb_vinfo->bits_per_pixel); } +void FBDevBackend::enableDoubleBuffer(int height, struct fb_var_screeninfo* fb_vinfo) +{ + fb_vinfo->yres_virtual = height * 2; + + // Try to use real double buffer inside graphic card memory. If framebuffer + // driver don't support to have a virtual framebuffer bigger than the actual + // one, then we'll use a buffer in memory. It's not so efficient and could + // lead to some tearing, but with VSync this should be minimal and at least + // we'll not see screen redraws. + useCopyBuffer = ioctl(this->fb_fd, FBIOPUT_VSCREENINFO, fb_vinfo) == -1; + + fb_data_screen = this->fb_data; + fb_data_surface = useCopyBuffer + ? (unsigned char*)malloc(this->fb_finfo.smem_len) + : this->fb_data + fb_vinfo->yres * fb_finfo.line_length; + + // Allow VSync requests by default + listenOnDraw = true; +} + void FBDevBackend::FbDevIoctlHelper(unsigned long request, void* data, string errmsg) @@ -114,7 +134,7 @@ cairo_surface_t* FBDevBackend::createSurface() "Error reading variable framebuffer information"); // create cairo surface from data - this->surface = cairo_image_surface_create_for_data(this->fb_data, + this->surface = cairo_image_surface_create_for_data(this->fb_data_surface, bits2format(fb_vinfo.bits_per_pixel), fb_vinfo.xres, fb_vinfo.yres, fb_finfo.line_length); @@ -145,6 +165,8 @@ void FBDevBackend::setHeight(int height) fb_vinfo.yres = height; + if(useCopyBuffer) fb_vinfo.yres_virtual = height * 2; + this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, "Error setting variable framebuffer information"); @@ -181,6 +203,38 @@ void FBDevBackend::waitVSync() "Error waiting for framebuffer VSync"); } +void FBDevBackend::swapBuffers() +{ + if(useCopyBuffer) + memcpy(fb_data_screen, fb_data_surface, this->fb_finfo.smem_len); + + else + { + // Update display panning + struct fb_var_screeninfo fb_vinfo; + + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, + "Error reading variable framebuffer information"); + + fb_vinfo.yoffset = fb_vinfo.yoffset ? 0 : fb_vinfo.yres; + + this->FbDevIoctlHelper(FBIOPAN_DISPLAY, &fb_vinfo, + "Error panning the framebuffer display"); + + // Swap front and back buffers pointers + unsigned char* fb_data_aux = fb_data_screen; + fb_data_screen = fb_data_surface; + fb_data_surface = fb_data_aux; + + // HACK Update surface pointer + // TODO Find how to cast `surface` pointer to `cairo_image_surface_t*`, + // or better how to get direct access to the `pixman_image` object + //cairo_surface_flush(surface); + //((cairo_image_surface_t*)surface)->pixman_image->bits.bits = fb_data_surface; + //cairo_surface_mark_dirty(surface); + } +} + Nan::Persistent FBDevBackend::constructor; diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 7c6fe3e5e..678b87b6e 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -17,10 +17,14 @@ class FBDevBackend : public Backend int fb_fd; struct fb_fix_screeninfo fb_finfo; unsigned char* fb_data; + unsigned char* fb_data_screen; + unsigned char* fb_data_surface; + bool useCopyBuffer; ~FBDevBackend(); void initFbDev(string deviceName, struct fb_var_screeninfo* fb_vinfo); + void enableDoubleBuffer(int height, struct fb_var_screeninfo* fb_vinfo); void FbDevIoctlHelper(unsigned long request, void* data, string errmsg); cairo_surface_t* createSurface(); void setWidth(int width); @@ -28,6 +32,7 @@ class FBDevBackend : public Backend void setFormat(cairo_format_t format); void waitVSync(); + void swapBuffers(); public: FBDevBackend(int width, int height, string deviceName = DEFAULT_DEVICE); From 72b933c23b24d384a0dacebedefada0ca7595da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 2 Dec 2018 22:33:36 +0100 Subject: [PATCH 098/183] [FBDevBackend] Remove double buffer hack and instead destroy Cairo surface --- src/backend/FBDevBackend.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index ae22e7f12..044b3ca94 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -226,12 +226,8 @@ void FBDevBackend::swapBuffers() fb_data_screen = fb_data_surface; fb_data_surface = fb_data_aux; - // HACK Update surface pointer - // TODO Find how to cast `surface` pointer to `cairo_image_surface_t*`, - // or better how to get direct access to the `pixman_image` object - //cairo_surface_flush(surface); - //((cairo_image_surface_t*)surface)->pixman_image->bits.bits = fb_data_surface; - //cairo_surface_mark_dirty(surface); + // Destroy Cairo surface to force create new one in the new back buffer + destroySurface(); } } From 0236d7252f7538db9a2b95c24a6c8faa9fd61797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 3 Dec 2018 21:43:22 +0100 Subject: [PATCH 099/183] [Backends] Renamed `listenOnDraw` to `listenOnPaint` --- src/backend/Backend.cc | 8 ++++---- src/backend/Backend.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index be187ca8e..81b6b80e0 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -11,7 +11,7 @@ void WaitVSync(void* arg) backend->swapBuffers(); // Listen new `onDraw()` requests - backend->listenOnDraw = true; + backend->listenOnPaint = true; } @@ -21,7 +21,7 @@ Backend::Backend(string name, int width, int height) , height(height) , surface(NULL) , canvas(NULL) - , listenOnDraw(false) + , listenOnPaint(false) {} Backend::~Backend() @@ -113,9 +113,9 @@ bool Backend::isSurfaceValid(){ void Backend::onPaint() { - if(!listenOnDraw) return; + if(!listenOnPaint) return; - listenOnDraw = false; + listenOnPaint = false; // Dispatch thread to wait for VSync uv_thread_create(&vSyncThread, WaitVSync, this); diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 7e4a9582f..8a7500d6a 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -35,7 +35,7 @@ class Backend : public Nan::ObjectWrap static Backend *construct(int width, int height){ return nullptr; } public: - bool listenOnDraw; + bool listenOnPaint; virtual ~Backend(); From 1dad8d4f82a1dc5840eb37f0536e73044ff291be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 3 Dec 2018 21:48:10 +0100 Subject: [PATCH 100/183] [Backend] Splitted `dispatchWaitVSync()` from `onPaint()` --- src/backend/Backend.cc | 22 +++++++++++++++++++--- src/backend/Backend.h | 2 ++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 81b6b80e0..e289f87ab 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -8,10 +8,17 @@ void WaitVSync(void* arg) Backend* backend = (Backend*)arg; backend->waitVSync(); - backend->swapBuffers(); - // Listen new `onDraw()` requests - backend->listenOnPaint = true; + // Swap buffers if it was requested + if(!backend->listenOnPaint) + { + backend->swapBuffers(); + + backend->listenOnPaint = true; + } + + // Listen new `VSync` requests + backend->waitingVSync = false; } @@ -117,6 +124,15 @@ void Backend::onPaint() listenOnPaint = false; + dispatchWaitVSync(); +} + +void Backend::dispatchWaitVSync() +{ + if(waitingVSync) return; + + waitingVSync = true; + // Dispatch thread to wait for VSync uv_thread_create(&vSyncThread, WaitVSync, this); } diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 8a7500d6a..2a0274efc 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -23,6 +23,7 @@ class Backend : public Nan::ObjectWrap const char* error = NULL; uv_thread_t vSyncThread; + void dispatchWaitVSync(); protected: int width; @@ -36,6 +37,7 @@ class Backend : public Nan::ObjectWrap public: bool listenOnPaint; + bool waitingVSync; virtual ~Backend(); From 225c5b75d176696ad9ec12b4af760966b141fba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 3 Dec 2018 21:49:57 +0100 Subject: [PATCH 101/183] [Backend] Added support `requestAnimationFrame()` --- src/backend/Backend.cc | 69 ++++++++++++++++++++++++++++++++++++++++++ src/backend/Backend.h | 14 +++++++++ 2 files changed, 83 insertions(+) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index e289f87ab..fcdfbeccd 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -1,8 +1,15 @@ +#include #include #include "Backend.h" +using Nan::New; +using v8::Local; +using v8::Number; +using v8::Value; + + void WaitVSync(void* arg) { Backend* backend = (Backend*)arg; @@ -17,6 +24,9 @@ void WaitVSync(void* arg) backend->listenOnPaint = true; } + // Execute `requestAnimationFrame()` callbacks (if any) + backend->executeCallbacks(); + // Listen new `VSync` requests backend->waitingVSync = false; } @@ -24,11 +34,13 @@ void WaitVSync(void* arg) Backend::Backend(string name, int width, int height) : name(name) + , requestID(0) , width(width) , height(height) , surface(NULL) , canvas(NULL) , listenOnPaint(false) + , raf_callbacks(NULL) {} Backend::~Backend() @@ -137,6 +149,63 @@ void Backend::dispatchWaitVSync() uv_thread_create(&vSyncThread, WaitVSync, this); } +void Backend::executeCallbacks() +{ + if(!raf_callbacks) return; + + map_callbacks* callbacks = raf_callbacks; + raf_callbacks = NULL; + + if(callbacks->size()) + { + struct timeval tp; + gettimeofday(&tp, NULL); + double timestamp = tp.tv_sec * 1000 + tp.tv_usec / 1000; // milliseconds + + Local argv[] = {New(timestamp)}; + + for(auto it = callbacks->cbegin(); it != callbacks->cend(); ++it) + { + Callback* callback = (*it).second; + + callback->Call(1, argv); + delete callback; + } + + callbacks->clear(); + } + + delete callbacks; +} + + +// +// Animation Frame Provider API +// +// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#animationframeprovider +// + +NAN_METHOD(Backend::requestAnimationFrame) +{ + requestID++; + + if(!raf_callbacks) raf_callbacks = new map_callbacks; + + raf_callbacks->insert(std::pair(requestID, + new Callback(Nan::To(info[0]).ToLocalChecked()))); + + dispatchWaitVSync(); + + info.GetReturnValue().Set(Nan::New(requestID)); +} + +NAN_METHOD(Backend::cancelAnimationFrame) +{ + if(!raf_callbacks) return; + + raf_callbacks->erase(Nan::To(info[0]).FromJust()); +} + BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend, string operation_name) diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 2a0274efc..53642d450 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -2,6 +2,7 @@ #define __BACKEND_H__ #include +#include #include #include #include @@ -16,6 +17,12 @@ class Canvas; using namespace std; +using Nan::Callback; + + +typedef map map_callbacks; + + class Backend : public Nan::ObjectWrap { private: @@ -23,6 +30,8 @@ class Backend : public Nan::ObjectWrap const char* error = NULL; uv_thread_t vSyncThread; + long requestID; + void dispatchWaitVSync(); protected: @@ -38,6 +47,7 @@ class Backend : public Nan::ObjectWrap public: bool listenOnPaint; bool waitingVSync; + map_callbacks* raf_callbacks; virtual ~Backend(); @@ -69,6 +79,10 @@ class Backend : public Nan::ObjectWrap virtual void waitVSync(){}; virtual void swapBuffers(){}; + void executeCallbacks(); + + NAN_METHOD(requestAnimationFrame); + NAN_METHOD(cancelAnimationFrame); }; From ffaac6b176fa5170a931b4a9f3b09041926f7a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Thu, 6 Dec 2018 19:12:43 +0100 Subject: [PATCH 102/183] [Backend] Add async method `waitVSync()` --- src/backend/Backend.cc | 38 ++++++++++++++++++++++++++++++++++++++ src/backend/Backend.h | 9 +++++++++ 2 files changed, 47 insertions(+) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 34ef541f5..319207179 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -1,6 +1,29 @@ #include "Backend.h" +using Nan::AsyncQueueWorker; +using Nan::AsyncWorker; +using Nan::Callback; + + +class WaitVSync: public AsyncWorker +{ + public: + WaitVSync(Callback* callback, Backend* backend) + : AsyncWorker(callback, "Backend:WaitVSync") + , backend(backend) + {} + + void Execute() + { + backend->waitVSync(); + } + + private: + Backend* backend; +}; + + Backend::Backend(string name, int width, int height) : name(name) , width(width) @@ -97,6 +120,21 @@ bool Backend::isSurfaceValid(){ } +NAN_METHOD(Backend::waitVSync) +{ + Backend* backend = Nan::ObjectWrap::Unwrap(info.This()); + + Callback* callback = new Callback(info[0].As()); + + AsyncQueueWorker(new WaitVSync(callback, backend)); +} + +void Backend::Initialize(Local ctor) +{ + Nan::SetPrototypeMethod(ctor, "waitVSync", waitVSync); +} + + BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend, string operation_name) : backend(backend) diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 75ae37aad..034318d35 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -15,13 +15,19 @@ class Canvas; using namespace std; +using namespace v8; + class Backend : public Nan::ObjectWrap { + friend class WaitVSync; + private: const string name; const char* error = NULL; + virtual void waitVSync(){}; + protected: int width; int height; @@ -31,6 +37,7 @@ class Backend : public Nan::ObjectWrap Backend(string name, int width, int height); static void init(const Nan::FunctionCallbackInfo &info); static Backend *construct(int width, int height){ return nullptr; } + static void Initialize(Local ctor); public: virtual ~Backend(); @@ -58,6 +65,8 @@ class Backend : public Nan::ObjectWrap bool isSurfaceValid(); inline const char* getError(){ return error; } + + static NAN_METHOD(waitVSync); }; From c2e07fee8be640396265c36dc1a3a159393a3f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Thu, 6 Dec 2018 22:16:12 +0100 Subject: [PATCH 103/183] [FbDevBackend] Add support for framebuffer native VSync --- src/backend/FBDevBackend.cc | 12 ++++++++++++ src/backend/FBDevBackend.h | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 450c2bd56..622ecd7a8 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -167,6 +167,15 @@ void FBDevBackend::setFormat(cairo_format_t format) } +void FBDevBackend::waitVSync() +{ + int arg = 0; + + this->FbDevIoctlHelper(FBIO_WAITFORVSYNC, &arg, + "Error waiting for framebuffer VSync"); +} + + Nan::Persistent FBDevBackend::constructor; void FBDevBackend::Initialize(Handle target) @@ -177,6 +186,9 @@ void FBDevBackend::Initialize(Handle target) FBDevBackend::constructor.Reset(ctor); ctor->InstanceTemplate()->SetInternalFieldCount(1); ctor->SetClassName(Nan::New("FBDevBackend").ToLocalChecked()); + + Backend::Initialize(ctor); + target->Set(Nan::New("FBDevBackend").ToLocalChecked(), ctor->GetFunction()); } diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 3ed436333..40d3d8ef3 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -26,7 +26,10 @@ class FBDevBackend : public Backend void setWidth(int width); void setHeight(int height); void setFormat(cairo_format_t format); - public: + + void waitVSync(); + + public: FBDevBackend(int width, int height, string deviceName = DEFAULT_DEVICE); FBDevBackend(string deviceName); static Nan::Persistent constructor; From b394d31f6743538d5ba5c58cc90d24aee0571fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Thu, 6 Dec 2018 22:26:47 +0100 Subject: [PATCH 104/183] [Backend] `swapBuffers()` method --- src/backend/Backend.cc | 13 +++++++++++++ src/backend/Backend.h | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 34ef541f5..639015c82 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -97,6 +97,19 @@ bool Backend::isSurfaceValid(){ } +NAN_METHOD(Backend::swapBuffers) +{ + Backend* backend = Nan::ObjectWrap::Unwrap(info.This()); + + backend->swapBuffers(); +} + +void Backend::Initialize(Local ctor) +{ + Nan::SetPrototypeMethod(ctor, "swapBuffers", swapBuffers); +} + + BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend, string operation_name) : backend(backend) diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 75ae37aad..4f193b229 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -15,6 +15,7 @@ class Canvas; using namespace std; +using namespace v8; class Backend : public Nan::ObjectWrap { @@ -22,6 +23,8 @@ class Backend : public Nan::ObjectWrap const string name; const char* error = NULL; + virtual void swapBuffers(){}; + protected: int width; int height; @@ -31,6 +34,7 @@ class Backend : public Nan::ObjectWrap Backend(string name, int width, int height); static void init(const Nan::FunctionCallbackInfo &info); static Backend *construct(int width, int height){ return nullptr; } + static void Initialize(Local ctor); public: virtual ~Backend(); @@ -58,6 +62,8 @@ class Backend : public Nan::ObjectWrap bool isSurfaceValid(); inline const char* getError(){ return error; } + + static NAN_METHOD(swapBuffers); }; From 3618b40279c9b205a6dd735cd4f7037dad2bf513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 7 Dec 2018 13:21:16 +0100 Subject: [PATCH 105/183] [FbDevBackend] Support for optional double buffering (disabled by default) --- src/backend/FBDevBackend.cc | 87 +++++++++++++++++++++++++++++++++++-- src/backend/FBDevBackend.h | 17 +++++++- 2 files changed, 99 insertions(+), 5 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 622ecd7a8..e4419d990 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -29,8 +29,11 @@ cairo_format_t bits2format(__u32 bits_per_pixel) } -FBDevBackend::FBDevBackend(int width, int height, string deviceName) +FBDevBackend::FBDevBackend(int width, int height, string deviceName, + bool useDoubleBuffer, bool forceUseCopyBuffer) : Backend("fbdev", width, height) + , useDoubleBuffer(useDoubleBuffer) + , useCopyBackBuffer(false) { struct fb_var_screeninfo fb_vinfo; @@ -41,10 +44,15 @@ FBDevBackend::FBDevBackend(int width, int height, string deviceName) this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, "Error setting variable framebuffer information"); + + this->enableDoubleBuffer(&fb_vinfo, forceUseCopyBuffer); } -FBDevBackend::FBDevBackend(string deviceName) +FBDevBackend::FBDevBackend(string deviceName, bool useDoubleBuffer, + bool forceUseCopyBuffer) : Backend("fbdev") + , useDoubleBuffer(useDoubleBuffer) + , useCopyBackBuffer(false) { struct fb_var_screeninfo fb_vinfo; @@ -52,12 +60,16 @@ FBDevBackend::FBDevBackend(string deviceName) this->width = fb_vinfo.xres; this->height = fb_vinfo.yres; + + this->enableDoubleBuffer(&fb_vinfo, forceUseCopyBuffer); } FBDevBackend::~FBDevBackend() { this->destroySurface(); + if(useCopyBackBuffer) free(back_buffer); + munmap(this->fb_data, this->fb_finfo.smem_len); close(this->fb_fd); } @@ -91,6 +103,36 @@ void FBDevBackend::initFbDev(string deviceName, struct fb_var_screeninfo* fb_vin this->format = bits2format(fb_vinfo->bits_per_pixel); } +void FBDevBackend::enableDoubleBuffer(struct fb_var_screeninfo* fb_vinfo, + bool forceUseCopyBuffer) +{ + front_buffer = this->fb_data; + + if(!useDoubleBuffer) + back_buffer = this->fb_data; + + else + { + if(forceUseCopyBuffer) + useCopyBackBuffer = true; + + else + { + fb_vinfo->yres_virtual = height * 2; + + // Try to use real double buffer inside graphic card memory. If FbDev + // driver don't support to have a virtual framebuffer bigger than the + // actual one, then we'll use a buffer in memory. It's not so efficient + // and could lead to some tearing, but with VSync this should be minimal + // and at least we'll not see screen redraws. + useCopyBackBuffer = ioctl(this->fb_fd, FBIOPUT_VSCREENINFO, fb_vinfo) == -1; + } + + back_buffer = useCopyBackBuffer + ? (unsigned char*)malloc(this->fb_finfo.smem_len) + : this->fb_data + fb_vinfo->yres * fb_finfo.line_length; + } +} void FBDevBackend::FbDevIoctlHelper(unsigned long request, void* data, string errmsg) @@ -108,7 +150,7 @@ cairo_surface_t* FBDevBackend::createSurface() "Error reading variable framebuffer information"); // create cairo surface from data - this->surface = cairo_image_surface_create_for_data(this->fb_data, + this->surface = cairo_image_surface_create_for_data(this->back_buffer, bits2format(fb_vinfo.bits_per_pixel), fb_vinfo.xres, fb_vinfo.yres, fb_finfo.line_length); @@ -139,6 +181,8 @@ void FBDevBackend::setHeight(int height) fb_vinfo.yres = height; + if(useCopyBackBuffer) fb_vinfo.yres_virtual = height * 2; + this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, "Error setting variable framebuffer information"); @@ -167,6 +211,43 @@ void FBDevBackend::setFormat(cairo_format_t format) } +void FBDevBackend::copyBackBuffer() +{ + memcpy(front_buffer, back_buffer, this->fb_finfo.smem_len); +} +void FBDevBackend::flipBuffers() +{ + // Update display panning + struct fb_var_screeninfo fb_vinfo; + + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, + "Error reading variable framebuffer information"); + + fb_vinfo.yoffset = fb_vinfo.yoffset ? 0 : fb_vinfo.yres; + + this->FbDevIoctlHelper(FBIOPAN_DISPLAY, &fb_vinfo, + "Error panning the framebuffer display"); + + // Swap front and back buffers pointers + unsigned char* aux = front_buffer; + front_buffer = back_buffer; + back_buffer = aux; + + // Destroy Cairo surface to force to create a new one in the new back buffer + destroySurface(); +} + +void FBDevBackend::swapBuffers() +{ + if(!useDoubleBuffer) return; + + if(useCopyBackBuffer) + copyBackBuffer(); + + else + flipBuffers(); +} + void FBDevBackend::waitVSync() { int arg = 0; diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 40d3d8ef3..9100f8892 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -17,21 +17,34 @@ class FBDevBackend : public Backend int fb_fd; struct fb_fix_screeninfo fb_finfo; unsigned char* fb_data; + unsigned char* front_buffer; + unsigned char* back_buffer; + bool useDoubleBuffer; + bool useCopyBackBuffer; ~FBDevBackend(); void initFbDev(string deviceName, struct fb_var_screeninfo* fb_vinfo); + void enableDoubleBuffer(struct fb_var_screeninfo* fb_vinfo, + bool forceUseCopyBuffer); void FbDevIoctlHelper(unsigned long request, void* data, string errmsg); + cairo_surface_t* createSurface(); + void setWidth(int width); void setHeight(int height); void setFormat(cairo_format_t format); + void copyBackBuffer(); + void flipBuffers(); + void swapBuffers(); void waitVSync(); public: - FBDevBackend(int width, int height, string deviceName = DEFAULT_DEVICE); - FBDevBackend(string deviceName); + FBDevBackend(int width, int height, string deviceName = DEFAULT_DEVICE, + bool useDoubleBuffer = false, bool forceUseCopyBuffer = false); + FBDevBackend(string deviceName, bool useDoubleBuffer = false, + bool forceUseCopyBuffer = false); static Nan::Persistent constructor; static void Initialize(v8::Handle target); static NAN_METHOD(New); From 995a3f324c9a9c7831de2736086204a775dc467b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 7 Dec 2018 13:22:07 +0100 Subject: [PATCH 106/183] [FbDevBackend] Allow to enable double buffering from Javascript --- src/Canvas.cc | 14 ++++++++++++-- src/backend/FBDevBackend.cc | 9 ++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index 58727c5a2..bc22461e0 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -95,8 +95,18 @@ NAN_METHOD(Canvas::New) { if (info[2]->IsString()) { if (0 == strcmp("fbdev", *Nan::Utf8String(info[2]))) { - if (info[3]->IsString()) - backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3])); + if (info[3]->IsString()) { + if(info[4]->IsBoolean()) { + if(info[5]->IsBoolean()) + backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), + info[4]->BooleanValue(), info[5]->BooleanValue()); + else + backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), + info[4]->BooleanValue()); + } + else + backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3])); + } else backend = new FBDevBackend(width, height); } diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index e4419d990..336ddde83 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -278,7 +278,14 @@ NAN_METHOD(FBDevBackend::New) string fbDevice = DEFAULT_DEVICE; if(info[0]->IsString()) fbDevice = *String::Utf8Value(info[0].As()); - FBDevBackend* backend = new FBDevBackend(fbDevice); + bool useDoubleBuffer = false; + if(info[1]->IsBoolean()) useDoubleBuffer = info[1]->BooleanValue(); + + bool forceUseCopyBuffer = false; + if(info[2]->IsBoolean()) forceUseCopyBuffer = info[2]->BooleanValue(); + + FBDevBackend* backend = new FBDevBackend(fbDevice, useDoubleBuffer, + forceUseCopyBuffer); backend->Wrap(info.This()); info.GetReturnValue().Set(info.This()); From 0e8be2246aa27db45e2e41b60ef9f6210db61152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 7 Dec 2018 20:35:03 +0100 Subject: [PATCH 107/183] clean-up --- src/backend/FBDevBackend.h | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 3ed436333..73abcb919 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -1,11 +1,16 @@ #ifndef __FBDEV_BACKEND_H__ #define __FBDEV_BACKEND_H__ - #include + +#include #include - #include - #include - #include "Backend.h" - using namespace std; + +#include +#include + +#include "Backend.h" + + +using namespace std; const string DEFAULT_DEVICE = "/dev/fb0"; @@ -29,17 +34,23 @@ class FBDevBackend : public Backend public: FBDevBackend(int width, int height, string deviceName = DEFAULT_DEVICE); FBDevBackend(string deviceName); - static Nan::Persistent constructor; + + static Nan::Persistent constructor; static void Initialize(v8::Handle target); static NAN_METHOD(New); }; - class FBDevBackendException : public std::exception + + +class FBDevBackendException : public std::exception { private: string err_msg; - public: + + public: FBDevBackendException(const string msg) : err_msg(msg) {}; ~FBDevBackendException() throw() {}; - const char *what() const throw() { return this->err_msg.c_str(); }; + + const char *what() const throw() { return this->err_msg.c_str(); }; }; - #endif + +#endif From 81fa69f90b94770706ed4a7af406f995e78a2c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 7 Dec 2018 20:41:40 +0100 Subject: [PATCH 108/183] [FbDev] Show used pixel format in `simple_fbdev` example --- examples/simple_fbdev.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/simple_fbdev.js b/examples/simple_fbdev.js index 6c8832495..f8b440322 100644 --- a/examples/simple_fbdev.js +++ b/examples/simple_fbdev.js @@ -32,7 +32,8 @@ ctx.fillRect(0, offsetY, squareSize, squareSize) ctx.fillStyle = '#FFFFFF' ctx.fillRect(offsetX, offsetY, squareSize, squareSize) -console.log('Width: ' + canvas.width + ', Height: ' + canvas.height) +console.log('Width: ' + canvas.width + ', Height: ' + canvas.height + + 'Pixel format: ' + ctx.pixelFormat) var outPath = join(__dirname, 'rectangle.png') From b79795d638cc5de2d0f920a9c1cfb04a2f25bd31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 8 Dec 2018 19:29:04 +0100 Subject: [PATCH 109/183] [Backend] Made `destroySurface()` method virtual --- src/backend/Backend.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 0f5d8337a..f6a943db3 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -47,11 +47,10 @@ class Backend : public Nan::ObjectWrap void setCanvas(Canvas* canvas); virtual cairo_surface_t* createSurface() = 0; + virtual void destroySurface(); virtual cairo_surface_t* recreateSurface(); DLL_PUBLIC cairo_surface_t* getSurface(); - void destroySurface(); - DLL_PUBLIC string getName(); DLL_PUBLIC int getWidth(); From 0778ed89f9af63b17e9cbe88309002960ea6e746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 8 Dec 2018 19:32:17 +0100 Subject: [PATCH 110/183] [FbDevBackend] Made `copyBackBuffer()` copy only screen size memory --- src/backend/FBDevBackend.cc | 23 ++++++++++++----------- src/backend/FBDevBackend.h | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 336ddde83..357fc16e6 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -211,21 +211,17 @@ void FBDevBackend::setFormat(cairo_format_t format) } -void FBDevBackend::copyBackBuffer() +void FBDevBackend::copyBackBuffer(struct fb_var_screeninfo* fb_vinfo) { - memcpy(front_buffer, back_buffer, this->fb_finfo.smem_len); + memcpy(front_buffer, back_buffer, fb_vinfo->yres * fb_finfo.line_length); } -void FBDevBackend::flipBuffers() +void FBDevBackend::flipBuffers(struct fb_var_screeninfo* fb_vinfo) { // Update display panning - struct fb_var_screeninfo fb_vinfo; + fb_vinfo->yoffset = fb_vinfo->yoffset ? 0 : fb_vinfo->yres; - this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, - "Error reading variable framebuffer information"); - fb_vinfo.yoffset = fb_vinfo.yoffset ? 0 : fb_vinfo.yres; - - this->FbDevIoctlHelper(FBIOPAN_DISPLAY, &fb_vinfo, + this->FbDevIoctlHelper(FBIOPAN_DISPLAY, fb_vinfo, "Error panning the framebuffer display"); // Swap front and back buffers pointers @@ -241,11 +237,16 @@ void FBDevBackend::swapBuffers() { if(!useDoubleBuffer) return; + struct fb_var_screeninfo fb_vinfo; + + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, + "Error reading variable framebuffer information"); + if(useCopyBackBuffer) - copyBackBuffer(); + copyBackBuffer(&fb_vinfo); else - flipBuffers(); + flipBuffers(&fb_vinfo); } void FBDevBackend::waitVSync() diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 9100f8892..b89241f7d 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -35,8 +35,8 @@ class FBDevBackend : public Backend void setHeight(int height); void setFormat(cairo_format_t format); - void copyBackBuffer(); - void flipBuffers(); + void copyBackBuffer(struct fb_var_screeninfo* fb_vinfo); + void flipBuffers(struct fb_var_screeninfo* fb_vinfo); void swapBuffers(); void waitVSync(); From 9f183c3fca55a5df817f9b21356e3990ea6d7d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 8 Dec 2018 19:33:33 +0100 Subject: [PATCH 111/183] [FbDevBackend] Add `destroySurface()` that free in-memory buffer --- src/backend/FBDevBackend.cc | 7 +++++++ src/backend/FBDevBackend.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 357fc16e6..52ad1e9ef 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -157,6 +157,13 @@ cairo_surface_t* FBDevBackend::createSurface() return this->surface; } +void FBDevBackend::destroySurface() +{ + if(useInMemoryBackBuffer) free(back_buffer); + + Backend::destroySurface(); +} + void FBDevBackend::setWidth(int width) { diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index b89241f7d..ea87e040e 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -30,6 +30,7 @@ class FBDevBackend : public Backend void FbDevIoctlHelper(unsigned long request, void* data, string errmsg); cairo_surface_t* createSurface(); + void destroySurface(); void setWidth(int width); void setHeight(int height); From 73b4b4d478a40d05bacac960b548c776de42ee54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 8 Dec 2018 19:37:38 +0100 Subject: [PATCH 112/183] [FbDevBackend] Replaced `forceUseCopyBuffer` for lazy checking of panning --- src/Canvas.cc | 11 +--- src/backend/FBDevBackend.cc | 106 +++++++++++++++++++----------------- src/backend/FBDevBackend.h | 8 +-- 3 files changed, 63 insertions(+), 62 deletions(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index bc22461e0..da5cc48e8 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -96,14 +96,9 @@ NAN_METHOD(Canvas::New) { if (info[2]->IsString()) { if (0 == strcmp("fbdev", *Nan::Utf8String(info[2]))) { if (info[3]->IsString()) { - if(info[4]->IsBoolean()) { - if(info[5]->IsBoolean()) - backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), - info[4]->BooleanValue(), info[5]->BooleanValue()); - else - backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), - info[4]->BooleanValue()); - } + if(info[4]->IsBoolean()) + backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), + info[4]->BooleanValue()); else backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3])); } diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 52ad1e9ef..93e3f8404 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -30,9 +30,10 @@ cairo_format_t bits2format(__u32 bits_per_pixel) FBDevBackend::FBDevBackend(int width, int height, string deviceName, - bool useDoubleBuffer, bool forceUseCopyBuffer) + bool useDoubleBuffer) : Backend("fbdev", width, height) , useDoubleBuffer(useDoubleBuffer) + , useInMemoryBackBuffer(false) , useCopyBackBuffer(false) { struct fb_var_screeninfo fb_vinfo; @@ -44,14 +45,12 @@ FBDevBackend::FBDevBackend(int width, int height, string deviceName, this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, "Error setting variable framebuffer information"); - - this->enableDoubleBuffer(&fb_vinfo, forceUseCopyBuffer); } -FBDevBackend::FBDevBackend(string deviceName, bool useDoubleBuffer, - bool forceUseCopyBuffer) +FBDevBackend::FBDevBackend(string deviceName, bool useDoubleBuffer) : Backend("fbdev") , useDoubleBuffer(useDoubleBuffer) + , useInMemoryBackBuffer(false) , useCopyBackBuffer(false) { struct fb_var_screeninfo fb_vinfo; @@ -60,16 +59,12 @@ FBDevBackend::FBDevBackend(string deviceName, bool useDoubleBuffer, this->width = fb_vinfo.xres; this->height = fb_vinfo.yres; - - this->enableDoubleBuffer(&fb_vinfo, forceUseCopyBuffer); } FBDevBackend::~FBDevBackend() { this->destroySurface(); - if(useCopyBackBuffer) free(back_buffer); - munmap(this->fb_data, this->fb_finfo.smem_len); close(this->fb_fd); } @@ -97,42 +92,14 @@ void FBDevBackend::initFbDev(string deviceName, struct fb_var_screeninfo* fb_vin if(this->fb_data == MAP_FAILED) throw FBDevBackendException("Failed to map framebuffer device to memory"); + front_buffer = back_buffer = this->fb_data; + this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, fb_vinfo, "Error reading variable framebuffer information"); this->format = bits2format(fb_vinfo->bits_per_pixel); } -void FBDevBackend::enableDoubleBuffer(struct fb_var_screeninfo* fb_vinfo, - bool forceUseCopyBuffer) -{ - front_buffer = this->fb_data; - - if(!useDoubleBuffer) - back_buffer = this->fb_data; - - else - { - if(forceUseCopyBuffer) - useCopyBackBuffer = true; - - else - { - fb_vinfo->yres_virtual = height * 2; - - // Try to use real double buffer inside graphic card memory. If FbDev - // driver don't support to have a virtual framebuffer bigger than the - // actual one, then we'll use a buffer in memory. It's not so efficient - // and could lead to some tearing, but with VSync this should be minimal - // and at least we'll not see screen redraws. - useCopyBackBuffer = ioctl(this->fb_fd, FBIOPUT_VSCREENINFO, fb_vinfo) == -1; - } - - back_buffer = useCopyBackBuffer - ? (unsigned char*)malloc(this->fb_finfo.smem_len) - : this->fb_data + fb_vinfo->yres * fb_finfo.line_length; - } -} void FBDevBackend::FbDevIoctlHelper(unsigned long request, void* data, string errmsg) @@ -149,6 +116,47 @@ cairo_surface_t* FBDevBackend::createSurface() this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, "Error reading variable framebuffer information"); + if(useDoubleBuffer) + { + front_buffer = this->fb_data; + + // Try to use page flipping inside graphic card memory. If FbDev driver + // don't support to have a virtual framebuffer bigger than the actual one, + // then we'll use a buffer in memory. It's not so efficient and could lead + // to some tearing, but with VSync this should be minimal and at least we'll + // not see screen redraws. + fb_vinfo.yres_virtual = height * 2; + + useInMemoryBackBuffer = ioctl(this->fb_fd, FBIOPUT_VSCREENINFO, &fb_vinfo) == -1; + + if(useInMemoryBackBuffer) + { + useCopyBackBuffer = true; + + back_buffer = (unsigned char*)malloc(fb_vinfo.yres * fb_finfo.line_length); + } + + else + { + // back buffer in memory card + back_buffer = this->fb_data + fb_vinfo.yres * fb_finfo.line_length; + + // Try to use page flipping inside graphic card memory. If FbDev driver + // don't support vertical panning, then we'll need to copy data from back + // buffer. It's not so efficient and could lead to some tearing, but with + // VSync this should be minimal and at least we'll not see screen redraws. + fb_vinfo.yoffset = fb_vinfo.yres; + + useCopyBackBuffer = ioctl(this->fb_fd, FBIOPAN_DISPLAY, &fb_vinfo) == -1; + + if(!useCopyBackBuffer) + { + front_buffer = back_buffer; + back_buffer = this->fb_data; + } + } + } + // create cairo surface from data this->surface = cairo_image_surface_create_for_data(this->back_buffer, bits2format(fb_vinfo.bits_per_pixel), fb_vinfo.xres, fb_vinfo.yres, @@ -188,8 +196,6 @@ void FBDevBackend::setHeight(int height) fb_vinfo.yres = height; - if(useCopyBackBuffer) fb_vinfo.yres_virtual = height * 2; - this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, "Error setting variable framebuffer information"); @@ -227,7 +233,6 @@ void FBDevBackend::flipBuffers(struct fb_var_screeninfo* fb_vinfo) // Update display panning fb_vinfo->yoffset = fb_vinfo->yoffset ? 0 : fb_vinfo->yres; - this->FbDevIoctlHelper(FBIOPAN_DISPLAY, fb_vinfo, "Error panning the framebuffer display"); @@ -236,8 +241,15 @@ void FBDevBackend::flipBuffers(struct fb_var_screeninfo* fb_vinfo) front_buffer = back_buffer; back_buffer = aux; - // Destroy Cairo surface to force to create a new one in the new back buffer - destroySurface(); + // Destroy Cairo surface and create it in the new back buffer vertical offset + if(this->surface) + { + cairo_surface_destroy(this->surface); + + this->surface = cairo_image_surface_create_for_data(this->back_buffer, + bits2format(fb_vinfo->bits_per_pixel), fb_vinfo->xres, fb_vinfo->yres, + fb_finfo.line_length); + } } void FBDevBackend::swapBuffers() @@ -289,11 +301,7 @@ NAN_METHOD(FBDevBackend::New) bool useDoubleBuffer = false; if(info[1]->IsBoolean()) useDoubleBuffer = info[1]->BooleanValue(); - bool forceUseCopyBuffer = false; - if(info[2]->IsBoolean()) forceUseCopyBuffer = info[2]->BooleanValue(); - - FBDevBackend* backend = new FBDevBackend(fbDevice, useDoubleBuffer, - forceUseCopyBuffer); + FBDevBackend* backend = new FBDevBackend(fbDevice, useDoubleBuffer); backend->Wrap(info.This()); info.GetReturnValue().Set(info.This()); diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index ea87e040e..62da4224f 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -20,13 +20,12 @@ class FBDevBackend : public Backend unsigned char* front_buffer; unsigned char* back_buffer; bool useDoubleBuffer; + bool useInMemoryBackBuffer; bool useCopyBackBuffer; ~FBDevBackend(); void initFbDev(string deviceName, struct fb_var_screeninfo* fb_vinfo); - void enableDoubleBuffer(struct fb_var_screeninfo* fb_vinfo, - bool forceUseCopyBuffer); void FbDevIoctlHelper(unsigned long request, void* data, string errmsg); cairo_surface_t* createSurface(); @@ -43,9 +42,8 @@ class FBDevBackend : public Backend public: FBDevBackend(int width, int height, string deviceName = DEFAULT_DEVICE, - bool useDoubleBuffer = false, bool forceUseCopyBuffer = false); - FBDevBackend(string deviceName, bool useDoubleBuffer = false, - bool forceUseCopyBuffer = false); + bool useDoubleBuffer = false); + FBDevBackend(string deviceName, bool useDoubleBuffer = false); static Nan::Persistent constructor; static void Initialize(v8::Handle target); static NAN_METHOD(New); From 6864325e117461a98962a827e9e080dae870267d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 10 Dec 2018 12:11:45 +0100 Subject: [PATCH 113/183] [FbDevBackend] Added support for 24 bits framebuffers --- src/backend/FBDevBackend.cc | 62 +++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 93e3f8404..89b04ba1b 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -21,10 +22,11 @@ cairo_format_t bits2format(__u32 bits_per_pixel) switch(bits_per_pixel) { case 16: return CAIRO_FORMAT_RGB16_565; + case 24: return CAIRO_FORMAT_RGB24; case 32: return CAIRO_FORMAT_ARGB32; default: - throw FBDevBackendException("Only valid formats are RGB16_565 & ARGB32"); + throw FBDevBackendException("Only valid formats are RGB16_565, RGB24 and ARGB32"); } } @@ -92,8 +94,6 @@ void FBDevBackend::initFbDev(string deviceName, struct fb_var_screeninfo* fb_vin if(this->fb_data == MAP_FAILED) throw FBDevBackendException("Failed to map framebuffer device to memory"); - front_buffer = back_buffer = this->fb_data; - this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, fb_vinfo, "Error reading variable framebuffer information"); @@ -116,10 +116,13 @@ cairo_surface_t* FBDevBackend::createSurface() this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, "Error reading variable framebuffer information"); - if(useDoubleBuffer) - { - front_buffer = this->fb_data; + front_buffer = this->fb_data; + if(!useDoubleBuffer && fb_vinfo.bits_per_pixel != 24) + back_buffer = front_buffer; + + else + { // Try to use page flipping inside graphic card memory. If FbDev driver // don't support to have a virtual framebuffer bigger than the actual one, // then we'll use a buffer in memory. It's not so efficient and could lead @@ -127,13 +130,19 @@ cairo_surface_t* FBDevBackend::createSurface() // not see screen redraws. fb_vinfo.yres_virtual = height * 2; + // Adjust virtual framebuffer width to hold RGB24 Cairo surface in 24 bits + fb_vinfo.xres_virtual = fb_vinfo.bits_per_pixel != 24 + ? width + : ceil(width*4/3); + useInMemoryBackBuffer = ioctl(this->fb_fd, FBIOPUT_VSCREENINFO, &fb_vinfo) == -1; if(useInMemoryBackBuffer) { useCopyBackBuffer = true; - back_buffer = (unsigned char*)malloc(fb_vinfo.yres * fb_finfo.line_length); + int stride = cairo_format_stride_for_width(format, fb_vinfo.xres); + back_buffer = (unsigned char*)malloc(fb_vinfo.yres * stride); } else @@ -147,7 +156,8 @@ cairo_surface_t* FBDevBackend::createSurface() // VSync this should be minimal and at least we'll not see screen redraws. fb_vinfo.yoffset = fb_vinfo.yres; - useCopyBackBuffer = ioctl(this->fb_fd, FBIOPAN_DISPLAY, &fb_vinfo) == -1; + useCopyBackBuffer = fb_vinfo.bits_per_pixel != 24 + && ioctl(this->fb_fd, FBIOPAN_DISPLAY, &fb_vinfo) == -1; if(!useCopyBackBuffer) { @@ -158,9 +168,9 @@ cairo_surface_t* FBDevBackend::createSurface() } // create cairo surface from data + int stride = cairo_format_stride_for_width(format, fb_vinfo.xres); this->surface = cairo_image_surface_create_for_data(this->back_buffer, - bits2format(fb_vinfo.bits_per_pixel), fb_vinfo.xres, fb_vinfo.yres, - fb_finfo.line_length); + format, fb_vinfo.xres, fb_vinfo.yres, stride); return this->surface; } @@ -211,10 +221,11 @@ void FBDevBackend::setFormat(cairo_format_t format) switch(format) { case CAIRO_FORMAT_RGB16_565: fb_vinfo.bits_per_pixel = 16; break; + case CAIRO_FORMAT_RGB24: fb_vinfo.bits_per_pixel = 24; break; case CAIRO_FORMAT_ARGB32: fb_vinfo.bits_per_pixel = 32; break; default: - throw FBDevBackendException("Only valid formats are RGB16_565 & ARGB32"); + throw FBDevBackendException("Only valid formats are RGB16_565, RGB24 and ARGB32"); } this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, @@ -226,10 +237,24 @@ void FBDevBackend::setFormat(cairo_format_t format) void FBDevBackend::copyBackBuffer(struct fb_var_screeninfo* fb_vinfo) { - memcpy(front_buffer, back_buffer, fb_vinfo->yres * fb_finfo.line_length); + if(fb_vinfo->bits_per_pixel != 24) + memcpy(front_buffer, back_buffer, fb_vinfo->yres * fb_finfo.line_length); + + else + { + int stride = cairo_format_stride_for_width(format, fb_vinfo->xres); + + for(unsigned int y=0; yyres; y++) + for(unsigned int x=0; xxres; x++) + memcpy(front_buffer + y*fb_finfo.line_length + x*3, + back_buffer + y*stride + x*4 + 1, + 3); + } } -void FBDevBackend::flipBuffers(struct fb_var_screeninfo* fb_vinfo) +void FBDevBackend::flipPages(struct fb_var_screeninfo* fb_vinfo) { + if(!this->surface) return; + // Update display panning fb_vinfo->yoffset = fb_vinfo->yoffset ? 0 : fb_vinfo->yres; @@ -242,18 +267,15 @@ void FBDevBackend::flipBuffers(struct fb_var_screeninfo* fb_vinfo) back_buffer = aux; // Destroy Cairo surface and create it in the new back buffer vertical offset - if(this->surface) - { - cairo_surface_destroy(this->surface); + cairo_surface_destroy(this->surface); - this->surface = cairo_image_surface_create_for_data(this->back_buffer, - bits2format(fb_vinfo->bits_per_pixel), fb_vinfo->xres, fb_vinfo->yres, - fb_finfo.line_length); - } + this->surface = cairo_image_surface_create_for_data(this->back_buffer, + format, fb_vinfo->xres, fb_vinfo->yres, fb_finfo.line_length); } void FBDevBackend::swapBuffers() { + if(!this->surface) return; if(!useDoubleBuffer) return; struct fb_var_screeninfo fb_vinfo; From 6bf6f1e512d6a77da0e9443624cf82ce1f21fbe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 10 Dec 2018 12:12:58 +0100 Subject: [PATCH 114/183] [FbDev] Replaced `useCopyBackBuffer` for `useFlipPages` for readibility --- src/backend/FBDevBackend.cc | 18 +++++++++--------- src/backend/FBDevBackend.h | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 89b04ba1b..2e728cb4b 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -36,7 +36,7 @@ FBDevBackend::FBDevBackend(int width, int height, string deviceName, : Backend("fbdev", width, height) , useDoubleBuffer(useDoubleBuffer) , useInMemoryBackBuffer(false) - , useCopyBackBuffer(false) + , useFlipPages(false) { struct fb_var_screeninfo fb_vinfo; @@ -53,7 +53,7 @@ FBDevBackend::FBDevBackend(string deviceName, bool useDoubleBuffer) : Backend("fbdev") , useDoubleBuffer(useDoubleBuffer) , useInMemoryBackBuffer(false) - , useCopyBackBuffer(false) + , useFlipPages(false) { struct fb_var_screeninfo fb_vinfo; @@ -139,7 +139,7 @@ cairo_surface_t* FBDevBackend::createSurface() if(useInMemoryBackBuffer) { - useCopyBackBuffer = true; + useFlipPages = false; int stride = cairo_format_stride_for_width(format, fb_vinfo.xres); back_buffer = (unsigned char*)malloc(fb_vinfo.yres * stride); @@ -156,10 +156,10 @@ cairo_surface_t* FBDevBackend::createSurface() // VSync this should be minimal and at least we'll not see screen redraws. fb_vinfo.yoffset = fb_vinfo.yres; - useCopyBackBuffer = fb_vinfo.bits_per_pixel != 24 - && ioctl(this->fb_fd, FBIOPAN_DISPLAY, &fb_vinfo) == -1; + useFlipPages = fb_vinfo.bits_per_pixel != 24 + && ioctl(this->fb_fd, FBIOPAN_DISPLAY, &fb_vinfo) == -1; - if(!useCopyBackBuffer) + if(useFlipPages) { front_buffer = back_buffer; back_buffer = this->fb_data; @@ -283,11 +283,11 @@ void FBDevBackend::swapBuffers() this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, "Error reading variable framebuffer information"); - if(useCopyBackBuffer) - copyBackBuffer(&fb_vinfo); + if(useFlipPages) + flipPages(&fb_vinfo); else - flipBuffers(&fb_vinfo); + copyBackBuffer(&fb_vinfo); } void FBDevBackend::waitVSync() diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 62da4224f..dddff3146 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -21,7 +21,7 @@ class FBDevBackend : public Backend unsigned char* back_buffer; bool useDoubleBuffer; bool useInMemoryBackBuffer; - bool useCopyBackBuffer; + bool useFlipPages; ~FBDevBackend(); @@ -36,7 +36,7 @@ class FBDevBackend : public Backend void setFormat(cairo_format_t format); void copyBackBuffer(struct fb_var_screeninfo* fb_vinfo); - void flipBuffers(struct fb_var_screeninfo* fb_vinfo); + void flipPages(struct fb_var_screeninfo* fb_vinfo); void swapBuffers(); void waitVSync(); From 9c974383b9103dec77c7b95fad2abbf4fa790cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 10 Dec 2018 12:13:47 +0100 Subject: [PATCH 115/183] [FbDevBackend] Use `calloc()` to clean data at in-memory buffer --- src/backend/FBDevBackend.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 2e728cb4b..525db5dbe 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -142,7 +142,7 @@ cairo_surface_t* FBDevBackend::createSurface() useFlipPages = false; int stride = cairo_format_stride_for_width(format, fb_vinfo.xres); - back_buffer = (unsigned char*)malloc(fb_vinfo.yres * stride); + back_buffer = (unsigned char*)calloc(fb_vinfo.yres, stride); } else From 8b8edd20ccac9fc8b68be870224f6c13856c65ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Thu, 13 Dec 2018 15:00:40 +0100 Subject: [PATCH 116/183] [Backends] Don't return `cairo_surface_t` objects in `createSurface()` --- src/Canvas.cc | 2 -- src/backend/Backend.cc | 4 ++-- src/backend/Backend.h | 8 +++++--- src/backend/ImageBackend.cc | 8 +++----- src/backend/ImageBackend.h | 4 ++-- src/backend/PdfBackend.cc | 8 +++----- src/backend/PdfBackend.h | 4 ++-- src/backend/SvgBackend.cc | 8 ++++---- src/backend/SvgBackend.h | 4 ++-- 9 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index 8b2825a43..dcd5a226a 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -852,8 +852,6 @@ Canvas::resurface(Local canvas) { Nan::HandleScope scope; Local context; - backend()->recreateSurface(); - // Reset context context = canvas->Get(Nan::New("context").ToLocalChecked()); if (!context->IsUndefined()) { diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 34ef541f5..5891b69aa 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -32,11 +32,11 @@ void Backend::setCanvas(Canvas* _canvas) } -cairo_surface_t* Backend::recreateSurface() +void Backend::recreateSurface() { this->destroySurface(); - return this->createSurface(); + this->createSurface(); } DLL_PUBLIC cairo_surface_t* Backend::getSurface() { diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 75ae37aad..993c9d948 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -29,6 +29,11 @@ class Backend : public Nan::ObjectWrap Canvas* canvas; Backend(string name, int width, int height); + + virtual void createSurface() = 0; + virtual void destroySurface(); + virtual void recreateSurface(); + static void init(const Nan::FunctionCallbackInfo &info); static Backend *construct(int width, int height){ return nullptr; } @@ -37,9 +42,6 @@ class Backend : public Nan::ObjectWrap void setCanvas(Canvas* canvas); - virtual cairo_surface_t* createSurface() = 0; - virtual cairo_surface_t* recreateSurface(); - DLL_PUBLIC cairo_surface_t* getSurface(); void destroySurface(); diff --git a/src/backend/ImageBackend.cc b/src/backend/ImageBackend.cc index b9d169af8..bd6cda85f 100644 --- a/src/backend/ImageBackend.cc +++ b/src/backend/ImageBackend.cc @@ -39,17 +39,15 @@ int32_t ImageBackend::approxBytesPerPixel() { } } -cairo_surface_t* ImageBackend::createSurface() +void ImageBackend::createSurface() { assert(!this->surface); this->surface = cairo_image_surface_create(this->format, width, height); assert(this->surface); Nan::AdjustExternalMemory(approxBytesPerPixel() * width * height); - - return this->surface; } -cairo_surface_t* ImageBackend::recreateSurface() +void ImageBackend::recreateSurface() { // Re-surface if (this->surface) { @@ -59,7 +57,7 @@ cairo_surface_t* ImageBackend::recreateSurface() Nan::AdjustExternalMemory(-approxBytesPerPixel() * old_width * old_height); } - return createSurface(); + createSurface(); } cairo_format_t ImageBackend::getFormat() { diff --git a/src/backend/ImageBackend.h b/src/backend/ImageBackend.h index c245565e0..5d2d3c500 100644 --- a/src/backend/ImageBackend.h +++ b/src/backend/ImageBackend.h @@ -10,8 +10,8 @@ using namespace std; class ImageBackend : public Backend { private: - cairo_surface_t* createSurface(); - cairo_surface_t* recreateSurface(); + void createSurface(); + void recreateSurface(); cairo_format_t format = DEFAULT_FORMAT; public: diff --git a/src/backend/PdfBackend.cc b/src/backend/PdfBackend.cc index df409799a..0ba5a61fd 100644 --- a/src/backend/PdfBackend.cc +++ b/src/backend/PdfBackend.cc @@ -25,16 +25,14 @@ Backend *PdfBackend::construct(int width, int height){ return new PdfBackend(width, height); } -cairo_surface_t* PdfBackend::createSurface() { +void PdfBackend::createSurface() { if (!_closure) _closure = new PdfSvgClosure(canvas); + surface = cairo_pdf_surface_create_for_stream(toBuffer, _closure, width, height); - return surface; } -cairo_surface_t* PdfBackend::recreateSurface() { +void PdfBackend::recreateSurface() { cairo_pdf_surface_set_size(surface, width, height); - - return surface; } diff --git a/src/backend/PdfBackend.h b/src/backend/PdfBackend.h index 2c597a703..1858692f7 100644 --- a/src/backend/PdfBackend.h +++ b/src/backend/PdfBackend.h @@ -11,8 +11,8 @@ using namespace std; class PdfBackend : public Backend { private: - cairo_surface_t* createSurface(); - cairo_surface_t* recreateSurface(); + void createSurface(); + void recreateSurface(); public: PdfSvgClosure* _closure = NULL; diff --git a/src/backend/SvgBackend.cc b/src/backend/SvgBackend.cc index eaec46e83..afe8c7402 100644 --- a/src/backend/SvgBackend.cc +++ b/src/backend/SvgBackend.cc @@ -25,18 +25,18 @@ Backend *SvgBackend::construct(int width, int height){ return new SvgBackend(width, height); } -cairo_surface_t* SvgBackend::createSurface() { +void SvgBackend::createSurface() { if (!_closure) _closure = new PdfSvgClosure(canvas); + surface = cairo_svg_surface_create_for_stream(toBuffer, _closure, width, height); - return surface; } -cairo_surface_t* SvgBackend::recreateSurface() { +void SvgBackend::recreateSurface() { cairo_surface_finish(surface); delete _closure; cairo_surface_destroy(surface); - return createSurface(); + createSurface(); } diff --git a/src/backend/SvgBackend.h b/src/backend/SvgBackend.h index b703a3b94..7f5e86a9c 100644 --- a/src/backend/SvgBackend.h +++ b/src/backend/SvgBackend.h @@ -11,8 +11,8 @@ using namespace std; class SvgBackend : public Backend { private: - cairo_surface_t* createSurface(); - cairo_surface_t* recreateSurface(); + void createSurface(); + void recreateSurface(); public: PdfSvgClosure* _closure = NULL; From c21b8a5a144626a63a6bc9f0f19016d26a3556cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Thu, 13 Dec 2018 15:13:28 +0100 Subject: [PATCH 117/183] [FbDevBackend] Don't return surface in `createSurface()` --- src/backend/FBDevBackend.cc | 4 +--- src/backend/FBDevBackend.h | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 525db5dbe..3011321fc 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -109,7 +109,7 @@ void FBDevBackend::FbDevIoctlHelper(unsigned long request, void* data, } -cairo_surface_t* FBDevBackend::createSurface() +void FBDevBackend::createSurface() { struct fb_var_screeninfo fb_vinfo; @@ -171,8 +171,6 @@ cairo_surface_t* FBDevBackend::createSurface() int stride = cairo_format_stride_for_width(format, fb_vinfo.xres); this->surface = cairo_image_surface_create_for_data(this->back_buffer, format, fb_vinfo.xres, fb_vinfo.yres, stride); - - return this->surface; } void FBDevBackend::destroySurface() diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index dddff3146..bde65bc8b 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -28,8 +28,8 @@ class FBDevBackend : public Backend void initFbDev(string deviceName, struct fb_var_screeninfo* fb_vinfo); void FbDevIoctlHelper(unsigned long request, void* data, string errmsg); - cairo_surface_t* createSurface(); - void destroySurface(); + void createSurface(); + void destroySurface(); void setWidth(int width); void setHeight(int height); From 1c8cdeab2340c769a99f4009965137f098254930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Thu, 13 Dec 2018 15:43:16 +0100 Subject: [PATCH 118/183] [FbDevBackend][fix] Use pages flipping if driver supports vertical panning --- src/backend/FBDevBackend.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 3011321fc..27acb334d 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -157,10 +157,11 @@ void FBDevBackend::createSurface() fb_vinfo.yoffset = fb_vinfo.yres; useFlipPages = fb_vinfo.bits_per_pixel != 24 - && ioctl(this->fb_fd, FBIOPAN_DISPLAY, &fb_vinfo) == -1; + && ioctl(this->fb_fd, FBIOPAN_DISPLAY, &fb_vinfo) == 0; if(useFlipPages) { + // Swap front and back buffers since vertical panning was succesful front_buffer = back_buffer; back_buffer = this->fb_data; } From b50fe3e2a49ebcb56dc8b088eee05f402ff143b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Thu, 13 Dec 2018 15:45:01 +0100 Subject: [PATCH 119/183] [FbDevBackend] Prevent double free'ing of back buffer memory --- src/backend/FBDevBackend.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 27acb334d..8e9f3f841 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -34,6 +34,7 @@ cairo_format_t bits2format(__u32 bits_per_pixel) FBDevBackend::FBDevBackend(int width, int height, string deviceName, bool useDoubleBuffer) : Backend("fbdev", width, height) + , back_buffer(NULL) , useDoubleBuffer(useDoubleBuffer) , useInMemoryBackBuffer(false) , useFlipPages(false) @@ -51,6 +52,7 @@ FBDevBackend::FBDevBackend(int width, int height, string deviceName, FBDevBackend::FBDevBackend(string deviceName, bool useDoubleBuffer) : Backend("fbdev") + , back_buffer(NULL) , useDoubleBuffer(useDoubleBuffer) , useInMemoryBackBuffer(false) , useFlipPages(false) @@ -111,6 +113,8 @@ void FBDevBackend::FbDevIoctlHelper(unsigned long request, void* data, void FBDevBackend::createSurface() { + destroySurface(); + struct fb_var_screeninfo fb_vinfo; this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, @@ -176,9 +180,14 @@ void FBDevBackend::createSurface() void FBDevBackend::destroySurface() { - if(useInMemoryBackBuffer) free(back_buffer); - Backend::destroySurface(); + + if(useInMemoryBackBuffer && back_buffer) + { + free(back_buffer); + + back_buffer = NULL; + } } From 96383b16115a9c685622132b9373fa17b4da3a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Thu, 13 Dec 2018 15:45:44 +0100 Subject: [PATCH 120/183] [FbDevBackend] Clean-up & improved code readibility --- src/Canvas.cc | 8 ++++---- src/backend/FBDevBackend.cc | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index 40f7fbec5..ca46eea4e 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -284,7 +284,7 @@ static void parsePNGArgs(Local arg, PngClosure& pngargs) { static void parseJPEGArgs(Local arg, JpegClosure& jpegargs) { // "If Type(quality) is not Number, or if quality is outside that range, the - // user agent must use its default quality value, as if the quality argument + // user agent must use its default quality value, as if the quality argument // had not been given." - 4.12.5.5 if (arg->IsObject()) { Local obj = Nan::To(arg).ToLocalChecked(); @@ -463,9 +463,9 @@ NAN_METHOD(Canvas::ToBuffer) { Nan::ThrowError(Canvas::Error(ex)); return; } - + parseJPEGArgs(info[1], *closure); - + // TODO: only one callback fn in closure // TODO what does this comment mean? canvas->Ref(); closure->pfn = new Nan::Callback(info[0].As()); @@ -507,7 +507,7 @@ streamPNG(void *c, const uint8_t *data, unsigned len) { NAN_METHOD(Canvas::StreamPNGSync) { if (!info[0]->IsFunction()) return Nan::ThrowTypeError("callback function required"); - + Canvas *canvas = Nan::ObjectWrap::Unwrap(info.This()); PngClosure closure(canvas); diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 8e9f3f841..081ed8e07 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -152,7 +152,7 @@ void FBDevBackend::createSurface() else { // back buffer in memory card - back_buffer = this->fb_data + fb_vinfo.yres * fb_finfo.line_length; + back_buffer = front_buffer + fb_vinfo.yres * fb_finfo.line_length; // Try to use page flipping inside graphic card memory. If FbDev driver // don't support vertical panning, then we'll need to copy data from back From f07cba4ba1793a9c2c117a3baf36f10d3bf7359d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Fri, 14 Dec 2018 21:44:06 +0100 Subject: [PATCH 121/183] [FbDevBackend] `mmap()` graphic memory on `createSurface()` & code clean-up --- src/backend/FBDevBackend.cc | 85 +++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 081ed8e07..31ca074ba 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -34,6 +34,7 @@ cairo_format_t bits2format(__u32 bits_per_pixel) FBDevBackend::FBDevBackend(int width, int height, string deviceName, bool useDoubleBuffer) : Backend("fbdev", width, height) + , fb_data(NULL) , back_buffer(NULL) , useDoubleBuffer(useDoubleBuffer) , useInMemoryBackBuffer(false) @@ -52,6 +53,7 @@ FBDevBackend::FBDevBackend(int width, int height, string deviceName, FBDevBackend::FBDevBackend(string deviceName, bool useDoubleBuffer) : Backend("fbdev") + , fb_data(NULL) , back_buffer(NULL) , useDoubleBuffer(useDoubleBuffer) , useInMemoryBackBuffer(false) @@ -69,7 +71,6 @@ FBDevBackend::~FBDevBackend() { this->destroySurface(); - munmap(this->fb_data, this->fb_finfo.smem_len); close(this->fb_fd); } @@ -86,16 +87,6 @@ void FBDevBackend::initFbDev(string deviceName, struct fb_var_screeninfo* fb_vin throw FBDevBackendException(o.str()); } - this->FbDevIoctlHelper(FBIOGET_FSCREENINFO, &this->fb_finfo, - "Error reading fixed framebuffer information"); - - // Map the device to memory - this->fb_data = (unsigned char*) mmap(0, this->fb_finfo.smem_len, - PROT_READ | PROT_WRITE, MAP_SHARED, this->fb_fd, 0); - - if(this->fb_data == MAP_FAILED) - throw FBDevBackendException("Failed to map framebuffer device to memory"); - this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, fb_vinfo, "Error reading variable framebuffer information"); @@ -120,13 +111,13 @@ void FBDevBackend::createSurface() this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, "Error reading variable framebuffer information"); - front_buffer = this->fb_data; - - if(!useDoubleBuffer && fb_vinfo.bits_per_pixel != 24) - back_buffer = front_buffer; + int stride = cairo_format_stride_for_width(format, fb_vinfo.xres); - else + // Check support for double buffering features + if(useDoubleBuffer || fb_vinfo.bits_per_pixel == 24) { + useFlipPages = false; + // Try to use page flipping inside graphic card memory. If FbDev driver // don't support to have a virtual framebuffer bigger than the actual one, // then we'll use a buffer in memory. It's not so efficient and could lead @@ -141,39 +132,52 @@ void FBDevBackend::createSurface() useInMemoryBackBuffer = ioctl(this->fb_fd, FBIOPUT_VSCREENINFO, &fb_vinfo) == -1; - if(useInMemoryBackBuffer) + if(!useInMemoryBackBuffer && fb_vinfo.bits_per_pixel != 24) { - useFlipPages = false; - - int stride = cairo_format_stride_for_width(format, fb_vinfo.xres); - back_buffer = (unsigned char*)calloc(fb_vinfo.yres, stride); - } - - else - { - // back buffer in memory card - back_buffer = front_buffer + fb_vinfo.yres * fb_finfo.line_length; - // Try to use page flipping inside graphic card memory. If FbDev driver // don't support vertical panning, then we'll need to copy data from back // buffer. It's not so efficient and could lead to some tearing, but with // VSync this should be minimal and at least we'll not see screen redraws. fb_vinfo.yoffset = fb_vinfo.yres; - useFlipPages = fb_vinfo.bits_per_pixel != 24 - && ioctl(this->fb_fd, FBIOPAN_DISPLAY, &fb_vinfo) == 0; + useFlipPages = ioctl(this->fb_fd, FBIOPAN_DISPLAY, &fb_vinfo) == 0; + } + } - if(useFlipPages) - { - // Swap front and back buffers since vertical panning was succesful - front_buffer = back_buffer; - back_buffer = this->fb_data; - } + // Map the device to memory with new virtual framebuffer dimensions and config + this->FbDevIoctlHelper(FBIOGET_FSCREENINFO, &fb_finfo, + "Error reading fixed framebuffer information"); + + this->fb_data = (unsigned char*) mmap(0, fb_finfo.smem_len, + PROT_READ | PROT_WRITE, MAP_SHARED, this->fb_fd, 0); + + if(this->fb_data == MAP_FAILED) + throw FBDevBackendException("Failed to map framebuffer device to memory"); + + // Set pointers of the front and back buffers + front_buffer = this->fb_data; + + if(!useDoubleBuffer && fb_vinfo.bits_per_pixel != 24) + back_buffer = front_buffer; + + else if(useInMemoryBackBuffer) + back_buffer = (unsigned char*)calloc(fb_vinfo.yres, stride); + + else + { + // back buffer in graphic card memory + back_buffer = front_buffer + fb_vinfo.yres * fb_finfo.line_length; + + if(useFlipPages) + { + // Swap front and back buffers since vertical panning checking was + // succesful (so for the graphic card they are already swapped) + front_buffer = back_buffer; + back_buffer = this->fb_data; } } // create cairo surface from data - int stride = cairo_format_stride_for_width(format, fb_vinfo.xres); this->surface = cairo_image_surface_create_for_data(this->back_buffer, format, fb_vinfo.xres, fb_vinfo.yres, stride); } @@ -188,6 +192,13 @@ void FBDevBackend::destroySurface() back_buffer = NULL; } + + if(this->fb_data) + { + munmap(this->fb_data, fb_finfo.smem_len); + + this->fb_data = NULL; + } } From b0f81d77c9c8a4b4d64119a66f4970fb4a87ff1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 15 Dec 2018 14:31:39 +0100 Subject: [PATCH 122/183] [FbDevBackend] Option to enable flip buffers (disabled by default) --- src/Canvas.cc | 11 ++++++++--- src/backend/FBDevBackend.cc | 15 +++++++++++---- src/backend/FBDevBackend.h | 6 ++++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index ca46eea4e..41344ca27 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -96,9 +96,14 @@ NAN_METHOD(Canvas::New) { if (info[2]->IsString()) { if (0 == strcmp("fbdev", *Nan::Utf8String(info[2]))) { if (info[3]->IsString()) { - if(info[4]->IsBoolean()) - backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), - info[4]->BooleanValue()); + if(info[4]->IsBoolean()) { + if(info[5]->IsBoolean()) + backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), + info[4]->BooleanValue(), info[5]->BooleanValue()); + else + backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), + info[4]->BooleanValue()); + } else backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3])); } diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 31ca074ba..948855fff 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -32,13 +32,14 @@ cairo_format_t bits2format(__u32 bits_per_pixel) FBDevBackend::FBDevBackend(int width, int height, string deviceName, - bool useDoubleBuffer) + bool useDoubleBuffer, bool enableFlipPages) : Backend("fbdev", width, height) , fb_data(NULL) , back_buffer(NULL) , useDoubleBuffer(useDoubleBuffer) , useInMemoryBackBuffer(false) , useFlipPages(false) + , enableFlipPages(enableFlipPages) { struct fb_var_screeninfo fb_vinfo; @@ -51,13 +52,15 @@ FBDevBackend::FBDevBackend(int width, int height, string deviceName, "Error setting variable framebuffer information"); } -FBDevBackend::FBDevBackend(string deviceName, bool useDoubleBuffer) +FBDevBackend::FBDevBackend(string deviceName, bool useDoubleBuffer, + bool enableFlipPages) : Backend("fbdev") , fb_data(NULL) , back_buffer(NULL) , useDoubleBuffer(useDoubleBuffer) , useInMemoryBackBuffer(false) , useFlipPages(false) + , enableFlipPages(enableFlipPages) { struct fb_var_screeninfo fb_vinfo; @@ -132,7 +135,7 @@ void FBDevBackend::createSurface() useInMemoryBackBuffer = ioctl(this->fb_fd, FBIOPUT_VSCREENINFO, &fb_vinfo) == -1; - if(!useInMemoryBackBuffer && fb_vinfo.bits_per_pixel != 24) + if(enableFlipPages && !useInMemoryBackBuffer && fb_vinfo.bits_per_pixel != 24) { // Try to use page flipping inside graphic card memory. If FbDev driver // don't support vertical panning, then we'll need to copy data from back @@ -342,7 +345,11 @@ NAN_METHOD(FBDevBackend::New) bool useDoubleBuffer = false; if(info[1]->IsBoolean()) useDoubleBuffer = info[1]->BooleanValue(); - FBDevBackend* backend = new FBDevBackend(fbDevice, useDoubleBuffer); + bool enableFlipPages = false; + if(info[2]->IsBoolean()) enableFlipPages = info[2]->BooleanValue(); + + FBDevBackend* backend = new FBDevBackend(fbDevice, useDoubleBuffer, + enableFlipPages); backend->Wrap(info.This()); info.GetReturnValue().Set(info.This()); diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index bde65bc8b..58f81833f 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -22,6 +22,7 @@ class FBDevBackend : public Backend bool useDoubleBuffer; bool useInMemoryBackBuffer; bool useFlipPages; + bool enableFlipPages; ~FBDevBackend(); @@ -42,8 +43,9 @@ class FBDevBackend : public Backend public: FBDevBackend(int width, int height, string deviceName = DEFAULT_DEVICE, - bool useDoubleBuffer = false); - FBDevBackend(string deviceName, bool useDoubleBuffer = false); + bool useDoubleBuffer = false, bool enableFlipPages = false); + FBDevBackend(string deviceName, bool useDoubleBuffer = false, + bool enableFlipPages = false); static Nan::Persistent constructor; static void Initialize(v8::Handle target); static NAN_METHOD(New); From e90b95c42de98ee104db2fcd57ca7ae6225df7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 15 Dec 2018 14:32:07 +0100 Subject: [PATCH 123/183] [FbDevBackend][fix] Reset vertical panning before creating surface --- src/backend/FBDevBackend.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 948855fff..2513c938b 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -116,6 +116,10 @@ void FBDevBackend::createSurface() int stride = cairo_format_stride_for_width(format, fb_vinfo.xres); + // Reset vertical panning + fb_vinfo.yoffset = 0; + ioctl(this->fb_fd, FBIOPAN_DISPLAY, &fb_vinfo); + // Check support for double buffering features if(useDoubleBuffer || fb_vinfo.bits_per_pixel == 24) { From d7378423cfa1d784272c28aa210197a6b2b40a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 15 Dec 2018 14:33:52 +0100 Subject: [PATCH 124/183] [FbDevBackend][fix] Use `swapBuffers()` always for 24 bits images --- src/backend/FBDevBackend.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 2513c938b..5039c410b 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -302,13 +302,14 @@ void FBDevBackend::flipPages(struct fb_var_screeninfo* fb_vinfo) void FBDevBackend::swapBuffers() { if(!this->surface) return; - if(!useDoubleBuffer) return; struct fb_var_screeninfo fb_vinfo; this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, "Error reading variable framebuffer information"); + if(!useDoubleBuffer && fb_vinfo.bits_per_pixel != 24) return; + if(useFlipPages) flipPages(&fb_vinfo); From a1830670d3e1e1877c7b5e5a61e3f68c1fd5ffd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 15 Dec 2018 14:34:25 +0100 Subject: [PATCH 125/183] [FbDevBackend] Code clean-up, better readibility --- src/backend/FBDevBackend.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 5039c410b..a3498fe40 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -130,12 +130,12 @@ void FBDevBackend::createSurface() // then we'll use a buffer in memory. It's not so efficient and could lead // to some tearing, but with VSync this should be minimal and at least we'll // not see screen redraws. - fb_vinfo.yres_virtual = height * 2; + fb_vinfo.yres_virtual = fb_vinfo.yres * 2; // Adjust virtual framebuffer width to hold RGB24 Cairo surface in 24 bits - fb_vinfo.xres_virtual = fb_vinfo.bits_per_pixel != 24 - ? width - : ceil(width*4/3); + fb_vinfo.xres_virtual = fb_vinfo.bits_per_pixel == 24 + ? ceil(fb_vinfo.xres*4/3) + : fb_vinfo.xres; useInMemoryBackBuffer = ioctl(this->fb_fd, FBIOPUT_VSCREENINFO, &fb_vinfo) == -1; @@ -178,7 +178,7 @@ void FBDevBackend::createSurface() if(useFlipPages) { // Swap front and back buffers since vertical panning checking was - // succesful (so for the graphic card they are already swapped) + // succesful (so for the graphic card they were already swapped) front_buffer = back_buffer; back_buffer = this->fb_data; } From 6a22cb2c118adc991a10a73a3080f62c38e195d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 24 Dec 2018 17:27:14 +0100 Subject: [PATCH 126/183] Fixed documentation --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index c76a77fb7..2cdbccf65 100644 --- a/Readme.md +++ b/Readme.md @@ -97,7 +97,7 @@ This project is an implementation of the Web Canvas API and implements that API ### createCanvas() > ```ts -> createCanvas(width: number, height: number, type?: 'PDF'|'SVG') => Canvas +> createCanvas(width: number, height: number, type?: 'fbdev'|'pdf'|'svg') => Canvas > ``` Creates a Canvas instance. This method works in both Node.js and Web browsers, where there is no Canvas constructor. (See `browser.js` for the implementation that runs in browsers.) @@ -463,7 +463,7 @@ See also: ## SVG Output Support -node-canvas can create SVG documents instead of images. The canva type must be set when creating the canvas as follows: +node-canvas can create SVG documents instead of images. The canvas type must be set when creating the canvas as follows: ```js const canvas = createCanvas(200, 500, 'svg') From bfb4f1d469096da8648e16631ca8456e825cb80f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 21 Mar 2020 15:00:03 +0100 Subject: [PATCH 127/183] Fixes after merge --- lib/image.js | 17 ++++++----------- src/backend/FBDevBackend.cc | 8 +++++--- src/backend/FBDevBackend.h | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/image.js b/lib/image.js index 15cd6a18e..a09bcc8e0 100644 --- a/lib/image.js +++ b/lib/image.js @@ -17,12 +17,7 @@ const util = require('util') // Lazily loaded simple-get let get; -const proto = Image.prototype -const _getSource = proto.getSource -const _setSource = proto.setSource - -delete proto.getSource -delete proto.setSource +const {GetSource, SetSource} = bindings; Object.defineProperty(Image.prototype, 'src', { /** @@ -88,11 +83,11 @@ Image.prototype[util.inspect.custom || 'inspect'] = function(){ + ']'; }; -function getSource (img) { - return img._originalSource || _getSource.call(img) +function getSource(img){ + return img._originalSource || GetSource.call(img); } -function setSource (img, src, origSrc) { - _setSource.call(img, src) - img._originalSource = origSrc +function setSource(img, src, origSrc){ + SetSource.call(img, src); + img._originalSource = origSrc; } diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 450c2bd56..8117d1165 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -169,7 +169,7 @@ void FBDevBackend::setFormat(cairo_format_t format) Nan::Persistent FBDevBackend::constructor; -void FBDevBackend::Initialize(Handle target) +void FBDevBackend::Initialize(Local target) { Nan::HandleScope scope; @@ -177,13 +177,15 @@ void FBDevBackend::Initialize(Handle target) FBDevBackend::constructor.Reset(ctor); ctor->InstanceTemplate()->SetInternalFieldCount(1); ctor->SetClassName(Nan::New("FBDevBackend").ToLocalChecked()); - target->Set(Nan::New("FBDevBackend").ToLocalChecked(), ctor->GetFunction()); + Nan::Set(target, + Nan::New("FBDevBackend").ToLocalChecked(), + Nan::GetFunction(ctor).ToLocalChecked()).Check(); } NAN_METHOD(FBDevBackend::New) { string fbDevice = DEFAULT_DEVICE; - if(info[0]->IsString()) fbDevice = *String::Utf8Value(info[0].As()); + if(info[0]->IsString()) fbDevice = *Nan::Utf8String(info[0]); FBDevBackend* backend = new FBDevBackend(fbDevice); diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 73abcb919..902024164 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -36,7 +36,7 @@ class FBDevBackend : public Backend FBDevBackend(string deviceName); static Nan::Persistent constructor; - static void Initialize(v8::Handle target); + static void Initialize(v8::Local target); static NAN_METHOD(New); }; From b5f5dd07bd44d565e42b8ecd70d2118cd2df8c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 21 Mar 2020 15:00:33 +0100 Subject: [PATCH 128/183] Fixed linting --- test/public/tests.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/public/tests.js b/test/public/tests.js index 31ee6aaca..2b67ad680 100644 --- a/test/public/tests.js +++ b/test/public/tests.js @@ -585,7 +585,7 @@ tests['createRadialGradient()'] = function (ctx) { ctx.fillRect(0, 0, 150, 150) } -tests['globalAlpha'] = function (ctx) { +tests.globalAlpha = function (ctx) { ctx.globalAlpha = 0.5 ctx.fillStyle = 'rgba(0,0,0,0.5)' ctx.strokeRect(0, 0, 50, 50) @@ -618,7 +618,7 @@ tests['globalAlpha 2'] = function (ctx) { } } -tests['fillStyle'] = function (ctx) { +tests.fillStyle = function (ctx) { for (var i = 0; i < 6; i++) { for (var j = 0; j < 6; j++) { ctx.fillStyle = 'rgb(' + Math.floor(255 - 42.5 * i) + ',' + Math.floor(255 - 42.5 * j) + ',0)' @@ -627,7 +627,7 @@ tests['fillStyle'] = function (ctx) { } } -tests['strokeStyle'] = function (ctx) { +tests.strokeStyle = function (ctx) { for (var i = 0; i < 6; i++) { for (var j = 0; j < 6; j++) { ctx.strokeStyle = 'rgb(0,' + Math.floor(255 - 42.5 * i) + ',' + @@ -662,7 +662,7 @@ tests['floating point coordinates'] = function (ctx) { ctx.stroke() } -tests['lineWidth'] = function (ctx) { +tests.lineWidth = function (ctx) { for (var i = 0; i < 10; i++) { ctx.lineWidth = 1 + i ctx.beginPath() @@ -718,7 +718,7 @@ tests['lineCap default'] = function (ctx) { ctx.stroke() } -tests['lineCap'] = function (ctx) { +tests.lineCap = function (ctx) { ctx.beginPath() ctx.lineWidth = 10.0 ctx.lineCap = 'round' @@ -728,7 +728,7 @@ tests['lineCap'] = function (ctx) { ctx.stroke() } -tests['lineJoin'] = function (ctx) { +tests.lineJoin = function (ctx) { ctx.beginPath() ctx.lineWidth = 10.0 ctx.lineJoin = 'round' @@ -738,7 +738,7 @@ tests['lineJoin'] = function (ctx) { ctx.stroke() } -tests['states'] = function (ctx) { +tests.states = function (ctx) { ctx.save() ctx.rect(50, 50, 100, 100) ctx.stroke() @@ -1325,7 +1325,7 @@ tests['known bug #416'] = function (ctx, done) { img1.src = imageSrc('existing.png') } -tests['shadowBlur'] = function (ctx) { +tests.shadowBlur = function (ctx) { ctx.fillRect(150, 10, 20, 20) ctx.lineTo(20, 5) @@ -1351,7 +1351,7 @@ tests['shadowBlur'] = function (ctx) { ctx.fillRect(150, 150, 20, 20) } -tests['shadowColor'] = function (ctx) { +tests.shadowColor = function (ctx) { ctx.fillRect(150, 10, 20, 20) ctx.lineTo(20, 5) @@ -2249,7 +2249,7 @@ tests['putImageData() png data 3'] = function (ctx, done) { img.src = imageSrc('state.png') } -tests['setLineDash'] = function (ctx) { +tests.setLineDash = function (ctx) { ctx.setLineDash([10, 5, 25, 15]) ctx.lineWidth = 14 @@ -2283,7 +2283,7 @@ tests['setLineDash'] = function (ctx) { line([0, 3, 0, 0], 'green') // should be empty } -tests['lineDashOffset'] = function (ctx) { +tests.lineDashOffset = function (ctx) { ctx.setLineDash([10, 5, 25, 15]) ctx.lineWidth = 4 @@ -2310,7 +2310,7 @@ tests['lineDashOffset'] = function (ctx) { line(60, 'orange') line(-Infinity) line(70, 'purple') - line(void 0) + line(undefined) line(80, 'black') line(ctx.lineDashOffset + 10) From 64fb2e53ed9ec900fd7d2ac8529fc585afdbc521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 21 Mar 2020 15:01:33 +0100 Subject: [PATCH 129/183] Isolated `lint` script --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index fe619b0ea..61697ae78 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "scripts": { "prebenchmark": "node-gyp build", "benchmark": "node benchmarks/run.js", - "pretest": "standard examples/*.js test/server.js test/public/*.js benchmarks/run.js lib/context2d.js util/has_lib.js browser.js index.js && node-gyp build", + "lint": "standard examples/*.js test/server.js test/public/*.js benchmarks/run.js lib/context2d.js util/has_lib.js browser.js index.js", + "pretest": "npm run lint && node-gyp build", "test": "mocha test/*.test.js", "pretest-server": "node-gyp build", "test-server": "node test/server.js", From 45021a7bfd8d664ec788ece85084e86e7c77c7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 21 Mar 2020 15:06:34 +0100 Subject: [PATCH 130/183] Throw exception for unknown canvas type instead create `Image` by default --- src/Canvas.cc | 2 +- test/canvas.test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index 5fd4fa64a..c689c1a2f 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -114,7 +114,7 @@ NAN_METHOD(Canvas::New) { else if (0 == strcmp("svg", *Nan::Utf8String(info[2]))) backend = new SvgBackend(width, height); else - backend = new ImageBackend(width, height); + return Nan::ThrowRangeError("Unknown canvas type"); } else backend = new ImageBackend(width, height); diff --git a/test/canvas.test.js b/test/canvas.test.js index 2e1b7cf51..107132814 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -260,8 +260,8 @@ describe('Canvas', function () { assert.equal(canvas.type, 'pdf') var canvas = createCanvas(10, 10, 'svg') assert.equal(canvas.type, 'svg') - var canvas = createCanvas(10, 10, 'hey') - assert.equal(canvas.type, 'image') + + assert.throws(function () { createCanvas(10, 10, 'hey'); }, /RangeError/); }) it('Canvas#getContext("2d")', function () { From 601a415721de3d9141cac0d9c155da27f8f6d85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 21 Mar 2020 15:06:46 +0100 Subject: [PATCH 131/183] Updated dependencies --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 61697ae78..f7c64fbc3 100644 --- a/package.json +++ b/package.json @@ -50,17 +50,17 @@ "types": "types/index.d.ts", "dependencies": { "nan": "^2.14.0", - "node-pre-gyp": "^0.11.0", + "node-pre-gyp": "^0.14.0", "simple-get": "^3.0.3" }, "devDependencies": { "@types/node": "^10.12.18", "assert-rejects": "^1.0.0", "dtslint": "^0.5.3", - "express": "^4.16.3", - "mocha": "^5.2.0", - "pixelmatch": "^4.0.2", - "standard": "^12.0.1" + "express": "^4.17.1", + "mocha": "^7.1.1", + "pixelmatch": "^5.1.0", + "standard": "^14.3.3" }, "engines": { "node": ">=6" From 3fc6170e9eb42d48d4adb98414b230385968a5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 21 Mar 2020 15:08:57 +0100 Subject: [PATCH 132/183] Updated dependencies --- package.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index fe619b0ea..1388caf43 100644 --- a/package.json +++ b/package.json @@ -49,17 +49,17 @@ "types": "types/index.d.ts", "dependencies": { "nan": "^2.14.0", - "node-pre-gyp": "^0.11.0", - "simple-get": "^3.0.3" + "node-pre-gyp": "^0.14.0", + "simple-get": "^3.1.0" }, "devDependencies": { - "@types/node": "^10.12.18", + "@types/node": "^13.9.2", "assert-rejects": "^1.0.0", - "dtslint": "^0.5.3", - "express": "^4.16.3", - "mocha": "^5.2.0", - "pixelmatch": "^4.0.2", - "standard": "^12.0.1" + "dtslint": "^3.3.0", + "express": "^4.17.1", + "mocha": "^7.1.1", + "pixelmatch": "^5.1.0", + "standard": "^14.3.3" }, "engines": { "node": ">=6" From 352f3693729105dc5d17ebf3e8d0007d96ba87e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 21 Mar 2020 15:13:27 +0100 Subject: [PATCH 133/183] Throw exception for unknown canvas type instead create `Image` by default # Conflicts: # test/canvas.test.js --- src/Canvas.cc | 2 +- test/canvas.test.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index edeb2f4d6..80221d031 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -107,7 +107,7 @@ NAN_METHOD(Canvas::New) { else if (0 == strcmp("svg", *Nan::Utf8String(info[2]))) backend = new SvgBackend(width, height); else - backend = new ImageBackend(width, height); + return Nan::ThrowRangeError("Unknown canvas type"); } else backend = new ImageBackend(width, height); diff --git a/test/canvas.test.js b/test/canvas.test.js index b28a33990..2803f8841 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -256,9 +256,9 @@ describe('Canvas', function () { assert.equal(canvas.type, 'pdf'); var canvas = createCanvas(10, 10, 'svg'); assert.equal(canvas.type, 'svg'); - var canvas = createCanvas(10, 10, 'hey'); - assert.equal(canvas.type, 'image'); - }); + + assert.throws(function () { createCanvas(10, 10, 'hey'); }, /RangeError/); + }) it('Canvas#getContext("2d")', function () { var canvas = createCanvas(200, 300) From 3978af3ce68a74e88adb643f2990af18e2c121cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 21 Mar 2020 18:32:45 +0100 Subject: [PATCH 134/183] Moved screen-only `swapBuffers()` method to isolated `ScreenBuffer` class --- binding.gyp | 1 + src/backend/Backend.cc | 13 ------------- src/backend/Backend.h | 5 ----- src/backend/ScreenBackend.cc | 17 +++++++++++++++++ src/backend/ScreenBackend.h | 17 +++++++++++++++++ 5 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 src/backend/ScreenBackend.cc create mode 100644 src/backend/ScreenBackend.h diff --git a/binding.gyp b/binding.gyp index 24b08d5a6..95dc8d9d0 100644 --- a/binding.gyp +++ b/binding.gyp @@ -62,6 +62,7 @@ 'src/backend/Backend.cc', 'src/backend/ImageBackend.cc', 'src/backend/PdfBackend.cc', + 'src/backend/ScreenBackend.cc', 'src/backend/SvgBackend.cc', 'src/bmp/BMPParser.cc', 'src/Backends.cc', diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 3c5fc9bec..a78fecd5c 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -95,19 +95,6 @@ bool Backend::isSurfaceValid(){ } -NAN_METHOD(Backend::swapBuffers) -{ - Backend* backend = Nan::ObjectWrap::Unwrap(info.This()); - - backend->swapBuffers(); -} - -void Backend::Initialize(Local ctor) -{ - Nan::SetPrototypeMethod(ctor, "swapBuffers", swapBuffers); -} - - BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend, std::string operation_name) : backend(backend) diff --git a/src/backend/Backend.h b/src/backend/Backend.h index fbb90f9f4..c0c4e1928 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -15,8 +15,6 @@ class Backend : public Nan::ObjectWrap const std::string name; const char* error = NULL; - virtual void swapBuffers(){}; - protected: int width; int height; @@ -26,7 +24,6 @@ class Backend : public Nan::ObjectWrap Backend(std::string name, int width, int height); static void init(const Nan::FunctionCallbackInfo &info); static Backend *construct(int width, int height){ return nullptr; } - static void Initialize(Local ctor); public: virtual ~Backend(); @@ -54,8 +51,6 @@ class Backend : public Nan::ObjectWrap bool isSurfaceValid(); inline const char* getError(){ return error; } - - static NAN_METHOD(swapBuffers); }; diff --git a/src/backend/ScreenBackend.cc b/src/backend/ScreenBackend.cc new file mode 100644 index 000000000..e8392ac30 --- /dev/null +++ b/src/backend/ScreenBackend.cc @@ -0,0 +1,17 @@ +#include "ScreenBackend.h" + + +using namespace v8; + + +NAN_METHOD(ScreenBackend::swapBuffers) +{ + ScreenBackend* backend = Nan::ObjectWrap::Unwrap(info.This()); + + backend->swapBuffers(); +} + +void ScreenBackend::Initialize(Local ctor) +{ + Nan::SetPrototypeMethod(ctor, "swapBuffers", swapBuffers); +} diff --git a/src/backend/ScreenBackend.h b/src/backend/ScreenBackend.h new file mode 100644 index 000000000..e4eeffa39 --- /dev/null +++ b/src/backend/ScreenBackend.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Backend.h" + + +class Canvas; + +class ScreenBackend : public Backend +{ + private: + virtual void swapBuffers(){}; + + static NAN_METHOD(swapBuffers); + + protected: + static void Initialize(v8::Local ctor); +}; From 8e2486124a5c3d32e1ce65ef1ad7e678a926509e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 21 Mar 2020 19:02:47 +0100 Subject: [PATCH 135/183] Moved screens-only `waitVSync` method to `ScreenBackend` abstract class --- src/backend/Backend.cc | 38 ------------------------------------ src/backend/Backend.h | 7 ------- src/backend/ScreenBackend.cc | 33 ++++++++++++++++++++++++++++++- src/backend/ScreenBackend.h | 9 +++++++-- 4 files changed, 39 insertions(+), 48 deletions(-) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 3e1a0df7f..373e5915b 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -2,29 +2,6 @@ #include -using Nan::AsyncQueueWorker; -using Nan::AsyncWorker; -using Nan::Callback; - - -class WaitVSync: public AsyncWorker -{ - public: - WaitVSync(Callback* callback, Backend* backend) - : AsyncWorker(callback, "Backend:WaitVSync") - , backend(backend) - {} - - void Execute() - { - backend->waitVSync(); - } - - private: - Backend* backend; -}; - - Backend::Backend(std::string name, int width, int height) : name(name) , width(width) @@ -119,21 +96,6 @@ bool Backend::isSurfaceValid(){ } -NAN_METHOD(Backend::waitVSync) -{ - Backend* backend = Nan::ObjectWrap::Unwrap(info.This()); - - Callback* callback = new Callback(info[0].As()); - - AsyncQueueWorker(new WaitVSync(callback, backend)); -} - -void Backend::Initialize(Local ctor) -{ - Nan::SetPrototypeMethod(ctor, "waitVSync", waitVSync); -} - - BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend, std::string operation_name) : backend(backend) diff --git a/src/backend/Backend.h b/src/backend/Backend.h index a75bd28b4..c0c4e1928 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -11,14 +11,10 @@ class Canvas; class Backend : public Nan::ObjectWrap { - friend class WaitVSync; - private: const std::string name; const char* error = NULL; - virtual void waitVSync(){}; - protected: int width; int height; @@ -28,7 +24,6 @@ class Backend : public Nan::ObjectWrap Backend(std::string name, int width, int height); static void init(const Nan::FunctionCallbackInfo &info); static Backend *construct(int width, int height){ return nullptr; } - static void Initialize(Local ctor); public: virtual ~Backend(); @@ -56,8 +51,6 @@ class Backend : public Nan::ObjectWrap bool isSurfaceValid(); inline const char* getError(){ return error; } - - static NAN_METHOD(waitVSync); }; diff --git a/src/backend/ScreenBackend.cc b/src/backend/ScreenBackend.cc index e8392ac30..b1b70f089 100644 --- a/src/backend/ScreenBackend.cc +++ b/src/backend/ScreenBackend.cc @@ -1,7 +1,27 @@ #include "ScreenBackend.h" -using namespace v8; +using Nan::AsyncQueueWorker; +using Nan::AsyncWorker; +using Nan::Callback; + + +class WaitVSync: public AsyncWorker +{ + public: + WaitVSync(Callback* callback, ScreenBackend* backend) + : AsyncWorker(callback, "ScreenBackend:WaitVSync") + , backend(backend) + {} + + void Execute() + { + backend->waitVSync(); + } + + private: + ScreenBackend* backend; +}; NAN_METHOD(ScreenBackend::swapBuffers) @@ -11,7 +31,18 @@ NAN_METHOD(ScreenBackend::swapBuffers) backend->swapBuffers(); } +NAN_METHOD(ScreenBackend::waitVSync) +{ + ScreenBackend* backend = Nan::ObjectWrap::Unwrap(info.This()); + + Callback* callback = new Callback(info[0].As()); + + AsyncQueueWorker(new WaitVSync(callback, backend)); +} + + void ScreenBackend::Initialize(Local ctor) { Nan::SetPrototypeMethod(ctor, "swapBuffers", swapBuffers); + Nan::SetPrototypeMethod(ctor, "waitVSync", waitVSync); } diff --git a/src/backend/ScreenBackend.h b/src/backend/ScreenBackend.h index e4eeffa39..ec37c041a 100644 --- a/src/backend/ScreenBackend.h +++ b/src/backend/ScreenBackend.h @@ -3,15 +3,20 @@ #include "Backend.h" -class Canvas; +using namespace v8; + class ScreenBackend : public Backend { + friend class WaitVSync; + private: virtual void swapBuffers(){}; + virtual void waitVSync(){}; static NAN_METHOD(swapBuffers); + static NAN_METHOD(waitVSync); protected: - static void Initialize(v8::Local ctor); + static void Initialize(Local ctor); }; From aa3a6aea8dc3ca4e7c6200c60c361a9a4be9a779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 21 Mar 2020 19:35:43 +0100 Subject: [PATCH 136/183] Fixes after merge --- src/Canvas.cc | 4 ++-- src/backend/FBDevBackend.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index 060f12a7e..cfc7d420d 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -108,10 +108,10 @@ NAN_METHOD(Canvas::New) { if(info[4]->IsBoolean()) { if(info[5]->IsBoolean()) backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), - info[4]->BooleanValue(), info[5]->BooleanValue()); + Nan::To(info[4]).FromMaybe(0), Nan::To(info[5]).FromMaybe(0)); else backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), - info[4]->BooleanValue()); + Nan::To(info[4]).FromMaybe(0)); } else backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3])); diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 7c8b09972..826eee31a 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -350,10 +350,10 @@ NAN_METHOD(FBDevBackend::New) if(info[0]->IsString()) fbDevice = *Nan::Utf8String(info[0]); bool useDoubleBuffer = false; - if(info[1]->IsBoolean()) useDoubleBuffer = info[1]->BooleanValue(); + if(info[1]->IsBoolean()) useDoubleBuffer = Nan::To(info[1]).FromMaybe(0); bool enableFlipPages = false; - if(info[2]->IsBoolean()) enableFlipPages = info[2]->BooleanValue(); + if(info[2]->IsBoolean()) enableFlipPages = Nan::To(info[2]).FromMaybe(0); FBDevBackend* backend = new FBDevBackend(fbDevice, useDoubleBuffer, enableFlipPages); From 3023b363d87b4f0192d711cccb0c9774891e745f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 21 Mar 2020 19:46:42 +0100 Subject: [PATCH 137/183] Fixes after merge --- src/backend/FBDevBackend.cc | 14 +++++++------- src/backend/FBDevBackend.h | 4 ++-- src/backend/ScreenBackend.cc | 5 +++++ src/backend/ScreenBackend.h | 2 ++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 826eee31a..32b3f69ee 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -33,7 +33,7 @@ cairo_format_t bits2format(__u32 bits_per_pixel) FBDevBackend::FBDevBackend(int width, int height, string deviceName, bool useDoubleBuffer, bool enableFlipPages) - : Backend("fbdev", width, height) + : ScreenBackend("fbdev", width, height) , fb_data(NULL) , back_buffer(NULL) , useDoubleBuffer(useDoubleBuffer) @@ -54,7 +54,7 @@ FBDevBackend::FBDevBackend(int width, int height, string deviceName, FBDevBackend::FBDevBackend(string deviceName, bool useDoubleBuffer, bool enableFlipPages) - : Backend("fbdev") + : ScreenBackend("fbdev") , fb_data(NULL) , back_buffer(NULL) , useDoubleBuffer(useDoubleBuffer) @@ -191,7 +191,7 @@ void FBDevBackend::createSurface() void FBDevBackend::destroySurface() { - Backend::destroySurface(); + ScreenBackend::destroySurface(); if(useInMemoryBackBuffer && back_buffer) { @@ -221,7 +221,7 @@ void FBDevBackend::setWidth(int width) this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, "Error setting variable framebuffer information"); - Backend::setWidth(width); + ScreenBackend::setWidth(width); } void FBDevBackend::setHeight(int height) { @@ -235,7 +235,7 @@ void FBDevBackend::setHeight(int height) this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, "Error setting variable framebuffer information"); - Backend::setHeight(height); + ScreenBackend::setHeight(height); } void FBDevBackend::setFormat(cairo_format_t format) { @@ -257,7 +257,7 @@ void FBDevBackend::setFormat(cairo_format_t format) this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, "Error setting variable framebuffer information"); - Backend::setFormat(format); + ScreenBackend::setFormat(format); } @@ -337,7 +337,7 @@ void FBDevBackend::Initialize(Local target) ctor->InstanceTemplate()->SetInternalFieldCount(1); ctor->SetClassName(Nan::New("FBDevBackend").ToLocalChecked()); - Backend::Initialize(ctor); + ScreenBackend::Initialize(ctor); Nan::Set(target, Nan::New("FBDevBackend").ToLocalChecked(), diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 73cf43ce9..8f0a07db6 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -7,7 +7,7 @@ #include #include -#include "Backend.h" +#include "ScreenBackend.h" using namespace std; @@ -16,7 +16,7 @@ using namespace std; const string DEFAULT_DEVICE = "/dev/fb0"; -class FBDevBackend : public Backend +class FBDevBackend : public ScreenBackend { private: int fb_fd; diff --git a/src/backend/ScreenBackend.cc b/src/backend/ScreenBackend.cc index b1b70f089..00ff35a3e 100644 --- a/src/backend/ScreenBackend.cc +++ b/src/backend/ScreenBackend.cc @@ -24,6 +24,11 @@ class WaitVSync: public AsyncWorker }; +ScreenBackend::ScreenBackend(std::string name, int width, int height) + : Backend(name, width, height) +{} + + NAN_METHOD(ScreenBackend::swapBuffers) { ScreenBackend* backend = Nan::ObjectWrap::Unwrap(info.This()); diff --git a/src/backend/ScreenBackend.h b/src/backend/ScreenBackend.h index ec37c041a..36ec32bea 100644 --- a/src/backend/ScreenBackend.h +++ b/src/backend/ScreenBackend.h @@ -18,5 +18,7 @@ class ScreenBackend : public Backend static NAN_METHOD(waitVSync); protected: + ScreenBackend(std::string name, int width = 0, int height = 0); + static void Initialize(Local ctor); }; From 6161eb757b9c0f6de33425c38e49c73e240aaa91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 22 Mar 2020 00:00:34 +0100 Subject: [PATCH 138/183] Fixes after merge & removal of raf API --- src/backend/Backend.cc | 77 ------------------------------------- src/backend/Backend.h | 18 +-------- src/backend/FBDevBackend.cc | 63 +----------------------------- src/backend/FBDevBackend.h | 1 - 4 files changed, 2 insertions(+), 157 deletions(-) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 29e433767..d73cc6680 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -7,7 +7,6 @@ Backend::Backend(std::string name, int width, int height) : name(name) - , requestID(0) , format(CAIRO_FORMAT_INVALID) , width(width) , height(height) @@ -110,82 +109,6 @@ bool Backend::isSurfaceValid(){ return isValid; } -void Backend::onPaint() -{ - if(!listenOnPaint) return; - - listenOnPaint = false; - - dispatchWaitVSync(); -} - -void Backend::dispatchWaitVSync() -{ - if(waitingVSync) return; - - waitingVSync = true; - - // Dispatch thread to wait for VSync - uv_thread_create(&vSyncThread, WaitVSync, this); -} - -void Backend::executeCallbacks() -{ - if(!raf_callbacks) return; - - map_callbacks* callbacks = raf_callbacks; - raf_callbacks = NULL; - - if(callbacks->size()) - { - struct timeval tp; - gettimeofday(&tp, NULL); - double timestamp = tp.tv_sec * 1000 + tp.tv_usec / 1000; // milliseconds - - Local argv[] = {New(timestamp)}; - - for(auto it = callbacks->cbegin(); it != callbacks->cend(); ++it) - { - Callback* callback = (*it).second; - - callback->Call(1, argv); - delete callback; - } - - callbacks->clear(); - } - - delete callbacks; -} - - -// -// Animation Frame Provider API -// -// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#animationframeprovider -// - -NAN_METHOD(Backend::requestAnimationFrame) -{ - requestID++; - - if(!raf_callbacks) raf_callbacks = new map_callbacks; - - raf_callbacks->insert(std::pair(requestID, - new Callback(Nan::To(info[0]).ToLocalChecked()))); - - dispatchWaitVSync(); - - info.GetReturnValue().Set(Nan::New(requestID)); -} - -NAN_METHOD(Backend::cancelAnimationFrame) -{ - if(!raf_callbacks) return; - - raf_callbacks->erase(Nan::To(info[0]).FromJust()); -} - BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend, std::string operation_name) diff --git a/src/backend/Backend.h b/src/backend/Backend.h index caa2d9f18..7f79cbcca 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -15,11 +15,6 @@ class Backend : public Nan::ObjectWrap const std::string name; const char* error = NULL; - uv_thread_t vSyncThread; - long requestID; - - void dispatchWaitVSync(); - protected: int width; int height; @@ -37,10 +32,6 @@ class Backend : public Nan::ObjectWrap static Backend *construct(int width, int height){ return nullptr; } public: - bool listenOnPaint; - bool waitingVSync; - map_callbacks* raf_callbacks; - virtual ~Backend(); void setCanvas(Canvas* canvas); @@ -61,14 +52,7 @@ class Backend : public Nan::ObjectWrap bool isSurfaceValid(); inline const char* getError(){ return error; } - void onPaint(); - - virtual void waitVSync(){}; - virtual void swapBuffers(){}; - void executeCallbacks(); - - NAN_METHOD(requestAnimationFrame); - NAN_METHOD(cancelAnimationFrame); + virtual void onPaint(){}; }; diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 9139dd335..b991e5427 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -50,8 +50,6 @@ FBDevBackend::FBDevBackend(int width, int height, string deviceName, this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, "Error setting variable framebuffer information"); - - this->enableDoubleBuffer(height, &fb_vinfo); } FBDevBackend::FBDevBackend(string deviceName, bool useDoubleBuffer, @@ -70,8 +68,6 @@ FBDevBackend::FBDevBackend(string deviceName, bool useDoubleBuffer, this->width = fb_vinfo.xres; this->height = fb_vinfo.yres; - - this->enableDoubleBuffer(height, &fb_vinfo); } FBDevBackend::~FBDevBackend() @@ -100,26 +96,6 @@ void FBDevBackend::initFbDev(string deviceName, struct fb_var_screeninfo* fb_vin this->format = bits2format(fb_vinfo->bits_per_pixel); } -void FBDevBackend::enableDoubleBuffer(int height, struct fb_var_screeninfo* fb_vinfo) -{ - fb_vinfo->yres_virtual = height * 2; - - // Try to use real double buffer inside graphic card memory. If framebuffer - // driver don't support to have a virtual framebuffer bigger than the actual - // one, then we'll use a buffer in memory. It's not so efficient and could - // lead to some tearing, but with VSync this should be minimal and at least - // we'll not see screen redraws. - useCopyBuffer = ioctl(this->fb_fd, FBIOPUT_VSCREENINFO, fb_vinfo) == -1; - - fb_data_screen = this->fb_data; - fb_data_surface = useCopyBuffer - ? (unsigned char*)malloc(this->fb_finfo.smem_len) - : this->fb_data + fb_vinfo->yres * fb_finfo.line_length; - - // Allow VSync requests by default - listenOnDraw = true; -} - void FBDevBackend::FbDevIoctlHelper(unsigned long request, void* data, string errmsg) @@ -256,7 +232,7 @@ void FBDevBackend::setHeight(int height) fb_vinfo.yres = height; - if(useCopyBuffer) fb_vinfo.yres_virtual = height * 2; + if(useDoubleBuffer) fb_vinfo.yres_virtual = height * 2; this->FbDevIoctlHelper(FBIOPUT_VSCREENINFO, &fb_vinfo, "Error setting variable framebuffer information"); @@ -343,15 +319,6 @@ void FBDevBackend::swapBuffers() copyBackBuffer(&fb_vinfo); } -void FBDevBackend::waitVSync() -{ - int arg = 0; - - this->FbDevIoctlHelper(FBIO_WAITFORVSYNC, &arg, - "Error waiting for framebuffer VSync"); -} - - void FBDevBackend::waitVSync() { int arg = 0; @@ -360,34 +327,6 @@ void FBDevBackend::waitVSync() "Error waiting for framebuffer VSync"); } -void FBDevBackend::swapBuffers() -{ - if(useCopyBuffer) - memcpy(fb_data_screen, fb_data_surface, this->fb_finfo.smem_len); - - else - { - // Update display panning - struct fb_var_screeninfo fb_vinfo; - - this->FbDevIoctlHelper(FBIOGET_VSCREENINFO, &fb_vinfo, - "Error reading variable framebuffer information"); - - fb_vinfo.yoffset = fb_vinfo.yoffset ? 0 : fb_vinfo.yres; - - this->FbDevIoctlHelper(FBIOPAN_DISPLAY, &fb_vinfo, - "Error panning the framebuffer display"); - - // Swap front and back buffers pointers - unsigned char* fb_data_aux = fb_data_screen; - fb_data_screen = fb_data_surface; - fb_data_surface = fb_data_aux; - - // Destroy Cairo surface to force create new one in the new back buffer - destroySurface(); - } -} - Nan::Persistent FBDevBackend::constructor; diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 3f62c53a1..8f0a07db6 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -32,7 +32,6 @@ class FBDevBackend : public ScreenBackend ~FBDevBackend(); void initFbDev(string deviceName, struct fb_var_screeninfo* fb_vinfo); - void enableDoubleBuffer(int height, struct fb_var_screeninfo* fb_vinfo); void FbDevIoctlHelper(unsigned long request, void* data, string errmsg); void createSurface(); From f884acc928419eeaa960832c2413fc10b34c92fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 22 Mar 2020 00:01:15 +0100 Subject: [PATCH 139/183] Clean-ups --- src/backend/FBDevBackend.cc | 16 +++------------- src/backend/FBDevBackend.h | 8 ++++---- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index b991e5427..6a3df45f1 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -34,11 +34,7 @@ cairo_format_t bits2format(__u32 bits_per_pixel) FBDevBackend::FBDevBackend(int width, int height, string deviceName, bool useDoubleBuffer, bool enableFlipPages) : ScreenBackend("fbdev", width, height) - , fb_data(NULL) - , back_buffer(NULL) , useDoubleBuffer(useDoubleBuffer) - , useInMemoryBackBuffer(false) - , useFlipPages(false) , enableFlipPages(enableFlipPages) { struct fb_var_screeninfo fb_vinfo; @@ -55,11 +51,7 @@ FBDevBackend::FBDevBackend(int width, int height, string deviceName, FBDevBackend::FBDevBackend(string deviceName, bool useDoubleBuffer, bool enableFlipPages) : ScreenBackend("fbdev") - , fb_data(NULL) - , back_buffer(NULL) , useDoubleBuffer(useDoubleBuffer) - , useInMemoryBackBuffer(false) - , useFlipPages(false) , enableFlipPages(enableFlipPages) { struct fb_var_screeninfo fb_vinfo; @@ -123,9 +115,7 @@ void FBDevBackend::createSurface() // Check support for double buffering features if(useDoubleBuffer || fb_vinfo.bits_per_pixel == 24) { - useFlipPages = false; - - // Try to use page flipping inside graphic card memory. If FbDev driver + // Try to use real double buffer inside graphic card memory. If FbDev driver // don't support to have a virtual framebuffer bigger than the actual one, // then we'll use a buffer in memory. It's not so efficient and could lead // to some tearing, but with VSync this should be minimal and at least we'll @@ -149,6 +139,8 @@ void FBDevBackend::createSurface() useFlipPages = ioctl(this->fb_fd, FBIOPAN_DISPLAY, &fb_vinfo) == 0; } + else + useFlipPages = false; } // Map the device to memory with new virtual framebuffer dimensions and config @@ -281,8 +273,6 @@ void FBDevBackend::copyBackBuffer(struct fb_var_screeninfo* fb_vinfo) } void FBDevBackend::flipPages(struct fb_var_screeninfo* fb_vinfo) { - if(!this->surface) return; - // Update display panning fb_vinfo->yoffset = fb_vinfo->yoffset ? 0 : fb_vinfo->yres; diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 8f0a07db6..68a137583 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -21,12 +21,12 @@ class FBDevBackend : public ScreenBackend private: int fb_fd; struct fb_fix_screeninfo fb_finfo; - unsigned char* fb_data; + unsigned char* fb_data = NULL; unsigned char* front_buffer; - unsigned char* back_buffer; + unsigned char* back_buffer = NULL; bool useDoubleBuffer; - bool useInMemoryBackBuffer; - bool useFlipPages; + bool useInMemoryBackBuffer = false; + bool useFlipPages = false; bool enableFlipPages; ~FBDevBackend(); From 1bfe1f10d94ace919f42f7228cdc6caf3881f5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 22 Mar 2020 00:32:05 +0100 Subject: [PATCH 140/183] Flip between two surfaces instead of delete and create a new one each time --- src/backend/FBDevBackend.cc | 25 +++++++++++++++++-------- src/backend/FBDevBackend.h | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 6a3df45f1..b885d31fb 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -112,6 +112,8 @@ void FBDevBackend::createSurface() fb_vinfo.yoffset = 0; ioctl(this->fb_fd, FBIOPAN_DISPLAY, &fb_vinfo); + bool useFlipPages = false; + // Check support for double buffering features if(useDoubleBuffer || fb_vinfo.bits_per_pixel == 24) { @@ -139,8 +141,6 @@ void FBDevBackend::createSurface() useFlipPages = ioctl(this->fb_fd, FBIOPAN_DISPLAY, &fb_vinfo) == 0; } - else - useFlipPages = false; } // Map the device to memory with new virtual framebuffer dimensions and config @@ -173,6 +173,9 @@ void FBDevBackend::createSurface() // succesful (so for the graphic card they were already swapped) front_buffer = back_buffer; back_buffer = this->fb_data; + + this->flip_surface = cairo_image_surface_create_for_data(this->back_buffer, + format, fb_vinfo.xres, fb_vinfo.yres, stride); } } @@ -198,6 +201,13 @@ void FBDevBackend::destroySurface() this->fb_data = NULL; } + + if(this->flip_surface) + { + cairo_surface_destroy(this->flip_surface); + + this->flip_surface = NULL; + } } @@ -284,11 +294,10 @@ void FBDevBackend::flipPages(struct fb_var_screeninfo* fb_vinfo) front_buffer = back_buffer; back_buffer = aux; - // Destroy Cairo surface and create it in the new back buffer vertical offset - cairo_surface_destroy(this->surface); - - this->surface = cairo_image_surface_create_for_data(this->back_buffer, - format, fb_vinfo->xres, fb_vinfo->yres, fb_finfo.line_length); + // Swap front and back surfaces pointers + cairo_surface_t* aux_surface = flip_surface; + flip_surface = surface; + surface = aux_surface; } void FBDevBackend::swapBuffers() @@ -302,7 +311,7 @@ void FBDevBackend::swapBuffers() if(!useDoubleBuffer && fb_vinfo.bits_per_pixel != 24) return; - if(useFlipPages) + if(this->flip_surface) flipPages(&fb_vinfo); else diff --git a/src/backend/FBDevBackend.h b/src/backend/FBDevBackend.h index 68a137583..b316162b5 100644 --- a/src/backend/FBDevBackend.h +++ b/src/backend/FBDevBackend.h @@ -26,7 +26,7 @@ class FBDevBackend : public ScreenBackend unsigned char* back_buffer = NULL; bool useDoubleBuffer; bool useInMemoryBackBuffer = false; - bool useFlipPages = false; + cairo_surface_t* flip_surface = NULL; bool enableFlipPages; ~FBDevBackend(); From 5194e0d88de0160e71a733a1dd72c237b09470bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 22 Mar 2020 00:39:15 +0100 Subject: [PATCH 141/183] Remove useless swapping of buffers pointers --- src/backend/FBDevBackend.cc | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index b885d31fb..0a7d6ae18 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -289,15 +289,10 @@ void FBDevBackend::flipPages(struct fb_var_screeninfo* fb_vinfo) this->FbDevIoctlHelper(FBIOPAN_DISPLAY, fb_vinfo, "Error panning the framebuffer display"); - // Swap front and back buffers pointers - unsigned char* aux = front_buffer; - front_buffer = back_buffer; - back_buffer = aux; - - // Swap front and back surfaces pointers - cairo_surface_t* aux_surface = flip_surface; + // Swap front and back surfaces + cairo_surface_t* aux = flip_surface; flip_surface = surface; - surface = aux_surface; + surface = aux; } void FBDevBackend::swapBuffers() From 4aad102d06f4d34bba176079e773b7f6a86be7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 22 Mar 2020 01:53:40 +0100 Subject: [PATCH 142/183] Fix checking of libraries (and return missing ones) & Update libpng --- static/ensure_deps.sh | 4 ++-- util/has_lib.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/static/ensure_deps.sh b/static/ensure_deps.sh index 1415c313b..708fc4f9a 100755 --- a/static/ensure_deps.sh +++ b/static/ensure_deps.sh @@ -9,7 +9,7 @@ GIFLIB_VERSION=4.2.3 GLIB_VERSION=2.50.2 HARFBUZZ_VERSION=1.4.2 LIBJPEG_VERSION=1.2.1 -LIBPNG_VERSION=1.2.56 +LIBPNG_VERSION=1.6.37 PANGO_VERSION=1.40.3 PIXMAN_VERSION=0.32.6 ZLIB_VERSION=1.2.11 @@ -23,7 +23,7 @@ GIFLIB_URL=http://sourceforge.net/projects/giflib/files/giflib-4.x/giflib-$GIFLI GLIB_URL=https://download.gnome.org/sources/glib/2.50/glib-$GLIB_VERSION.tar.xz HARFBUZZ_URL=https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-$HARFBUZZ_VERSION.tar.bz2 LIBJPEG_URL=http://downloads.sourceforge.net/project/libjpeg-turbo/$LIBJPEG_VERSION/libjpeg-turbo-$LIBJPEG_VERSION.tar.gz -LIBPNG_URL=http://sourceforge.net/projects/libpng/files/libpng12/$LIBPNG_VERSION/libpng-$LIBPNG_VERSION.tar.xz +LIBPNG_URL=http://sourceforge.net/projects/libpng/files/libpng16/$LIBPNG_VERSION/libpng-$LIBPNG_VERSION.tar.xz PANGO_URL=http://ftp.gnome.org/pub/GNOME/sources/pango/1.40/pango-$PANGO_VERSION.tar.xz PIXMAN_URL=http://cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz ZLIB_URL=https://sourceforge.net/projects/libpng/files/zlib/$ZLIB_VERSION/zlib-$ZLIB_VERSION.tar.gz diff --git a/util/has_lib.js b/util/has_lib.js index afd9c18c4..1f96c84ef 100644 --- a/util/has_lib.js +++ b/util/has_lib.js @@ -65,10 +65,10 @@ function hasLdconfig () { try { // Add /sbin to path as ldconfig is located there on some systems -- e.g. // Debian (and it can still be used by unprivileged users): - childProcess.execSync('export PATH="$PATH:/sbin"') - process.env.PATH = '...' + execSync('export PATH="$PATH:/sbin"') + // process.env.PATH = '...' // execSync throws on nonzero exit - childProcess.execSync('hash ldconfig 2>/dev/null') + execSync('hash ldconfig 2>/dev/null') return true } catch (err) { return false @@ -96,7 +96,7 @@ function hasPkgconfigLib (lib) { function main (query) { if (!query) { for (var libname of ['gif', 'jpeg', 'cairo', 'pango', 'freetype', 'rsvg']) { - if (!main(libname)) return false + if (!main(libname)) return libname } return true From d03fbe154a15c512629699390734a998c7fdd06f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 22 Mar 2020 02:11:38 +0100 Subject: [PATCH 143/183] Fix search of system libraries --- util/has_lib.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/has_lib.js b/util/has_lib.js index 1f96c84ef..44fae74d3 100644 --- a/util/has_lib.js +++ b/util/has_lib.js @@ -45,6 +45,8 @@ function hasSystemLib (lib) { } // Try checking common library locations + const libNameRegex = new RegExp(libName) + return SYSTEM_PATHS.some(function (systemPath) { try { var dirListing = fs.readdirSync(systemPath) From fdf14bcafa2346e70109873c0aeec9edec0defb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro?= Date: Sun, 22 Mar 2020 20:57:57 +0100 Subject: [PATCH 144/183] Remove unmaintained Node.js v6 and v8 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d9975ab93..10b3db9ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,6 @@ node_js: - '13' - '12' - '10' - - '8' - - '6' addons: apt: sources: From 3f38854fc0cce1086fad998807dae1dd9732a31f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro?= Date: Sun, 22 Mar 2020 20:58:35 +0100 Subject: [PATCH 145/183] Remove unmaintained Node.js v6 and v8 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d9975ab93..10b3db9ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,6 @@ node_js: - '13' - '12' - '10' - - '8' - - '6' addons: apt: sources: From 17256c75dc76e5c1e27609ff335eda11c05a28b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro?= Date: Sun, 22 Mar 2020 20:59:06 +0100 Subject: [PATCH 146/183] Remove unmaintained Node.js v6 and v8 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d9975ab93..10b3db9ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,6 @@ node_js: - '13' - '12' - '10' - - '8' - - '6' addons: apt: sources: From fcba4d1939b2f28ee12cd85714f511efb097610a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 19:24:29 +0200 Subject: [PATCH 147/183] Update `devDependencies` to fix linting errors --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 78b31f82b..cde80c41f 100644 --- a/package.json +++ b/package.json @@ -53,13 +53,14 @@ "simple-get": "^3.0.3" }, "devDependencies": { - "@types/node": "^10.12.18", + "@types/node": "^14.11.10", "assert-rejects": "^1.0.0", - "dtslint": "^0.5.3", + "dtslint": "^4.0.4", "express": "^4.16.3", "mocha": "^5.2.0", "pixelmatch": "^4.0.2", - "standard": "^12.0.1" + "standard": "^12.0.1", + "typescript": "^4.0.3" }, "engines": { "node": ">=6" From c014caa8f19a6b3f3bddcfde25e78eab6d73e84b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 19:26:43 +0200 Subject: [PATCH 148/183] Update `devDependencies` to fix linting errors --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 78b31f82b..cde80c41f 100644 --- a/package.json +++ b/package.json @@ -53,13 +53,14 @@ "simple-get": "^3.0.3" }, "devDependencies": { - "@types/node": "^10.12.18", + "@types/node": "^14.11.10", "assert-rejects": "^1.0.0", - "dtslint": "^0.5.3", + "dtslint": "^4.0.4", "express": "^4.16.3", "mocha": "^5.2.0", "pixelmatch": "^4.0.2", - "standard": "^12.0.1" + "standard": "^12.0.1", + "typescript": "^4.0.3" }, "engines": { "node": ">=6" From 173a8e48bf18ecb0538a9f61a425e510e4c9f581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 19:24:29 +0200 Subject: [PATCH 149/183] Update `devDependencies` to fix linting errors --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 78b31f82b..cde80c41f 100644 --- a/package.json +++ b/package.json @@ -53,13 +53,14 @@ "simple-get": "^3.0.3" }, "devDependencies": { - "@types/node": "^10.12.18", + "@types/node": "^14.11.10", "assert-rejects": "^1.0.0", - "dtslint": "^0.5.3", + "dtslint": "^4.0.4", "express": "^4.16.3", "mocha": "^5.2.0", "pixelmatch": "^4.0.2", - "standard": "^12.0.1" + "standard": "^12.0.1", + "typescript": "^4.0.3" }, "engines": { "node": ">=6" From 297514f51e0fed8647c076aa081ac14b5155e36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 19:24:29 +0200 Subject: [PATCH 150/183] Update `devDependencies` to fix linting errors --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 78b31f82b..cde80c41f 100644 --- a/package.json +++ b/package.json @@ -53,13 +53,14 @@ "simple-get": "^3.0.3" }, "devDependencies": { - "@types/node": "^10.12.18", + "@types/node": "^14.11.10", "assert-rejects": "^1.0.0", - "dtslint": "^0.5.3", + "dtslint": "^4.0.4", "express": "^4.16.3", "mocha": "^5.2.0", "pixelmatch": "^4.0.2", - "standard": "^12.0.1" + "standard": "^12.0.1", + "typescript": "^4.0.3" }, "engines": { "node": ">=6" From 0688eff0549b22cbf524a8cfa1f5c6149918b823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 19:30:45 +0200 Subject: [PATCH 151/183] Update `devDependencies` to fix linting errors # Conflicts: # package.json --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 5b71db4e4..8f5c17d09 100644 --- a/package.json +++ b/package.json @@ -54,13 +54,14 @@ "simple-get": "^3.0.3" }, "devDependencies": { - "@types/node": "^10.12.18", + "@types/node": "^14.11.10", "assert-rejects": "^1.0.0", - "dtslint": "^0.5.3", + "dtslint": "^4.0.4", "express": "^4.17.1", "mocha": "^7.1.1", "pixelmatch": "^5.1.0", - "standard": "^14.3.3" + "standard": "^14.3.3", + "typescript": "^4.0.3" }, "engines": { "node": ">=6" From 144337da1f37fe8e2685fa57aab2ba3fef51ca2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 19:30:45 +0200 Subject: [PATCH 152/183] Update `devDependencies` to fix linting errors # Conflicts: # package.json --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 5b71db4e4..8f5c17d09 100644 --- a/package.json +++ b/package.json @@ -54,13 +54,14 @@ "simple-get": "^3.0.3" }, "devDependencies": { - "@types/node": "^10.12.18", + "@types/node": "^14.11.10", "assert-rejects": "^1.0.0", - "dtslint": "^0.5.3", + "dtslint": "^4.0.4", "express": "^4.17.1", "mocha": "^7.1.1", "pixelmatch": "^5.1.0", - "standard": "^14.3.3" + "standard": "^14.3.3", + "typescript": "^4.0.3" }, "engines": { "node": ">=6" From e8cfd1a9eb80a6e84c5e327c0c8e66e977000496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 19:30:45 +0200 Subject: [PATCH 153/183] Update `devDependencies` to fix linting errors # Conflicts: # package.json --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 5b71db4e4..8f5c17d09 100644 --- a/package.json +++ b/package.json @@ -54,13 +54,14 @@ "simple-get": "^3.0.3" }, "devDependencies": { - "@types/node": "^10.12.18", + "@types/node": "^14.11.10", "assert-rejects": "^1.0.0", - "dtslint": "^0.5.3", + "dtslint": "^4.0.4", "express": "^4.17.1", "mocha": "^7.1.1", "pixelmatch": "^5.1.0", - "standard": "^14.3.3" + "standard": "^14.3.3", + "typescript": "^4.0.3" }, "engines": { "node": ">=6" From d7db3bf206132685ae5f5f26b76dc29fd1103d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 19:42:06 +0200 Subject: [PATCH 154/183] Update `devDependencies` to fix linting errors # Conflicts: # package.json # Conflicts: # package.json --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index fb998196d..127169b30 100644 --- a/package.json +++ b/package.json @@ -53,13 +53,14 @@ "simple-get": "^3.1.0" }, "devDependencies": { - "@types/node": "^13.9.2", + "@types/node": "^14.11.10", "assert-rejects": "^1.0.0", - "dtslint": "^3.3.0", + "dtslint": "^4.0.4", "express": "^4.17.1", "mocha": "^7.1.1", "pixelmatch": "^5.1.0", - "standard": "^14.3.3" + "standard": "^14.3.3", + "typescript": "^4.0.3" }, "engines": { "node": ">=6" From 6c0eefc9e0deac1c016199e534752464fbf31272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 19:48:30 +0200 Subject: [PATCH 155/183] Fix `standard.js` linting --- test/public/tests.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/public/tests.js b/test/public/tests.js index 31ee6aaca..ef7b5a614 100644 --- a/test/public/tests.js +++ b/test/public/tests.js @@ -585,7 +585,7 @@ tests['createRadialGradient()'] = function (ctx) { ctx.fillRect(0, 0, 150, 150) } -tests['globalAlpha'] = function (ctx) { +tests.globalAlpha = function (ctx) { ctx.globalAlpha = 0.5 ctx.fillStyle = 'rgba(0,0,0,0.5)' ctx.strokeRect(0, 0, 50, 50) @@ -618,7 +618,7 @@ tests['globalAlpha 2'] = function (ctx) { } } -tests['fillStyle'] = function (ctx) { +tests.fillStyle = function (ctx) { for (var i = 0; i < 6; i++) { for (var j = 0; j < 6; j++) { ctx.fillStyle = 'rgb(' + Math.floor(255 - 42.5 * i) + ',' + Math.floor(255 - 42.5 * j) + ',0)' @@ -627,7 +627,7 @@ tests['fillStyle'] = function (ctx) { } } -tests['strokeStyle'] = function (ctx) { +tests.strokeStyle = function (ctx) { for (var i = 0; i < 6; i++) { for (var j = 0; j < 6; j++) { ctx.strokeStyle = 'rgb(0,' + Math.floor(255 - 42.5 * i) + ',' + @@ -662,7 +662,7 @@ tests['floating point coordinates'] = function (ctx) { ctx.stroke() } -tests['lineWidth'] = function (ctx) { +tests.lineWidth = function (ctx) { for (var i = 0; i < 10; i++) { ctx.lineWidth = 1 + i ctx.beginPath() @@ -718,7 +718,7 @@ tests['lineCap default'] = function (ctx) { ctx.stroke() } -tests['lineCap'] = function (ctx) { +tests.lineCap = function (ctx) { ctx.beginPath() ctx.lineWidth = 10.0 ctx.lineCap = 'round' @@ -728,7 +728,7 @@ tests['lineCap'] = function (ctx) { ctx.stroke() } -tests['lineJoin'] = function (ctx) { +tests.lineJoin = function (ctx) { ctx.beginPath() ctx.lineWidth = 10.0 ctx.lineJoin = 'round' @@ -738,7 +738,7 @@ tests['lineJoin'] = function (ctx) { ctx.stroke() } -tests['states'] = function (ctx) { +tests.states = function (ctx) { ctx.save() ctx.rect(50, 50, 100, 100) ctx.stroke() @@ -1325,7 +1325,7 @@ tests['known bug #416'] = function (ctx, done) { img1.src = imageSrc('existing.png') } -tests['shadowBlur'] = function (ctx) { +tests.shadowBlur = function (ctx) { ctx.fillRect(150, 10, 20, 20) ctx.lineTo(20, 5) @@ -1351,7 +1351,7 @@ tests['shadowBlur'] = function (ctx) { ctx.fillRect(150, 150, 20, 20) } -tests['shadowColor'] = function (ctx) { +tests.shadowColor = function (ctx) { ctx.fillRect(150, 10, 20, 20) ctx.lineTo(20, 5) @@ -2249,7 +2249,7 @@ tests['putImageData() png data 3'] = function (ctx, done) { img.src = imageSrc('state.png') } -tests['setLineDash'] = function (ctx) { +tests.setLineDash = function (ctx) { ctx.setLineDash([10, 5, 25, 15]) ctx.lineWidth = 14 @@ -2283,7 +2283,7 @@ tests['setLineDash'] = function (ctx) { line([0, 3, 0, 0], 'green') // should be empty } -tests['lineDashOffset'] = function (ctx) { +tests.lineDashOffset = function (ctx) { ctx.setLineDash([10, 5, 25, 15]) ctx.lineWidth = 4 @@ -2310,7 +2310,7 @@ tests['lineDashOffset'] = function (ctx) { line(60, 'orange') line(-Infinity) line(70, 'purple') - line(void 0) + line() line(80, 'black') line(ctx.lineDashOffset + 10) From 01298779e7c1d4eb41c5fdd554a668585ea49c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 20:02:07 +0200 Subject: [PATCH 156/183] Fixed indentation --- shared.gypi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shared.gypi b/shared.gypi index d6aae693b..aa31a41f7 100644 --- a/shared.gypi +++ b/shared.gypi @@ -148,9 +148,9 @@ 'cflags_cc!': ['-fno-exceptions'] }], ['OS=="mac"', { - 'xcode_settings': { - 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES' - } + 'xcode_settings': { + 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES' + } }], ['with_freetype=="true"', { From 6988889d3935b6222d6de954f8670e4a9e31512d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 20:02:52 +0200 Subject: [PATCH 157/183] By-pass shell checking tool on Windows --- binding.gyp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/binding.gyp b/binding.gyp index c46e9fcaf..8728adb22 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,14 +1,21 @@ { - 'variables': - { - 'shared%': ' Date: Sat, 17 Oct 2020 21:17:37 +0200 Subject: [PATCH 158/183] Enable FbDev backend only on Linux --- binding.gyp | 2 +- src/Canvas.cc | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/binding.gyp b/binding.gyp index bc26603f2..65777141e 100644 --- a/binding.gyp +++ b/binding.gyp @@ -145,7 +145,7 @@ 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES' } }], - ['has_FBDev=="true"', + ['OS=="linux" and has_FBDev=="true"', { 'defines': ['HAS_FBDEV'], 'sources': ['src/backend/FBDevBackend.cc'] diff --git a/src/Canvas.cc b/src/Canvas.cc index b84baa8f3..8015c3061 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -26,11 +26,14 @@ #include "JPEGStream.h" #endif -#include "backend/FBDevBackend.h" #include "backend/ImageBackend.h" #include "backend/PdfBackend.h" #include "backend/SvgBackend.h" +#ifdef HAS_FBDEV +#include "backend/FBDevBackend.h" +#endif + #define GENERIC_FACE_ERROR \ "The second argument to registerFont is required, and should be an object " \ "with at least a family (string) and optionally weight (string/number) " \ @@ -103,16 +106,18 @@ NAN_METHOD(Canvas::New) { if (info[1]->IsNumber()) height = Nan::To(info[1]).FromMaybe(0); if (info[2]->IsString()) { - if (0 == strcmp("fbdev", *Nan::Utf8String(info[2]))) { + if (0 == strcmp("pdf", *Nan::Utf8String(info[2]))) + backend = new PdfBackend(width, height); + else if (0 == strcmp("svg", *Nan::Utf8String(info[2]))) + backend = new SvgBackend(width, height); +#ifdef HAS_FBDEV + else if (0 == strcmp("fbdev", *Nan::Utf8String(info[2]))) { if (info[3]->IsString()) backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3])); else backend = new FBDevBackend(width, height); } - else if (0 == strcmp("pdf", *Nan::Utf8String(info[2]))) - backend = new PdfBackend(width, height); - else if (0 == strcmp("svg", *Nan::Utf8String(info[2]))) - backend = new SvgBackend(width, height); +#endif else return Nan::ThrowRangeError("Unknown canvas type"); } @@ -120,10 +125,13 @@ NAN_METHOD(Canvas::New) { backend = new ImageBackend(width, height); } else if (info[0]->IsObject()) { - if (Nan::New(FBDevBackend::constructor)->HasInstance(info[0]) || - Nan::New(ImageBackend::constructor)->HasInstance(info[0]) || + if (Nan::New(ImageBackend::constructor)->HasInstance(info[0]) || Nan::New(PdfBackend::constructor)->HasInstance(info[0]) || - Nan::New(SvgBackend::constructor)->HasInstance(info[0])) { + Nan::New(SvgBackend::constructor)->HasInstance(info[0]) +#ifdef HAS_FBDEV + || Nan::New(FBDevBackend::constructor)->HasInstance(info[0]) +#endif + ) { backend = Nan::ObjectWrap::Unwrap(Nan::To(info[0]).ToLocalChecked()); }else{ return Nan::ThrowTypeError("Invalid arguments"); From 81904df526b2de52b2fab176882cd72109ce62d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 21:24:00 +0200 Subject: [PATCH 159/183] Enable FbDev backend only on Linux # Conflicts: # src/Canvas.cc --- binding.gyp | 2 +- src/Canvas.cc | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/binding.gyp b/binding.gyp index 40fe4814b..841e59ee2 100644 --- a/binding.gyp +++ b/binding.gyp @@ -146,7 +146,7 @@ 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES' } }], - ['has_FBDev=="true"', + ['OS=="linux" and has_FBDev=="true"', { 'defines': ['HAS_FBDEV'], 'sources': ['src/backend/FBDevBackend.cc'] diff --git a/src/Canvas.cc b/src/Canvas.cc index 3b9b2883c..1924be138 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -26,11 +26,14 @@ #include "JPEGStream.h" #endif -#include "backend/FBDevBackend.h" #include "backend/ImageBackend.h" #include "backend/PdfBackend.h" #include "backend/SvgBackend.h" +#ifdef HAS_FBDEV +#include "backend/FBDevBackend.h" +#endif + #define GENERIC_FACE_ERROR \ "The second argument to registerFont is required, and should be an object " \ "with at least a family (string) and optionally weight (string/number) " \ @@ -103,7 +106,12 @@ NAN_METHOD(Canvas::New) { if (info[1]->IsNumber()) height = Nan::To(info[1]).FromMaybe(0); if (info[2]->IsString()) { - if (0 == strcmp("fbdev", *Nan::Utf8String(info[2]))) { + if (0 == strcmp("pdf", *Nan::Utf8String(info[2]))) + backend = new PdfBackend(width, height); + else if (0 == strcmp("svg", *Nan::Utf8String(info[2]))) + backend = new SvgBackend(width, height); +#ifdef HAS_FBDEV + else if (0 == strcmp("fbdev", *Nan::Utf8String(info[2]))) { if (info[3]->IsString()) { if(info[4]->IsBoolean()) { if(info[5]->IsBoolean()) @@ -119,10 +127,7 @@ NAN_METHOD(Canvas::New) { else backend = new FBDevBackend(width, height); } - else if (0 == strcmp("pdf", *Nan::Utf8String(info[2]))) - backend = new PdfBackend(width, height); - else if (0 == strcmp("svg", *Nan::Utf8String(info[2]))) - backend = new SvgBackend(width, height); +#endif else return Nan::ThrowRangeError("Unknown canvas type"); } @@ -130,10 +135,13 @@ NAN_METHOD(Canvas::New) { backend = new ImageBackend(width, height); } else if (info[0]->IsObject()) { - if (Nan::New(FBDevBackend::constructor)->HasInstance(info[0]) || - Nan::New(ImageBackend::constructor)->HasInstance(info[0]) || + if (Nan::New(ImageBackend::constructor)->HasInstance(info[0]) || Nan::New(PdfBackend::constructor)->HasInstance(info[0]) || - Nan::New(SvgBackend::constructor)->HasInstance(info[0])) { + Nan::New(SvgBackend::constructor)->HasInstance(info[0]) +#ifdef HAS_FBDEV + || Nan::New(FBDevBackend::constructor)->HasInstance(info[0]) +#endif + ) { backend = Nan::ObjectWrap::Unwrap(Nan::To(info[0]).ToLocalChecked()); }else{ return Nan::ThrowTypeError("Invalid arguments"); From 2cb428e73f0bffea7125cb2c076f7316330130af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 21:24:00 +0200 Subject: [PATCH 160/183] Enable FbDev backend only on Linux # Conflicts: # src/Canvas.cc --- binding.gyp | 2 +- src/Canvas.cc | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/binding.gyp b/binding.gyp index 40fe4814b..841e59ee2 100644 --- a/binding.gyp +++ b/binding.gyp @@ -146,7 +146,7 @@ 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES' } }], - ['has_FBDev=="true"', + ['OS=="linux" and has_FBDev=="true"', { 'defines': ['HAS_FBDEV'], 'sources': ['src/backend/FBDevBackend.cc'] diff --git a/src/Canvas.cc b/src/Canvas.cc index 3b9b2883c..1924be138 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -26,11 +26,14 @@ #include "JPEGStream.h" #endif -#include "backend/FBDevBackend.h" #include "backend/ImageBackend.h" #include "backend/PdfBackend.h" #include "backend/SvgBackend.h" +#ifdef HAS_FBDEV +#include "backend/FBDevBackend.h" +#endif + #define GENERIC_FACE_ERROR \ "The second argument to registerFont is required, and should be an object " \ "with at least a family (string) and optionally weight (string/number) " \ @@ -103,7 +106,12 @@ NAN_METHOD(Canvas::New) { if (info[1]->IsNumber()) height = Nan::To(info[1]).FromMaybe(0); if (info[2]->IsString()) { - if (0 == strcmp("fbdev", *Nan::Utf8String(info[2]))) { + if (0 == strcmp("pdf", *Nan::Utf8String(info[2]))) + backend = new PdfBackend(width, height); + else if (0 == strcmp("svg", *Nan::Utf8String(info[2]))) + backend = new SvgBackend(width, height); +#ifdef HAS_FBDEV + else if (0 == strcmp("fbdev", *Nan::Utf8String(info[2]))) { if (info[3]->IsString()) { if(info[4]->IsBoolean()) { if(info[5]->IsBoolean()) @@ -119,10 +127,7 @@ NAN_METHOD(Canvas::New) { else backend = new FBDevBackend(width, height); } - else if (0 == strcmp("pdf", *Nan::Utf8String(info[2]))) - backend = new PdfBackend(width, height); - else if (0 == strcmp("svg", *Nan::Utf8String(info[2]))) - backend = new SvgBackend(width, height); +#endif else return Nan::ThrowRangeError("Unknown canvas type"); } @@ -130,10 +135,13 @@ NAN_METHOD(Canvas::New) { backend = new ImageBackend(width, height); } else if (info[0]->IsObject()) { - if (Nan::New(FBDevBackend::constructor)->HasInstance(info[0]) || - Nan::New(ImageBackend::constructor)->HasInstance(info[0]) || + if (Nan::New(ImageBackend::constructor)->HasInstance(info[0]) || Nan::New(PdfBackend::constructor)->HasInstance(info[0]) || - Nan::New(SvgBackend::constructor)->HasInstance(info[0])) { + Nan::New(SvgBackend::constructor)->HasInstance(info[0]) +#ifdef HAS_FBDEV + || Nan::New(FBDevBackend::constructor)->HasInstance(info[0]) +#endif + ) { backend = Nan::ObjectWrap::Unwrap(Nan::To(info[0]).ToLocalChecked()); }else{ return Nan::ThrowTypeError("Invalid arguments"); From fee2521817d44d90c3d5564e816ead006e670270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 21:36:59 +0200 Subject: [PATCH 161/183] Enable FbDev backend only on Linux # Conflicts: # src/Canvas.cc # Conflicts: # binding.gyp # src/Canvas.cc --- canvas.gypi | 2 +- src/Canvas.cc | 34 +++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/canvas.gypi b/canvas.gypi index 77d79eb34..b967ce737 100644 --- a/canvas.gypi +++ b/canvas.gypi @@ -13,7 +13,7 @@ 'cflags!': ['-fno-exceptions'], 'cflags_cc!': ['-fno-exceptions'] }], - ['has_FBDev=="true"', + ['OS=="linux" and has_FBDev=="true"', { 'defines': ['HAS_FBDEV'], 'sources': ['src/backend/FBDevBackend.cc'] diff --git a/src/Canvas.cc b/src/Canvas.cc index 102981ab8..de22a6376 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -26,11 +26,14 @@ #include "JPEGStream.h" #endif -#include "backend/FBDevBackend.h" #include "backend/ImageBackend.h" #include "backend/PdfBackend.h" #include "backend/SvgBackend.h" +#ifdef HAS_FBDEV +#include "backend/FBDevBackend.h" +#endif + #define GENERIC_FACE_ERROR \ "The second argument to registerFont is required, and should be an object " \ "with at least a family (string) and optionally weight (string/number) " \ @@ -107,17 +110,38 @@ NAN_METHOD(Canvas::New) { backend = new PdfBackend(width, height); else if (0 == strcmp("svg", *Nan::Utf8String(info[2]))) backend = new SvgBackend(width, height); +#ifdef HAS_FBDEV + else if (0 == strcmp("fbdev", *Nan::Utf8String(info[2]))) { + if (info[3]->IsString()) { + if(info[4]->IsBoolean()) { + if(info[5]->IsBoolean()) + backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), + Nan::To(info[4]).FromMaybe(0), Nan::To(info[5]).FromMaybe(0)); + else + backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), + Nan::To(info[4]).FromMaybe(0)); + } + else + backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3])); + } + else + backend = new FBDevBackend(width, height); + } +#endif else - backend = new ImageBackend(width, height); + return Nan::ThrowRangeError("Unknown canvas type"); } else backend = new ImageBackend(width, height); } else if (info[0]->IsObject()) { - if (Nan::New(FBDevBackend::constructor)->HasInstance(info[0]) || - Nan::New(ImageBackend::constructor)->HasInstance(info[0]) || + if (Nan::New(ImageBackend::constructor)->HasInstance(info[0]) || Nan::New(PdfBackend::constructor)->HasInstance(info[0]) || - Nan::New(SvgBackend::constructor)->HasInstance(info[0])) { + Nan::New(SvgBackend::constructor)->HasInstance(info[0]) +#ifdef HAS_FBDEV + || Nan::New(FBDevBackend::constructor)->HasInstance(info[0]) +#endif + ) { backend = Nan::ObjectWrap::Unwrap(Nan::To(info[0]).ToLocalChecked()); }else{ return Nan::ThrowTypeError("Invalid arguments"); From 2757d9b0cafaa68eedd9f77174c28d304295d001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 21:44:27 +0200 Subject: [PATCH 162/183] Remove useless `` include --- src/backend/Backend.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index d73cc6680..64158e4e3 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -1,8 +1,8 @@ -#include +#include + #include #include "Backend.h" -#include Backend::Backend(std::string name, int width, int height) From 9daf309725962e9a8b7dab9dbd73aa158dc649a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 21:50:47 +0200 Subject: [PATCH 163/183] Fix 'Canvas#type' test --- test/canvas.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/canvas.test.js b/test/canvas.test.js index b04ce697a..dd59841b5 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -260,8 +260,8 @@ describe('Canvas', function () { assert.equal(canvas.type, 'pdf') var canvas = createCanvas(10, 10, 'svg') assert.equal(canvas.type, 'svg') - var canvas = createCanvas(10, 10, 'hey') - assert.equal(canvas.type, 'image') + + assert.throws(function () { createCanvas(10, 10, 'hey'); }, /RangeError/); }) it('Canvas#getContext("2d")', function () { From a429c00fc70ae02bf4e2d1f4f8fee5b15f8cb30c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 17 Oct 2020 20:02:52 +0200 Subject: [PATCH 164/183] By-pass shell checking tool on Windows --- binding.gyp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/binding.gyp b/binding.gyp index c46e9fcaf..8728adb22 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,14 +1,21 @@ { - 'variables': - { - 'shared%': ' Date: Sat, 17 Oct 2020 22:07:16 +0200 Subject: [PATCH 165/183] Don't check for X11 support on Windows --- canvas.gypi | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/canvas.gypi b/canvas.gypi index b967ce737..5a19b8ced 100644 --- a/canvas.gypi +++ b/canvas.gypi @@ -1,8 +1,7 @@ { 'variables': { - 'has_FBDev%': 'true', - 'has_X11%': ' Date: Sun, 18 Oct 2020 11:09:32 +0200 Subject: [PATCH 166/183] Fixed signature of FbDevBackend --- src/Canvas.cc | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index de22a6376..ebfe43a92 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -111,21 +111,9 @@ NAN_METHOD(Canvas::New) { else if (0 == strcmp("svg", *Nan::Utf8String(info[2]))) backend = new SvgBackend(width, height); #ifdef HAS_FBDEV - else if (0 == strcmp("fbdev", *Nan::Utf8String(info[2]))) { - if (info[3]->IsString()) { - if(info[4]->IsBoolean()) { - if(info[5]->IsBoolean()) - backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), - Nan::To(info[4]).FromMaybe(0), Nan::To(info[5]).FromMaybe(0)); - else - backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3]), - Nan::To(info[4]).FromMaybe(0)); - } - else - backend = new FBDevBackend(width, height, *Nan::Utf8String(info[3])); - } - else - backend = new FBDevBackend(width, height); + else if (0 == strcmp("fbdev", *Nan::Utf8String(info[2])) + && info[3]->IsString()) { + backend = new FBDevBackend(*Nan::Utf8String(info[3])); } #endif else From 79c3b846f6d269592b8e6925fd5058c8a8d58613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Mon, 19 Oct 2020 01:18:54 +0200 Subject: [PATCH 167/183] Remove useless `.gyp` files in benefict of `.gypi` ones --- shared.gyp | 206 -------------------------------- shared.gypi | 16 +-- static.gyp | 33 ------ static/cairo.gyp | 275 ------------------------------------------- static/cairo.gypi | 51 +++++++- static/common.gyp | 41 ------- static/freetype.gyp | 240 ------------------------------------- static/gif.gyp | 22 ---- static/jpeg.gyp | 117 ------------------ static/libpng.gyp | 69 ----------- static/locations.gyp | 11 -- static/pixman.gyp | 60 ---------- static/zlib.gyp | 60 ---------- 13 files changed, 58 insertions(+), 1143 deletions(-) delete mode 100644 shared.gyp delete mode 100644 static.gyp delete mode 100644 static/cairo.gyp delete mode 100644 static/common.gyp delete mode 100644 static/freetype.gyp delete mode 100644 static/gif.gyp delete mode 100644 static/jpeg.gyp delete mode 100644 static/libpng.gyp delete mode 100644 static/locations.gyp delete mode 100644 static/pixman.gyp delete mode 100644 static/zlib.gyp diff --git a/shared.gyp b/shared.gyp deleted file mode 100644 index 6c3d30bd6..000000000 --- a/shared.gyp +++ /dev/null @@ -1,206 +0,0 @@ -{ - 'conditions': - [ - ['OS=="win"', { - 'variables': - { - 'GTK_Root%': 'C:/GTK', # Set the location of GTK all-in-one bundle - 'with_jpeg%': 'false', - 'with_gif%': 'false', - 'variables': { # Nest jpeg_root to evaluate it before with_jpeg - 'jpeg_root%': ' Date: Mon, 19 Oct 2020 01:31:36 +0200 Subject: [PATCH 168/183] Renamed `X11Backend` to `XlibBackend` --- canvas.gypi | 2 +- examples/animated_clock.js | 2 +- examples/simple_x11.js | 2 +- src/Backends.cc | 4 +-- src/backend/{X11Backend.cc => XlibBackend.cc} | 30 +++++++++---------- src/backend/{X11Backend.h => XlibBackend.h} | 16 +++++----- 6 files changed, 28 insertions(+), 28 deletions(-) rename src/backend/{X11Backend.cc => XlibBackend.cc} (58%) rename src/backend/{X11Backend.h => XlibBackend.h} (65%) diff --git a/canvas.gypi b/canvas.gypi index 4eb5f2703..77683cdf9 100644 --- a/canvas.gypi +++ b/canvas.gypi @@ -20,7 +20,7 @@ ['has_X11=="true"', { 'defines': ['HAS_X11'], - 'sources': ['src/backend/X11Backend.cc'], + 'sources': ['src/backend/XlibBackend.cc'], 'libraries': ['-lX11', '-lXrender', '-lXext'] }] ], diff --git a/examples/animated_clock.js b/examples/animated_clock.js index 2e6126e8f..ea0d583c3 100644 --- a/examples/animated_clock.js +++ b/examples/animated_clock.js @@ -1,7 +1,7 @@ var Canvas = require('..') // var backend = new Canvas.backends.FBDevBackend("/dev/fb0"); -var backend = new Canvas.backends.X11Backend(800, 600) +var backend = new Canvas.backends.XlibBackend(800, 600) var canvas = new Canvas(backend) var ctx = canvas.getContext('2d') diff --git a/examples/simple_x11.js b/examples/simple_x11.js index 0cfe2be6d..82fb13f1e 100755 --- a/examples/simple_x11.js +++ b/examples/simple_x11.js @@ -6,7 +6,7 @@ var Canvas = require('..') -var backend = new Canvas.backends.X11Backend(800, 600) +var backend = new Canvas.backends.XlibBackend(800, 600) var canvas = new Canvas(backend) var ctx = canvas.getContext('2d') diff --git a/src/Backends.cc b/src/Backends.cc index be587fd84..ae2c795fc 100644 --- a/src/Backends.cc +++ b/src/Backends.cc @@ -8,7 +8,7 @@ #include "backend/FBDevBackend.h" #endif #ifdef HAS_X11 -#include "backend/X11Backend.h" +#include "backend/XlibBackend.h" #endif using namespace v8; @@ -25,7 +25,7 @@ void Backends::Initialize(Local target) { FBDevBackend::Initialize(obj); #endif #ifdef HAS_X11 - X11Backend::Initialize(obj); + XlibBackend::Initialize(obj); #endif Nan::Set(target, Nan::New("Backends").ToLocalChecked(), obj).Check(); diff --git a/src/backend/X11Backend.cc b/src/backend/XlibBackend.cc similarity index 58% rename from src/backend/X11Backend.cc rename to src/backend/XlibBackend.cc index 2c4714a9a..334f82fc4 100644 --- a/src/backend/X11Backend.cc +++ b/src/backend/XlibBackend.cc @@ -1,13 +1,13 @@ -#include "X11Backend.h" +#include "XlibBackend.h" using namespace v8; -X11Backend::X11Backend(int width, int height) +XlibBackend::XlibBackend(int width, int height) : Backend("x11", width, height) { display = XOpenDisplay(NULL); if(!display) - throw X11BackendException("Can't open display. Is DISPLAY set?\n"); + throw XlibBackendException("Can't open display. Is DISPLAY set?\n"); this->window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, this->width, this->height, 0, 0, BlackPixel(display, 0)); @@ -16,7 +16,7 @@ X11Backend::X11Backend(int width, int height) XMapWindow(display, this->window); } -X11Backend::~X11Backend() +XlibBackend::~XlibBackend() { this->destroySurface(); @@ -24,7 +24,7 @@ X11Backend::~X11Backend() } -cairo_surface_t* X11Backend::createSurface() +cairo_surface_t* XlibBackend::createSurface() { this->surface = cairo_xlib_surface_create(display, this->window, DefaultVisual(display, 0), this->width, this->height); @@ -33,13 +33,13 @@ cairo_surface_t* X11Backend::createSurface() } -void X11Backend::setWidth(int width) +void XlibBackend::setWidth(int width) { XResizeWindow(this->display, this->window, width, this->height); Backend::setWidth(width); } -void X11Backend::setHeight(int height) +void XlibBackend::setHeight(int height) { XResizeWindow(this->display, this->window, this->width, height); @@ -47,27 +47,27 @@ void X11Backend::setHeight(int height) } -Nan::Persistent X11Backend::constructor; +Nan::Persistent XlibBackend::constructor; -void X11Backend::Initialize(Handle target) +void XlibBackend::Initialize(Handle target) { Nan::HandleScope scope; - Local ctor = Nan::New(X11Backend::New); - X11Backend::constructor.Reset(ctor); + Local ctor = Nan::New(XlibBackend::New); + XlibBackend::constructor.Reset(ctor); ctor->InstanceTemplate()->SetInternalFieldCount(1); - ctor->SetClassName(Nan::New("X11Backend").ToLocalChecked()); - target->Set(Nan::New("X11Backend").ToLocalChecked(), ctor->GetFunction()); + ctor->SetClassName(Nan::New("XlibBackend").ToLocalChecked()); + target->Set(Nan::New("XlibBackend").ToLocalChecked(), ctor->GetFunction()); } -NAN_METHOD(X11Backend::New) +NAN_METHOD(XlibBackend::New) { int width = 0; int height = 0; if(info[0]->IsNumber()) width = info[0]->Uint32Value(); if(info[1]->IsNumber()) height = info[1]->Uint32Value(); - X11Backend *backend = new X11Backend(width, height); + XlibBackend *backend = new XlibBackend(width, height); backend->Wrap(info.This()); info.GetReturnValue().Set(info.This()); diff --git a/src/backend/X11Backend.h b/src/backend/XlibBackend.h similarity index 65% rename from src/backend/X11Backend.h rename to src/backend/XlibBackend.h index b4be0cc61..c2f2c2f91 100644 --- a/src/backend/X11Backend.h +++ b/src/backend/XlibBackend.h @@ -1,5 +1,5 @@ -#ifndef __X11_BACKEND_H__ -#define __X11_BACKEND_H__ +#ifndef __XLIB_BACKEND_H__ +#define __XLIB_BACKEND_H__ #include @@ -11,13 +11,13 @@ using namespace std; -class X11Backend : public Backend +class XlibBackend : public Backend { private: Display* display; Window window; - ~X11Backend(); + ~XlibBackend(); cairo_surface_t* createSurface(); void destroySurface(); @@ -26,7 +26,7 @@ class X11Backend : public Backend void setHeight(int height); public: - X11Backend(int width, int height); + XlibBackend(int width, int height); static Nan::Persistent constructor; static void Initialize(v8::Handle target); @@ -34,13 +34,13 @@ class X11Backend : public Backend }; -class X11BackendException : public std::exception { +class XlibBackendException : public std::exception { private: string err_msg; public: - X11BackendException(const string msg) : err_msg(msg) {}; - ~X11BackendException() throw() {}; + XlibBackendException(const string msg) : err_msg(msg) {}; + ~XlibBackendException() throw() {}; const char *what() const throw() { return this->err_msg.c_str(); }; }; From c9af67ee94e4867c83ff0a8d0b520cacb4792bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 20 Oct 2020 10:47:03 +0200 Subject: [PATCH 169/183] Remove warning of unsorted initialization --- src/backend/Backend.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 363a1e72e..0dfbfd0be 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -7,9 +7,9 @@ Backend::Backend(std::string name, int width, int height) : name(name) - , format(CAIRO_FORMAT_INVALID) , width(width) , height(height) + , format(CAIRO_FORMAT_INVALID) {} Backend::~Backend() From aa0c1d293e5f8ad63968834d233e1ba875bfb2a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 20 Oct 2020 18:59:39 +0200 Subject: [PATCH 170/183] Fixed and updated examples --- examples/animated_clock.js | 8 +++++--- examples/simple_fbdev.js | 2 +- examples/simple_x11.js | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) mode change 100644 => 100755 examples/animated_clock.js diff --git a/examples/animated_clock.js b/examples/animated_clock.js old mode 100644 new mode 100755 index ea0d583c3..91855f0a8 --- a/examples/animated_clock.js +++ b/examples/animated_clock.js @@ -1,7 +1,9 @@ -var Canvas = require('..') +#!/usr/bin/env node -// var backend = new Canvas.backends.FBDevBackend("/dev/fb0"); -var backend = new Canvas.backends.XlibBackend(800, 600) +const { backends: { FBDevBackend, XlibBackend }, Canvas } = require('..') + +// var backend = new FBDevBackend("/dev/fb0"); +var backend = new XlibBackend(800, 600) var canvas = new Canvas(backend) var ctx = canvas.getContext('2d') diff --git a/examples/simple_fbdev.js b/examples/simple_fbdev.js index f8b440322..588138451 100755 --- a/examples/simple_fbdev.js +++ b/examples/simple_fbdev.js @@ -32,7 +32,7 @@ ctx.fillRect(0, offsetY, squareSize, squareSize) ctx.fillStyle = '#FFFFFF' ctx.fillRect(offsetX, offsetY, squareSize, squareSize) -console.log('Width: ' + canvas.width + ', Height: ' + canvas.height + +console.log('Width: ' + canvas.width + ', Height: ' + canvas.height + ', ' + 'Pixel format: ' + ctx.pixelFormat) var outPath = join(__dirname, 'rectangle.png') diff --git a/examples/simple_x11.js b/examples/simple_x11.js index 82fb13f1e..680c9200f 100755 --- a/examples/simple_x11.js +++ b/examples/simple_x11.js @@ -4,9 +4,9 @@ * Module dependencies. */ -var Canvas = require('..') +const { backends: { XlibBackend }, Canvas } = require('..') -var backend = new Canvas.backends.XlibBackend(800, 600) +var backend = new XlibBackend(800, 600) var canvas = new Canvas(backend) var ctx = canvas.getContext('2d') From 04234526223fc6a6ad4626b20f77b655cf434173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 20 Oct 2020 19:03:44 +0200 Subject: [PATCH 171/183] Updated and fixed code for `XlibBackend` --- canvas.gypi | 5 ++- src/Backends.h | 2 +- src/backend/XlibBackend.cc | 64 ++++++++++++++++++++-------------- src/backend/XlibBackend.h | 17 +++++---- src/backend/XlibBackendPriv.cc | 49 ++++++++++++++++++++++++++ src/backend/XlibBackendPriv.h | 35 +++++++++++++++++++ 6 files changed, 135 insertions(+), 37 deletions(-) create mode 100644 src/backend/XlibBackendPriv.cc create mode 100644 src/backend/XlibBackendPriv.h diff --git a/canvas.gypi b/canvas.gypi index 77683cdf9..af753b199 100644 --- a/canvas.gypi +++ b/canvas.gypi @@ -20,7 +20,10 @@ ['has_X11=="true"', { 'defines': ['HAS_X11'], - 'sources': ['src/backend/XlibBackend.cc'], + 'sources': [ + 'src/backend/XlibBackend.cc', + 'src/backend/XlibBackendPriv.cc' + ], 'libraries': ['-lX11', '-lXrender', '-lXext'] }] ], diff --git a/src/Backends.h b/src/Backends.h index dbea053ce..f6c48b960 100644 --- a/src/Backends.h +++ b/src/Backends.h @@ -1,9 +1,9 @@ #pragma once -#include "backend/Backend.h" #include #include + class Backends : public Nan::ObjectWrap { public: static void Initialize(v8::Local target); diff --git a/src/backend/XlibBackend.cc b/src/backend/XlibBackend.cc index 334f82fc4..0346b6774 100644 --- a/src/backend/XlibBackend.cc +++ b/src/backend/XlibBackend.cc @@ -1,55 +1,54 @@ #include "XlibBackend.h" -using namespace v8; XlibBackend::XlibBackend(int width, int height) - : Backend("x11", width, height) + : ScreenBackend("xlib", width, height) { - display = XOpenDisplay(NULL); - if(!display) + printf("XlibBackend::XlibBackend %i %i\n", width, height); + if(!xlibBackendPriv.OpenDisplay()) throw XlibBackendException("Can't open display. Is DISPLAY set?\n"); - this->window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, - this->width, this->height, 0, 0, BlackPixel(display, 0)); + xlibBackendPriv.CreateSimpleWindow(this->width, this->height); - XSelectInput(display, this->window, StructureNotifyMask | ExposureMask); - XMapWindow(display, this->window); + xlibBackendPriv.SelectInput(); + xlibBackendPriv.MapWindow(); } XlibBackend::~XlibBackend() { this->destroySurface(); - XCloseDisplay(this->display); + xlibBackendPriv.DestroyWindow(); + xlibBackendPriv.CloseDisplay(); } -cairo_surface_t* XlibBackend::createSurface() +void XlibBackend::createSurface() { - this->surface = cairo_xlib_surface_create(display, this->window, - DefaultVisual(display, 0), this->width, this->height); + destroySurface(); - return this->surface; + this->surface = xlibBackendPriv.cairo_surface_create(width, height); } void XlibBackend::setWidth(int width) { - XResizeWindow(this->display, this->window, width, this->height); + xlibBackendPriv.ResizeWindow(width, this->height); - Backend::setWidth(width); + ScreenBackend::setWidth(width); } + void XlibBackend::setHeight(int height) { - XResizeWindow(this->display, this->window, this->width, height); + xlibBackendPriv.ResizeWindow(this->width, height); - Backend::setHeight(height); + ScreenBackend::setHeight(height); } Nan::Persistent XlibBackend::constructor; -void XlibBackend::Initialize(Handle target) +void XlibBackend::Initialize(Local target) { Nan::HandleScope scope; @@ -57,18 +56,31 @@ void XlibBackend::Initialize(Handle target) XlibBackend::constructor.Reset(ctor); ctor->InstanceTemplate()->SetInternalFieldCount(1); ctor->SetClassName(Nan::New("XlibBackend").ToLocalChecked()); - target->Set(Nan::New("XlibBackend").ToLocalChecked(), ctor->GetFunction()); + + ScreenBackend::Initialize(ctor); + + Nan::Set(target, + Nan::New("XlibBackend").ToLocalChecked(), + Nan::GetFunction(ctor).ToLocalChecked()).Check(); } NAN_METHOD(XlibBackend::New) { - int width = 0; - int height = 0; - if(info[0]->IsNumber()) width = info[0]->Uint32Value(); - if(info[1]->IsNumber()) height = info[1]->Uint32Value(); + // TODO use Backend::init() instead of having duplicated code. Problem is with + // `construct` static function, that use the defalt one instead of ours. + // init(info); + + int width = 0; + int height = 0; + if (info[0]->IsNumber()) width = Nan::To(info[0]).FromMaybe(0); + if (info[1]->IsNumber()) height = Nan::To(info[1]).FromMaybe(0); + + XlibBackend *backend = new XlibBackend(width, height); - XlibBackend *backend = new XlibBackend(width, height); + printf("XlibBackend::New 1 %i %i %i\n", width, height,backend); + backend->Wrap(info.This()); + printf("XlibBackend::New 2 %i %i\n", width, height); - backend->Wrap(info.This()); - info.GetReturnValue().Set(info.This()); + info.GetReturnValue().Set(info.This()); + printf("XlibBackend::New 3 %i %i\n", width, height); } diff --git a/src/backend/XlibBackend.h b/src/backend/XlibBackend.h index c2f2c2f91..34833dd80 100644 --- a/src/backend/XlibBackend.h +++ b/src/backend/XlibBackend.h @@ -1,26 +1,24 @@ #ifndef __XLIB_BACKEND_H__ #define __XLIB_BACKEND_H__ -#include +#include "ScreenBackend.h" -#include +#include -#include "Backend.h" +#include "XlibBackendPriv.h" using namespace std; -class XlibBackend : public Backend +class XlibBackend : public ScreenBackend { private: - Display* display; - Window window; + XlibBackendPriv xlibBackendPriv; ~XlibBackend(); - cairo_surface_t* createSurface(); - void destroySurface(); + void createSurface(); void setWidth(int width); void setHeight(int height); @@ -29,7 +27,7 @@ class XlibBackend : public Backend XlibBackend(int width, int height); static Nan::Persistent constructor; - static void Initialize(v8::Handle target); + static void Initialize(v8::Local target); static NAN_METHOD(New); }; @@ -41,6 +39,7 @@ class XlibBackendException : public std::exception { public: XlibBackendException(const string msg) : err_msg(msg) {}; ~XlibBackendException() throw() {}; + const char *what() const throw() { return this->err_msg.c_str(); }; }; diff --git a/src/backend/XlibBackendPriv.cc b/src/backend/XlibBackendPriv.cc new file mode 100644 index 000000000..4db7b41b9 --- /dev/null +++ b/src/backend/XlibBackendPriv.cc @@ -0,0 +1,49 @@ +#include "XlibBackendPriv.h" + +#include + + +cairo_surface_t* XlibBackendPriv::cairo_surface_create(int width, int height) +{ + return cairo_xlib_surface_create(this->display, this->window, + DefaultVisual(display, 0), width, height); +} + + +void XlibBackendPriv::CloseDisplay() +{ + XCloseDisplay(this->display); +} + +void XlibBackendPriv::CreateSimpleWindow(int width, int height) +{ + this->window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, + width, height, 0, 0, BlackPixel(display, 0)); +} + +void XlibBackendPriv::DestroyWindow() +{ + XDestroyWindow(this->display, this->window); +} + +void XlibBackendPriv::MapWindow() +{ + XMapWindow(this->display, this->window); +} + +void* XlibBackendPriv::OpenDisplay() +{ + this->display = XOpenDisplay(NULL); + + return this->display; +} + +void XlibBackendPriv::ResizeWindow(int width, int height) +{ + XResizeWindow(this->display, this->window, width, height); +} + +void XlibBackendPriv::SelectInput() +{ + XSelectInput(this->display, this->window, StructureNotifyMask | ExposureMask); +} diff --git a/src/backend/XlibBackendPriv.h b/src/backend/XlibBackendPriv.h new file mode 100644 index 000000000..41812034b --- /dev/null +++ b/src/backend/XlibBackendPriv.h @@ -0,0 +1,35 @@ +/** + * Cairo Xlib glue code for `XlibBackend` class + * + * This is needed to fix conflicting declaration between Xlib `GC` (Graphic + * Context) and V8 `GC` (Garbage Collector). This way, all references to Xlib + * are isolated in this class, accesible only by `XlibBackend`. + */ +#pragma once + +#include +#include + +// Extracted from `X11/Xlib.h` +struct _XDisplay; +typedef struct _XDisplay Display; + + +class XlibBackendPriv +{ + friend class XlibBackend; + + private: + Display* display; + Window window; + + cairo_surface_t* cairo_surface_create(int width, int height); + + void CloseDisplay(); + void CreateSimpleWindow(int width, int height); + void DestroyWindow(); + void MapWindow(); + void* OpenDisplay(); + void ResizeWindow(int width, int height); + void SelectInput(); +}; From 18ffbdf649398716afc719775c1d10b9f278209a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 20 Oct 2020 19:04:45 +0200 Subject: [PATCH 172/183] Enable usage of `Xlib` backend --- src/Canvas.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Canvas.cc b/src/Canvas.cc index 96491edf2..5ac403981 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -33,6 +33,9 @@ #ifdef HAS_FBDEV #include "backend/FBDevBackend.h" #endif +#ifdef HAS_X11 +#include "backend/XlibBackend.h" +#endif #define GENERIC_FACE_ERROR \ "The second argument to registerFont is required, and should be an object " \ @@ -127,6 +130,11 @@ NAN_METHOD(Canvas::New) { else backend = new FBDevBackend(width, height); } +#endif +#ifdef HAS_X11 + else if (0 == strcmp("xlib", *Nan::Utf8String(info[2]))) { + backend = new XlibBackend(width, height); + } #endif else return Nan::ThrowRangeError("Unknown canvas type"); @@ -140,6 +148,9 @@ NAN_METHOD(Canvas::New) { Nan::New(SvgBackend::constructor)->HasInstance(info[0]) #ifdef HAS_FBDEV || Nan::New(FBDevBackend::constructor)->HasInstance(info[0]) +#endif +#ifdef HAS_X11 + || Nan::New(XlibBackend::constructor)->HasInstance(info[0]) #endif ) { backend = Nan::ObjectWrap::Unwrap(Nan::To(info[0]).ToLocalChecked()); From ffd38a60eb386c9fb121cfc47222fcc3b83472c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Tue, 20 Oct 2020 19:06:53 +0200 Subject: [PATCH 173/183] Fix linting --- examples/animated_clock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/animated_clock.js b/examples/animated_clock.js index 91855f0a8..fdc077d41 100755 --- a/examples/animated_clock.js +++ b/examples/animated_clock.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -const { backends: { FBDevBackend, XlibBackend }, Canvas } = require('..') +const { backends: { /* FBDevBackend, */ XlibBackend }, Canvas } = require('..') // var backend = new FBDevBackend("/dev/fb0"); var backend = new XlibBackend(800, 600) From 1a79dd65380e768d984b8709d621b68a0d1527ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 24 Oct 2020 17:51:22 +0200 Subject: [PATCH 174/183] Improved npm scripts --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ccfee7500..579f2517e 100644 --- a/package.json +++ b/package.json @@ -23,12 +23,13 @@ "homepage": "https://github.com/Automattic/node-canvas", "repository": "git://github.com/Automattic/node-canvas.git", "scripts": { - "prebenchmark": "node-gyp build", + "build": "node-pre-gyp build", + "prebenchmark": "npm run build", "benchmark": "node benchmarks/run.js", "lint": "standard examples/*.js test/server.js test/public/*.js benchmarks/run.js lib/context2d.js util/has_lib.js browser.js index.js", - "pretest": "npm run lint && node-gyp build", + "pretest": "npm run lint && npm run build", "test": "mocha test/*.test.js", - "pretest-server": "node-gyp build", + "pretest-server": "npm run build", "test-server": "node test/server.js", "install": "node-pre-gyp install --fallback-to-build", "dtslint": "dtslint types" From 63e180f709efd351e2ef925a3704e1e203e1068b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sat, 24 Oct 2020 17:54:45 +0200 Subject: [PATCH 175/183] [XlibBackend] Improve abstraction --- src/backend/XlibBackend.cc | 35 ++++++------------------------ src/backend/XlibBackend.h | 19 +---------------- src/backend/XlibBackendPriv.cc | 39 ++++++++++++---------------------- src/backend/XlibBackendPriv.h | 29 ++++++++++++++++++------- 4 files changed, 42 insertions(+), 80 deletions(-) diff --git a/src/backend/XlibBackend.cc b/src/backend/XlibBackend.cc index 0346b6774..da356980e 100644 --- a/src/backend/XlibBackend.cc +++ b/src/backend/XlibBackend.cc @@ -1,26 +1,10 @@ #include "XlibBackend.h" -XlibBackend::XlibBackend(int width, int height) +XlibBackend::XlibBackend(int width, int height, char *display_name) : ScreenBackend("xlib", width, height) -{ - printf("XlibBackend::XlibBackend %i %i\n", width, height); - if(!xlibBackendPriv.OpenDisplay()) - throw XlibBackendException("Can't open display. Is DISPLAY set?\n"); - - xlibBackendPriv.CreateSimpleWindow(this->width, this->height); - - xlibBackendPriv.SelectInput(); - xlibBackendPriv.MapWindow(); -} - -XlibBackend::~XlibBackend() -{ - this->destroySurface(); - - xlibBackendPriv.DestroyWindow(); - xlibBackendPriv.CloseDisplay(); -} + , xlibBackendPriv(width, height, display_name) +{} void XlibBackend::createSurface() @@ -66,21 +50,16 @@ void XlibBackend::Initialize(Local target) NAN_METHOD(XlibBackend::New) { - // TODO use Backend::init() instead of having duplicated code. Problem is with - // `construct` static function, that use the defalt one instead of ours. - // init(info); - int width = 0; int height = 0; if (info[0]->IsNumber()) width = Nan::To(info[0]).FromMaybe(0); if (info[1]->IsNumber()) height = Nan::To(info[1]).FromMaybe(0); - XlibBackend *backend = new XlibBackend(width, height); + char *display_name = NULL; + if (info[2]->IsString()) display_name = (*Nan::Utf8String(info[2])).c_str(); - printf("XlibBackend::New 1 %i %i %i\n", width, height,backend); - backend->Wrap(info.This()); - printf("XlibBackend::New 2 %i %i\n", width, height); + XlibBackend *backend = new XlibBackend(width, height, display_name); + backend->Wrap(info.This()); info.GetReturnValue().Set(info.This()); - printf("XlibBackend::New 3 %i %i\n", width, height); } diff --git a/src/backend/XlibBackend.h b/src/backend/XlibBackend.h index 34833dd80..490119506 100644 --- a/src/backend/XlibBackend.h +++ b/src/backend/XlibBackend.h @@ -8,23 +8,18 @@ #include "XlibBackendPriv.h" -using namespace std; - - class XlibBackend : public ScreenBackend { private: XlibBackendPriv xlibBackendPriv; - ~XlibBackend(); - void createSurface(); void setWidth(int width); void setHeight(int height); public: - XlibBackend(int width, int height); + XlibBackend(int width, int height, char *display_name = NULL); static Nan::Persistent constructor; static void Initialize(v8::Local target); @@ -32,16 +27,4 @@ class XlibBackend : public ScreenBackend }; -class XlibBackendException : public std::exception { - private: - string err_msg; - - public: - XlibBackendException(const string msg) : err_msg(msg) {}; - ~XlibBackendException() throw() {}; - - const char *what() const throw() { return this->err_msg.c_str(); }; -}; - - #endif diff --git a/src/backend/XlibBackendPriv.cc b/src/backend/XlibBackendPriv.cc index 4db7b41b9..a83f9b666 100644 --- a/src/backend/XlibBackendPriv.cc +++ b/src/backend/XlibBackendPriv.cc @@ -3,47 +3,34 @@ #include -cairo_surface_t* XlibBackendPriv::cairo_surface_create(int width, int height) +XlibBackendPriv::XlibBackendPriv(int width, int height, char *display_name) { - return cairo_xlib_surface_create(this->display, this->window, - DefaultVisual(display, 0), width, height); -} + this->display = XOpenDisplay(display_name); + if(!this->display) + throw XlibBackendException("Can't open display. Is DISPLAY set?\n"); -void XlibBackendPriv::CloseDisplay() -{ - XCloseDisplay(this->display); -} - -void XlibBackendPriv::CreateSimpleWindow(int width, int height) -{ this->window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, width, height, 0, 0, BlackPixel(display, 0)); -} -void XlibBackendPriv::DestroyWindow() -{ - XDestroyWindow(this->display, this->window); + XSelectInput(this->display, this->window, StructureNotifyMask | ExposureMask); + XMapWindow(this->display, this->window); } -void XlibBackendPriv::MapWindow() +void XlibBackendPriv::~XlibBackendPriv() { - XMapWindow(this->display, this->window); + XCloseDisplay(this->display); } -void* XlibBackendPriv::OpenDisplay() -{ - this->display = XOpenDisplay(NULL); - return this->display; +cairo_surface_t* XlibBackendPriv::cairo_surface_create(int width, int height) +{ + return cairo_xlib_surface_create(this->display, this->window, + DefaultVisual(display, 0), width, height); } + void XlibBackendPriv::ResizeWindow(int width, int height) { XResizeWindow(this->display, this->window, width, height); } - -void XlibBackendPriv::SelectInput() -{ - XSelectInput(this->display, this->window, StructureNotifyMask | ExposureMask); -} diff --git a/src/backend/XlibBackendPriv.h b/src/backend/XlibBackendPriv.h index 41812034b..9f5a5e3ec 100644 --- a/src/backend/XlibBackendPriv.h +++ b/src/backend/XlibBackendPriv.h @@ -10,6 +10,10 @@ #include #include + +using namespace std; + + // Extracted from `X11/Xlib.h` struct _XDisplay; typedef struct _XDisplay Display; @@ -20,16 +24,25 @@ class XlibBackendPriv friend class XlibBackend; private: - Display* display; + Display* display = NULL; Window window; + XlibBackendPriv(int width, int height, char *display_name = NULL); + ~XlibBackendPriv(); + cairo_surface_t* cairo_surface_create(int width, int height); - void CloseDisplay(); - void CreateSimpleWindow(int width, int height); - void DestroyWindow(); - void MapWindow(); - void* OpenDisplay(); - void ResizeWindow(int width, int height); - void SelectInput(); + void ResizeWindow(int width, int height); +}; + + +class XlibBackendException : public std::exception { + private: + string err_msg; + + public: + XlibBackendException(const string msg) : err_msg(msg) {}; + ~XlibBackendException() throw() {}; + + const char *what() const throw() { return this->err_msg.c_str(); }; }; From 1358bcc6d56e446ae6bff7c1e8ce8997f519c464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 25 Oct 2020 21:22:37 +0100 Subject: [PATCH 176/183] Change duplication of `destroySurface()` for assertion it was destroyed --- src/backend/FBDevBackend.cc | 2 +- src/backend/XlibBackend.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/FBDevBackend.cc b/src/backend/FBDevBackend.cc index 0a7d6ae18..fa100df1f 100644 --- a/src/backend/FBDevBackend.cc +++ b/src/backend/FBDevBackend.cc @@ -99,7 +99,7 @@ void FBDevBackend::FbDevIoctlHelper(unsigned long request, void* data, void FBDevBackend::createSurface() { - destroySurface(); + assert(!surface); struct fb_var_screeninfo fb_vinfo; diff --git a/src/backend/XlibBackend.cc b/src/backend/XlibBackend.cc index da356980e..50b67853d 100644 --- a/src/backend/XlibBackend.cc +++ b/src/backend/XlibBackend.cc @@ -9,7 +9,7 @@ XlibBackend::XlibBackend(int width, int height, char *display_name) void XlibBackend::createSurface() { - destroySurface(); + assert(!surface); this->surface = xlibBackendPriv.cairo_surface_create(width, height); } From 851661afe23c8f933513e6f8fffd39a201633ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 25 Oct 2020 21:23:11 +0100 Subject: [PATCH 177/183] Fixed setting of DISPLAY name --- src/backend/XlibBackend.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/XlibBackend.cc b/src/backend/XlibBackend.cc index 50b67853d..cd76e19c4 100644 --- a/src/backend/XlibBackend.cc +++ b/src/backend/XlibBackend.cc @@ -55,8 +55,8 @@ NAN_METHOD(XlibBackend::New) if (info[0]->IsNumber()) width = Nan::To(info[0]).FromMaybe(0); if (info[1]->IsNumber()) height = Nan::To(info[1]).FromMaybe(0); - char *display_name = NULL; - if (info[2]->IsString()) display_name = (*Nan::Utf8String(info[2])).c_str(); + char *display_name = nullptr; + if (info[2]->IsString()) display_name = *Nan::Utf8String(info[2]); XlibBackend *backend = new XlibBackend(width, height, display_name); From 412dfde7387f8c4cbbe09bcfc17ab5241ff41b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 25 Oct 2020 21:23:53 +0100 Subject: [PATCH 178/183] Fixed missing definitions --- src/backend/XlibBackendPriv.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/XlibBackendPriv.h b/src/backend/XlibBackendPriv.h index 9f5a5e3ec..880017aa7 100644 --- a/src/backend/XlibBackendPriv.h +++ b/src/backend/XlibBackendPriv.h @@ -7,6 +7,8 @@ */ #pragma once +#include + #include #include @@ -24,10 +26,10 @@ class XlibBackendPriv friend class XlibBackend; private: - Display* display = NULL; + Display* display = nullptr; Window window; - XlibBackendPriv(int width, int height, char *display_name = NULL); + XlibBackendPriv(int width, int height, char *display_name = nullptr); ~XlibBackendPriv(); cairo_surface_t* cairo_surface_create(int width, int height); From 975a0dad33e2dad364e9698dd907603a9c00d1aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 25 Oct 2020 21:24:13 +0100 Subject: [PATCH 179/183] Fixed bad signature of destructor --- src/backend/XlibBackendPriv.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/XlibBackendPriv.cc b/src/backend/XlibBackendPriv.cc index a83f9b666..a485a6bd3 100644 --- a/src/backend/XlibBackendPriv.cc +++ b/src/backend/XlibBackendPriv.cc @@ -17,7 +17,7 @@ XlibBackendPriv::XlibBackendPriv(int width, int height, char *display_name) XMapWindow(this->display, this->window); } -void XlibBackendPriv::~XlibBackendPriv() +XlibBackendPriv::~XlibBackendPriv() { XCloseDisplay(this->display); } From 7db6bc6cee6752690dea0fafd1cfb1b7fa75cc40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 25 Oct 2020 21:25:57 +0100 Subject: [PATCH 180/183] Set window size hints --- src/backend/XlibBackendPriv.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/backend/XlibBackendPriv.cc b/src/backend/XlibBackendPriv.cc index a485a6bd3..80024173c 100644 --- a/src/backend/XlibBackendPriv.cc +++ b/src/backend/XlibBackendPriv.cc @@ -1,6 +1,21 @@ #include "XlibBackendPriv.h" #include +#include +#include + + +void setSizeHints(Display* display, Window window, int width, int height) +{ + XSizeHints* sh = XAllocSizeHints(); + + sh->flags = PMinSize | PMaxSize; + sh->min_width = sh->max_width = width; + sh->min_height = sh->max_height = height; + + XSetWMNormalHints(display, window, sh); + XFree(sh); +} XlibBackendPriv::XlibBackendPriv(int width, int height, char *display_name) @@ -13,6 +28,8 @@ XlibBackendPriv::XlibBackendPriv(int width, int height, char *display_name) this->window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, width, height, 0, 0, BlackPixel(display, 0)); + setSizeHints(this->display, this->window, width, height); + XSelectInput(this->display, this->window, StructureNotifyMask | ExposureMask); XMapWindow(this->display, this->window); } @@ -32,5 +49,7 @@ cairo_surface_t* XlibBackendPriv::cairo_surface_create(int width, int height) void XlibBackendPriv::ResizeWindow(int width, int height) { + setSizeHints(this->display, this->window, width, height); + XResizeWindow(this->display, this->window, width, height); } From 30c41e17df96d182a79660d46fc967292f5c65c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 25 Oct 2020 21:26:45 +0100 Subject: [PATCH 181/183] Remove window Close and Maximize buttons and resize operation --- src/backend/XlibBackendPriv.cc | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/backend/XlibBackendPriv.cc b/src/backend/XlibBackendPriv.cc index 80024173c..3648816a1 100644 --- a/src/backend/XlibBackendPriv.cc +++ b/src/backend/XlibBackendPriv.cc @@ -1,10 +1,49 @@ #include "XlibBackendPriv.h" #include +#include #include #include +// Extracted from Xm/MwmUtil.h +struct MwmHints { + unsigned long flags; + unsigned long functions; + unsigned long decorations; + long input_mode; + unsigned long status; +}; +enum { + MWM_HINTS_FUNCTIONS = (1L << 0), + MWM_HINTS_DECORATIONS = (1L << 1), + + MWM_FUNC_ALL = (1L << 0), + MWM_FUNC_RESIZE = (1L << 1), + MWM_FUNC_MOVE = (1L << 2), + MWM_FUNC_MINIMIZE = (1L << 3), + MWM_FUNC_MAXIMIZE = (1L << 4), + MWM_FUNC_CLOSE = (1L << 5) +}; + + +// We control the window from code, so we try to prevent windows manager to +// close or resize the window. Doing so correctly, would requires us to capture +// the window manager events in a thread loop and update canvas size, but it's +// not clear if canvas size should change or being scaled/zoomed or if it should +// maintain aspect ratio. + +void configWindow(Display* display, Window window) +{ + struct MwmHints hints; + hints.flags = MWM_HINTS_FUNCTIONS; + hints.functions = MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE; + + Atom wm = XInternAtom(display, "_MOTIF_WM_HINTS", False); + XChangeProperty(display, window, wm, XA_ATOM, 32, PropModeReplace, + (unsigned char*)&hints, 5); +} + void setSizeHints(Display* display, Window window, int width, int height) { XSizeHints* sh = XAllocSizeHints(); @@ -28,6 +67,7 @@ XlibBackendPriv::XlibBackendPriv(int width, int height, char *display_name) this->window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, width, height, 0, 0, BlackPixel(display, 0)); + configWindow(this->display, this->window); setSizeHints(this->display, this->window, width, height); XSelectInput(this->display, this->window, StructureNotifyMask | ExposureMask); From 8a459734db1b75a910cb24e5bca25262011045a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro=20=27piranna?= Date: Sun, 25 Oct 2020 21:26:56 +0100 Subject: [PATCH 182/183] Updated dependencies --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 579f2517e..22d434158 100644 --- a/package.json +++ b/package.json @@ -50,18 +50,18 @@ ], "types": "types/index.d.ts", "dependencies": { - "nan": "^2.14.0", + "nan": "^2.14.2", "node-pre-gyp": "^0.15.0", - "simple-get": "^3.1.0" + "simple-get": "^4.0.0" }, "devDependencies": { - "@types/node": "^14.11.10", + "@types/node": "^14.14.2", "assert-rejects": "^1.0.0", "dtslint": "^4.0.4", "express": "^4.17.1", - "mocha": "^7.1.1", - "pixelmatch": "^5.1.0", - "standard": "^14.3.3", + "mocha": "^8.2.0", + "pixelmatch": "^5.2.1", + "standard": "^15.0.0", "typescript": "^4.0.3" }, "engines": { From e3efd6800ba5b44c210868de10bc11f30910ac8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s-Combarro?= Date: Fri, 6 Nov 2020 17:22:09 +0100 Subject: [PATCH 183/183] Updated Win32 backend (WiP) --- .vscode/c_cpp_properties.json | 21 +++++ .vscode/settings.json | 5 ++ src/backend/Win32Backend.cc | 146 ++++++++++++++++++++++++++++++++++ src/backend/Win32Backend.h | 47 +++++++++++ 4 files changed, 219 insertions(+) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json create mode 100644 src/backend/Win32Backend.cc create mode 100644 src/backend/Win32Backend.h diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 000000000..05730e8bd --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,21 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "windowsSdkVersion": "10.0.18362.0", + "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "msvc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..4b8990287 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "*.rh": "cpp" + } +} \ No newline at end of file diff --git a/src/backend/Win32Backend.cc b/src/backend/Win32Backend.cc new file mode 100644 index 000000000..d4f0b35f4 --- /dev/null +++ b/src/backend/Win32Backend.cc @@ -0,0 +1,146 @@ +#include "Win32Backend.h" + +using namespace v8; + + +UINT style = WS_BORDER | WS_CAPTION | WS_MINIMIZEBOX | WS_OVERLAPPED; + + +void adjustWindowRect(LPRECT pRect, int width, int height) +{ + pRect->left = CW_USEDEFAULT; + pRect->top = CW_USEDEFAULT; + pRect->right = width; + pRect->bottom = height; + + if(!AdjustWindowRect(pRect, style, FALSE)) + { + std::ostringstream o; + o << "cannot adjust window rect"; + throw Win32BackendException(o.str()); + }; +} + + +Win32Backend::Win32Backend(int width, int height) + : ScreenBackend("win32", width, height) +{ + RECT rect; + + adjustWindowRect(&rect, width, height); + + this->window = CreateWindow('', '', style, + rect.left, rect.top, rect.right, rect.bottom, + NULL, NULL, NULL, NULL + ); + + if(!this->window) + { + std::ostringstream o; + o << "cannot create the window"; + throw Win32BackendException(o.str()); + }; + + // Disable window close button + IntPtr menuHandle = GetSystemMenu(this->window, FALSE); + + if(EnableMenuItem(menuHandle, SC_CLOSE | SC_MOVE | SC_SIZE, + MF_BYCOMMAND | MF_DISABLED | MF_GRAYED) == -1) + { + std::ostringstream o; + o << "cannot enable menu item"; + throw Win32BackendException(o.str()); + }; + + if(!DestroyMenu(menuHandle)) + { + std::ostringstream o; + o << "cannot destroy menu handler"; + throw Win32BackendException(o.str()); + }; +} + +Win32Backend::~Win32Backend() +{ + if(!DestroyWindow(this->window)) + { + std::ostringstream o; + o << "cannot destroy the window"; + throw Win32BackendException(o.str()); + }; +} + + +void Win32Backend::createSurface() +{ + assert(!surface); + + this->surface = cairo_win32_surface_create(hdc); +} + + +void Win32Backend::setWidth(int width) +{ + RECT rect; + + adjustWindowRect(&rect, width, height); + + if(!SetWindowPos(this->window, HWND_TOP, 0, 0, rect.right, rect.bottom, + SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER)) + { + std::ostringstream o; + o << "cannot set width \"" << width << "\""; + throw Win32BackendException(o.str()); + }; + + ScreenBackend::setWidth(width); +} + +void Win32Backend::setHeight(int height) +{ + RECT rect; + + adjustWindowRect(&rect, width, height); + + if(!SetWindowPos(this->window, HWND_TOP, 0, 0, rect.right, rect.bottom, + SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER)) + { + std::ostringstream o; + o << "cannot set height \"" << height << "\""; + throw Win32BackendException(o.str()); + }; + + ScreenBackend::setHeight(height); +} + + +Nan::Persistent Win32Backend::constructor; + +void Win32Backend::Initialize(Handle target) +{ + Nan::HandleScope scope; + + Local ctor = Nan::New(Win32Backend::New); + Win32Backend::constructor.Reset(ctor); + ctor->InstanceTemplate()->SetInternalFieldCount(1); + ctor->SetClassName(Nan::New("Win32Backend").ToLocalChecked()); + + ScreenBackend::Initialize(ctor); + + Nan::Set(target, + Nan::New("Win32Backend").ToLocalChecked(), + Nan::GetFunction(ctor).ToLocalChecked()).Check(); +} + +NAN_METHOD(Win32Backend::New) +{ + int width = 0; + int height = 0; + if(info[0]->IsNumber()) width = info[0]->Uint32Value(); + if(info[1]->IsNumber()) height = info[1]->Uint32Value(); + + Win32Backend* backend = new Win32Backend(width, height); + + backend->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); +} diff --git a/src/backend/Win32Backend.h b/src/backend/Win32Backend.h new file mode 100644 index 000000000..bec96f1d3 --- /dev/null +++ b/src/backend/Win32Backend.h @@ -0,0 +1,47 @@ +#ifndef __WIN32_BACKEND_H__ +#define __WIN32_BACKEND_H__ + +#include + +#include + +#include "ScreenBackend.h" + + +using namespace std; + + +class Win32Backend : public ScreenBackend +{ + private: + HWND window; + + ~Win32Backend(); + + void createSurface(); + + void setWidth(int width); + void setHeight(int height); + + public: + Win32Backend(int width, int height); + + static Nan::Persistent constructor; + static void Initialize(v8::Handle target); + static NAN_METHOD(New); +}; + + +class Win32BackendException : public std::exception +{ + private: + string err_msg; + + public: + Win32BackendException(const string msg) : err_msg(msg) {}; + ~Win32BackendException() throw() {}; + + const char *what() const throw() { return this->err_msg.c_str(); }; +}; + +#endif