@shqld/canvas 3.2.2-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/Readme.md +654 -0
  2. package/binding.gyp +229 -0
  3. package/browser.js +31 -0
  4. package/index.d.ts +507 -0
  5. package/index.js +94 -0
  6. package/lib/DOMMatrix.js +678 -0
  7. package/lib/bindings.js +113 -0
  8. package/lib/canvas.js +113 -0
  9. package/lib/context2d.js +11 -0
  10. package/lib/image.js +97 -0
  11. package/lib/jpegstream.js +41 -0
  12. package/lib/pattern.js +15 -0
  13. package/lib/pdfstream.js +35 -0
  14. package/lib/pngstream.js +42 -0
  15. package/package.json +77 -0
  16. package/scripts/install.js +19 -0
  17. package/src/Backends.h +9 -0
  18. package/src/Canvas.cc +1026 -0
  19. package/src/Canvas.h +128 -0
  20. package/src/CanvasError.h +37 -0
  21. package/src/CanvasGradient.cc +113 -0
  22. package/src/CanvasGradient.h +20 -0
  23. package/src/CanvasPattern.cc +129 -0
  24. package/src/CanvasPattern.h +33 -0
  25. package/src/CanvasRenderingContext2d.cc +3527 -0
  26. package/src/CanvasRenderingContext2d.h +238 -0
  27. package/src/CharData.h +233 -0
  28. package/src/FontParser.cc +605 -0
  29. package/src/FontParser.h +115 -0
  30. package/src/Image.cc +1719 -0
  31. package/src/Image.h +146 -0
  32. package/src/ImageData.cc +138 -0
  33. package/src/ImageData.h +26 -0
  34. package/src/InstanceData.h +12 -0
  35. package/src/JPEGStream.h +157 -0
  36. package/src/PNG.h +292 -0
  37. package/src/Point.h +11 -0
  38. package/src/Util.h +9 -0
  39. package/src/bmp/BMPParser.cc +459 -0
  40. package/src/bmp/BMPParser.h +60 -0
  41. package/src/bmp/LICENSE.md +24 -0
  42. package/src/closure.cc +52 -0
  43. package/src/closure.h +98 -0
  44. package/src/color.cc +796 -0
  45. package/src/color.h +30 -0
  46. package/src/dll_visibility.h +20 -0
  47. package/src/init.cc +114 -0
  48. package/src/register_font.cc +352 -0
  49. package/src/register_font.h +7 -0
  50. package/util/has_lib.js +119 -0
  51. package/util/win_jpeg_lookup.js +21 -0
