Anonymous avatar Anonymous committed 623e6d6

Added __copy__ and __deepcopy__ methods to freetype2.Font, base.Color,
base.Rect and base.FRect classes.

Comments (0)

Files changed (4)

 static PyObject* _color_repr (PyColor *color);
 static PyObject* _color_normalize (PyColor *color);
 static PyObject* _color_correct_gamma (PyColor *color, PyObject *args);
+static PyObject* _color_copy (PyColor *color, PyObject *unused);
 
 /* Getters/setters */
 static PyObject* _color_get_r (PyColor *color, void *closure);
 /* C API */
 static PyObject* PyColor_New (pgbyte rgba[]);
 static PyObject* PyColor_NewFromNumber (pguint32 val);
+static PyObject* PyColor_NewFromRGBA (pgbyte r, pgbyte g, pgbyte b, pgbyte a);
 static pguint32 PyColor_AsNumber (PyObject *color);
 
 /**
       DOC_BASE_COLOR_NORMALIZE },
     { "correct_gamma", (PyCFunction) _color_correct_gamma, METH_O,
       DOC_BASE_COLOR_CORRECT_GAMMA },
+    { "__copy__", _color_copy, METH_NOARGS, NULL },
+    { "__deepcopy__", _color_copy, METH_O, NULL },
     { NULL, NULL, 0, NULL }
 };
 
     return PyColor_New (rgba);
 }
 
+static PyObject*
+_color_copy (PyColor *color, PyObject *unused)
+{
+    return PyColor_NewFromRGBA (color->r, color->g, color->b, color->a);
+}
+
 /**
  * color.r
  */

src/base/floatrect.c

     void *closure);
 
 static PyObject* _frect_clip (PyObject* self, PyObject *args);
-static PyObject* _frect_copy (PyObject* self);
+static PyObject* _frect_copy (PyObject* self, PyObject *unused);
 static PyObject* _frect_move (PyObject* self, PyObject *args);
 static PyObject* _frect_move_ip (PyObject* self, PyObject *args);
 static PyObject* _frect_union (PyObject* self, PyObject *args);
     { "ceil", (PyCFunction) _frect_ceil, METH_NOARGS, DOC_BASE_FRECT_CEIL },
     { "floor", (PyCFunction) _frect_floor, METH_NOARGS, DOC_BASE_FRECT_FLOOR },
     { "trunc", (PyCFunction) _frect_trunc, METH_NOARGS, DOC_BASE_FRECT_TRUNC },
+    { "__copy__", (PyCFunction)_frect_copy, METH_NOARGS, DOC_BASE_FRECT_COPY },
+    { "__deepcopy__", (PyCFunction)_frect_copy, METH_O, DOC_BASE_FRECT_COPY },
     { NULL, NULL, 0, NULL }
 };
 
 }
 
 static PyObject*
-_frect_copy (PyObject* self)
+_frect_copy (PyObject* self, PyObject *unused)
 {
     return PyFRect_New (((PyFRect*)self)->x, ((PyFRect*)self)->y,
         ((PyFRect*)self)->w, ((PyFRect*)self)->h);
     void *closure);
 
 static PyObject* _rect_clip (PyObject* self, PyObject *args);
-static PyObject* _rect_copy (PyObject* self);
+static PyObject* _rect_copy (PyObject* self, PyObject *unused);
 static PyObject* _rect_move (PyObject* self, PyObject *args);
 static PyObject* _rect_move_ip (PyObject* self, PyObject *args);
 static PyObject* _rect_union (PyObject* self, PyObject *args);
       METH_VARARGS | METH_KEYWORDS, DOC_BASE_RECT_COLLIDEDICT },
     { "collidedictall", (PyCFunction) _rect_collidedictall,
       METH_VARARGS | METH_KEYWORDS, DOC_BASE_RECT_COLLIDEDICTALL },
+    { "__copy__", (PyCFunction)_rect_copy, METH_NOARGS, DOC_BASE_RECT_COPY },
+    { "__deepcopy__", (PyCFunction)_rect_copy, METH_O, DOC_BASE_RECT_COPY },
     { NULL, NULL, 0, NULL }
 };
 
 }
 
 static PyObject*
-_rect_copy (PyObject* self)
+_rect_copy (PyObject* self, PyObject *unused)
 {
     return PyRect_New (((PyRect*)self)->x, ((PyRect*)self)->y,
         ((PyRect*)self)->w, ((PyRect*)self)->h);

src/freetype/ft_font.c

 static PyObject* _ftfont_getmetrics(PyObject *self, PyObject* args, PyObject *kwds);
 static PyObject* _ftfont_render(PyObject *self, PyObject* args, PyObject *kwds);
 static PyObject* _ftfont_render_raw(PyObject *self, PyObject* args, PyObject *kwds);
-static PyObject* _ftfont_copy (PyObject *self);
+
+typedef PyObject* (*arglessfunc)(PyObject *self);
+static PyObject* _ftfont_copy (PyObject *self, PyObject *unused);
 
 /*
  * Getters/setters
     { "render_raw", (PyCFunction)_ftfont_render_raw,
       METH_VARARGS | METH_KEYWORDS, DOC_BASE_FONT_RENDER_RAW },
     { "copy", (PyCFunction)_ftfont_copy, METH_NOARGS, DOC_BASE_FONT_COPY },
+    { "__copy__", (PyCFunction)_ftfont_copy, METH_NOARGS, DOC_BASE_FONT_COPY },
+    { "__deepcopy__", (PyCFunction)_ftfont_copy, METH_O, DOC_BASE_FONT_COPY },
     { NULL, NULL, 0, NULL }
 };
 
     font->pyfont.set_style = _ftfont_setstyle;
     font->pyfont.get_size = _ftfont_getsize;
     font->pyfont.render = _ftfont_render;
-    font->pyfont.copy = _ftfont_copy;
+    font->pyfont.copy = (arglessfunc)_ftfont_copy;
 
     return (PyObject*)font;
 }
 }
 
 static PyObject*
-_ftfont_copy (PyObject *self)
+_ftfont_copy (PyObject *self, PyObject *unused)
 {
     PyFreeTypeFont *font;
     FreeTypeInstance *ft;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.