1 |
|
2 |
|
3 | #pragma once
|
4 |
|
5 | #include "backend/Backend.h"
|
6 | #include <cairo.h>
|
7 | #include "dll_visibility.h"
|
8 | #include <nan.h>
|
9 | #include <pango/pangocairo.h>
|
10 | #include <v8.h>
|
11 | #include <vector>
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | #ifndef CANVAS_MAX_STATES
|
19 | #define CANVAS_MAX_STATES 64
|
20 | #endif
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | class FontFace {
|
27 | public:
|
28 | PangoFontDescription *sys_desc = nullptr;
|
29 | PangoFontDescription *user_desc = nullptr;
|
30 | };
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | class Canvas: public Nan::ObjectWrap {
|
37 | public:
|
38 | static Nan::Persistent<v8::FunctionTemplate> constructor;
|
39 | static void Initialize(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target);
|
40 | static NAN_METHOD(New);
|
41 | static NAN_METHOD(ToBuffer);
|
42 | static NAN_GETTER(GetType);
|
43 | static NAN_GETTER(GetStride);
|
44 | static NAN_GETTER(GetWidth);
|
45 | static NAN_GETTER(GetHeight);
|
46 | static NAN_SETTER(SetWidth);
|
47 | static NAN_SETTER(SetHeight);
|
48 | static NAN_METHOD(StreamPNGSync);
|
49 | static NAN_METHOD(StreamPDFSync);
|
50 | static NAN_METHOD(StreamJPEGSync);
|
51 | static NAN_METHOD(RegisterFont);
|
52 | static v8::Local<v8::Value> Error(cairo_status_t status);
|
53 | static void ToPngBufferAsync(uv_work_t *req);
|
54 | static void ToJpegBufferAsync(uv_work_t *req);
|
55 | static void ToBufferAsyncAfter(uv_work_t *req);
|
56 | static PangoWeight GetWeightFromCSSString(const char *weight);
|
57 | static PangoStyle GetStyleFromCSSString(const char *style);
|
58 | static PangoFontDescription *ResolveFontDescription(const PangoFontDescription *desc);
|
59 |
|
60 | DLL_PUBLIC inline Backend* backend() { return _backend; }
|
61 | DLL_PUBLIC inline cairo_surface_t* surface(){ return backend()->getSurface(); }
|
62 | cairo_t* createCairoContext();
|
63 |
|
64 | DLL_PUBLIC inline uint8_t *data(){ return cairo_image_surface_get_data(surface()); }
|
65 | DLL_PUBLIC inline int stride(){ return cairo_image_surface_get_stride(surface()); }
|
66 | DLL_PUBLIC inline int nBytes(){ return getHeight() * stride(); }
|
67 |
|
68 | DLL_PUBLIC inline int getWidth() { return backend()->getWidth(); }
|
69 | DLL_PUBLIC inline int getHeight() { return backend()->getHeight(); }
|
70 |
|
71 | Canvas(Backend* backend);
|
72 | void resurface(v8::Local<v8::Object> canvas);
|
73 |
|
74 | private:
|
75 | ~Canvas();
|
76 | Backend* _backend;
|
77 | };
|