ClanSoft logo
ClanSoft logo
Entire Class Index Main Class Index Cross Index Global Index

Class CL_Font

ClanLib's font class.
Contained in: global
Derived from: none
Derived by: none
Group: Display (Fonts)

#include <ClanLib/display.h>


public function member index:

Static_init:

static CL_Font* create(CL_Font_Description* font_desc);
static CL_Font* load(const std::string& resource_id, CL_ResourceManager* resource_manager);

Construction:

CL_Font(CL_Font_Description* provider);
CL_Font(const std::string& resource_id, CL_ResourceManager* manager);
CL_Font(const CL_Font& font);
virtual ~CL_Font();

Operations:

CL_Font& operator =(const CL_Font& copy);
int get_height();
int get_text_width(const std::string& text);
int get_char_width(const char character);
void print_left(int x, int y, const std::string& text, int n_height=1);
void print_left(int x, int y, float scale_x, float scale_y, const std::string& text);
void print_center(int x, int y, const std::string& text, int n_height=1);
void print_right(int x, int y, const std::string& text, int n_height=1);
void put_target(int x, int y, const std::string& text, CL_Target* target, int alignment = ALIGN_LEFT);
int change_size(int size);
unsigned int change_colour(unsigned char r, unsigned char g, unsigned char b, unsigned char a);

Implementation:

CL_Font(class CL_Font_Generic* impl);
 

Description:

This class allows you to easilly draw text onto the backbuffer or to a renderer target.

The font can be created in two ways. Either it is loaded from a resource, or it is created using the font description interface. The font and its description have the same relationship/functionality as the CL_Surface surface and its CL_SurfaceProvider provider.

Please read the CL_Font_Description page if you want an description on how to create your own font.


Function Member Descriptions:

CL_Font::CL_Font - Creates a font from a font provider/description
CL_Font(CL_Font_Description* provider);


CL_Font::CL_Font - Loads a font from a resource file.
CL_Font(const std::string& resource_id, CL_ResourceManager* manager);


CL_Font::CL_Font - Make a copy of an other font, but share the image data.
CL_Font(const CL_Font& font);


CL_Font::CL_Font - Font constructor
CL_Font(class CL_Font_Generic* impl);


CL_Font::change_colour - Changes the colour of the font used.
unsigned int change_colour(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
r - The red component
g - The green component
b - The blue component
a - The alpha component
Returns - Returns the font set in packed ARGB format.



CL_Font::change_size - Changes the size of the font used.
This function only does something meaninful if you use TrueType fonts
int change_size(int size);
size - The new size to use.
Returns - Returns the size set or -1 if the font size cannot be changed to size



CL_Font::create - Creates the font from a font description.
static CL_Font* create(CL_Font_Description* font_desc);
font_desc - The font description used to construct the font.



CL_Font::get_char_width - Return the width of character if drawn with this font.
int get_char_width(const char character);
text - Character the width should be calculated from.
Returns - Width of the character (in pixels).



CL_Font::get_height - Returns the height of the font.
int get_height();
Returns - Width of the font.



CL_Font::get_text_width - Return the width of 'text' if drawn with this font.
int get_text_width(const std::string& text);
text - Text string the width should be calculated from.
Returns - Width of the text (in pixels).



CL_Font::load - Loads the font from resources.
static CL_Font* load(const std::string& resource_id, CL_ResourceManager* resource_manager);
resource_id - The resource ID of the font.
resource_manager - The resource manager used to load the
resources from.



CL_Font::operator = - Copy assignment operator.
CL_Font& operator =(const CL_Font& copy);


CL_Font::print_center - Prints 'text' center aligned at coordinates ('x','y').
void print_center(int x, int y, const std::string& text, int n_height=1);
x - X coordinate (in pixels) the text is centered at.
y - Y coordiante (in pixels) the text is centered at.
text - The text to be drawn with this font.
n_height - Adds font height + n_height pixels to Y coordinate on new line ('\n').



CL_Font::print_left - Prints 'text' left aligned at coordinates ('x','y').
void print_left(int x, int y, const std::string& text, int n_height=1);
x - X coordinate (in pixels) the text is drawn at.
y - Y coordiante (in pixels) the text is drawn at.
text - The text to be drawn with this font.
n_height - Adds font height + n_height pixels to Y coordinate on new line ('\n').



CL_Font::print_left - Prints 'text' left aligned at coordinates ('x','y').
void print_left(int x, int y, float scale_x, float scale_y, const std::string& text);
x - X coordinate (in pixels) the text is drawn at.
y - Y coordiante (in pixels) the text is drawn at.
scale_x - Scale font width scale_x times.
scale_y - Scale font height scale_y times.
text - The text to be drawn with this font.



CL_Font::print_right - Prints 'text' right aligned at coordinates ('x','y').
void print_right(int x, int y, const std::string& text, int n_height=1);
x - X coordinate (in pixels) the text is ends at.
y - Y coordiante (in pixels) the text is drawn at.
text - The text to be drawn with this font.
n_height - Adds font height + n_height pixels to Y coordinate on new line ('\n').



CL_Font::put_target - Prints 'text' aligned with alignment at coordinates ('x','y') to the target surface.
If CL_Font::ALIGN_LEFT is specified the text is draw starting from x, y.
If CL_Font::ALIGN_CENTER is specified the text is centered at x, y.
If CL_Font::ALIGN_RIGHT is specified the text ends at x, y;
void put_target(int x, int y, const std::string& text, CL_Target* target, int alignment = ALIGN_LEFT);
x - X coordinate (in pixels)
y - Y coordiante (in pixels)
text - The text to be drawn with this font.
target - the target surface to blit to.
alignment - the alignment of the text, CL_Font::ALIGN_LEFT, CL_Font::ALIGN_CENTER, CL_Font::ALIGN_RIGHT



CL_Font::~CL_Font - Font Destructor
virtual ~CL_Font();



Variable Member Descriptions:

CL_Font::impl - The font generic implementation
CL_Font_Generic * impl;

CL_Font::resource - Font resource, if any.
CL_Resource resource;