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_PS_SURFACE
9 : : #include <cairo.h>
10 : :
11 : : #if CAIRO_HAS_PS_SURFACE
12 : : # include <cairo-ps.h>
13 : : #endif
14 : :
15 : : #include <js/TypeDecls.h>
16 : :
17 : : #if CAIRO_HAS_PS_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 : :
24 : : # include "gjs/auto.h"
25 : : # include "gjs/jsapi-util-args.h"
26 : : # include "modules/cairo-private.h"
27 : :
28 : : namespace JS {
29 : : class CallArgs;
30 : : }
31 : :
32 : 2 : JSObject* CairoPSSurface::new_proto(JSContext* cx, JSProtoKey) {
33 : 2 : JS::RootedObject parent_proto(cx, CairoSurface::prototype(cx));
34 : 2 : return JS_NewObjectWithGivenProto(cx, nullptr, parent_proto);
35 : 2 : }
36 : :
37 : 0 : cairo_surface_t* CairoPSSurface::constructor_impl(JSContext* cx,
38 : : const JS::CallArgs& argv) {
39 : 0 : Gjs::AutoChar filename;
40 : : double width, height;
41 : : cairo_surface_t *surface;
42 [ # # ]: 0 : if (!gjs_parse_call_args(cx, "PSSurface", argv, "Fff", "filename",
43 : : &filename, "width", &width, "height", &height))
44 : 0 : return nullptr;
45 : :
46 : 0 : surface = cairo_ps_surface_create(filename, width, height);
47 : :
48 [ # # ]: 0 : if (!gjs_cairo_check_status(cx, cairo_surface_status(surface), "surface"))
49 : 0 : return nullptr;
50 : :
51 : 0 : return surface;
52 : 0 : }
53 : :
54 : : // clang-format off
55 : : const JSPropertySpec CairoPSSurface::proto_props[] = {
56 : : JS_STRING_SYM_PS(toStringTag, "PSSurface", JSPROP_READONLY),
57 : : JS_PS_END};
58 : : // clang-format on
59 : :
60 : : const JSFunctionSpec CairoPSSurface::proto_funcs[] = {
61 : : // restrictToLevel
62 : : // getLevels
63 : : // levelToString
64 : : // setEPS
65 : : // getEPS
66 : : // setSize
67 : : // dscBeginSetup
68 : : // dscBeginPageSetup
69 : : // dscComment
70 : : JS_FS_END};
71 : :
72 : : #else
73 : : JSObject* CairoPSSurface::from_c_ptr(JSContext* cx, cairo_surface_t* surface) {
74 : : gjs_throw(cx,
75 : : "could not create PS surface, recompile cairo and gjs with PS "
76 : : "support.");
77 : : return nullptr;
78 : : }
79 : : #endif // CAIRO_HAS_PS_SURFACE
|