From 8d698a1158c59265618c5656d6386c2235f297c1 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 17 Mar 2006 09:56:28 +0000 Subject: [PATCH] * Full Unicode support in the SVG exporter. --- cucul/export_svg.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/cucul/export_svg.c b/cucul/export_svg.c index 285f45a..9fbf798 100644 --- a/cucul/export_svg.c +++ b/cucul/export_svg.c @@ -106,10 +106,36 @@ void _cucul_get_svg(cucul_t *qq, struct cucul_buffer *ex) *lineattr++, x * 6, (y * 10) + 10); if(c < 0x00000020) cur += sprintf(cur, "?"); - else if(c < 0x00000080) - cur += sprintf(cur, "%c", c); - else - cur += sprintf(cur, "?"); /* FIXME: SVG supports UTF-8 */ + else if(c > 0x0000007f) + { + static const uint8_t mark[7] = + { + 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC + }; + + char buf[10], *parser; + int bytes = (c < 0x800) ? 2 : (c < 0x10000) ? 3 : 4; + + buf[bytes] = '\0'; + parser = buf + bytes; + + switch(bytes) + { + case 4: *--parser = (c | 0x80) & 0xbf; c >>= 6; + case 3: *--parser = (c | 0x80) & 0xbf; c >>= 6; + case 2: *--parser = (c | 0x80) & 0xbf; c >>= 6; + } + *--parser = c | mark[bytes]; + + cur += sprintf(cur, "%s", buf); + } + else switch((uint8_t)c) + { + case '>': cur += sprintf(cur, ">"); break; + case '<': cur += sprintf(cur, "<"); break; + case '&': cur += sprintf(cur, "&"); break; + default: cur += sprintf(cur, "%c", c); break; + } cur += sprintf(cur, "\n"); } }