瀏覽代碼

* Truecolor support in the SVG and PostScript exporters.

tags/v0.99.beta14
Sam Hocevar sam 18 年之前
父節點
當前提交
47229fa0b3
共有 2 個文件被更改,包括 24 次插入45 次删除
  1. +16
    -16
      cucul/export_ps.c
  2. +8
    -29
      cucul/export_svg.c

+ 16
- 16
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;


+ 8
- 29
cucul/export_svg.c 查看文件

@@ -32,26 +32,14 @@ static char const svg_header[] =
"<svg width=\"%d\" height=\"%d\" viewBox=\"0 0 %d %d\""
" xmlns=\"http://www.w3.org/2000/svg\""
" xmlns:xlink=\"http://www.w3.org/1999/xlink\""
" xml:space=\"preserve\" version=\"1.1\" baseProfile=\"full\">\n"
" <defs>\n"
" <style type=\"text/css\">\n"
" <![CDATA[\n";
" xml:space=\"preserve\" version=\"1.1\" baseProfile=\"full\">\n";

/** \brief Generate SVG representation of current image.
*
* This function generates and returns a SVG representation of
/*
* This function generates and returns an SVG representation of
* the current image.
*/
void _cucul_get_svg(cucul_t *qq, cucul_buffer_t *ex)
{
static int const palette[] =
{
0x000000, 0x000088, 0x008800, 0x008888,
0x880000, 0x880088, 0x888800, 0x888888,
0x444444, 0x4444ff, 0x44ff44, 0x44ffff,
0xff4444, 0xff44ff, 0xffff44, 0xffffff,
};

char *cur;
unsigned int x, y;

@@ -65,16 +53,6 @@ void _cucul_get_svg(cucul_t *qq, cucul_buffer_t *ex)
cur += sprintf(cur, svg_header, qq->width * 6, qq->height * 10,
qq->width * 6, qq->height * 10);

/* Precalc of colors in CSS style */
for(x = 0; x < 0x100; x++)
{
cur += sprintf(cur, ".b%02x {fill:#%06X}\n", x, palette[x >> 4]);
cur += sprintf(cur, ".f%02x {fill:#%06X}\n", x, palette[x & 0xf]);
}

cur += sprintf(cur, "]]>\n");
cur += sprintf(cur, " </style>\n");
cur += sprintf(cur, " </defs>\n");
cur += sprintf(cur, " <g id=\"mainlayer\" font-size=\"12\">\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, "<rect class=\"b%02x\" x=\"%d\" y=\"%d\""
cur += sprintf(cur, "<rect style=\"fill:#%.03x\" x=\"%d\" y=\"%d\""
" width=\"6\" height=\"10\"/>\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, "<text class=\"f%02x\" x=\"%d\" y=\"%d\">",
_cucul_argb32_to_ansi8(*lineattr++),
cur += sprintf(cur, "<text style=\"fill:#%.03x\" "
"x=\"%d\" y=\"%d\">",
_cucul_argb32_to_rgb12fg(*lineattr++),
x * 6, (y * 10) + 10);
if(c < 0x00000020)
cur += sprintf(cur, "?");


Loading…
取消
儲存