Branch data Line data Source code
1 : : /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2 : : // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
3 : : // SPDX-FileCopyrightText: 2010 litl, LLC.
4 : : // SPDX-FileCopyrightText: 2020 Philip Chimento <philip.chimento@gmail.com>
5 : :
6 : : #include <config.h>
7 : :
8 : : #include <cairo-features.h> // for CAIRO_HAS_PDF_SURFACE
9 : : #include <cairo.h>
10 : :
11 : : #if CAIRO_HAS_PDF_SURFACE
12 : : # include <cairo-pdf.h>
13 : : #endif
14 : :
15 : : #include <js/TypeDecls.h>
16 : :
17 : : #if CAIRO_HAS_PDF_SURFACE
18 : : # include <js/PropertyDescriptor.h> // for JSPROP_READONLY
19 : : # include <js/PropertySpec.h>
20 : : # include <js/RootingAPI.h>
21 : : # include <jsapi.h> // for JS_NewObjectWithGivenProto
22 : : # include <jspubtd.h> // for JSProtoKey
23 : : #endif
24 : :
25 : : #include "gjs/jsapi-util.h"
26 : :
27 : : #if CAIRO_HAS_PDF_SURFACE
28 : : # include "gjs/jsapi-util-args.h"
29 : : # include "modules/cairo-private.h"
30 : :
31 : : namespace JS {
32 : : class CallArgs;
33 : : }
34 : :
35 : 2 : JSObject* CairoPDFSurface::new_proto(JSContext* cx, JSProtoKey) {
36 : 2 : JS::RootedObject parent_proto(cx, CairoSurface::prototype(cx));
37 : 2 : return JS_NewObjectWithGivenProto(cx, nullptr, parent_proto);
38 : 2 : }
39 : :
40 : 0 : cairo_surface_t* CairoPDFSurface::constructor_impl(JSContext* context,
41 : : const JS::CallArgs& argv) {
42 : 0 : GjsAutoChar filename;
43 : : double width, height;
44 : : cairo_surface_t *surface;
45 [ # # ]: 0 : if (!gjs_parse_call_args(context, "PDFSurface", argv, "Fff",
46 : : "filename", &filename,
47 : : "width", &width,
48 : : "height", &height))
49 : 0 : return nullptr;
50 : :
51 : 0 : surface = cairo_pdf_surface_create(filename, width, height);
52 : :
53 [ # # ]: 0 : if (!gjs_cairo_check_status(context, cairo_surface_status(surface),
54 : : "surface"))
55 : 0 : return nullptr;
56 : :
57 : 0 : return surface;
58 : 0 : }
59 : :
60 : : // clang-format off
61 : : JSPropertySpec gjs_cairo_pdf_surface_proto_props[] = {
62 : : JS_STRING_SYM_PS(toStringTag, "PDFSurface", JSPROP_READONLY),
63 : : JS_PS_END};
64 : : // clang-format on
65 : : #else
66 : : JSObject* CairoPDFSurface::from_c_ptr(JSContext* context,
67 : : cairo_surface_t* surface) {
68 : : gjs_throw(context,
69 : : "could not create PDF surface, recompile cairo and gjs with "
70 : : "PDF support.");
71 : : return nullptr;
72 : : }
73 : : #endif /* CAIRO_HAS_PDF_SURFACE */
|