MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TypeFaceFoundry.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <ft2build.h>
4#include FT_FREETYPE_H
5
7
8class FontFace;
9class GlyphAtlas;
10
11/**
12 * @class TypeFaceFoundry
13 * @brief Singleton owner of the FT_Library handle.
14 *
15 * Initialised once by Portal::Text::initialize() and shut down by
16 * Portal::Text::shutdown(). All FontFace instances borrow the library
17 * handle via get_library(); they must not outlive this singleton.
18 */
19class MAYAFLUX_API TypeFaceFoundry {
20public:
22 {
23 static TypeFaceFoundry ctx;
24 return ctx;
25 }
26
31
32 /**
33 * @brief Initialise the FreeType library.
34 * @return true on success, false if FT_Init_FreeType fails.
35 */
36 bool initialize();
37
38 /**
39 * @brief Release the FreeType library handle.
40 */
41 void shutdown();
42
43 /**
44 * @brief Returns true after a successful initialize() call.
45 */
46 [[nodiscard]] bool is_initialized() const { return m_library != nullptr; }
47
48 /**
49 * @brief Raw FT_Library handle for use by FontFace.
50 * @pre is_initialized() must be true.
51 */
52 [[nodiscard]] FT_Library get_library() const { return m_library; }
53
54 /**
55 * @brief Locate a system font by family and style, then load it as the default.
56 *
57 * Delegates font path resolution to find_font, then calls the
58 * path-based overload. Returns false and logs if the family cannot be
59 * located on the current platform.
60 *
61 * @param family Font family name, e.g. "JetBrains Mono".
62 * @param style Style hint, e.g. "Medium", "Bold".
63 * @param pixel_size Glyph height in pixels.
64 * @param atlas_size Atlas texture dimension (power of two, default 512).
65 * @return true on success.
66 */
67 bool set_default_font(const std::string& path, uint32_t pixel_size, uint32_t atlas_size = 512);
68
69 /**
70 * @brief Return the default GlyphAtlas, or nullptr if set_default_font()
71 * has not been called successfully.
72 */
73 [[nodiscard]] GlyphAtlas* get_default_glyph_atlas() const { return m_default_atlas.get(); }
74
75private:
78
79 FT_Library m_library { nullptr };
80
81 std::unique_ptr<FontFace> m_default_face;
82 std::unique_ptr<GlyphAtlas> m_default_atlas;
83};
84
85} // namespace MayaFlux::Portal::Text
Rasterizes and packs glyphs from a FontFace into a TextureContainer.
GlyphAtlas * get_default_glyph_atlas() const
Return the default GlyphAtlas, or nullptr if set_default_font() has not been called successfully.
TypeFaceFoundry & operator=(TypeFaceFoundry &&)=delete
bool is_initialized() const
Returns true after a successful initialize() call.
std::unique_ptr< FontFace > m_default_face
std::unique_ptr< GlyphAtlas > m_default_atlas
TypeFaceFoundry(const TypeFaceFoundry &)=delete
TypeFaceFoundry & operator=(const TypeFaceFoundry &)=delete
TypeFaceFoundry(TypeFaceFoundry &&)=delete
FT_Library get_library() const
Raw FT_Library handle for use by FontFace.
Singleton owner of the FT_Library handle.
void initialize()
Definition main.cpp:11
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