Browse Source

* Make output drivers more error resilient when handling UTF-32 characters,

by simply ignoring everything non ASCII :-)
tags/v0.99.beta14
Sam Hocevar sam 19 years ago
parent
commit
a499e05961
6 changed files with 60 additions and 30 deletions
  1. +7
    -1
      caca/driver_conio.c
  2. +13
    -14
      caca/driver_gl.c
  3. +6
    -1
      caca/driver_ncurses.c
  4. +13
    -5
      caca/driver_slang.c
  5. +7
    -1
      caca/driver_win32.c
  6. +14
    -8
      caca/driver_x11.c

+ 7
- 1
caca/driver_conio.c View File

@@ -103,7 +103,13 @@ static void conio_display(caca_t *kk)
uint32_t *chars = kk->qq->chars;
for(n = kk->qq->height * kk->qq->width; n--; )
{
*screen++ = *chars++ & 0x7f;
uint32_t c = *chars++;

if(c > 0x00000020 && c < 0x00000080)
*screen++ = (char)c;
else
*screen++ = ' ';

*screen++ = *attr++;
}
# if defined(SCREENUPDATE_IN_PC_H)


+ 13
- 14
caca/driver_gl.c View File

@@ -78,7 +78,7 @@ struct driver_private
unsigned int new_width, new_height;
float font_width, font_height;
float incx, incy;
int id[94];
int id[128 - 32];
unsigned char bit;
unsigned char mouse_changed, mouse_clicked;
unsigned int mouse_x, mouse_y;
@@ -164,27 +164,27 @@ static int gl_init_graphics(caca_t *kk)
memset(empty_texture, 0xff, 16 * 16 * 4);
glEnable(GL_TEXTURE_2D);

for(i = 0; i < 94; i++)
for(i = 32; i < 128; i++)
{
glGenTextures(1, (GLuint*)&kk->drv.p->id[i]);
glBindTexture(GL_TEXTURE_2D, kk->drv.p->id[i]);
glGenTextures(1, (GLuint*)&kk->drv.p->id[i - 32]);
glBindTexture(GL_TEXTURE_2D, kk->drv.p->id[i - 32]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,
16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, empty_texture);
}

for(i = 0; i < 94; i++)
for(i = 32; i < 128; i++)
{
glDisable(GL_TEXTURE_2D);
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1, 1, 1);
glRasterPos2f(0, 15);
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, i + 32);
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, i);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, kk->drv.p->id[i]);
glBindTexture(GL_TEXTURE_2D, kk->drv.p->id[i - 32]);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
0, kk->drv.p->height - 16, 16, 16, 0);

@@ -236,7 +236,8 @@ static void gl_display(caca_t *kk)
glBegin(GL_QUADS);
glVertex2f(x, y);
glVertex2f(x + kk->drv.p->font_width, y);
glVertex2f(x + kk->drv.p->font_width, y + kk->drv.p->font_height);
glVertex2f(x + kk->drv.p->font_width,
y + kk->drv.p->font_height);
glVertex2f(x, y + kk->drv.p->font_height);
glEnd();

@@ -259,12 +260,11 @@ static void gl_display(caca_t *kk)

for(x = 0; x < kk->drv.p->width; x += kk->drv.p->font_width)
{
if(*chars != (uint32_t)' ')
{
char ch = *chars & 0x7f;
uint32_t c = *chars++;

/* FIXME: check ch bounds */
glBindTexture(GL_TEXTURE_2D, kk->drv.p->id[ch - 32]);
if(c > 0x00000020 && c < 0x00000080)
{
glBindTexture(GL_TEXTURE_2D, kk->drv.p->id[c - 32]);
glColor4bv(gl_bgpal[attr[0] & 0xf]);
glBegin(GL_QUADS);
glTexCoord2f(0, kk->drv.p->sh);
@@ -279,7 +279,6 @@ static void gl_display(caca_t *kk)
}

attr++;
chars++;
}
line++;
}


+ 6
- 1
caca/driver_ncurses.c View File

@@ -192,8 +192,13 @@ static void ncurses_display(caca_t *kk)
move(y, 0);
for(x = kk->qq->width; x--; )
{
uint32_t c = *chars++;

attrset(kk->drv.p->attr[*attr++]);
addch(*chars++ & 0x7f);
if(c > 0x00000020 && c < 0x00000080)
addch((char)c);
else
addch(' ');
}
}
refresh();


