[R] pattern on bars?

Jim Lemon bitwrit at ozemail.com.au
Tue Aug 8 14:31:27 CEST 2000


Apologies for late posting, I've been off the air for a couple of days.
This may help with the pattern problem, one which I have had myself.
The following sample C code contains two functions that will fill a
PostScript path with hatch lines.  If I have understood the code in
'devPS.c' correctly, the functions should fit into the method currently
used for filling, that is, the entire "fill" function is bracketed
within "gsave...grestore".

Please let me know if:
a) it is useful
b) there are any mods necessary to integrate it with the current code

Jim
-------------- next part --------------
#include <stdio.h>
#include <unistd.h>

static void PostScriptInitHatch(FILE *fp) {
 char *hatch_cmd[] =
  {"<< /PaintType 2 /PatternType 1 /TilingType 1",
   "/BBox [-11 -11 11 11] /XStep 20 /YStep 20",
   "/PaintProc { pop 0 -10 moveto 0 10 lineto stroke } >>",
   "matrix makepattern /VertLine exch def",
   "<< /PaintType 2 /PatternType 1 /TilingType 1",
   "/BBox [-11 -11 11 11] /XStep 20 /YStep 20",
   "/PaintProc { pop -10 0 moveto 10 0 lineto stroke } >>",
   "matrix makepattern /HorizLine exch def",
   "<< /PaintType 2 /PatternType 1 /TilingType 1",
   "/BBox [-11 -11 11 11] /XStep 20 /YStep 20",
   "/PaintProc { pop -10 -10 moveto 10 10 lineto stroke } >>",
   "matrix makepattern /URLine exch def",
   "<< /PaintType 2 /PatternType 1 /TilingType 1",
   "/BBox [-11 -11 11 11] /XStep 20 /YStep 20",
   "/PaintProc { pop 10 -10 moveto -10 10 lineto stroke } >>",
   "matrix makepattern /ULLine exch def",
   "[/Pattern /DeviceRGB] setcolorspace",
   NULL};
 int index = 0;

 while(hatch_cmd[index]) fprintf(fp,"%s\n",hatch_cmd[index++]);
}

#define N_HATCH 4

static void PostScriptHatchFill(FILE *fp,double r,double g,double b,
 int hatch_type) {
 char *hatch_name[N_HATCH] = {"VertLine","HorizLine","URLine","ULLine"};

 if(hatch_type > 0 && hatch_type <= N_HATCH)
  fprintf(fp,"%.3f %.3f %.3f %s setpattern fill\n",r,g,b,hatch_name[hatch_type-1]);
}

int main() {
 FILE *fp;
 
 if((fp = fopen("testhatch.ps","w")) != NULL) {
  fprintf(fp,"%%!PS-Adobe-2.0 EPSF-2.0\n");
  fprintf(fp,"%%%%BoundingBox: 0 0 200 200\n");
  fprintf(fp,"%%%%EndComments\n");
  PostScriptInitHatch(fp);
  fprintf(fp,"2 setlinewidth\n0 0 0 setrgbcolor\n");
  fprintf(fp,"50 50 50 0 360 arc gsave\n");
  PostScriptHatchFill(fp,0,0,1,1);
  fprintf(fp,"grestore stroke\n");
  fprintf(fp,"150 50 50 0 360 arc gsave\n");
  PostScriptHatchFill(fp,1,0,1,2);
  fprintf(fp,"grestore stroke\n");
  fprintf(fp,"50 150 50 0 360 arc gsave\n");
  PostScriptHatchFill(fp,1,1,0,3);
  fprintf(fp,"grestore stroke\n");
  fprintf(fp,"150 150 50 0 360 arc gsave\n");
  PostScriptHatchFill(fp,0,1,0,4);
  fprintf(fp,"grestore stroke\n");
  fprintf(fp,"showpage\n");
  fclose(fp);
 }
 return(0);
}


More information about the R-help mailing list