MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TypeFaceFoundry.cpp
Go to the documentation of this file.
1#include "TypeFaceFoundry.hpp"
2
5
7
9
11
13
15{
16 if (m_library) {
18 "TypeFaceFoundry already initialized");
19 return true;
20 }
21
22 if (const FT_Error err = FT_Init_FreeType(&m_library); err != 0) {
24 "FT_Init_FreeType failed with error {}", static_cast<int>(err));
25 m_library = nullptr;
26 return false;
27 }
28
30 "TypeFaceFoundry initialized");
31 return true;
32}
33
34bool TypeFaceFoundry::set_default_font(const std::string& font_path, uint32_t pixel_size, uint32_t atlas_size)
35{
36 auto face = std::make_unique<FontFace>();
37 if (!face->load(font_path)) {
39 "set_default_font: failed to load '{}'", font_path);
40 return false;
41 }
42
43 auto atlas = std::make_unique<GlyphAtlas>(*face, pixel_size, atlas_size);
44
45 m_default_atlas = std::move(atlas);
46 m_default_face = std::move(face);
47
49 "Default font set: '{}' {}px atlas {}px", font_path, pixel_size, atlas_size);
50 return true;
51}
52
54{
55 if (!m_library) {
56 return;
57 }
58
59 if (m_default_face) {
60 m_default_face->unload();
61 }
62
63 FT_Done_FreeType(m_library);
64 m_library = nullptr;
65
67 "TypeFaceFoundry shutdown");
68}
69
70} // namespace MayaFlux::Portal::Text
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
bool set_default_font(const std::string &path, uint32_t pixel_size, uint32_t atlas_size=512)
Locate a system font by family and style, then load it as the default.
std::unique_ptr< FontFace > m_default_face
std::unique_ptr< GlyphAtlas > m_default_atlas
void shutdown()
Release the FreeType library handle.
bool initialize()
Initialise the FreeType library.
@ API
API calls from external code.
@ Portal
High-level user-facing API layer.