1111#include < cstring>
1212#include < cctype>
1313#include < ctime>
14- #include < glib.h>
1514#include " PNG.h"
1615#include < sstream>
1716#include < stdlib.h>
1817#include < string>
1918#include < unordered_set>
2019#include " Util.h"
2120#include < vector>
22- #include " node_buffer.h"
2321#include " FontParser.h"
24-
25- #ifdef HAVE_JPEG
2622#include " JPEGStream.h"
27- #endif
2823
2924#define CAIRO_MAX_SIZE 32767
3025
@@ -44,9 +39,7 @@ Canvas::Initialize(Napi::Env& env, Napi::Object& exports) {
4439 InstanceMethod<&Canvas::ToBuffer>(" toBuffer" , napi_default_method),
4540 InstanceMethod<&Canvas::StreamPNGSync>(" streamPNGSync" , napi_default_method),
4641 InstanceMethod<&Canvas::StreamPDFSync>(" streamPDFSync" , napi_default_method),
47- #ifdef HAVE_JPEG
4842 InstanceMethod<&Canvas::StreamJPEGSync>(" streamJPEGSync" , napi_default_method),
49- #endif
5043 InstanceAccessor<&Canvas::GetType>(" type" , napi_default_jsproperty),
5144 InstanceAccessor<&Canvas::GetStride>(" stride" , napi_default_jsproperty),
5245 InstanceAccessor<&Canvas::GetWidth, &Canvas::SetWidth>(" width" , napi_default_jsproperty),
@@ -212,13 +205,11 @@ Canvas::ToPngBufferAsync(Closure* base) {
212205 closure);
213206}
214207
215- #ifdef HAVE_JPEG
216208void
217209Canvas::ToJpegBufferAsync (Closure* base) {
218210 JpegClosure* closure = static_cast <JpegClosure*>(base);
219211 write_to_jpeg_buffer (closure->canvas ->ensureSurface (), closure);
220212}
221- #endif
222213
223214static void
224215parsePNGArgs (Napi::Value arg, PngClosure& pngargs) {
@@ -263,7 +254,6 @@ parsePNGArgs(Napi::Value arg, PngClosure& pngargs) {
263254 }
264255}
265256
266- #ifdef HAVE_JPEG
267257static void parseJPEGArgs (Napi::Value arg, JpegClosure& jpegargs) {
268258 // "If Type(quality) is not Number, or if quality is outside that range, the
269259 // user agent must use its default quality value, as if the quality argument
@@ -295,9 +285,6 @@ static void parseJPEGArgs(Napi::Value arg, JpegClosure& jpegargs) {
295285 }
296286 }
297287}
298- #endif
299-
300- #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 16, 0)
301288
302289static inline void setPdfMetaStr (cairo_surface_t * surf, Napi::Object opts,
303290 cairo_pdf_metadata_t t, const char * propName) {
@@ -331,8 +318,6 @@ static void setPdfMetadata(Canvas* canvas, Napi::Object opts) {
331318 setPdfMetaDate (surf, opts, CAIRO_PDF_METADATA_MOD_DATE, " modDate" );
332319}
333320
334- #endif // CAIRO 16+
335-
336321/*
337322 * Converts/encodes data to a Buffer. Async when a callback function is passed.
338323
@@ -368,11 +353,9 @@ Canvas::ToBuffer(const Napi::CallbackInfo& info) {
368353 // mime type may be present, but it's not checked
369354 PdfSvgClosure* closure = static_cast <PdfSvgClosure*>(_closure);
370355 if (isPDF ()) {
371- #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 16, 0)
372356 if (info[1 ].IsObject ()) { // toBuffer("application/pdf", config)
373357 setPdfMetadata (this , info[1 ].As <Napi::Object>());
374358 }
375- #endif // CAIRO 16+
376359 }
377360
378361 cairo_surface_t *surf = ensureSurface ();
@@ -391,10 +374,6 @@ Canvas::ToBuffer(const Napi::CallbackInfo& info) {
391374 if (info[0 ].StrictEquals (Napi::String::New (env, " raw" ))) {
392375 cairo_surface_t *surface = ensureSurface ();
393376 cairo_surface_flush (surface);
394- if (nBytes () > node::Buffer::kMaxLength ) {
395- Napi::Error::New (env, " Data exceeds maximum buffer length." ).ThrowAsJavaScriptException ();
396- return env.Undefined ();
397- }
398377 return Napi::Buffer<uint8_t >::Copy (env, cairo_image_surface_get_data (surface), nBytes ());
399378 }
400379
@@ -455,7 +434,6 @@ Canvas::ToBuffer(const Napi::CallbackInfo& info) {
455434 return env.Undefined ();
456435 }
457436
458- #ifdef HAVE_JPEG
459437 // Sync JPEG
460438 Napi::Value jpegStr = Napi::String::New (env, " image/jpeg" );
461439 if (info[0 ].StrictEquals (jpegStr)) {
@@ -491,7 +469,6 @@ Canvas::ToBuffer(const Napi::CallbackInfo& info) {
491469 worker->Queue ();
492470 return env.Undefined ();
493471 }
494- #endif
495472
496473 return env.Undefined ();
497474}
@@ -596,11 +573,9 @@ Canvas::StreamPDFSync(const Napi::CallbackInfo& info) {
596573 return ;
597574 }
598575
599- #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 16, 0)
600576 if (info[1 ].IsObject ()) {
601577 setPdfMetadata (this , info[1 ].As <Napi::Object>());
602578 }
603- #endif
604579
605580 cairo_surface_finish (ensureSurface ());
606581
@@ -626,7 +601,6 @@ Canvas::StreamPDFSync(const Napi::CallbackInfo& info) {
626601 * Stream JPEG data synchronously.
627602 */
628603
629- #ifdef HAVE_JPEG
630604static uint32_t getSafeBufSize (Canvas* canvas) {
631605 // Don't allow the buffer size to exceed the size of the canvas (#674)
632606 // TODO not sure if this is really correct, but it fixed #674
@@ -647,7 +621,6 @@ Canvas::StreamJPEGSync(const Napi::CallbackInfo& info) {
647621 uint32_t bufsize = getSafeBufSize (this );
648622 write_to_jpeg_stream (ensureSurface (), bufsize, &closure);
649623}
650- #endif
651624
652625char *
653626str_value (Napi::Maybe<Napi::Value> maybe, const char *fallback, bool can_be_number) {
@@ -708,10 +681,8 @@ Canvas::approxBytesPerPixel() {
708681 case CAIRO_FORMAT_ARGB32:
709682 case CAIRO_FORMAT_RGB24:
710683 return 4 ;
711- #ifdef CAIRO_FORMAT_RGB30
712684 case CAIRO_FORMAT_RGB30:
713685 return 3 ;
714- #endif
715686 case CAIRO_FORMAT_RGB16_565:
716687 return 2 ;
717688 case CAIRO_FORMAT_A8:
0 commit comments