Commits

Lenard Lindstrom  committed 271935c

fix bug introduced into arrinter.py in r3208 that affects Pythons earlier than 2.7

  • Participants
  • Parent commits a976caa

Comments (0)

Files changed (8)

File src/freetype.c

  */
 static PyObject *_ftface_new(PyTypeObject *, PyObject *, PyObject *);
 static void _ftface_dealloc(PgFaceObject *);
-static PyObject *_ftface_repr(PyObject *);
-static int _ftface_init(PyObject *, PyObject *, PyObject *);
+static PyObject *_ftface_repr(PgFaceObject *);
+static int _ftface_init(PgFaceObject *, PyObject *, PyObject *);
 
 /*
  * Main methods
  */
-static PyObject *_ftface_getrect(PyObject *, PyObject *, PyObject *);
-static PyObject *_ftface_getmetrics(PyObject *, PyObject *, PyObject *);
-static PyObject *_ftface_render(PyObject *, PyObject *, PyObject *);
-static PyObject *_ftface_render_raw(PyObject *, PyObject *, PyObject *);
+static PyObject *_ftface_getrect(PgFaceObject *, PyObject *, PyObject *);
+static PyObject *_ftface_getmetrics(PgFaceObject *, PyObject *, PyObject *);
+static PyObject *_ftface_render(PgFaceObject *, PyObject *, PyObject *);
+static PyObject *_ftface_render_raw(PgFaceObject *, PyObject *, PyObject *);
 static PyObject *_ftface_getsizedascender(PgFaceObject *, PyObject *);
 static PyObject *_ftface_getsizeddescender(PgFaceObject *, PyObject *);
 static PyObject *_ftface_getsizedheight(PgFaceObject *, PyObject *);
 static PyObject *_ftface_settransform(PgFaceObject *, PyObject *);
 static PyObject *_ftface_deletetransform(PgFaceObject *);
 
-/* static PyObject *_ftface_copy(PyObject *); */
+/* static PyObject *_ftface_copy(PgFaceObject *); */
 
 /*
  * Getters/setters
  */
-static PyObject *_ftface_getstyle(PyObject *, void *);
-static int _ftface_setstyle(PyObject *, PyObject *, void *);
-static PyObject *_ftface_getheight(PyObject *, void *);
-static PyObject *_ftface_getascender(PyObject *, void *);
-static PyObject *_ftface_getdescender(PyObject *, void *);
-static PyObject *_ftface_getname(PyObject *, void *);
-static PyObject *_ftface_getpath(PyObject *, void *);
-static PyObject *_ftface_getfixedwidth(PyObject *, void *);
+static PyObject *_ftface_getstyle(PgFaceObject *, void *);
+static int _ftface_setstyle(PgFaceObject *, PyObject *, void *);
+static PyObject *_ftface_getname(PgFaceObject *, void *);
+static PyObject *_ftface_getpath(PgFaceObject *, void *);
+static PyObject *_ftface_getfixedwidth(PgFaceObject *, void *);
 static PyObject *_ftface_getstrength(PgFaceObject *, void *);
 static int _ftface_setstrength(PgFaceObject *, PyObject *, void *);
 static PyObject *_ftface_getunderlineadjustment(PgFaceObject *, void *);
 static int _ftface_setunderlineadjustment(PgFaceObject *, PyObject *, void *);
 
-static PyObject *_ftface_getvertical(PyObject *, void *);
-static int _ftface_setvertical(PyObject *, PyObject *, void *);
-static PyObject *_ftface_getantialias(PyObject *, void *);
-static int _ftface_setantialias(PyObject *, PyObject *, void *);
-static PyObject *_ftface_getkerning(PyObject *, void *);
-static int _ftface_setkerning(PyObject *, PyObject *, void *);
-static PyObject *_ftface_getucs4(PyObject *, void *);
-static int _ftface_setucs4(PyObject *, PyObject *, void *);
-static PyObject *_ftface_getorigin(PyObject *, void *);
-static int _ftface_setorigin(PyObject *, PyObject *, void *);
-static PyObject *_ftface_getpad(PyObject *, void *);
-static int _ftface_setpad(PyObject *, PyObject *, void *);
+static PyObject *_ftface_getresolution(PgFaceObject *, void *);
 
-static PyObject *_ftface_getresolution(PyObject *, void *);
+static PyObject *_ftface_getfacemetric(PgFaceObject *, void *);
 
-static PyObject *_ftface_getstyle_flag(PyObject *, void *);
-static int _ftface_setstyle_flag(PyObject *, PyObject *, void *);
+static PyObject *_ftface_getstyle_flag(PgFaceObject *, void *);
+static int _ftface_setstyle_flag(PgFaceObject *, PyObject *, void *);
+
+static PyObject *_ftface_getrender_flag(PgFaceObject *, void *);
+static int _ftface_setrender_flag(PgFaceObject *, PyObject *, void *);
 
 #if defined(PGFT_DEBUG_CACHE)
