4#ifndef GREM_GRAPHICS_2D_FONT_2D_HPP
5#define GREM_GRAPHICS_2D_FONT_2D_HPP
32 .initialResolution = 128,
240 [[nodiscard]] GREM_API(graphics_2d)
vec2 getKerning(uint32_t characterSize,
char32_t left,
char32_t right) const noexcept;
268 GREM_API(graphics_2d)
void operator()(
void* handle)
const noexcept;
271 struct RenderedGlyphKey {
272 uint32_t characterSize;
275 [[nodiscard]]
constexpr auto operator<=>(
const RenderedGlyphKey&)
const =
default;
278 Allocation<byte> fontFileContents{};
279 UniqueHandle<void*, FontDeleter> font{};
280 resource::AtlasPacker atlasPacker;
281 Texture atlasTexture{};
282 OrderedMap<RenderedGlyphKey, RenderedGlyphInfo> renderedGlyphs{};
283 Font2DOptions options;
Base interface for a filesystem.
Definition Filesystem.hpp:25
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
GlyphMetrics getGlyphMetrics(uint32_t characterSize, char32_t codePoint) const noexcept
Get the dimensions of a single glyph in this font, for shaping text.
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 be...
Font2D(const Filesystem &filesystem, CStringView filepath, const Font2DOptions &options={})
Load a font from a file.
void clearRenderedGlyphs() noexcept
Remove all rendered glyphs in the font and reset the texture atlas.
~Font2D()=default
Destructor.
Font2D(const Font2D &)=delete
Copying a font is not allowed, since the memory location of the file contents must remain stable.
Font2DOptions getOptions() const noexcept
Get the current configuration options of the font.
Definition Font2D.hpp:262
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.
void setOptions(Device &device, const Font2DOptions &newOptions)
Update the configuration options of this font and recreate the texture atlas if necessary to apply th...
Font2D(Font2D &&other) noexcept=default
Move constructor.
const Texture & getAtlasTexture() const noexcept
Get the texture atlas to use when rendering glyphs from this font.
Definition Font2D.hpp:251
Font2D & operator=(Font2D &&other) noexcept=default
Move assignment.
LineMetrics getLineMetrics(uint32_t characterSize) const noexcept
Get the vertical dimensions for shaping lines of text with this font.
Font2D & operator=(const Font2D &other)=delete
Copying a font is not allowed, since the memory location of the file contents must remain stable.
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.
Storage for multidimensional data, such as 2D images, on the GPU, combined with a sampler configurati...
Definition Texture.hpp:700
Definition buffer_layouts.hpp:20
vec< 2, float > vec2
Definition math.hpp:438
constexpr std::compare_three_way_result_t< A, B > operator<=>(const Indirect< A, AllocatorA > &a, const Indirect< B, AllocatorB > &b)
Definition Indirect.hpp:273
CStringViewBase< char, std::char_traits< char > > CStringView
Definition CStringView.hpp:635
Configuration options for a Font2D.
Definition Font2D.hpp:27
bool useLinearFiltering
Use bilinear filtering rather than nearest-neighbor interpolation when rendering text at a non-1:1 sc...
Definition Font2D.hpp:50
resource::AtlasPackerOptions atlasPackerOptions
Configuration options for the font's internal atlas packer.
Definition Font2D.hpp:31
constexpr bool operator==(const Font2DOptions &other) const =default
Compare these options to another set of options for equality.
Dimensions of a single glyph in this font, for shaping text.
Definition Font2D.hpp:79
float advance
Horizontal offset to apply in order to advance to the next glyph position, excluding any kerning.
Definition Font2D.hpp:82
vec2 bearing
Offset from the baseline to apply to the glyph's rectangle position when rendering this glyph.
Definition Font2D.hpp:81
vec2 size
Size of this glyph's rectangle when rendered, in pixels.
Definition Font2D.hpp:80
Vertical dimensions for shaping lines of text with this font.
Definition Font2D.hpp:88
float ascender
Vertical offset from the baseline to the visual top of the text.
Definition Font2D.hpp:89
float height
Vertical offset to apply in order to advance to the next line.
Definition Font2D.hpp:91
float descender
Vertical offset from the baseline to the visual bottom of the text.
Definition Font2D.hpp:90
Information about a single glyph's entry in the texture atlas.
Definition Font2D.hpp:71
vec2 sizeInAtlas
Size of this glyph's rectangle in the texture atlas, in texels.
Definition Font2D.hpp:73
vec2 positionInAtlas
Position of this glyph's rectangle in the texture atlas, in texels.
Definition Font2D.hpp:72
Configuration options for an AtlasPacker.
Definition AtlasPacker.hpp:20