[Rd] Re: [R] problem clipping R postscript plots within latex (PR#625)

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
04 Aug 2000 17:45:42 +0200


Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:

> ripley@stats.ox.ac.uk writes:
> 
> > > >     /cl  { gr gs newpath 3 index 3 index moveto 1 index
> > > > 	   4 -1 roll lineto  exch 1 index lineto lineto
> > > > 	   closepath clip newpath } def
> > > > 
> > > >     PD> and end everything with a "gr". Not too sure that is perfectly
> > > >     PD> safe, though...
...
> 
> 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. 

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)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._