4#ifndef GREM_GRAPHICS_2D_TEXT_2D_HPP
5#define GREM_GRAPHICS_2D_TEXT_2D_HPP
313 append(font, characterSize,
string, offset,
scale);
323 append(font, characterSize,
string, offset,
scale);
330 shapedGlyphs.clear();
331 shapedGlyphsInfo.clear();
332 shapedLinesInfo.clear();
344 return append(font, characterSize,
string, offset,
scale);
355 return append(font, characterSize,
string, offset,
scale);
406 static_assert(
sizeof(char) ==
sizeof(char8_t));
407 static_assert(
alignof(char) ==
alignof(char8_t));
408 return append(font, characterSize,
UTF8StringView{std::launder(
reinterpret_cast<const char8_t*
>(
string.data())),
string.size()}, offset,
scale);
438 return shapedGlyphsInfo;
453 return shapedLinesInfo;
473 if (!shapedLinesInfo.empty()) {
492 switch (horizontalAlignment) {
495 if (!shapedLinesInfo.empty()) {
501 if (!shapedLinesInfo.empty()) {
507 if (!shapedLinesInfo.empty()) {
513 if (!shapedLinesInfo.empty()) {
534 switch (verticalAlignment) {
537 if (!shapedLinesInfo.empty()) {
543 if (!shapedLinesInfo.empty()) {
549 if (!shapedLinesInfo.empty()) {
555 if (!shapedLinesInfo.empty()) {
582 Buffer<ShapedLineInfo> shapedLinesInfo{};
583 Box<2, float> boundingBox{};
Typeface describing an assortment of character glyphs that may be rendered on-demand into an expandin...
Definition Font2D.hpp:66
vec2 getNextLineOffset() const noexcept
Get the scaled offset where the next line would have ended up if another line had followed the last s...
Definition Text2D.hpp:472
float getVerticalAlignmentOffset(TextAlignVertical verticalAlignment) const
Get the scaled vertical offset to apply when rendering the text with a specific vertical alignment.
Definition Text2D.hpp:533
Box< 2, float > getBoundingBox() const noexcept
Get the scaled bounding box of the shaped text.
Definition Text2D.hpp:462
Span< const ShapedGlyph > getShapedGlyphs() const noexcept
Get the list of ShapedGlyph data for all shaped glyphs.
Definition Text2D.hpp:422
vec2 getAlignmentOffset(TextAlign alignment) const noexcept
Get the scaled offset to apply when rendering the text with a specific alignment.
Definition Text2D.hpp:575
float getHorizontalAlignmentOffset(TextAlignHorizontal horizontalAlignment) const
Get the scaled horizontal offset to apply when rendering the text with a specific horizontal alignmen...
Definition Text2D.hpp:491
ShapeResult append(Font2D &font, uint32_t characterSize, UTF8StringView string, vec2 offset={0.0f, 0.0f}, vec2 scale={1.0f, 1.0f})
Use a font to shape a string of UTF-8 encoded text into a sequence of glyphs that are ready to be dra...
ShapeResult assign(Font2D &font, uint32_t characterSize, UTF8StringView string, vec2 offset={0.0f, 0.0f}, vec2 scale={1.0f, 1.0f})
Helper function that is equivalent to clear() followed by append().
Definition Text2D.hpp:353
ShapeResult assign(Font2D &font, uint32_t characterSize, StringView string, vec2 offset={0.0f, 0.0f}, vec2 scale={1.0f, 1.0f})
Helper function that is equivalent to clear() followed by append().
Definition Text2D.hpp:342
ShapeResult append(Font2D &font, uint32_t characterSize, StringView string, vec2 offset={0.0f, 0.0f}, vec2 scale={1.0f, 1.0f})
Helper overload of append() that takes an arbitrary byte string and interprets it as UTF-8.
Definition Text2D.hpp:405
Span< const ShapedLineInfo > getShapedLinesInfo() const noexcept
Get the list of ShapedLineInfo data for all shaped lines.
Definition Text2D.hpp:452
void clear() noexcept
Erase all shaped glyphs and reset the text to an empty state.
Definition Text2D.hpp:329
Span< const ShapedGlyphInfo > getShapedGlyphsInfo() const noexcept
Get the list of ShapedGlyphInfo data for all shaped glyphs.
Definition Text2D.hpp:437
Text2D() noexcept=default
Construct an empty text.
Text2D(Font2D &font, uint32_t characterSize, StringView string, vec2 offset={0.0f, 0.0f}, vec2 scale={1.0f, 1.0f})
Helper overload of Text2D() that takes an arbitrary byte string and interprets it as UTF-8.
Definition Text2D.hpp:322
Definition buffer_layouts.hpp:20
@ NONE
Ignore the depth buffer.
Definition shaders.hpp:59
TextAlignHorizontal
Horizontal text alignment mode.
Definition Text2D.hpp:25
@ RIGHT
Align to the right of the bounding box of the text.
Definition Text2D.hpp:33
@ LEFT
Align to the left of the bounding box of the text.
Definition Text2D.hpp:31
@ LAST_LINE_START
Align to the start of the first glyph in the last line of the text.
Definition Text2D.hpp:29
@ LAST_LINE_END
Align to the end of the last glyph in the last line of the text.
Definition Text2D.hpp:30
@ FIRST_LINE_END
Align to the end of the last glyph in the first line of the text.
Definition Text2D.hpp:28
@ NONE
No horizontal alignment.
Definition Text2D.hpp:26
@ CENTER
Align to the horizontal center of the bounding box of the text.
Definition Text2D.hpp:32
@ FIRST_LINE_START
Align to the start of the first glyph in the first line of the text.
Definition Text2D.hpp:27
TextAlignVertical
Vertical text alignment mode.
Definition Text2D.hpp:39
@ LAST_LINE_TOP
Align to the ascender of the last line in the text.
Definition Text2D.hpp:43
@ BOTTOM
Align to the bottom of the bounding box of the text.
Definition Text2D.hpp:45
@ LAST_LINE_BASE
Align to the baseline of the last line in the text.
Definition Text2D.hpp:44
@ FIRST_LINE_TOP
Align to the ascender of the first line in the text.
Definition Text2D.hpp:41
@ TOP
Align to the top of the bounding box of the text.
Definition Text2D.hpp:47
@ FIRST_LINE_BASE
Align to the baseline of the first line in the text.
Definition Text2D.hpp:42
@ NONE
No vertical alignment.
Definition Text2D.hpp:40
@ CENTER
Align to the vertical center of the bounding box of the text.
Definition Text2D.hpp:46
vec< 2, float > vec2
Definition math.hpp:438
GREM_ALWAYS_INLINE constexpr vec< N, T > GREM_VECTORCALL round(vec< N, T > a)
Definition math.hpp:1418
StringViewBase< char, std::char_traits< char > > StringView
Definition StringView.hpp:16
GREM_ALWAYS_INLINE constexpr mat< 3, 3, T > GREM_VECTORCALL scale(vec< 2, T > scale)
Create a scale matrix describing a 2D scale.
Definition math.hpp:2665
StringViewBase< char8_t, std::char_traits< char8_t > > UTF8StringView
Definition StringView.hpp:17
Generic axis-aligned box shape with minimum and maximum extents in N-dimensional space.
Definition geometry.hpp:149
Result of the text shaping functions.
Definition Text2D.hpp:256
size_t shapedGlyphOffset
Index, into the lists returned by getShapedGlyphs() and getShapedGlyphsInfo(), of the ShapedGlyph and...
Definition Text2D.hpp:265
size_t shapedLineOffset
Index, into the list returned by getShapedLinesInfo(), of the ShapedLineInfo corresponding to the fir...
Definition Text2D.hpp:271
Additional information about a single shaped glyph, including some data that is not strictly required...
Definition Text2D.hpp:230
size_t shapedLineIndex
Index of the ShapedLineInfo corresponding to the line that this glyph is part of.
Definition Text2D.hpp:233
size_t stringOffset
Byte offset in the input string of the first code unit that this glyph originated from.
Definition Text2D.hpp:234
vec2 shapedAdvance
Scaled offset to apply in order to advance to the next glyph position, including kerning.
Definition Text2D.hpp:232
vec2 shapedOffset
Scaled offset from the starting position to draw this glyph at, in pixels.
Definition Text2D.hpp:231
Data required to render a single shaped glyph relative to at any given starting position.
Definition Text2D.hpp:215
uint32_t characterSize
Character size that this glyph was shaped at.
Definition Text2D.hpp:219
char32_t codePoint
Unicode code point of this glyph.
Definition Text2D.hpp:220
Font2D * font
Non-owning read-only non-null pointer to the font used to shape this glyph.
Definition Text2D.hpp:216
vec2 shapedSize
Scaled size of this glyph's rectangle, in pixels.
Definition Text2D.hpp:218
vec2 shapedOffset
Scaled offset from the starting position to draw this glyph at, in pixels.
Definition Text2D.hpp:217
Information about a line of shaped glyphs, including some data that is not strictly required for simp...
Definition Text2D.hpp:244
vec2 shapedOffset
Scaled offset of the baseline at the start of this line of text.
Definition Text2D.hpp:245
size_t shapedGlyphOffset
Index of the ShapedGlyph and ShapedGlyphInfo corresponding to the first glyph that is part of this li...
Definition Text2D.hpp:249
float shapedAscender
Scaled total ascender of this line.
Definition Text2D.hpp:247
size_t stringOffset
Byte offset in the input string of the first code unit that the first glyph that is part of this line...
Definition Text2D.hpp:250
float shapedDescender
Scaled total descender of this line.
Definition Text2D.hpp:248
vec2 shapedSize
Scaled total size of this line.
Definition Text2D.hpp:246
Text alignment mode.
Definition Text2D.hpp:53
static const TextAlign CENTER_HORIZONTALLY_LAST_LINE_TOP
Align to the horizontal center of the bounding box on the last line's ascender.
Definition Text2D.hpp:65
static const TextAlign CENTER_HORIZONTALLY_BOTTOM
Align to the bottom center of the bounding box of the text.
Definition Text2D.hpp:70
static const TextAlign LEFT
Align to the left of the bounding box of the text.
Definition Text2D.hpp:74
TextAlignHorizontal horizontal
Horizontal alignment mode.
Definition Text2D.hpp:79
static const TextAlign NONE
No alignment.
Definition Text2D.hpp:54
static const TextAlign CENTER_VERTICALLY
Align to the vertical center of the bounding box of the text.
Definition Text2D.hpp:69
static const TextAlign RIGHT
Align to the right of the bounding box of the text.
Definition Text2D.hpp:75
static const TextAlign CENTER
Align to the center of the bounding box of the text.
Definition Text2D.hpp:67
static const TextAlign LAST_LINE_END_BASE
Align to the end of the last line's baseline.
Definition Text2D.hpp:62
static const TextAlign LAST_LINE_START_TOP
Align to the start of the last line's ascender.
Definition Text2D.hpp:59
static const TextAlign FIRST_LINE_START_TOP
Align to the start of the first line's ascender.
Definition Text2D.hpp:55
static const TextAlign TOP
Align to the top of the bounding box of the text.
Definition Text2D.hpp:77
static const TextAlign LAST_LINE_END_TOP
Align to the end of the last line's ascender.
Definition Text2D.hpp:61
static const TextAlign CENTER_VERTICALLY_RIGHT
Align to the right center of the bounding box of the text.
Definition Text2D.hpp:73
static const TextAlign FIRST_LINE_END_BASE
Align to the end of the first line's baseline.
Definition Text2D.hpp:58
static const TextAlign CENTER_HORIZONTALLY_LAST_LINE_BASE
Align to the horizontal center of the bounding box on the last line's baseline.
Definition Text2D.hpp:66
static const TextAlign CENTER_HORIZONTALLY
Align to the horizontal center of the bounding box of the text.
Definition Text2D.hpp:68
static const TextAlign LAST_LINE_START_BASE
Align to the start of the last line's baseline.
Definition Text2D.hpp:60
static const TextAlign CENTER_HORIZONTALLY_FIRST_LINE_BASE
Align to the horizontal center of the bounding box on the first line's baseline.
Definition Text2D.hpp:64
static const TextAlign BOTTOM
Align to the bottom of the bounding box of the text.
Definition Text2D.hpp:76
static const TextAlign CENTER_VERTICALLY_LEFT
Align to the left center of the bounding box of the text.
Definition Text2D.hpp:72
static const TextAlign CENTER_HORIZONTALLY_FIRST_LINE_TOP
Align to the horizontal center of the bounding box on the first line's ascender.
Definition Text2D.hpp:63
TextAlignVertical vertical
Vertical alignment mode.
Definition Text2D.hpp:80
static const TextAlign FIRST_LINE_START_BASE
Align to the start of the first line's baseline.
Definition Text2D.hpp:56
static const TextAlign FIRST_LINE_END_TOP
Align to the end of the first line's ascender.
Definition Text2D.hpp:57
static const TextAlign CENTER_HORIZONTALLY_TOP
Align to the top center of the bounding box of the text.
Definition Text2D.hpp:71