pstricks export



I can verify #143414 and #161636 (marked as a DUP).

The relevant issue has come up on the pstricks mailing list a couple
of times.  The cause is a conflict with the graphicx \scalebox macro.
See:

  <http://tug.org/mailman/htdig/pstricks/2004/001692.html>

The resolution is to switch to the new \psscalebox syntax (recent
versions of pstricks won't clobber \scalebox), with the arguments in
the same format as dia is using now.

Nevertheless, the rendering at the moment is too naive to produce good
quality output: the text is undersized and the baseline is incorrectly
aligned.

In regards to escaping for TeX ala tex_escape_string (there seems to
be some controversy in the comments), I think it's a good thing unless
Dia becomes smart enough to do its own TeX processing (like, say,
Ipe).  If people put raw TeX code inside a Dia container expecting it
to look good after going through pstricks, they'll be disappointed.
The rendererd TeX won't have the same bounding box as the raw text
that Dia sees and the rendered text can underfill or overflow its
container.

The extent of the escaping should be documented, and that
seemingly-innocent characters might not be translated faithfully.
Consider the "<" and ">" used in Dia UML diagrams for stereotypes.
Under the default (OT1) font encoding, they'll come up as inverted "!"
and "?"  instead of the guillemets they are translated to in other
encodings.  In general though, you can probably count on LaTeX users
to know what they're doing.

As a minor issue, it would be nice for pstricks hackers (and rendering
times, file sizes, etc) if the actual pstricks code was cleaner.  Here
are a few easy optimisations:

  - keep a static record of the last fill and line colour used, and
    only print pstricks code to change the colour if necessary

  - do the y-coordinate transformation in the filter so that
    postscript isn't rendering upside down

The attached patches are blind (I didn't have the necessary
dependencies on hand to rebuild), but they're not complex.

Index: render_pstricks.c
===================================================================
RCS file: /cvs/gnome/dia/plug-ins/pstricks/render_pstricks.c,v
retrieving revision 1.23
diff -u -r1.23 render_pstricks.c
--- render_pstricks.c   18 Jul 2005 18:53:28 -0000      1.23
+++ render_pstricks.c   3 Dec 2005 09:54:15 -0000
@@ -783,7 +783,7 @@
        fprintf(renderer->file,"[r]");
        break;
     }
-    fprintf(renderer->file,"(%s,%s){\\scalebox{1 -1}{%s}}\n",
+    fprintf(renderer->file,"(%s,%s){\\psscalebox{1 -1}{%s}}\n",
            pstricks_dtostr(px_buf,pos->x),
            pstricks_dtostr(py_buf,pos->y),
            escaped );
@@ -957,7 +957,7 @@
            pstricks_dtostr(eb_buf,-extent->bottom * data->paper.scaling),
            pstricks_dtostr(er_buf,extent->right * data->paper.scaling),
            pstricks_dtostr(et_buf,-extent->top * data->paper.scaling) );
-    fprintf(renderer->file,"\\scalebox{%s %s}{\n",
+    fprintf(renderer->file,"\\psscalebox{%s %s}{\n",
            pstricks_dtostr(scale1_buf,data->paper.scaling),
            pstricks_dtostr(scale2_buf,-data->paper.scaling) );
 
Index: render_pstricks.c
===================================================================
RCS file: /cvs/gnome/dia/plug-ins/pstricks/render_pstricks.c,v
retrieving revision 1.23
diff -u -r1.23 render_pstricks.c
--- render_pstricks.c   18 Jul 2005 18:53:28 -0000      1.23
+++ render_pstricks.c   3 Dec 2005 10:45:04 -0000
@@ -214,6 +214,11 @@
     gchar green_buf[DTOSTR_BUF_SIZE];
     gchar blue_buf[DTOSTR_BUF_SIZE];
 
+    if (!memcmp(color, &renderer->saved_line_color, sizeof(Color)))
+       return;
+
+    renderer->saved_line_color = *color;
+
     fprintf(renderer->file, "\\newrgbcolor{dialinecolor}{%s %s %s}\n",
            pstricks_dtostr(red_buf, (gdouble) color->red),
            pstricks_dtostr(green_buf, (gdouble) color->green),
@@ -228,6 +233,11 @@
     gchar green_buf[DTOSTR_BUF_SIZE];
     gchar blue_buf[DTOSTR_BUF_SIZE];
 
+    if (!memcmp(color, &renderer->saved_fill_color, sizeof(Color)))
+       return;
+
+    renderer->saved_fill_color = *color;
+
     fprintf(renderer->file, "\\newrgbcolor{diafillcolor}{%s %s %s}\n",
            pstricks_dtostr(red_buf, (gdouble) color->red),
            pstricks_dtostr(green_buf, (gdouble) color->green),
@@ -919,6 +929,8 @@
     renderer->dash_length = 1.0;
     renderer->dot_length = 0.2;
     renderer->saved_line_style = LINESTYLE_SOLID;
+    renderer->saved_line_color = color_black;
+    renderer->saved_fill_color = color_white;
   
     time_now  = time(NULL);
     extent = &data->extents;
@@ -961,15 +973,9 @@
            pstricks_dtostr(scale1_buf,data->paper.scaling),
            pstricks_dtostr(scale2_buf,-data->paper.scaling) );
 
-    initial_color.red=0.;
-    initial_color.green=0.;
-    initial_color.blue=0.;
-    set_line_color(renderer,&initial_color);
-
-    initial_color.red=1.;
-    initial_color.green=1.;
-    initial_color.blue=1.;
-    set_fill_color(renderer,&initial_color);
+    /* line/fill are switched to force output at least once */
+    set_line_color(renderer,&renderer->saved_fill_color);
+    set_fill_color(renderer,&renderer->saved_line_color);
 
     data_render(data, DIA_RENDERER(renderer), NULL, NULL, NULL);
 
Index: render_pstricks.h
===================================================================
RCS file: /cvs/gnome/dia/plug-ins/pstricks/render_pstricks.h,v
retrieving revision 1.2
diff -u -r1.2 render_pstricks.h
--- render_pstricks.h   11 Oct 2002 20:39:00 -0000      1.2
+++ render_pstricks.h   3 Dec 2005 10:45:04 -0000
@@ -58,6 +58,9 @@
     LineStyle saved_line_style;
     real dash_length;
     real dot_length;
+
+    Color saved_line_color;
+    Color saved_fill_color;
 };
 
 extern DiaExportFilter pstricks_export_filter;

-- 
Dean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]