class MASKING_DLL_DECLSPEC Font

Class for handling fonts.

Public Methods

[more] Font()
Default constructor.
[more] Font(FONT* f)
Constructor for making a font with an existing FONT.
[more] Font(ALFONT_FONT* f)
Constructor for making a font with an existing ALFONT_FONT.
[more] Font(const char* f)
Constructor for making a font by loading it from a file.
[more] Font(const Font& f)
Copy constructor
[more]Font& Create()
[more]Font& Create(FONT* f)
[more]Font& Create(ALFONT_FONT* f)
Create a font from either the default font or an existing FONT or ALFONT_FONT.
[more]Font& operator=(FONT* f)
[more]Font& operator=(ALFONT_FONT* f)
[more]Font& operator=(const Font &f)
Assignment operators.
[more]Error Load(const char* f)
Attempts to load a new font from a disk file.
[more]void Destroy()
Destroys the font and sets it to the default Allegro 8x8 font
[more]int SetSize(int h)
Reloads the font with the new size.
[more]void Textout(Bitmap &bmp, const char* s, const Point &p, const Color &c, const Color &bg, int align) const
[more]void TextPrintf(Bitmap &bmp, const Point &p, const Color &c, const Color &bg, int align, const char* format, ...) const
[more]void Textout(Bitmap &bmp, const char* s, int x, int y, int c, int bg, int align) const
[more]void TextPrintf(Bitmap &bmp, int x, int y, int c, int bg, int align, const char* format, ...) const
Wrappers for regular Allegro text output functions.
[more]void GUITextout(Bitmap &bmp, const char* text, const Point &p, const Color &col1, const Color &col2, const Color &bg, int align) const
[more]void GUITextout(Bitmap &bmp, const char* text, int x, int y, int col1, int col2, int bg, int align) const
[more]int GUITextoutEx(Bitmap &bmp, const char* text, const Point &p, const Color &col1, const Color &col2, const Color &bg, int align) const
[more]int GUITextoutEx(Bitmap &bmp, const char* text, int x, int y, int col1, int col2, int bg, int align) const
Special GUI text output.
[more]int GUITextLength(const char* text) const
Returns the length of the text as printed with GUITextoutEx()
[more]void ColumnPrint(Bitmap &bmp, const char* text, int fg, int bg, int textMode, int x, int y, int w, int hal) const
Prints text word-wrapped on a column with a specified width but unspecified height.
[more]void BoxPrint(Bitmap &bmp, const char* text, int fg, int bg, int textMode, int x, int y, int w, int h, int hal, int val) const
Prints text word-wrapped in a box with specified width and height.
[more]int TextHeight() const
Returns the height of the font
[more]int TextLength(const char* str) const
Returns the length of the string in pixels
[more]bool IsFixed() const
Returns true if the font supports several fixed sizes.
[more]bool IsScalable() const
Returns true if the font is fully scalable.
[more]const int* GetAvailableFixedSizes() const
Returns an array of the fixed sizes that the font supports
[more]int GetNOfAvailableFixedSizes() const
Returns the number of fixed sizes the font supports
[more]int GetSpacing() const
[more]void SetSpacing(int s)
Functions for getting and setting the extra spacing between characters.
[more]int GetWrapPos(const char* text, int maxwidth, int &preferredwidth) const
Number of characters that fit on a line.
[more]int GetWrapPos(const char* text, int maxwidth) const
Simple wrapper for when you don't need the preferredwidth parameter
[more]int SkipWhiteSpace(const char* text) const
Returns number of whitespace at the start of text.
[more]int CountLines(const char* text, int maxwidth) const
Counts number of lines needed to print text in an area with width = maxwidth.

Protected Fields

[more]Type type
The type of the currently loaded underlying font
[more]PALETTE pal
The fonts palette.
[more]bool allocated
Did we actually allocate memory or did we just make a pointer?

Protected Members

[more]enum Type
Available font types.


Documentation

Class for handling fonts. Font is a wrapper class for two kinds of fonts (might change in the future): normal Allegro fonts (struct FONT) and AlFont fonts (struct ALFONT_FONT). AlFont is an Allegro addon library which is basically a wrapper for the FreeType project. The Font class provides a unified API for loading and outputting text with many types of fonts including bitmap, BIOS, GRX, truetype, type1 fonts and some other formats. There are also other text output functions specifically meant for GUI purposes.
oenum Type
Available font types. Currently Font has support for two font structures: normal Allegro FONT and AlFont's ALFONT_FONT but only one is loaded at any time. The Type enum has actually the following values:
       ALLEGRO_FONT         - normal Allegro FONT
       FREETYPE_FONT        - AlFont's ALFONT_FONT

oType type
The type of the currently loaded underlying font

oPALETTE pal
The fonts palette. Only aplicable for non-monochrome bitmap fonts. The palette is set automatically on every textprint operation if necessary.

obool allocated
Did we actually allocate memory or did we just make a pointer? This variable is set to true if the object allocated memory for the font itself. If it did then it will be freed when the object is destroyed or a new font is loaded, otherwise the "owner" of the underlying data is responsible for freeing it.

o Font()
Default constructor. Creates a new font and initializes it with the default Allegro 8x8 font or whatever is curently loaded in font.

o Font(FONT* f)
Constructor for making a font with an existing FONT. Doesn't copy the data, only makes a pointer!

