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