GameKit  0.0.1a
C++ gamedev tools
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
gk::Font Class Reference

Class for loading and manipulating character fonts. More...

#include <Font.hpp>

Inheritance diagram for gk::Font:
gk::NonCopyable

Public Member Functions

 Font ()=default
 Default constructor. More...
 
 Font (const std::string &filename)
 Construct the font from a file. More...
 
void loadFromFile (const std::string &filename)
 Load the font from a file. More...
 
void setFontKerning (int kerning)
 Set font kerning. More...
 
void setFontHinting (int hinting)
 Set font hinting. More...
 
void setFontOutline (int outline)
 Set font outline. More...
 
void loadFont (int ptsize) const
 Load a new font size into this font. More...
 
TTF_Font * getFont (int ptsize) const
 Get the SDL font for a specific font size. More...
 

Private Types

using TTF_FontPtr = std::unique_ptr< TTF_Font, decltype(&TTF_CloseFont)>
 

Private Member Functions

void update ()
 Update kerning, hinting and outline of all font sizes. More...
 

Private Attributes

std::string m_filename
 Font filename. More...
 
int m_kerning = 1
 Kerning value. More...
 
int m_hinting = TTF_HINTING_NORMAL
 Hinting value. More...
 
int m_outline = 0
 Outline value. More...
 
std::unordered_map< int, TTF_FontPtrm_fonts
 SDL font container. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gk::NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
const NonCopyableoperator= (const NonCopyable &)=delete
 

Detailed Description

Class for loading and manipulating character fonts.

gk::Font is a class that allows loading a font from a file.

This class can't display anything on its own and has to be used with gk::Text.

/warning Each different font size will result in another SDL object loaded, please avoid using a lot of different sizes for the same font.

Definition at line 30 of file Font.hpp.

Member Typedef Documentation

§ TTF_FontPtr

using gk::Font::TTF_FontPtr = std::unique_ptr<TTF_Font, decltype(&TTF_CloseFont)>
private

Definition at line 103 of file Font.hpp.

Constructor & Destructor Documentation

§ Font() [1/2]

gk::Font::Font ( )
default

Default constructor.

This constructor defines an empty font

§ Font() [2/2]

gk::Font::Font ( const std::string &  filename)
inline

Construct the font from a file.

Parameters
filenamePath of the font file to load

Definition at line 46 of file Font.hpp.

Member Function Documentation

§ getFont()

TTF_Font * gk::Font::getFont ( int  ptsize) const

Get the SDL font for a specific font size.

Parameters
ptsizeFont size

Definition at line 34 of file Font.cpp.

§ loadFont()

void gk::Font::loadFont ( int  ptsize) const

Load a new font size into this font.

Parameters
ptsizeFont size

Definition at line 19 of file Font.cpp.

§ loadFromFile()

void gk::Font::loadFromFile ( const std::string &  filename)
inline

Load the font from a file.

Parameters
filenamePath of the font file to load

Definition at line 54 of file Font.hpp.

§ setFontHinting()

void gk::Font::setFontHinting ( int  hinting)
inline

Set font hinting.

Parameters
kerningNew font hinting

Definition at line 70 of file Font.hpp.

§ setFontKerning()

void gk::Font::setFontKerning ( int  kerning)
inline

Set font kerning.

Parameters
kerningNew font kerning

Definition at line 62 of file Font.hpp.

§ setFontOutline()

void gk::Font::setFontOutline ( int  outline)
inline

Set font outline.

Parameters
outlineNew font outline

Definition at line 78 of file Font.hpp.

§ update()

void gk::Font::update ( )
private

Update kerning, hinting and outline of all font sizes.

Definition at line 42 of file Font.cpp.

Member Data Documentation

§ m_filename

std::string gk::Font::m_filename
private

Font filename.

Definition at line 108 of file Font.hpp.

§ m_fonts

std::unordered_map<int, TTF_FontPtr> gk::Font::m_fonts
mutableprivate

SDL font container.

Definition at line 114 of file Font.hpp.

§ m_hinting

int gk::Font::m_hinting = TTF_HINTING_NORMAL
private

Hinting value.

Definition at line 111 of file Font.hpp.

§ m_kerning

int gk::Font::m_kerning = 1
private

Kerning value.

Definition at line 110 of file Font.hpp.

§ m_outline

int gk::Font::m_outline = 0
private

Outline value.

Definition at line 112 of file Font.hpp.


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