[dia] pstricks: optimize draw_polygon/draw_beziergon
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] pstricks: optimize draw_polygon/draw_beziergon
- Date: Sat, 3 May 2014 12:41:20 +0000 (UTC)
commit 8962877a8ff5eacd9e796396c9d9cfe369d03c1d
Author: Hans Breuer <hans breuer org>
Date: Fri May 2 17:04:05 2014 +0200
pstricks: optimize draw_polygon/draw_beziergon
Also finally adapted to the even-odd-fill Dia is using.
Looking good with convert-to-path although some general
clipping problem still exists.
plug-ins/pstricks/render_pstricks.c | 95 +++++++++++++++++++++++------------
samples/pst-test.tex | 15 ++++++
2 files changed, 78 insertions(+), 32 deletions(-)
---
diff --git a/plug-ins/pstricks/render_pstricks.c b/plug-ins/pstricks/render_pstricks.c
index 481e6f2..455912f 100644
--- a/plug-ins/pstricks/render_pstricks.c
+++ b/plug-ins/pstricks/render_pstricks.c
@@ -118,6 +118,30 @@ static void draw_image(DiaRenderer *self,
real width, real height,
DiaImage *image);
+/*!
+ * \brief Advertize special capabilities
+ *
+ * Some objects drawing adapts to capabilities advertized by the respective
+ * renderer. Usually there is a fallback, but generally the real thing should
+ * be better.
+ *
+ * \memberof _PstricksRenderer
+ */
+static gboolean
+is_capable_to (DiaRenderer *renderer, RenderCapability cap)
+{
+ if (RENDER_HOLES == cap)
+ return TRUE; /* ... with under-documented fillstyle=eofill */
+ else if (RENDER_ALPHA == cap)
+ return FALSE; /* simulate with hatchwidth? */
+ else if (RENDER_AFFINE == cap)
+ return FALSE; /* maybe by: \translate, \scale, \rotate */
+ else if (RENDER_PATTERN == cap)
+ return FALSE; /* nope */
+ return FALSE;
+}
+
+/* GObject stuff */
static void pstricks_renderer_class_init (PstricksRendererClass *klass);
static gpointer parent_class = NULL;
@@ -168,6 +192,7 @@ pstricks_renderer_class_init (PstricksRendererClass *klass)
renderer_class->begin_render = begin_render;
renderer_class->end_render = end_render;
+ renderer_class->is_capable_to = is_capable_to;
renderer_class->set_linewidth = set_linewidth;
renderer_class->set_linecaps = set_linecaps;
@@ -429,21 +454,35 @@ draw_polyline(DiaRenderer *self,
}
static void
-pstricks_polygon(PstricksRenderer *renderer,
- Point *points, gint num_points,
- Color *line_color, gboolean filled)
+draw_polygon (DiaRenderer *self,
+ Point *points, int num_points,
+ Color *fill, Color *stroke)
{
+ PstricksRenderer *renderer = PSTRICKS_RENDERER(self);
gint i;
gchar px_buf[DTOSTR_BUF_SIZE];
gchar py_buf[DTOSTR_BUF_SIZE];
+ const char *style;
- set_line_color(renderer, line_color);
+ if (fill)
+ set_fill_color(renderer, fill);
+ if (stroke)
+ set_line_color(renderer, stroke);
+
+ if (fill && stroke)
+ style = "[fillstyle=eofill,fillcolor=diafillcolor,linecolor=dialinecolor]";
+ else if (fill)
+ style = "[fillstyle=eofill,fillcolor=diafillcolor]";
+ else
+ style = "";
/* The graphics objects all have a starred version (e.g., \psframe*) which
* draws a solid object whose color is linecolor. [pstricks-doc.pdf p7]
+ *
+ * Not properly documented, but still working ...
*/
fprintf(renderer->file, "\\pspolygon%s(%s,%s)",
- (filled?"*":""),
+ style,
pstricks_dtostr(px_buf,points[0].x),
pstricks_dtostr(py_buf,points[0].y) );
@@ -456,19 +495,6 @@ pstricks_polygon(PstricksRenderer *renderer,
}
static void
-draw_polygon (DiaRenderer *self,
- Point *points, int num_points,
- Color *fill, Color *stroke)
-{
- PstricksRenderer *renderer = PSTRICKS_RENDERER(self);
-
- if (fill)
- pstricks_polygon(renderer,points,num_points,fill,TRUE);
- if (stroke)
- pstricks_polygon(renderer,points,num_points,stroke,FALSE);
-}
-
-static void
pstricks_arc(PstricksRenderer *renderer,
Point *center,
real width, real height,
@@ -581,7 +607,9 @@ static void
pstricks_bezier(PstricksRenderer *renderer,
BezPoint *points,
gint numpoints,
- Color *color, gboolean filled)
+ Color *fill,
+ Color *stroke,
+ gboolean closed)
{
gint i;
gchar p1x_buf[DTOSTR_BUF_SIZE];
@@ -591,7 +619,10 @@ pstricks_bezier(PstricksRenderer *renderer,
gchar p3x_buf[DTOSTR_BUF_SIZE];
gchar p3y_buf[DTOSTR_BUF_SIZE];
- set_line_color(renderer,color);
+ if (fill)
+ set_fill_color(renderer,fill);
+ if (stroke)
+ set_line_color(renderer,stroke);
fprintf(renderer->file, "\\pscustom{\n");
@@ -605,7 +636,9 @@ pstricks_bezier(PstricksRenderer *renderer,
for (i = 1; i < numpoints; i++)
switch (points[i].type) {
case BEZ_MOVE_TO:
- g_warning("only first BezPoint can be a BEZ_MOVE_TO");
+ fprintf(renderer->file, "\\moveto(%s,%s)\n",
+ pstricks_dtostr(p1x_buf,points[i].p1.x),
+ pstricks_dtostr(p1y_buf,points[i].p1.y) );
break;
case BEZ_LINE_TO:
fprintf(renderer->file, "\\lineto(%s,%s)\n",
@@ -623,8 +656,13 @@ pstricks_bezier(PstricksRenderer *renderer,
break;
}
- if (filled)
- fprintf(renderer->file, "\\fill[fillstyle=solid,fillcolor=diafillcolor,linecolor=diafillcolor]}\n");
+ if (closed)
+ fprintf(renderer->file, "\\closepath\n");
+
+ if (fill && stroke)
+ fprintf(renderer->file, "\\fill[fillstyle=eofill,fillcolor=diafillcolor,linecolor=dialinecolor]}\n");
+ else if (fill)
+ fprintf(renderer->file, "\\fill[fillstyle=eofill,fillcolor=diafillcolor,linecolor=diafillcolor]}\n");
else
fprintf(renderer->file, "\\stroke}\n");
}
@@ -637,7 +675,7 @@ draw_bezier(DiaRenderer *self,
{
PstricksRenderer *renderer = PSTRICKS_RENDERER(self);
- pstricks_bezier(renderer,points,numpoints,color,FALSE);
+ pstricks_bezier(renderer,points,numpoints,NULL,color,FALSE);
}
@@ -650,14 +688,7 @@ draw_beziergon (DiaRenderer *self,
{
PstricksRenderer *renderer = PSTRICKS_RENDERER(self);
- /* XXX: it should be easy to fill and stroke in one step using
- * fillcolor and linecolor at the same time
- */
- if (fill)
- pstricks_bezier(renderer,points,numpoints,fill,TRUE);
- /* XXX: still not closing the path */
- if (stroke)
- pstricks_bezier(renderer,points,numpoints,stroke,FALSE);
+ pstricks_bezier(renderer,points,numpoints,fill,stroke,TRUE);
}
/* Do we really want to do this? What if the text is intended as
diff --git a/samples/pst-test.tex b/samples/pst-test.tex
new file mode 100644
index 0000000..24c2f61
--- /dev/null
+++ b/samples/pst-test.tex
@@ -0,0 +1,15 @@
+% Test file for Dia's PSTricks export
+\documentclass[landscape]{article}
+\usepackage[pdf]{pstricks}
+\usepackage[crop=off]{auto-pst-pdf}
+\title{Dia Export Test}
+\author{Hans Breuer}
+\begin{document}
+\maketitle
+\include{convert-to-path.pst}
+%\include{jigsaw.pst}
+% while the former files had clipping issues render-test does not
+% produce any visible result within in this setup, not even single
+% layers of it
+%\include{render-test.pst}
+\end{document}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]