HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
FontBook.hpp
1// Copyright 2019, 2020 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include "TTauri/Text/FontDescription.hpp"
7#include "TTauri/Text/Grapheme.hpp"
8#include "TTauri/Text/Font.hpp"
9#include "TTauri/Text/FontFamilyID.hpp"
10#include "TTauri/Text/FontID.hpp"
11#include "TTauri/Text/FontGraphemeID.hpp"
12#include "TTauri/Text/FontGlyphIDs.hpp"
13#include "TTauri/Foundation/URL.hpp"
14#include "TTauri/Foundation/attributes.hpp"
15#include <limits>
16#include <array>
17#include <new>
18
19
20namespace tt {
21
28class FontBook {
29 struct FontEntry {
30 URL url;
31 FontDescription description;
32 mutable std::unique_ptr<Font> font;
33 std::vector<FontID> fallbacks;
34
35 FontEntry(URL url, FontDescription description) noexcept : url(std::move(url)), description(std::move(description)), font(), fallbacks() {}
36 };
37
38
42
45 std::unordered_map<std::string,std::string> family_name_fallback_chain;
46
49 std::vector<std::array<FontID,FontVariant::max()>> font_variants;
50
51 std::vector<FontEntry> font_entries;
52
56 mutable std::unordered_map<std::string,FontFamilyID> family_name_cache;
57
62
63public:
64 FontBook(std::vector<URL> const &font_directories);
65
78
83 void post_process() noexcept;
84
85
89 [[nodiscard]] FontFamilyID find_family(std::string_view family_name) const noexcept;
90
94 [[nodiscard]] FontFamilyID register_family(std::string_view family_name) noexcept;
95
103 [[nodiscard]] FontID find_font(FontFamilyID family_id, FontVariant variant) const noexcept;
104
113 [[nodiscard]] FontID find_font(FontFamilyID family_id, FontWeight weight, bool italic) const noexcept;
114
123 [[nodiscard]] FontID find_font(std::string_view family_name, FontWeight weight, bool italic) const noexcept;
124
125 [[nodiscard]] Font const &get_font(FontID font_id) const noexcept;
126
135 [[nodiscard]] FontGlyphIDs find_glyph(FontID font_id, Grapheme grapheme) const noexcept;
136
137private:
138
139 void calculate_fallback_fonts(FontEntry &entry, std::function<bool(FontDescription const&,FontDescription const&)> predicate) noexcept;
140
144 [[nodiscard]] FontGlyphIDs find_glyph_actual(FontID font_id, Grapheme grapheme) const noexcept;
145
148 //void morph_glyphs(glyph_array &glyphs) const noexcept;
149
152 //void atlas_lookup(glyph &glyph) noexcept;
153
156 //void atlas_lookup(glyph_array &glyphs) noexcept;
157
158 //void kern_glyphs(glyph_array &glyphs) const noexcept;
159
163 [[nodiscard]] std::string const &find_fallback_family_name(std::string const &name) const noexcept;
164
165 void create_family_name_fallback_chain() noexcept;
166
167};
168
169inline FontBook *fontBook;
170
171}
STL namespace.
Definition URL.hpp:45
Definition Font.hpp:25
FontBook keeps track of multiple fonts.
Definition FontBook.hpp:28
FontFamilyID register_family(std::string_view family_name) noexcept
Register font family id.
FontGlyphIDs find_glyph(FontID font_id, Grapheme grapheme) const noexcept
Find a glyph using the given code-point.
FontID register_font(URL url, bool post_process=true)
Register a font.
FontID find_font(FontFamilyID family_id, FontVariant variant) const noexcept
Find a font closest to the variant.
void post_process() noexcept
Post process FontBook Should be called after a set of register_font() calls This calculates font fall...
FontFamilyID find_family(std::string_view family_name) const noexcept
Find font family id.
Definition FontDescription.hpp:15
Definition FontGlyphIDs.hpp:77
A font variant is one of 16 different fonts that can be part of a family.
Definition FontVariant.hpp:15
Definition Grapheme.hpp:20
T move(T... args)