Maria GDK 5.0.0.738
Documentation of native code in develop branch
Loading...
Searching...
No Matches
STK::Font Class Referenceabstract

#include <StkFont.h>

Inheritance diagram for STK::Font:
STK::TextureFont STK::TextureFontSDF

Classes

struct  GlyphInfo
 

Public Member Functions

 Font (const std::string &font_id)
 
const std::string & getFontID () const
 
int getFontNumber () const
 Return unique integer ID for this font.
 
bool initFontData (const std::string &filename, int font_size, int font_idx=0)
 Initialize font.
 
void updateTexture ()
 Update the OpenGL texture. This is normally done on demand, but may also be called explicitly if you need to keep control of when this should happen.
 
void clearTexture ()
 Clear OpenGL texture data. Requires a valid OpenGL context.
 
Font::GlyphInfo makeGlyphInfo (uint32_t character, float &offsetX, float &offsetY)
 
void bindTexture ()
 
void saveTextureAtlas (const std::string &filename="")
 
float getAscent () const
 Get max distance (in pixels) above the baseline for this font.
 
float getDescent () const
 Get max distance (in pixels) below the baseline for this font.
 
float getLineGap () const
 Get spacing (in pixels) between one row's descent and the next row's ascent for this font.
 
float getLineDistance () const
 Get default distance (in pixels) between two rows in this font.
 
int getPixelSize () const
 Get font size (in pixels).
 
void getAdvanceBearing (int codepoint, float &advance, float &bearing)
 Get horizontal metrics (in pixels) for the given character. Bearing is the offset from the current horizontal position to the left edge of the character. advance is the offset from the current horizontal position to the next horizontal position.
 

Static Public Member Functions

static double pointToPixelSize (double pt_size, double dpi=96)
 
static double pixelToPointSize (double px_size, double dpi=96)
 

Protected Member Functions

template<class T >
void findCharRanges (std::vector< std::unique_ptr< T > > &char_ranges, int max_cp)
 
template<class T >
int calcMaxPackedCodepoint (const std::vector< std::unique_ptr< T > > &char_ranges) const
 
virtual bool getCharacterQuad (int codepoint, stbtt_aligned_quad &quad, float &offsetX, float &offsetY)=0
 

Protected Attributes

std::string font_id_
 
std::string font_filename_
 
int font_num_ = 0
 
int font_size_ = 0
 
float font_scale_ = 0.0f
 
int atlas_width_ = 0
 
int atlas_height_ = 0
 
std::unique_ptr< uint8_t[]> atlas_data_
 
GLuint texture_ = 0
 
bool texture_dirty_ = false
 
std::unique_ptr< stbtt_fontinfofont_info_
 
std::vector< uint8_t > font_data_
 
int font_idx_ = 0
 

Static Protected Attributes

static int s_font_num_ = 1
 

Detailed Description

Font - Base class for STK fonts.

Member Function Documentation

◆ bindTexture()

void STK::Font::bindTexture ( )
inline

Update and bind OpenGL texture object. This method will update the OpenGL texture data if there has been any changes to the underlying atlas, and then bind the texture handle.

◆ getAdvanceBearing()

void STK::Font::getAdvanceBearing ( int  codepoint,
float &  advance,
float &  bearing 
)
inline

Get horizontal metrics (in pixels) for the given character. Bearing is the offset from the current horizontal position to the left edge of the character. advance is the offset from the current horizontal position to the next horizontal position.

Parameters
codepointThe unicode codepoint for a character.
advanceOutput advance (in pixels) for the character.
bearingOutput bearing (in pixels) for the character.

◆ getFontNumber()

int STK::Font::getFontNumber ( ) const
inline

Return unique integer ID for this font.

Returns

◆ getPixelSize()

int STK::Font::getPixelSize ( ) const
inline

Get font size (in pixels).

Returns

◆ initFontData()

bool Font::initFontData ( const std::string &  filename,
int  font_size,
int  font_idx = 0 
)

Initialize font.

Parameters
filename
font_sizeFont size (in pixels)
font_idx
Returns

◆ makeGlyphInfo()

Font::GlyphInfo Font::makeGlyphInfo ( uint32_t  character,
float &  offsetX,
float &  offsetY 
)

Calculate glyph vertex and texture coordinates for the given Unicode character code. The vertices will be offset by the input offset values. The offset values will be increased by the glyphs advance and can be used to place the next character on the line.

◆ saveTextureAtlas()

void Font::saveTextureAtlas ( const std::string &  filename = "")

Save texture atlas to file as PNG. This method is mostly useful for debugging. If no filename is given, a name is generated from the font name.


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