JNGL
Easy to use cross-platform 2D game library
|
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. | |
void | print (const Mat3 &modelview, const std::string &text, Rgba color) const |
Draw text using modelview in color. | |
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. The color can be specified using setFontColor. | |
void | print (const Mat3 &modelview, const std::string &text) const |
Draw text using modelview. The color can be specified using setFontColor. | |
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. | |
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.