Backend.h
1.52 KB
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
#pragma once
#include <cairo.h>
#include "../dll_visibility.h"
#include <exception>
#include <nan.h>
#include <string>
#include <v8.h>
class Canvas;
class Backend : public Nan::ObjectWrap
{
private:
const std::string name;
const char* error = NULL;
protected:
int width;
int height;
cairo_surface_t* surface = nullptr;
Canvas* canvas = nullptr;
Backend(std::string name, int width, int height);
static void init(const Nan::FunctionCallbackInfo<v8::Value> &info);
static Backend *construct(int width, int height){ return nullptr; }
public:
virtual ~Backend();
void setCanvas(Canvas* canvas);
virtual cairo_surface_t* createSurface() = 0;
virtual cairo_surface_t* recreateSurface();
DLL_PUBLIC cairo_surface_t* getSurface();
virtual void destroySurface();
DLL_PUBLIC std::string getName();
DLL_PUBLIC int getWidth();
virtual void setWidth(int width);
DLL_PUBLIC int getHeight();
virtual void setHeight(int height);
// Overridden by ImageBackend. SVG and PDF thus always return INVALID.
virtual cairo_format_t getFormat() {
return CAIRO_FORMAT_INVALID;
}
bool isSurfaceValid();
inline const char* getError(){ return error; }
};
class BackendOperationNotAvailable: public std::exception
{
private:
Backend* backend;
std::string operation_name;
public:
BackendOperationNotAvailable(Backend* backend, std::string operation_name);
~BackendOperationNotAvailable() throw();
const char* what() const throw();
};