Debian Codegraph @

cairo/textextents.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_bearing", "y_bearing", "width", "height",
37 "x_advance", "y_advance", NULL};
38
39 static PyObject *
40 text_extents_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
41 cairo_text_extents_t e;
42 PyObject *tuple_args, *result;
43
44 if (!PyArg_ParseTupleAndKeywords (args, kwds, "dddddd:TextExtents.__new__",
45 KWDS, &e.x_bearing, &e.y_bearing, &e.width, &e.height,
46 &e.x_advance, &e.y_advance))
47 return NULL;
48
49 tuple_args = Py_BuildValue ("((dddddd))", e.x_bearing, e.y_bearing,
50 e.width, e.height, e.x_advance, e.y_advance);
51 if (tuple_args == NULL)
52 return NULL;
53 result = PyTuple_Type.tp_new (type, tuple_args, NULL);
54 Py_DECREF (tuple_args);
55 return result;
56 }
57
58 static PyObject*
59 text_extents_repr(PyObject *self) {
60 PyObject *format, *result;
61
62 format = PyUnicode_FromString (
63 "cairo.TextExtents(x_bearing=%r, y_bearing=%r, width=%r, height=%r, "
64 "x_advance=%r, y_advance=%r)");
65 if (format == NULL)
66 return NULL;
67 result = PyUnicode_Format (format, self);
68 Py_DECREF (format);
69 return result;
70 }
71
72 static PyObject *
73 text_extents_get_x_bearing(PyObject *self, void *closure)
74 {
75 PyObject *obj = PyTuple_GetItem (self, 0);
76 Py_XINCREF (obj);
77 return obj;
78 }
79
80 static PyObject *
81 text_extents_get_y_bearing(PyObject *self, void *closure)
82 {
83 PyObject *obj = PyTuple_GetItem (self, 1);
84 Py_XINCREF (obj);
85 return obj;
86 }
87
88 static PyObject *
89 text_extents_get_width(PyObject *self, void *closure)
90 {
91 PyObject *obj = PyTuple_GetItem (self, 2);
92 Py_XINCREF (obj);
93 return obj;
94 }
95
96 static PyObject *
97 text_extents_get_height(PyObject *self, void *closure)
98 {
99 PyObject *obj = PyTuple_GetItem (self, 3);
100 Py_XINCREF (obj);
101 return obj;
102 }
103
104 static PyObject *
105 text_extents_get_x_advance(PyObject *self, void *closure)
106 {
107 PyObject *obj = PyTuple_GetItem (self, 4);
108 Py_XINCREF (obj);
109 return obj;
110 }
111
112 static PyObject *
113 text_extents_get_y_advance(PyObject *self, void *closure)
114 {
115 PyObject *obj = PyTuple_GetItem (self, 5);
116 Py_XINCREF (obj);
117 return obj;
118 }
119
120 static PyGetSetDef text_cluster_getset[] = {
121 {"x_bearing", (getter)text_extents_get_x_bearing},
122 {"y_bearing", (getter)text_extents_get_y_bearing},
123 {"width", (getter)text_extents_get_width},
124 {"height", (getter)text_extents_get_height},
125 {"x_advance", (getter)text_extents_get_x_advance},
126 {"y_advance", (getter)text_extents_get_y_advance},
127 {NULL,},
128 };
129
130 PyTypeObject PycairoTextExtents_Type = {
131 PyVarObject_HEAD_INIT(NULL, 0)
132 "cairo.TextExtents", /* tp_name */
133 sizeof(PycairoTextExtents), /* tp_basicsize */
134 0, /* tp_itemsize */
135 0, /* tp_dealloc */
136 0, /* tp_print */
137 0, /* tp_getattr */
138 0, /* tp_setattr */
139 0, /* tp_compare */
140 (reprfunc)text_extents_repr, /* tp_repr */
141 0, /* tp_as_number */
142 0, /* tp_as_sequence */
143 0, /* tp_as_mapping */
144 0, /* tp_hash */
145 0, /* tp_call */
146 0, /* tp_str */
147 0, /* tp_getattro */
148 0, /* tp_setattro */
149 0, /* tp_as_buffer */
150 Py_TPFLAGS_DEFAULT, /* tp_flags */
151 0, /* tp_doc */
152 0, /* tp_traverse */
153 0, /* tp_clear */
154 0, /* tp_richcompare */
155 0, /* tp_weaklistoffset */
156 0, /* tp_iter */
157 0, /* tp_iternext */
158 0, /* tp_methods */
159 0, /* tp_members */
160 text_cluster_getset, /* tp_getset */
161 0, /* tp_base */
162 0, /* tp_dict */
163 0, /* tp_descr_get */
164 0, /* tp_descr_set */
165 0, /* tp_dictoffset */
166 0, /* tp_init */
167 0, /* tp_alloc */
168 (newfunc)text_extents_new, /* tp_new */
169 0, /* tp_free */
170 0, /* tp_is_gc */
171 0, /* tp_bases */
172 };