package/binding.gyp ADDED
@@ -0,0 +1,229 @@
1
+ {
2
+ 'conditions': [
3
+ ['OS=="win"', {
4
+ 'variables': {
5
+ 'GTK_Root%': 'C:/GTK', # Set the location of GTK all-in-one bundle
6
+ 'with_jpeg%': 'false',
7
+ 'with_gif%': 'false',
8
+ 'with_rsvg%': 'false',
9
+ 'variables': { # Nest jpeg_root to evaluate it before with_jpeg
10
+ 'jpeg_root%': '<!(node ./util/win_jpeg_lookup)'
11
+ },
12
+ 'jpeg_root%': '<(jpeg_root)', # Take value of nested variable
13
+ 'conditions': [
14
+ ['jpeg_root==""', {
15
+ 'with_jpeg%': 'false'
16
+ }, {
17
+ 'with_jpeg%': 'true'
18
+ }]
19
+ ]
20
+ }
21
+ }, { # 'OS!="win"'
22
+ 'variables': {
23
+ 'with_jpeg%': '<!(node ./util/has_lib.js jpeg)',
24
+ 'with_gif%': '<!(node ./util/has_lib.js gif)',
25
+ 'with_rsvg%': '<!(node ./util/has_lib.js rsvg)'
26
+ }
27
+ }]
28
+ ],
29
+ 'targets': [
30
+ {
31
+ 'target_name': 'canvas-postbuild',
32
+ 'dependencies': ['canvas'],
33
+ 'conditions': [
34
+ ['OS=="win"', {
35
+ 'copies': [{
36
+ 'destination': '<(PRODUCT_DIR)',
37
+ 'files': [
38
+ '<(GTK_Root)/bin/zlib1.dll',
39
+ '<(GTK_Root)/bin/libintl-8.dll',
40
+ '<(GTK_Root)/bin/libpng14-14.dll',
41
+ '<(GTK_Root)/bin/libpangocairo-1.0-0.dll',
42
+ '<(GTK_Root)/bin/libpango-1.0-0.dll',
43
+ '<(GTK_Root)/bin/libpangoft2-1.0-0.dll',
44
+ '<(GTK_Root)/bin/libpangowin32-1.0-0.dll',
45
+ '<(GTK_Root)/bin/libcairo-2.dll',
46
+ '<(GTK_Root)/bin/libfontconfig-1.dll',
47
+ '<(GTK_Root)/bin/libfreetype-6.dll',
48
+ '<(GTK_Root)/bin/libglib-2.0-0.dll',
49
+ '<(GTK_Root)/bin/libgobject-2.0-0.dll',
50
+ '<(GTK_Root)/bin/libgmodule-2.0-0.dll',
51
+ '<(GTK_Root)/bin/libgthread-2.0-0.dll',
52
+ '<(GTK_Root)/bin/libexpat-1.dll'
53
+ ]
54
+ }]
55
+ }]
56
+ ]
57
+ },
58
+ {
59
+ 'target_name': 'canvas',
60
+ 'include_dirs': ["<!(node -p \"require('node-addon-api').include_dir\")"],
61
+ 'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS', 'NODE_ADDON_API_ENABLE_MAYBE' ],
62
+ 'sources': [
63
+ 'src/bmp/BMPParser.cc',
64
+ 'src/Canvas.cc',
65
+ 'src/CanvasGradient.cc',
66
+ 'src/CanvasPattern.cc',
67
+ 'src/CanvasRenderingContext2d.cc',
68
+ 'src/closure.cc',
69
+ 'src/color.cc',
70
+ 'src/Image.cc',
71
+ 'src/ImageData.cc',
72
+ 'src/init.cc',
73
+ 'src/register_font.cc',
74
+ 'src/FontParser.cc'
75
+ ],
76
+ 'conditions': [
77
+ ['OS=="win"', {
78
+ 'libraries': [
79
+ '-l<(GTK_Root)/lib/cairo.lib',
80
+ '-l<(GTK_Root)/lib/libpng.lib',
81
+ '-l<(GTK_Root)/lib/pangocairo-1.0.lib',
82
+ '-l<(GTK_Root)/lib/pango-1.0.lib',
83
+ '-l<(GTK_Root)/lib/freetype.lib',
84
+ '-l<(GTK_Root)/lib/glib-2.0.lib',
85
+ '-l<(GTK_Root)/lib/gobject-2.0.lib'
86
+ ],
87
+ 'include_dirs': [
88
+ '<(GTK_Root)/include',
89
+ '<(GTK_Root)/include/cairo',
90
+ '<(GTK_Root)/include/pango-1.0',
91
+ '<(GTK_Root)/include/glib-2.0',
92
+ '<(GTK_Root)/include/freetype2',
93
+ '<(GTK_Root)/lib/glib-2.0/include'
94
+ ],
95
+ 'defines': [
96
+ '_USE_MATH_DEFINES', # for M_PI
97
+ 'NOMINMAX' # allow std::min/max to work
98
+ ],
99
+ 'configurations': {
100
+ 'Debug': {
101
+ 'msvs_settings': {
102
+ 'VCCLCompilerTool': {
103
+ 'WarningLevel': 4,
104
+ 'ExceptionHandling': 1,
105
+ 'DisableSpecificWarnings': [
106
+ 4100, 4611
107
+ ]
108
+ }
109
+ }
110
+ },
111
+ 'Release': {
112
+ 'msvs_settings': {
113
+ 'VCCLCompilerTool': {
114
+ 'WarningLevel': 4,
115
+ 'ExceptionHandling': 1,
116
+ 'DisableSpecificWarnings': [
117
+ 4100, 4611
118
+ ]
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }, { # 'OS!="win"'
124
+ 'libraries': [
125
+ '<!@(pkg-config pixman-1 --libs)',
126
+ '<!@(pkg-config cairo --libs)',
127
+ '<!@(pkg-config libpng --libs)',
128
+ '<!@(pkg-config pangocairo --libs)',
129
+ '<!@(pkg-config freetype2 --libs)'
130
+ ],
131
+ 'include_dirs': [
132
+ '<!@(pkg-config cairo --cflags-only-I | sed s/-I//g)',
133
+ '<!@(pkg-config libpng --cflags-only-I | sed s/-I//g)',
134
+ '<!@(pkg-config pangocairo --cflags-only-I | sed s/-I//g)',
135
+ '<!@(pkg-config freetype2 --cflags-only-I | sed s/-I//g)'
136
+ ],
137
+ 'cflags': ['-Wno-cast-function-type'],
138
+ 'cflags!': ['-fno-exceptions'],
139
+ 'cflags_cc!': ['-fno-exceptions']
140
+ }],
141
+ ['OS=="mac"', {
142
+ 'cflags+': ['-fvisibility=hidden'],
143
+ 'xcode_settings': {
144
+ 'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
145
+ 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
146
+ }
147
+ }],
148
+ ['with_jpeg=="true"', {
149
+ 'defines': [
150
+ 'HAVE_JPEG'
151
+ ],
152
+ 'conditions': [
153
+ ['OS=="win"', {
154
+ 'copies': [{
155
+ 'destination': '<(PRODUCT_DIR)',
156
+ 'files': [
157
+ '<(jpeg_root)/bin/jpeg62.dll',
158
+ ]
159
+ }],
160
+ 'include_dirs': [
161
+ '<(jpeg_root)/include'
162
+ ],
163
+ 'libraries': [
164
+ '-l<(jpeg_root)/lib/jpeg.lib',
165
+ ]
166
+ }, {
167
+ 'include_dirs': [
168
+ '<!@(pkg-config libjpeg --cflags-only-I | sed s/-I//g)'
169
+ ],
170
+ 'libraries': [
171
+ '<!@(pkg-config libjpeg --libs)'
172
+ ]
173
+ }]
174
+ ]
175
+ }],
176
+ ['with_gif=="true"', {
177
+ 'defines': [
178
+ 'HAVE_GIF'
179
+ ],
180
+ 'conditions': [
181
+ ['OS=="win"', {
182
+ 'libraries': [
183
+ '-l<(GTK_Root)/lib/gif.lib'
184
+ ]
185
+ }, {
186
+ 'include_dirs': [
187
+ '/opt/homebrew/include'
188
+ ],
189
+ 'libraries': [
190
+ '-L/opt/homebrew/lib',
191
+ '-lgif'
192
+ ]
193
+ }]
194
+ ]
195
+ }],
196
+ ['with_rsvg=="true"', {
197
+ 'defines': [
198
+ 'HAVE_RSVG'
199
+ ],
200
+ 'conditions': [
201
+ ['OS=="win"', {
202
+ 'copies': [{
203
+ 'destination': '<(PRODUCT_DIR)',
204
+ 'files': [
205
+ '<(GTK_Root)/bin/librsvg-2-2.dll',
206
+ '<(GTK_Root)/bin/libgdk_pixbuf-2.0-0.dll',
207
+ '<(GTK_Root)/bin/libgio-2.0-0.dll',
208
+ '<(GTK_Root)/bin/libcroco-0.6-3.dll',
209
+ '<(GTK_Root)/bin/libgsf-1-114.dll',
210
+ '<(GTK_Root)/bin/libxml2-2.dll'
211
+ ]
212
+ }],
213
+ 'libraries': [
214
+ '-l<(GTK_Root)/lib/librsvg-2-2.lib'
215
+ ]
216
+ }, {
217
+ 'include_dirs': [
218
+ '<!@(pkg-config librsvg-2.0 --cflags-only-I | sed s/-I//g)'
219
+ ],
220
+ 'libraries': [
221
+ '<!@(pkg-config librsvg-2.0 --libs)'
222
+ ]
223
+ }]
224
+ ]
225
+ }]
226
+ ]
227
+ }
228
+ ]
229
+ }
package/browser.js ADDED
@@ -0,0 +1,31 @@
1
+ /* globals document, ImageData */
2
+
3
+ exports.createCanvas = function (width, height) {
4
+ return Object.assign(document.createElement('canvas'), { width: width, height: height })
5
+ }
6
+
7
+ exports.createImageData = function (array, width, height) {
8
+ // Browser implementation of ImageData looks at the number of arguments passed
9
+ switch (arguments.length) {
10
+ case 0: return new ImageData()
11
+ case 1: return new ImageData(array)
12
+ case 2: return new ImageData(array, width)
13
+ default: return new ImageData(array, width, height)
14
+ }
15
+ }
16
+
17
+ exports.loadImage = function (src, options) {
18
+ return new Promise(function (resolve, reject) {
19
+ const image = Object.assign(document.createElement('img'), options)
20
+
21
+ function cleanup () {
22
+ image.onload = null
23
+ image.onerror = null
24
+ }
25
+
26
+ image.onload = function () { cleanup(); resolve(image) }
27
+ image.onerror = function () { cleanup(); reject(new Error('Failed to load the image "' + src + '"')) }
28
+
29
+ image.src = src
30
+ })
31
+ }