/
Canvas.h
87 lines (74 loc) · 2.21 KB
/
Canvas.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// Canvas.h
//
// Copyright (c) 2010 LearnBoost <tj@learnboost.com>
//
#ifndef __NODE_CANVAS_H__
#define __NODE_CANVAS_H__
#include <v8.h>
#include <node.h>
#include <node_object_wrap.h>
#include <node_version.h>
#include <cairo.h>
using namespace v8;
using namespace node;
/*
* Maxmimum states per context.
* TODO: remove/resize
*/
#ifndef CANVAS_MAX_STATES
#define CANVAS_MAX_STATES 64
#endif
/*
* Canvas types.
*/
typedef enum {
CANVAS_TYPE_IMAGE,
CANVAS_TYPE_PDF
} canvas_type_t;
/*
* Canvas.
*/
class Canvas: public node::ObjectWrap {
public:
int width;
int height;
canvas_type_t type;
static Persistent<FunctionTemplate> constructor;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
static Handle<Value> ToBuffer(const Arguments &args);
static Handle<Value> GetType(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetWidth(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetHeight(Local<String> prop, const AccessorInfo &info);
static void SetWidth(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetHeight(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static Handle<Value> StreamPNGSync(const Arguments &args);
static Handle<Value> StreamJPEGSync(const Arguments &args);
static Local<Value> Error(cairo_status_t status);
#if NODE_VERSION_AT_LEAST(0, 6, 0)
static void ToBufferAsync(uv_work_t *req);
static void ToBufferAsyncAfter(uv_work_t *req);
#else
static
#if NODE_VERSION_AT_LEAST(0, 5, 4)
void
#else
int
#endif
EIO_ToBuffer(eio_req *req);
static int EIO_AfterToBuffer(eio_req *req);
#endif
inline bool isPDF(){ return CANVAS_TYPE_PDF == type; }
inline cairo_surface_t *surface(){ return _surface; }
inline void *closure(){ return _closure; }
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, canvas_type_t type);
void resurface(Handle<Object> canvas);
private:
~Canvas();
cairo_surface_t *_surface;
void *_closure;
};
#endif