MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TypeSetter.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "GlyphAtlas.hpp"
4
6
7/**
8 * @struct GlyphQuad
9 * @brief Screen-space quad for one rasterized glyph.
10 *
11 * All coordinates are in pixels relative to the pen origin passed to
12 * lay_out(). The caller is responsible for converting to NDC or whatever
13 * coordinate system the render path expects.
14 *
15 * UV coordinates are in normalised [0, 1] atlas space, matching the values
16 * stored in GlyphMetrics.
17 */
18struct GlyphQuad {
19 float x0, y0; ///< Top-left pixel position.
20 float x1, y1; ///< Bottom-right pixel position.
21 float uv_x0, uv_y0; ///< Top-left UV in atlas space.
22 float uv_x1, uv_y1; ///< Bottom-right UV in atlas space.
23 uint32_t codepoint { 0 }; ///< Unicode codepoint that produced this quad.
24};
25
26/**
27 * @brief Result of lay_out(), carrying the quads and the final pen position.
28 *
29 * final_pen_x and final_pen_y are the pen coordinates immediately after the
30 * last codepoint was processed. impress() uses these directly to update the
31 * TextBuffer cursor, avoiding re-deriving the position from quad geometry
32 * (which is incorrect after a newline resets pen_x mid-run).
33 */
35 std::vector<GlyphQuad> quads;
36 float final_pen_x { 0.F };
37 float final_pen_y { 0.F };
38};
39
40/**
41 * @brief Lay out a UTF-8 string into a sequence of screen-space quads.
42 *
43 * Handles \n (advance pen_y by atlas.line_height(), reset pen_x to the
44 * initial value) and \r (consumed silently). All other control codepoints
45 * with no glyph in the face are skipped without advancing the pen.
46 *
47 * Bidirectional reordering and shaping are not performed. HarfBuzz slots in
48 * before the glyph index step when needed; the quad assembly loop and
49 * GlyphAtlas remain unchanged.
50 *
51 * @param text UTF-8 encoded input string.
52 * @param atlas GlyphAtlas to query and populate. May be modified (dirty flag
53 * set) if new glyphs are rasterized.
54 * @param pen_x Starting horizontal pen position in pixels.
55 * @param pen_y Starting vertical pen position in pixels (baseline).
56 * @return LayoutResult containing quads and final pen position.
57 */
58[[nodiscard]] LayoutResult lay_out(
59 std::string_view text,
60 GlyphAtlas& atlas,
61 float pen_x = 0.F,
62 float pen_y = 0.F,
63 uint32_t wrap_w = 0);
64
65} // namespace MayaFlux::Portal::Text
LayoutResult lay_out(std::string_view text, GlyphAtlas &atlas, float pen_x, float pen_y, uint32_t wrap_w)
Lay out a UTF-8 string into a sequence of screen-space quads.
Definition TypeSetter.cpp:9
float y0
Top-left pixel position.
float uv_y1
Bottom-right UV in atlas space.
float uv_y0
Top-left UV in atlas space.
float y1
Bottom-right pixel position.
uint32_t codepoint
Unicode codepoint that produced this quad.
Screen-space quad for one rasterized glyph.
std::vector< GlyphQuad > quads
Result of lay_out(), carrying the quads and the final pen position.