clan::Font Class Reference - ClanLib SDK
Description: clan::Font Class Reference

Public Member Functions | Static Public Member Functions | Friends | List of all members
clan::Font Class Reference
clanDisplay Font

Font class. More...

`#include <font.h>`

## Public Member Functions
| Font ()
| Constructs a null 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.
| Font (const FontDescription &desc, const std::string &ttf_filename)
| Font (const FontDescription &desc, const std::string &ttf_filename, FileSystem fs)
| Font (const std::string &typeface_name, const FontDescription &desc)
| Font (const std::string &typeface_name, float height)
| Constructs standard font.
| Font (FontFamily &font_family, const FontDescription &desc)
| Font (FontFamily &font_family, float height)
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.
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.
std::vector< Rectf > | get_character_indices (Canvas &canvas, const std::string &text) const
| Get the rectangles of each glyph in a string of text.
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.
FontDescription | get_description () const
FontMetrics | get_font_metrics (Canvas &canvas) const
| Retrieves font metrics description for the selected font.
FontHandle * | get_handle (Canvas &canvas)
| Get the font handle interface.
GlyphMetrics | get_metrics (Canvas &canvas, unsigned int glyph) const
| Gets the glyph metrics.
bool | is_null () const
| Returns true if this object is invalid.
GlyphMetrics | measure_text (Canvas &canvas, const std::string &string) const
| Measure text size.
| operator bool () const
void | set_height (float value)
| Sets the font height.
void | set_line_height (float height)
| Sets the distance between each line.
void | set_scalable (float height_threshold=64.0f)
| Sets the threshold to determine if the font can be drawn scaled.
void | set_style (FontStyle setting=FontStyle::normal)
| Sets the font style setting.
void | set_weight (FontWeight value=FontWeight::normal)
| Sets the font weight.
void | throw_if_null () const
| Throw an exception if this object is invalid.

## 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.
static Resource< Font > | resource (Canvas &canvas, const std::string &family_name, const FontDescription &desc, const ResourceManager &resources)
| Retrieves a Font resource from the resource manager.

## 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

## ◆ Font() [1/8]

clan::Font::Font | ( |  | ) |

Constructs a null font.

Referenced by load().

## ◆ Font() [2/8]

clan::Font::Font | ( | FontFamily & | font_family,
|  | float | height )

## ◆ Font() [3/8]

clan::Font::Font | ( | FontFamily & | font_family,
|  | const FontDescription & | desc )

## ◆ Font() [4/8]

clan::Font::Font | ( | const std::string & | typeface_name,
|  | float | height )

Constructs standard font.

## ◆ Font() [5/8]

clan::Font::Font | ( | const std::string & | typeface_name,
|  | const FontDescription & | desc )

## ◆ Font() [6/8]

clan::Font::Font | ( | const FontDescription & | desc,
|  | const std::string & | ttf_filename )

## ◆ Font() [7/8]

clan::Font::Font | ( | const FontDescription & | desc,
|  | const std::string & | ttf_filename,
|  | FileSystem | fs )

## ◆ Font() [8/8]

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

## ◆ clip_from_left()

size_t clan::Font::clip_from_left | ( | Canvas & | canvas,
|  | const std::string & | text,
|  | float | width ) const

## ◆ clip_from_right()

size_t clan::Font::clip_from_right | ( | Canvas & | canvas,
|  | const std::string & | text,
|  | float | width ) const

## ◆ draw_text() [1/2]

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

References clan::StandardColorf::white().

## ◆ draw_text() [2/2]

void clan::Font::draw_text | ( | Canvas & | canvas,
|  | float | xpos,
|  | float | ypos,
|  | const std::string & | text,
|  | const Colorf & | color = StandardColorf::white() )
| inline

References clan::color, draw_text(), and clan::StandardColorf::white().

Referenced by draw_text().

## ◆ get_character_index()

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

## ◆ get_character_indices()

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

## ◆ get_clipped_text()

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

## ◆ get_description()

FontDescription clan::Font::get_description | ( |  | ) | const

## ◆ get_font_metrics()

FontMetrics clan::Font::get_font_metrics | ( | Canvas & | canvas | ) | const

Retrieves font metrics description for the selected font.

## ◆ get_handle()

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

## ◆ get_metrics()

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

## ◆ is_null()

bool clan::Font::is_null | ( |  | ) | const
| inline

Returns true if this object is invalid.

## ◆ load()

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::function< Resource< Sprite >(Canvas &, const std::string &)>() )
| static

Loads a Font from a XML resource definition.

References Font().

## ◆ measure_text()

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

Measure text size.

Parameters

  string | = The text to use

Returns
  The metrics

## ◆ operator bool()

clan::Font::operator bool | ( |  | ) | const
| inlineexplicit

## ◆ resource()

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

## ◆ set_height()

void clan::Font::set_height | ( | float | value | ) |

Sets the font height.

## ◆ set_line_height()

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

Sets the distance between each line.

## ◆ set_scalable()

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

## ◆ set_style()

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

Sets the font style setting.

References clan::normal.

## ◆ set_weight()

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

Sets the font weight.

References clan::normal.

## ◆ throw_if_null()

void clan::Font::throw_if_null | ( |  | ) | const

Throw an exception if this object is invalid.

## Friends And Related Symbol Documentation

## ◆ Path

friend class Path
| friend

References Path.

Referenced by Path.

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

- font.h