Search code examples
textfontsoperating-systemosdevuefi

Trouble printing text with a set_pixel function in GOP graphics (UEFI)


Actually I have an .efi application (intended to be a very early kernel) that set-up graphics along with other things, I use this graphics to make a "set_pixel" function, and a few days ago I had the need of printing text.
After a few days of research I found that my only solution is to write all of the characters that I need to use with this "set_pixel" function and some other derivations that I made ("draw_line", etc.)
As you can imagine, this is a very tedious and slow task, there is another solution than writing all the characters "by hand"? A method to import a font and use it? Thanks in advance!


Solution

  • Here's my own solution.

    I have created a simple font (incomplete for now ...) in the form of an header file. Then I use this function in order to draw a character into the GOP buffer:

    void drawChar(uint32_t *buffer, uint32_t x, uint32_t y, uint32_t color, wchar_t charcode) {
        extern wchar_t font_system_8x16[KAOS_FONTS_SIZE];
        wchar_t p = charcode * 128 - 128; // Size of a font's character
        for (int l = 0; l < 16; l++) {
            for (int c = 0; c < 8; c++) {
                if (font_system_8x16[p] == 1) {
                    drawPoint(buffer, x + c, y + l, color);
                }
    
                p++;
            }
        }
    }
    

    https://bitbucket.org/cgerardin/kaos/src/0e6c92e02d549969ae8c8c7ee58af32e78ad1206/src/fonts/system-8x16.h?at=master&fileviewer=file-view-default

    Feel free to get inspired.

    EDIT: For a faster way to generate header file, look at this C header file with bitmapped fonts