PROTO::KLUDGE  0.1
Quick prototyping library for games using SDL and OpenGL.
pk::Font Class Reference

A class implemented using the Facade pattern used for loading SDL TTF_Font data. More...

#include <Font.hpp>

Collaboration diagram for pk::Font:
Collaboration graph

Public Types

enum  hinting { h_normal = TTF_HINTING_NORMAL, h_light = TTF_HINTING_LIGHT, h_mono = TTF_HINTING_MONO, h_none = TTF_HINTING_NONE }
 From SDL_ttf docs: Hinting Font hinting is the use of mathematical instructions to adjust the display of an outline font so that it lines up with a rasterized grid. At small screen sizes, with or without antialiasing, hinting is critical for producing a clear, legible text for human readers. More...
 
enum  style {
  normal = TTF_STYLE_NORMAL, bold = TTF_STYLE_BOLD, italic = TTF_STYLE_ITALIC, underline = TTF_STYLE_UNDERLINE,
  strikethrough = TTF_STYLE_STRIKETHROUGH
}
 Set the style of the font. More...
 

Public Member Functions

 Font ()
 Default constructor. More...
 
virtual ~Font ()
 
bool loadFont (char *file, int fontSize)
 Load a font from a file. More...
 
void setFont (TTF_Font *font)
 Set the internal TTF_Font for the Font. More...
 
TTF_Font * getFont ()
 Get a pointer to the TTF_Font data. More...
 
void setHinting (Uint32 hinting)
 Set the hinting of the font (use Font::hinting enum to set valid values). More...
 
const Uint32 & getHinting ()
 Get the current hinting of the font. More...
 
void setKerning (int allowed)
 Turn on/off font kerning (on by default). More...
 
int getOutline ()
 Get the outline for the font (in pixels). More...
 
void setOutline (int outline)
 Set the outline for the font (in pixels). More...
 
void setFontStyle (int style)
 Set the style for the font. Use Font::style enum flags to combine styles. More...
 
const int & getStyle ()
 Get the current style of the font. More...
 
void setFontSize (int s)
 Set the size for the font (in pixels). More...
 

Private Attributes

TTF_Font * m_font
 Pointer to TTF_Font data - memory managed outside class. More...
 
char * m_path
 The path to the Font file. More...
 
Uint32 m_hinting
 Hinting for the font. More...
 
int m_kerning
 Kerning for the font (set to 1, or on, by default. More...
 
int m_outline
 Font outline (set to 0, or off, by default). More...
 
int m_style
 Font style (defaults to style::normal). More...
 

Detailed Description

A class implemented using the Facade pattern used for loading SDL TTF_Font data.

Member Enumeration Documentation

◆ hinting

From SDL_ttf docs: Hinting Font hinting is the use of mathematical instructions to adjust the display of an outline font so that it lines up with a rasterized grid. At small screen sizes, with or without antialiasing, hinting is critical for producing a clear, legible text for human readers.

Enumerator
h_normal 
h_light 
h_mono 
h_none 

◆ style

Set the style of the font.

Enumerator
normal 
bold 
italic 
underline 
strikethrough 

Constructor & Destructor Documentation

◆ Font()

pk::Font::Font ( )

Default constructor.

◆ ~Font()

virtual pk::Font::~Font ( )
virtual

Member Function Documentation

◆ getFont()

TTF_Font * pk::Font::getFont ( )
inline

Get a pointer to the TTF_Font data.

Returns
TTF_Font * - pointer to TTF_Font data.

◆ getHinting()

const Uint32 & pk::Font::getHinting ( )
inline

Get the current hinting of the font.

Returns
Uint32 - a 32 bit unsigned integer corresponding to an integer mapped to Font::hinting.

◆ getOutline()

void pk::Font::getOutline ( )
inline

Get the outline for the font (in pixels).

Parameters
int- a plain integer value for number of pixels for the outline.

◆ getStyle()

const int & pk::Font::getStyle ( )
inline

Get the current style of the font.

Returns
int - a plain integer corresponding to Font::style enum value(s).

◆ loadFont()

pk::Font::loadFont ( char *  file,
int  fontSize 
)

Load a font from a file.

Parameters
constchar *file - a character constant path to a file
intfontSize - the size of the font in points.
Returns
bool - true on success, false on failure.

◆ setFont()

void pk::Font::setFont ( TTF_Font *  font)
inline

Set the internal TTF_Font for the Font.

Parameters
TTF_Font*font - a pointer to a TTF_Font.

◆ setFontSize()

void pk::Font::setFontSize ( int  s)

Set the size for the font (in pixels).

Parameters
ints - a plain integer value for font size (in pixels).

◆ setFontStyle()

void pk::Font::setFontStyle ( int  style)
inline

Set the style for the font. Use Font::style enum flags to combine styles.

Parameters
intstyle - a plain integer used as flag variable for font style.

◆ setHinting()

void pk::Font::setHinting ( Uint32  hinting)
inline

Set the hinting of the font (use Font::hinting enum to set valid values).

Parameters
Uint32hinting - a 32 bit unsigned integer mapped to Font::hinting.

◆ setKerning()

void pk::Font::setKerning ( int  allowed)
inline

Turn on/off font kerning (on by default).

◆ setOutline()

void pk::Font::setOutline ( int  outline)
inline

Set the outline for the font (in pixels).

Parameters
intoutline - a plain integer value for number of pixels to outline by.

Member Data Documentation

◆ m_font

TTF_Font* pk::Font::m_font
private

Pointer to TTF_Font data - memory managed outside class.

◆ m_hinting

Uint32 pk::Font::m_hinting
private

Hinting for the font.

◆ m_kerning

int pk::Font::m_kerning
private

Kerning for the font (set to 1, or on, by default.

◆ m_outline

int pk::Font::m_outline
private

Font outline (set to 0, or off, by default).

◆ m_path

char* pk::Font::m_path
private

The path to the Font file.

◆ m_style

int pk::Font::m_style
private

Font style (defaults to style::normal).


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