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 "ttauri/text/font_description.hpp"
8#include "ttauri/text/grapheme.hpp"
9#include "ttauri/text/font.hpp"
10#include "ttauri/text/font_family_id.hpp"
11#include "ttauri/text/font_id.hpp"
12#include "ttauri/text/font_grapheme_id.hpp"
13#include "ttauri/text/font_glyph_ids.hpp"
14#include "ttauri/URL.hpp"
15#include "ttauri/alignment.hpp"
16#include <limits>
17#include <array>
18#include <new>
19
20
21namespace tt {
22
29class font_book {
30public:
31 static inline std::unique_ptr<font_book> global;
32
33 font_book(std::vector<URL> const &font_directories);
34
47
52 void post_process() noexcept;
53
57 [[nodiscard]] font_family_id find_family(std::string_view family_name) const noexcept;
58
62 [[nodiscard]] font_family_id register_family(std::string_view family_name) noexcept;
63
71 [[nodiscard]] font_id find_font(font_family_id family_id, font_variant variant) const noexcept;
72
81 [[nodiscard]] font_id find_font(font_family_id family_id, font_weight weight, bool italic) const noexcept;
82
91 [[nodiscard]] font_id find_font(std::string_view family_name, font_weight weight, bool italic) const noexcept;
92
93 [[nodiscard]] font const &get_font(font_id font_id) const noexcept;
94
104
105private:
106 struct fontEntry {
107 URL url;
108 font_description description;
110 std::vector<font_id> fallbacks;
111
112 fontEntry(URL url, font_description description) noexcept :
113 url(std::move(url)), description(std::move(description)), font(), fallbacks()
114 {
115 }
116 };
117
121
124 std::unordered_map<std::string, std::string> family_name_fallback_chain;
125
128 std::vector<std::array<font_id, font_variant::max()>> font_variants;
129
130 std::vector<fontEntry> font_entries;
131
135 mutable std::unordered_map<std::string, font_family_id> family_name_cache;
136
141 void calculate_fallback_fonts(fontEntry &entry, std::function<bool(font_description const&,font_description const&)> predicate) noexcept;
142
146 [[nodiscard]] font_glyph_ids find_glyph_actual(font_id font_id, grapheme grapheme) const noexcept;
147
150 //void morph_glyphs(glyph_array &glyphs) const noexcept;
151
154 //void atlas_lookup(glyph &glyph) noexcept;
155
158 //void atlas_lookup(glyph_array &glyphs) noexcept;
159
160 //void kern_glyphs(glyph_array &glyphs) const noexcept;
161
165 [[nodiscard]] std::string const &find_fallback_family_name(std::string const &name) const noexcept;
166
167 void create_family_name_fallback_chain() noexcept;
168};
169
170}
STL namespace.
Definition font.hpp:26
font_book keeps track of multiple fonts.
Definition font_book.hpp:29
font_glyph_ids find_glyph(font_id font_id, grapheme grapheme) const noexcept
Find a glyph using the given code-point.
font_family_id find_family(std::string_view family_name) const noexcept
Find font family id.
font_id find_font(font_family_id family_id, font_variant variant) const noexcept
Find a font closest to the variant.
font_family_id register_family(std::string_view family_name) noexcept
Register font family id.
void post_process() noexcept
Post process font_book Should be called after a set of register_font() calls This calculates font fal...
font_id register_font(URL url, bool post_process=true)
Register a font.
Definition font_description.hpp:16
Definition font_glyph_ids.hpp:78
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:46
T move(T... args)