Bitmaps?
Bitmaps?
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.
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.
Website: https://joscor.com
- Combuster
- 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:
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:
which is basically an application of binary math
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 );
}
seems good.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:which is basically an application of binary mathCode: 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 ); }
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.
Keep coding...
...the sky is the limit
AsteriOS project: http://www.mindfields.gr/main/index.php ... &Itemid=27
...the sky is the limit
AsteriOS project: http://www.mindfields.gr/main/index.php ... &Itemid=27
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.)
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.)
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.
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.ucosty wrote:bewing: You can't patent a font. You CAN copyright it, though.
See here.
C8H10N4O2 | #446691 | Trust the nodes.
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.
edit: Wait a minute I'm not entirely wrong here. We both mentioned fonts which are the implemenation and not the original typeface design.
The cake is a lie | rackbits.com
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).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.
JAL
- zaleschiemilgabriel
- Member
- Posts: 232
- Joined: Mon Feb 04, 2008 3:58 am
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...
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?
Hi,
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
You could draw them by hand (and use a scanner)!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.
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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.