I got it to go on Solaris, but I keep hitting a seg
> fault on the creation of the FT2Font object around
> line 261 in backend_agg.py. It ran when I put a print
> in before the creation of the FT2Font object. That's
> right. Something spooky like that means to me that
> there is a bug in ft2font.c where some variable is not
> initialized correctly and the extra print leaves the
> right patch of initialized memory so it runs. Only
> way to really nail something like that is with a
> Purify or Valgrind like tool.
Thanks for the additional information. This one is a little harder
for me to debug since I can't replicate it. I recently rewrote the
agg backend using cxx which is really nice, and a hell of a lot easier
than doing the extension code by hand. I may do the same for
ft2font.
In the meantime, if you have some free time to either run a debugger
or just insert some sporadic prints in newFT2FontObject that would
help narrow where the segfault is occurring.
Something like
static FT2FontObject *
newFT2FontObject(PyObject *args)
{
int error;
char* facefile;
printf("initializing\n");
if (! _initLib) {
error = FT_Init_FreeType( &_ft2Library ); //initialize library
if (error) {
PyErr_SetString(PyExc_RuntimeError,
"Could not find initialize the freetype2 library");
return NULL;
}
_initLib = 1;
}
printf("parsing args\n");
if (!PyArg_ParseTuple(args, "s:FT2Font", &facefile))
return NULL;
printf("creating object\n");
FT2FontObject *self;
self = PyObject_New(FT2FontObject, &FT2Font_Type);
self->image.buffer = NULL;
self->text = NULL;
self->num_glyphs = 0;
FT2Font_clear(self);
printf("new face\n");
error = FT_New_Face( _ft2Library, facefile, 0, &self->face );
if (error == FT_Err_Unknown_File_Format ) {
set_error(PyExc_RuntimeError,
"Could not load facefile %s; Unknown_File_Format", facefile);
return NULL;
}
else if (error == FT_Err_Cannot_Open_Resource) {
set_error(PyExc_RuntimeError,
"Could not open facefile %s; Cannot_Open_Resource", facefile);
return NULL;
}
else if (error == FT_Err_Invalid_File_Format) {
set_error(PyExc_RuntimeError,
"Could not open facefile %s; Invalid_File_Format", facefile);
return NULL;
}
else if (error) {
set_error(PyExc_RuntimeError,
"Could not load face file %s; freetype error code %d", facefile, error);
return NULL;
}
printf("setting size\n");
// set a default fontsize 12 pt at 72dpi
error = FT_Set_Char_Size( self->face, 12 * 64, 0, 72, 72 );
if (error) {
PyErr_SetString(PyExc_RuntimeError,
"Could not set the fontsize");
return NULL;
}
printf("initing dict\n");
if (self == NULL)
return NULL;
self->x_attr = NULL;
printf("getting ps name\n");
// set some face props as attributes
const char* ps_name;
ps_name = FT_Get_Postscript_Name( self->face );
if ( ps_name == NULL )
ps_name = "UNAVAILABLE";
printf("setting attributes\n");
SETATTR(self, FT2Font_setattr, "postscript_name", PyString_FromString, ps_name);
SETATTR(self, FT2Font_setattr, "num_faces", PyInt_FromLong, self->face->num_faces);
SETATTR(self, FT2Font_setattr, "family_name", PyString_FromString, self->face->family_name);
SETATTR(self, FT2Font_setattr, "style_name", PyString_FromString, self->face->style_name);
SETATTR(self, FT2Font_setattr, "face_flags", PyInt_FromLong, self->face->face_flags);
SETATTR(self, FT2Font_setattr, "style_flags", PyInt_FromLong, self->face->style_flags);
SETATTR(self, FT2Font_setattr, "num_glyphs", PyInt_FromLong, self->face->num_glyphs);
SETATTR(self, FT2Font_setattr, "num_fixed_sizes", PyInt_FromLong, self->face->num_fixed_sizes);
SETATTR(self, FT2Font_setattr, "num_charmaps", PyInt_FromLong, self->face->num_charmaps);
printf("checking scalable\n");
int scalable;
scalable = FT_IS_SCALABLE( self->face );
SETATTR(self, FT2Font_setattr, "scalable", PyInt_FromLong, scalable);
if (scalable) {
SETATTR(self, FT2Font_setattr, "units_per_EM", PyInt_FromLong, self->face->units_per_EM);
printf("building bbox\n");
PyObject *bbox = Py_BuildValue
("(llll)",
self->face->bbox.xMin, self->face->bbox.yMin,
self->face->bbox.xMax, self->face->bbox.yMax );
SETATTR_PYOBJ(self, FT2Font_setattr, "bbox", bbox);
SETATTR(self, FT2Font_setattr, "ascender", PyInt_FromLong, self->face->ascender);
SETATTR(self, FT2Font_setattr, "descender", PyInt_FromLong, self->face->descender);
SETATTR(self, FT2Font_setattr, "height", PyInt_FromLong, self->face->height);
SETATTR(self, FT2Font_setattr, "max_advance_width", PyInt_FromLong, self->face->max_advance_width);
SETATTR(self, FT2Font_setattr, "max_advance_height", PyInt_FromLong, self->face->max_advance_height);
SETATTR(self, FT2Font_setattr, "underline_position", PyInt_FromLong, self->face->underline_position);
SETATTR(self, FT2Font_setattr, "underline_thickness", PyInt_FromLong, self->face->underline_thickness);
}
printf("made it!\n");
return self;
}