ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5


3 - A Group of Fonts

Fonts can also be arranged in groups, in a structure called (surprisingly enough) FONTGROUP. This structure is worth looking at in more detail:

struct FONTGROUP
{
U16 size, style;
S32 font;
};

A font package contains an array of these FONTGROUP structures, each indicating a specific font. The fields above are quite straightforward: size is the pixel height of the font, while style is a description, and can be any of the following: CTRL_NORMAL, CTRL_BOLD, CTRL_ITALIC, CTRL_SUPERSCRIPT, CTRL_SUBSCRIPT, CTRL_BOLDITALIC, and CTRL_SMALL. These values can be used to help in font searching (for example to ignore superscript and subscript fonts).

The font value may at first appear to be a miscast pointer, but is actually an offset value from the start of the FONTGROUP structure being referred to. Using it, we can arrive at the FONT pointer to the specific font, after a rather nasty cast (the value is in bytes, so we need to cast to char first). Here, fontGroupPointer points to our first FONTGROUP structure, and fontIndex to the entry within it:

FONT *font=(FONT*)(((char)(fontGroupPointer))+fontGroupPointer[fontIndex].font);

The good news is that the Default font provided with all programs already contains this font group - we simply need to dig into it to use the extra fonts in our programs. I think the best way to show this in action is to include actual code, so I've written a font pick dialog, suitable for anyone working with fonts. The source code (eg_7.zip) includes this dialog source and a simple test program, with accompanying SEB of course.

When called, the pick dialog simply returns a FONT pointer to the chosen font, or 0 if none picked. In addition, the font dialog shows each font in its 'natural' state, making selection more intuitive.



Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice