@shqld/canvas 2.11.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.
- package/Readme.md +600 -0
- package/binding.gyp +230 -0
- package/browser.js +35 -0
- package/index.js +94 -0
- package/lib/DOMMatrix.js +620 -0
- package/lib/bindings.js +80 -0
- package/lib/canvas.js +113 -0
- package/lib/context2d.js +14 -0
- package/lib/image.js +96 -0
- package/lib/jpegstream.js +41 -0
- package/lib/parse-font.js +101 -0
- package/lib/pattern.js +17 -0
- package/lib/pdfstream.js +35 -0
- package/lib/pngstream.js +42 -0
- package/package.json +71 -0
- package/scripts/install.js +24 -0
- package/src/Backends.cc +18 -0
- package/src/Backends.h +10 -0
- package/src/Canvas.cc +965 -0
- package/src/Canvas.h +96 -0
- package/src/CanvasError.h +23 -0
- package/src/CanvasGradient.cc +123 -0
- package/src/CanvasGradient.h +22 -0
- package/src/CanvasPattern.cc +136 -0
- package/src/CanvasPattern.h +37 -0
- package/src/CanvasRenderingContext2d.cc +3360 -0
- package/src/CanvasRenderingContext2d.h +225 -0
- package/src/Image.cc +1434 -0
- package/src/Image.h +127 -0
- package/src/ImageData.cc +146 -0
- package/src/ImageData.h +27 -0
- package/src/JPEGStream.h +167 -0
- package/src/PNG.h +292 -0
- package/src/Point.h +11 -0
- package/src/Util.h +9 -0
- package/src/backend/Backend.cc +112 -0
- package/src/backend/Backend.h +69 -0
- package/src/backend/ImageBackend.cc +74 -0
- package/src/backend/ImageBackend.h +26 -0
- package/src/backend/PdfBackend.cc +53 -0
- package/src/backend/PdfBackend.h +24 -0
- package/src/backend/SvgBackend.cc +61 -0
- package/src/backend/SvgBackend.h +24 -0
- package/src/bmp/BMPParser.cc +457 -0
- package/src/bmp/BMPParser.h +60 -0
- package/src/bmp/LICENSE.md +24 -0
- package/src/closure.cc +26 -0
- package/src/closure.h +81 -0
- package/src/color.cc +779 -0
- package/src/color.h +30 -0
- package/src/dll_visibility.h +20 -0
- package/src/init.cc +94 -0
- package/src/register_font.cc +408 -0
- package/src/register_font.h +7 -0
- package/types/index.d.ts +484 -0
- package/util/has_lib.js +119 -0
- package/util/win_jpeg_lookup.js +21 -0
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
// TypeScript Version: 3.0
|
|
2
|
+
|
|
3
|
+
import { Readable } from 'stream'
|
|
4
|
+
|
|
5
|
+
export interface PngConfig {
|
|
6
|
+
/** Specifies the ZLIB compression level. Defaults to 6. */
|
|
7
|
+
compressionLevel?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
|
8
|
+
/**
|
|
9
|
+
* Any bitwise combination of `PNG_FILTER_NONE`, `PNG_FILTER_SUB`,
|
|
10
|
+
* `PNG_FILTER_UP`, `PNG_FILTER_AVG` and `PNG_FILTER_PATETH`; or one of
|
|
11
|
+
* `PNG_ALL_FILTERS` or `PNG_NO_FILTERS` (all are properties of the canvas
|
|
12
|
+
* instance). These specify which filters *may* be used by libpng. During
|
|
13
|
+
* encoding, libpng will select the best filter from this list of allowed
|
|
14
|
+
* filters. Defaults to `canvas.PNG_ALL_FILTERS`.
|
|
15
|
+
*/
|
|
16
|
+
filters?: number
|
|
17
|
+
/**
|
|
18
|
+
* _For creating indexed PNGs._ The palette of colors. Entries should be in
|
|
19
|
+
* RGBA order.
|
|
20
|
+
*/
|
|
21
|
+
palette?: Uint8ClampedArray
|
|
22
|
+
/**
|
|
23
|
+
* _For creating indexed PNGs._ The index of the background color. Defaults
|
|
24
|
+
* to 0.
|
|
25
|
+
*/
|
|
26
|
+
backgroundIndex?: number
|
|
27
|
+
/** pixels per inch */
|
|
28
|
+
resolution?: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface JpegConfig {
|
|
32
|
+
/** Specifies the quality, between 0 and 1. Defaults to 0.75. */
|
|
33
|
+
quality?: number
|
|
34
|
+
/** Enables progressive encoding. Defaults to `false`. */
|
|
35
|
+
progressive?: boolean
|
|
36
|
+
/** Enables 2x2 chroma subsampling. Defaults to `true`. */
|
|
37
|
+
chromaSubsampling?: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface PdfConfig {
|
|
41
|
+
title?: string
|
|
42
|
+
author?: string
|
|
43
|
+
subject?: string
|
|
44
|
+
keywords?: string
|
|
45
|
+
creator?: string
|
|
46
|
+
creationDate?: Date
|
|
47
|
+
modDate?: Date
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface NodeCanvasRenderingContext2DSettings {
|
|
51
|
+
alpha?: boolean
|
|
52
|
+
pixelFormat?: 'RGBA32' | 'RGB24' | 'A8' | 'RGB16_565' | 'A1' | 'RGB30'
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class Canvas {
|
|
56
|
+
width: number
|
|
57
|
+
height: number
|
|
58
|
+
|
|
59
|
+
/** _Non standard._ The type of the canvas. */
|
|
60
|
+
readonly type: 'image'|'pdf'|'svg'
|
|
61
|
+
|
|
62
|
+
/** _Non standard._ Getter. The stride used by the canvas. */
|
|
63
|
+
readonly stride: number;
|
|
64
|
+
|
|
65
|
+
/** Constant used in PNG encoding methods. */
|
|
66
|
+
readonly PNG_NO_FILTERS: number
|
|
67
|
+
/** Constant used in PNG encoding methods. */
|
|
68
|
+
readonly PNG_ALL_FILTERS: number
|
|
69
|
+
/** Constant used in PNG encoding methods. */
|
|
70
|
+
readonly PNG_FILTER_NONE: number
|
|
71
|
+
/** Constant used in PNG encoding methods. */
|
|
72
|
+
readonly PNG_FILTER_SUB: number
|
|
73
|
+
/** Constant used in PNG encoding methods. */
|
|
74
|
+
readonly PNG_FILTER_UP: number
|
|
75
|
+
/** Constant used in PNG encoding methods. */
|
|
76
|
+
readonly PNG_FILTER_AVG: number
|
|
77
|
+
/** Constant used in PNG encoding methods. */
|
|
78
|
+
readonly PNG_FILTER_PAETH: number
|
|
79
|
+
|
|
80
|
+
constructor(width: number, height: number, type?: 'image'|'pdf'|'svg')
|
|
81
|
+
|
|
82
|
+
getContext(contextId: '2d', contextAttributes?: NodeCanvasRenderingContext2DSettings): CanvasRenderingContext2D
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* For image canvases, encodes the canvas as a PNG. For PDF canvases,
|
|
86
|
+
* encodes the canvas as a PDF. For SVG canvases, encodes the canvas as an
|
|
87
|
+
* SVG.
|
|
88
|
+
*/
|
|
89
|
+
toBuffer(cb: (err: Error|null, result: Buffer) => void): void
|
|
90
|
+
toBuffer(cb: (err: Error|null, result: Buffer) => void, mimeType: 'image/png', config?: PngConfig): void
|
|
91
|
+
toBuffer(cb: (err: Error|null, result: Buffer) => void, mimeType: 'image/jpeg', config?: JpegConfig): void
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* For image canvases, encodes the canvas as a PNG. For PDF canvases,
|
|
95
|
+
* encodes the canvas as a PDF. For SVG canvases, encodes the canvas as an
|
|
96
|
+
* SVG.
|
|
97
|
+
*/
|
|
98
|
+
toBuffer(): Buffer
|
|
99
|
+
toBuffer(mimeType: 'image/png', config?: PngConfig): Buffer
|
|
100
|
+
toBuffer(mimeType: 'image/jpeg', config?: JpegConfig): Buffer
|
|
101
|
+
toBuffer(mimeType: 'application/pdf', config?: PdfConfig): Buffer
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Returns the unencoded pixel data, top-to-bottom. On little-endian (most)
|
|
105
|
+
* systems, the array will be ordered BGRA; on big-endian systems, it will
|
|
106
|
+
* be ARGB.
|
|
107
|
+
*/
|
|
108
|
+
toBuffer(mimeType: 'raw'): Buffer
|
|
109
|
+
|
|
110
|
+
createPNGStream(config?: PngConfig): PNGStream
|
|
111
|
+
createJPEGStream(config?: JpegConfig): JPEGStream
|
|
112
|
+
createPDFStream(config?: PdfConfig): PDFStream
|
|
113
|
+
|
|
114
|
+
/** Defaults to PNG image. */
|
|
115
|
+
toDataURL(): string
|
|
116
|
+
toDataURL(mimeType: 'image/png'): string
|
|
117
|
+
toDataURL(mimeType: 'image/jpeg', quality?: number): string
|
|
118
|
+
/** _Non-standard._ Defaults to PNG image. */
|
|
119
|
+
toDataURL(cb: (err: Error|null, result: string) => void): void
|
|
120
|
+
/** _Non-standard._ */
|
|
121
|
+
toDataURL(mimeType: 'image/png', cb: (err: Error|null, result: string) => void): void
|
|
122
|
+
/** _Non-standard._ */
|
|
123
|
+
toDataURL(mimeType: 'image/jpeg', cb: (err: Error|null, result: string) => void): void
|
|
124
|
+
/** _Non-standard._ */
|
|
125
|
+
toDataURL(mimeType: 'image/jpeg', config: JpegConfig, cb: (err: Error|null, result: string) => void): void
|
|
126
|
+
/** _Non-standard._ */
|
|
127
|
+
toDataURL(mimeType: 'image/jpeg', quality: number, cb: (err: Error|null, result: string) => void): void
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface TextMetrics {
|
|
131
|
+
readonly actualBoundingBoxAscent: number;
|
|
132
|
+
readonly actualBoundingBoxDescent: number;
|
|
133
|
+
readonly actualBoundingBoxLeft: number;
|
|
134
|
+
readonly actualBoundingBoxRight: number;
|
|
135
|
+
readonly fontBoundingBoxAscent: number;
|
|
136
|
+
readonly fontBoundingBoxDescent: number;
|
|
137
|
+
readonly width: number;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export type CanvasFillRule = 'evenodd' | 'nonzero';
|
|
141
|
+
|
|
142
|
+
export type GlobalCompositeOperation =
|
|
143
|
+
| 'clear'
|
|
144
|
+
| 'copy'
|
|
145
|
+
| 'destination'
|
|
146
|
+
| 'source-over'
|
|
147
|
+
| 'destination-over'
|
|
148
|
+
| 'source-in'
|
|
149
|
+
| 'destination-in'
|
|
150
|
+
| 'source-out'
|
|
151
|
+
| 'destination-out'
|
|
152
|
+
| 'source-atop'
|
|
153
|
+
| 'destination-atop'
|
|
154
|
+
| 'xor'
|
|
155
|
+
| 'lighter'
|
|
156
|
+
| 'normal'
|
|
157
|
+
| 'multiply'
|
|
158
|
+
| 'screen'
|
|
159
|
+
| 'overlay'
|
|
160
|
+
| 'darken'
|
|
161
|
+
| 'lighten'
|
|
162
|
+
| 'color-dodge'
|
|
163
|
+
| 'color-burn'
|
|
164
|
+
| 'hard-light'
|
|
165
|
+
| 'soft-light'
|
|
166
|
+
| 'difference'
|
|
167
|
+
| 'exclusion'
|
|
168
|
+
| 'hue'
|
|
169
|
+
| 'saturation'
|
|
170
|
+
| 'color'
|
|
171
|
+
| 'luminosity'
|
|
172
|
+
| 'saturate';
|
|
173
|
+
|
|
174
|
+
export type CanvasLineCap = 'butt' | 'round' | 'square';
|
|
175
|
+
|
|
176
|
+
export type CanvasLineJoin = 'bevel' | 'miter' | 'round';
|
|
177
|
+
|
|
178
|
+
export type CanvasTextBaseline = 'alphabetic' | 'bottom' | 'hanging' | 'ideographic' | 'middle' | 'top';
|
|
179
|
+
|
|
180
|
+
export type CanvasTextAlign = 'center' | 'end' | 'left' | 'right' | 'start';
|
|
181
|
+
|
|
182
|
+
export class CanvasRenderingContext2D {
|
|
183
|
+
drawImage(image: Canvas|Image, dx: number, dy: number): void
|
|
184
|
+
drawImage(image: Canvas|Image, dx: number, dy: number, dw: number, dh: number): void
|
|
185
|
+
drawImage(image: Canvas|Image, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void
|
|
186
|
+
putImageData(imagedata: ImageData, dx: number, dy: number): void;
|
|
187
|
+
putImageData(imagedata: ImageData, dx: number, dy: number, dirtyX: number, dirtyY: number, dirtyWidth: number, dirtyHeight: number): void;
|
|
188
|
+
getImageData(sx: number, sy: number, sw: number, sh: number): ImageData;
|
|
189
|
+
createImageData(sw: number, sh: number): ImageData;
|
|
190
|
+
createImageData(imagedata: ImageData): ImageData;
|
|
191
|
+
/**
|
|
192
|
+
* For PDF canvases, adds another page. If width and/or height are omitted,
|
|
193
|
+
* the canvas's initial size is used.
|
|
194
|
+
*/
|
|
195
|
+
addPage(width?: number, height?: number): void
|
|
196
|
+
save(): void;
|
|
197
|
+
restore(): void;
|
|
198
|
+
rotate(angle: number): void;
|
|
199
|
+
translate(x: number, y: number): void;
|
|
200
|
+
transform(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
201
|
+
getTransform(): DOMMatrix;
|
|
202
|
+
resetTransform(): void;
|
|
203
|
+
setTransform(transform?: DOMMatrix): void;
|
|
204
|
+
isPointInPath(x: number, y: number, fillRule?: CanvasFillRule): boolean;
|
|
205
|
+
scale(x: number, y: number): void;
|
|
206
|
+
clip(fillRule?: CanvasFillRule): void;
|
|
207
|
+
fill(fillRule?: CanvasFillRule): void;
|
|
208
|
+
stroke(): void;
|
|
209
|
+
fillText(text: string, x: number, y: number, maxWidth?: number): void;
|
|
210
|
+
strokeText(text: string, x: number, y: number, maxWidth?: number): void;
|
|
211
|
+
fillRect(x: number, y: number, w: number, h: number): void;
|
|
212
|
+
strokeRect(x: number, y: number, w: number, h: number): void;
|
|
213
|
+
clearRect(x: number, y: number, w: number, h: number): void;
|
|
214
|
+
rect(x: number, y: number, w: number, h: number): void;
|
|
215
|
+
roundRect(x: number, y: number, w: number, h: number, radii?: number | number[]): void;
|
|
216
|
+
measureText(text: string): TextMetrics;
|
|
217
|
+
moveTo(x: number, y: number): void;
|
|
218
|
+
lineTo(x: number, y: number): void;
|
|
219
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
|
|
220
|
+
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
|
|
221
|
+
beginPath(): void;
|
|
222
|
+
closePath(): void;
|
|
223
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void;
|
|
224
|
+
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
|
|
225
|
+
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void;
|
|
226
|
+
setLineDash(segments: number[]): void;
|
|
227
|
+
getLineDash(): number[];
|
|
228
|
+
createPattern(image: Canvas|Image, repetition: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat' | '' | null): CanvasPattern
|
|
229
|
+
createLinearGradient(x0: number, y0: number, x1: number, y1: number): CanvasGradient;
|
|
230
|
+
createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): CanvasGradient;
|
|
231
|
+
/**
|
|
232
|
+
* _Non-standard_. Defaults to 'good'. Affects pattern (gradient, image,
|
|
233
|
+
* etc.) rendering quality.
|
|
234
|
+
*/
|
|
235
|
+
patternQuality: 'fast' | 'good' | 'best' | 'nearest' | 'bilinear'
|
|
236
|
+
imageSmoothingEnabled: boolean;
|
|
237
|
+
globalCompositeOperation: GlobalCompositeOperation;
|
|
238
|
+
globalAlpha: number;
|
|
239
|
+
shadowColor: string;
|
|
240
|
+
miterLimit: number;
|
|
241
|
+
lineWidth: number;
|
|
242
|
+
lineCap: CanvasLineCap;
|
|
243
|
+
lineJoin: CanvasLineJoin;
|
|
244
|
+
lineDashOffset: number;
|
|
245
|
+
shadowOffsetX: number;
|
|
246
|
+
shadowOffsetY: number;
|
|
247
|
+
shadowBlur: number;
|
|
248
|
+
/** _Non-standard_. Sets the antialiasing mode. */
|
|
249
|
+
antialias: 'default' | 'gray' | 'none' | 'subpixel'
|
|
250
|
+
/**
|
|
251
|
+
* Defaults to 'path'. The effect depends on the canvas type:
|
|
252
|
+
*
|
|
253
|
+
* * **Standard (image)** `'glyph'` and `'path'` both result in rasterized
|
|
254
|
+
* text. Glyph mode is faster than path, but may result in lower-quality
|
|
255
|
+
* text, especially when rotated or translated.
|
|
256
|
+
*
|
|
257
|
+
* * **PDF** `'glyph'` will embed text instead of paths into the PDF. This
|
|
258
|
+
* is faster to encode, faster to open with PDF viewers, yields a smaller
|
|
259
|
+
* file size and makes the text selectable. The subset of the font needed
|
|
260
|
+
* to render the glyphs will be embedded in the PDF. This is usually the
|
|
261
|
+
* mode you want to use with PDF canvases.
|
|
262
|
+
*
|
|
263
|
+
* * **SVG** glyph does not cause `<text>` elements to be produced as one
|
|
264
|
+
* might expect ([cairo bug](https://gitlab.freedesktop.org/cairo/cairo/issues/253)).
|
|
265
|
+
* Rather, glyph will create a `<defs>` section with a `<symbol>` for each
|
|
266
|
+
* glyph, then those glyphs be reused via `<use>` elements. `'path'` mode
|
|
267
|
+
* creates a `<path>` element for each text string. glyph mode is faster
|
|
268
|
+
* and yields a smaller file size.
|
|
269
|
+
*
|
|
270
|
+
* In glyph mode, `ctx.strokeText()` and `ctx.fillText()` behave the same
|
|
271
|
+
* (aside from using the stroke and fill style, respectively).
|
|
272
|
+
*/
|
|
273
|
+
textDrawingMode: 'path' | 'glyph'
|
|
274
|
+
/**
|
|
275
|
+
* _Non-standard_. Defaults to 'good'. Like `patternQuality`, but applies to
|
|
276
|
+
* transformations affecting more than just patterns.
|
|
277
|
+
*/
|
|
278
|
+
quality: 'fast' | 'good' | 'best' | 'nearest' | 'bilinear'
|
|
279
|
+
/** Returns or sets a `DOMMatrix` for the current transformation matrix. */
|
|
280
|
+
currentTransform: DOMMatrix
|
|
281
|
+
fillStyle: string | CanvasGradient | CanvasPattern;
|
|
282
|
+
strokeStyle: string | CanvasGradient | CanvasPattern;
|
|
283
|
+
font: string;
|
|
284
|
+
textBaseline: CanvasTextBaseline;
|
|
285
|
+
textAlign: CanvasTextAlign;
|
|
286
|
+
canvas: Canvas;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export class CanvasGradient {
|
|
290
|
+
addColorStop(offset: number, color: string): void;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export class CanvasPattern {
|
|
294
|
+
setTransform(transform?: DOMMatrix): void;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// This does not extend HTMLImageElement because there are dozens of inherited
|
|
298
|
+
// methods and properties that we do not provide.
|
|
299
|
+
export class Image {
|
|
300
|
+
/** Track image data */
|
|
301
|
+
static readonly MODE_IMAGE: number
|
|
302
|
+
/** Track MIME data */
|
|
303
|
+
static readonly MODE_MIME: number
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The URL, `data:` URI or local file path of the image to be loaded, or a
|
|
307
|
+
* Buffer instance containing an encoded image.
|
|
308
|
+
*/
|
|
309
|
+
src: string | Buffer
|
|
310
|
+
/** Retrieves whether the object is fully loaded. */
|
|
311
|
+
readonly complete: boolean
|
|
312
|
+
/** Sets or retrieves the height of the image. */
|
|
313
|
+
height: number
|
|
314
|
+
/** Sets or retrieves the width of the image. */
|
|
315
|
+
width: number
|
|
316
|
+
|
|
317
|
+
/** The original height of the image resource before sizing. */
|
|
318
|
+
readonly naturalHeight: number
|
|
319
|
+
/** The original width of the image resource before sizing. */
|
|
320
|
+
readonly naturalWidth: number
|
|
321
|
+
/**
|
|
322
|
+
* Applies to JPEG images drawn to PDF canvases only. Setting
|
|
323
|
+
* `img.dataMode = Image.MODE_MIME` or `Image.MODE_MIME|Image.MODE_IMAGE`
|
|
324
|
+
* enables image MIME data tracking. When MIME data is tracked, PDF canvases
|
|
325
|
+
* can embed JPEGs directly into the output, rather than re-encoding into
|
|
326
|
+
* PNG. This can drastically reduce filesize and speed up rendering.
|
|
327
|
+
*/
|
|
328
|
+
dataMode: number
|
|
329
|
+
|
|
330
|
+
onload: (() => void) | null;
|
|
331
|
+
onerror: ((err: Error) => void) | null;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Creates a Canvas instance. This function works in both Node.js and Web
|
|
336
|
+
* browsers, where there is no Canvas constructor.
|
|
337
|
+
* @param type Optionally specify to create a PDF or SVG canvas. Defaults to an
|
|
338
|
+
* image canvas.
|
|
339
|
+
*/
|
|
340
|
+
export function createCanvas(width: number, height: number, type?: 'pdf'|'svg'): Canvas
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Creates an ImageData instance. This function works in both Node.js and Web
|
|
344
|
+
* browsers.
|
|
345
|
+
* @param data An array containing the pixel representation of the image.
|
|
346
|
+
* @param height If omitted, the height is calculated based on the array's size
|
|
347
|
+
* and `width`.
|
|
348
|
+
*/
|
|
349
|
+
export function createImageData(data: Uint8ClampedArray, width: number, height?: number): ImageData
|
|
350
|
+
/**
|
|
351
|
+
* _Non-standard._ Creates an ImageData instance for an alternative pixel
|
|
352
|
+
* format, such as RGB16_565
|
|
353
|
+
* @param data An array containing the pixel representation of the image.
|
|
354
|
+
* @param height If omitted, the height is calculated based on the array's size
|
|
355
|
+
* and `width`.
|
|
356
|
+
*/
|
|
357
|
+
export function createImageData(data: Uint16Array, width: number, height?: number): ImageData
|
|
358
|
+
/**
|
|
359
|
+
* Creates an ImageData instance. This function works in both Node.js and Web
|
|
360
|
+
* browsers.
|
|
361
|
+
*/
|
|
362
|
+
export function createImageData(width: number, height: number): ImageData
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Convenience function for loading an image with a Promise interface. This
|
|
366
|
+
* function works in both Node.js and Web browsers; however, the `src` must be
|
|
367
|
+
* a string in Web browsers (it can only be a Buffer in Node.js).
|
|
368
|
+
* @param src URL, `data: ` URI or (Node.js only) a local file path or Buffer
|
|
369
|
+
* instance.
|
|
370
|
+
*/
|
|
371
|
+
export function loadImage(src: string|Buffer, options?: any): Promise<Image>
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Registers a font that is not installed as a system font. This must be used
|
|
375
|
+
* before creating Canvas instances.
|
|
376
|
+
* @param path Path to local font file.
|
|
377
|
+
* @param fontFace Description of the font face, corresponding to CSS properties
|
|
378
|
+
* used in `@font-face` rules.
|
|
379
|
+
*/
|
|
380
|
+
export function registerFont(path: string, fontFace: {family: string, weight?: string, style?: string}): void
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Unloads all fonts
|
|
384
|
+
*/
|
|
385
|
+
export function deregisterAllFonts(): void;
|
|
386
|
+
|
|
387
|
+
/** This class must not be constructed directly; use `canvas.createPNGStream()`. */
|
|
388
|
+
export class PNGStream extends Readable {}
|
|
389
|
+
/** This class must not be constructed directly; use `canvas.createJPEGStream()`. */
|
|
390
|
+
export class JPEGStream extends Readable {}
|
|
391
|
+
/** This class must not be constructed directly; use `canvas.createPDFStream()`. */
|
|
392
|
+
export class PDFStream extends Readable {}
|
|
393
|
+
|
|
394
|
+
export class DOMPoint {
|
|
395
|
+
w: number;
|
|
396
|
+
x: number;
|
|
397
|
+
y: number;
|
|
398
|
+
z: number;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export class DOMMatrix {
|
|
402
|
+
constructor(init: string | number[]);
|
|
403
|
+
toString(): string;
|
|
404
|
+
multiply(other?: DOMMatrix): DOMMatrix;
|
|
405
|
+
multiplySelf(other?: DOMMatrix): DOMMatrix;
|
|
406
|
+
preMultiplySelf(other?: DOMMatrix): DOMMatrix;
|
|
407
|
+
translate(tx?: number, ty?: number, tz?: number): DOMMatrix;
|
|
408
|
+
translateSelf(tx?: number, ty?: number, tz?: number): DOMMatrix;
|
|
409
|
+
scale(scaleX?: number, scaleY?: number, scaleZ?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
|
|
410
|
+
scale3d(scale?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
|
|
411
|
+
scale3dSelf(scale?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
|
|
412
|
+
scaleSelf(scaleX?: number, scaleY?: number, scaleZ?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
|
|
413
|
+
rotateFromVector(x?: number, y?: number): DOMMatrix;
|
|
414
|
+
rotateFromVectorSelf(x?: number, y?: number): DOMMatrix;
|
|
415
|
+
rotate(rotX?: number, rotY?: number, rotZ?: number): DOMMatrix;
|
|
416
|
+
rotateSelf(rotX?: number, rotY?: number, rotZ?: number): DOMMatrix;
|
|
417
|
+
rotateAxisAngle(x?: number, y?: number, z?: number, angle?: number): DOMMatrix;
|
|
418
|
+
rotateAxisAngleSelf(x?: number, y?: number, z?: number, angle?: number): DOMMatrix;
|
|
419
|
+
skewX(sx?: number): DOMMatrix;
|
|
420
|
+
skewXSelf(sx?: number): DOMMatrix;
|
|
421
|
+
skewY(sy?: number): DOMMatrix;
|
|
422
|
+
skewYSelf(sy?: number): DOMMatrix;
|
|
423
|
+
flipX(): DOMMatrix;
|
|
424
|
+
flipY(): DOMMatrix;
|
|
425
|
+
inverse(): DOMMatrix;
|
|
426
|
+
invertSelf(): DOMMatrix;
|
|
427
|
+
setMatrixValue(transformList: string): DOMMatrix;
|
|
428
|
+
transformPoint(point?: DOMPoint): DOMPoint;
|
|
429
|
+
toFloat32Array(): Float32Array;
|
|
430
|
+
toFloat64Array(): Float64Array;
|
|
431
|
+
readonly is2D: boolean;
|
|
432
|
+
readonly isIdentity: boolean;
|
|
433
|
+
a: number;
|
|
434
|
+
b: number;
|
|
435
|
+
c: number;
|
|
436
|
+
d: number;
|
|
437
|
+
e: number;
|
|
438
|
+
f: number;
|
|
439
|
+
m11: number;
|
|
440
|
+
m12: number;
|
|
441
|
+
m13: number;
|
|
442
|
+
m14: number;
|
|
443
|
+
m21: number;
|
|
444
|
+
m22: number;
|
|
445
|
+
m23: number;
|
|
446
|
+
m24: number;
|
|
447
|
+
m31: number;
|
|
448
|
+
m32: number;
|
|
449
|
+
m33: number;
|
|
450
|
+
m34: number;
|
|
451
|
+
m41: number;
|
|
452
|
+
m42: number;
|
|
453
|
+
m43: number;
|
|
454
|
+
m44: number;
|
|
455
|
+
static fromMatrix(other: DOMMatrix): DOMMatrix;
|
|
456
|
+
static fromFloat32Array(a: Float32Array): DOMMatrix;
|
|
457
|
+
static fromFloat64Array(a: Float64Array): DOMMatrix;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export class ImageData {
|
|
461
|
+
constructor(sw: number, sh: number);
|
|
462
|
+
constructor(data: Uint8ClampedArray, sw: number, sh?: number);
|
|
463
|
+
readonly data: Uint8ClampedArray;
|
|
464
|
+
readonly height: number;
|
|
465
|
+
readonly width: number;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// This is marked private, but is exported...
|
|
469
|
+
// export function parseFont(description: string): object
|
|
470
|
+
|
|
471
|
+
// Not documented: backends
|
|
472
|
+
|
|
473
|
+
/** Library version. */
|
|
474
|
+
export const version: string
|
|
475
|
+
/** Cairo version. */
|
|
476
|
+
export const cairoVersion: string
|
|
477
|
+
/** jpeglib version, if built with JPEG support. */
|
|
478
|
+
export const jpegVersion: string | undefined
|
|
479
|
+
/** giflib version, if built with GIF support. */
|
|
480
|
+
export const gifVersion: string | undefined
|
|
481
|
+
/** freetype version. */
|
|
482
|
+
export const freetypeVersion: string
|
|
483
|
+
/** rsvg version. */
|
|
484
|
+
export const rsvgVersion: string | undefined
|
package/util/has_lib.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
const query = process.argv[2]
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
const childProcess = require('child_process')
|
|
4
|
+
|
|
5
|
+
const SYSTEM_PATHS = [
|
|
6
|
+
'/lib',
|
|
7
|
+
'/usr/lib',
|
|
8
|
+
'/usr/lib64',
|
|
9
|
+
'/usr/local/lib',
|
|
10
|
+
'/opt/local/lib',
|
|
11
|
+
'/opt/homebrew/lib',
|
|
12
|
+
'/usr/lib/x86_64-linux-gnu',
|
|
13
|
+
'/usr/lib/i386-linux-gnu',
|
|
14
|
+
'/usr/lib/arm-linux-gnueabihf',
|
|
15
|
+
'/usr/lib/arm-linux-gnueabi',
|
|
16
|
+
'/usr/lib/aarch64-linux-gnu'
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Checks for lib using ldconfig if present, or searching SYSTEM_PATHS
|
|
21
|
+
* otherwise.
|
|
22
|
+
* @param {string} lib - library name, e.g. 'jpeg' in 'libjpeg64.so' (see first line)
|
|
23
|
+
* @return {boolean} exists
|
|
24
|
+
*/
|
|
25
|
+
function hasSystemLib (lib) {
|
|
26
|
+
const libName = 'lib' + lib + '.+(so|dylib)'
|
|
27
|
+
const libNameRegex = new RegExp(libName)
|
|
28
|
+
|
|
29
|
+
// Try using ldconfig on linux systems
|
|
30
|
+
if (hasLdconfig()) {
|
|
31
|
+
try {
|
|
32
|
+
if (childProcess.execSync('ldconfig -p 2>/dev/null | grep -E "' + libName + '"').length) {
|
|
33
|
+
return true
|
|
34
|
+
}
|
|
35
|
+
} catch (err) {
|
|
36
|
+
// noop -- proceed to other search methods
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Try checking common library locations
|
|
41
|
+
return SYSTEM_PATHS.some(function (systemPath) {
|
|
42
|
+
try {
|
|
43
|
+
const dirListing = fs.readdirSync(systemPath)
|
|
44
|
+
return dirListing.some(function (file) {
|
|
45
|
+
return libNameRegex.test(file)
|
|
46
|
+
})
|
|
47
|
+
} catch (err) {
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Checks for ldconfig on the path and /sbin
|
|
55
|
+
* @return {boolean} exists
|
|
56
|
+
*/
|
|
57
|
+
function hasLdconfig () {
|
|
58
|
+
try {
|
|
59
|
+
// Add /sbin to path as ldconfig is located there on some systems -- e.g.
|
|
60
|
+
// Debian (and it can still be used by unprivileged users):
|
|
61
|
+
childProcess.execSync('export PATH="$PATH:/sbin"')
|
|
62
|
+
process.env.PATH = '...'
|
|
63
|
+
// execSync throws on nonzero exit
|
|
64
|
+
childProcess.execSync('hash ldconfig 2>/dev/null')
|
|
65
|
+
return true
|
|
66
|
+
} catch (err) {
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Checks for freetype2 with --cflags-only-I
|
|
73
|
+
* @return Boolean exists
|
|
74
|
+
*/
|
|
75
|
+
function hasFreetype () {
|
|
76
|
+
try {
|
|
77
|
+
if (childProcess.execSync('pkg-config cairo --cflags-only-I 2>/dev/null | grep freetype2').length) {
|
|
78
|
+
return true
|
|
79
|
+
}
|
|
80
|
+
} catch (err) {
|
|
81
|
+
// noop
|
|
82
|
+
}
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Checks for lib using pkg-config.
|
|
88
|
+
* @param {string} lib - library name
|
|
89
|
+
* @return {boolean} exists
|
|
90
|
+
*/
|
|
91
|
+
function hasPkgconfigLib (lib) {
|
|
92
|
+
try {
|
|
93
|
+
// execSync throws on nonzero exit
|
|
94
|
+
childProcess.execSync('pkg-config --exists "' + lib + '" 2>/dev/null')
|
|
95
|
+
return true
|
|
96
|
+
} catch (err) {
|
|
97
|
+
return false
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function main (query) {
|
|
102
|
+
switch (query) {
|
|
103
|
+
case 'gif':
|
|
104
|
+
case 'cairo':
|
|
105
|
+
return hasSystemLib(query)
|
|
106
|
+
case 'pango':
|
|
107
|
+
return hasPkgconfigLib(query)
|
|
108
|
+
case 'freetype':
|
|
109
|
+
return hasFreetype()
|
|
110
|
+
case 'jpeg':
|
|
111
|
+
return hasPkgconfigLib('libjpeg')
|
|
112
|
+
case 'rsvg':
|
|
113
|
+
return hasPkgconfigLib('librsvg-2.0')
|
|
114
|
+
default:
|
|
115
|
+
throw new Error('Unknown library: ' + query)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
process.stdout.write(main(query).toString())
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const paths = ['C:/libjpeg-turbo']
|
|
3
|
+
|
|
4
|
+
if (process.arch === 'x64') {
|
|
5
|
+
paths.unshift('C:/libjpeg-turbo64')
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
paths.forEach(function (path) {
|
|
9
|
+
if (exists(path)) {
|
|
10
|
+
process.stdout.write(path)
|
|
11
|
+
process.exit()
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
function exists (path) {
|
|
16
|
+
try {
|
|
17
|
+
return fs.lstatSync(path).isDirectory()
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
}
|