-static PyObject *_ftface_getdebugcachestats(PyObject *, void *);
+static PyObject *_ftface_getdebugcachestats(PgFaceObject *, void *);
 #endif
 
 /*
     },
     {
         "height",
-        (getter)_ftface_getheight,
+        (getter)_ftface_getfacemetric,
         0,
         DOC_FACEHEIGHT,
-        0
+        (void *)_PGFT_Face_GetHeight
     },
     {
         "ascender",
-        (getter)_ftface_getascender,
+        (getter)_ftface_getfacemetric,
         0,
         DOC_FACEASCENDER,
-        0
+        (void *)_PGFT_Face_GetAscender
     },
     {
         "descender",
-        (getter)_ftface_getdescender,
+        (getter)_ftface_getfacemetric,
         0,
         DOC_FACEASCENDER,
-        0
+        (void *)_PGFT_Face_GetDescender
     },
     {
         "name",
     },
     {
         "antialiased",
-        (getter)_ftface_getantialias,
-        (setter)_ftface_setantialias,
+        (getter)_ftface_getrender_flag,
+        (setter)_ftface_setrender_flag,
         DOC_FACEANTIALIASED,
-        0
+        (void *)FT_RFLAG_ANTIALIAS
     },
     {
         "kerning",
-        (getter)_ftface_getkerning,
-        (setter)_ftface_setkerning,
+        (getter)_ftface_getrender_flag,
+        (setter)_ftface_setrender_flag,
         DOC_FACEKERNING,
-        0
+        (void *)FT_RFLAG_KERNING
     },
     {
         "vertical",
-        (getter)_ftface_getvertical,
-        (setter)_ftface_setvertical,
+        (getter)_ftface_getrender_flag,
+        (setter)_ftface_setrender_flag,
         DOC_FACEVERTICAL,
-        0
+        (void *)FT_RFLAG_VERTICAL
     },
     {
         "pad",
-        (getter)_ftface_getpad,
-        (setter)_ftface_setpad,
+        (getter)_ftface_getrender_flag,
+        (setter)_ftface_setrender_flag,
         DOC_FACEPAD,
-        0
+        (void *)FT_RFLAG_PAD
     },
     {
         "oblique",
     },
     {
         "ucs4",
-        (getter)_ftface_getucs4,
-        (setter)_ftface_setucs4,
+        (getter)_ftface_getrender_flag,
+        (setter)_ftface_setrender_flag,
         DOC_FACEUCS4,
-        0
+        (void *)FT_RFLAG_UCS4
     },
     {
         "resolution",
     },
     {
         "origin",
-        (getter)_ftface_getorigin,
-        (setter)_ftface_setorigin,
+        (getter)_ftface_getrender_flag,
+        (setter)_ftface_setrender_flag,
         DOC_FACEORIGIN,
-        0
+        (void *)FT_RFLAG_ORIGIN
     },
 #if defined(PGFT_DEBUG_CACHE)
     {
         obj->_internals = 0;
         obj->ptsize = -1;
         obj->style = FT_STYLE_NORMAL;
+        obj->render_flags = FT_RFLAG_DEFAULTS;
         obj->strength = PGFT_DBL_DEFAULT_STRENGTH;
         obj->underline_adjustment = 1.0;
-        obj->vertical = 0;
-        obj->antialias = 1;
-        obj->kerning = 0;
-        obj->ucs4 = 0;
-        obj->origin = 0;
-	obj->pad = 0;
-        obj->do_transform = 0;
         obj->transform.xx = FX16_ONE;
         obj->transform.xy = 0;
         obj->transform.yx = 0;
 }
 
 static int
-_ftface_init(PyObject *self, PyObject *args, PyObject *kwds)
+_ftface_init(PgFaceObject *self, PyObject *args, PyObject *kwds)
 {
     static char *kwlist[] =  {
         "font", "ptsize", "style", "face_index", "vertical",
         "ucs4", "resolution", "origin", 0
     };
 
-    PgFaceObject *font = (PgFaceObject *)self;
-
     PyObject *file, *original_file;
     int face_index = 0;
     int ptsize;
-    int font_style;
+    int style;
     int ucs4;
     int vertical;
     unsigned resolution = 0;
     FreeTypeInstance *ft;
     ASSERT_GRAB_FREETYPE(ft, -1);
 
-    ptsize = font->ptsize;
-    font_style = font->style;
-    ucs4 = font->ucs4;
-    vertical = font->vertical;
-    origin = font->origin;
+    ptsize = self->ptsize;
+    style = self->style;
+    ucs4 = self->render_flags & FT_RFLAG_UCS4 ? 1 : 0;
+    vertical = self->render_flags & FT_RFLAG_VERTICAL ? 1 : 0;
+    origin = self->render_flags & FT_RFLAG_ORIGIN ? 1 : 0;
 
     if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iiIiiIi", kwlist,
-                                     &file, &ptsize, &font_style, &face_index,
+                                     &file, &ptsize, &style, &face_index,
                                      &vertical, &ucs4, &resolution, &origin)) {
         return -1;
     }
 
     original_file = file;
 
-    _PGFT_UnloadFace(ft, font);
-    Py_XDECREF(font->path);
-    font->path = 0;
+    _PGFT_UnloadFace(ft, self);
+    Py_XDECREF(self->path);
+    self->path = 0;
 
-    if (_PGFT_CheckStyle(font_style)) {
+    if (_PGFT_CheckStyle(style)) {
         PyErr_Format(PyExc_ValueError,
-                     "Invalid style value %x", (int)font_style);
+                     "Invalid style value %x", (int)style);
         return -1;
     }
-    font->ptsize = (FT_Int16)((ptsize <= 0) ? -1 : ptsize);
-    font->style = (FT_Byte)font_style;
-    font->ucs4 = ucs4 ? (FT_Byte)1 : (FT_Byte)0;
-    font->vertical = vertical;
-    font->origin = (FT_Byte)origin;
-    if (resolution) {
-        font->resolution = (FT_UInt)resolution;
+    self->ptsize = (FT_Int16)((ptsize <= 0) ? -1 : ptsize);
+    self->style = (FT_Int16)style;
+    if (ucs4) {
+        self->render_flags |= FT_RFLAG_UCS4;
     }
     else {
-        font->resolution = FREETYPE_STATE->resolution;
+        self->render_flags &= ~FT_RFLAG_UCS4;
+    }
+    if (vertical) {
+        self->render_flags |= FT_RFLAG_VERTICAL;
+    }
+    else {
+        self->render_flags &= ~FT_RFLAG_VERTICAL;
+    }
+    if (origin) {
+        self->render_flags |= FT_RFLAG_ORIGIN;
+    }
+    else {
+        self->render_flags &= ~FT_RFLAG_ORIGIN;
+    }
+    if (resolution) {
+        self->resolution = (FT_UInt)resolution;
+    }
+    else {
+        self->resolution = FREETYPE_STATE->resolution;
     }
     if (file == Py_None) {
         file = load_font_res(DEFAULT_FONT_NAME);
         return -1;
     }
     if (Bytes_Check(file)) {
-        if (_PGFT_TryLoadFont_Filename(ft, font, Bytes_AS_STRING(file),
+        if (_PGFT_TryLoadFont_Filename(ft, self, Bytes_AS_STRING(file),
                                        face_index)) {
             goto end;
         }
              * cycles from a derived class. This means no tp_traverse or
              * tp_clear for the PyFreetypeFont type.
              */
-            font->path = Object_Unicode(original_file);
+            self->path = Object_Unicode(original_file);
         }
         else {
-            font->path = PyUnicode_FromEncodedObject(file, "raw_unicode_escape",
+            self->path = PyUnicode_FromEncodedObject(file, "raw_unicode_escape",
                                                      "replace");
         }
     }
             goto end;
         }
 
-        if (_PGFT_TryLoadFont_RWops(ft, font, source, face_index)) {
+        if (_PGFT_TryLoadFont_RWops(ft, self, source, face_index)) {
             goto end;
         }
 
             str = Bytes_FromFormat("<%s instance at %p>",
                                    Py_TYPE(file)->tp_name, (void *)file);
             if (str) {
-                font->path = PyUnicode_FromEncodedObject(str,
+                self->path = PyUnicode_FromEncodedObject(str,
                                                          "ascii", "strict");
                 Py_DECREF(str);
             }
              * cycles from a derived class. This means no tp_traverse or
              * tp_clear for the PyFreetypeFont type.
              */
-            font->path = Object_Unicode(path);
+            self->path = Object_Unicode(path);
         }
         else if (Bytes_Check(path)) {
-            font->path = PyUnicode_FromEncodedObject(path,
+            self->path = PyUnicode_FromEncodedObject(path,
                                                "unicode_escape", "replace");
         }
         else {
-            font->path = Object_Unicode(path);
+            self->path = Object_Unicode(path);
         }
         Py_XDECREF(path);
     }
 }
 
 static PyObject *
