]> granicus.if.org Git - graphviz/commitdiff
Fix bug 1025 - if charset != latin1, have postscript check for latin1
authorerg <devnull@localhost>
Fri, 22 Sep 2006 22:16:33 +0000 (22:16 +0000)
committererg <devnull@localhost>
Fri, 22 Sep 2006 22:16:33 +0000 (22:16 +0000)
values in the utf-8 and convert them to latin1 for the postscript output.

lib/common/psusershape.c
plugin/core/gvrender_core_ps.c

index f9cfe3498625a30afe3e52512d752d6b255605b9..c7cfd4a1eed7e430a8dd68a53bb2ea6030a4a03f 100644 (file)
@@ -194,17 +194,55 @@ void epsf_define(FILE * of)
     }
 }
 
+enum {ASCII, LATIN1, NONLATIN};
+
+/* charsetOf:
+ * Assuming legal utf-8 input, determine if
+ * the character value range is ascii, latin-1 or otherwise.
+ */
+static int
+charsetOf (char* s)
+{
+    int r = ASCII;
+    unsigned char c;
+
+    while ((c = *(unsigned char*)s++)) {
+       if (c < 0x7F) 
+           continue;
+       else if ((c & 0xFC) == 0xC0) {
+           r = LATIN1;
+           s++; /* eat second byte */
+       }
+       else return NONLATIN;
+    }
+    return r;
+}
+
 char *ps_string(char *ins, int latin)
 {
     char *s;
     char *base;
     static agxbuf  xb;
+    static int warned;
     int rc;
 
     if (latin)
         base = utf8ToLatin1 (ins);
-    else
+    else switch (charsetOf (ins)) {
+    case ASCII :
         base = ins;
+       break;
+    case LATIN1 :
+        base = utf8ToLatin1 (ins);
+       break;
+    case NONLATIN :
+        if (!warned) {
+           agerr (AGWARN, "UTF-8 input uses non-Latin1 characters which cannot be handled in PostScript output");
+           warned = 1;
+       }
+        base = ins;
+       break;
+    }
 
     if (xb.buf == NULL)
         agxbinit (&xb, 0, NULL);
index 61f486a11a433c5cda50c51ae05832d88412829c..ed854b67bd60c50cf5c66ea43a1d64828979669a 100644 (file)
@@ -103,7 +103,13 @@ static void psgen_begin_graph(GVJ_t * job)
         epsf_define(job->output_file);
     }
     isLatin1 = (GD_charset(obj->u.g) == CHAR_LATIN1);
-    if (isLatin1 && !setupLatin1) {
+    /* We always setup Latin1. The charset info is always output,
+     * and installing it is cheap. With it installed, we can then
+     * rely on ps_string to convert UTF-8 characters whose encoding
+     * is in the range of Latin-1 into the Latin-1 equivalent and
+     * get the expected PostScript output.
+     */
+    if (!setupLatin1) {
        core_fputs(job, "setupLatin1\n");       /* as defined in ps header */
        setupLatin1 = TRUE;
     }