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.
tags/v0.99.beta14
| @@ -84,32 +84,32 @@ int cucul_draw_thin_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2) | |||||
| /* Draw edges */ | /* Draw edges */ | ||||
| if(y1 >= 0) | if(y1 >= 0) | ||||
| for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) | 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) | if(y2 <= ymax) | ||||
| for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) | 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) | if(x1 >= 0) | ||||
| for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) | 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) | if(x2 <= xmax) | ||||
| for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) | 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 */ | /* Draw corners */ | ||||
| if(x1 >= 0 && y1 >= 0) | if(x1 >= 0 && y1 >= 0) | ||||
| _cucul_putchar32(cv, x1, y1, (uint32_t)','); | |||||
| cucul_putchar(cv, x1, y1, ','); | |||||
| if(x1 >= 0 && y2 <= ymax) | if(x1 >= 0 && y2 <= ymax) | ||||
| _cucul_putchar32(cv, x1, y2, (uint32_t)'`'); | |||||
| cucul_putchar(cv, x1, y2, '`'); | |||||
| if(x2 <= xmax && y1 >= 0) | if(x2 <= xmax && y1 >= 0) | ||||
| _cucul_putchar32(cv, x2, y1, (uint32_t)'.'); | |||||
| cucul_putchar(cv, x2, y1, '.'); | |||||
| if(x2 <= xmax && y2 <= ymax) | if(x2 <= xmax && y2 <= ymax) | ||||
| _cucul_putchar32(cv, x2, y2, (uint32_t)'\''); | |||||
| cucul_putchar(cv, x2, y2, '\''); | |||||
| return 0; | 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(y = y1; y <= y2; y++) | ||||
| for(x = x1; x <= x2; x++) | for(x = x1; x <= x2; x++) | ||||
| _cucul_putchar32(cv, x, y, ch); | |||||
| cucul_putchar(cv, x, y, ch); | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| @@ -41,14 +41,16 @@ | |||||
| #include "cucul.h" | #include "cucul.h" | ||||
| #include "cucul_internals.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. | * This function never fails. | ||||
| * | * | ||||
| @@ -58,12 +60,12 @@ | |||||
| * \param ch The character to print. | * \param ch The character to print. | ||||
| * \return This function always returns 0. | * \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) | if(x < 0 || x >= (int)cv->width || y < 0 || y >= (int)cv->height) | ||||
| return 0; | return 0; | ||||
| if((unsigned char)ch < 0x20 || (unsigned char)ch > 0x7f) | |||||
| if((unsigned char)ch < 0x20) | |||||
| ch = 0x20; | ch = 0x20; | ||||
| cv->chars[x + y * cv->width] = ch; | cv->chars[x + y * cv->width] = ch; | ||||
| @@ -260,17 +262,3 @@ int cucul_blit(cucul_canvas_t *dst, int x, int y, | |||||
| return 0; | 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; | |||||
| } | |||||
| @@ -248,15 +248,15 @@ static void ellipsepoints(cucul_canvas_t *cv, int xo, int yo, int x, int y, | |||||
| b |= 0x8; | b |= 0x8; | ||||
| if((b & (0x1|0x4)) == (0x1|0x4)) | 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)) | 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)) | 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)) | if((b & (0x2|0x8)) == (0x2|0x8)) | ||||
| _cucul_putchar32(cv, xo - x, yo - y, ch); | |||||
| cucul_putchar(cv, xo - x, yo - y, ch); | |||||
| } | } | ||||
| @@ -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_color(cucul_canvas_t *, unsigned char, unsigned char); | ||||
| int cucul_set_truecolor(cucul_canvas_t *, unsigned int, unsigned int); | int cucul_set_truecolor(cucul_canvas_t *, unsigned int, unsigned int); | ||||
| char const *cucul_get_color_name(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_putstr(cucul_canvas_t *, int, int, char const *); | ||||
| int cucul_printf(cucul_canvas_t *, int, int, char const *, ...); | int cucul_printf(cucul_canvas_t *, int, int, char const *, ...); | ||||
| int cucul_clear_canvas(cucul_canvas_t *); | int cucul_clear_canvas(cucul_canvas_t *); | ||||
| @@ -52,7 +52,6 @@ extern int _cucul_end_dither(void); | |||||
| /* Canvas functions */ | /* Canvas functions */ | ||||
| extern int _cucul_set_canvas_size(cucul_canvas_t *, unsigned int, unsigned int); | 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 */ | /* Charset functions */ | ||||
| extern unsigned int _cucul_strlen_utf8(char const *); | extern unsigned int _cucul_strlen_utf8(char const *); | ||||
| @@ -83,7 +83,7 @@ static int const rgb_palette[] = | |||||
| static int const rgb_weight[] = | 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 | 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_16, | ||||
| COLOR_MODE_FULLGRAY, | COLOR_MODE_FULLGRAY, | ||||
| COLOR_MODE_FULL8, | COLOR_MODE_FULL8, | ||||
| COLOR_MODE_FULL16, | |||||
| COLOR_MODE_FULL16 | |||||
| }; | }; | ||||
| struct cucul_dither | 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 */ | /* Now output the character */ | ||||
| cucul_set_color(cv, outfg, outbg); | cucul_set_color(cv, outfg, outbg); | ||||
| _cucul_putchar32(cv, x, y, outch); | |||||
| cucul_putchar(cv, x, y, outch); | |||||
| d->increment_dither(); | d->increment_dither(); | ||||
| } | } | ||||
| @@ -382,7 +382,7 @@ static cucul_canvas_t *import_ansi(void const *data, unsigned int size) | |||||
| if(width < 80) | if(width < 80) | ||||
| cucul_set_canvas_size(cv, width = 80, height); | cucul_set_canvas_size(cv, width = 80, height); | ||||
| for(j = x; j < 80; j++) | for(j = x; j < 80; j++) | ||||
| _cucul_putchar32(cv, j, y, (uint32_t)' '); | |||||
| cucul_putchar(cv, j, y, ' '); | |||||
| x = 80; | x = 80; | ||||
| break; | break; | ||||
| case 'm': /* SGR - Select Graphic Rendition */ | 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); | cucul_set_canvas_size(cv, width, height = y + 1); | ||||
| /* Now paste our character */ | /* 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++; | x++; | ||||
| } | } | ||||
| @@ -260,7 +260,7 @@ static void draw_solid_line(cucul_canvas_t *cv, struct line* s) | |||||
| for(; dx>=0; dx--) | for(; dx>=0; dx--) | ||||
| { | { | ||||
| _cucul_putchar32(cv, x1, y1, s->ch); | |||||
| cucul_putchar(cv, x1, y1, s->ch); | |||||
| if(delta > 0) | if(delta > 0) | ||||
| { | { | ||||
| x1 += xinc; | x1 += xinc; | ||||
| @@ -282,7 +282,7 @@ static void draw_solid_line(cucul_canvas_t *cv, struct line* s) | |||||
| for(; dy >= 0; dy--) | for(; dy >= 0; dy--) | ||||
| { | { | ||||
| _cucul_putchar32(cv, x1, y1, s->ch); | |||||
| cucul_putchar(cv, x1, y1, s->ch); | |||||
| if(delta > 0) | if(delta > 0) | ||||
| { | { | ||||
| x1 += xinc; | x1 += xinc; | ||||
| @@ -309,14 +309,14 @@ static void draw_thin_line(cucul_canvas_t *cv, struct line* s) | |||||
| if(s->x2 >= s->x1) | 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; | x1 = s->x1; y1 = s->y1; x2 = s->x2; y2 = s->y2; | ||||
| } | } | ||||
| else | 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; | 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) | if(y1 > y2) | ||||
| { | { | ||||
| charmapy[0] = (uint32_t)','; | |||||
| charmapy[1] = (uint32_t)'\''; | |||||
| charmapy[0] = ','; | |||||
| charmapy[1] = '\''; | |||||
| yinc = -1; | yinc = -1; | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| yinc = 1; | yinc = 1; | ||||
| charmapy[0] = (uint32_t)'`'; | |||||
| charmapy[1] = (uint32_t)'.'; | |||||
| charmapy[0] = '`'; | |||||
| charmapy[1] = '.'; | |||||
| } | } | ||||
| if(dx >= dy) | if(dx >= dy) | ||||
| @@ -347,7 +347,7 @@ static void draw_thin_line(cucul_canvas_t *cv, struct line* s) | |||||
| { | { | ||||
| if(delta > 0) | if(delta > 0) | ||||
| { | { | ||||
| _cucul_putchar32(cv, x1, y1, charmapy[1]); | |||||
| cucul_putchar(cv, x1, y1, charmapy[1]); | |||||
| x1++; | x1++; | ||||
| y1 += yinc; | y1 += yinc; | ||||
| delta += dpru; | delta += dpru; | ||||
| @@ -356,9 +356,9 @@ static void draw_thin_line(cucul_canvas_t *cv, struct line* s) | |||||
| else | else | ||||
| { | { | ||||
| if(prev) | if(prev) | ||||
| _cucul_putchar32(cv, x1, y1, charmapy[0]); | |||||
| cucul_putchar(cv, x1, y1, charmapy[0]); | |||||
| else | else | ||||
| _cucul_putchar32(cv, x1, y1, (uint32_t)'-'); | |||||
| cucul_putchar(cv, x1, y1, '-'); | |||||
| x1++; | x1++; | ||||
| delta += dpr; | delta += dpr; | ||||
| prev = 0; | prev = 0; | ||||
| @@ -375,15 +375,15 @@ static void draw_thin_line(cucul_canvas_t *cv, struct line* s) | |||||
| { | { | ||||
| if(delta > 0) | 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++; | x1++; | ||||
| y1 += yinc; | y1 += yinc; | ||||
| delta += dpru; | delta += dpru; | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| _cucul_putchar32(cv, x1, y1, (uint32_t)'|'); | |||||
| cucul_putchar(cv, x1, y1, '|'); | |||||
| y1 += yinc; | y1 += yinc; | ||||
| delta += dpr; | delta += dpr; | ||||
| } | } | ||||
| @@ -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; | if(xb > xmax) xb = xmax; | ||||
| for(x = xa; x <= xb; x++) | for(x = xa; x <= xb; x++) | ||||
| _cucul_putchar32(cv, x, y, ch); | |||||
| cucul_putchar(cv, x, y, ch); | |||||
| } | } | ||||
| return 0; | return 0; | ||||
| @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) | |||||
| { | { | ||||
| for(j = blocklist[i]; j < blocklist[i + 1]; j++) | for(j = blocklist[i]; j < blocklist[i + 1]; j++) | ||||
| { | { | ||||
| _cucul_putchar32(cv, x, y, j); | |||||
| cucul_putchar(cv, x, y, j); | |||||
| if(++x == WIDTH) | if(++x == WIDTH) | ||||
| { | { | ||||