FontGen
   Multilingual
   Grayscale
   Graphics support
   Rotation
   Cross Platform
   Compression
   Release notes
   Get it
  
Keil LCD extension
Display library
FAQ

 

Glyphs have an area which their black pixels are in, while they may have completely empty columns/rows.

		0x00, 	/*  [        ]  */
		0x00, 	/*  [        ]  */
		0x00, 	/*  [        ]  */
		0x38, 	/*  [  ***   ]  */
		0x04, 	/*  [     *  ]  */
		0x04, 	/*  [     *  ]  */
		0x3C, 	/*  [  ****  ]  */
		0x44, 	/*  [ *   *  ]  */
		0x44, 	/*  [ *   *  ]  */
		0x3E, 	/*  [  ***** ]  */
		0x00, 	/*  [        ]  */
		0x00, 	/*  [        ]  */
		0x00, 	/*  [        ]  */

Consider the glyph above for character 'a'. This glyph have 1 empty column at both left and right of it, and have 3 empty rows at the top and bottom of it. That's why, it comsumes 13 rows * 8 columns, while all of its black pixels are in a rectangle of 7*6 size.

FontGen can remove these empty rows and columns to reduce the size of the font definition produced. When it does so, it tracks the width and height of the black area of each glyph. Black area is the area where glyph's black pixels are in. Besides this information, it also tracks the offset of the top-left point of the black area of the glyph.

For our example glyph above, the values are as follows:

black width: 6
black height: 7
offset x: 1
offset y: 3

With this information, the display procedure can paint the glyph with the following compact glyph data:

		0x70, 	/*  [ ***  ]  */
		0x08, 	/*  [    * ]  */
		0x08, 	/*  [    * ]  */
		0x78, 	/*  [ **** ]  */
		0x88, 	/*  [*   * ]  */
		0x88, 	/*  [*   * ]  */
		0x7C, 	/*  [ *****]  */

All above is about the compression, but below is about more than compression.

Negative offsets

At the first look, we can assume that offset x is always a positive value, but this is not true for all glyphs.

		0x00, 0xC0, 	/*  [        **]  */
		0x01, 0x40, 	/*  [       * *]  */
		0x01, 0x00, 	/*  [       *  ]  */
		0x02, 0x00, 	/*  [      *   ]  */
		0x0F, 0x00, 	/*  [    ****  ]  */
		0x02, 0x00, 	/*  [      *   ]  */
		0x04, 0x00, 	/*  [     *    ]  */
		0x04, 0x00, 	/*  [     *    ]  */
		0x04, 0x00, 	/*  [     *    ]  */
		0x08, 0x00, 	/*  [    *     ]  */
		0x08, 0x00, 	/*  [    *     ]  */
		0x08, 0x00, 	/*  [    *     ]  */
		0x90, 0x00, 	/*  [*  *      ]  */
		0xE0, 0x00, 	/*  [***       ]  */

Consider the glyph for 'f' character for Times New Roman Italic font. While its width is only 5 pixels, the width of its black area is 10 pixels. Its offset x value is -3, which means that the tails of 'f' will be printed just below of the previously printed glyph on the LCD. With these values, we find that the head part of 'f' will be printed to the area of the glyph which will be printed after 'f'.

 

Above is the zoomed view of the LCD to show how 'f' is printed with the other glyphs. You can see how the tail and head of 'f' exceed the boundaries.

The overhang is the part of the ink of a glyph that extends beyond the advance width of the glyph. Most glyphs (such as "H") have no overhang, as there is a little white space on either side to separate them from adjacent glyphs. An example of a glyph with overhang is 'f' in our example. Both the top and bottom of the italic 'f' overhang the adjacent glyphs.

The underhang is a width of white space to the left or right of the solid portion of a glyph. Underhang is sometimes known as "padding".

