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