e2d::graphics::Font Class Reference

List of all members.

Detailed Description

Bitmap fonts are composed of two parts: the first is an image file containing all of its characters sorted by ASCII value, and the second is a binary file containing information on the width in pixels of each character. We recommend using F2IBuilder (http://f2ibuilder.sourceforge.net) to create these files from fonts installed on your computer.

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" />

Internally, this class uses an instance of Tileset to keep the font data (character image and size). When you load a font, a tileset is automatically created. If you load it from a XML file, the tileset will be added to (or recovered from) the ResourceMap.
In the tag <font>, name is the name that will be used to store this font's tileset in the ResourceMap. Attributes horizontal_spacing and vertical_spacing are, respectively, the horizontal and vertical character spacing used when blitting this font. In the tag <image>, source is the path (relative to the executable file of your game) to the image file containing the characters for this font; trans (optional) is a RGB hexadecimal value for a color that will be considered transparent (not blitted); width and height are the width and height of the image. In the tag <dat>, source is the path (always relative to the executable) to the binary dat file.

It is important to keep the order of the tags in this file; the <image> tag must come before the <dat> tag.
You may choose to load the image and the dat file by hand, using LoadImage() and then LoadDat() methods, in this order. If you do so, you must add the generated tileset to the ResourceMap yourself if you want to share it with other objects.

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.
TilesetGetTileset (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.

Constructor & Destructor Documentation

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.

Member Function Documentation

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   ) 

The horizontal character spacing set to this font.
e2d::core::Exception if blitting fails.

Tileset * e2d::graphics::Font::GetTileset ( void   ) 

This font's tileset.

int e2d::graphics::Font::GetVerticalSpacing ( void   ) 

The vertical character spacing set to this font.

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.

Generated on Tue Dec 8 10:32:45 2009 for Easy2D by  doxygen 1.5.6