HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
font_book.hpp
1// Copyright Take Vos 2020-2022.
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 "../alignment.hpp"
15#include "../subsystem.hpp"
16#include "../generator.hpp"
17#include <limits>
18#include <array>
19#include <new>
20#include <atomic>
21#include <filesystem>
22
23namespace hi::inline v1 {
24
31class font_book {
32public:
33 font_book(std::vector<std::filesystem::path> const &font_directories);
34
46 font &register_font(std::filesystem::path const &path, bool post_process = true);
47
48 void register_elusive_icon_font(std::filesystem::path const& path)
49 {
50 _elusive_icon_font = &register_font(path, false);
51 }
52
53 void register_hikogui_icon_font(std::filesystem::path const& path)
54 {
55 _hikogui_icon_font = &register_font(path, false);
56 }
57
62 void post_process() noexcept;
63
67 [[nodiscard]] font_family_id find_family(std::string_view family_name) const noexcept;
68
72 [[nodiscard]] font_family_id register_family(std::string_view family_name) noexcept;
73
81 [[nodiscard]] font const &find_font(font_family_id family_id, font_variant variant) const noexcept;
82
91 [[nodiscard]] font const &find_font(font_family_id family_id, font_weight weight, bool italic) const noexcept;
92
101 [[nodiscard]] font const &find_font(std::string_view family_name, font_weight weight, bool italic) const noexcept;
102
111 [[nodiscard]] glyph_ids find_glyph(font const &font, grapheme grapheme) const noexcept;
112
113 [[nodiscard]] glyph_ids find_glyph(elusive_icon rhs) const noexcept
114 {
115 hi_axiom(_elusive_icon_font);
116 return _elusive_icon_font->find_glyph(grapheme{static_cast<char32_t>(rhs)});
117 }
118
119 [[nodiscard]] glyph_ids find_glyph(hikogui_icon rhs) const noexcept
120 {
121 hi_axiom(_hikogui_icon_font);
122 return _hikogui_icon_font->find_glyph(grapheme{static_cast<char32_t>(rhs)});
123 }
124
125private:
126 font const *_elusive_icon_font = nullptr;
127 font const *_hikogui_icon_font = nullptr;
128
132
135 std::unordered_map<std::string, std::string> _family_name_fallback_chain;
136
139 std::vector<std::array<font const *, font_variant::max()>> _font_variants;
140
142 std::vector<hi::font *> _font_ptrs;
143
147 mutable std::unordered_map<std::string, font_family_id> _family_name_cache;
148
153
154 [[nodiscard]] std::vector<hi::font *> make_fallback_chain(font_weight weight, bool italic) noexcept;
155
158 // void morph_glyphs(glyph_array &glyphs) const noexcept;
159
162 // void atlas_lookup(glyph &glyph) noexcept;
163
166 // void atlas_lookup(glyph_array &glyphs) noexcept;
167
168 // void kern_glyphs(glyph_array &glyphs) const noexcept;
169
172 [[nodiscard]] generator<std::string> generate_family_names(std::string_view name) const noexcept;
173
174 void create_family_name_fallback_chain() noexcept;
175};
176
177} // namespace hi::inline v1
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
font_weight
Definition font_weight.hpp:17
Definition font.hpp:32
font_book keeps track of multiple fonts.
Definition font_book.hpp:31
void post_process() noexcept
Post process font_book Should be called after a set of register_font() calls This calculates font fal...
font & register_font(std::filesystem::path const &path, bool post_process=true)
Register a font.
A font variant is one of 16 different fonts that can be part of a family.
Definition font_variant.hpp:16
A set of glyph-ids of a font which composites into a single glyph.
Definition glyph_ids.hpp:135
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:41