MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
FontFace.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <ft2build.h>
4#include FT_FREETYPE_H
5
7
8/**
9 * @class FontFace
10 * @brief Owns a single FT_Face loaded from a file path.
11 *
12 * A FontFace is the source from which GlyphAtlas instances at specific
13 * pixel sizes are constructed. One FontFace may serve any number of
14 * atlases; the FT_Face handle is shared by reference and must not be
15 * used concurrently from multiple threads without external locking.
16 *
17 * The face index parameter handles font collections (.ttc, .otc); pass
18 * 0 for single-face files.
19 *
20 * FontFace does not call FT_Set_Pixel_Sizes -- that is GlyphAtlas's
21 * responsibility immediately before each rasterization call, ensuring
22 * the face is configured for the atlas's declared size.
23 */
24class MAYAFLUX_API FontFace {
25public:
26 FontFace() = default;
27 ~FontFace() { unload(); }
28
29 FontFace(const FontFace&) = delete;
30 FontFace& operator=(const FontFace&) = delete;
31 FontFace(FontFace&&) = delete;
33
34 /**
35 * @brief Load a font file from disk.
36 * @param path Absolute or relative path to a TTF, OTF, or collection file.
37 * @param index Face index within a collection; 0 for ordinary font files.
38 * @return true on success.
39 * @pre FreeTypeContext::instance().is_initialized() must be true.
40 */
41 bool load(const std::string& path, FT_Long index = 0);
42
43 /**
44 * @brief Release the FT_Face handle.
45 */
46 void unload();
47
48 /**
49 * @brief Returns true after a successful load() call.
50 */
51 [[nodiscard]] bool is_loaded() const { return m_face != nullptr; }
52
53 /**
54 * @brief Raw FT_Face handle for use by GlyphAtlas.
55 * @pre is_loaded() must be true.
56 */
57 [[nodiscard]] FT_Face get_face() const { return m_face; }
58
59 /**
60 * @brief Path passed to load(), empty if not yet loaded.
61 */
62 [[nodiscard]] const std::string& path() const { return m_path; }
63
64private:
65 FT_Face m_face { nullptr };
66 std::string m_path;
67};
68
69} // namespace MayaFlux::Portal::Text
const std::string & path() const
Path passed to load(), empty if not yet loaded.
Definition FontFace.hpp:62
FontFace & operator=(FontFace &&)=delete
FontFace(FontFace &&)=delete
FontFace & operator=(const FontFace &)=delete
FontFace(const FontFace &)=delete
FT_Face get_face() const
Raw FT_Face handle for use by GlyphAtlas.
Definition FontFace.hpp:57
bool is_loaded() const
Returns true after a successful load() call.
Definition FontFace.hpp:51
Owns a single FT_Face loaded from a file path.
Definition FontFace.hpp:24