@@ -33,6 +33,8 @@ typedef struct
33
33
Py_ssize_t suboffsets[2 ];
34
34
} PyFT2Image;
35
35
36
+ static PyTypeObject PyFT2ImageType;
37
+
36
38
static PyObject *PyFT2Image_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
37
39
{
38
40
PyFT2Image *self;
@@ -121,9 +123,7 @@ static int PyFT2Image_get_buffer(PyFT2Image *self, Py_buffer *buf, int flags)
121
123
return 1 ;
122
124
}
123
125
124
- static PyTypeObject PyFT2ImageType;
125
-
126
- static PyTypeObject *PyFT2Image_init_type (PyObject *m, PyTypeObject *type)
126
+ static PyTypeObject* PyFT2Image_init_type ()
127
127
{
128
128
static PyMethodDef methods[] = {
129
129
{" draw_rect" , (PyCFunction)PyFT2Image_draw_rect, METH_VARARGS, PyFT2Image_draw_rect__doc__},
@@ -132,28 +132,18 @@ static PyTypeObject *PyFT2Image_init_type(PyObject *m, PyTypeObject *type)
132
132
};
133
133
134
134
static PyBufferProcs buffer_procs;
135
- memset (&buffer_procs, 0 , sizeof (PyBufferProcs));
136
135
buffer_procs.bf_getbuffer = (getbufferproc)PyFT2Image_get_buffer;
137
136
138
- memset (type, 0 , sizeof (PyTypeObject));
139
- type->tp_name = " matplotlib.ft2font.FT2Image" ;
140
- type->tp_basicsize = sizeof (PyFT2Image);
141
- type->tp_dealloc = (destructor)PyFT2Image_dealloc;
142
- type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
143
- type->tp_methods = methods;
144
- type->tp_new = PyFT2Image_new;
145
- type->tp_init = (initproc)PyFT2Image_init;
146
- type->tp_as_buffer = &buffer_procs;
147
-
148
- if (PyType_Ready (type) < 0 ) {
149
- return NULL ;
150
- }
137
+ PyFT2ImageType.tp_name = " matplotlib.ft2font.FT2Image" ;
138
+ PyFT2ImageType.tp_basicsize = sizeof (PyFT2Image);
139
+ PyFT2ImageType.tp_dealloc = (destructor)PyFT2Image_dealloc;
140
+ PyFT2ImageType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
141
+ PyFT2ImageType.tp_methods = methods;
142
+ PyFT2ImageType.tp_new = PyFT2Image_new;
143
+ PyFT2ImageType.tp_init = (initproc)PyFT2Image_init;
144
+ PyFT2ImageType.tp_as_buffer = &buffer_procs;
151
145
152
- if (PyModule_AddObject (m, " FT2Image" , (PyObject *)type)) {
153
- return NULL ;
154
- }
155
-
156
- return type;
146
+ return &PyFT2ImageType;
157
147
}
158
148
159
149
/* *********************************************************************
@@ -212,7 +202,7 @@ static PyObject *PyGlyph_get_bbox(PyGlyph *self, void *closure)
212
202
" llll" , self->bbox .xMin , self->bbox .yMin , self->bbox .xMax , self->bbox .yMax );
213
203
}
214
204
215
- static PyTypeObject *PyGlyph_init_type (PyObject *m, PyTypeObject *type )
205
+ static PyTypeObject *PyGlyph_init_type ()
216
206
{
217
207
static PyMemberDef members[] = {
218
208
{(char *)" width" , T_LONG, offsetof (PyGlyph, width), READONLY, (char *)" " },
@@ -232,22 +222,14 @@ static PyTypeObject *PyGlyph_init_type(PyObject *m, PyTypeObject *type)
232
222
{NULL }
233
223
};
234
224
235
- memset (type, 0 , sizeof (PyTypeObject));
236
- type->tp_name = " matplotlib.ft2font.Glyph" ;
237
- type->tp_basicsize = sizeof (PyGlyph);
238
- type->tp_dealloc = (destructor)PyGlyph_dealloc;
239
- type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
240
- type->tp_members = members;
241
- type->tp_getset = getset;
242
-
243
- if (PyType_Ready (type) < 0 ) {
244
- return NULL ;
245
- }
246
-
247
- /* Don't need to add to module, since you can't create glyphs
248
- directly from Python */
225
+ PyGlyphType.tp_name = " matplotlib.ft2font.Glyph" ;
226
+ PyGlyphType.tp_basicsize = sizeof (PyGlyph);
227
+ PyGlyphType.tp_dealloc = (destructor)PyGlyph_dealloc;
228
+ PyGlyphType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
229
+ PyGlyphType.tp_members = members;
230
+ PyGlyphType.tp_getset = getset;
249
231
250
- return type ;
232
+ return &PyGlyphType ;
251
233
}
252
234
253
235
/* *********************************************************************
@@ -265,6 +247,8 @@ typedef struct
265
247
Py_ssize_t suboffsets[2 ];
266
248
} PyFT2Font;
267
249
250
+ static PyTypeObject PyFT2FontType;
251
+
268
252
static unsigned long read_from_file_callback (FT_Stream stream,
269
253
unsigned long offset,
270
254
unsigned char *buffer,
@@ -312,8 +296,6 @@ static void close_file_callback(FT_Stream stream)
312
296
PyErr_Restore (type, value, traceback);
313
297
}
314
298
315
- static PyTypeObject PyFT2FontType;
316
-
317
299
static PyObject *PyFT2Font_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
318
300
{
319
301
PyFT2Font *self;
@@ -1449,7 +1431,7 @@ static int PyFT2Font_get_buffer(PyFT2Font *self, Py_buffer *buf, int flags)
1449
1431
return 1 ;
1450
1432
}
1451
1433
1452
- static PyTypeObject *PyFT2Font_init_type (PyObject *m, PyTypeObject *type )
1434
+ static PyTypeObject *PyFT2Font_init_type ()
1453
1435
{
1454
1436
static PyGetSetDef getset[] = {
1455
1437
{(char *)" postscript_name" , (getter)PyFT2Font_postscript_name, NULL , NULL , NULL },
@@ -1504,30 +1486,20 @@ static PyTypeObject *PyFT2Font_init_type(PyObject *m, PyTypeObject *type)
1504
1486
};
1505
1487
1506
1488
static PyBufferProcs buffer_procs;
1507
- memset (&buffer_procs, 0 , sizeof (PyBufferProcs));
1508
1489
buffer_procs.bf_getbuffer = (getbufferproc)PyFT2Font_get_buffer;
1509
1490
1510
- memset (type, 0 , sizeof (PyTypeObject));
1511
- type->tp_name = " matplotlib.ft2font.FT2Font" ;
1512
- type->tp_doc = PyFT2Font_init__doc__;
1513
- type->tp_basicsize = sizeof (PyFT2Font);
1514
- type->tp_dealloc = (destructor)PyFT2Font_dealloc;
1515
- type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
1516
- type->tp_methods = methods;
1517
- type->tp_getset = getset;
1518
- type->tp_new = PyFT2Font_new;
1519
- type->tp_init = (initproc)PyFT2Font_init;
1520
- type->tp_as_buffer = &buffer_procs;
1521
-
1522
- if (PyType_Ready (type) < 0 ) {
1523
- return NULL ;
1524
- }
1525
-
1526
- if (PyModule_AddObject (m, " FT2Font" , (PyObject *)type)) {
1527
- return NULL ;
1528
- }
1491
+ PyFT2FontType.tp_name = " matplotlib.ft2font.FT2Font" ;
1492
+ PyFT2FontType.tp_doc = PyFT2Font_init__doc__;
1493
+ PyFT2FontType.tp_basicsize = sizeof (PyFT2Font);
1494
+ PyFT2FontType.tp_dealloc = (destructor)PyFT2Font_dealloc;
1495
+ PyFT2FontType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
1496
+ PyFT2FontType.tp_methods = methods;
1497
+ PyFT2FontType.tp_getset = getset;
1498
+ PyFT2FontType.tp_new = PyFT2Font_new;
1499
+ PyFT2FontType.tp_init = (initproc)PyFT2Font_init;
1500
+ PyFT2FontType.tp_as_buffer = &buffer_procs;
1529
1501
1530
- return type ;
1502
+ return &PyFT2FontType ;
1531
1503
}
1532
1504
1533
1505
static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, " ft2font" };
@@ -1547,11 +1519,12 @@ PyMODINIT_FUNC PyInit_ft2font(void)
1547
1519
FT_Library_Version (_ft2Library, &major, &minor, &patch);
1548
1520
snprintf (version_string, sizeof (version_string), " %d.%d.%d" , major, minor, patch);
1549
1521
1550
- PyObject *m = PyModule_Create (&moduledef);
1551
- if (!m ||
1552
- !PyFT2Image_init_type (m, &PyFT2ImageType) ||
1553
- !PyGlyph_init_type (m, &PyGlyphType) ||
1554
- !PyFT2Font_init_type (m, &PyFT2FontType) ||
1522
+ PyObject *m;
1523
+ if (!(m = PyModule_Create (&moduledef)) ||
1524
+ prepare_and_add_type (PyFT2Image_init_type (), m) ||
1525
+ prepare_and_add_type (PyFT2Font_init_type (), m) ||
1526
+ // Glyph is not constructible from Python, thus not added to the module.
1527
+ PyType_Ready (PyGlyph_init_type ()) ||
1555
1528
PyModule_AddStringConstant (m, " __freetype_version__" , version_string) ||
1556
1529
PyModule_AddStringConstant (m, " __freetype_build_type__" , STRINGIFY (FREETYPE_BUILD_TYPE)) ||
1557
1530
PyModule_AddIntConstant (m, " SCALABLE" , FT_FACE_FLAG_SCALABLE) ||
0 commit comments