Font class. More...

#include <font.h>

Public Member Functions

 Font ()
 Constructs a null font. More...
 
 Font (FontFamily &font_family, float height)
 
 Font (FontFamily &font_family, const FontDescription &desc)
 
 Font (const std::string &typeface_name, float height)
 Constructs standard font. More...
 
 Font (const std::string &typeface_name, const FontDescription &desc)
 
 Font (const FontDescription &desc, const std::string &ttf_filename)
 
 Font (const FontDescription &desc, const std::string &ttf_filename, FileSystem fs)
 
 Font (Canvas &canvas, const std::string &typeface_name, Sprite &sprite, const std::string &glyph_list, float spacelen, bool monospace, const FontMetrics &metrics)
 Constructs a Font based on a sprite. More...
 
size_t clip_from_left (Canvas &canvas, const std::string &text, float width) const
 
size_t clip_from_right (Canvas &canvas, const std::string &text, float width) const
 
void draw_text (Canvas &canvas, const Pointf &position, const std::string &text, const Colorf &color=StandardColorf::white())
 Print text. More...
 
void draw_text (Canvas &canvas, float xpos, float ypos, const std::string &text, const Colorf &color=StandardColorf::white())
 
int get_character_index (Canvas &canvas, const std::string &text, const Pointf &point) const
 Get the character index at a specified point. More...
 
std::vector< Rectfget_character_indices (Canvas &canvas, const std::string &text) const
 Get the rectangles of each glyph in a string of text. More...
 
std::string get_clipped_text (Canvas &canvas, const Sizef &box_size, const std::string &text, const std::string &ellipsis_text="...") const
 Retrieves clipped version of the text that will fit into a box. More...
 
FontDescription get_description () const
 
FontMetrics get_font_metrics (Canvas &canvas) const
 Retrieves font metrics description for the selected font. More...
 
FontHandleget_handle (Canvas &canvas)
 Get the font handle interface. More...
 
GlyphMetrics get_metrics (Canvas &canvas, unsigned int glyph) const
 Gets the glyph metrics. More...
 
bool is_null () const
 Returns true if this object is invalid. More...
 
GlyphMetrics measure_text (Canvas &canvas, const std::string &string) const
 Measure text size. More...
 
 operator bool () const
 
void set_height (float value)
 Sets the font height. More...
 
void set_line_height (float height)
 Sets the distance between each line. More...
 
void set_scalable (float height_threshold=64.0f)
 Sets the threshold to determine if the font can be drawn scaled. More...
 
void set_style (FontStyle setting=FontStyle::normal)
 Sets the font style setting. More...
 
void set_weight (FontWeight value=FontWeight::normal)
 Sets the font weight. More...
 
void throw_if_null () const
 Throw an exception if this object is invalid. More...
 

Static Public Member Functions

static Font load (Canvas &canvas, const std::string &family_name, const FontDescription &reference_desc, FontFamily &font_family, const XMLResourceDocument &doc, std::function< Resource< Sprite >(Canvas &, const std::string &)> cb_get_sprite=std::function< Resource< Sprite >(Canvas &, const std::string &)>())
 Loads a Font from a XML resource definition. More...
 
static Resource< Fontresource (Canvas &canvas, const std::string &family_name, const FontDescription &desc, const ResourceManager &resources)
 Retrieves a Font resource from the resource manager. More...
 

Friends

class Path
 

Detailed Description

Font class.

A Font is a collection of images that can be used to represent text on a screen.

Constructor & Destructor Documentation

clan::Font::Font ( )

Constructs a null font.

clan::Font::Font ( FontFamily font_family,
float  height 
)
clan::Font::Font ( FontFamily font_family,
const FontDescription desc 
)
clan::Font::Font ( const std::string typeface_name,
float  height 
)

Constructs standard font.

clan::Font::Font ( const std::string typeface_name,
const FontDescription desc 
)
clan::Font::Font ( const FontDescription desc,
const std::string ttf_filename 
)
clan::Font::Font ( const FontDescription desc,
const std::string ttf_filename,
FileSystem  fs 
)
clan::Font::Font ( Canvas canvas,
const std::string typeface_name,
Sprite sprite,
const std::string glyph_list,
float  spacelen,
bool  monospace,
const FontMetrics metrics 
)