-_ftface_repr(PyObject *self)
+_ftface_repr(PgFaceObject *self)
 {
-    PgFaceObject *font = (PgFaceObject *)self;
-
-    if (PgFace_IS_ALIVE(font)) {
+    if (PgFace_IS_ALIVE(self)) {
 #if PY3
-        return PyUnicode_FromFormat("Face('%.1024u')", font->path);
+        return PyUnicode_FromFormat("Face('%.1024u')", self->path);
 #else
-        PyObject *str = PyUnicode_AsEncodedString(font->path,
+        PyObject *str = PyUnicode_AsEncodedString(self->path,
                                                   "raw_unicode_escape",
                                                   "replace");
         PyObject *rval = 0;
  * GETTERS/SETTERS
  ****************************************************/
 
-/** Vertical attribute */
+/** Generic style attributes */
 static PyObject *
-_ftface_getvertical(PyObject *self, void *closure)
+_ftface_getstyle_flag(PgFaceObject *self, void *closure)
 {
-    PgFaceObject *font = (PgFaceObject *)self;
+    const int style_flag = (int)closure;
 
-    return PyBool_FromLong(font->vertical);
+    return PyBool_FromLong(self->style & style_flag);
 }
 
 static int
-_ftface_setvertical(PyObject *self, PyObject *value, void *closure)
-{
-    PgFaceObject *font = (PgFaceObject *)self;
-
-    if (!PyBool_Check(value)) {
-        PyErr_SetString(PyExc_TypeError, "Expecting 'bool' type");
-        return -1;
-    }
-    font->vertical = (FT_Byte)PyObject_IsTrue(value);
-    return 0;
-}
-
-
-/** Antialias attribute */
-static PyObject *
-_ftface_getantialias(PyObject *self, void *closure)
-{
-    PgFaceObject *font = (PgFaceObject *)self;
-
-    return PyBool_FromLong(font->antialias);
-}
-
-static int
-_ftface_setantialias(PyObject *self, PyObject *value, void *closure)
-{
-    PgFaceObject *font = (PgFaceObject *)self;
-
-    if (!PyBool_Check(value)) {
-        PyErr_SetString(PyExc_TypeError, "Expecting 'bool' type");
-        return -1;
-    }
-    font->antialias = (FT_Byte)PyObject_IsTrue(value);
-    return 0;
-}
-
-
-/** kerning attribute */
-static PyObject *
-_ftface_getkerning(PyObject *self, void *closure)
-{
-    PgFaceObject *font = (PgFaceObject *)self;
-
-    return PyBool_FromLong(font->kerning);
-}
-
-static int
-_ftface_setkerning(PyObject *self, PyObject *value, void *closure)
-{
-    PgFaceObject *font = (PgFaceObject *)self;
-
-    if (!PyBool_Check(value)) {
-        PyErr_SetString(PyExc_TypeError, "Expecting 'bool' type");
-        return -1;
-    }
-    font->kerning = (FT_Byte)PyObject_IsTrue(value);
-    return 0;
-}
-
-
-/** Generic style attributes */
-static PyObject *
-_ftface_getstyle_flag(PyObject *self, void *closure)
+_ftface_setstyle_flag(PgFaceObject *self, PyObject *value, void *closure)
 {
     const int style_flag = (int)closure;
-    PgFaceObject *font = (PgFaceObject *)self;
-
-    return PyBool_FromLong(font->style & style_flag);
-}
-
-static int
-_ftface_setstyle_flag(PyObject *self, PyObject *value, void *closure)
-{
-    const int style_flag = (int)closure;
-    PgFaceObject *font = (PgFaceObject *)self;
 
     if (!PyBool_Check(value)) {
         PyErr_SetString(PyExc_TypeError,
     }
 
     if (PyObject_IsTrue(value)) {
-        font->style |= (FT_Byte)style_flag;
+        self->style |= (FT_UInt16)style_flag;
     }
     else {
-        font->style &= (FT_Byte)(~style_flag);
+        self->style &= (FT_UInt16)(~style_flag);
     }
 
     return 0;
 
 /** Style attribute */
 static PyObject *
-_ftface_getstyle (PyObject *self, void *closure)
+_ftface_getstyle (PgFaceObject *self, void *closure)
 {
-    PgFaceObject *font = (PgFaceObject *)self;
-
-    return PyInt_FromLong(font->style);
+    return PyInt_FromLong(self->style);
 }
 
 static int
-_ftface_setstyle(PyObject *self, PyObject *value, void *closure)
+_ftface_setstyle(PgFaceObject *self, PyObject *value, void *closure)
 {
-    PgFaceObject *font = (PgFaceObject *)self;
     FT_UInt32 style;
 
     if (!PyInt_Check(value)) {
         return -1;
     }
 
-    font->style = (FT_Byte)style;
+    self->style = (FT_UInt16)style;
     return 0;
 }
 
 static PyObject *
-_ftface_getascender(PyObject *self, void *closure)
-{
-    FreeTypeInstance *ft;
-    long height;
-    ASSERT_GRAB_FREETYPE(ft, 0);
-
-    ASSERT_SELF_IS_ALIVE(self);
-    height = _PGFT_Face_GetAscender(ft, (PgFaceObject *)self);
-    if (!height && PyErr_Occurred()) {
-        return 0;
-    }
-    return PyInt_FromLong(height);
-}
-
-static PyObject *
-_ftface_getdescender(PyObject *self, void *closure)
-{
-    FreeTypeInstance *ft;
-    long height;
-    ASSERT_GRAB_FREETYPE(ft, 0);
-
-    ASSERT_SELF_IS_ALIVE(self);
-    height = _PGFT_Face_GetDescender(ft, (PgFaceObject *)self);
-    if (!height && PyErr_Occurred()) {
-        return 0;
-    }
-    return PyInt_FromLong(height);
-}
-
-static PyObject *
-_ftface_getheight(PyObject *self, void *closure)
-{
-    FreeTypeInstance *ft;
-    long height;
-    ASSERT_GRAB_FREETYPE(ft, 0);
-
-    ASSERT_SELF_IS_ALIVE(self);
-    height = _PGFT_Face_GetHeight(ft, (PgFaceObject *)self);
-    if (!height && PyErr_Occurred()) {
-        return 0;
-    }
-    return PyInt_FromLong(height);
-}
-
-static PyObject *
-_ftface_getname(PyObject *self, void *closure)
-{
-    FreeTypeInstance *ft;
-    const char *name;
-    ASSERT_GRAB_FREETYPE(ft, 0);
-
-    if (PgFace_IS_ALIVE(self)) {
-        name = _PGFT_Face_GetName(ft, (PgFaceObject *)self);
-        return name ? Text_FromUTF8(name) : 0;
-    }
-    return PyObject_Repr(self);
-}
-
-static PyObject *
-_ftface_getpath(PyObject *self, void *closure)
-{
-    PyObject *path = ((PgFaceObject *)self)->path;
-
-    if (!path) {
-        PyErr_SetString(PyExc_AttributeError, "path unavailable");
-        return 0;
-    }
-    Py_INCREF(path);
-    return path;
-}
-
-static PyObject *
-_ftface_getfixedwidth(PyObject *self, void *closure)
-{
-    FreeTypeInstance *ft;
-    long fixed_width;
-    ASSERT_GRAB_FREETYPE(ft, 0);
-
-    ASSERT_SELF_IS_ALIVE(self);
-    fixed_width = _PGFT_Face_IsFixedWidth(ft, (PgFaceObject *)self);
-    return fixed_width >= 0 ? PyBool_FromLong(fixed_width) : 0;
-}
-
-static PyObject *
 _ftface_getstrength(PgFaceObject *self, void *closure)
 {
     return PyFloat_FromDouble(self->strength);
 }
 
 
-/** ucs4 unicode text handling attribute */
+/** general face attributes */
+
 static PyObject *
-_ftface_getucs4(PyObject *self, void *closure)
+_ftface_getfacemetric(PgFaceObject *self, void *closure)
 {
-    PgFaceObject *font = (PgFaceObject *)self;
+    typedef long (*getter)(FreeTypeInstance *, PgFaceObject *);
+    FreeTypeInstance *ft;
+    long height;
+    ASSERT_GRAB_FREETYPE(ft, 0);
 
-    return PyBool_FromLong(font->ucs4);
+    ASSERT_SELF_IS_ALIVE(self);
+    height = ((getter)closure)(ft, self);
+    if (!height && PyErr_Occurred()) {
+        return 0;
+    }
+    return PyInt_FromLong(height);
+}
+
+static PyObject *
+_ftface_getname(PgFaceObject *self, void *closure)
+{
+    FreeTypeInstance *ft;
+    const char *name;
+    ASSERT_GRAB_FREETYPE(ft, 0);
+
+    if (PgFace_IS_ALIVE(self)) {
+        name = _PGFT_Face_GetName(ft, self);
+        return name ? Text_FromUTF8(name) : 0;
+    }
+    return PyObject_Repr((PyObject *)self);
+}
+
+static PyObject *
+_ftface_getpath(PgFaceObject *self, void *closure)
+{
+    PyObject *path = ((PgFaceObject *)self)->path;
+
+    if (!path) {
+        PyErr_SetString(PyExc_AttributeError, "path unavailable");
+        return 0;
+    }
+    Py_INCREF(path);
+    return path;
+}
+
+static PyObject *
+_ftface_getfixedwidth(PgFaceObject *self, void *closure)
+{
+    FreeTypeInstance *ft;
+    long fixed_width;
+    ASSERT_GRAB_FREETYPE(ft, 0);
+
+    ASSERT_SELF_IS_ALIVE(self);
+    fixed_width = _PGFT_Face_IsFixedWidth(ft, (PgFaceObject *)self);
+    return fixed_width >= 0 ? PyBool_FromLong(fixed_width) : 0;
+}
+
+
+/** Generic render flag attributes */
+static PyObject *
+_ftface_getrender_flag(PgFaceObject *self, void *closure)
+{
+    const int render_flag = (int)closure;
+
+    return PyBool_FromLong(self->render_flags & render_flag);
 }
 
 static int
-_ftface_setucs4(PyObject *self, PyObject *value, void *closure)
+_ftface_setrender_flag(PgFaceObject *self, PyObject *value, void *closure)
 {
-    PgFaceObject *font = (PgFaceObject *)self;
+    const int render_flag = (int)closure;
 
     if (!PyBool_Check(value)) {
-        PyErr_SetString(PyExc_TypeError, "Expecting 'bool' type");
+        PyErr_SetString(PyExc_TypeError,
+                "The style value must be a boolean");
         return -1;
     }
-    font->ucs4 = (FT_Byte)PyObject_IsTrue(value);
+
+    if (PyObject_IsTrue(value)) {
+        self->render_flags |= (FT_UInt16)render_flag;
+    }
+    else {
+        self->render_flags &= (FT_UInt16)(~render_flag);
+    }
+
     return 0;
 }
 
 
-/** render at text origin attribute */
+/** resolution pixel size attribute */
 static PyObject *
-_ftface_getorigin(PyObject *self, void *closure)
+_ftface_getresolution(PgFaceObject *self, void *closure)
 {
-    PgFaceObject *font = (PgFaceObject *)self;
-
-    return PyBool_FromLong(font->origin);
+    return PyLong_FromUnsignedLong((unsigned long)self->resolution);
 }
 
-static int
-_ftface_setorigin(PyObject *self, PyObject *value, void *closure)
-{
-    PgFaceObject *font = (PgFaceObject *)self;
-
-    if (!PyBool_Check(value)) {
-        PyErr_SetString(PyExc_TypeError, "Expecting 'bool' type");
-        return -1;
-    }
-    font->origin = (FT_Byte)PyObject_IsTrue(value);
-    return 0;
-}
-
-
-/** pad bounding box as font.Face does */
-static PyObject *
-_ftface_getpad(PyObject *self, void *closure)
-{
-    PgFaceObject *font = (PgFaceObject *)self;
-
-    return PyBool_FromLong(font->pad);
-}
-
-static int
-_ftface_setpad(PyObject *self, PyObject *value, void *closure)
-{
-    PgFaceObject *font = (PgFaceObject *)self;
-
-    if (!PyBool_Check(value)) {
-        PyErr_SetString(PyExc_TypeError, "Expecting 'bool' type");
-        return -1;
-    }
-    font->pad = (FT_Byte)PyObject_IsTrue(value);
-    return 0;
-}
-
-
-/** resolution pixel size attribute */
-static PyObject *
-_ftface_getresolution(PyObject *self, void *closure)
-{
-    PgFaceObject *font = (PgFaceObject *)self;
-
-    return PyLong_FromUnsignedLong((unsigned long)font->resolution);
-}
-
 
 /** testing and debugging */
-#if defined(_PGFT_DEBUG_CACHE)
+#if defined(PGFT_DEBUG_CACHE)
 static PyObject *
-_ftface_getdebugcachestats(PyObject *self, void *closure)
+_ftface_getdebugcachestats(PgFaceObject *self, void *closure)
 {
     /* Yes, this kind of breaches the boundary between the top level
      * freetype.c and the lower level ft_text.c. But it is built
      * of ft_text.c and ft_cache.c (hoping to remove the Python
      * api completely from ft_text.c and support C modules at some point.)
      */
-    const FaceCache *cache = &PGFT_FACE_CACHE((PgFaceObject *)self);
+    const FaceCache *cache = &PGFT_FACE_CACHE(self);
 
     return Py_BuildValue("kkkkk",
                          (unsigned long)cache->_debug_count,
  * MAIN METHODS
  ****************************************************/
 static PyObject *
-_ftface_getrect(PyObject *self, PyObject *args, PyObject *kwds)
+_ftface_getrect(PgFaceObject *self, PyObject *args, PyObject *kwds)
 {
 /* MODIFIED
  */
         "text", "style", "rotation", "ptsize", 0
     };
 
-    PgFaceObject *font = (PgFaceObject *)self;
     PyObject *textobj;
     PGFT_String *text;
     PyObject *rectobj = 0;
     }
 
     /* Encode text */
-    text = _PGFT_EncodePyString(textobj, font->ucs4);
+    text = _PGFT_EncodePyString(textobj, self->render_flags & FT_RFLAG_UCS4);
     if (!text) {
         return 0;
     }
     ASSERT_SELF_IS_ALIVE(self);
 
     /* Build rendering mode, always anti-aliased by default */
-    if (_PGFT_BuildRenderMode(ft, font, &render,
+    if (_PGFT_BuildRenderMode(ft, self, &render,
                              ptsize, style, rotation)) {
         return 0;
     }
 
-    error = _PGFT_GetTextRect(ft, font, &render, text, &r);
+    error = _PGFT_GetTextRect(ft, self, &render, text, &r);
     _PGFT_FreeString(text);
 
     if (!error) {
 
 static PyObject *
 get_metrics(FreeTypeInstance *ft, FaceRenderMode *render,
-          PgFaceObject *font, PGFT_String *text)
+          PgFaceObject *face, PGFT_String *text)
 {
     Py_ssize_t length = PGFT_String_GET_LENGTH(text);
     PGFT_char *data = PGFT_String_GET_DATA(text);
         return 0;
     }
     for (i = 0; i < length; ++i) {
-        if (_PGFT_GetMetrics(ft, font, data[i], render,
+        if (_PGFT_GetMetrics(ft, face, data[i], render,
                              &gindex, &minx, &maxx, &miny, &maxy,
                              &advance_x, &advance_y) == 0) {
             if (gindex == 0) {
 }
 
 static PyObject *
-_ftface_getmetrics(PyObject *self, PyObject *args, PyObject *kwds)
+_ftface_getmetrics(PgFaceObject *self, PyObject *args, PyObject *kwds)
 {
     /* keyword list */
     static char *kwlist[] =  {
         "text", "ptsize", 0
     };
 
-    PgFaceObject *font = (PgFaceObject *)self;
     FaceRenderMode render;
     PyObject *list = 0;
 
     }
 
     /* Encode text */
-    text = _PGFT_EncodePyString(textobj, font->ucs4);
+    text = _PGFT_EncodePyString(textobj, self->render_flags & FT_RFLAG_UCS4);
     if (!text) {
         return 0;
     }
      * Build the render mode with the given size and no
      * rotation/styles/vertical text
      */
-    if (_PGFT_BuildRenderMode(ft, font, &render, ptsize, FT_STYLE_NORMAL, 0)) {
+    if (_PGFT_BuildRenderMode(ft, self, &render, ptsize, FT_STYLE_NORMAL, 0)) {
         _PGFT_FreeString(text);
         return 0;
     }
 
     /* get metrics */
-    list = get_metrics(ft, &render, font, text);
+    list = get_metrics(ft, &render, self, text);
 
     _PGFT_FreeString(text);
     return list;
 }
 
 static PyObject *
-_ftface_render_raw(PyObject *self, PyObject *args, PyObject *kwds)
+_ftface_render_raw(PgFaceObject *self, PyObject *args, PyObject *kwds)
 {
     /* keyword list */
     static char *kwlist[] =  {
         "text", "style", "rotation", "ptsize", 0
     };
 
-    PgFaceObject *font = (PgFaceObject *)self;
-    FaceRenderMode render;
+    FaceRenderMode mode;
 
     /* input arguments */
     PyObject *textobj;
     }
 
     /* Encode text */
-    text = _PGFT_EncodePyString(textobj, font->ucs4);
+    text = _PGFT_EncodePyString(textobj, self->render_flags & FT_RFLAG_UCS4);
     if (!text) {
         return 0;
     }
      * Build the render mode with the given size and no
      * rotation/styles/vertical text
      */
-    if (_PGFT_BuildRenderMode(ft, font, &render, ptsize, style, rotation)) {
+    if (_PGFT_BuildRenderMode(ft, self, &mode, ptsize, style, rotation)) {
         _PGFT_FreeString(text);
         return 0;
     }
 
-    rbuffer = _PGFT_Render_PixelArray(ft, font, &render, text, &width, &height);
+    rbuffer = _PGFT_Render_PixelArray(ft, self, &mode, text, &width, &height);
     _PGFT_FreeString(text);
 
     if (!rbuffer) {
 }
 
 static PyObject *
-_ftface_render(PyObject *self, PyObject *args, PyObject *kwds)
+_ftface_render(PgFaceObject *self, PyObject *args, PyObject *kwds)
 {
 #ifndef HAVE_PYGAME_SDL_VIDEO
 
         "style", "rotation", "ptsize", 0
     };
 
-    PgFaceObject *font = (PgFaceObject *)self;
-
     /* input arguments */
     PyObject *textobj = 0;
     PGFT_String *text;
     }
 
     /* Encode text */
-    text = _PGFT_EncodePyString(textobj, font->ucs4);
+    text = _PGFT_EncodePyString(textobj, self->render_flags & FT_RFLAG_UCS4);
     if (!text) {
         return 0;
     }
 
     ASSERT_SELF_IS_ALIVE(self);
 
-    if (_PGFT_BuildRenderMode(ft, font, &render, ptsize, style, rotation)) {
+    if (_PGFT_BuildRenderMode(ft, self, &render, ptsize, style, rotation)) {
         _PGFT_FreeString(text);
         return 0;
     }
     if (dest == Py_None) {
         SDL_Surface *r_surface = 0;
 
-        r_surface = _PGFT_Render_NewSurface(ft, font, &render, text, &fg_color,
+        r_surface = _PGFT_Render_NewSurface(ft, self, &render, text, &fg_color,
                                             bg_color_obj ? &bg_color : 0,
                                             &r);
         _PGFT_FreeString(text);
 
         surface = PySurface_AsSurface(surface_obj);
 
-        rcode = _PGFT_Render_ExistingSurface(ft, font, &render, text, surface,
+        rcode = _PGFT_Render_ExistingSurface(ft, self, &render, text, surface,
                                              xpos, ypos, &fg_color,
                                              bg_color_obj ? &bg_color : 0,
                                              &r);
 static PyObject *
 _ftface_gettransform(PgFaceObject *self)
 {
-    if (!self->do_transform) {
+    if (!(self->render_flags & FT_RFLAG_TRANSFORM)) {
         Py_RETURN_NONE;
     }
     return Py_BuildValue("dddd",
     self->transform.xy = FX16_TO_DBL(xy);
     self->transform.yx = FX16_TO_DBL(yx);
     self->transform.yy = FX16_TO_DBL(yy);
-    self->do_transform = 1;
+    self->render_flags |= FT_RFLAG_TRANSFORM;
     Py_RETURN_NONE;
 }
 
 static PyObject *
 _ftface_deletetransform(PgFaceObject *self)
 {
-    self->do_transform = 0;
+    self->render_flags &= ~FT_RFLAG_TRANSFORM;
     self->transform.xx = 0x00010000;
     self->transform.xy = 0x00000000;
     self->transform.yx = 0x00000000;

File src/freetype.h

 #define FT_RFLAG_KERNING        (1 << 4)
 #define FT_RFLAG_TRANSFORM      (1 << 5)
 #define FT_RFLAG_PAD            (1 << 6)
-#define FT_RFLAG_DEFAULTS       (FT_RFLAG_NONE | FT_RFLAG_HINTED)
+#define FT_RFLAG_ORIGIN         (1 << 7)
+#define FT_RFLAG_UCS4           (1 << 8)
+#define FT_RFLAG_DEFAULTS       (FT_RFLAG_HINTED | FT_RFLAG_ANTIALIAS)
 
 
 #define FT_RENDER_NEWBYTEARRAY      0x0
     PyObject *path;
 
     FT_Int16 ptsize;
-    FT_Byte style;
+    FT_Int16 style;
+    FT_Int16 render_flags;
     double strength;
     double underline_adjustment;
-    FT_Byte vertical;
-    FT_Byte antialias;
-    FT_Byte kerning;
-    FT_Byte ucs4;
     FT_UInt resolution;
-    FT_Byte origin;
-    FT_Byte pad;
-    FT_Byte do_transform;
     FT_Matrix transform;
 
     void *_internals;

File src/freetype/ft_render.c

 
         pt_size = faceobj->ptsize;
     }
-
     if (pt_size <= 0) {
         PyErr_SetString(PyExc_ValueError, "Invalid point size for font.");
         return -1;
     }
-
     mode->pt_size = (FT_UInt16)pt_size;
 
     if (style == FT_STYLE_DEFAULT) {
-        mode->style = (FT_Byte)faceobj->style;
+        mode->style = faceobj->style;
     }
     else {
         if (_PGFT_CheckStyle((FT_UInt32)style)) {
             return -1;
         }
 
-        mode->style = (FT_Byte)style;
+        mode->style = (FT_UInt16)style;
     }
     mode->strength = DBL_TO_FX16(faceobj->strength);
 
-    mode->render_flags = FT_RFLAG_DEFAULTS;
-
-    if (faceobj->vertical) {
-        mode->render_flags |= FT_RFLAG_VERTICAL;
-    }
-    if (faceobj->antialias) {
-        mode->render_flags |= FT_RFLAG_ANTIALIAS;
-    }
-    if (faceobj->pad) {
-        mode->render_flags |= FT_RFLAG_PAD;
-    }
-
+    mode->render_flags = faceobj->render_flags;
     angle = rotation % 360;
     while (angle < 0) angle += 360;
     mode->rotation_angle = INT_TO_FX16(angle);
-
-    if (faceobj->do_transform) {
-        mode->render_flags |= FT_RFLAG_TRANSFORM;
-    }
     mode->transform = faceobj->transform;
 
     if (mode->rotation_angle != 0) {
     font_surf.buffer = surface->pixels;
     font_surf.offset.x = INT_TO_FX6(x);
     font_surf.offset.y = INT_TO_FX6(y);
-    if (faceobj->origin) {
+    if (mode->render_flags & FT_RFLAG_ORIGIN) {
         x -= FX6_TRUNC(FX6_CEIL(font_text->offset.x));
         y -= FX6_TRUNC(FX6_CEIL(font_text->offset.y));
     }

File src/freetype/ft_text.c

     FT_Vector   *next_pos;
 
     int         vertical = mode->render_flags & FT_RFLAG_VERTICAL;
-    int         use_kerning = faceobj->kerning;
+    int         use_kerning = mode->render_flags & FT_RFLAG_KERNING;
     int         pad = mode->render_flags & FT_RFLAG_PAD;
     FT_UInt     prev_glyph_index = 0;
 

File test/freetype_font_tags.py

-__tags__ = ['development']
-
-exclude = False
-
-try:
-    import pygame.freetype
-except ImportError:
-    exclude = True
-
-if exclude:
-    __tags__.extend(['ignore', 'subprocess_ignore'])
-

File test/freetype_font_test.py

-import sys
-import os
-if __name__ == '__main__':
-    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
-    parent_dir, pkg_name = os.path.split(pkg_dir)
-    is_pygame_pkg = (pkg_name == 'tests' and
-                     os.path.split(parent_dir)[1] == 'pygame')
-    if not is_pygame_pkg:
-        sys.path.insert(0, parent_dir)
-else:
-    is_pygame_pkg = __name__.startswith('pygame.tests.')
-
-if is_pygame_pkg:
-    from pygame.tests.test_utils import test_not_implemented, unittest, \
-                                        geterror
-else:
-    from test.test_utils import test_not_implemented, unittest, geterror
-
-import pygame
-try:
-    import pygame.freetype as ft
-except ImportError:
-    ft = None
-from pygame.compat import as_unicode, bytes_, unichr_, unicode_
-
-
-FONTDIR = os.path.join(os.path.dirname (os.path.abspath (__file__)),
-                       'fixtures', 'fonts')
-
-def nullfont():
-    """return an uninitialized font instance"""
-    return ft.Font.__new__(ft.Font)
-
-class FreeTypeFontTest(unittest.TestCase):
-
-    _fixed_path = os.path.join(FONTDIR, 'test_fixed.otf')
-    _sans_path = os.path.join(FONTDIR, 'test_sans.ttf')
-    _TEST_FONTS = {}
-
-    def setUp(self):
-        ft.init()
-
-        if 'fixed' not in self._TEST_FONTS:
-            # Inconsolata is an open-source font designed by Raph Levien
-            # Licensed under the Open Font License
-            # http://www.levien.com/type/myfonts/inconsolata.html
-            self._TEST_FONTS['fixed'] = ft.Font(self._fixed_path)
-
-        if 'sans' not in self._TEST_FONTS:
-            # Liberation Sans is an open-source font designed by Steve Matteson
-            # Licensed under the GNU GPL
-            # https://fedorahosted.org/liberation-fonts/
-            self._TEST_FONTS['sans'] = ft.Font(self._sans_path)
-
-    def test_freetype_defaultfont(self):
-        font = ft.Font(None)
-        self.assertEqual(font.name, "FreeSans")
-
-    def test_freetype_Font_init(self):
-
-        self.assertRaises(IOError, ft.Font, os.path.join (FONTDIR, 'nonexistant.ttf'))
-
-        f = self._TEST_FONTS['sans']
-        self.assertTrue(isinstance(f, ft.Font))
-
-        f = self._TEST_FONTS['fixed']
-        self.assertTrue(isinstance(f, ft.Font))
-
-        f = ft.Font(None, ptsize=24)
-        self.assert_(f.height > 0)
-        self.assertRaises(IOError, f.__init__,
-                          os.path.join(FONTDIR, 'nonexistant.ttf'))
-        self.assertRaises(RuntimeError, f.get_rect, 'a', ptsize=24)
-        
-        # Test attribute preservation during reinitalization
-        f = ft.Font(self._sans_path, ptsize=24, ucs4=True)
-        self.assertEqual(f.name, 'Liberation Sans')
-        self.assertFalse(f.fixed_width)
-        self.assertTrue(f.antialiased)
-        self.assertFalse(f.oblique)
-        self.assertTrue(f.ucs4)
-        f.antialiased = False
-        f.oblique = True
-        f.__init__(self._fixed_path)
-        self.assertEqual(f.name, 'Inconsolata')
-        ##self.assertTrue(f.fixed_width)
-        self.assertFalse(f.fixed_width)  # need a properly marked Mono font
-        self.assertFalse(f.antialiased)
-        self.assertTrue(f.oblique)
-        self.assertTrue(f.ucs4)
-
-    def test_freetype_Font_fixed_width(self):
-
-        f = self._TEST_FONTS['sans']
-        self.assertFalse(f.fixed_width)
-
-        f = self._TEST_FONTS['fixed']
-        ##self.assertTrue(f.fixed_width)
-        self.assertFalse(f.fixed_width)  # need a properly marked Mone font
-
-        self.assertRaises(RuntimeError, lambda : nullfont().fixed_width)
-
-    def test_freetype_Font_get_metrics(self):
-
-        font = self._TEST_FONTS['sans']
-
-        metrics = font.get_metrics('ABCD', ptsize=24)
-        self.assertEqual(len(metrics), len('ABCD'))
-        self.assertTrue(isinstance(metrics, list))
-
-        for metrics_tuple in metrics:
-            self.assertTrue(isinstance(metrics_tuple, tuple), metrics_tuple)
-            self.assertEqual(len(metrics_tuple), 6)
-            for m in metrics_tuple[:4]:
-                self.assertTrue(isinstance(m, int))
-            for m in metrics_tuple[4:]:
-                self.assertTrue(isinstance(m, float))
-
-        # test for empty string
-        metrics = font.get_metrics('', ptsize=24)
-        self.assertEqual(metrics, [])
-
-        # test for invalid string
-        self.assertRaises(TypeError, font.get_metrics, 24, 24)
-
-        # raises exception when uninitalized
-        self.assertRaises(RuntimeError, nullfont().get_metrics,
-                          'a', ptsize=24)
-
-    def test_freetype_Font_get_rect(self):
-
-        font = self._TEST_FONTS['sans']
-
-        def test_rect(r):
-            self.assertTrue(isinstance(r, pygame.Rect))
-
-        rect_default = font.get_rect("ABCDabcd", ptsize=24)
-        test_rect(rect_default)
-        self.assertTrue(rect_default.size > (0, 0))
-        self.assertTrue(rect_default.width > rect_default.height)
-
-        rect_bigger = font.get_rect("ABCDabcd", ptsize=32)
-        test_rect(rect_bigger)
-        self.assertTrue(rect_bigger.size > rect_default.size)
-
-        rect_bolden = font.get_rect("ABCDabcd", ptsize=24, style=ft.STYLE_BOLD)
-        test_rect(rect_bolden)
-        self.assertTrue(rect_bolden.size > rect_default.size)
-
-        font.vertical = True
-        rect_vert = font.get_rect("ABCDabcd", ptsize=24)
-        test_rect(rect_vert)
-        self.assertTrue(rect_vert.width < rect_vert.height)
-        font.vertical = False
-
-        rect_oblique = font.get_rect("ABCDabcd", ptsize=24, style=ft.STYLE_OBLIQUE)
-        test_rect(rect_oblique)
-        self.assertTrue(rect_oblique.width > rect_default.width)
-        self.assertTrue(rect_oblique.height == rect_default.height)
-
-        rect_under = font.get_rect("ABCDabcd", ptsize=24, style=ft.STYLE_UNDERLINE)
-        test_rect(rect_under)
-        self.assertTrue(rect_under.width == rect_default.width)
-        self.assertTrue(rect_under.height > rect_default.height)
-
-#        size_utf32 = font.get_size(as_unicode(r'\U000130A7'), ptsize=24)
-#        size_utf16 = font.get_size(as_unicode(r'\uD80C\uDCA7'), ptsize=24)
-#        self.assertEqual(size_utf16[0], size_utf32[0]);
-#        font.utf16_surrogates = False
-#        try:
-#            size_utf16 = font.get_size(as_unicode(r'\uD80C\uDCA7'), ptsize=24)
-#        finally:
-#            font.utf16_surrogates = True
-#        self.assertNotEqual(size_utf16[0], size_utf32[0]);
-        
-        self.assertRaises(RuntimeError,
-                          nullfont().get_rect, 'a', ptsize=24)
-
-    def test_freetype_Font_height(self):
-
-        f = self._TEST_FONTS['sans']
-        self.assertEqual(f.height, 2355)
-
-        f = self._TEST_FONTS['fixed']
-        self.assertEqual(f.height, 1100)
-
-        self.assertRaises(RuntimeError, lambda : nullfont().height)
-        
-
-    def test_freetype_Font_name(self):
-
-        f = self._TEST_FONTS['sans']
-        self.assertEqual(f.name, 'Liberation Sans')
-
-        f = self._TEST_FONTS['fixed']
-        self.assertEqual(f.name, 'Inconsolata')
-
-        nf = nullfont()
-        self.assertEqual(nf.name, repr(nf))
-
-    def test_freetype_Font_render(self):
-
-        font = self._TEST_FONTS['sans']
-
-        surf = pygame.Surface((800, 600))
-        color = pygame.Color(0, 0, 0)
-
-        # make sure we always have a valid fg color
-        self.assertRaises(TypeError, font.render, None, 'FoobarBaz')
-        self.assertRaises(TypeError, font.render, None, 'FoobarBaz', None)
-
-        # render to new surface
-        rend = font.render(None, 'FoobarBaz', pygame.Color(0, 0, 0), None, ptsize=24)
-        self.assertTrue(isinstance(rend, tuple))
-        self.assertEqual(len(rend), 2)
-        self.assertTrue(isinstance(rend[0], pygame.Surface))
-        self.assertTrue(isinstance(rend[1], pygame.Rect))
-        self.assertEqual(rend[0].get_rect().size, rend[1].size)
-        s, r = font.render(None, '', pygame.Color(0, 0, 0), None, ptsize=24)
-        self.assertEqual(r.width, 1)
-        self.assertEqual(r.height, font.get_sized_height(24))
-        self.assertEqual(s.get_size(), r.size)
-        self.assertEqual(s.get_bitsize(), 32)
-
-        # render to existing surface
-        refcount = sys.getrefcount(surf);
-        rend = font.render((surf, 32, 32), 'FoobarBaz', color, None, ptsize=24)
-        self.assertEqual(sys.getrefcount(surf), refcount + 1)
-        self.assertTrue(isinstance(rend, tuple))
-        self.assertEqual(len(rend), 2)
-        rsurf, rrect = rend
-        self.assertTrue(rsurf is surf)
-        self.assertTrue(isinstance(rrect, pygame.Rect))
-        self.assertEqual(rrect.top, rrect.height)
-##        self.assertEqual(rrect.left, something or other)
-        rcopy = rrect.copy()
-        rcopy.topleft = (32, 32)
-        self.assertTrue(rsurf.get_rect().contains(rcopy))
-        
-        rect = pygame.Rect(20, 20, 2, 2)
-        rend = font.render((surf, rect), 'FoobarBax', color, None, ptsize=24)
-        self.assertEqual(rend[1].top, rend[1].height)
-        self.assertNotEqual(rend[1].size, rect.size)
-        rend = font.render((surf, 20.1, 18.9), 'FoobarBax',
-                           color, None, ptsize=24)
-##        self.assertEqual(tuple(rend[1].topleft), (20, 18))
-
-        s, r = font.render((surf, rect), '', color, None, ptsize=24)
-        self.assertFalse(r)
-        self.assertEqual(r.height, font.get_sized_height(24))
-        self.assertTrue(s is surf)
-
-        # invalid dest test
-        for dest in [0, (), (surf,), (surf, 'a'), (surf, ()),
-                     (surf, (1,)), (surf, ('a', 2)), (surf, (1, 'a')),
-                     (surf, (1+2j, 2)), (surf, (1, 1+2j)),
-                     (surf, 'a', 2), (surf, 1, 'a'), (surf, 1+2j, 2),
-                     (surf, 1, 1+2j), (surf, 1, 2, 3)]: 
-            self.assertRaises(TypeError, font.render,
-                              dest, 'foobar', color, ptsize=24)
-
-        # misc parameter test
-        self.assertRaises(ValueError, font.render, None, 'foobar', color)
-        self.assertRaises(TypeError, font.render, None, 'foobar', color, "",
-                ptsize=24)
-        self.assertRaises(ValueError, font.render, None, 'foobar', color, None,
-                style=42, ptsize=24)
-        self.assertRaises(TypeError, font.render, None, 'foobar', color, None,
-                style=None, ptsize=24)
-        self.assertRaises(ValueError, font.render, None, 'foobar', color, None,
-                style=97, ptsize=24)
-
-        # valid surrogate pairs
-#        rend1 = font.render(None, as_unicode(r'\uD800\uDC00'), color, ptsize=24)
-#        rend1 = font.render(None, as_unicode(r'\uDBFF\uDFFF'), color, ptsize=24)
-#        rend1 = font.render(None, as_unicode(r'\uD80C\uDCA7'), color, ptsize=24)
-#        rend2 = font.render(None, as_unicode(r'\U000130A7'), color, ptsize=24)
-#        self.assertEqual(rend1[1], rend2[1])
-#        font.utf16_surrogates = False
-#        try:
-#            rend1 = font.render(None, as_unicode(r'\uD80C\uDCA7'),
-#                                color, ptsize=24)
-#        finally:
-#            font.utf16_surrogates = True
-#        self.assertNotEqual(rend1[1], rend2[1])
-            
-        # malformed surrogate pairs
-        self.assertRaises(UnicodeEncodeError, font.render,
-                          None, as_unicode(r'\uD80C'), color, ptsize=24)
-        self.assertRaises(UnicodeEncodeError, font.render,
-                          None, as_unicode(r'\uDCA7'), color, ptsize=24)
-        self.assertRaises(UnicodeEncodeError, font.render,
-                          None, as_unicode(r'\uD7FF\uDCA7'), color, ptsize=24)
-        self.assertRaises(UnicodeEncodeError, font.render,
-                          None, as_unicode(r'\uDC00\uDCA7'), color, ptsize=24)
-        self.assertRaises(UnicodeEncodeError, font.render,
-                          None, as_unicode(r'\uD80C\uDBFF'), color, ptsize=24)
-        self.assertRaises(UnicodeEncodeError, font.render,
-                          None, as_unicode(r'\uD80C\uE000'), color, ptsize=24)
-
-        # raises exception when uninitalized
-        self.assertRaises(RuntimeError, nullfont().render,
-                          None, 'a', (0, 0, 0), ptsize=24)
-
-        # *** need more unicode testing to ensure the proper glyphs are rendered
-
-    def test_freetype_Font_render_mono(self):
-        font = self._TEST_FONTS['sans']
-        color = pygame.Color('black')
-        colorkey = pygame.Color('white')
-        text = "."
-
-        save_antialiased = font.antialiased
-        font.antialiased = False
-        try:
-            surf, r = font.render(None, text, color, ptsize=24)
-            self.assertEqual(surf.get_bitsize(), 8)
-            flags = surf.get_flags()
-            self.assertTrue(flags & pygame.SRCCOLORKEY)
-            self.assertFalse(flags & (pygame.SRCALPHA | pygame.HWSURFACE))
-            self.assertEqual(surf.get_colorkey(), colorkey)
-            self.assertTrue(surf.get_alpha() is None)
-
-            translucent_color = pygame.Color(*color)
-            translucent_color.a = 55
-            surf, r = font.render(None, text, translucent_color, ptsize=24)
-            self.assertEqual(surf.get_bitsize(), 8)
-            flags = surf.get_flags()
-            self.assertTrue(flags & (pygame.SRCCOLORKEY | pygame.SRCALPHA))
-            self.assertFalse(flags & pygame.HWSURFACE)
-            self.assertEqual(surf.get_colorkey(), colorkey)
-            self.assertEqual(surf.get_alpha(), translucent_color.a)
-
-            surf, r = font.render(None, text, color, colorkey, ptsize=24)
-            self.assertEqual(surf.get_bitsize(), 32)
-        finally:
-            font.antialiased = save_antialiased
-
-    def test_freetype_Font_render_raw(self):
-    
-        font = self._TEST_FONTS['sans']
-        
-        text = "abc"
-        size = font.get_rect(text, ptsize=24).size
-        rend = font.render_raw(text, ptsize=24)
-        self.assertTrue(isinstance(rend, tuple))
-        self.assertEqual(len(rend), 2)
-        r, s = rend
-        self.assertTrue(isinstance(r, bytes_))
-        self.assertTrue(isinstance(s, tuple))
-        self.assertTrue(len(s), 2)
-        w, h = s
-        self.assertTrue(isinstance(w, int))
-        self.assertTrue(isinstance(w, int))
-        self.assertEqual(s, size)
-        self.assertEqual(len(r), w * h)
-        
-        r, (w, h) = font.render_raw('', ptsize=24)
-        self.assertEqual(w, 0)
-        self.assertEqual(h, font.height)
-        self.assertEqual(len(r), 0)
-        
-        # bug with decenders: this would crash
-        rend = font.render_raw('render_raw', ptsize=24)
-
-        # bug with non-printable characters: this would cause a crash
-        # because the text length was not adjusted for skipped characters.
-        text = unicode_("").join([unichr_(i) for i in range(31, 64)])
-        rend = font.render_raw(text, ptsize=10)
-
-    def test_freetype_Font_style(self):
-
-        font = self._TEST_FONTS['sans']
-
-        # make sure STYLE_NORMAL is the default value
-        self.assertEqual(ft.STYLE_NORMAL, font.style)
-
-        # make sure we check for style type
-        try:    font.style = "None"
-        except TypeError: pass
-        else:   self.fail("Failed style assignement")
-
-        try:    font.style = None
-        except TypeError: pass
-        else:   self.fail("Failed style assignement")
-
-        # make sure we only accept valid constants
-        try:    font.style = 112
-        except ValueError: pass
-        else:   self.fail("Failed style assignement")
-
-        # make assure no assignements happened
-        self.assertEqual(ft.STYLE_NORMAL, font.style)
-
-        # test assignement
-        font.style = ft.STYLE_UNDERLINE
-        self.assertEqual(ft.STYLE_UNDERLINE, font.style)
-
-        # test complex styles
-        st = (  ft.STYLE_BOLD | ft.STYLE_UNDERLINE |
-                ft.STYLE_OBLIQUE )
-
-        font.style = st
-        self.assertEqual(st, font.style)
-
-        # revert changes
-        font.style = ft.STYLE_NORMAL
-        self.assertEqual(ft.STYLE_NORMAL, font.style)
-
-    def test_freetype_Font_resolution(self):
-        text = "|"  # Differs in width and height
-        resolution = ft.get_default_resolution()
-        new_font = ft.Font(self._sans_path, resolution=2 * resolution)
-        self.assertEqual(new_font.resolution, 2 * resolution)
-        size_normal = self._TEST_FONTS['sans'].get_rect(text, ptsize=24).size
-        size_scaled = new_font.get_rect(text, ptsize=24).size
-        size_by_2 = size_normal[0] * 2
-        self.assertTrue(size_by_2 + 2 >= size_scaled[0] >= size_by_2 - 2,
-                        "%i not equal %i" % (size_scaled[1], size_by_2))
-        size_by_2 = size_normal[1] * 2
-        self.assertTrue(size_by_2 + 2 >= size_scaled[1] >= size_by_2 - 2,
-                        "%i not equal %i" % (size_scaled[1], size_by_2))
-        new_resolution = resolution + 10
-        ft.set_default_resolution(new_resolution)
-        try:
-            new_font = ft.Font(self._sans_path, resolution=0)
-            self.assertEqual(new_font.resolution, new_resolution)
-        finally:
-            ft.set_default_resolution()
-
-    def test_freetype_Font_path(self):
-        self.assertEqual(self._TEST_FONTS['sans'].path, self._sans_path)
-        self.assertRaises(AttributeError, getattr, nullfont(), 'path')
-
-    # This Font cache test is conditional on freetype being built by a debug
-    # version of Python or with the C macro PGFT_DEBUG_CACHE defined.
-    def test_freetype_Font_cache(self):
-        glyphs = "abcde"
-        glen = len(glyphs)
-        other_glyphs = "123"
-        oglen = len(other_glyphs)
-        uempty = unicode_("")
-##        many_glyphs = (uempty.join([unichr_(i) for i in range(32,127)] +
-##                                   [unichr_(i) for i in range(161,172)] +
-##                                   [unichr_(i) for i in range(174,239)]))
-        many_glyphs = uempty.join([unichr_(i) for i in range(32,127)])
-        mglen = len(many_glyphs)
-
-        count = 0
-        access = 0
-        hit = 0
-        miss = 0
-
-        f = ft.Font(None, ptsize=24, style=ft.STYLE_NORMAL, vertical=False)
-        f.antialiased = True
-
-        # Ensure debug counters are zero
-        self.assertEqual(f._debug_cache_stats, (0, 0, 0, 0, 0))
-        # Load some basic glyphs
-        count = access = miss = glen
-        f.render_raw(glyphs)
-        self.assertEqual(f._debug_cache_stats, (count, 0, access, hit, miss))
-        # Vertical should not affect the cache
-        access += glen
-        hit += glen
-        f.vertical = True
-        f.render_raw(glyphs)
-        f.vertical = False
-        self.assertEqual(f._debug_cache_stats, (count, 0, access, hit, miss))
-        # New glyphs will
-        count += oglen
-        access += oglen
-        miss += oglen
-        f.render_raw(other_glyphs)
-        self.assertEqual(f._debug_cache_stats, (count, 0, access, hit, miss))
-        # Point size does
-        count += glen
-        access += glen
-        miss += glen
-        f.render_raw(glyphs, ptsize=12)
-        self.assertEqual(f._debug_cache_stats, (count, 0, access, hit, miss))
-        # Underline style does not
-        access += oglen
-        hit += oglen
-        f.underline = True
-        f.render_raw(other_glyphs)
-        f.underline = False
-        self.assertEqual(f._debug_cache_stats, (count, 0, access, hit, miss))
-        # Oblique style does
-        count += glen
-        access += glen
-        miss += glen
-        f.oblique = True
-        f.render_raw(glyphs)
-        f.oblique = False
-        self.assertEqual(f._debug_cache_stats, (count, 0, access, hit, miss))
-        # Bold style does; by this point cache clears can happen
-        count += glen
-        access += glen
-        miss += glen
-        f.bold = True
-        f.render_raw(glyphs)
-        f.bold = False
-        ccount, cdelete_count, caccess, chit, cmiss = f._debug_cache_stats
-        self.assertEqual((ccount + cdelete_count, caccess, chit, cmiss),
-                         (count, access, hit, miss))
-        # Rotation does
-        count += glen
-        access += glen
-        miss += glen
-        f.render_raw(glyphs, rotation=10)
-        ccount, cdelete_count, caccess, chit, cmiss = f._debug_cache_stats
-        self.assertEqual((ccount + cdelete_count, caccess, chit, cmiss),
-                         (count, access, hit, miss))
-        # aliased (mono) glyphs do
-        count += oglen
-        access += oglen
-        miss += oglen
-        f.antialiased = False
-        f.render_raw(other_glyphs)
-        f.antialiased = True
-        ccount, cdelete_count, caccess, chit, cmiss = f._debug_cache_stats
-        self.assertEqual((ccount + cdelete_count, caccess, chit, cmiss),
-                         (count, access, hit, miss))
-        # Trigger a cleanup for sure.
-        count += 2 * mglen
-        access += 2 * mglen
-        miss += 2 * mglen
-        f.get_metrics(many_glyphs, ptsize=8)
-        f.get_metrics(many_glyphs, ptsize=10)
-        ccount, cdelete_count, caccess, chit, cmiss = f._debug_cache_stats
-        print (ccount, cdelete_count, caccess, chit, cmiss)
-        self.assertTrue(ccount < count)
-        self.assertEqual((ccount + cdelete_count, caccess, chit, cmiss),
-                         (count, access, hit, miss))
-
-    try:
-        ft.Font._debug_cache_stats
-    except AttributeError:
-        del test_freetype_Font_cache
-
-    def test_undefined_character_code(self):
-        # To be consistent with pygame.font.Font, undefined codes
-        # are rendered as the undefined character, and has metrics
-        # of None.
-        font = self._TEST_FONTS['sans']
-
-        img, size1 = font.render(None, unichr_(1), (0, 0, 0), ptsize=24)
-        img, size0 = font.render(None, "", (0, 0, 0), ptsize=24)
-        self.assertTrue(size1.width > size0.width )
-
-        metrics = font.get_metrics(unichr_(1) + unichr_(48), ptsize=24)
-        self.assertEqual(len(metrics), 2)
-        self.assertTrue(metrics[0] is None)
-        self.assertTrue(isinstance(metrics[1], tuple))
-
-class FreeTypeFont(unittest.TestCase):
-
-    def test_resolution(self):
-        was_init = ft.was_init()
-        if not was_init:
-            ft.init()
-        try:
-            ft.set_default_resolution()
-            resolution = ft.get_default_resolution()
-            self.assertEqual(resolution, 72)
-            new_resolution = resolution + 10
-            ft.set_default_resolution(new_resolution)
-            self.assertEqual(ft.get_default_resolution(), new_resolution)
-            ft.init(resolution=resolution+20)
-            self.assertEqual(ft.get_default_resolution(), new_resolution)
-        finally:
-            ft.set_default_resolution()
-            if was_init:
-                ft.quit()
-
-
-if __name__ == '__main__':
-    unittest.main()

File test/freetype_tags.py

+__tags__ = ['development']
+
+exclude = False
+
+try:
+    import pygame.freetype
+except ImportError:
+    exclude = True
+
+if exclude:
+    __tags__.extend(['ignore', 'subprocess_ignore'])
+

File test/test_utils/arrinter.py

 if sys.version_info >= (3,):
     PY3 = 1
 
+SIZEOF_VOID_P = sizeof(c_void_p)
+if SIZEOF_VOID_P <= sizeof(c_int):
+    Py_intptr_t = c_int
+elif SIZEOF_VOID_P <= sizeof(c_long):
+    Py_intptr_t = c_long
+elif 'c_longlong' in globals() and SIZEOF_VOID_P <= sizeof(c_longlong):
+    Py_intptr_t = c_longlong
+else:
+    raise RuntimeError("Unrecognized pointer size %i" % (pointer_size,))
+
 class PyArrayInterface(Structure):
     _fields_ = [('two', c_int), ('nd', c_int), ('typekind', c_char),
                 ('itemsize', c_int), ('flags', c_int),
-                ('shape', POINTER(c_ssize_t)),
-                ('strides', POINTER(c_ssize_t)),
+                ('shape', POINTER(Py_intptr_t)),
+                ('strides', POINTER(Py_intptr_t)),
                 ('data', c_void_p), ('descr', py_object)]
 
 PAI_Ptr = POINTER(PyArrayInterface)