openMSX
Public Member Functions | List of all members
openmsx::TTFFont Class Reference

#include <TTFFont.hh>

Public Member Functions

 TTFFont (const TTFFont &)=delete
 
TTFFontoperator= (const TTFFont &)=delete
 
 TTFFont ()=default
 Construct an empty font. More...
 
 TTFFont (const std::string &filename, int ptSize)
 Construct new TTFFont object. More...
 
 TTFFont (TTFFont &&other) noexcept
 Move construct. More...
 
TTFFontoperator= (TTFFont &&other) noexcept
 Move assignment. More...
 
 ~TTFFont ()
 
bool empty () const
 Is this an empty font? (a default constructed object). More...
 
SDLSurfacePtr render (std::string text, byte r, byte g, byte b) const
 Render the given text to a new SDL_Surface. More...
 
unsigned getHeight () const
 Return the height of the font. More...
 
bool isFixedWidth () const
 Returns true iff this is a fixed-with (=mono-spaced) font. More...
 
unsigned getWidth () const
 Return the width of the font. More...
 
void getSize (const std::string &text, unsigned &width, unsigned &height) const
 Return the size in pixels of the text if it would be rendered. More...
 

Detailed Description

Definition at line 11 of file TTFFont.hh.

Constructor & Destructor Documentation

◆ TTFFont() [1/4]

openmsx::TTFFont::TTFFont ( const TTFFont )
delete

◆ TTFFont() [2/4]

openmsx::TTFFont::TTFFont ( )
default

Construct an empty font.

The only valid operations on empty font objects are:

  • (move)-assign a different value to it
  • destruct the object post-condition: empty()

◆ TTFFont() [3/4]

openmsx::TTFFont::TTFFont ( const std::string &  filename,
int  ptSize 
)

Construct new TTFFont object.

Parameters
filenameFilename of font (.fft file, possibly (g)zipped).
ptSizePoint size (based on 72DPI) to load font as. post-condition: !empty()

Definition at line 135 of file TTFFont.cc.

References openmsx::TTFFontPool::get(), and openmsx::TTFFontPool::instance().

◆ TTFFont() [4/4]

openmsx::TTFFont::TTFFont ( TTFFont &&  other)
inlinenoexcept

Move construct.

Definition at line 33 of file TTFFont.hh.

◆ ~TTFFont()

openmsx::TTFFont::~TTFFont ( )

Definition at line 140 of file TTFFont.cc.

References openmsx::TTFFontPool::instance(), and openmsx::TTFFontPool::release().

Referenced by operator=().

Member Function Documentation

◆ empty()

bool openmsx::TTFFont::empty ( ) const
inline

Is this an empty font? (a default constructed object).

Definition at line 49 of file TTFFont.hh.

References g, getHeight(), getSize(), getWidth(), isFixedWidth(), and render().

Referenced by openmsx::OSDText::getType(), and openmsx::OSDConsoleRenderer::OSDConsoleRenderer().

◆ getHeight()

unsigned openmsx::TTFFont::getHeight ( ) const

Return the height of the font.

This is the recommended number of pixels between two text lines.

Definition at line 218 of file TTFFont.cc.

Referenced by empty(), openmsx::OSDConsoleRenderer::OSDConsoleRenderer(), and openmsx::OSDConsoleRenderer::~OSDConsoleRenderer().

◆ getSize()

void openmsx::TTFFont::getSize ( const std::string &  text,
unsigned &  width,
unsigned &  height 
) const

Return the size in pixels of the text if it would be rendered.

Definition at line 241 of file TTFFont.cc.

Referenced by empty(), openmsx::OSDText::getType(), and openmsx::OSDConsoleRenderer::~OSDConsoleRenderer().

◆ getWidth()

unsigned openmsx::TTFFont::getWidth ( ) const

Return the width of the font.

This is the recommended number of pixels between two characters. This number only makes sense for fixed-width fonts.

Definition at line 228 of file TTFFont.cc.

References utf8::advance().

Referenced by empty(), openmsx::OSDConsoleRenderer::OSDConsoleRenderer(), and openmsx::OSDConsoleRenderer::~OSDConsoleRenderer().

◆ isFixedWidth()

bool openmsx::TTFFont::isFixedWidth ( ) const

Returns true iff this is a fixed-with (=mono-spaced) font.

Definition at line 223 of file TTFFont.cc.

Referenced by empty().

◆ operator=() [1/2]

TTFFont& openmsx::TTFFont::operator= ( const TTFFont )
delete

◆ operator=() [2/2]

TTFFont& openmsx::TTFFont::operator= ( TTFFont &&  other)
inlinenoexcept

Move assignment.

Definition at line 40 of file TTFFont.hh.

References ~TTFFont().

◆ render()

SDLSurfacePtr openmsx::TTFFont::render ( std::string  text,
byte  r,
byte  g,
byte  b 
) const

Render the given text to a new SDL_Surface.

The text must be UTF-8 encoded. The result is a 32bpp RGBA SDL_Surface.

Definition at line 146 of file TTFFont.cc.

References g, SDLSurfacePtr::get(), gl::max(), StringOp::split(), StringOp::trimRight(), and xrange().

Referenced by empty(), openmsx::OSDText::getType(), and openmsx::OSDConsoleRenderer::~OSDConsoleRenderer().


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