|
From: Albert C. <mat...@ml...> - 2006-02-26 21:11:43
|
On Sun, Feb 26, 2006 at 01:32:44PM -0600, Albert Chin wrote:
> Another alternative is to have anything requiring src/ft2font.cpp to
> simply 'import ft2font'. For the moment, I've remove src/ft2font.cpp
> from all modules except ft2font.so. This seems to work. Patch
> attached. Should I submit patches to PyImport_ImportModule("ft2font")
> as well?
Attached is a patch to import matplotlib.ft2font from
src/_backend_agg.cpp. I chose PyRun_SimpleString() rather than
PyImport_ImportModule() so the initf2font() function would be invoked
automatically.
I'm thinking that instead of:
FT2Font *font = static_cast<FT2Font*>(args[0].ptr());
we could use some Python calls to essentially duplicate
"FT2Font(args[0].ptr())" like so:
PyObject *fromlist = PyList_New (1);
PyObject *matplotlib_ft2font = PyString_FromString ("matplotlib.ft2font");
PyList_Append (fromlist, matplotlib_ft2font);
PyObject *ft2font = PyImport_ImportModuleEx("FT2Font", NULL, NULL,
fromlist);
PyObject *font = PyInstance_New (PyDict_GetItemString (ft2font,
(char *)"FT2Font"), Py_BuildValue ("s", args[0].ptr()), NULL);
Py_INCREF (font);
Of course, we'd have to expose the FT2Image members to Python but that
seems cleaner. The above might not be right but it should give an idea
of what I'm talking about (I've never embedded Python in C/C++
before).
--
albert chin (ch...@th...)
|