Ultra:
very nice! As far as i´ve understood, you are currently using the "lineTo" methods to draw the font, which makes sense for this linear font.
But to have a more universal font-drawing mechanism, i´d recommend to implement a packed bitmap font engine, that can handle characters with front leading ("j" in your example).
What you always have to keep in mind is the uC-limitations, you don´t have endless space, so "packing" data as well as possible is a necessity, or you will run out of memory for your main program...
So instead of using a full byte, if a pixel is lit or not, you could use a bit and extract it via bit operations (and/or/not bitwise operators -> wikipedia has some article on it).
To store a character with left offset, and flexible length you could
* put all characters in a 16x12 pixel bitmap (width x height), which will use only 192/8 = 24 bytes of space for each character.
* have a character "leading" and character "width" control parameter associated with each character, which you can also put into your packed font data structure (=26 bytes per character).
* do not output "blank pixels", so that the left offset of the "j" does not overwrite the right character pixels of the "a" in your demo.
Quick pseudo-algorithm to draw "j" with positive left-side leading
(Sorry don´t have more time to write the inner loop pixel checking and setting)
unsigned char x = 100; // Current x "cursor" coordinate
unsigned char y = 16; // Current y "cursor" coordinate
// Grab output buffer, that has enough room to store the to-be-rendered screen data
...
// Character output loop, example just writing character "j", assuming font with height 12 pixels, j has a left lead of 2 pixels, forces cursor to "go back"
unsigned char leftLead = packedCharacter['j'][24]; // Byte 25 contains the left leading
unsigned char width = packedCharacter['j'][25]; // Byte 26 contains the width
for (unsigned char yChar = y; yChar < y + 12; yChar++)
{
for (unsigned char xChar = x - leftLead; xChar < x - leftLead + width; xChar++)
{
// Code, that checks, if a pixel is lit in character buffer
// Only, if pixel is lit, modify output buffer
}
}
// Write output buffer to screen
...
Edited by Hawkeye, 05 April 2012 - 08:37.






