From 7fddcf89e260f660b49621f757c45f460f3eae44 Mon Sep 17 00:00:00 2001 From: oetiker Date: Tue, 10 May 2005 18:35:55 +0000 Subject: [PATCH] fix for character escaping in EPS -- Peter Speck git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@538 a5681a0c-68f1-0310-ab6d-d61299d08faa --- src/rrd_gfx.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/rrd_gfx.c b/src/rrd_gfx.c index 9322e9e..b38f5ad 100644 --- a/src/rrd_gfx.c +++ b/src/rrd_gfx.c @@ -1696,7 +1696,7 @@ static void eps_write_linearea(eps_state *state, gfx_node_t *node) static void eps_write_text(eps_state *state, gfx_node_t *node) { FILE *fp = state->fp; - const unsigned char *p; + const char *p; const char *ps_font = afm_get_font_postscript_name(node->filename); int lineLen = 0; pdf_coords g; @@ -1712,28 +1712,41 @@ static void eps_write_text(eps_state *state, gfx_node_t *node) fputs("T1 ", fp); fputs("(", fp); lineLen = 20; - for (p = (const unsigned char*)node->text; *p; p++) { - if (lineLen > 70) { + p = node->text; + while (1) { + unsigned char ch = *(unsigned char*)p; + if (!ch) + break; + if (++lineLen > 70) { fputs("\\\n", fp); /* backslash and \n */ lineLen = 0; } - switch (*p) { + switch (ch) { + case '%': case '(': case ')': case '\\': + fputc('\\', fp); + fputc(ch, fp); + break; case '\n': + fputs("\\n", fp); + break; case '\r': + fputs("\\r", fp); + break; case '\t': - fputc('\\', fp); - lineLen++; - /* fall-through */ + fputs("\\t", fp); + break; default: - if (*p >= 126) - fprintf(fp, "\\%03o", *p); - else - fputc(*p, fp); - lineLen++; - } + if (ch >= 126 || ch < 32) { + fprintf(fp, "\\%03o", ch); + lineLen += 3; + } else { + fputc(ch, fp); + } + } + p++; } if (node->angle) { /* can't use svg_write_number as 2 decimals is far from enough to avoid @@ -1927,7 +1940,7 @@ static void pdf_put_string_contents(pdf_buffer *buf, const char *text) { const char *p = text; while (1) { - char ch = *p; + unsigned char ch = *(unsigned char*)p; switch (ch) { case 0: return; case '(': -- 2.11.0