Beyond that, Easy2D needs some more info for loading these fonts, and they may be defined in a XML file. The format for this file must be as follows:
<?xml version="1.0"?> <font name="MyFont" horizontal_spacing="0" vertical_spacing="2" > <image source="myfont.png" trans="000000" width="256" height="256" /> <dat source="myfont.dat" /> </font>
To blit text with this font, you can either use the BlitMessage() method, or use the specialized class Label.
Public Member Functions | |
Font (const Font &original) | |
Copy Constructor. | |
void | BlitMessage (const char *message, Rect *position, SDL_Surface *destination) |
Blits the message to the destination. | |
int | GetHorizontalSpacing (void) |
Returns Horizontal Character Spacing. | |
Tileset * | GetTileset (void) |
Gets this font's tileset. | |
int | GetVerticalSpacing (void) |
Returns Vertical Character Spacing. | |
void | Load (const char *filename) |
Loads a font from a XML file. | |
void | LoadDat (const char *dat_filename) |
Loads the character widths for this font. | |
void | LoadImage (const char *filename, unsigned int image_width, unsigned int image_height) |
Loads a bitmap font. | |
void | Optimize (void) |
Optimizes blitting. | |
void | SetCharSpacing (int horizontal=0, int vertical=0) |
Sets character spacing. |
e2d::graphics::Font::Font | ( | const Font & | original | ) |
No need to load the same font again. Use the copy constructor.
original | Font to copy data from. |
void e2d::graphics::Font::BlitMessage | ( | const char * | message, | |
Rect * | position, | |||
SDL_Surface * | destination | |||
) |
Blits the message to the destination.
message | Text to blit with this font (recognizes '\n' character) | |
position | Position of the destination surface where the message will be blitted. | |
destination | Pointer to an SDL_Surface where the image will be blitted. |
int e2d::graphics::Font::GetHorizontalSpacing | ( | void | ) |
e2d::core::Exception | if blitting fails. |
Tileset * e2d::graphics::Font::GetTileset | ( | void | ) |
int e2d::graphics::Font::GetVerticalSpacing | ( | void | ) |
void e2d::graphics::Font::Load | ( | const char * | filename | ) |
Loads a font from a XML file.
filename | Path to the XML file. |
e2d::core::Exception | if loading fails. |
void e2d::graphics::Font::LoadDat | ( | const char * | dat_filename | ) |
Loads the binary file containing the character widths for this font.
dat_filename | Path to the dat file. |
e2d::core::Exception | if you try to call this method before calling LoadImage(). |
void e2d::graphics::Font::LoadImage | ( | const char * | filename, | |
unsigned int | image_width, | |||
unsigned int | image_height | |||
) |
Loads an image containing the characters for this font.
filename | Path to the image file. | |
image_width | Width of the image, in pixels. | |
image_height | Height of the image, in pixels. |
e2d::core::Exception | if loading fails. |
void e2d::graphics::Font::Optimize | ( | void | ) |
Calls Tileset::Optimize on this font's tileset.
void e2d::graphics::Font::SetCharSpacing | ( | int | horizontal = 0 , |
|
int | vertical = 0 | |||
) |
You may want to have a pixel space between characters when you blit the message. Set it with this method.
horizontal | Horizontal character spacing. | |
vertical | Vertical character spacing. |