MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
FontFace.cpp
Go to the documentation of this file.
1#include "FontFace.hpp"
2
4#include "TypeFaceFoundry.hpp"
5
7
8bool FontFace::load(const std::string& path, FT_Long index)
9{
10 unload();
11
12 auto& ctx = TypeFaceFoundry::instance();
13 if (!ctx.is_initialized()) {
15 "FontFace::load called before TypeFaceFoundry is initialized");
16 return false;
17 }
18
19 if (const FT_Error err = FT_New_Face(ctx.get_library(), path.c_str(), index, &m_face);
20 err != 0) {
22 "FT_New_Face failed for '{}' (index {}) with error {}",
23 path, index, static_cast<int>(err));
24 m_face = nullptr;
25 return false;
26 }
27
28 m_path = path;
29
31 "FontFace loaded: '{}' ({} glyphs)", path, m_face->num_glyphs);
32 return true;
33}
34
36{
37 if (!m_face) {
38 return;
39 }
40
41 FT_Done_Face(m_face);
42 m_face = nullptr;
43 m_path.clear();
44}
45
46} // namespace MayaFlux::Portal::Text
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
const std::string & path() const
Path passed to load(), empty if not yet loaded.
Definition FontFace.hpp:64
bool load(const std::string &path, FT_Long index=0)
Load a font file from disk.
Definition FontFace.cpp:8
void unload()
Release the FT_Face handle.
Definition FontFace.cpp:35
@ API
API calls from external code.
@ Portal
High-level user-facing API layer.