// // Canvas.h // // Copyright (c) 2010 LearnBoost // #ifndef __NODE_CANVAS_H__ #define __NODE_CANVAS_H__ #include #include #include #include using namespace v8; using namespace node; /* * Maxmimum states per context. * TODO: remove/resize */ #ifndef CANVAS_MAX_STATES #define CANVAS_MAX_STATES 64 #endif /* * RGBA arg assertions. */ #define RGBA_ARGS(N) \ if (!args[N]->IsNumber()) \ return ThrowException(Exception::TypeError(String::New("r required"))); \ if (!args[N+1]->IsNumber()) \ return ThrowException(Exception::TypeError(String::New("g required"))); \ if (!args[N+2]->IsNumber()) \ return ThrowException(Exception::TypeError(String::New("b required"))); \ if (!args[N+3]->IsNumber()) \ return ThrowException(Exception::TypeError(String::New("alpha required"))); \ double r = args[N]->Int32Value(); \ double g = args[N+1]->Int32Value(); \ double b = args[N+2]->Int32Value(); \ double a = args[N+3]->NumberValue(); /* * Canvas. */ class Canvas: public node::ObjectWrap { public: int width; int height; static void Initialize(Handle target); static Handle New(const Arguments &args); static Handle ToBuffer(const Arguments &args); static Handle GetWidth(Local prop, const AccessorInfo &info); static Handle GetHeight(Local prop, const AccessorInfo &info); static void SetWidth(Local prop, Local val, const AccessorInfo &info); static void SetHeight(Local prop, Local val, const AccessorInfo &info); static Handle StreamPNGSync(const Arguments &args); static Local Error(cairo_status_t status); inline cairo_surface_t *surface(){ return _surface; } inline uint8_t *data(){ return cairo_image_surface_get_data(_surface); } inline int stride(){ return cairo_image_surface_get_stride(_surface); } Canvas(int width, int height); void resurface(); private: ~Canvas(); cairo_surface_t *_surface; }; #endif