Debian Codegraph @

cairo/rectangle.c

raw symbols SCIP
1 /* -*- mode: C; c-basic-offset: 2 -*-
2 *
3 * Pycairo - Python bindings for cairo
4 *
5 * Copyright © 2017 Christoph Reiter
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it either under the terms of the GNU Lesser General Public
9 * License version 2.1 as published by the Free Software Foundation
10 * (the "LGPL") or, at your option, under the terms of the Mozilla
11 * Public License Version 1.1 (the "MPL"). If you do not alter this
12 * notice, a recipient may use your version of this file under either
13 * the MPL or the LGPL.
14 *
15 * You should have received a copy of the LGPL along with this library
16 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * You should have received a copy of the MPL along with this library
19 * in the file COPYING-MPL-1.1
20 *
21 * The contents of this file are subject to the Mozilla Public License
22 * Version 1.1 (the "License"); you may not use this file except in
23 * compliance with the License. You may obtain a copy of the License at
24 * http://www.mozilla.org/MPL/
25 *
26 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
27 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
28 * the specific language governing rights and limitations.
29 */
30
31 #define PY_SSIZE_T_CLEAN
32 #include <Python.h>
33
34 #include "private.h"
35
36 static char *KWDS[] = {"x", "y", "width", "height", NULL};
37
38 static PyObject *
39 rectangle_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
40 double x, y, width, height;
41 PyObject *tuple_args, *result;
42
43 if (!PyArg_ParseTupleAndKeywords (args, kwds, "dddd:Rectangle.__new__",
44 KWDS, &x, &y, &width, &height))
45 return NULL;
46
47 tuple_args = Py_BuildValue ("((dddd))", x, y, width, height);
48 if (tuple_args == NULL)
49 return NULL;
50 result = PyTuple_Type.tp_new (type, tuple_args, NULL);
51 Py_DECREF (tuple_args);
52 return result;
53 }
54
55 static PyObject*
56 rectangle_repr(PyObject *self) {
57 PyObject *format, *result;
58
59 format = PyUnicode_FromString (
60 "cairo.Rectangle(x=%r, y=%r, width=%r, height=%r)");
61 if (format == NULL)
62 return NULL;
63 result = PyUnicode_Format (format, self);
64 Py_DECREF (format);
65 return result;
66 }
67
68 static PyObject *
69 rectangle_get_x(PyObject *self, void *closure)
70 {
71 PyObject *obj = PyTuple_GetItem (self, 0);
72 Py_XINCREF (obj);
73 return obj;
74 }
75
76 static PyObject *
77 rectangle_get_y(PyObject *self, void *closure)
78 {
79 PyObject *obj = PyTuple_GetItem (self, 1);
80 Py_XINCREF (obj);
81 return obj;
82 }
83
84 static PyObject *
85 rectangle_get_width(PyObject *self, void *closure)
86 {
87 PyObject *obj = PyTuple_GetItem (self, 2);
88 Py_XINCREF (obj);
89 return obj;
90 }
91
92 static PyObject *
93 rectangle_get_height(PyObject *self, void *closure)
94 {
95 PyObject *obj = PyTuple_GetItem (self, 3);
96 Py_XINCREF (obj);
97 return obj;
98 }
99
100 static PyGetSetDef rectangle_getset[] = {
101 {"x", (getter)rectangle_get_x},
102 {"y", (getter)rectangle_get_y},
103 {"width", (getter)rectangle_get_width},
104 {"height", (getter)rectangle_get_height},
105 {NULL,},
106 };
107
108 PyTypeObject PycairoRectangle_Type = {
109 PyVarObject_HEAD_INIT(NULL, 0)
110 "cairo.Rectangle", /* tp_name */
111 sizeof(PycairRectangle), /* tp_basicsize */
112 0, /* tp_itemsize */
113 0, /* tp_dealloc */
114 0, /* tp_print */
115 0, /* tp_getattr */
116 0, /* tp_setattr */
117 0, /* tp_compare */
118 (reprfunc)rectangle_repr, /* tp_repr */
119 0, /* tp_as_number */
120 0, /* tp_as_sequence */
121 0, /* tp_as_mapping */
122 0, /* tp_hash */
123 0, /* tp_call */
124 0, /* tp_str */
125 0, /* tp_getattro */
126 0, /* tp_setattro */
127 0, /* tp_as_buffer */
128 Py_TPFLAGS_DEFAULT, /* tp_flags */
129 0, /* tp_doc */
130 0, /* tp_traverse */
131 0, /* tp_clear */
132 0, /* tp_richcompare */
133 0, /* tp_weaklistoffset */
134 0, /* tp_iter */
135 0, /* tp_iternext */
136 0, /* tp_methods */
137 0, /* tp_members */
138 rectangle_getset, /* tp_getset */
139 0, /* tp_base */
140 0, /* tp_dict */
141 0, /* tp_descr_get */
142 0, /* tp_descr_set */
143 0, /* tp_dictoffset */
144 0, /* tp_init */
145 0, /* tp_alloc */
146 (newfunc)rectangle_new, /* tp_new */
147 0, /* tp_free */
148 0, /* tp_is_gc */
149 0, /* tp_bases */
150 };