While negative x offset value lets part of the glyph can be painted in the area of the previously printed glyph, it even can let you to paint all the glyph in the area of the previously printed glyph. This may sound weird but , it is required for some alphabets like arabic and indian.

		/* char: 's' hexcode: 0x0073 glyph_width: 13 black_width: 16 origin_x: -1 */
		0xFF, 0xFE, 	/*  [*************** ]  */
		0xFF, 0xFE, 	/*  [*************** ]  */
		0x0C, 0x30, 	/*  [    **    **    ]  */
		0x06, 0x30, 	/*  [     **   **    ]  */
		0x06, 0x30, 	/*  [     **   **    ]  */
		0x0E, 0x30, 	/*  [    ***   **    ]  */
		0x0C, 0x70, 	/*  [    **   ***    ]  */
		0x7F, 0xF0, 	/*  [ ***********    ]  */
		0x7B, 0xF0, 	/*  [ **** ******    ]  */
		0x30, 0x30, 	/*  [  **      **    ]  */
		0x18, 0x30, 	/*  [   **     **    ]  */
		0x08, 0x30, 	/*  [    *     **    ]  */
		0x0C, 0x30, 	/*  [    **    **    ]  */


		/* char: 't' hexcode: 0x0074 glyph_width: 11 black_width: 14 origin_x: -1 */
		0xFF, 0xF8, 	/*  [************* ]  */
		0xFF, 0xF8, 	/*  [************* ]  */
		0x00, 0xC0, 	/*  [        **    ]  */
		0x00, 0xC0, 	/*  [        **    ]  */
		0x1F, 0xC0, 	/*  [   *******    ]  */
		0x3F, 0xC0, 	/*  [  ********    ]  */
		0x78, 0x00, 	/*  [ ****         ]  */
		0x70, 0x00, 	/*  [ ***          ]  */
		0x60, 0x00, 	/*  [ **           ]  */
		0x60, 0x00, 	/*  [ **           ]  */
		0x60, 0xC0, 	/*  [ **     **    ]  */
		0x3F, 0xC0, 	/*  [  ********    ]  */
		0x1F, 0x80, 	/*  [   ******     ]  */
		
		/* char: 'u' hexcode: 0x0075 glyph_width: 0 black_width: 8 origin_x: -9 */
		0x8E, 	/*  [*   *** ]  */
		0xCF, 	/*  [**  ****]  */
		0x73, 	/*  [ ***  **]  */
		0x3F, 	/*  [  ******]  */
		0x1E, 	/*  [   **** ]  */
		
		/* char: 'w' hexcode: 0x0077 glyph_width: 5 black_width: 8 origin_x: -2 */
		0xFF, 	/*  [********]  */
		0xFF, 	/*  [********]  */
		0x18, 	/*  [   **   ]  */
		0x18, 	/*  [   **   ]  */
		0x18, 	/*  [   **   ]  */
		0x18, 	/*  [   **   ]  */
		0x18, 	/*  [   **   ]  */
		0x18, 	/*  [   **   ]  */
		0x18, 	/*  [   **   ]  */
		0x18, 	/*  [   **   ]  */
		0x18, 	/*  [   **   ]  */
		0x18, 	/*  [   **   ]  */
		0x18, 	/*  [   **   ]  */

Below is the output on the LCD when "stuw" is printed, with the font definition (for Gurbani Hindi) given above:

 

Here you see that glyph for character 'u' is printed completely in the area reserved for glyph for character 't'.

Advance width

Each glyph has an advance value, which holds the information of how many pixels we should advance the x value of the cursor after painting the glyph. It is evident that advance value is the width of the glyph for our example for character 'a' above. FontGen holds the width information in the glyph width or width table fields of the font definition record.

Looking at the 'f' glyph above, we can tell either 5 or 10 is the width. However it is clear that the advance width is 5. FontGen stores the advance width of the glyphs in the glyph width or width table fields of the font definition structure.

So in short, you should increment the x value of your cursor on the LCD, by the value of the glyph_width or width_table[glyph] value.

Please note that advance width can even be zero for some glyphs. Consider the Gurbani Hindi font definition given above. The advance width for character 'u' is given as zero.

 

Please note that all the features detailed in this page, works only for TrueType fonts. For non TrueType fonts, negative x-offset is not supported and advance width is set as the width of the glyph always.

 

Copyright 2006-2015 - dreamsware - info@dreamsware.info