SvgBackend.cc
1.44 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
#include "SvgBackend.h"
#include <cairo-svg.h>
#include "../Canvas.h"
#include "../closure.h"
#include <cassert>
using namespace v8;
SvgBackend::SvgBackend(int width, int height)
: Backend("svg", width, height) {
createSurface();
}
SvgBackend::~SvgBackend() {
cairo_surface_finish(surface);
if (_closure) {
delete _closure;
_closure = nullptr;
}
destroySurface();
}
Backend *SvgBackend::construct(int width, int height){
return new SvgBackend(width, height);
}
cairo_surface_t* SvgBackend::createSurface() {
assert(!_closure);
_closure = new PdfSvgClosure(canvas);
surface = cairo_svg_surface_create_for_stream(PdfSvgClosure::writeVec, _closure, width, height);
return surface;
}
cairo_surface_t* SvgBackend::recreateSurface() {
cairo_surface_finish(surface);
delete _closure;
_closure = nullptr;
cairo_surface_destroy(surface);
return createSurface();
}
Nan::Persistent<FunctionTemplate> SvgBackend::constructor;
void SvgBackend::Initialize(Local<Object> target) {
Nan::HandleScope scope;
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(SvgBackend::New);
SvgBackend::constructor.Reset(ctor);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(Nan::New<String>("SvgBackend").ToLocalChecked());
Nan::Set(target,
Nan::New<String>("SvgBackend").ToLocalChecked(),
Nan::GetFunction(ctor).ToLocalChecked()).Check();
}
NAN_METHOD(SvgBackend::New) {
init(info);
}