Typeface describing an assortment of character glyphs that may be rendered on-demand into an expanding texture atlas, for use in Text2D rendering.
More...
#include <GREM/graphics_2d/Font2D.hpp>
|
| | Font2D (const Filesystem &filesystem, CStringView filepath, const Font2DOptions &options={}) |
| | Load a font from a file.
|
| | ~Font2D ()=default |
| | Destructor.
|
| | Font2D (const Font2D &)=delete |
| | Copying a font is not allowed, since the memory location of the file contents must remain stable.
|
| | Font2D (Font2D &&other) noexcept=default |
| | Move constructor.
|
| Font2D & | operator= (const Font2D &other)=delete |
| | Copying a font is not allowed, since the memory location of the file contents must remain stable.
|
| Font2D & | operator= (Font2D &&other) noexcept=default |
| | Move assignment.
|
| void | clearRenderedGlyphs () noexcept |
| | Remove all rendered glyphs in the font and reset the texture atlas.
|
| Optional< RenderedGlyphInfo > | findRenderedGlyphInfo (uint32_t characterSize, char32_t codePoint) const noexcept |
| | Look up the information about a glyph's entry in the texture atlas for a specific code point.
|
| Pair< RenderedGlyphInfo, bool > | renderGlyph (Device &device, uint32_t characterSize, char32_t codePoint) |
| | Render the glyph for a specific character and store it in the texture atlas, if it has not already been rendered.
|
| void | setOptions (Device &device, const Font2DOptions &newOptions) |
| | Update the configuration options of this font and recreate the texture atlas if necessary to apply the new sampler options.
|
| GlyphMetrics | getGlyphMetrics (uint32_t characterSize, char32_t codePoint) const noexcept |
| | Get the dimensions of a single glyph in this font, for shaping text.
|
| LineMetrics | getLineMetrics (uint32_t characterSize) const noexcept |
| | Get the vertical dimensions for shaping lines of text with this font.
|
| vec2 | getKerning (uint32_t characterSize, char32_t left, char32_t right) const noexcept |
| | Get the kerning offset to use between a pair of adjacent character glyphs while shaping text.
|
| const Texture & | getAtlasTexture () const noexcept |
| | Get the texture atlas to use when rendering glyphs from this font.
|
| Font2DOptions | getOptions () const noexcept |
| | Get the current configuration options of the font.
|
Typeface describing an assortment of character glyphs that may be rendered on-demand into an expanding texture atlas, for use in Text2D rendering.
◆ Font2D() [1/3]
Load a font from a file.
The supported file formats are:
- TrueType (.ttf)
- OpenType (.otf)
- Parameters
-
| filesystem | filesystem to load the file from. |
| filepath | input filepath of the font file to load. |
| options | font options, see Font2DOptions. |
- Exceptions
-
| File::Error | on failure to open the file. |
| graphics::Error | on failure to load a font from the file. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
- Note
- The only supported text encoding is Unicode.
-
Only TrueType fonts are fully supported. OpenType extensions that are not a part of TrueType may not work.
◆ ~Font2D()
| grem::graphics::Font2D::~Font2D |
( |
| ) |
|
|
default |
◆ Font2D() [2/3]
| grem::graphics::Font2D::Font2D |
( |
const Font2D & | | ) |
|
|
delete |
Copying a font is not allowed, since the memory location of the file contents must remain stable.
◆ Font2D() [3/3]
| grem::graphics::Font2D::Font2D |
( |
Font2D && | other | ) |
|
|
defaultnoexcept |
◆ operator=() [1/2]
| Font2D & grem::graphics::Font2D::operator= |
( |
const Font2D & | other | ) |
|
|
delete |
Copying a font is not allowed, since the memory location of the file contents must remain stable.
◆ operator=() [2/2]
| Font2D & grem::graphics::Font2D::operator= |
( |
Font2D && | other | ) |
|
|
defaultnoexcept |
◆ clearRenderedGlyphs()
| void grem::graphics::Font2D::clearRenderedGlyphs |
( |
| ) |
|
|
noexcept |
Remove all rendered glyphs in the font and reset the texture atlas.
◆ findRenderedGlyphInfo()
| Optional< RenderedGlyphInfo > grem::graphics::Font2D::findRenderedGlyphInfo |
( |
uint32_t | characterSize, |
|
|
char32_t | codePoint ) const |
|
nodiscardnoexcept |
Look up the information about a glyph's entry in the texture atlas for a specific code point.
- Parameters
-
| characterSize | character size of the glyph to search for. |
| codePoint | Unicode code point of the glyph to search for. |
- Returns
- the rendered glyph information, see RenderedGlyphInfo, or an empty optional if the glyph has not been rendered.
- See also
- renderGlyph()
-
getAtlasTexture()
◆ renderGlyph()
Render the glyph for a specific character and store it in the texture atlas, if it has not already been rendered.
- Parameters
-
| device | device to use for rendering the glyph. Must outlive the font. |
| characterSize | character size to render the glyph at. |
| codePoint | Unicode code point of the glyph to render. |
- Returns
- a pair of:
- information about the rendered glyph, and
- a bool that is true if the glyph was actually rendered, or false if the glyph had already been rendered previously.
- Exceptions
-
| graphics::Error | on failure to render the glyph. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
- Note
- If the specified glyph has already been rendered previously, no modification is made, and the already rendered glyph is returned. In this case, the function is guaranteed to not throw any exceptions.
- See also
- findRenderedGlyphInfo()
-
getGlyphMetrics()
-
getAtlasTexture()
◆ setOptions()
Update the configuration options of this font and recreate the texture atlas if necessary to apply the new sampler options.
- Parameters
-
| device | device to use for the texture atlas. Must outlive the font. |
| newOptions | new font options, see Font2DOptions. |
- Exceptions
-
| graphics::Error | on failure to render the glyphs. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
- See also
- getOptions()
◆ getGlyphMetrics()
| GlyphMetrics grem::graphics::Font2D::getGlyphMetrics |
( |
uint32_t | characterSize, |
|
|
char32_t | codePoint ) const |
|
nodiscardnoexcept |
Get the dimensions of a single glyph in this font, for shaping text.
- Parameters
-
| characterSize | character size to get the glyph metrics of. |
| codePoint | Unicode code point to get the glyph metrics of. |
- Returns
- the glyph metrics of the given code point at the given character size, see GlyphMetrics.
- See also
- findRenderedGlyphInfo()
-
renderGlyph()
◆ getLineMetrics()
| LineMetrics grem::graphics::Font2D::getLineMetrics |
( |
uint32_t | characterSize | ) |
const |
|
nodiscardnoexcept |
Get the vertical dimensions for shaping lines of text with this font.
- Parameters
-
| characterSize | character size to get the line metrics of. |
- Returns
- the line metrics at the given character size, see LineMetrics.
◆ getKerning()
| vec2 grem::graphics::Font2D::getKerning |
( |
uint32_t | characterSize, |
|
|
char32_t | left, |
|
|
char32_t | right ) const |
|
nodiscardnoexcept |
Get the kerning offset to use between a pair of adjacent character glyphs while shaping text.
- Parameters
-
| characterSize | character size of the glyphs to get the kerning of. |
| left | Unicode code point of the left glyph in the adjacent pair. |
| right | Unicode code point of the right glyph in the adjacent pair. |
- Returns
- if the font contains a valid glyph for both the left and the right characters, returns the additional offset to advance the position by when going from the left glyph to the right glyph. Otherwise, returns (0, 0).
◆ getAtlasTexture()
| const Texture & grem::graphics::Font2D::getAtlasTexture |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
Get the texture atlas to use when rendering glyphs from this font.
- Returns
- a read-only reference to a square texture containing all loaded glyphs.
- See also
- findRenderedGlyphInfo()
-
renderGlyph()
◆ getOptions()
Get the current configuration options of the font.
- Returns
- the current font options.
- See also
- setOptions()
The documentation for this class was generated from the following file: