@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.
Files changed (57) hide show
  1. package/Readme.md +600 -0
  2. package/binding.gyp +230 -0
  3. package/browser.js +35 -0
  4. package/index.js +94 -0
  5. package/lib/DOMMatrix.js +620 -0
  6. package/lib/bindings.js +80 -0
  7. package/lib/canvas.js +113 -0
  8. package/lib/context2d.js +14 -0
  9. package/lib/image.js +96 -0
  10. package/lib/jpegstream.js +41 -0
  11. package/lib/parse-font.js +101 -0
  12. package/lib/pattern.js +17 -0
  13. package/lib/pdfstream.js +35 -0
  14. package/lib/pngstream.js +42 -0
  15. package/package.json +71 -0
  16. package/scripts/install.js +24 -0
  17. package/src/Backends.cc +18 -0
  18. package/src/Backends.h +10 -0
  19. package/src/Canvas.cc +965 -0
  20. package/src/Canvas.h +96 -0
  21. package/src/CanvasError.h +23 -0
  22. package/src/CanvasGradient.cc +123 -0
  23. package/src/CanvasGradient.h +22 -0
  24. package/src/CanvasPattern.cc +136 -0
  25. package/src/CanvasPattern.h +37 -0
  26. package/src/CanvasRenderingContext2d.cc +3360 -0
  27. package/src/CanvasRenderingContext2d.h +225 -0
  28. package/src/Image.cc +1434 -0
  29. package/src/Image.h +127 -0
  30. package/src/ImageData.cc +146 -0
  31. package/src/ImageData.h +27 -0
  32. package/src/JPEGStream.h +167 -0
  33. package/src/PNG.h +292 -0
  34. package/src/Point.h +11 -0
  35. package/src/Util.h +9 -0
  36. package/src/backend/Backend.cc +112 -0
  37. package/src/backend/Backend.h +69 -0
  38. package/src/backend/ImageBackend.cc +74 -0
  39. package/src/backend/ImageBackend.h +26 -0
  40. package/src/backend/PdfBackend.cc +53 -0
  41. package/src/backend/PdfBackend.h +24 -0
  42. package/src/backend/SvgBackend.cc +61 -0
  43. package/src/backend/SvgBackend.h +24 -0
  44. package/src/bmp/BMPParser.cc +457 -0
  45. package/src/bmp/BMPParser.h +60 -0
  46. package/src/bmp/LICENSE.md +24 -0
  47. package/src/closure.cc +26 -0
  48. package/src/closure.h +81 -0
  49. package/src/color.cc +779 -0
  50. package/src/color.h +30 -0
  51. package/src/dll_visibility.h +20 -0
  52. package/src/init.cc +94 -0
  53. package/src/register_font.cc +408 -0
  54. package/src/register_font.h +7 -0
  55. package/types/index.d.ts +484 -0
  56. package/util/has_lib.js +119 -0
  57. package/util/win_jpeg_lookup.js +21 -0
package/src/closure.h ADDED
@@ -0,0 +1,81 @@
1
+ // Copyright (c) 2010 LearnBoost <tj@learnboost.com>
2
+
3
+ #pragma once
4
+
5
+ #include "Canvas.h"
6
+
7
+ #ifdef HAVE_JPEG
8
+ #include <jpeglib.h>
9
+ #endif
10
+
11
+ #include <nan.h>
12
+ #include <png.h>
13
+ #include <stdint.h> // node < 7 uses libstdc++ on macOS which lacks complete c++11
14
+ #include <vector>
15
+
16
+ #ifndef PAGE_SIZE
17
+ #define PAGE_SIZE 4096
18
+ #endif
19
+
20
+ /*
21
+ * Image encoding closures.
22
+ */
23
+
24
+ struct Closure {
25
+ std::vector<uint8_t> vec;
26
+ Nan::Callback cb;
27
+ Canvas* canvas = nullptr;
28
+ cairo_status_t status = CAIRO_STATUS_SUCCESS;
29
+
30
+ static cairo_status_t writeVec(void *c, const uint8_t *odata, unsigned len) {
31
+ Closure* closure = static_cast<Closure*>(c);
32
+ try {
33
+ closure->vec.insert(closure->vec.end(), odata, odata + len);
34
+ } catch (const std::bad_alloc &) {
35
+ return CAIRO_STATUS_NO_MEMORY;
36
+ }
37
+ return CAIRO_STATUS_SUCCESS;
38
+ }
39
+
40
+ Closure(Canvas* canvas) : canvas(canvas) {};
41
+ };
42
+
43
+ struct PdfSvgClosure : Closure {
44
+ PdfSvgClosure(Canvas* canvas) : Closure(canvas) {};
45
+ };
46
+
47
+ struct PngClosure : Closure {
48
+ uint32_t compressionLevel = 6;
49
+ uint32_t filters = PNG_ALL_FILTERS;
50
+ uint32_t resolution = 0; // 0 = unspecified
51
+ // Indexed PNGs:
52
+ uint32_t nPaletteColors = 0;
53
+ uint8_t* palette = nullptr;
54
+ uint8_t backgroundIndex = 0;
55
+
56
+ PngClosure(Canvas* canvas) : Closure(canvas) {};
57
+ };
58
+
59
+ #ifdef HAVE_JPEG
60
+ struct JpegClosure : Closure {
61
+ uint32_t quality = 75;
62
+ uint32_t chromaSubsampling = 2;
63
+ bool progressive = false;
64
+ jpeg_destination_mgr* jpeg_dest_mgr = nullptr;
65
+
66
+ static void init_destination(j_compress_ptr cinfo);
67
+ static boolean empty_output_buffer(j_compress_ptr cinfo);
68
+ static void term_destination(j_compress_ptr cinfo);
69
+
70
+ JpegClosure(Canvas* canvas) : Closure(canvas) {
71
+ jpeg_dest_mgr = new jpeg_destination_mgr;
72
+ jpeg_dest_mgr->init_destination = init_destination;
73
+ jpeg_dest_mgr->empty_output_buffer = empty_output_buffer;
74
+ jpeg_dest_mgr->term_destination = term_destination;
75
+ };
76
+
77
+ ~JpegClosure() {
78
+ delete jpeg_dest_mgr;
79
+ }
80
+ };
81
+ #endif