From 2fcc915da9e1ca0788424511f359c74231fedcc7 Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 3 Jan 2014 02:15:58 +0100 Subject: Fixed font rnedering and width computation --- host/matelight/font.c | 5 +++-- host/matelight/main.c | 57 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/host/matelight/font.c b/host/matelight/font.c index f22f05b..725e039 100644 --- a/host/matelight/font.c +++ b/host/matelight/font.c @@ -14,10 +14,11 @@ void render_glyph(glyph_t *g, uint8_t *buf, unsigned int bufwidth, unsigned int data <<= 8; data |= bitmap[y*bitmap_row_width+i]; } - uint8_t *p = buf + (offy+y)*bufwidth + offx; + uint8_t *p = buf + ((offy+y)*bufwidth + offx)*3; for(unsigned int x=0; x < g->width; x++){ color_t c = (data&(1<<(g->width-1))) ? fg : bg; - *((color_t *)(p++)) = c; + *((color_t *)p) = c; + p += 3; data <<= 1; } } diff --git a/host/matelight/main.c b/host/matelight/main.c index 48c50d9..7633507 100644 --- a/host/matelight/main.c +++ b/host/matelight/main.c @@ -27,6 +27,17 @@ int console_render(char *s, glyph_t **glyph_table, unsigned int glyph_table_size goto error; } for(;;){ + if(*p == '\033'){ + p++; + // Jump over escape sequences + for(;;p++){ + if(!(*p == ';' || *p == '[' || ('0' < *p && *p < '9'))){ + p++; + break; + } + } + } + size_t inc = mbrtowc(&c, p, MB_CUR_MAX, &ps); // MB_CUR_MAX is safe since p is \0-terminated if(inc == -1 || inc == -2){ fprintf(stderr, "Error rendering string: No valid UTF-8 input.\n"); @@ -70,19 +81,19 @@ int console_render(char *s, glyph_t **glyph_table, unsigned int glyph_table_size struct { color_t fg; color_t bg; - int blink:4; - int bold:1; // TODO - int underline:1; - int strikethrough:1; - int fraktur:1; // TODO See: Flat10 Fraktur font - int invert:1; + unsigned int blink:4; + unsigned int bold:1; // TODO + unsigned int underline:1; + unsigned int strikethrough:1; + unsigned int fraktur:1; // TODO See: Flat10 Fraktur font + unsigned int invert:1; } style = { colortable[DEFAULT_FG_COLOR], colortable[DEFAULT_BG_COLOR], 0, 0, 0, 0, 0, 0 }; for(;;){ // NOTE: This nested escape sequence parsing does not contain any unicode-awareness whatsoever if(*p == '\033'){ // Escape sequence YAY - char *sequence_start = p++; + char *sequence_start = ++p; if(*p == '['){ // This was a CSI! long elems[MAX_CSI_ELEMENTS]; int nelems; @@ -91,22 +102,26 @@ int console_render(char *s, glyph_t **glyph_table, unsigned int glyph_table_size char *endptr; elems[nelems] = strtol(p, &endptr, 10); if(p == endptr){ - fprintf(stderr, "Invalid ANSI escape code: \"\\e%s\"\n", sequence_start); + fprintf(stderr, "Invalid escape sequence: \"\\e%s\"\n", sequence_start); goto error; } + p = endptr; if(*endptr == 'm') break; if(*endptr != ';'){ - fprintf(stderr, "Invalid ANSI escape code: \"\\e%s\"\n", sequence_start); + fprintf(stderr, "Invalid escape sequence: \"\\e%s\"\n", sequence_start); goto error; } } + p++; // gobble up trailing 'm' of "\033[23;42m" + nelems++; // By now we know it's a SGR since we error'ed out on anything else if(nelems < 1){ fprintf(stderr, "Unsupported escape sequence: \"\\e%s\"\n", sequence_start); goto error; } for(int i=0; iy usually is a negative index of the glyph's baseline measured from the glyph's bottom int uly = gbufheight + g->y; + printf("Generating strikethrough at y=%d, underline at y=%d\n", sty, uly); for(int i=0; iwidth; i++){ if(style.strikethrough) - *((color_t *)(gbuf + (sty*gbufwidth + i)*3)) = fg; + *((color_t *)(gbuf + (sty*gbufwidth + x + i)*3)) = fg; if(style.underline) - *((color_t *)(gbuf + (uly*gbufwidth + i)*3)) = fg; + *((color_t *)(gbuf + (uly*gbufwidth + x + i)*3)) = fg; } } x += g->width; } + printf("Rendering buffer of size %d*%d\n", gbufwidth, gbufheight); for(unsigned int y=0; y < gbufheight; y++){ for(unsigned int x=0; x < gbufwidth; x++){ color_t c = *((color_t *)(gbuf + (y*gbufwidth + x)*3)); -- cgit