| Header file: | font.h |
| Object name: | fFONT |
| Object index: | 1 of 3 Objects (Others: fFONTNAMER and fFONTCHOOSER) |
The fFONT object is a general purpose font class really only for creating a font. This font can then be applied to components or used for graphics.
| Name | Description |
| HFONT Handle; |
This is the handle of the font object. You can use this directly if you need to - but if you write to it, be sure to delete the current contents first with DeleteObject(Font.Handle);
|
| LOGFONT FontAttribs; | This is the LOGFONT structure which comprises of the seperate things that make up a font. This LOGFONT structure is eventually used to make the font, and is provided here so that you can use it for some more obscure things. |
| Prototype | Description |
| void Internal_CompileFont(void); | This function internally takes the LOGFONT structure and makes it into a proper font and resets the HFONT Handle. Don't understand? Don't worry, this function is called for you automatically most of the time. |
| void SetFont(HWND Handle); |
This function applies the current font to the window specified by Handle. Generally for most GUI components you would use Component.SetFont(&Font);
|
|
void Size(int Size); int Size(void); | These functions set/get the size of the font. Exactly what units these are depends on what you do with the font... but use the benchmark size of '8' as being the default size font in Windows. |
|
void Slant(int Slant); int Slant(void); | These functions set/get the slant of the font. The slant is in tenths of degrees. What exactly does this do? I'm not sure, see if you can work it out for yourself: (extract taken from the Win32 SDK Reference manual) "Specifies the angle, in tenths of degrees, between the escapement vector and the x-axis of the device. The escapement vector is parallel to the base line of a row of text." If you can understand and find a use for that, good on you! |
|
void Angle(int Angle); int Angle(void); | This function sets/gets the same thing as the above function. Have a look at that to see what it's for. |
|
void Weight(int Weight); int Weight(void); |
These functions set/get the weight of the font. This specifies how 'bold' the font is - so equate this for bold. You can specify a number between 0 and 1000 for boldness - 0 means that you don't care (the default will be used), 400 is a normal font, and 700 is bold. Windows also knows the following values to make things a tad easier: (taken from the Win32 SDK Reference Manual)
|
|
void Italic(bool Set); bool Italic(void); | These functions set/get whether the font is Italic or not. Pass TRUE to make it italic, or FALSE to make it not-italic. |
|
void Strikeout(bool Set); bool Strikeout(void); | These functions set/get whether or not the font has a strikethrough style set. Pass TRUE to make it have a strikethrough, or FALSE to prevent this. |
|
void FontName(char* Name); char* FontName(void); | These functions set/get the name of the font to use. It can be any font that is part of the system. If you make this empty, or you specify a font that does not exist, Windows will substitute a font with similar properties to those already specified. Please don't rely on this automatic selection too much! |
| void ReverseCurrentFont(void); | This function takes the font that is currently in the class and decompiles it down to a LOGFONT structure, which can then be used to change the properties of the font. It may not always be nessecary to do this, as this is automatically called before you retrieve a property anyway. However, if you set the font handle, you might like to do this to get the properties. |
| void ReverseEngineerFont(HFONT Font); | This function is useful if you have a handle to a font and you want to find out what it's properties are - or even change a few. Just call this function with the font, and it's properties will be taken out and placed into the LOGFONT structure. Please note that the font handle will not be recorded. See the example source code at the end for an example of how to use this. |
The following snippet gives a basic idea of how to use this component.
//First create the font object.
//What is the default font?
//Default settings:
//Height = 14
//Boldness (weight) = 0 (default for font)
//Italic = FALSE
//Underline = FALSE
//Strikethrough = FALSE
//Font Name = "MS Sans Serif"
fFONT Font;
Font.FontName("Courier New"); //Nice mono-spaced font.
Font.Size(10); //Smaller font.
//The font is automatically rebuilt to a HFONT whenever
//you change something.
fBUTTON Button;
Button.SetFont(&Font); //Apply the font.
//Now, some tricky stuff: get the properties from
//another font. Let's say the default GUI font.
DeleteObject(Font.Handle); //No memory leaks!
//You must record the handle if you want more than just the properties.
Font.Handle = (HFONT)GetStockObject(DEFUALT_GUI_FONT);
Font.ReverseEngineerFont((HFONT)GetStockObject(DEFAULT_GUI_FONT));
//Now the font can be changed slightly, without needing to
//set all properties.
//Say now, with the default font already set, we want to make
//it Italic...
Font.Italic(TRUE);
//Now we can do things with it...
| Back to index | The FreeFoote Foundation Classes Documentation |