[dia] PyDia: allow to implement DiaRenderer::is_capabale_to() ...
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] PyDia: allow to implement DiaRenderer::is_capabale_to() ...
- Date: Sat, 26 Apr 2014 17:17:37 +0000 (UTC)
commit 1e456ba06433cd447bcad90b93c1b488ca7ea0eb
Author: Hans Breuer <hans breuer org>
Date: Fri Apr 25 12:44:34 2014 +0200
PyDia: allow to implement DiaRenderer::is_capabale_to() ...
... and use that for diasvg.py. The latter is necessary to avoid some
recently implemented fallbacks of the DiaRenderer base class, i.e.
render-alpha, render-affine and render-holes are all supported with
diasvg.py, but the core was applying some fallbacks.
plug-ins/python/diasvg.py | 16 +++++++++++++---
plug-ins/python/pydia-render.c | 40 ++++++++++++++++++++++++++++++++++++++--
2 files changed, 51 insertions(+), 5 deletions(-)
---
diff --git a/plug-ins/python/diasvg.py b/plug-ins/python/diasvg.py
index bf8b759..a02bb7d 100644
--- a/plug-ins/python/diasvg.py
+++ b/plug-ins/python/diasvg.py
@@ -53,6 +53,16 @@ class SvgRenderer :
def end_render (self) :
self.f.write('</svg>')
self.f.close()
+ def is_capable_to (self, cap) :
+ if cap == 1 : # RENDER_HOLES
+ return 1
+ elif cap == 2 : # RENDER_ALPHA
+ return 1
+ elif cap == 4 : # RENDER_AFFINE
+ return 1
+ elif cap == 8 : # RENDER_PATTERN
+ return 0
+ return 0
def draw_object (self, object, matrix) :
self.f.write("<!-- " + object.type.name + " -->\n")
odict = object.properties["meta"].value
@@ -62,8 +72,8 @@ class SvgRenderer :
attrs = ''
if matrix :
attrs += 'transform="matrix' + str(matrix) + '" '
- if odict.has_key("id") :
- attrs += 'id="' + self._escape(odict['id']) + '"'
+ if odict.has_key("id") :
+ attrs += 'id="' + self._escape(odict['id']) + '"'
self.f.write('<g ' + attrs + '>\n')
# don't forget to render the object
object.draw (self)
@@ -72,7 +82,7 @@ class SvgRenderer :
if odict.has_key("url") :
self.f.write('</a>\n')
def set_linewidth (self, width) :
- if width < 0.001 : # zero line width is invisble ?
+ if width < 0.001 : # zero line width is invisible ?
self.line_width = 0.001
else :
self.line_width = width
diff --git a/plug-ins/python/pydia-render.c b/plug-ins/python/pydia-render.c
index ede92a8..f8a235b 100644
--- a/plug-ins/python/pydia-render.c
+++ b/plug-ins/python/pydia-render.c
@@ -411,6 +411,40 @@ set_font(DiaRenderer *renderer, DiaFont *font, real height)
static gpointer parent_class = NULL;
/*!
+ * \brief Advertise the renderer's capabilities
+ * \memberof _DiaTransformRenderer
+ */
+static gboolean
+is_capable_to (DiaRenderer *renderer, RenderCapability cap)
+{
+ PyObject *func, *res, *arg, *self = PYDIA_RENDERER (renderer);
+ gboolean bRet = FALSE;
+
+ func = PyObject_GetAttrString (self, "is_capable_to");
+ if (func && PyCallable_Check(func)) {
+ Py_INCREF(self);
+ Py_INCREF(func);
+ arg = Py_BuildValue ("(i)", cap);
+ if (arg) {
+ res = PyEval_CallObject (func, arg);
+ if (res && PyInt_Check(res)) {
+ bRet = (PyInt_AsLong(res) != 0);
+ Py_DECREF (res);
+ } else {
+ ON_RES(res, FALSE);
+ }
+ }
+ Py_XDECREF(arg);
+ Py_DECREF(func);
+ Py_DECREF(self);
+ } else {
+ PyErr_Clear(); /* member optional */
+ return DIA_RENDERER_CLASS (parent_class)->is_capable_to (renderer, cap);
+ }
+ return bRet;
+}
+
+/*!
* \brief Draw object
*
* Optional on the PyDia side. If not implemented the base class method
@@ -420,7 +454,7 @@ static gpointer parent_class = NULL;
* object information in the drawing. It is also necessary if the PyDia
* renderer should support transformations.
*
- * If implementing a drawing exposrt filter and overwriting draw_object()
+ * If implementing a drawing export filter and overwriting draw_object()
* the following code shall be used. Otherwise no draw/fill method will
* be called at all.
*
@@ -429,7 +463,7 @@ static gpointer parent_class = NULL;
object.draw (self)
* \endcode
*
- * Not calling the object draw method is only usefull when a non-drawing
+ * Not calling the object draw method is only useful when a non-drawing
* export - e.g. code generation \sa codegen.py - is implemented.
*
* @param renderer Self
@@ -1240,5 +1274,7 @@ dia_py_renderer_class_init (DiaPyRendererClass *klass)
/* highest level functions */
renderer_class->draw_rounded_rect = draw_rounded_rect;
renderer_class->fill_rounded_rect = fill_rounded_rect;
+ /* other */
+ renderer_class->is_capable_to = is_capable_to;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]