o Font(ALFONT_FONT* f)
Constructor for making a font with an existing ALFONT_FONT. Doesn't copy the data, only makes a pointer!

o Font(const char* f)
Constructor for making a font by loading it from a file. See below for a list of supported formats.

o Font(const Font& f)
Copy constructor

oFont& Create()

oFont& Create(FONT* f)

oFont& Create(ALFONT_FONT* f)
Create a font from either the default font or an existing FONT or ALFONT_FONT. If you create a Font from and existing font, the font data doesn't get copied as you might expect but only a pointer is made!

oFont& operator=(FONT* f)

oFont& operator=(ALFONT_FONT* f)

oFont& operator=(const Font &f)
Assignment operators. These create a font from an existing font by making a pointer (not an actual copy!)

oError Load(const char* f)
Attempts to load a new font from a disk file. If unsuccessull it sets itself to the default Allegro 8x8 font. The file can be in one of the following formats:
      - bitmap font (either BMP, PCX, LBM or TGA)
      - BIOS 8x8 or 8x16 font (FNT)
      - GRX font (FNT)
      - scripted font (TXT)
      - Impulse Tracker 8x8 font (ITF)
      - any of the formats supported by AlFont (True Type, Type 1, etc.)

ovoid Destroy()
Destroys the font and sets it to the default Allegro 8x8 font

oint SetSize(int h)
Reloads the font with the new size. This is only valid for scalable fonts such as truetype or type 1. By default these fonts are loaded with the height of 8 pixels.

ovoid Textout(Bitmap &bmp, const char* s, const Point &p, const Color &c, const Color &bg, int align) const

ovoid TextPrintf(Bitmap &bmp, const Point &p, const Color &c, const Color &bg, int align, const char* format, ...) const

ovoid Textout(Bitmap &bmp, const char* s, int x, int y, int c, int bg, int align) const

ovoid TextPrintf(Bitmap &bmp, int x, int y, int c, int bg, int align, const char* format, ...) const
Wrappers for regular Allegro text output functions. They take the same argument list execpt for the font (obviously) and the align parameter. Align may be 0 for left alignment 1 for right alignment and 2 for centered text.

ovoid GUITextout(Bitmap &bmp, const char* text, const Point &p, const Color &col1, const Color &col2, const Color &bg, int align) const

ovoid GUITextout(Bitmap &bmp, const char* text, int x, int y, int col1, int col2, int bg, int align) const

oint GUITextoutEx(Bitmap &bmp, const char* text, const Point &p, const Color &col1, const Color &col2, const Color &bg, int align) const

oint GUITextoutEx(Bitmap &bmp, const char* text, int x, int y, int col1, int col2, int bg, int align) const
Special GUI text output. Same as the normal text output functions except that the second color is used as a text shadow. The functions appended with Ex also interpret the '&' character as an underscore and render the next character with a horizontal line below it and return the length in pixels of actually renderd text.

oint GUITextLength(const char* text) const
Returns the length of the text as printed with GUITextoutEx()

ovoid ColumnPrint(Bitmap &bmp, const char* text, int fg, int bg, int textMode, int x, int y, int w, int hal) const
Prints text word-wrapped on a column with a specified width but unspecified height. note: hal = horizontal alignment. Performs horizontal alignment but not vertical.

ovoid BoxPrint(Bitmap &bmp, const char* text, int fg, int bg, int textMode, int x, int y, int w, int h, int hal, int val) const
Prints text word-wrapped in a box with specified width and height. Performs horizontal and vertical alignment.

oint TextHeight() const
Returns the height of the font

oint TextLength(const char* str) const
Returns the length of the string in pixels

obool IsFixed() const
Returns true if the font supports several fixed sizes. Only a few font formats support this.

obool IsScalable() const
Returns true if the font is fully scalable. Only true-type fonts, type 1 fonts and some others are scalable.

oconst int* GetAvailableFixedSizes() const
Returns an array of the fixed sizes that the font supports

oint GetNOfAvailableFixedSizes() const
Returns the number of fixed sizes the font supports

oint GetSpacing() const

ovoid SetSpacing(int s)
Functions for getting and setting the extra spacing between characters. Only some fonts support this (i.e. the ones that are loaded by AlFont).

oint GetWrapPos(const char* text, int maxwidth, int &preferredwidth) const
Number of characters that fit on a line. Returns number of characters of the string text that fit on this line, while performing word-wrapping. Maxwidth is the width of this line. Preferredwidth is the actual width of that number of characters, so you can calculate the remaining space by substracting preferredwidth from maxwidth and align the text as you wish. Treats \n characters as hard (=forced) line breaks, so even if more characters fit on a line it always stops at a \n.

oint GetWrapPos(const char* text, int maxwidth) const
Simple wrapper for when you don't need the preferredwidth parameter

oint SkipWhiteSpace(const char* text) const
Returns number of whitespace at the start of text. Doesn't count \0 or \n as whitespace.

oint CountLines(const char* text, int maxwidth) const
Counts number of lines needed to print text in an area with width = maxwidth. Empty string is 0 lines. Only whitespace is 1 line. Usefull for calculating the height of a textbox.


This class has no child classes.

Alphabetic index Hierarchy of classes


Back to front page   |   page generated with DOC++