@@ -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
/* *********************************************************************
@@ -217,7 +207,7 @@ static PyObject *PyGlyph_get_bbox(PyGlyph *self, void *closure)
217
207
" llll" , self->bbox .xMin , self->bbox .yMin , self->bbox .xMax , self->bbox .yMax );
218
208
}
219
209
220
- static PyTypeObject *PyGlyph_init_type (PyObject *m, PyTypeObject *type )
210
+ static PyTypeObject *PyGlyph_init_type ()
221
211
{
222
212
static PyMemberDef members[] = {
223
213
{(char *)" width" , T_LONG, offsetof (PyGlyph, width), READONLY, (char *)" " },
@@ -237,22 +227,14 @@ static PyTypeObject *PyGlyph_init_type(PyObject *m, PyTypeObject *type)
237
227
{NULL }
238
228
};
239
229
240
- memset (type, 0 , sizeof (PyTypeObject));
241
- type->tp_name = " matplotlib.ft2font.Glyph" ;
242
- type->tp_basicsize = sizeof (PyGlyph);
243
- type->tp_dealloc = (destructor)PyGlyph_dealloc;
244
- type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
245
- type->tp_members = members;
246
- type->tp_getset = getset;
247
-
248
- if (PyType_Ready (type) < 0 ) {
249
- return NULL ;
250
- }
251
-
252
- /* Don't need to add to module, since you can't create glyphs
253
- directly from Python */
230
+ PyGlyphType.tp_name = " matplotlib.ft2font.Glyph" ;
231
+ PyGlyphType.tp_basicsize = sizeof (PyGlyph);
232
+ PyGlyphType.tp_dealloc = (destructor)PyGlyph_dealloc;
233
+ PyGlyphType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
234
+ PyGlyphType.tp_members = members;
235
+ PyGlyphType.tp_getset = getset;
254
236
255
- return type ;
237
+ return &PyGlyphType ;
256
238
}
257
239
258
240
/* *********************************************************************
@@ -270,6 +252,8 @@ typedef struct
270
252
Py_ssize_t suboffsets[2 ];
271
253
} PyFT2Font;
272
254
255
+ static PyTypeObject PyFT2FontType;
256
+
273
257
static unsigned long read_from_file_callback (FT_Stream stream,
274
258
unsigned long offset,
275
259
unsigned char *buffer,
@@ -317,8 +301,6 @@ static void close_file_callback(FT_Stream stream)
317
301
PyErr_Restore (type, value, traceback);
318
302
}
319
303
320
- static PyTypeObject PyFT2FontType;
321
-
322
304
static PyObject *PyFT2Font_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
323
305
{
324
306
PyFT2Font *self;
@@ -1448,7 +1430,7 @@ static int PyFT2Font_get_buffer(PyFT2Font *self, Py_buffer *buf, int flags)
1448
1430
return 1 ;
1449
1431
}
1450
1432
1451
- static PyTypeObject *PyFT2Font_init_type (PyObject *m, PyTypeObject *type )
1433
+ static PyTypeObject *PyFT2Font_init_type ()
1452
1434
{
1453
1435
static PyGetSetDef getset[] = {
1454
1436
{(char *)" postscript_name" , (getter)PyFT2Font_postscript_name, NULL , NULL , NULL },
@@ -1503,30 +1485,20 @@ static PyTypeObject *PyFT2Font_init_type(PyObject *m, PyTypeObject *type)
1503
1485
};
1504
1486
1505
1487
static PyBufferProcs buffer_procs;
1506
- memset (&buffer_procs, 0 , sizeof (PyBufferProcs));
1507
1488
buffer_procs.bf_getbuffer = (getbufferproc)PyFT2Font_get_buffer;
1508
1489
1509
- memset (type, 0 , sizeof (PyTypeObject));
1510
- type->tp_name = " matplotlib.ft2font.FT2Font" ;
1511
- type->tp_doc = PyFT2Font_init__doc__;
1512
- type->tp_basicsize = sizeof (PyFT2Font);
1513
- type->tp_dealloc = (destructor)PyFT2Font_dealloc;
1514
- type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
1515
- type->tp_methods = methods;
1516
- type->tp_getset = getset;
1517
- type->tp_new = PyFT2Font_new;
1518
- type->tp_init = (initproc)PyFT2Font_init;
1519
- type->tp_as_buffer = &buffer_procs;
1520
-
1521
- if (PyType_Ready (type) < 0 ) {
1522
- return NULL ;
1523
- }
1524
-
1525
- if (PyModule_AddObject (m, " FT2Font" , (PyObject *)type)) {
1526
- return NULL ;
1527
- }
1490
+ PyFT2FontType.tp_name = " matplotlib.ft2font.FT2Font" ;
1491
+ PyFT2FontType.tp_doc = PyFT2Font_init__doc__;
1492
+ PyFT2FontType.tp_basicsize = sizeof (PyFT2Font);
1493
+ PyFT2FontType.tp_dealloc = (destructor)PyFT2Font_dealloc;
1494
+ PyFT2FontType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
1495
+ PyFT2FontType.tp_methods = methods;
1496
+ PyFT2FontType.tp_getset = getset;
1497
+ PyFT2FontType.tp_new = PyFT2Font_new;
1498
+ PyFT2FontType.tp_init = (initproc)PyFT2Font_init;
1499
+ PyFT2FontType.tp_as_buffer = &buffer_procs;
1528
1500
1529
- return type ;
1501
+ return &PyFT2FontType ;
1530
1502
}
1531
1503
1532
1504
static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, " ft2font" };
@@ -1546,11 +1518,12 @@ PyMODINIT_FUNC PyInit_ft2font(void)
1546
1518
FT_Library_Version (_ft2Library, &major, &minor, &patch);
1547
1519
snprintf (version_string, sizeof (version_string), " %d.%d.%d" , major, minor, patch);
1548
1520
1549
- PyObject *m = PyModule_Create (&moduledef);
1550
- if (!m ||
1551
- !PyFT2Image_init_type (m, &PyFT2ImageType) ||
1552
- !PyGlyph_init_type (m, &PyGlyphType) ||
1553
- !PyFT2Font_init_type (m, &PyFT2FontType) ||
1521
+ PyObject *m;
1522
+ if (!(m = PyModule_Create (&moduledef)) ||
1523
+ prepare_and_add_type (PyFT2Image_init_type (), m) ||
1524
+ prepare_and_add_type (PyFT2Font_init_type (), m) ||
1525
+ // Glyph is not constructible from Python, thus not added to the module.
1526
+ PyType_Ready (PyGlyph_init_type ()) ||
1554
1527
PyModule_AddStringConstant (m, " __freetype_version__" , version_string) ||
1555
1528
PyModule_AddStringConstant (m, " __freetype_build_type__" , STRINGIFY (FREETYPE_BUILD_TYPE)) ||
1556
1529
PyModule_AddIntConstant (m, " SCALABLE" , FT_FACE_FLAG_SCALABLE) ||
0 commit comments