Index: trunk/i386/boot2/gui.c =================================================================== --- trunk/i386/boot2/gui.c (revision 1715) +++ trunk/i386/boot2/gui.c (revision 1716) @@ -27,6 +27,8 @@ #define vram VIDEO(baseAddr) +#define TAB_PIXELS_WIDTH (font->chars[0]->width * 4) // tab = 4 spaces + int lasttime = 0; // we need this for animating maybe @@ -1312,34 +1314,49 @@ return 1; } +pixmap_t* charToPixmap(unsigned char ch, font_t *font) { + unsigned int cha = (unsigned int)ch - 32; + if (cha >= font->count) + // return ? if the font for the char doesn't exists + cha = '?' - 32; + + return font->chars[cha] ? font->chars[cha] : NULL; +} + +position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) { + pixmap_t* pm = charToPixmap(ch, font); + if (pm && ((p.x + pm->width) < blendInto->width)) + { + blend(pm, blendInto, p); + return pos(p.x + pm->width, p.y); + } + else + return p; +} + void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p) { int i=0; - int y=0; // we need this to support multilines '\n' - int x=0; + position_t current_pos = pos(p.x, p.y); - for(i=0;iheight; + current_pos.x = p.x; + current_pos.y += font->height; continue; } // tab ? - if( ch[i] == '\t' ) - x+=(font->chars[0]->width*5); + if ( ch[i] == '\t' ) + { + current_pos.x += TAB_PIXELS_WIDTH; + continue; + } - if(font->chars[cha] && ((x + font->chars[cha]->width) < blendInto->width)) - blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y)); - - x += font->chars[cha]->width; + current_pos = drawChar(ch[i], font, blendInto, current_pos); } } @@ -1347,32 +1364,31 @@ { int i = 0; int width = 0; + int max_width = 0; // calculate the width in pixels - for(i=0;ichars[text[i]-32]->width; + for (i=0; i < strlen(text); i++) { + if (text[i] == '\n') + width = 0; + else if (text[i] == '\t') + width += TAB_PIXELS_WIDTH; + else + { + pixmap_t* pm = charToPixmap(text[i], font); + if (pm) + width += pm->width; + } + if (width > max_width) + max_width = width; + } - p.x = ( p.x - ( width / 2 ) ); + p.x = ( p.x - ( max_width / 2 ) ); p.y = ( p.y - ( font->height / 2 ) ); if ( p.x == -6 ) - { p.x = 0; - } - for(i=0;ichars[cha]) - { - blend(font->chars[cha], blendInto, p); - p.x += font->chars[cha]->width; - } - } - + drawStr(text, font, blendInto, p); } int initFont(font_t *font, image_t *data) @@ -1383,9 +1399,9 @@ bool monospaced = false; - font->height = data->image->height; + font->height = data->image->height; - for( x = 0; x < data->image->width; x++) + for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) { start = end; @@ -1423,9 +1439,14 @@ } } + for (x = count; x < CHARACTERS_COUNT; x++) + font->chars[x] = NULL; + if(monospaced) font->width = 0; + font->count = count; + return 0; } Index: trunk/i386/boot2/gui.h =================================================================== --- trunk/i386/boot2/gui.h (revision 1715) +++ trunk/i386/boot2/gui.h (revision 1716) @@ -64,6 +64,7 @@ uint16_t height; // Font Height uint16_t width; // Font Width for monospace font only pixmap_t *chars[CHARACTERS_COUNT]; + uint16_t count; // Number of chars in font } font_t; /*