|
|
@@ -30,32 +30,31 @@ |
|
|
|
#include "cucul_internals.h" |
|
|
|
|
|
|
|
|
|
|
|
char ps_header[] = {"%%! \n \ |
|
|
|
%%%% libcaca PDF export \n \ |
|
|
|
%%%%LanguageLevel: 2 \n \ |
|
|
|
%%%%Pages: 1 \n \ |
|
|
|
%%%%DocumentData: Clean7Bit \n \ |
|
|
|
/csquare { \n \ |
|
|
|
newpath \n \ |
|
|
|
0 0 moveto \n \ |
|
|
|
0 1 rlineto \n \ |
|
|
|
1 0 rlineto \n \ |
|
|
|
0 -1 rlineto \n \ |
|
|
|
closepath \n \ |
|
|
|
setrgbcolor \n \ |
|
|
|
fill \n \ |
|
|
|
} def \n \ |
|
|
|
/S { \n \ |
|
|
|
Show \n \ |
|
|
|
} bind def \n \ |
|
|
|
\n \ |
|
|
|
\n \ |
|
|
|
/Times-Roman findfont \n \ |
|
|
|
8 scalefont \n \ |
|
|
|
setfont\n \ |
|
|
|
6 10 scale \n"}; |
|
|
|
|
|
|
|
|
|
|
|
char ps_header[] = {"%%! \n " |
|
|
|
"%%%% libcaca PDF export \n " |
|
|
|
"%%%%LanguageLevel: 2 \n " |
|
|
|
"%%%%Pages: 1 \n " |
|
|
|
"%%%%DocumentData: Clean7Bit \n " |
|
|
|
"/csquare { \n " |
|
|
|
" newpath \n " |
|
|
|
" 0 0 moveto \n " |
|
|
|
" 0 1 rlineto \n " |
|
|
|
" 1 0 rlineto \n " |
|
|
|
" 0 -1 rlineto \n " |
|
|
|
" closepath \n " |
|
|
|
" setrgbcolor \n " |
|
|
|
" fill \n " |
|
|
|
"} def \n " |
|
|
|
"/S { \n " |
|
|
|
" Show \n " |
|
|
|
"} bind def \n " |
|
|
|
" \n " |
|
|
|
" \n " |
|
|
|
"/Courier-Bold findfont \n " |
|
|
|
"8 scalefont \n " |
|
|
|
"setfont\n " |
|
|
|
"gsave \n " |
|
|
|
"6 10 scale \n"}; |
|
|
|
|
|
|
|
|
|
|
|
/** \brief Generate Postscript representation of current image. |
|
|
@@ -65,38 +64,37 @@ setfont\n \ |
|
|
|
*/ |
|
|
|
char* cucul_get_ps(cucul_t *qq, int *size) |
|
|
|
{ |
|
|
|
char *cur; |
|
|
|
int x, y; |
|
|
|
|
|
|
|
static float const paletteR[] = |
|
|
|
{ |
|
|
|
0, 0, 0, 0, |
|
|
|
0.5, 0.5, 0.5, 0.5, |
|
|
|
0.5, 0.5, 0.5, 0.5, |
|
|
|
1.0, 1.0, 1.0, 1.0, |
|
|
|
}; |
|
|
|
{ |
|
|
|
0, 0, 0, 0, |
|
|
|
0.5, 0.5, 0.5, 0.5, |
|
|
|
0.5, 0.5, 0.5, 0.5, |
|
|
|
1.0, 1.0, 1.0, 1.0, |
|
|
|
}; |
|
|
|
static float const paletteG[] = |
|
|
|
{ |
|
|
|
0, 0, 0.5, 0.5, |
|
|
|
0, 0, 0.5, 0.5, |
|
|
|
0, 0, 1.0, 1.0, |
|
|
|
0, 0, 1.0, 1.0, |
|
|
|
}; |
|
|
|
{ |
|
|
|
0, 0, 0.5, 0.5, |
|
|
|
0, 0, 0.5, 0.5, |
|
|
|
0, 0, 1.0, 1.0, |
|
|
|
0, 0, 1.0, 1.0, |
|
|
|
}; |
|
|
|
static float const paletteB[] = |
|
|
|
{ |
|
|
|
0, 0.5, 0, 0.5, |
|
|
|
0, 0.5, 0, 0.5, |
|
|
|
0, 1.0, 0.5, 1.0, |
|
|
|
0, 1.0, 0, 1.0, |
|
|
|
}; |
|
|
|
|
|
|
|
{ |
|
|
|
0, 0.5, 0, 0.5, |
|
|
|
0, 0.5, 0, 0.5, |
|
|
|
0, 1.0, 0.5, 1.0, |
|
|
|
0, 1.0, 0, 1.0, |
|
|
|
}; |
|
|
|
|
|
|
|
char *cur; |
|
|
|
unsigned int x, y; |
|
|
|
|
|
|
|
if(qq->ps_buffer) |
|
|
|
free(qq->ps_buffer); |
|
|
|
|
|
|
|
/* 400 is arbitrary and needs to be precised */ |
|
|
|
qq->ps_buffer = malloc((strlen(ps_header) + (qq->height*qq->width)*400) * sizeof(char)); |
|
|
|
/* 200 is arbitrary but should be ok */ |
|
|
|
qq->ps_buffer = malloc((strlen(ps_header) + (qq->height*qq->width)*200) * sizeof(char)); |
|
|
|
cur = qq->ps_buffer; |
|
|
|
|
|
|
|
/* Header */ |
|
|
@@ -104,10 +102,10 @@ char* cucul_get_ps(cucul_t *qq, int *size) |
|
|
|
|
|
|
|
|
|
|
|
/* Background, drawn using csquare macro defined in header */ |
|
|
|
for(y=0;y<qq->height; y++) { |
|
|
|
for(y=(int)(qq->height-1);y>=0; y--) { |
|
|
|
uint8_t *lineattr = qq->attr + y * qq->width; |
|
|
|
|
|
|
|
for(x = 0; x < qq->width; x++) { |
|
|
|
for(x = 0; x < (int)qq->width; x++) { |
|
|
|
float bgR = paletteR[lineattr[x] >> 4]; |
|
|
|
float bgG = paletteG[lineattr[x] >> 4]; |
|
|
|
float bgB = paletteB[lineattr[x] >> 4]; |
|
|
@@ -122,25 +120,22 @@ char* cucul_get_ps(cucul_t *qq, int *size) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/* Text. FIXME, doesn't work yet */ |
|
|
|
cur += sprintf(cur, "1 1 scale\n"); |
|
|
|
cur += sprintf(cur, "newpath\n0 0 moveto\n"); |
|
|
|
for(y=0;y<qq->height; y++) { |
|
|
|
uint8_t *lineattr = qq->attr + y * qq->width; |
|
|
|
cur += sprintf(cur, "grestore\n"); // Restore normal transformation matrix |
|
|
|
for(y=(int)(qq->height-1);y>=0; y--) { |
|
|
|
uint8_t *lineattr = qq->attr + y * qq->width; |
|
|
|
uint32_t *linechar = qq->chars + y * qq->width; |
|
|
|
|
|
|
|
for(x = 0; x < qq->width; x++) { |
|
|
|
for(x = 0; x < (int)qq->width; x++) { |
|
|
|
uint32_t cR = linechar[x]; |
|
|
|
float fgR = paletteR[lineattr[x] & 0x0f]; |
|
|
|
float fgG = paletteG[lineattr[x] & 0x0f]; |
|
|
|
float fgB = paletteB[lineattr[x] & 0x0f]; |
|
|
|
|
|
|
|
cur += sprintf(cur, "newpath\n%d %d moveto\n", (x+1)*6, (y)*10); |
|
|
|
cur += sprintf(cur, "%f %f %f setrgbcolor\n", fgR, fgG, fgB); |
|
|
|
cur += sprintf(cur, "1 0 translate\n"); |
|
|
|
cur += sprintf(cur, "{%c} \n", cR); |
|
|
|
cur += sprintf(cur, "(%c) show\n", cR); |
|
|
|
|
|
|
|
} |
|
|
|
cur += sprintf(cur, "%d 1 translate \n", -qq->width); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@@ -148,6 +143,7 @@ char* cucul_get_ps(cucul_t *qq, int *size) |
|
|
|
|
|
|
|
/* Crop to really used size */ |
|
|
|
*size = (strlen(qq->ps_buffer) + 1) * sizeof(char); |
|
|
|
|
|
|
|
qq->ps_buffer = realloc(qq->ps_buffer, *size); |
|
|
|
|
|
|
|
return qq->ps_buffer; |
|
|
|