/*! * \brief Draw polyline * * Optional on the PyDia side. If not implemented fallback to base class member. * * \memberof _DiaPyRenderer */ static void draw_polyline(DiaRenderer *renderer, Point *points, int num_points, Color *line_colour) { PyObject *func, *res, *arg, *self = PYDIA_RENDERER (renderer); func = PyObject_GetAttrString (self, "draw_polyline"); if (func && PyCallable_Check(func)) { PyObject *optt = PyDiaPointTuple_New (points, num_points); PyObject *ocolor = PyDiaColor_New (line_colour); Py_INCREF(self); Py_INCREF(func); arg = Py_BuildValue ("(OO)", optt, ocolor); if (arg) { res = PyEval_CallObject (func, arg); ON_RES(res, FALSE); } Py_XDECREF (arg); Py_XDECREF (optt); Py_XDECREF (ocolor); Py_DECREF(func); Py_DECREF(self); } else { /* member optional */ PyErr_Clear(); /* XXX: implementing the same fallback as DiaRenderer */ DIA_RENDERER_CLASS (parent_class)->draw_polyline (renderer, points, num_points, line_colour); } }
/* kept for backward compatibility, not any longer in the renderer interface */ static void fill_bezier(DiaRenderer *renderer, BezPoint *points, /* Last point must be same as first point */ int num_points, Color *colour) { PyObject *func, *res, *arg, *self = PYDIA_RENDERER (renderer); func = PyObject_GetAttrString (self, "fill_bezier"); if (func && PyCallable_Check(func)) { PyObject *obt = PyDiaBezPointTuple_New (points, num_points); PyObject *ocolor = PyDiaColor_New (colour); Py_INCREF(self); Py_INCREF(func); arg = Py_BuildValue ("(OO)", obt, ocolor); if (arg) { res = PyEval_CallObject (func, arg); ON_RES(res, FALSE); } Py_XDECREF (arg); Py_XDECREF (obt); Py_XDECREF (ocolor); Py_DECREF(func); Py_DECREF(self); } else { /* member optional */ PyErr_Clear(); /* XXX: implementing the same fallback as DiaRenderer would do */ DIA_RENDERER_CLASS (parent_class)->draw_beziergon (renderer, points, num_points, colour, NULL); } }
/*! * \brief Draw line * * Not optional on the PyDia side. If not implemented a runtime warning * will be generated when called. * * \memberof _DiaPyRenderer */ static void draw_line(DiaRenderer *renderer, Point *start, Point *end, Color *line_colour) { PyObject *func, *res, *arg, *self = PYDIA_RENDERER (renderer); func = PyObject_GetAttrString (self, "draw_line"); if (func && PyCallable_Check(func)) { PyObject *ostart = PyDiaPoint_New (start); PyObject *oend = PyDiaPoint_New (end); PyObject *ocolor = PyDiaColor_New (line_colour); Py_INCREF(self); Py_INCREF(func); arg = Py_BuildValue ("(OOO)", ostart, oend, ocolor); if (arg) { res = PyEval_CallObject (func, arg); ON_RES(res, FALSE); } Py_XDECREF (arg); Py_XDECREF (ostart); Py_XDECREF (oend); Py_XDECREF (ocolor); Py_DECREF(func); Py_DECREF(self); } else { /* member not optional */ gchar *msg = g_strdup_printf ("%s.draw_line() implmentation missing.", G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (renderer))); PyErr_Clear(); PyErr_Warn (PyExc_RuntimeWarning, msg); g_free (msg); } }
/*! * \brief Fill and/or stroke a closed path * \memberof _DiaPyRenderer */ static void draw_beziergon (DiaRenderer *renderer, BezPoint *points, int num_points, Color *fill, Color *stroke) { PyObject *func, *res, *arg, *self = PYDIA_RENDERER (renderer); func = PyObject_GetAttrString (self, "draw_beziergon"); if (func && PyCallable_Check(func)) { PyObject *obt = PyDiaBezPointTuple_New (points, num_points); PyObject *fill_po; PyObject *stroke_po; Py_INCREF(self); Py_INCREF(func); /* we have to provide a Python object even if there is no color */ if (fill) fill_po = PyDiaColor_New (fill); else Py_INCREF(Py_None), fill_po = Py_None; if (stroke) stroke_po = PyDiaColor_New (stroke); else Py_INCREF(Py_None), stroke_po = Py_None; arg = Py_BuildValue ("(OOO)", obt, fill_po, stroke_po); if (arg) { res = PyEval_CallObject (func, arg); ON_RES(res, FALSE); } Py_XDECREF (arg); Py_XDECREF (obt); Py_XDECREF (fill_po); Py_XDECREF (stroke_po); Py_DECREF(func); Py_DECREF(self); } else { /* member optional */ PyErr_Clear(); /* PyDia only backward compatibility */ if (fill) fill_bezier (renderer, points, num_points, fill); if (stroke) /* XXX: still not closing */ draw_bezier (renderer, points, num_points, stroke); } }
/*! * \brief Draw ellipse * * Not optional on the PyDia side. If not implemented a runtime warning * will be generated when called. * * \memberof _DiaPyRenderer */ static void draw_ellipse(DiaRenderer *renderer, Point *center, real width, real height, Color *fill, Color *stroke) { PyObject *func, *res, *arg, *self = PYDIA_RENDERER (renderer); func = PyObject_GetAttrString (self, "draw_ellipse"); if (func && PyCallable_Check(func)) { PyObject *opoint = PyDiaPoint_New (center); PyObject *fill_po; PyObject *stroke_po; Py_INCREF(self); Py_INCREF(func); /* we have to provide a Python object even if there is no color */ if (fill) fill_po = PyDiaColor_New (fill); else Py_INCREF(Py_None), fill_po = Py_None; if (stroke) stroke_po = PyDiaColor_New (stroke); else Py_INCREF(Py_None), stroke_po = Py_None; arg = Py_BuildValue ("(OddOO)", opoint, width, height, fill_po, stroke_po); if (arg) { res = PyEval_CallObject (func, arg); ON_RES(res, FALSE); } Py_XDECREF (arg); Py_XDECREF (opoint); Py_XDECREF (fill_po); Py_XDECREF (stroke_po); Py_DECREF(func); Py_DECREF(self); } else { /* member not optional */ gchar *msg = g_strdup_printf ("%s.draw_ellipse() implementation missing.", G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (renderer))); PyErr_Clear(); PyErr_Warn (PyExc_RuntimeWarning, msg); g_free (msg); } }
static void draw_rounded_rect(DiaRenderer *renderer, Point *ul_corner, Point *lr_corner, Color *fill, Color *stroke, real rounding) { PyObject *func, *res, *arg, *self = PYDIA_RENDERER (renderer); func = PyObject_GetAttrString (self, "draw_rounded_rect"); if (func && PyCallable_Check(func)) { PyObject *orect = PyDiaRectangle_New_FromPoints (ul_corner, lr_corner); PyObject *fill_po, *stroke_po; Py_INCREF(self); Py_INCREF(func); if (fill) fill_po = PyDiaColor_New (fill); else Py_INCREF(Py_None), fill_po = Py_None; if (stroke) stroke_po = PyDiaColor_New (stroke); else Py_INCREF(Py_None), stroke_po = Py_None; arg = Py_BuildValue ("(OOOd)", orect, fill_po, stroke_po, rounding); if (arg) { res = PyEval_CallObject (func, arg); ON_RES(res, FALSE); } Py_XDECREF (arg); Py_XDECREF (fill_po); Py_XDECREF (stroke_po); Py_XDECREF (orect); Py_DECREF(func); Py_DECREF(self); } else { /* member optional */ PyErr_Clear(); /* implementing the same fallback as DiaRenderer would do */ DIA_RENDERER_CLASS (parent_class)->draw_rounded_rect (renderer, ul_corner, lr_corner, fill, stroke, rounding); } }
/*! * \brief Draw polygon * * Optional on the PyDia side. If not implemented fallback to base class member. * * \memberof _DiaPyRenderer */ static void draw_polygon(DiaRenderer *renderer, Point *points, int num_points, Color *fill, Color *stroke) { PyObject *func, *res, *arg, *self = PYDIA_RENDERER (renderer); func = PyObject_GetAttrString (self, "draw_polygon"); if (func && PyCallable_Check(func)) { PyObject *optt = PyDiaPointTuple_New (points, num_points); PyObject *fill_po, *stroke_po; if (fill) fill_po = PyDiaColor_New (fill); else Py_INCREF(Py_None), fill_po = Py_None; if (stroke) stroke_po = PyDiaColor_New (stroke); else Py_INCREF(Py_None), stroke_po = Py_None; Py_INCREF(self); Py_INCREF(func); arg = Py_BuildValue ("(OOO)", optt, fill_po, stroke_po); if (arg) { res = PyEval_CallObject (func, arg); ON_RES(res, FALSE); } Py_XDECREF (arg); Py_XDECREF (optt); Py_XDECREF (fill_po); Py_XDECREF (stroke_po); Py_DECREF(func); Py_DECREF(self); } else { /* fill_polygon was not an optional member */ PyErr_Warn (PyExc_RuntimeWarning, "DiaPyRenderer : draw_polygon() method missing!\n"); } }
/*! * \brief Draw string * * Not optional on the PyDia side. If not implemented a runtime warning * will be generated when called. * * \memberof _DiaPyRenderer */ static void draw_string(DiaRenderer *renderer, const char *text, Point *pos, Alignment alignment, Color *colour) { PyObject *func, *res, *arg, *self = PYDIA_RENDERER (renderer); switch (alignment) { case ALIGN_LEFT: break; case ALIGN_CENTER: break; case ALIGN_RIGHT: break; } func = PyObject_GetAttrString (self, "draw_string"); if (func && PyCallable_Check(func)) { PyObject *opoint = PyDiaPoint_New (pos); PyObject *ocolor = PyDiaColor_New (colour); Py_INCREF(self); Py_INCREF(func); arg = Py_BuildValue ("(sOiO)", text, opoint, alignment, ocolor); if (arg) { res = PyEval_CallObject (func, arg); ON_RES(res, FALSE); } Py_XDECREF (arg); Py_XDECREF (opoint); Py_XDECREF (ocolor); Py_DECREF(func); Py_DECREF(self); } else { /* member not optional */ gchar *msg = g_strdup_printf ("%s.draw_string() implmentation missing.", G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (renderer))); PyErr_Clear(); PyErr_Warn (PyExc_RuntimeWarning, msg); g_free (msg); } }
/*! * \brief Fill arc * * Not optional on the PyDia side. If not implemented a runtime warning * will be generated when called. * * \memberof _DiaPyRenderer */ static void fill_arc(DiaRenderer *renderer, Point *center, real width, real height, real angle1, real angle2, Color *colour) { PyObject *func, *res, *arg, *self = PYDIA_RENDERER (renderer); func = PyObject_GetAttrString (self, "fill_arc"); if (func && PyCallable_Check(func)) { PyObject *opoint = PyDiaPoint_New (center); PyObject *ocolor = PyDiaColor_New (colour); Py_INCREF(self); Py_INCREF(func); arg = Py_BuildValue ("(OddddO)", opoint, width, height, angle1, angle2, ocolor); if (arg) { res = PyEval_CallObject (func, arg); ON_RES(res, FALSE); } Py_XDECREF (arg); Py_XDECREF (opoint); Py_XDECREF (ocolor); Py_DECREF(func); Py_DECREF(self); } else { /* member not optional */ gchar *msg = g_strdup_printf ("%s.fill_arc() implmentation missing.", G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (renderer))); PyErr_Clear(); PyErr_Warn (PyExc_RuntimeWarning, msg); g_free (msg); } }
static PyObject * PyDiaDiagramData_GetAttr(PyDiaDiagramData *self, gchar *attr) { Diagram *diagram = DIA_DIAGRAM(self->data); if (!strcmp(attr, "__members__")) return Py_BuildValue("[ssssssssssss]", "extents", "bg_color", "paper", "layers", "active_layer", "grid_width", "grid_visible", "hguides", "vguides", "layers", "active_layer", "selected" ); else if (!strcmp(attr, "extents")) return PyDiaRectangle_New(&self->data->extents, NULL); else if (!strcmp(attr, "bg_color")) { return PyDiaColor_New (&(self->data->bg_color)); } else if (!strcmp(attr, "layers")) { guint i, len = self->data->layers->len; PyObject *ret = PyTuple_New(len); for (i = 0; i < len; i++) PyTuple_SetItem(ret, i, PyDiaLayer_New( g_ptr_array_index(self->data->layers, i))); return ret; } else if (!strcmp(attr, "active_layer")) { return PyDiaLayer_New(self->data->active_layer); } else if (!strcmp(attr, "paper")) { return PyDiaPaperinfo_New (&self->data->paper); } else if (diagram && !strcmp(attr, "grid_width")) return Py_BuildValue("(dd)", diagram->grid.width_x, diagram->grid.width_y); else if (diagram && !strcmp(attr, "grid_visible")) return Py_BuildValue("(ii)", diagram->grid.visible_x, diagram->grid.visible_y); else if (diagram && !strcmp(attr, "hguides")) { int len = diagram->guides.nhguides; PyObject *ret = PyTuple_New(len); int i; for (i = 0; i < len; i++) PyTuple_SetItem(ret, i, PyFloat_FromDouble(diagram->guides.hguides[i])); return ret; } else if (diagram && !strcmp(attr, "vguides")) { int len = diagram->guides.nvguides; PyObject *ret = PyTuple_New(len); int i; for (i = 0; i < len; i++) PyTuple_SetItem(ret, i, PyFloat_FromDouble(diagram->guides.vguides[i])); return ret; } else if (!strcmp(attr, "layers")) { guint i, len = self->data->layers->len; PyObject *ret = PyTuple_New(len); for (i = 0; i < len; i++) PyTuple_SetItem(ret, i, PyDiaLayer_New( g_ptr_array_index(self->data->layers, i))); return ret; } else if (!strcmp(attr, "active_layer")) { return PyDiaLayer_New(self->data->active_layer); } else if (!strcmp(attr, "selected")) { PyObject *ret; GList *tmp; gint i; ret = PyTuple_New(g_list_length(self->data->selected)); for (i = 0, tmp = self->data->selected; tmp; i++, tmp = tmp->next) PyTuple_SetItem(ret, i, PyDiaObject_New((DiaObject *)tmp->data)); return ret; } return Py_FindMethod(PyDiaDiagramData_Methods, (PyObject *)self, attr); }