+ 13
- 5
caca/driver_slang.c View File

@@ -203,15 +203,21 @@ static void slang_display(caca_t *kk)
SLsmg_gotorc(y, 0);
for(x = kk->qq->width; x--; )
{
uint32_t c = *chars++;

#if defined(OPTIMISE_SLANG_PALETTE)
/* If foreground == background, just don't use this colour
* pair, and print a space instead of the real character. */
uint8_t fgcolor = *attr & 0xf;
uint8_t bgcolor = *attr >> 4;

/* If foreground == background, just don't use this colour
* pair, and print a space instead of the real character. */
if(fgcolor != bgcolor)
{
SLsmg_set_color(slang_assoc[*attr++]);
SLsmg_write_char(*chars++ & 0x7f);
if(c > 0x00000020 && 0x00000080)
SLsmg_write_char((char)c);
else
SLsmg_write_char(' ');
}
else
{
@@ -224,12 +230,14 @@ static void slang_display(caca_t *kk)
fgcolor = CUCUL_COLOR_WHITE;
SLsmg_set_color(slang_assoc[fgcolor + 16 * bgcolor]);
SLsmg_write_char(' ');
chars++;
attr++;
}
#else
SLsmg_set_color(*attr++);
SLsmg_write_char(*chars++ & 0x7f);
if(c > 0x00000020 && 0x00000080)
SLsmg_write_char((char)c);
else
SLsmg_write_char(' ');
#endif
}
}


+ 7
- 1
caca/driver_win32.c View File

@@ -198,7 +198,13 @@ static void win32_display(caca_t *kk)
/* Render everything to our back buffer */
for(i = 0; i < kk->qq->width * kk->qq->height; i++)
{
kk->drv.p->buffer[i].Char.AsciiChar = kk->qq->chars[i] & 0x7f;
uint32_t c = kk->qq->chars[i];

if(c > 0x00000020 && c < 0x00000080)
kk->drv.p->buffer[i].Char.AsciiChar = (char)c;
else
kk->drv.p->buffer[i].Char.AsciiChar = ' ';

kk->drv.p->buffer[i].Attributes =
win32_fg_palette[kk->qq->attr[i] & 0xf]
| win32_bg_palette[kk->qq->attr[i] >> 4];


+ 14
- 8
caca/driver_x11.c View File

@@ -271,6 +271,9 @@ static void x11_display(caca_t *kk)
/* Then print the foreground characters */
for(y = 0; y < kk->qq->height; y++)
{
unsigned int yoff = (y + 1) * kk->drv.p->font_height
- kk->drv.p->font_offset;

for(x = 0; x < kk->qq->width; x += len)
{
char buffer[BUFSIZ]; /* FIXME: use a smaller buffer */
@@ -280,27 +283,30 @@ static void x11_display(caca_t *kk)
len = 1;

/* Skip spaces */
if(chars[0] == ' ')
if(chars[0] <= 0x00000020 || chars[0] >= 0x00000080)
continue;

buffer[0] = chars[0] & 0x7f;
buffer[0] = (char)chars[0];

while(x + len < kk->qq->width
&& (attr[len] & 0xf) == (attr[0] & 0xf))
{
buffer[len] = chars[len] & 0x7f;
if(chars[len] > 0x00000020 && chars[len] < 0x00000080)
buffer[len] = (char)chars[len];
else
buffer[len] = ' ';
len++;
}

XSetForeground(kk->drv.p->dpy, kk->drv.p->gc, kk->drv.p->colors[attr[0] & 0xf]);
XSetForeground(kk->drv.p->dpy, kk->drv.p->gc,
kk->drv.p->colors[attr[0] & 0xf]);
XDrawString(kk->drv.p->dpy, kk->drv.p->pixmap, kk->drv.p->gc,
x * kk->drv.p->font_width,
(y + 1) * kk->drv.p->font_height - kk->drv.p->font_offset,
buffer, len);
x * kk->drv.p->font_width, yoff, buffer, len);
}
}

XCopyArea(kk->drv.p->dpy, kk->drv.p->pixmap, kk->drv.p->window, kk->drv.p->gc, 0, 0,
XCopyArea(kk->drv.p->dpy, kk->drv.p->pixmap, kk->drv.p->window,
kk->drv.p->gc, 0, 0,
kk->qq->width * kk->drv.p->font_width,
kk->qq->height * kk->drv.p->font_height,
0, 0);


Loading…
Cancel
Save