#include #include #include #include // typedef struct { // PyObject_HEAD // cairo_font_face_t *cairoface; // } pFT_Face; // // PyObject *getface(PyObject *self, PyObject *args); // void killface (pFT_Face *self); // // PyTypeObject pFT_Face_Type = { // PyObject_HEAD_INIT(NULL) // 0, // "Face", // sizeof(pFT_Face), // 0, // (destructor) killface, /* tp_dealloc */ // 0, /* tp_print */ // 0, /* tp_getattr */ // 0, /* tp_setattr */ // 0, /* tp_compare */ // 0, /* tp_repr */ // 0, /* tp_as_number */ // 0, /* tp_as_sequence */ // 0, /* tp_as_mapping */ // 0, /* tp_hash */ // }; PyObject* getface(PyObject *self, PyObject *args){ FT_Library library; FT_Face face; int error; //pFT_Face *pFace; char *paf; if (!PyArg_ParseTuple(args, "s", &paf)) return NULL; // pFace = PyObject_New(pFT_Face, &pFT_Face_Type); // if (!pFace) { // return NULL; // } error = FT_Init_FreeType( &library ); if ( error ) { PyErr_SetString(PyExc_TypeError, "Error initializing FreeType library"); return NULL; } error = FT_New_Face( library,paf,0,&face ); if ( error == FT_Err_Unknown_File_Format ) { PyErr_SetString(PyExc_TypeError, "The font file could be opened and read, \n but it appears that its font format is unsupported\n"); return NULL; } else if ( error ) { PyErr_SetString(PyExc_TypeError, "Font file could not be opened or otherwise is broken.\n"); return NULL; } cairo_font_face_t *cairoface; cairoface = cairo_ft_font_face_create_for_ft_face(face,0); //Py_INCREF(pFace); /* FT_Done_Face ( face ); FT_Done_FreeType( library );*/ return (PyObject*) cairoface; //Py_BuildValue("s", paf) } PyMethodDef Foo_methods[] = { { "getface", getface, METH_VARARGS }, { NULL } }; void initFoo(void) { Py_InitModule("Foo", Foo_methods); }