HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
font_book.hpp
1// Copyright Take Vos 2020-2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "grapheme.hpp"
8#include "font.hpp"
9#include "font_family_id.hpp"
10#include "font_grapheme_id.hpp"
11#include "font_glyph_ids.hpp"
12#include "elusive_icon.hpp"
13#include "ttauri_icon.hpp"
14#include "../URL.hpp"
15#include "../alignment.hpp"
16#include "../subsystem.hpp"
17#include <limits>
18#include <array>
19#include <new>
20#include <atomic>
21
22namespace tt {
23
30class font_book {
31public:
32 font_book(std::vector<URL> const &font_directories);
33
45 font &register_font(URL url, bool post_process = true);
46
47 void register_elusive_icon_font(URL url)
48 {
49 _elusive_icon_font = &register_font(url, false);
50 }
51
52 void register_ttauri_icon_font(URL url)
53 {
54 _ttauri_icon_font = &register_font(url, false);
55 }
56
61 void post_process() noexcept;
62
66 [[nodiscard]] font_family_id find_family(std::string_view family_name) const noexcept;
67
71 [[nodiscard]] font_family_id register_family(std::string_view family_name) noexcept;
72
80 [[nodiscard]] font const &find_font(font_family_id family_id, font_variant variant) const noexcept;
81
90 [[nodiscard]] font const &find_font(font_family_id family_id, font_weight weight, bool italic) const noexcept;
91
100 [[nodiscard]] font const &find_font(std::string_view family_name, font_weight weight, bool italic) const noexcept;
101
110 [[nodiscard]] font_glyph_ids find_glyph(font const &font, grapheme grapheme) const noexcept;
111
112 [[nodiscard]] font_glyph_ids find_glyph(elusive_icon rhs) const noexcept
113 {
114 tt_axiom(_elusive_icon_font);
115 return _elusive_icon_font->find_glyph(grapheme{static_cast<char32_t>(rhs)});
116 }
117
118 [[nodiscard]] font_glyph_ids find_glyph(ttauri_icon rhs) const noexcept
119 {
120 tt_axiom(_ttauri_icon_font);
121 return _ttauri_icon_font->find_glyph(grapheme{static_cast<char32_t>(rhs)});
122 }
123
124private:
125 font const *_elusive_icon_font = nullptr;
126 font const *_ttauri_icon_font = nullptr;
127
131
134 std::unordered_map<std::string, std::string> family_name_fallback_chain;
135
138 std::vector<std::array<font const *, font_variant::max()>> font_variants;
139
141 std::vector<tt::font *> _font_ptrs;
142
146 mutable std::unordered_map<std::string, font_family_id> family_name_cache;
147
152
153 [[nodiscard]] std::vector<tt::font *> make_fallback_chain(font_weight weight, bool italic) noexcept;
154
157 // void morph_glyphs(glyph_array &glyphs) const noexcept;
158
161 // void atlas_lookup(glyph &glyph) noexcept;
162
165 // void atlas_lookup(glyph_array &glyphs) noexcept;
166
167 // void kern_glyphs(glyph_array &glyphs) const noexcept;
168
172 [[nodiscard]] std::string const &find_fallback_family_name(std::string const &name) const noexcept;
173
174 void create_family_name_fallback_chain() noexcept;
175};
176
177} // namespace tt
STL namespace.
Definition font.hpp:28
virtual tt::glyph_id find_glyph(char32_t c) const noexcept=0
Get the glyph for a code-point.
font_book keeps track of multiple fonts.
Definition font_book.hpp:30
font const & find_font(font_family_id family_id, font_variant variant) const noexcept
Find a font closest to the variant.
font_family_id find_family(std::string_view family_name) const noexcept
Find font family id.
font_glyph_ids find_glyph(font const &font, grapheme grapheme) const noexcept
Find a glyph using the given code-point.
font_family_id register_family(std::string_view family_name) noexcept
Register font family id.
font & register_font(URL url, bool post_process=true)
Register a font.
void post_process() noexcept
Post process font_book Should be called after a set of register_font() calls This calculates font fal...
Definition font_glyph_ids.hpp:80
A font variant is one of 16 different fonts that can be part of a family.
Definition font_variant.hpp:16
Definition grapheme.hpp:21
Definition URL.hpp:47