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/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 e04494d14..1a495971d 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -1,28 +1,25 @@ -// -// Canvas.cc -// // Copyright (c) 2010 LearnBoost -// +#include "Canvas.h" + +#include // std::min #include -#include -#include -#include -#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" @@ -37,6 +34,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 +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 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 +377,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..c8d2db63a 100644 --- a/src/Canvas.h +++ b/src/Canvas.h @@ -1,27 +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" - - -using namespace node; -using namespace v8; +#include +#include +#include +#include /* * Maxmimum states per context. @@ -48,7 +35,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 +49,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,11 +69,9 @@ 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(); Backend* _backend; }; - -#endif diff --git a/src/CanvasError.h b/src/CanvasError.h index 802fcad02..cb751e312 100644 --- a/src/CanvasError.h +++ b/src/CanvasError.h @@ -1,5 +1,4 @@ -#ifndef __CANVAS_ERROR_H__ -#define __CANVAS_ERROR_H__ +#pragma once #include @@ -9,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(); @@ -22,5 +21,3 @@ class CanvasError { cerrno = 0; } }; - -#endif diff --git a/src/CanvasGradient.cc b/src/CanvasGradient.cc index 1f493af78..c4997f5b3 100644 --- a/src/CanvasGradient.cc +++ b/src/CanvasGradient.cc @@ -1,14 +1,12 @@ - -// -// 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 2459eb60d..b6902c428 100644 --- a/src/CanvasGradient.h +++ b/src/CanvasGradient.h @@ -1,18 +1,14 @@ - -// -// 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: - 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); @@ -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 f37a0028c..e4392f348 100644 --- a/src/CanvasPattern.cc +++ b/src/CanvasPattern.cc @@ -1,13 +1,11 @@ - -// -// Pattern.cc -// // Copyright (c) 2010 LearnBoost -// + +#include "CanvasPattern.h" #include "Canvas.h" #include "Image.h" -#include "CanvasPattern.h" + +using namespace v8; const cairo_user_data_key_t *pattern_repeat_key; diff --git a/src/CanvasPattern.h b/src/CanvasPattern.h index afbd4703e..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. @@ -25,7 +21,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); @@ -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 62c901413..8897f0d85 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -1,28 +1,25 @@ - -// -// 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; // Windows doesn't support the C99 names for these #ifdef _MSC_VER @@ -1766,7 +1763,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 +1809,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)) { diff --git a/src/CanvasRenderingContext2d.h b/src/CanvasRenderingContext2d.h index 421928da6..59d6f6d11 100644 --- a/src/CanvasRenderingContext2d.h +++ b/src/CanvasRenderingContext2d.h @@ -1,21 +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" - -using namespace std; +#include "color.h" +#include "nan.h" +#include typedef enum { TEXT_DRAW_PATHS, @@ -71,9 +62,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,21 +184,19 @@ 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; PangoLayout *_layout; }; - -#endif diff --git a/src/Image.cc b/src/Image.cc index bf7de79de..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 { @@ -40,6 +36,8 @@ typedef struct { uint8_t *buf; } read_closure_t; +using namespace v8; + Nan::Persistent Image::constructor; /* @@ -239,9 +237,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 +1372,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..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 @@ -42,7 +39,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); @@ -128,5 +125,3 @@ class Image: public Nan::ObjectWrap { #endif ~Image(); }; - -#endif diff --git a/src/ImageData.cc b/src/ImageData.cc index 751edfea1..19568b542 100644 --- a/src/ImageData.cc +++ b/src/ImageData.cc @@ -1,13 +1,11 @@ - -// -// 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 392b1faca..4832b37b2 100644 --- a/src/ImageData.h +++ b/src/ImageData.h @@ -1,21 +1,14 @@ - -// -// 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; + static Nan::Persistent constructor; static void Initialize(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target); static NAN_METHOD(New); static NAN_GETTER(GetWidth); @@ -32,5 +25,3 @@ class ImageData: public Nan::ObjectWrap { uint8_t *_data; }; - -#endif diff --git a/src/JPEGStream.h b/src/JPEGStream.h index 300b0f2c2..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 @@ -34,10 +27,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 +49,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() }; @@ -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.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..c0c4e1928 100644 --- a/src/backend/Backend.h +++ b/src/backend/Backend.h @@ -1,25 +1,18 @@ -#ifndef __BACKEND_H__ -#define __BACKEND_H__ +#pragma once -#include -#include -#include -#include - -#include -#include #include - #include "../dll_visibility.h" +#include +#include +#include +#include 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 +21,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 +36,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,17 +54,15 @@ 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(); }; - -#endif diff --git a/src/backend/ImageBackend.h b/src/backend/ImageBackend.h index 4c002abe4..cb2b4e917 100644 --- a/src/backend/ImageBackend.h +++ b/src/backend/ImageBackend.h @@ -1,11 +1,7 @@ -#ifndef __IMAGE_BACKEND_H__ -#define __IMAGE_BACKEND_H__ - -#include +#pragma once #include "Backend.h" - -using namespace std; +#include class ImageBackend : public Backend { @@ -28,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 2c597a703..4d334c9d2 100644 --- a/src/backend/PdfBackend.h +++ b/src/backend/PdfBackend.h @@ -1,12 +1,8 @@ -#ifndef __PDF_BACKEND_H__ -#define __PDF_BACKEND_H__ +#pragma once -#include - -#include "../closure.h" #include "Backend.h" - -using namespace std; +#include "../closure.h" +#include class PdfBackend : public Backend { @@ -26,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 b703a3b94..b2a6be655 100644 --- a/src/backend/SvgBackend.h +++ b/src/backend/SvgBackend.h @@ -1,12 +1,8 @@ -#ifndef __SVG_BACKEND_H__ -#define __SVG_BACKEND_H__ - -#include +#pragma once #include "Backend.h" #include "../closure.h" - -using namespace std; +#include class SvgBackend : public Backend { @@ -26,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..db423d0fe 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. */ @@ -33,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; @@ -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 3c2f721cf..97ab79ac8 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) @@ -31,6 +25,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 @@ -65,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); 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); -