From: north Date: Tue, 28 Jun 2005 21:23:14 +0000 (+0000) Subject: Hack for inline PS macros. Need this when the PS code attempts X-Git-Tag: LAST_LIBGRAPH~32^2~7489 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9abca4976330bca22bfe12da87e5ece412826c5d;p=graphviz Hack for inline PS macros. Need this when the PS code attempts to literally read the current file (e.g. Imagemagick SAVE output.) --- diff --git a/lib/common/psgen.c b/lib/common/psgen.c index 120a8097b..989ff37af 100644 --- a/lib/common/psgen.c +++ b/lib/common/psgen.c @@ -35,6 +35,7 @@ #include extern void epsf_define(FILE * of); +void epsf_emit_body(ps_image_t *img, FILE *of); extern void ps_freeusershapes(void); extern ps_image_t *ps_usershape(char *shapeimagefile); @@ -508,9 +509,11 @@ static void ps_user_shape(char *name, point * A, int sides, int filled) ps_begin_context(); offset.x = -img->origin.x - (img->size.x) / 2; offset.y = -img->origin.y - (img->size.y) / 2; - fprintf(Output_file, "%d %d translate newpath user_shape_%d\n", + fprintf(Output_file, "%d %d translate newpath\n", ND_coord_i(Curnode).x + offset.x, - ND_coord_i(Curnode).y + offset.y, img->macro_id); + ND_coord_i(Curnode).y + offset.y); + if (img->must_inline) epsf_emit_body(img,Output_file); + else fprintf(Output_file,"user_shape_%d\n",img->macro_id); ps_end_context(); } else if (shapeimagefile) { diff --git a/lib/common/psusershape.c b/lib/common/psusershape.c index c07031ca2..89a6ccb3c 100644 --- a/lib/common/psusershape.c +++ b/lib/common/psusershape.c @@ -49,7 +49,7 @@ static ps_image_t *user_init(char *str) char line[BUFSIZ]; FILE *fp; struct stat statbuf; - int saw_bb; + int saw_bb, must_inline; int lx, ly, ux, uy; ps_image_t *val; @@ -65,14 +65,15 @@ static ps_image_t *user_init(char *str) return NULL; } /* try to find size */ - saw_bb = FALSE; + saw_bb = must_inline = FALSE; while (fgets(line, sizeof(line), fp)) { if (sscanf (line, "%%%%BoundingBox: %d %d %d %d", &lx, &ly, &ux, &uy) == 4) { saw_bb = TRUE; - break; } + if ((line[0] != '%') && strstr(line,"read")) must_inline = TRUE; + if (saw_bb && must_inline) break; } if (saw_bb) { @@ -90,6 +91,7 @@ static ps_image_t *user_init(char *str) contents[statbuf.st_size] = '\0'; fclose(fp); dtinsert(EPSF_contents, val); + val->must_inline = must_inline; return val; } else { agerr(AGWARN, "BoundingBox not found in epsf file %s\n", str); @@ -127,50 +129,58 @@ void epsf_free(node_t * n) free(ND_shape_info(n)); } -void epsf_define(FILE * of) -{ #define FILTER_EPSF 1 -#if FILTER_EPSF - char *p; +#ifdef FILTER_EPSF +/* this removes EPSF DSC comments that, when nested in another + * document, cause errors in Ghostview and other Postscript + * processors (although legal according to the Adobe EPSF spec). */ +void epsf_emit_body(ps_image_t *img, FILE *of) +{ + char *p; + p = img->contents; + while (*p) { + /* skip %%EOF lines */ + if ((p[0] == '%') && (p[1] == '%') + && (!strncasecmp(&p[2], "EOF", 3) + || !strncasecmp(&p[2], "BEGIN", 5) + || !strncasecmp(&p[2], "END", 3) + || !strncasecmp(&p[2], "TRAILER", 7) + )) { + /* check for *p since last line might not end in '\n' */ + while (*p && (*p++ != '\n')); + continue; + } + do { + fputc(*p, of); + } while (*p++ != '\n'); + } +} +#else +void epsf_emit_body(ps_image_t *img, FILE *of) +{ + if (fputs(img->contents, of) == EOF) { + perror("epsf_define()->fputs"); + exit(EXIT_FAILURE); + } +} #endif + +void epsf_define(FILE * of) +{ ps_image_t *img; if (!EPSF_contents) return; for (img = dtfirst(EPSF_contents); img; img = dtnext(EPSF_contents, img)) { + if (img->must_inline) continue; fprintf(of, "/user_shape_%d {\n", img->macro_id); if (fputs("%%BeginDocument:\n", of) == EOF) { perror("epsf_define()->fputs"); exit(EXIT_FAILURE); } -#if FILTER_EPSF - /* this removes EPSF DSC comments that, when nested in another - * document, cause errors in Ghostview and other Postscript - * processors (although legal according to the Adobe EPSF spec). */ - p = img->contents; - while (*p) { /* skip %%EOF lines */ - if ((p[0] == '%') && (p[1] == '%') - && (!strncasecmp(&p[2], "EOF", 3) - || !strncasecmp(&p[2], "BEGIN", 5) - || !strncasecmp(&p[2], "END", 3) - || !strncasecmp(&p[2], "TRAILER", 7) - )) { - /* check for *p since last line might not end in '\n' */ - while (*p && (*p++ != '\n')); - continue; - } - do { - fputc(*p, of); - } while (*p++ != '\n'); - } -#else - if (fputs(img->contents, of) == EOF) { - perror("epsf_define()->fputs"); - exit(EXIT_FAILURE); - } -#endif + epsf_emit_body(img,of); if (fputs("%%EndDocument\n", of) == EOF) { perror("epsf_define()->fputs"); diff --git a/lib/common/render.h b/lib/common/render.h index fa29d2336..476a83ebf 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -69,6 +69,7 @@ typedef struct { point size; point origin; char *contents; + int must_inline; } ps_image_t;