From 47229fa0b3ce8c84b32460028094038c1d6f2a35 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 17 Apr 2006 12:48:05 +0000 Subject: [PATCH] * Truecolor support in the SVG and PostScript exporters. --- cucul/export_ps.c | 32 ++++++++++++++++---------------- cucul/export_svg.c | 37 ++++++++----------------------------- 2 files changed, 24 insertions(+), 45 deletions(-) diff --git a/cucul/export_ps.c b/cucul/export_ps.c index aff1d23..9709ccd 100644 --- a/cucul/export_ps.c +++ b/cucul/export_ps.c @@ -59,15 +59,6 @@ static char const *ps_header = */ void _cucul_get_ps(cucul_t *qq, cucul_buffer_t *ex) { - static char const * const palette[] = - { - "0.0 0.0 0.0", "0.0 0.0 0.5", "0.0 0.5 0.0", "0.0 0.5 0.5", - "0.5 0.0 0.0", "0.5 0.0 0.5", "0.5 0.5 0.0", "0.5 0.5 0.5", - - "0.2 0.2 0.2", "0.2 0.2 1.0", "0.2 1.0 0.2", "0.2 1.0 1.0", - "1.0 0.2 0.2", "1.0 0.2 1.0", "1.0 1.0 0.2", "1.0 1.0 1.0", - }; - char *cur; unsigned int x, y; @@ -87,8 +78,12 @@ void _cucul_get_ps(cucul_t *qq, cucul_buffer_t *ex) for(x = 0; x < qq->width; x++) { - cur += sprintf(cur, "1 0 translate\n %s csquare\n", - palette[_cucul_argb32_to_ansi4bg(*lineattr++)]); + uint8_t argb[8]; + _cucul_argb32_to_argb4(*lineattr++, argb); + cur += sprintf(cur, "1 0 translate\n %f %f %f csquare\n", + (float)argb[1] * (1.0 / 0xf), + (float)argb[2] * (1.0 / 0xf), + (float)argb[3] * (1.0 / 0xf)); } /* Return to beginning of the line, and jump to the next one */ @@ -104,12 +99,17 @@ void _cucul_get_ps(cucul_t *qq, cucul_buffer_t *ex) for(x = 0; x < qq->width; x++) { + uint8_t argb[8]; uint32_t c = *linechar++; + _cucul_argb32_to_argb4(*lineattr++, argb); + cur += sprintf(cur, "newpath\n"); - cur += sprintf(cur, "%d %d moveto\n", (x + 1) * 6, y * 10); - cur += sprintf(cur, "%s setrgbcolor\n", - palette[_cucul_argb32_to_ansi4fg(*lineattr++)]); + cur += sprintf(cur, "%d %d moveto\n", (x + 1) * 6, y * 10 + 2); + cur += sprintf(cur, "%f %f %f setrgbcolor\n", + (float)argb[5] * (1.0 / 0xf), + (float)argb[6] * (1.0 / 0xf), + (float)argb[7] * (1.0 / 0xf)); if(c < 0x00000020) cur += sprintf(cur, "(?) show\n"); @@ -117,8 +117,8 @@ void _cucul_get_ps(cucul_t *qq, cucul_buffer_t *ex) cur += sprintf(cur, "(?) show\n"); else switch((uint8_t)(c & 0x7f)) { - case '\\': cur += sprintf(cur, "(\\\\) show\n"); break; - case '(': cur += sprintf(cur, "(\\() show\n"); break; + case '\\': + case '(': case ')': cur += sprintf(cur, "(\\%c) show\n", c); break; diff --git a/cucul/export_svg.c b/cucul/export_svg.c index 0840322..8da4ad9 100644 --- a/cucul/export_svg.c +++ b/cucul/export_svg.c @@ -32,26 +32,14 @@ static char const svg_header[] = "\n" - " \n" - " \n"); - cur += sprintf(cur, " \n"); cur += sprintf(cur, " \n"); /* Background */ @@ -84,9 +62,9 @@ void _cucul_get_svg(cucul_t *qq, cucul_buffer_t *ex) for(x = 0; x < qq->width; x++) { - cur += sprintf(cur, "\n", - _cucul_argb32_to_ansi8(*lineattr++), + _cucul_argb32_to_rgb12bg(*lineattr++), x * 6, y * 10); } } @@ -101,8 +79,9 @@ void _cucul_get_svg(cucul_t *qq, cucul_buffer_t *ex) { uint32_t c = *linechar++; - cur += sprintf(cur, "", - _cucul_argb32_to_ansi8(*lineattr++), + cur += sprintf(cur, "", + _cucul_argb32_to_rgb12fg(*lineattr++), x * 6, (y * 10) + 10); if(c < 0x00000020) cur += sprintf(cur, "?");