Constructs a Font based on a sprite.

Parameters
sprite= Sprite with glyphs
glyph_list= Letter to glyph mapping
spacelen= Width of space character
monospace= Force monospaced font (using widest sprite character)
metrics= Font metrics for the sprite font

Member Function Documentation

size_t clan::Font::clip_from_left ( Canvas canvas,
const std::string text,
float  width 
) const
size_t clan::Font::clip_from_right ( Canvas canvas,
const std::string text,
float  width 
) const
void clan::Font::draw_text ( Canvas canvas,
const Pointf position,
const std::string text,
const Colorf color = StandardColorf::white() 
)

Print text.

Parameters
canvas= Canvas
position= Dest position
text= The text to draw
color= The text color
void clan::Font::draw_text ( Canvas canvas,
float  xpos,
float  ypos,
const std::string text,
const Colorf color = StandardColorf::white() 
)
inline

References clan::color, and draw_text().

Referenced by draw_text().

int clan::Font::get_character_index ( Canvas canvas,
const std::string text,
const Pointf point 
) const

Get the character index at a specified point.

Parameters
canvas= Canvas
text= The string
point= The point
Returns
The character index. -1 = Not at specified point
std::vector<Rectf> clan::Font::get_character_indices ( Canvas canvas,
const std::string text 
) const

Get the rectangles of each glyph in a string of text.

Returns
A list of Rects for every glyph
std::string clan::Font::get_clipped_text ( Canvas canvas,
const Sizef box_size,
const std::string text,
const std::string ellipsis_text = "..." 
) const

Retrieves clipped version of the text that will fit into a box.

Returns
The string
FontDescription clan::Font::get_description ( ) const
FontMetrics clan::Font::get_font_metrics ( Canvas canvas) const

Retrieves font metrics description for the selected font.

FontHandle* clan::Font::get_handle ( Canvas canvas)

Get the font handle interface.

For example, use auto handle = dynamic_cast<FontHandle_Win32>(font.get_handle()); if (handle) {...} to obtain a specific interface

Returns
The font handle interface
GlyphMetrics clan::Font::get_metrics ( Canvas canvas,
unsigned int  glyph 
) const

Gets the glyph metrics.

Parameters
glyph= The glyph to get
Returns
The glyph metrics
bool clan::Font::is_null ( ) const
inline

Returns true if this object is invalid.

static Font clan::Font::load ( Canvas canvas,
const std::string family_name,
const FontDescription reference_desc,
FontFamily font_family,
const XMLResourceDocument doc,
std::function< Resource< Sprite >(Canvas &, const std::string &)>  cb_get_sprite = std::functionResourceSprite >(Canvas &, const std::string &)>() 
)
static

Loads a Font from a XML resource definition.

GlyphMetrics clan::Font::measure_text ( Canvas canvas,
const std::string string 
) const

Measure text size.

Parameters
string= The text to use
Returns
The metrics
clan::Font::operator bool ( ) const
inlineexplicit
static Resource<Font> clan::Font::resource ( Canvas canvas,
const std::string family_name,
const FontDescription desc,
const ResourceManager resources 
)
static

Retrieves a Font resource from the resource manager.

Parameters
canvas= Canvas
resources= Resource manager
id= id
void clan::Font::set_height ( float  value)

Sets the font height.

void clan::Font::set_line_height ( float  height)

Sets the distance between each line.

void clan::Font::set_scalable ( float  height_threshold = 64.0f)

Sets the threshold to determine if the font can be drawn scaled.

All font sizes are scalable when using sprite fonts

void clan::Font::set_style ( FontStyle  setting = FontStyle::normal)

Sets the font style setting.

void clan::Font::set_weight ( FontWeight  value = FontWeight::normal)

Sets the font weight.

void clan::Font::throw_if_null ( ) const

Throw an exception if this object is invalid.

Friends And Related Function Documentation

friend class Path
friend

The documentation for this class was generated from the following file: