|
MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
|
| MAYAFLUX_API LayoutResult MayaFlux::Portal::Text::lay_out | ( | std::string_view | text, |
| GlyphAtlas & | atlas, | ||
| float | pen_x = 0.F, |
||
| float | pen_y = 0.F, |
||
| uint32_t | wrap_w = 0, |
||
| uint32_t | tab_width = 4 |
||
| ) |
Lay out a UTF-8 string into a sequence of screen-space quads.
Every codepoint this text needs is rasterized (cached, if not already) before any quad is emitted, so a GlyphAtlas growth triggered partway through this text cannot invalidate the UV coordinates already baked into quads emitted earlier in the same call. This guarantee is per-call only: a LayoutResult held across later, unrelated lay_out() calls on the same atlas is not protected if the atlas grows afterward from something else.
Every codepoint for which is_control() is true is never rasterized or counted as printable content. Among those, \t advances pen_x to the next tab stop and
advances pen_y by atlas.line_height() and resets pen_x; every other control codepoint (including \r) is skipped with no side effect. This is the same is_control() identification raw-string text handling uses; only the reaction to it differs here.
Consecutive non-control glyphs are kerned via FT_Get_Kerning() when the producing face (GlyphMetrics::face) has a kerning table. The previous glyph index resets to none across any control codepoint, across a wrap-induced line break, and whenever the producing face changes between consecutive glyphs: a glyph index is only meaningful within the face that assigned it, so a codepoint resolved through GlyphAtlas's fallback chain never gets kerned against a glyph from a different face.
Wrapping at wrap_w is a pure render-bounds guarantee, not word-aware line breaking: it breaks mid-word freely, with no whitespace lookback. This is deliberate - correctness here means no glyph ever renders past wrap_w, not that words stay intact. Each glyph is checked before it is placed, against its own advance width times a 1.5x margin, so the decision to wrap accounts for the glyph about to be drawn rather than reacting one glyph late to cumulative pen_x history - the margin absorbs the gap between a glyph's advance and its true rendered width so a glyph is never placed half past the boundary. A tab is checked the same way against its own tab-stop advance (no margin, since it draws nothing itself) immediately after computing its destination, not deferred to the next glyph's turn.
Bidirectional reordering and shaping are not performed. HarfBuzz slots in before the glyph index step when needed; the quad assembly loop and GlyphAtlas remain unchanged.
Each quad's byte_offset is the position of its codepoint's first byte in text, letting a caller correlate a quad back to source text (styling, hit-testing, extraction) without re-decoding UTF-8 itself.
| text | UTF-8 encoded input string. |
| atlas | GlyphAtlas to query and populate. May be modified (dirty flag set) if new glyphs are rasterized. |
| pen_x | Starting horizontal pen position in pixels. |
| pen_y | Starting vertical pen position in pixels (baseline). |
| wrap_w | Column to wrap at in pixels, or 0 to disable wrapping. |
| tab_width | Tab stop width in space-glyph-widths. |
Definition at line 22 of file TypeSetter.cpp.
References MayaFlux::Portal::Text::GlyphMetrics::advance_x, MayaFlux::Journal::API, MayaFlux::Portal::Text::GlyphMetrics::bearing_x, MayaFlux::Portal::Text::GlyphMetrics::bearing_y, MayaFlux::Portal::Text::GlyphMetrics::face, MayaFlux::Portal::Text::FontFace::get_face(), MayaFlux::Portal::Text::GlyphAtlas::get_or_rasterize(), MayaFlux::Portal::Text::GlyphMetrics::glyph_index, MayaFlux::Portal::Text::GlyphMetrics::height, is_control(), MayaFlux::Portal::Text::GlyphAtlas::line_height(), MF_WARN, offset, out, MayaFlux::Journal::Portal, q, MayaFlux::Portal::Text::LayoutResult::quads, MayaFlux::Portal::Text::GlyphMetrics::uv_x0, MayaFlux::Portal::Text::GlyphMetrics::uv_x1, MayaFlux::Portal::Text::GlyphMetrics::uv_y0, MayaFlux::Portal::Text::GlyphMetrics::uv_y1, MayaFlux::Portal::Text::GlyphMetrics::width, and MayaFlux::Portal::Text::GlyphQuad::x0.
Referenced by create_layout(), impress(), MayaFlux::Portal::Text::TextRun::lay_out_text(), and x_at().
Here is the call graph for this function:
Here is the caller graph for this function: