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 "font.hpp"
8#include "font_family_id.hpp"
9#include "font_grapheme_id.hpp"
10#include "glyph_ids.hpp"
11#include "elusive_icon.hpp"
12#include "hikogui_icon.hpp"
13#include "../unicode/grapheme.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 hi::inline v1 {
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_hikogui_icon_font(URL url)
53 {
54 _hikogui_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]] glyph_ids find_glyph(font const &font, grapheme grapheme) const noexcept;
111
112 [[nodiscard]] glyph_ids find_glyph(elusive_icon rhs) const noexcept
113 {
114 hi_axiom(_elusive_icon_font);
115 return _elusive_icon_font->find_glyph(grapheme{static_cast<char32_t>(rhs)});
116 }
117
118 [[nodiscard]] glyph_ids find_glyph(hikogui_icon rhs) const noexcept
119 {
120 hi_axiom(_hikogui_icon_font);
121 return _hikogui_icon_font->find_glyph(grapheme{static_cast<char32_t>(rhs)});
122 }
123
124private:
125 font const *_elusive_icon_font = nullptr;
126 font const *_hikogui_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<hi::font *> _font_ptrs;
142
146 mutable std::unordered_map<std::string, font_family_id> family_name_cache;
147
152
153 [[nodiscard]] std::vector<hi::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 hi::inline v1
STL namespace.
Definition font.hpp:34
font_book keeps track of multiple fonts.
Definition font_book.hpp:30
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...
A font variant is one of 16 different fonts that can be part of a family.
Definition font_variant.hpp:16
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:41
Definition URL.hpp:47