Skip to content

problem clipping R postscript plots within latex (PR#625)

4 messages · Brian Ripley, Paul Murrell, Peter Dalgaard

#
On Wed, 2 Aug 2000 p.dalgaard@biostat.ku.dk wrote:

            
Just to note that ?postscript says

    The postscript produced by R is EPS (Encapsulated PostScript)
    compatible,

yet initclip is not allowed in EPS files (PostScript Language Reference
Manual, 2nd edition).  I think the statement was possibly true once ....
#
ripley@stats.ox.ac.uk writes:
Exactly.
I don't think so. This is a design problem.

Unfortunately, the simple fix above doesn't seem to work [for rather
foreseeable reasons]. mosaicplot() seems to crash ghostview and even
plot(1:10) comes out without axis titles. 

The latter item occurs because we're doing

clip(region1)
set font
draw text
clip(region2)
draw more text in same font

but restoring the graphics context prior to the first clipping 
requires the font to be set once again. And there are probably many
similar problems. Sigh. 

Paul, are you around?
#
hi
Yes I'm around (I'm just concealed by my teaching load).  However, I may not
be much help.  This seems to be a problem with the definitions in the
postscript file header (set up in PSFileHeader).  [Trying not to sound like
I'm dodging a bullet ...] I have never delved too deeply into these so I
cannot really comment on their goodness or badness.  AFAIK this is all
pretty original stuff (by Ross ?), but I'm not sure what it was based on.
Something Ross has mentioned to me a couple of times is a library which
allows you to write C-like code which then gets processed into (correct,
efficient) postscript.  Maybe this would be a good solution (i.e., piggyback
on some other code which has got all of the postscript stuff properly sorted
out).  Sorry I can't be more help at this stage.

paul


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:
...
However, fixing the font issue seems to have done the trick. Fix
committed to the development branch (to become R 1.2). I'm not
trusting that fix enough to let it go into 1.1.1.

Here's the patch in case someone needs it:


$ cvs diff -ur 1.29 src/main/devPS.c
Index: src/main/devPS.c
===================================================================
RCS file: /home/rdevel/CVS-ARCHIVE/R/src/main/devPS.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- src/main/devPS.c    2000/06/27 22:26:19     1.29
+++ src/main/devPS.c    2000/08/04 15:35:33     1.30
@@ -549,10 +549,10 @@
     fprintf(fp, "/gs  { gsave } def\n");
     fprintf(fp, "/gr  { grestore } def\n");
     if (landscape)
-       fprintf(fp, "/bp  { gs %.2f 0 translate 90 rotate} def\n", paperwidth);
+       fprintf(fp, "/bp  { gs %.2f 0 translate 90 rotate gs } def\n", paperwidth);
     else
-       fprintf(fp, "/bp  { gs } def\n");
-    fprintf(fp, "/ep  { showpage gr } def\n");
+       fprintf(fp, "/bp  { gs gs } def\n");
+    fprintf(fp, "/ep  { showpage gr gr } def\n");
     fprintf(fp, "/m   { moveto } def\n");
     fprintf(fp, "/l   { lineto } def\n");
     fprintf(fp, "/np  { newpath } def\n");
@@ -569,7 +569,7 @@
     fprintf(fp, "       ps mul neg 0 2 1 roll rmoveto\n");
     fprintf(fp, "       1 index stringwidth pop\n");
     fprintf(fp, "       mul neg 0 rmoveto show grestore } def\n");
-    fprintf(fp, "/cl  { initclip newpath 3 index 3 index moveto 1 index\n");
+    fprintf(fp, "/cl  { gr gs newpath 3 index 3 index moveto 1 index\n");
     fprintf(fp, "       4 -1 roll lineto  exch 1 index lineto lineto\n");
     fprintf(fp, "       closepath clip newpath } def\n");
     fprintf(fp, "/rgb { setrgbcolor } def\n");
@@ -1133,6 +1133,8 @@
     PostScriptDesc *pd = (PostScriptDesc *) dd->deviceSpecific;
 
     PostScriptSetClipRect(pd->psfp, x0, x1, y0, y1);
+    /* clipping does grestore so invalidate current font */
+    pd->fontsize = -1; 
 }
 
 static void PS_Resize(DevDesc *dd)