From 7754db5ccf3f5ade0f97d5a3c1cde49da90bb4ce Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 18 May 2006 06:23:47 +0000 Subject: [PATCH] * Changed cucul_putchar's prototype so that it accepts a 32-bit unsigned int which shall be used as an UTF-32 character. We do not have any casting problems due to the signedness of chars because all characters were ASCII (ie. <= 0x7f) beforehands. --- cucul/box.c | 18 +++++++++--------- cucul/canvas.c | 34 +++++++++++----------------------- cucul/conic.c | 8 ++++---- cucul/cucul.h | 2 +- cucul/cucul_internals.h | 1 - cucul/dither.c | 6 +++--- cucul/import.c | 4 ++-- cucul/line.c | 32 ++++++++++++++++---------------- cucul/triangle.c | 2 +- test/font2tga.c | 2 +- 10 files changed, 48 insertions(+), 61 deletions(-) diff --git a/cucul/box.c b/cucul/box.c index 03c3b0f..93bfa7a 100644 --- a/cucul/box.c +++ b/cucul/box.c @@ -84,32 +84,32 @@ int cucul_draw_thin_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2) /* Draw edges */ if(y1 >= 0) for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) - _cucul_putchar32(cv, x, y1, (uint32_t)'-'); + cucul_putchar(cv, x, y1, '-'); if(y2 <= ymax) for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) - _cucul_putchar32(cv, x, y2, (uint32_t)'-'); + cucul_putchar(cv, x, y2, '-'); if(x1 >= 0) for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) - _cucul_putchar32(cv, x1, y, (uint32_t)'|'); + cucul_putchar(cv, x1, y, '|'); if(x2 <= xmax) for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) - _cucul_putchar32(cv, x2, y, (uint32_t)'|'); + cucul_putchar(cv, x2, y, '|'); /* Draw corners */ if(x1 >= 0 && y1 >= 0) - _cucul_putchar32(cv, x1, y1, (uint32_t)','); + cucul_putchar(cv, x1, y1, ','); if(x1 >= 0 && y2 <= ymax) - _cucul_putchar32(cv, x1, y2, (uint32_t)'`'); + cucul_putchar(cv, x1, y2, '`'); if(x2 <= xmax && y1 >= 0) - _cucul_putchar32(cv, x2, y1, (uint32_t)'.'); + cucul_putchar(cv, x2, y1, '.'); if(x2 <= xmax && y2 <= ymax) - _cucul_putchar32(cv, x2, y2, (uint32_t)'\''); + cucul_putchar(cv, x2, y2, '\''); return 0; } @@ -159,7 +159,7 @@ int cucul_fill_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, for(y = y1; y <= y2; y++) for(x = x1; x <= x2; x++) - _cucul_putchar32(cv, x, y, ch); + cucul_putchar(cv, x, y, ch); return 0; } diff --git a/cucul/canvas.c b/cucul/canvas.c index 483f69c..dfa702d 100644 --- a/cucul/canvas.c +++ b/cucul/canvas.c @@ -41,14 +41,16 @@ #include "cucul.h" #include "cucul_internals.h" -/** \brief Print an ASCII character. +/** \brief Print an ASCII or Unicode character. * - * This function prints an ASCII character at the given coordinates, using - * the default foreground and background values. If the coordinates are - * outside the canvas boundaries, nothing is printed. If the character - * value is a non-printable character or is outside the ASCII range, it is - * replaced with a space. To print a sequence of bytes forming an UTF-8 - * character, use cucul_putstr() instead. + * This function prints an ASCII or Unicode character at the given + * coordinates, using the default foreground and background values. + * + * If the coordinates are outside the canvas boundaries, nothing is printed. + * If the character value is a non-printable character or is outside the + * UTF-32 range, it is replaced with a space. To print a sequence of bytes + * forming an UTF-8 character instead of an UTF-32 character, use the + * cucul_putstr() function instead. * * This function never fails. * @@ -58,12 +60,12 @@ * \param ch The character to print. * \return This function always returns 0. */ -int cucul_putchar(cucul_canvas_t *cv, int x, int y, char ch) +int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch) { if(x < 0 || x >= (int)cv->width || y < 0 || y >= (int)cv->height) return 0; - if((unsigned char)ch < 0x20 || (unsigned char)ch > 0x7f) + if((unsigned char)ch < 0x20) ch = 0x20; cv->chars[x + y * cv->width] = ch; @@ -260,17 +262,3 @@ int cucul_blit(cucul_canvas_t *dst, int x, int y, return 0; } -/* - * XXX: The following functions are not exported - */ - -void _cucul_putchar32(cucul_canvas_t *cv, int x, int y, uint32_t ch) -{ - if(x < 0 || x >= (int)cv->width || - y < 0 || y >= (int)cv->height) - return; - - cv->chars[x + y * cv->width] = ch; - cv->attr[x + y * cv->width] = (cv->bgcolor << 16) | cv->fgcolor; -} - diff --git a/cucul/conic.c b/cucul/conic.c index 2380829..bd640b3 100644 --- a/cucul/conic.c +++ b/cucul/conic.c @@ -248,15 +248,15 @@ static void ellipsepoints(cucul_canvas_t *cv, int xo, int yo, int x, int y, b |= 0x8; if((b & (0x1|0x4)) == (0x1|0x4)) - _cucul_putchar32(cv, xo + x, yo + y, ch); + cucul_putchar(cv, xo + x, yo + y, ch); if((b & (0x2|0x4)) == (0x2|0x4)) - _cucul_putchar32(cv, xo - x, yo + y, ch); + cucul_putchar(cv, xo - x, yo + y, ch); if((b & (0x1|0x8)) == (0x1|0x8)) - _cucul_putchar32(cv, xo + x, yo - y, ch); + cucul_putchar(cv, xo + x, yo - y, ch); if((b & (0x2|0x8)) == (0x2|0x8)) - _cucul_putchar32(cv, xo - x, yo - y, ch); + cucul_putchar(cv, xo - x, yo - y, ch); } diff --git a/cucul/cucul.h b/cucul/cucul.h index c60af13..f8819eb 100644 --- a/cucul/cucul.h +++ b/cucul/cucul.h @@ -100,7 +100,7 @@ int cucul_free_buffer(cucul_buffer_t *); int cucul_set_color(cucul_canvas_t *, unsigned char, unsigned char); int cucul_set_truecolor(cucul_canvas_t *, unsigned int, unsigned int); char const *cucul_get_color_name(unsigned int); -int cucul_putchar(cucul_canvas_t *, int, int, char); +int cucul_putchar(cucul_canvas_t *, int, int, unsigned long int); int cucul_putstr(cucul_canvas_t *, int, int, char const *); int cucul_printf(cucul_canvas_t *, int, int, char const *, ...); int cucul_clear_canvas(cucul_canvas_t *); diff --git a/cucul/cucul_internals.h b/cucul/cucul_internals.h index 0226107..9027545 100644 --- a/cucul/cucul_internals.h +++ b/cucul/cucul_internals.h @@ -52,7 +52,6 @@ extern int _cucul_end_dither(void); /* Canvas functions */ extern int _cucul_set_canvas_size(cucul_canvas_t *, unsigned int, unsigned int); -extern void _cucul_putchar32(cucul_canvas_t *, int, int, uint32_t); /* Charset functions */ extern unsigned int _cucul_strlen_utf8(char const *); diff --git a/cucul/dither.c b/cucul/dither.c index 27a4933..d75f5a9 100644 --- a/cucul/dither.c +++ b/cucul/dither.c @@ -83,7 +83,7 @@ static int const rgb_palette[] = static int const rgb_weight[] = { - //2, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2 + /* 2, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; @@ -114,7 +114,7 @@ enum color_mode COLOR_MODE_16, COLOR_MODE_FULLGRAY, COLOR_MODE_FULL8, - COLOR_MODE_FULL16, + COLOR_MODE_FULL16 }; struct cucul_dither @@ -1061,7 +1061,7 @@ int cucul_dither_bitmap(cucul_canvas_t *cv, int x, int y, int w, int h, /* Now output the character */ cucul_set_color(cv, outfg, outbg); - _cucul_putchar32(cv, x, y, outch); + cucul_putchar(cv, x, y, outch); d->increment_dither(); } diff --git a/cucul/import.c b/cucul/import.c index dea72c0..139ba5d 100644 --- a/cucul/import.c +++ b/cucul/import.c @@ -382,7 +382,7 @@ static cucul_canvas_t *import_ansi(void const *data, unsigned int size) if(width < 80) cucul_set_canvas_size(cv, width = 80, height); for(j = x; j < 80; j++) - _cucul_putchar32(cv, j, y, (uint32_t)' '); + cucul_putchar(cv, j, y, ' '); x = 80; break; case 'm': /* SGR - Select Graphic Rendition */ @@ -405,7 +405,7 @@ static cucul_canvas_t *import_ansi(void const *data, unsigned int size) cucul_set_canvas_size(cv, width, height = y + 1); /* Now paste our character */ - _cucul_putchar32(cv, x, y, _cucul_cp437_to_utf32(buffer[i])); + cucul_putchar(cv, x, y, _cucul_cp437_to_utf32(buffer[i])); x++; } diff --git a/cucul/line.c b/cucul/line.c index 151de5e..5dcf0d2 100644 --- a/cucul/line.c +++ b/cucul/line.c @@ -260,7 +260,7 @@ static void draw_solid_line(cucul_canvas_t *cv, struct line* s) for(; dx>=0; dx--) { - _cucul_putchar32(cv, x1, y1, s->ch); + cucul_putchar(cv, x1, y1, s->ch); if(delta > 0) { x1 += xinc; @@ -282,7 +282,7 @@ static void draw_solid_line(cucul_canvas_t *cv, struct line* s) for(; dy >= 0; dy--) { - _cucul_putchar32(cv, x1, y1, s->ch); + cucul_putchar(cv, x1, y1, s->ch); if(delta > 0) { x1 += xinc; @@ -309,14 +309,14 @@ static void draw_thin_line(cucul_canvas_t *cv, struct line* s) if(s->x2 >= s->x1) { - charmapx[0] = (s->y1 > s->y2) ? (uint32_t)',' : (uint32_t)'`'; - charmapx[1] = (s->y1 > s->y2) ? (uint32_t)'\'' : (uint32_t)'.'; + charmapx[0] = (s->y1 > s->y2) ? ',' : '`'; + charmapx[1] = (s->y1 > s->y2) ? '\'' : '.'; x1 = s->x1; y1 = s->y1; x2 = s->x2; y2 = s->y2; } else { - charmapx[0] = (s->y1 > s->y2) ? (uint32_t)'`' : (uint32_t)'.'; - charmapx[1] = (s->y1 > s->y2) ? (uint32_t)',' : (uint32_t)'\''; + charmapx[0] = (s->y1 > s->y2) ? '`' : '.'; + charmapx[1] = (s->y1 > s->y2) ? ',' : '\''; x2 = s->x1; y2 = s->y1; x1 = s->x2; y1 = s->y2; } @@ -325,15 +325,15 @@ static void draw_thin_line(cucul_canvas_t *cv, struct line* s) if(y1 > y2) { - charmapy[0] = (uint32_t)','; - charmapy[1] = (uint32_t)'\''; + charmapy[0] = ','; + charmapy[1] = '\''; yinc = -1; } else { yinc = 1; - charmapy[0] = (uint32_t)'`'; - charmapy[1] = (uint32_t)'.'; + charmapy[0] = '`'; + charmapy[1] = '.'; } if(dx >= dy) @@ -347,7 +347,7 @@ static void draw_thin_line(cucul_canvas_t *cv, struct line* s) { if(delta > 0) { - _cucul_putchar32(cv, x1, y1, charmapy[1]); + cucul_putchar(cv, x1, y1, charmapy[1]); x1++; y1 += yinc; delta += dpru; @@ -356,9 +356,9 @@ static void draw_thin_line(cucul_canvas_t *cv, struct line* s) else { if(prev) - _cucul_putchar32(cv, x1, y1, charmapy[0]); + cucul_putchar(cv, x1, y1, charmapy[0]); else - _cucul_putchar32(cv, x1, y1, (uint32_t)'-'); + cucul_putchar(cv, x1, y1, '-'); x1++; delta += dpr; prev = 0; @@ -375,15 +375,15 @@ static void draw_thin_line(cucul_canvas_t *cv, struct line* s) { if(delta > 0) { - _cucul_putchar32(cv, x1, y1, charmapx[0]); - _cucul_putchar32(cv, x1 + 1, y1, charmapx[1]); + cucul_putchar(cv, x1, y1, charmapx[0]); + cucul_putchar(cv, x1 + 1, y1, charmapx[1]); x1++; y1 += yinc; delta += dpru; } else { - _cucul_putchar32(cv, x1, y1, (uint32_t)'|'); + cucul_putchar(cv, x1, y1, '|'); y1 += yinc; delta += dpr; } diff --git a/cucul/triangle.c b/cucul/triangle.c index 9c1aeff..d738ac0 100644 --- a/cucul/triangle.c +++ b/cucul/triangle.c @@ -141,7 +141,7 @@ int cucul_fill_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, if(xb > xmax) xb = xmax; for(x = xa; x <= xb; x++) - _cucul_putchar32(cv, x, y, ch); + cucul_putchar(cv, x, y, ch); } return 0; diff --git a/test/font2tga.c b/test/font2tga.c index eab2ccc..ae16388 100644 --- a/test/font2tga.c +++ b/test/font2tga.c @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) { for(j = blocklist[i]; j < blocklist[i + 1]; j++) { - _cucul_putchar32(cv, x, y, j); + cucul_putchar(cv, x, y, j); if(++x == WIDTH) {