From 4212d0ff0783f8d8c6aa52ef29a4a65fe4742ba5 Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Sat, 22 Dec 2018 13:25:58 -0800 Subject: [PATCH 1/6] remove unused variables --- src/CanvasRenderingContext2d.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 62c901413..1c213b0d3 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -1766,7 +1766,6 @@ NAN_GETTER(Context2d::GetFillStyle) { NAN_SETTER(Context2d::SetFillStyle) { Context2d *context = Nan::ObjectWrap::Unwrap(info.This()); - Local ctx = Nan::GetCurrentContext(); if (Nan::New(Gradient::constructor)->HasInstance(value) || Nan::New(Pattern::constructor)->HasInstance(value)) { @@ -1813,8 +1812,6 @@ NAN_GETTER(Context2d::GetStrokeStyle) { NAN_SETTER(Context2d::SetStrokeStyle) { Context2d *context = Nan::ObjectWrap::Unwrap(info.This()); - Isolate *iso = Isolate::GetCurrent(); - Local ctx = Nan::GetCurrentContext(); if (Nan::New(Gradient::constructor)->HasInstance(value) || Nan::New(Pattern::constructor)->HasInstance(value)) { From a6fba37b55986a15dddbfa561eaa5fcd92c1c1f0 Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Sat, 22 Dec 2018 13:47:19 -0800 Subject: [PATCH 2/6] don't use "using namespace" in header files https://stackoverflow.com/questions/5849457/using-namespace-in-c-headers --- src/Canvas.cc | 8 ++++++-- src/Canvas.h | 10 +++------- src/CanvasGradient.cc | 2 ++ src/CanvasGradient.h | 2 +- src/CanvasPattern.cc | 2 ++ src/CanvasPattern.h | 2 +- src/CanvasRenderingContext2d.cc | 2 ++ src/CanvasRenderingContext2d.h | 30 ++++++++++++++---------------- src/Image.cc | 10 ++++++---- src/Image.h | 2 +- src/ImageData.cc | 2 ++ src/ImageData.h | 2 +- src/JPEGStream.h | 10 +++++----- src/backend/Backend.cc | 15 +++++++-------- src/backend/Backend.h | 16 ++++++---------- src/backend/ImageBackend.h | 2 -- src/backend/PdfBackend.h | 2 -- src/backend/SvgBackend.h | 2 -- src/init.cc | 2 ++ 19 files changed, 61 insertions(+), 62 deletions(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index e04494d14..bd5b0fe60 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -9,6 +9,7 @@ #include #include #include +#include // std::min #include #include #include @@ -37,6 +38,9 @@ "with at least a family (string) and optionally weight (string/number) " \ "and style (string)." +using namespace v8; +using namespace std; + Nan::Persistent Canvas::constructor; std::vector font_face_list; @@ -305,7 +309,7 @@ static void parseJPEGArgs(Local arg, JpegClosure& jpegargs) { static uint32_t getSafeBufSize(Canvas* canvas) { // Don't allow the buffer size to exceed the size of the canvas (#674) // TODO not sure if this is really correct, but it fixed #674 - return min(canvas->getWidth() * canvas->getHeight() * 4, static_cast(PAGE_SIZE)); + return std::min(canvas->getWidth() * canvas->getHeight() * 4, static_cast(PAGE_SIZE)); } #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 16, 0) @@ -377,7 +381,7 @@ NAN_METHOD(Canvas::ToBuffer) { Canvas *canvas = Nan::ObjectWrap::Unwrap(info.This()); // Vector canvases, sync only - const string name = canvas->backend()->getName(); + const std::string name = canvas->backend()->getName(); if (name == "pdf" || name == "svg") { // mime type may be present, but it's not checked PdfSvgClosure* closure; diff --git a/src/Canvas.h b/src/Canvas.h index fe97dc5a8..218597300 100644 --- a/src/Canvas.h +++ b/src/Canvas.h @@ -19,10 +19,6 @@ #include "dll_visibility.h" #include "backend/Backend.h" - -using namespace node; -using namespace v8; - /* * Maxmimum states per context. * TODO: remove/resize @@ -48,7 +44,7 @@ class FontFace { class Canvas: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target); static NAN_METHOD(New); static NAN_METHOD(ToBuffer); @@ -62,7 +58,7 @@ class Canvas: public Nan::ObjectWrap { static NAN_METHOD(StreamPDFSync); static NAN_METHOD(StreamJPEGSync); static NAN_METHOD(RegisterFont); - static Local Error(cairo_status_t status); + static v8::Local Error(cairo_status_t status); static void ToPngBufferAsync(uv_work_t *req); static void ToJpegBufferAsync(uv_work_t *req); static void ToBufferAsyncAfter(uv_work_t *req); @@ -82,7 +78,7 @@ class Canvas: public Nan::ObjectWrap { DLL_PUBLIC inline int getHeight() { return backend()->getHeight(); } Canvas(Backend* backend); - void resurface(Local canvas); + void resurface(v8::Local canvas); private: ~Canvas(); diff --git a/src/CanvasGradient.cc b/src/CanvasGradient.cc index 1f493af78..d2669e52c 100644 --- a/src/CanvasGradient.cc +++ b/src/CanvasGradient.cc @@ -9,6 +9,8 @@ #include "Canvas.h" #include "CanvasGradient.h" +using namespace v8; + Nan::Persistent Gradient::constructor; /* diff --git a/src/CanvasGradient.h b/src/CanvasGradient.h index 2459eb60d..09d77bc76 100644 --- a/src/CanvasGradient.h +++ b/src/CanvasGradient.h @@ -12,7 +12,7 @@ class Gradient: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target); static NAN_METHOD(New); static NAN_METHOD(AddColorStop); diff --git a/src/CanvasPattern.cc b/src/CanvasPattern.cc index f37a0028c..f03be63a8 100644 --- a/src/CanvasPattern.cc +++ b/src/CanvasPattern.cc @@ -9,6 +9,8 @@ #include "Image.h" #include "CanvasPattern.h" +using namespace v8; + const cairo_user_data_key_t *pattern_repeat_key; Nan::Persistent Pattern::constructor; diff --git a/src/CanvasPattern.h b/src/CanvasPattern.h index afbd4703e..e60d3faa0 100644 --- a/src/CanvasPattern.h +++ b/src/CanvasPattern.h @@ -25,7 +25,7 @@ extern const cairo_user_data_key_t *pattern_repeat_key; class Pattern: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target); static NAN_METHOD(New); static repeat_type_t get_repeat_type_for_cairo_pattern(cairo_pattern_t *pattern); diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 1c213b0d3..e49697a66 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -24,6 +24,8 @@ #include "backend/ImageBackend.h" #include +using namespace v8; + // Windows doesn't support the C99 names for these #ifdef _MSC_VER #define isnan(x) _isnan(x) diff --git a/src/CanvasRenderingContext2d.h b/src/CanvasRenderingContext2d.h index 421928da6..f3ac29d28 100644 --- a/src/CanvasRenderingContext2d.h +++ b/src/CanvasRenderingContext2d.h @@ -15,8 +15,6 @@ #include "Canvas.h" #include "CanvasGradient.h" -using namespace std; - typedef enum { TEXT_DRAW_PATHS, TEXT_DRAW_GLYPHS @@ -71,9 +69,9 @@ class Context2d: public Nan::ObjectWrap { canvas_state_t *states[CANVAS_MAX_STATES]; canvas_state_t *state; Context2d(Canvas *canvas); - static Nan::Persistent _DOMMatrix; - static Nan::Persistent _parseFont; - static Nan::Persistent constructor; + static Nan::Persistent _DOMMatrix; + static Nan::Persistent _parseFont; + static Nan::Persistent constructor; static void Initialize(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target); static NAN_METHOD(New); static NAN_METHOD(SaveExternalModules); @@ -193,17 +191,17 @@ class Context2d: public Nan::ObjectWrap { private: ~Context2d(); void _resetPersistentHandles(); - Local _getFillColor(); - Local _getStrokeColor(); - void _setFillColor(Local arg); - void _setFillPattern(Local arg); - void _setStrokeColor(Local arg); - void _setStrokePattern(Local arg); - Nan::Persistent _fillStyle; - Nan::Persistent _strokeStyle; - Nan::Persistent _font; - Nan::Persistent _textBaseline; - Nan::Persistent _textAlign; + v8::Local _getFillColor(); + v8::Local _getStrokeColor(); + void _setFillColor(v8::Local arg); + void _setFillPattern(v8::Local arg); + void _setStrokeColor(v8::Local arg); + void _setStrokePattern(v8::Local arg); + Nan::Persistent _fillStyle; + Nan::Persistent _strokeStyle; + Nan::Persistent _font; + Nan::Persistent _textBaseline; + Nan::Persistent _textAlign; Canvas *_canvas; cairo_t *_context; cairo_path_t *_path; diff --git a/src/Image.cc b/src/Image.cc index bf7de79de..12cf0269a 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -40,6 +40,8 @@ typedef struct { uint8_t *buf; } read_closure_t; +using namespace v8; + Nan::Persistent Image::constructor; /* @@ -239,9 +241,9 @@ NAN_METHOD(Image::SetSource){ img->filename = strdup(*src); status = img->load(); // Buffer - } else if (Buffer::HasInstance(value)) { - uint8_t *buf = (uint8_t *) Buffer::Data(Nan::To(value).ToLocalChecked()); - unsigned len = Buffer::Length(Nan::To(value).ToLocalChecked()); + } else if (node::Buffer::HasInstance(value)) { + uint8_t *buf = (uint8_t *) node::Buffer::Data(Nan::To(value).ToLocalChecked()); + unsigned len = node::Buffer::Length(Nan::To(value).ToLocalChecked()); status = img->loadFromBuffer(buf, len); } @@ -1374,7 +1376,7 @@ Image::isSVG(uint8_t *data, unsigned len) { int Image::isBMP(uint8_t *data, unsigned len) { if(len < 2) return false; - string sig = string(1, (char)data[0]) + (char)data[1]; + std::string sig = std::string(1, (char)data[0]) + (char)data[1]; return sig == "BM" || sig == "BA" || sig == "CI" || diff --git a/src/Image.h b/src/Image.h index 8d00b5659..0dd5c7198 100644 --- a/src/Image.h +++ b/src/Image.h @@ -42,7 +42,7 @@ class Image: public Nan::ObjectWrap { char *filename; int width, height; int naturalWidth, naturalHeight; - static Nan::Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target); static NAN_METHOD(New); static NAN_GETTER(GetComplete); diff --git a/src/ImageData.cc b/src/ImageData.cc index 751edfea1..e9e906b7c 100644 --- a/src/ImageData.cc +++ b/src/ImageData.cc @@ -8,6 +8,8 @@ #include "Util.h" #include "ImageData.h" +using namespace v8; + Nan::Persistent ImageData::constructor; /* diff --git a/src/ImageData.h b/src/ImageData.h index 392b1faca..2bda00d48 100644 --- a/src/ImageData.h +++ b/src/ImageData.h @@ -15,7 +15,7 @@ class ImageData: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target); static NAN_METHOD(New); static NAN_GETTER(GetWidth); diff --git a/src/JPEGStream.h b/src/JPEGStream.h index 300b0f2c2..94711de5e 100644 --- a/src/JPEGStream.h +++ b/src/JPEGStream.h @@ -34,10 +34,10 @@ empty_closure_output_buffer(j_compress_ptr cinfo){ Nan::AsyncResource async("canvas:empty_closure_output_buffer"); closure_destination_mgr *dest = (closure_destination_mgr *) cinfo->dest; - Local buf = Nan::NewBuffer((char *)dest->buffer, dest->bufsize).ToLocalChecked(); + v8::Local buf = Nan::NewBuffer((char *)dest->buffer, dest->bufsize).ToLocalChecked(); // emit "data" - Local argv[2] = { + v8::Local argv[2] = { Nan::Null() , buf }; @@ -56,16 +56,16 @@ term_closure_destination(j_compress_ptr cinfo){ closure_destination_mgr *dest = (closure_destination_mgr *) cinfo->dest; /* emit remaining data */ - Local buf = Nan::NewBuffer((char *)dest->buffer, dest->bufsize - dest->pub.free_in_buffer).ToLocalChecked(); + v8::Local buf = Nan::NewBuffer((char *)dest->buffer, dest->bufsize - dest->pub.free_in_buffer).ToLocalChecked(); - Local data_argv[2] = { + v8::Local data_argv[2] = { Nan::Null() , buf }; dest->closure->cb.Call(sizeof data_argv / sizeof *data_argv, data_argv, &async); // emit "end" - Local end_argv[2] = { + v8::Local end_argv[2] = { Nan::Null() , Nan::Null() }; diff --git a/src/backend/Backend.cc b/src/backend/Backend.cc index 66b6af84d..a78fecd5c 100644 --- a/src/backend/Backend.cc +++ b/src/backend/Backend.cc @@ -1,6 +1,7 @@ #include "Backend.h" +#include -Backend::Backend(string name, int width, int height) +Backend::Backend(std::string name, int width, int height) : name(name) , width(width) , height(height) @@ -51,7 +52,7 @@ void Backend::destroySurface() } -string Backend::getName() +std::string Backend::getName() { return name; } @@ -95,7 +96,7 @@ bool Backend::isSurfaceValid(){ BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend, - string operation_name) + std::string operation_name) : backend(backend) , operation_name(operation_name) {}; @@ -104,10 +105,8 @@ BackendOperationNotAvailable::~BackendOperationNotAvailable() throw() {}; const char* BackendOperationNotAvailable::what() const throw() { - std::ostringstream o; + std::string msg = "operation " + this->operation_name + + " not supported by backend " + backend->getName(); - o << "operation " << this->operation_name; - o << " not supported by backend " + backend->getName(); - - return o.str().c_str(); + return msg.c_str(); }; diff --git a/src/backend/Backend.h b/src/backend/Backend.h index f310d9769..15edcf7b3 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -1,9 +1,7 @@ #ifndef __BACKEND_H__ #define __BACKEND_H__ -#include #include -#include #include #include @@ -14,12 +12,10 @@ class Canvas; -using namespace std; - class Backend : public Nan::ObjectWrap { private: - const string name; + const std::string name; const char* error = NULL; protected: @@ -28,7 +24,7 @@ class Backend : public Nan::ObjectWrap cairo_surface_t* surface = nullptr; Canvas* canvas = nullptr; - Backend(string name, int width, int height); + Backend(std::string name, int width, int height); static void init(const Nan::FunctionCallbackInfo &info); static Backend *construct(int width, int height){ return nullptr; } @@ -43,7 +39,7 @@ class Backend : public Nan::ObjectWrap DLL_PUBLIC cairo_surface_t* getSurface(); virtual void destroySurface(); - DLL_PUBLIC string getName(); + DLL_PUBLIC std::string getName(); DLL_PUBLIC int getWidth(); virtual void setWidth(int width); @@ -61,14 +57,14 @@ class Backend : public Nan::ObjectWrap }; -class BackendOperationNotAvailable: public exception +class BackendOperationNotAvailable: public std::exception { private: Backend* backend; - string operation_name; + std::string operation_name; public: - BackendOperationNotAvailable(Backend* backend, string operation_name); + BackendOperationNotAvailable(Backend* backend, std::string operation_name); ~BackendOperationNotAvailable() throw(); const char* what() const throw(); diff --git a/src/backend/ImageBackend.h b/src/backend/ImageBackend.h index 4c002abe4..09464087a 100644 --- a/src/backend/ImageBackend.h +++ b/src/backend/ImageBackend.h @@ -5,8 +5,6 @@ #include "Backend.h" -using namespace std; - class ImageBackend : public Backend { private: diff --git a/src/backend/PdfBackend.h b/src/backend/PdfBackend.h index 2c597a703..8f86b5c45 100644 --- a/src/backend/PdfBackend.h +++ b/src/backend/PdfBackend.h @@ -6,8 +6,6 @@ #include "../closure.h" #include "Backend.h" -using namespace std; - class PdfBackend : public Backend { private: diff --git a/src/backend/SvgBackend.h b/src/backend/SvgBackend.h index b703a3b94..20a53007d 100644 --- a/src/backend/SvgBackend.h +++ b/src/backend/SvgBackend.h @@ -6,8 +6,6 @@ #include "Backend.h" #include "../closure.h" -using namespace std; - class SvgBackend : public Backend { private: diff --git a/src/init.cc b/src/init.cc index 3c2f721cf..b3c6e6896 100644 --- a/src/init.cc +++ b/src/init.cc @@ -31,6 +31,8 @@ #include #include FT_FREETYPE_H +using namespace v8; + // Compatibility with Visual Studio versions prior to VS2015 #if defined(_MSC_VER) && _MSC_VER < 1900 #define snprintf _snprintf From 8da245169d923e2b5a1866cbb294ef3b3e10ac04 Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Sat, 22 Dec 2018 14:33:39 -0800 Subject: [PATCH 3/6] Clean up #includes --- src/Backends.h | 10 +++------- src/Canvas.cc | 34 +++++++++++++++------------------ src/Canvas.h | 23 ++++++---------------- src/CanvasError.h | 5 +---- src/CanvasGradient.cc | 10 +++------- src/CanvasGradient.h | 14 ++++---------- src/CanvasPattern.cc | 8 ++------ src/CanvasPattern.h | 14 ++++---------- src/CanvasRenderingContext2d.cc | 31 +++++++++++++----------------- src/CanvasRenderingContext2d.h | 19 +++++------------- src/Image.cc | 14 +++++--------- src/Image.h | 15 +++++---------- src/ImageData.cc | 8 ++------ src/ImageData.h | 15 +++------------ src/JPEGStream.h | 11 +---------- src/PNG.h | 10 ++++------ src/Point.h | 11 +---------- src/Util.h | 4 +++- src/backend/Backend.h | 15 +++++---------- src/backend/ImageBackend.h | 8 ++------ src/backend/PdfBackend.cc | 3 --- src/backend/PdfBackend.h | 10 +++------- src/backend/SvgBackend.cc | 3 --- src/backend/SvgBackend.h | 8 ++------ src/bmp/BMPParser.cc | 4 ++-- src/bmp/BMPParser.h | 6 ++---- src/closure.h | 16 ++++------------ src/color.cc | 15 ++++++--------- src/color.h | 14 ++------------ src/init.cc | 6 ------ src/register_font.cc | 2 ++ src/register_font.h | 3 ++- 32 files changed, 112 insertions(+), 257 deletions(-) diff --git a/src/Backends.h b/src/Backends.h index 1519883d1..55b663c15 100644 --- a/src/Backends.h +++ b/src/Backends.h @@ -1,14 +1,10 @@ -#ifndef __NODE_BACKENDS_H__ -#define __NODE_BACKENDS_H__ - -#include +#pragma once #include "backend/Backend.h" - +#include +#include class Backends : public Nan::ObjectWrap { public: static void Initialize(v8::Handle target); }; - -#endif diff --git a/src/Canvas.cc b/src/Canvas.cc index bd5b0fe60..1a495971d 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -1,29 +1,25 @@ -// -// Canvas.cc -// // Copyright (c) 2010 LearnBoost -// -#include -#include -#include -#include -#include +#include "Canvas.h" + #include // std::min -#include -#include -#include -#include -#include +#include #include #include -#include -#include "Util.h" -#include "Canvas.h" -#include "PNG.h" #include "CanvasRenderingContext2d.h" #include "closure.h" +#include +#include +#include +#include +#include "PNG.h" #include "register_font.h" +#include +#include +#include +#include +#include "Util.h" +#include #ifdef HAVE_JPEG #include "JPEGStream.h" @@ -309,7 +305,7 @@ static void parseJPEGArgs(Local arg, JpegClosure& jpegargs) { static uint32_t getSafeBufSize(Canvas* canvas) { // Don't allow the buffer size to exceed the size of the canvas (#674) // TODO not sure if this is really correct, but it fixed #674 - return std::min(canvas->getWidth() * canvas->getHeight() * 4, static_cast(PAGE_SIZE)); + return (std::min)(canvas->getWidth() * canvas->getHeight() * 4, static_cast(PAGE_SIZE)); } #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 16, 0) diff --git a/src/Canvas.h b/src/Canvas.h index 218597300..c8d2db63a 100644 --- a/src/Canvas.h +++ b/src/Canvas.h @@ -1,23 +1,14 @@ - -// -// Canvas.h -// // Copyright (c) 2010 LearnBoost -// -#ifndef __NODE_CANVAS_H__ -#define __NODE_CANVAS_H__ +#pragma once -#include -#include -#include -#include -#include +#include "backend/Backend.h" #include -#include - #include "dll_visibility.h" -#include "backend/Backend.h" +#include +#include +#include +#include /* * Maxmimum states per context. @@ -84,5 +75,3 @@ class Canvas: public Nan::ObjectWrap { ~Canvas(); Backend* _backend; }; - -#endif diff --git a/src/CanvasError.h b/src/CanvasError.h index 802fcad02..c7e322d82 100644 --- a/src/CanvasError.h +++ b/src/CanvasError.h @@ -1,5 +1,4 @@ -#ifndef __CANVAS_ERROR_H__ -#define __CANVAS_ERROR_H__ +#pragma once #include @@ -22,5 +21,3 @@ class CanvasError { cerrno = 0; } }; - -#endif diff --git a/src/CanvasGradient.cc b/src/CanvasGradient.cc index d2669e52c..c4997f5b3 100644 --- a/src/CanvasGradient.cc +++ b/src/CanvasGradient.cc @@ -1,14 +1,10 @@ - -// -// Gradient.cc -// // Copyright (c) 2010 LearnBoost -// -#include "color.h" -#include "Canvas.h" #include "CanvasGradient.h" +#include "Canvas.h" +#include "color.h" + using namespace v8; Nan::Persistent Gradient::constructor; diff --git a/src/CanvasGradient.h b/src/CanvasGradient.h index 09d77bc76..b6902c428 100644 --- a/src/CanvasGradient.h +++ b/src/CanvasGradient.h @@ -1,14 +1,10 @@ - -// -// CanvasGradient.h -// // Copyright (c) 2010 LearnBoost -// -#ifndef __NODE_GRADIENT_H__ -#define __NODE_GRADIENT_H__ +#pragma once -#include "Canvas.h" +#include +#include +#include class Gradient: public Nan::ObjectWrap { public: @@ -24,5 +20,3 @@ class Gradient: public Nan::ObjectWrap { ~Gradient(); cairo_pattern_t *_pattern; }; - -#endif diff --git a/src/CanvasPattern.cc b/src/CanvasPattern.cc index f03be63a8..e4392f348 100644 --- a/src/CanvasPattern.cc +++ b/src/CanvasPattern.cc @@ -1,13 +1,9 @@ - -// -// Pattern.cc -// // Copyright (c) 2010 LearnBoost -// + +#include "CanvasPattern.h" #include "Canvas.h" #include "Image.h" -#include "CanvasPattern.h" using namespace v8; diff --git a/src/CanvasPattern.h b/src/CanvasPattern.h index e60d3faa0..4313a28f5 100644 --- a/src/CanvasPattern.h +++ b/src/CanvasPattern.h @@ -1,14 +1,10 @@ - -// -// CanvasPattern.h -// // Copyright (c) 2011 LearnBoost -// -#ifndef __NODE_PATTERN_H__ -#define __NODE_PATTERN_H__ +#pragma once -#include "Canvas.h" +#include +#include +#include /* * Canvas types. @@ -36,5 +32,3 @@ class Pattern: public Nan::ObjectWrap { cairo_pattern_t *_pattern; repeat_type_t _repeat; }; - -#endif diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index e49697a66..8897f0d85 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -1,28 +1,23 @@ - -// -// CanvasRenderingContext2d.cc -// // Copyright (c) 2010 LearnBoost -// +#include "CanvasRenderingContext2d.h" + +#include +#include "backend/ImageBackend.h" +#include +#include "Canvas.h" +#include "CanvasGradient.h" +#include "CanvasPattern.h" #include #include +#include "Image.h" +#include "ImageData.h" #include -#include -#include -#include #include - -#include "Util.h" -#include "Canvas.h" #include "Point.h" -#include "Image.h" -#include "ImageData.h" -#include "CanvasRenderingContext2d.h" -#include "CanvasGradient.h" -#include "CanvasPattern.h" -#include "backend/ImageBackend.h" -#include +#include +#include "Util.h" +#include using namespace v8; diff --git a/src/CanvasRenderingContext2d.h b/src/CanvasRenderingContext2d.h index f3ac29d28..59d6f6d11 100644 --- a/src/CanvasRenderingContext2d.h +++ b/src/CanvasRenderingContext2d.h @@ -1,19 +1,12 @@ - -// -// CanvasRenderingContext2d.h -// // Copyright (c) 2010 LearnBoost -// - -#ifndef __NODE_CONTEXT2D_H__ -#define __NODE_CONTEXT2D_H__ -#include -#include +#pragma once -#include "color.h" +#include "cairo.h" #include "Canvas.h" -#include "CanvasGradient.h" +#include "color.h" +#include "nan.h" +#include typedef enum { TEXT_DRAW_PATHS, @@ -207,5 +200,3 @@ class Context2d: public Nan::ObjectWrap { cairo_path_t *_path; PangoLayout *_layout; }; - -#endif diff --git a/src/Image.cc b/src/Image.cc index 12cf0269a..ca2649803 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -1,18 +1,14 @@ -// -// Image.cc -// // Copyright (c) 2010 LearnBoost -// +#include "Image.h" + +#include "bmp/BMPParser.h" +#include "Canvas.h" +#include #include #include -#include #include - #include "Util.h" -#include "Canvas.h" -#include "Image.h" -#include "bmp/BMPParser.h" #ifdef HAVE_GIF typedef struct { diff --git a/src/Image.h b/src/Image.h index 0dd5c7198..62bc3f13b 100644 --- a/src/Image.h +++ b/src/Image.h @@ -1,16 +1,13 @@ - -// -// Image.h -// // Copyright (c) 2010 LearnBoost -// -#ifndef __NODE_IMAGE_H__ -#define __NODE_IMAGE_H__ +#pragma once -#include "Canvas.h" +#include #include "CanvasError.h" #include +#include +#include // node < 7 uses libstdc++ on macOS which lacks complete c++11 +#include #ifdef HAVE_JPEG #include @@ -128,5 +125,3 @@ class Image: public Nan::ObjectWrap { #endif ~Image(); }; - -#endif diff --git a/src/ImageData.cc b/src/ImageData.cc index e9e906b7c..19568b542 100644 --- a/src/ImageData.cc +++ b/src/ImageData.cc @@ -1,13 +1,9 @@ - -// -// ImageData.cc -// // Copyright (c) 2010 LearnBoost -// -#include "Util.h" #include "ImageData.h" +#include "Util.h" + using namespace v8; Nan::Persistent ImageData::constructor; diff --git a/src/ImageData.h b/src/ImageData.h index 2bda00d48..4832b37b2 100644 --- a/src/ImageData.h +++ b/src/ImageData.h @@ -1,18 +1,11 @@ - -// -// ImageData.h -// // Copyright (c) 2010 LearnBoost -// -#ifndef __NODE_IMAGE_DATA_H__ -#define __NODE_IMAGE_DATA_H__ +#pragma once -#include +#include +#include // node < 7 uses libstdc++ on macOS which lacks complete c++11 #include -#include "Canvas.h" - class ImageData: public Nan::ObjectWrap { public: static Nan::Persistent constructor; @@ -32,5 +25,3 @@ class ImageData: public Nan::ObjectWrap { uint8_t *_data; }; - -#endif diff --git a/src/JPEGStream.h b/src/JPEGStream.h index 94711de5e..677fc2550 100644 --- a/src/JPEGStream.h +++ b/src/JPEGStream.h @@ -1,13 +1,6 @@ - -// -// JPEGStream.h -// - -#ifndef __NODE_JPEG_STREAM_H__ -#define __NODE_JPEG_STREAM_H__ +#pragma once #include "closure.h" -#include "Canvas.h" #include #include @@ -172,5 +165,3 @@ write_to_jpeg_buffer(cairo_surface_t* surface, JpegClosure* closure) { closure->chromaSubsampling, closure->chromaSubsampling); } - -#endif diff --git a/src/PNG.h b/src/PNG.h index f5daca8c4..30b88f85f 100644 --- a/src/PNG.h +++ b/src/PNG.h @@ -1,13 +1,12 @@ -#ifndef _CANVAS_PNG_H -#define _CANVAS_PNG_H +#pragma once +#include +#include "closure.h" +#include // round #include #include #include #include -#include -#include // round -#include "closure.h" #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) #define likely(expr) (__builtin_expect (!!(expr), 1)) @@ -291,4 +290,3 @@ static cairo_status_t canvas_write_to_png_stream(cairo_surface_t *surface, cairo return canvas_write_png(surface, canvas_stream_write_func, &png_closure); } -#endif diff --git a/src/Point.h b/src/Point.h index 5baef1049..d3228acfa 100644 --- a/src/Point.h +++ b/src/Point.h @@ -1,13 +1,6 @@ - - -// -// Point.h -// // Copyright (c) 2010 LearnBoost -// -#ifndef __NODE_POINT_H__ -#define __NODE_POINT_H__ +#pragma once template class Point { @@ -15,5 +8,3 @@ class Point { T x, y; Point(T x, T y): x(x), y(y) {} }; - -#endif /* __NODE_POINT_H__ */ diff --git a/src/Util.h b/src/Util.h index f0c703516..d60a57ee4 100644 --- a/src/Util.h +++ b/src/Util.h @@ -1,5 +1,7 @@ -#include +#pragma once + #include +#include // Wrapper around Nan::SetAccessor that makes it easier to change the last // argument (signature). Getters/setters must be accessed only when there is diff --git a/src/backend/Backend.h b/src/backend/Backend.h index 15edcf7b3..c0c4e1928 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -1,14 +1,11 @@ -#ifndef __BACKEND_H__ -#define __BACKEND_H__ +#pragma once -#include -#include - -#include -#include #include - #include "../dll_visibility.h" +#include +#include +#include +#include class Canvas; @@ -69,5 +66,3 @@ class BackendOperationNotAvailable: public std::exception const char* what() const throw(); }; - -#endif diff --git a/src/backend/ImageBackend.h b/src/backend/ImageBackend.h index 09464087a..cb2b4e917 100644 --- a/src/backend/ImageBackend.h +++ b/src/backend/ImageBackend.h @@ -1,9 +1,7 @@ -#ifndef __IMAGE_BACKEND_H__ -#define __IMAGE_BACKEND_H__ - -#include +#pragma once #include "Backend.h" +#include class ImageBackend : public Backend { @@ -26,5 +24,3 @@ class ImageBackend : public Backend static NAN_METHOD(New); const static cairo_format_t DEFAULT_FORMAT = CAIRO_FORMAT_ARGB32; }; - -#endif diff --git a/src/backend/PdfBackend.cc b/src/backend/PdfBackend.cc index ac6112c8c..173103ed6 100644 --- a/src/backend/PdfBackend.cc +++ b/src/backend/PdfBackend.cc @@ -1,12 +1,9 @@ #include "PdfBackend.h" #include -#include - #include "../Canvas.h" #include "../closure.h" - using namespace v8; PdfBackend::PdfBackend(int width, int height) diff --git a/src/backend/PdfBackend.h b/src/backend/PdfBackend.h index 8f86b5c45..4d334c9d2 100644 --- a/src/backend/PdfBackend.h +++ b/src/backend/PdfBackend.h @@ -1,10 +1,8 @@ -#ifndef __PDF_BACKEND_H__ -#define __PDF_BACKEND_H__ +#pragma once -#include - -#include "../closure.h" #include "Backend.h" +#include "../closure.h" +#include class PdfBackend : public Backend { @@ -24,5 +22,3 @@ class PdfBackend : public Backend static void Initialize(v8::Handle target); static NAN_METHOD(New); }; - -#endif diff --git a/src/backend/SvgBackend.cc b/src/backend/SvgBackend.cc index a16fa6194..de792f4c8 100644 --- a/src/backend/SvgBackend.cc +++ b/src/backend/SvgBackend.cc @@ -1,12 +1,9 @@ #include "SvgBackend.h" #include -#include - #include "../Canvas.h" #include "../closure.h" - using namespace v8; SvgBackend::SvgBackend(int width, int height) diff --git a/src/backend/SvgBackend.h b/src/backend/SvgBackend.h index 20a53007d..b2a6be655 100644 --- a/src/backend/SvgBackend.h +++ b/src/backend/SvgBackend.h @@ -1,10 +1,8 @@ -#ifndef __SVG_BACKEND_H__ -#define __SVG_BACKEND_H__ - -#include +#pragma once #include "Backend.h" #include "../closure.h" +#include class SvgBackend : public Backend { @@ -24,5 +22,3 @@ class SvgBackend : public Backend static void Initialize(v8::Handle target); static NAN_METHOD(New); }; - -#endif diff --git a/src/bmp/BMPParser.cc b/src/bmp/BMPParser.cc index d0ae1be1d..76b122f21 100644 --- a/src/bmp/BMPParser.cc +++ b/src/bmp/BMPParser.cc @@ -1,7 +1,7 @@ -#include - #include "BMPParser.h" +#include + using namespace std; using namespace BMPParser; diff --git a/src/bmp/BMPParser.h b/src/bmp/BMPParser.h index 86d1465ed..9e02bdeb0 100644 --- a/src/bmp/BMPParser.h +++ b/src/bmp/BMPParser.h @@ -1,11 +1,11 @@ -#ifndef __NODE_BMP_PARSER_H__ -#define __NODE_BMP_PARSER_H__ +#pragma once #ifdef ERROR #define ERROR_ ERROR #undef ERROR #endif +#include // node < 7 uses libstdc++ on macOS which lacks complete c++11 #include namespace BMPParser{ @@ -56,5 +56,3 @@ namespace BMPParser{ #define ERROR ERROR_ #undef ERROR_ #endif - -#endif diff --git a/src/closure.h b/src/closure.h index 06d1be8bc..2f5b45f16 100644 --- a/src/closure.h +++ b/src/closure.h @@ -1,24 +1,18 @@ - -// -// closure.h -// // Copyright (c) 2010 LearnBoost -// -#ifndef __NODE_CLOSURE_H__ -#define __NODE_CLOSURE_H__ +#pragma once +#include "Canvas.h" +#include #include #include -#include +#include // node < 7 uses libstdc++ on macOS which lacks complete c++11 #include #ifndef PAGE_SIZE #define PAGE_SIZE 4096 #endif -#include "Canvas.h" - /* * Image encoding closures. */ @@ -79,5 +73,3 @@ struct JpegClosure : Closure { delete jpeg_dest_mgr; } }; - -#endif /* __NODE_CLOSURE_H__ */ diff --git a/src/color.cc b/src/color.cc index c6df4a6ec..8c41f1135 100644 --- a/src/color.cc +++ b/src/color.cc @@ -1,17 +1,14 @@ - -// -// color.cc -// // Copyright (c) 2010 LearnBoost -// -#include +#include "color.h" + +#include #include +#include +#include #include -#include -#include -#include "color.h" #include +#include // Compatibility with Visual Studio versions prior to VS2015 #if defined(_MSC_VER) && _MSC_VER < 1900 diff --git a/src/color.h b/src/color.h index f4123e1b6..137c1d6b3 100644 --- a/src/color.h +++ b/src/color.h @@ -1,17 +1,9 @@ - -// -// color.h -// // Copyright (c) 2010 LearnBoost -// -#ifndef __COLOR_PARSER_H__ -#define __COLOR_PARSER_H__ +#pragma once -#include #include // node < 7 uses libstdc++ on macOS which lacks complete c++11 -#include -#include +#include /* * RGBA struct. @@ -36,5 +28,3 @@ rgba_to_string(rgba_t rgba, char *buf, size_t len); void rgba_inspect(int32_t rgba); - -#endif /* __COLOR_PARSER_H__ */ diff --git a/src/init.cc b/src/init.cc index b3c6e6896..8322d5aa5 100644 --- a/src/init.cc +++ b/src/init.cc @@ -1,13 +1,7 @@ - -// -// init.cc -// // Copyright (c) 2010 LearnBoost -// #include #include -#include #include #if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 10, 0) diff --git a/src/register_font.cc b/src/register_font.cc index 3a81f3cf8..2817287a5 100644 --- a/src/register_font.cc +++ b/src/register_font.cc @@ -1,3 +1,5 @@ +#include "register_font.h" + #include #include #include diff --git a/src/register_font.h b/src/register_font.h index 33d006bab..cfac9f961 100644 --- a/src/register_font.h +++ b/src/register_font.h @@ -1,5 +1,6 @@ +#pragma once + #include PangoFontDescription *get_pango_font_description(unsigned char *filepath); bool register_font(unsigned char *filepath); - From d1a6c44467238125e1214f896e3f06f77836d93a Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Thu, 10 Jan 2019 23:47:05 -0800 Subject: [PATCH 4/6] closure.h: fix catch by value --- src/closure.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/closure.h b/src/closure.h index 2f5b45f16..db423d0fe 100644 --- a/src/closure.h +++ b/src/closure.h @@ -27,7 +27,7 @@ struct Closure { Closure* closure = static_cast(c); try { closure->vec.insert(closure->vec.end(), odata, odata + len); - } catch (std::bad_alloc) { + } catch (const std::bad_alloc &) { return CAIRO_STATUS_NO_MEMORY; } return CAIRO_STATUS_SUCCESS; From a65ac5000cbea4989690f503aeee60aa061c7417 Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Thu, 10 Jan 2019 23:52:17 -0800 Subject: [PATCH 5/6] fix ISO C++ violation; use string.assign --- src/CanvasError.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/CanvasError.h b/src/CanvasError.h index c7e322d82..cb751e312 100644 --- a/src/CanvasError.h +++ b/src/CanvasError.h @@ -8,11 +8,11 @@ class CanvasError { std::string syscall; std::string path; int cerrno = 0; - void set(char *iMessage = NULL, char *iSyscall = NULL, int iErrno = 0, char *iPath = NULL) { - if (iMessage) message = std::string(iMessage); - if (iSyscall) syscall = std::string(iSyscall); + void set(const char* iMessage = NULL, const char* iSyscall = NULL, int iErrno = 0, const char* iPath = NULL) { + if (iMessage) message.assign(iMessage); + if (iSyscall) syscall.assign(iSyscall); cerrno = iErrno; - if (iPath) path = std::string(iPath); + if (iPath) path.assign(iPath); } void reset() { message.clear(); From 7d9db8396be9e9b0c1e828d38148227735395db0 Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Fri, 11 Jan 2019 00:08:15 -0800 Subject: [PATCH 6/6] Un-disable a bunch of MSVC warnings None of these are necessary anymore --- binding.gyp | 4 ++-- src/init.cc | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/binding.gyp b/binding.gyp index 4970f6a82..24b08d5a6 100644 --- a/binding.gyp +++ b/binding.gyp @@ -105,7 +105,7 @@ 'WarningLevel': 4, 'ExceptionHandling': 1, 'DisableSpecificWarnings': [ - 4100, 4127, 4201, 4244, 4267, 4506, 4611, 4714, 4512 + 4100, 4611 ] } } @@ -116,7 +116,7 @@ 'WarningLevel': 4, 'ExceptionHandling': 1, 'DisableSpecificWarnings': [ - 4100, 4127, 4201, 4244, 4267, 4506, 4611, 4714, 4512 + 4100, 4611 ] } } diff --git a/src/init.cc b/src/init.cc index 8322d5aa5..97ab79ac8 100644 --- a/src/init.cc +++ b/src/init.cc @@ -61,7 +61,8 @@ NAN_MODULE_INIT(init) { #endif char jpeg_version[10]; - if (JPEG_LIB_VERSION_MINOR > 0) { + static bool minor_gt_0 = JPEG_LIB_VERSION_MINOR > 0; + if (minor_gt_0) { snprintf(jpeg_version, 10, "%d%c", JPEG_LIB_VERSION_MAJOR, JPEG_LIB_VERSION_MINOR + 'a' - 1); } else { snprintf(jpeg_version, 10, "%d", JPEG_LIB_VERSION_MAJOR);