[GRASS-dev] ps.map: simple pattern code

Hi,

A simple code (to efficiency and avoid mistakes) are:

File: eps.c
-----------
- replace
  int pat_save(FILE * fp, char *epsf, char *name)
  by
  int pat_store(FILE *fp, int code, char *epsf,
    double pwidth, double sc,
          int R, int G, int B)
{
char buf[1024];
FILE *epsfp;
double llx, lly, urx, ury;

if ((epsfp = fopen(epsf, "r")) == NULL)
  return (0);

eps_bbox(epsf, &llx, &lly, &urx, &ury);

fprintf(fp, "/PATTERN%d\n", code);
fprintf(PS.fp, "<< /PatternType 1\n /PaintType 1\n /TilingType 1\n");
fprintf(PS.fp, " /BBox [%f %f %f %f]\n", llx*sc, lly*sc, urx*sc, ury*sc);
fprintf(PS.fp, " /XStep %f\n /YStep %f\n", (urx-llx)*sc, (ury-lly)*sc);
fprintf(PS.fp, " /PaintProc\n");
fprintf(PS.fp, " { begin\n");
fprintf(PS.fp, " %.4f %.4f scale\n", sc, sc);
fprintf(PS.fp, " %.4f %.4f %.4f C\n", R/255., G/255., B/255.);
fprintf(PS.fp, " %.8f W\n", pwidth);
while (fgets(buf, 1024, epsfp) != NULL)
{
  if (strncmp(buf, "%!PS-Adobe", 10) == 0 ||
      strncmp(buf, "%%BoundingBox", 13) == 0)
    continue;
  fprintf(fp, " %s", buf);
}
fprintf(PS.fp, " end }\n");
fprintf(PS.fp, ">> store\n");

fclose(epsfp);
return (1);
}

File: vareas.c
--------------
replace code by

if (vector.layer[vec].pat != NULL) { /* use pattern */
  pat_store(PS.fp, vec, vector.layer[vec].pat,
    vector.layer[vec].pwidth, vector.layer[vec].scale,
    vector.layer[vec].fcolor.r,
          vector.layer[vec].fcolor.g,
    vector.layer[vec].fcolor.b); /* define pattern, TODO check if exist */

  /* use pattern by number, now */
  fprintf(PS.fp, "/Pattern setcolorspace ");
  fprintf(PS.fp, "PATTERN%d matrix makepattern setcolor\n", vec);

File: vlegend.c
---------------
replace code by
  if (vector.layer[i].pat != NULL) {
    /* use pattern by number, now */
    fprintf(PS.fp, "/Pattern setcolorspace ");
    fprintf(PS.fp, "PATTERN%d matrix makepattern setcolor\n", i);
  }

--
E. Jorge Tizado

E. Jorge Tizado wrote:

A simple code (to efficiency and avoid mistakes) are:

File: eps.c
-----------

Hi Jorge,

could you please create a patch against SVN trunk and post it to the
trac system? (all diffs in one file) It makes it much much easier for
us to manage.

I created a ticket for it already:
  http://trac.osgeo.org/grass/ticket/487

hints about making a patch:
  http://grass.osgeo.org/wiki/Patches
  http://grass.osgeo.org/wiki/Working_with_SVN (needs CVS -> SVN updates!)

thanks,
Hamish