MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Text.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Core {
6struct TextConfig;
7}
8
10
11class GlyphAtlas;
12
13/**
14 * @brief Initialize Portal::Text.
15 *
16 * Initialises TypeFaceFoundry. Must be called before constructing any
17 * FontFace or GlyphAtlas. Safe to call after Portal::Graphics::initialize().
18 *
19 * @return true on success.
20 */
21MAYAFLUX_API bool initialize(std::optional<Core::TextConfig> config);
22
23/**
24 * @brief Shutdown Portal::Text.
25 *
26 * Releases the FreeType library handle and destroys the default atlas if
27 * one was set. All FontFace and GlyphAtlas instances must be destroyed
28 * before calling this.
29 */
30MAYAFLUX_API void shutdown();
31
32/**
33 * @brief Returns true after a successful initialize() call.
34 */
35MAYAFLUX_API bool is_initialized();
36
37/**
38 * @brief Load a font file and create the default GlyphAtlas at a given size.
39 *
40 * Replaces any previously set default font. Must be called after
41 * initialize().
42 *
43 * @param font_path Path to a TTF or OTF file.
44 * @param pixel_size Glyph height in pixels.
45 * @param atlas_size Atlas texture dimension (power of two, default 512).
46 * @return true on success.
47 */
48MAYAFLUX_API bool set_default_font(
49 const std::string& font_path,
50 uint32_t pixel_size = 24,
51 uint32_t atlas_size = 512);
52
53/**
54 * @brief Locate a system font by family and style, then load it as the default.
55 *
56 * Delegates font path resolution to find_font, then calls the
57 * path-based overload. Returns false and logs if the family cannot be
58 * located on the current platform.
59 *
60 * @param family Font family name, e.g. "JetBrains Mono".
61 * @param style Style hint, e.g. "Medium", "Bold".
62 * @param pixel_size Glyph height in pixels.
63 * @param atlas_size Atlas texture dimension (power of two, default 512).
64 * @return true on success.
65 */
66MAYAFLUX_API bool set_default_font(
67 std::string_view family,
68 std::string_view style,
69 uint32_t pixel_size,
70 uint32_t atlas_size = 512);
71
72/**
73 * @brief Lay out a UTF-8 string into screen-space glyph quads using the default atlas.
74 *
75 * Each quad in the returned LayoutResult carries pixel-space position, atlas
76 * UV coordinates, and the Unicode codepoint that produced it. The caller may
77 * mutate the quads freely before passing them to rasterize_quads().
78 *
79 * @param text UTF-8 encoded input string.
80 * @param pen_x Starting horizontal pen position in pixels.
81 * @param pen_y Starting vertical pen position in pixels (baseline).
82 * @param wrap_w Wrap boundary in pixels. Zero disables wrapping.
83 * @return LayoutResult containing quads and final pen position.
84 * @pre set_default_font() must have been called successfully.
85 */
86[[nodiscard]] MAYAFLUX_API std::shared_ptr<LayoutResult> create_layout(
87 std::string_view text,
88 float pen_x = 0.F,
89 float pen_y = 0.F,
90 uint32_t wrap_w = 0);
91
92/**
93 * @brief Return the default GlyphAtlas, or nullptr if set_default_font()
94 * has not been called successfully.
95 */
96MAYAFLUX_API GlyphAtlas& get_default_atlas();
97
98} // namespace MayaFlux::Portal::Text
void initialize()
Definition main.cpp:11
bool is_initialized()
Returns true after a successful initialize() call.
Definition Text.cpp:77
bool set_default_font(std::string_view family, std::string_view style, uint32_t pixel_size, uint32_t atlas_size)
Locate a system font by family and style, then load it as the default.
Definition Text.cpp:82
void shutdown()
Shutdown Portal::Text.
Definition Text.cpp:61
std::shared_ptr< LayoutResult > create_layout(std::string_view text, float pen_x, float pen_y, uint32_t wrap_w)
Lay out a UTF-8 string into screen-space glyph quads using the default atlas.
Definition Text.cpp:52
GlyphAtlas & get_default_atlas()
Return the default GlyphAtlas, or nullptr if set_default_font() has not been called successfully.
Definition Text.cpp:105