]> granicus.if.org Git - graphviz/commitdiff
Hack for inline PS macros. Need this when the PS code attempts
authornorth <devnull@localhost>
Tue, 28 Jun 2005 21:23:14 +0000 (21:23 +0000)
committernorth <devnull@localhost>
Tue, 28 Jun 2005 21:23:14 +0000 (21:23 +0000)
to literally read the current file (e.g. Imagemagick SAVE output.)

lib/common/psgen.c
lib/common/psusershape.c
lib/common/render.h

index 120a8097bbaf0dca48003ee7cfb6564481be6cca..989ff37af95d3d6b0ec340cec623a4fce866f9e0 100644 (file)
@@ -35,6 +35,7 @@
 #include <stdio.h>
 
 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) {
index c07031ca2af6919db32e72c0ae38a8d928c2c946..89a6ccb3c932807ea589fb8a521068009caf196f 100644 (file)
@@ -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");
index fa29d2336b9da8559ad234eb5eac08d9f160c87d..476a83ebf66935b0b92706256bfa46d80ef128f4 100644 (file)
@@ -69,6 +69,7 @@ typedef struct {
     point size;
     point origin;
     char *contents;
+    int        must_inline;
 } ps_image_t;