Font encoding?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
tera4d
Member
Member
Posts: 37
Joined: Sun Apr 26, 2009 11:22 am

Font encoding?

Post 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
User avatar
Tobba
Posts: 21
Joined: Fri Mar 18, 2011 3:24 pm

Re: Font encoding?

Post 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
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: Font encoding?

Post 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...
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Font encoding?

Post 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).
If you have seen bad English in my words, tell me what's wrong, please.
tera4d
Member
Member
Posts: 37
Joined: Sun Apr 26, 2009 11:22 am

Re: Font encoding?

Post 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!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Font encoding?

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Font encoding?

Post by Chandra »

I personally prefer 16x16 fonts. It gives me better usage, especially when the characters are non-Latin.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Post Reply