Page 1 of 2
Bitmaps?
Posted: Mon Jan 28, 2008 3:05 pm
by 01000101
I recently toyed around with 640x480 256-bit color vga mode, and PLEASE tell me there is a better way to create fonts and such besides bitmaps. actually drawing letters in a *x* matrix array is horrible. also, the size of the code goes skyrocketing, I had only finished maybe half the alphabet in 7x7 matrixes and my kernel had overall multiplied in size by 3.
I have no intention on implementing a GUI or using the higher-res vga in my OS, but I still like messing around with things and seeing how things are properly done.
Posted: Mon Jan 28, 2008 3:34 pm
by Alboin
Have you thought about using an SVG type font system? (Describe how the graphic is made vs. the finished graphic.)
Posted: Mon Jan 28, 2008 3:37 pm
by Combuster
You could simply hack the font out of the VGA card when it's still in text mode. Otherwise, a bitwise font wouldn't add that much to your kernel at all:
7x7 = 49 bits, lets round it to 56 bits (7x8 matrix) now you need only 256*7 = 1.7k to store the entire font uncompressed. That's hardly what you call large. If you want, you can reduce the set to 128 characters (~1K) and even compress it (~500 bytes). Space isn't an argument, if done properly.
Or in C:
Code: Select all
const unsigned char font[] = {
....
/* A */ 0x7C, 0xC6, 0x82, 0xFE, 0x82, 0x82, 0x00,
/* B */ 0xFC, 0x86, 0x82, 0xFC, 0x82, 0xFC, 0x00,
....
};
void putchar(unsigned char c, int x, int y)
{
int lx; int ly;
for (lx = 0; lx < 7; lx++)
for (ly = 0; ly < 7; ly++)
putpixel (x+lx,y+ly, ((font[7*c + ly] << lx) & 0x80) ? WHITE : BLACK );
}
which is basically an application of binary math
Posted: Mon Jan 28, 2008 6:35 pm
by Jef
Combuster wrote:You could simply hack the font out of the VGA card when it's still in text mode. Otherwise, a bitwise font wouldn't add that much to your kernel at all:
7x7 = 49 bits, lets round it to 56 bits (7x8 matrix) now you need only 256*7 = 1.7k to store the entire font uncompressed. That's hardly what you call large. If you want, you can reduce the set to 128 characters (~1K) and even compress it (~500 bytes). Space isn't an argument, if done properly.
Or in C:
Code: Select all
const unsigned char font[] = {
....
/* A */ 0x7C, 0xC6, 0x82, 0xFE, 0x82, 0x82, 0x00,
/* B */ 0xFC, 0x86, 0x82, 0xFC, 0x82, 0xFC, 0x00,
....
};
void putchar(unsigned char c, int x, int y)
{
int lx; int ly;
for (lx = 0; lx < 7; lx++)
for (ly = 0; ly < 7; ly++)
putpixel (x+lx,y+ly, ((font[7*c + ly] << lx) & 0x80) ? WHITE : BLACK );
}
which is basically an application of binary math
seems good.
I don't know in asm how many lines will be ....
anyway,
an other way, that i used at the start of creation the GUI was to put all characters in a text editor (using oem dos like format) and i capture the screen.
The result was a bmp file ( 2048 X 13 pixels) that represents 255 characters 8 x 13. I convert it to asm data and then the maths was too easy.
maybe sounds stupid, but it was a good start (especially if you want to display Greek characters) and the code that displays a character its small and fast.
I really don't care for the size taken in memory as I care for the fast display.
Posted: Tue Jan 29, 2008 1:09 am
by bewing
Bitmaps are stupid. They are not nicely scalable. They take too much space, if you make them look nice. They are a pain to code. If you *really* insist on using bitmaps, then Jef's method sounds good.
But outline fonts were invented because they are better than bitmap fonts. The patent is expired, which means that the entire concept of "outline fonts" is public domain now. (And, in fact, the entire POINT of the patent system is to encourage the wide public adoption of great ideas after the patent is expired.) Draw your fonts using vectors of specific widths, and I'm intending to use splines to fit the curvy parts. Your fonts will look perfect at any scale, and if you code them nicely, they will take up far less space than a "nice" bitmap.
Adobe has also made a number of their fonts available as freeware. (TrueType itself is still copyrighted, with patent protection.)
Posted: Tue Jan 29, 2008 2:25 pm
by Alboin
bewing wrote:(TrueType itself is still copyrighted, with patent protection.)
IIRC, don't the patents only apply to certain guessing algorithms which aren't needed to read and use TTF fonts?
Posted: Tue Jan 29, 2008 3:38 pm
by bewing
Well, yes, sort-of. There are two types of patents. I was mostly referring to the second kind. You can't "disassemble" a TrueType font, and rename it a bewingFont, and sell it. The precise font itself is patented. Of the remaining patents of the first type, you are correct -- you don't need to use any of them to display an outline or TrueType font. The patents are just for making the fonts a tiny bit prettier at this point.
Posted: Tue Jan 29, 2008 6:31 pm
by ucosty
bewing: You can't patent a font. You CAN copyright it, though.
Posted: Tue Jan 29, 2008 7:01 pm
by Alboin
ucosty wrote:bewing: You can't patent a font. You CAN copyright it, though.
Quite the opposite. Under US copyright law (Is that part of the Berne Convention?) typefaces cannot be copyrighted, but distinguished typefaces may be patented. The only copyrighted part of the font is the actual implementation, so anyone can create their own clone implementation, as long as there are no patents.
See
here.
Posted: Tue Jan 29, 2008 7:13 pm
by ucosty
That's just weird.
edit: Wait a minute I'm not entirely wrong here. We both mentioned fonts which are the implemenation and not the original typeface design.
Posted: Tue Feb 05, 2008 8:59 am
by jal
bewing wrote:But outline fonts were invented because they are better than bitmap fonts. (...) Draw your fonts using vectors of specific widths, and I'm intending to use splines to fit the curvy parts. Your fonts will look perfect at any scale, and if you code them nicely, they will take up far less space than a "nice" bitmap.
Of course this is utter nonsence, as the whole reason for having these bytecode stuff in the TTF files is because outline fonts
do not look nice on small (i.e. normal) resolutions. The whole hinting, whether through bytecode (Windows/OSX) or autohinting (default Linux) is a big pain. For smaller resolutions, bitmaps are far better to start with. Then, implement TTF rendering using FreeType (current version 2.3.5).
JAL
Posted: Wed Feb 06, 2008 3:04 am
by bewing
"Hinting" is bogus, yes. With some intelligence you can implement an outline font without it, and it looks just like a bitmap font at low res.
Posted: Wed Feb 06, 2008 4:32 am
by jal
bewing wrote:"Hinting" is bogus, yes. With some intelligence you can implement an outline font without it, and it looks just like a bitmap font at low res.
Sure. It seems you know what you're talking about. *cough*
JAL
Posted: Wed Feb 06, 2008 4:51 am
by zaleschiemilgabriel
Actually, if you have the time, patience and resources to implement it, you could use OpenType/TrueType/PostScript fonts:
OpenType specification
IIRC all you need to draw OpenType glyph outlines are Bezier curves and straight lines. If you also want to draw filled glyphs, you need a scan-line fill algorithm based on Bezier curves and lines.
It's what I plan on using when I get there...
Re: Bitmaps?
Posted: Wed Feb 06, 2008 5:08 am
by Brendan
Hi,
01000101 wrote:I recently toyed around with 640x480 256-bit color vga mode, and PLEASE tell me there is a better way to create fonts and such besides bitmaps.
You could draw them by hand (and use a scanner)!
From a more practical perspective it might be worth pointing out that for font data (IMHO) your video code should blit bitmaps in a special format (no colour data except alpha) and *nothing* else. Later on you'd add a (seperate) font engine to this that converts strings of text into bitmap data, and implement it in a way that the bitmap data from the font engine can be cached by your video code to avoid rebuilding the font data each time it's used.
Cheers,
Brendan