1 | #include "PdfBackend.h"
|
2 |
|
3 | #include <cairo-pdf.h>
|
4 | #include "../Canvas.h"
|
5 | #include "../closure.h"
|
6 |
|
7 | using namespace v8;
|
8 |
|
9 | PdfBackend::PdfBackend(int width, int height)
|
10 | : Backend("pdf", width, height) {
|
11 | createSurface();
|
12 | }
|
13 |
|
14 | PdfBackend::~PdfBackend() {
|
15 | cairo_surface_finish(surface);
|
16 | if (_closure) delete _closure;
|
17 | destroySurface();
|
18 | }
|
19 |
|
20 | Backend *PdfBackend::construct(int width, int height){
|
21 | return new PdfBackend(width, height);
|
22 | }
|
23 |
|
24 | cairo_surface_t* PdfBackend::createSurface() {
|
25 | if (!_closure) _closure = new PdfSvgClosure(canvas);
|
26 | surface = cairo_pdf_surface_create_for_stream(PdfSvgClosure::writeVec, _closure, width, height);
|
27 | return surface;
|
28 | }
|
29 |
|
30 | cairo_surface_t* PdfBackend::recreateSurface() {
|
31 | cairo_pdf_surface_set_size(surface, width, height);
|
32 |
|
33 | return surface;
|
34 | }
|
35 |
|
36 |
|
37 | Nan::Persistent<FunctionTemplate> PdfBackend::constructor;
|
38 |
|
39 | void PdfBackend::Initialize(Local<Object> target) {
|
40 | Nan::HandleScope scope;
|
41 |
|
42 | Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(PdfBackend::New);
|
43 | PdfBackend::constructor.Reset(ctor);
|
44 | ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
45 | ctor->SetClassName(Nan::New<String>("PdfBackend").ToLocalChecked());
|
46 | Nan::Set(target,
|
47 | Nan::New<String>("PdfBackend").ToLocalChecked(),
|
48 | Nan::GetFunction(ctor).ToLocalChecked()).Check();
|
49 | }
|
50 |
|
51 | NAN_METHOD(PdfBackend::New) {
|
52 | init(info);
|
53 | }
|