JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Font Class Reference

Font loaded from a TTF or OTF file. More...

#include <jngl/font.hpp>

Public Member Functions

 Font (const std::string &filename, unsigned int size, float strokePercentage=0)
 Creates a font from filename in size px. More...
 
void print (const std::string &, int x, int y)
 Uses the font to print something at x y. The color can be specified using setFontColor.
 
void print (const std::string &text, Vec2 position) const
 Draw text at position.
 
void print (const Mat3 &modelview, const std::string &text) const
 Draw text using modelview.
 
double getTextWidth (std::string_view)
 Calculates the width of text in scale-independent pixels if it would be drawn with this font.
 
std::shared_ptr< FontImpl > getImpl ()
 Internal function.
 

Detailed Description

Font loaded from a TTF or OTF file.

Definition at line 19 of file font.hpp.

Constructor & Destructor Documentation

◆ Font()

Font ( const std::string filename,
unsigned int  size,
float  strokePercentage = 0 
)

Creates a font from filename in size px.

You may set strokePercentage to a positive or negative % value to increase or decrease the font size, without actually changing the position/size of the individual characters. This can be used to draw an outlined text by e.g. first drawing with a 5% stroke and then printing the same text with 0% (or even a negative stroke) over it.

Example: To increase the size of each character by 2px for a Font with a size of 20px, you would pass 10.f for strokePercentage.


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