Page 1 of 1

Font encoding?

Posted: Fri Jun 24, 2011 1:05 pm
by tera4d
Hello,

I am trying to work with a vesa mode of 640x480x8 and it is going well.
However I have one question: How are fonts and letters encoded?
I saw a piece of code from Dex which contains this:

Code: Select all

LetterX  DW         4400h,4400h,2800h,1000h,2800h,4400h,4400h
LetterY  DW         4400h,4400h,2800h,1000h,1000h,1000h,1000h
LetterZ  DW         7c00h,0400h,0800h,1000h,2000h,4000h,7c00h
CopyrightSymbol DW  1e00h,2100h,4c80h,4880h,4c80h,2100h,1e00h
Can someone please explain me on how these letters are encoded?
Thank you very much

Re: Font encoding?

Posted: Fri Jun 24, 2011 1:20 pm
by Tobba
Its most likely encoded in binary, one bit representing one pixel, more or less

This article on the wiki contains a section about font encoding:
http://wiki.osdev.org/Drawing_In_Protected_Mode

Re: Font encoding?

Posted: Fri Jun 24, 2011 1:23 pm
by mariuszp
Is it a graphics mode? If it is, letters are not encoded at all - everything is in pixels, and you must do the font rendering yourself. If you want to load a font from a file, you must either make your own format or learn about current ones. I personally haven't tried it, but I know (from the wiki), there is a thing called FreeType which can do the rendering for you, if you have a functional C library...

Re: Font encoding?

Posted: Fri Jun 24, 2011 1:38 pm
by egos
As I can see they are codes of 16-bit (probably 16-pixel) wide characters with left pixel code in most-significant bit(s).

Re: Font encoding?

Posted: Fri Jun 24, 2011 1:46 pm
by tera4d
This piece of code is in 16 bit real mode, But that does not matter I suppose
The resolution is 640x480x8bpp so I only need to convert my font letter to pixel positions? 0 off and 1 on right?
I think I understand what I need to do now haha.

Thank you for your quick replies!

Re: Font encoding?

Posted: Fri Jun 24, 2011 5:40 pm
by Combuster
Dex is known to provide code without explaining at all how it works. So essentially what I think it's meant to do is merely a guess.

I think it is meant to be some sort of variable-width font. Characters are 7 pixels tall and 1-16 pixels wide. For each of the three letters, only the first 6 bits (starting from bit 15 up to bit 10) are set, while the copyright symbol uses 8 bits yet never bit 15. The most significant bit appears to correspond to the leftmost pixel, the order of words is top to bottom. By testing the bits that are never set you can find out the character width in drawing code.

It is also a custom font (with potential legibility issues) and doesn't match any normal encoding standard. Based on that I'm going to plug My font source, which consists mostly the original IBM font with several additions. It's also 8x8 (and not ??x7) and it follows ascii/unicode ordering, making it trivial to convert strings to font indices (just multiply each byte by 8 and add the offset of the table to get the right font data to match). LSB is leftmost, first byte is topmost, and it also works in text mode.

Re: Font encoding?

Posted: Sat Jun 25, 2011 12:16 am
by Chandra
I personally prefer 16x16 fonts. It gives me better usage, especially when the characters are non-Latin.