ASGE  3.2.0
Simple Game Framework in GL
ASGE::Font Struct Referenceabstract

#include <Font.hpp>

Inheritance diagram for ASGE::Font:
[legend]
Collaboration diagram for ASGE::Font:
[legend]

Classes

struct  AtlasMetrics
 

Public Member Functions

 Font ()=default
 
virtual ~Font ()=default
 
int pxWide (const std::string &string) const
 
int pxWide (const char *ch, float scale) const
 
int pxHeight (const std::string &string) const
 
int pxHeight (const char *ch, float scale) const
 
std::tuple< float, float > boundsY (const char *ch, float scale) const
 
virtual std::tuple< float, float > boundsY (const std::string &string, float scale) const =0
 
virtual float pxWide (const std::string &string, float scale) const =0
 
virtual float pxHeight (const std::string &string, float scale) const =0
 
virtual void setMagFilter (ASGE::Texture2D::MagFilter mag_filter)=0
 
- Public Member Functions inherited from ASGE::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 

Public Attributes

const char * font_name = ""
 
float line_height = 0
 
float px_range = 2
 
int font_size = 0
 

Detailed Description

A font used to render text.

A font is used to store font related information. All fonts need a name, size and line height. This can be used by the renderer to ensure loaded fonts are being used correctly.

Usage:

// from binary data
file.open("/data/Fonts/DroidSansMono.ttf", ASGE::FILEIO::File::IOMode::READ);
ASGE::FILEIO::IOBuffer buffer = file.read();
renderer->loadFontFromMem("DroidSansMono", buffer.as_unsigned_char(), static_cast<unsigned int>(buffer.length), 18);
// directly using a local file
renderer->loadFont("/data/fonts/DroidSansMono.ttf", 18);
A file stored locally on the machine.
Definition: FileIO.hpp:188
IOBuffer read()
Reads the contents of the file.
bool open(const std::string &filename, IOMode mode=IOMode::READ)
Attempts to open a local file.
buffer for raw data.
Definition: FileIO.hpp:114
unsigned char * as_unsigned_char() noexcept
See also
Renderer
Text

Definition at line 50 of file Font.hpp.

Member Function Documentation

◆ boundsY() [1/2]

std::tuple<float, float> ASGE::Font::boundsY ( const char *  ch,
float  scale 
) const

Returns the distance from the baseline in the y axis.

Font's use a baseline for positioning the main body of text. This function calculates the max distance on the Y axis required to render the text. It returns both the deviation in the -Y and deviation in the +Y axis. This can be used to create bounding boxes. It will also correctly parse new lines.

Parameters
[in]chThe character used in the calculations.
[in]scaleAny scaling to apply.
Returns
The number of pixels required in the Y axis to render the string.

◆ boundsY() [2/2]

virtual std::tuple<float, float> ASGE::Font::boundsY ( const std::string &  string,
float  scale 
) const
pure virtual

Returns the distance from the baseline in the y axis.

Font's use a baseline for positioning the main body of text. This function calculates the max distance on the Y axis required to render the text. It returns both the deviation in the -Y and deviation in the +Y axis. This can be used to create bounding boxes. It will also correctly parse new lines.

Parameters
[in]strThe string used in the calculations.
[in]scaleAny scaling to apply.
Returns
The number of pixels required in the Y axis to render the string.

◆ pxHeight() [1/3]

int ASGE::Font::pxHeight ( const char *  ch,
float  scale 
) const

Returns the distance in y pixels.

Sometimes it's useful to know how tall a string rendered on the screen will be, maybe for procedurally placing text etc. This function attempts to return the number of pixels the height of a string will take.

Parameters
[in]chThe height of the character to calculate.
[in]scaleAny scaling to apply.
Returns
The max number of pixels high needed to render the string.

◆ pxHeight() [2/3]

int ASGE::Font::pxHeight ( const std::string &  string) const

Returns the distance in y pixels.

Sometimes it's useful to know how tall a string rendered on the screen will be, maybe for procedurally placing text etc. This function attempts to return the number of pixels the height of a string will take.

Parameters
[in]stringthe length you want to calculate.
Returns
The max number of pixels high needed to render the string.

◆ pxHeight() [3/3]

virtual float ASGE::Font::pxHeight ( const std::string &  string,
float  scale 
) const
pure virtual

Returns the distance scaled in y pixels.

Sometimes it's useful to know how wide a string rendered on the screen will be, maybe for procedurally placing text etc. This function attempts to return the number of pixels a string will take vertically.

Parameters
[in]stringThe length you want to calculate.
[in]scalethe scaled size you want to calculate.
Returns
The max number of pixels wide needed to render the string.

◆ pxWide() [1/3]

int ASGE::Font::pxWide ( const char *  ch,
float  scale 
) const

Returns the distance in x pixels.

Sometimes it's useful to know how wide a string rendered on the screen will be, maybe for procedurally placing text etc. This function attempts to return the number of pixels a string will take.

Parameters
[in]chThe character to check.
[in]scaleAny scaling to apply.
Returns
The max number of pixels wide needed to render the string.

◆ pxWide() [2/3]

int ASGE::Font::pxWide ( const std::string &  string) const

Returns the distance in x pixels.

Sometimes it's useful to know how wide a string rendered on the screen will be, maybe for procedurally placing text etc. This function attempts to return the number of pixels a string will take.

Parameters
[in]stringthe length you want to calculate.
Returns
The max number of pixels wide needed to render the string.

◆ pxWide() [3/3]

virtual float ASGE::Font::pxWide ( const std::string &  string,
float  scale 
) const
pure virtual

Returns the distance scaled in x pixels.

Sometimes it's useful to know how wide a string placing text etc. This function attempts to return rendered on the screen will be, maybe for procedurally placing text etc. This function attempts to return the number of pixels a string will take.

Parameters
[in]stringThe length you want to calculate.
[in]scaleThe scaled size you want to calculate.
Returns
The max number of pixels wide needed to render the string.

◆ setMagFilter()

virtual void ASGE::Font::setMagFilter ( ASGE::Texture2D::MagFilter  mag_filter)
pure virtual

Sets the filtering used for scaling the font upwards. The mag filter controls how a texture's sampling will operate when magnified. In general use, font's work well with linear sampling, but this allows the user to specify nearest neighbour instead which may lead to crisper results depending on the font face.

Parameters
[in]mag_filterThe magnification filter to use.

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