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

Detailed Description

Definition at line 13 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 142 of file TTFFont.cc.

◆ TTFFont() [4/4]

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

Move construct.

Definition at line 35 of file TTFFont.hh.

◆ ~TTFFont()

openmsx::TTFFont::~TTFFont ( )

Member Function Documentation

◆ empty()

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

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

Definition at line 51 of file TTFFont.hh.

◆ getHeight()

int openmsx::TTFFont::getHeight ( ) const

Return the height of the font.

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

Definition at line 237 of file TTFFont.cc.

Referenced by render().

◆ getSize()

gl::ivec2 openmsx::TTFFont::getSize ( zstring_view  text) const

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

Definition at line 260 of file TTFFont.cc.

References zstring_view::c_str().

Referenced by render().

◆ getWidth()

int 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 247 of file TTFFont.cc.

◆ isFixedWidth()

bool openmsx::TTFFont::isFixedWidth ( ) const

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

Definition at line 242 of file TTFFont.cc.

◆ 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 42 of file TTFFont.hh.

◆ render()

SDLSurfacePtr openmsx::TTFFont::render ( std::string  text,
uint8_t  r,
uint8_t  g,
uint8_t  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 153 of file TTFFont.cc.

References g, SDLSurfacePtr::get(), getHeight(), getSize(), StringOp::split_view(), and StringOp::trimRight().


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