HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
font.hpp
1// Copyright Take Vos 2019-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 "glyph_metrics.hpp"
8#include "font_glyph_ids.hpp"
9#include "gstring.hpp"
10#include "unicode_mask.hpp"
11#include "font_weight.hpp"
12#include "font_variant.hpp"
13#include "../graphic_path.hpp"
14#include "../resource_view.hpp"
15#include "../exception.hpp"
16#include "../required.hpp"
17#include "../URL.hpp"
18#include <span>
19#include <vector>
20#include <map>
21
22namespace tt {
23
28class font {
29public:
33 std::string sub_family_name;
34
35 bool monospace = false;
36 bool serif = false;
37 bool italic = false;
38 bool condensed = false;
39 font_weight weight = font_weight::Regular;
40 float optical_size = 12.0;
41
43
44 float xHeight = 0.0;
45 float HHeight = 0.0;
46 float DigitWidth = 0.0;
47
51
52 font() = default;
53 virtual ~font() = default;
54 font(font const &) = delete;
55 font &operator=(font const &) = delete;
56 font(font &&) = delete;
57 font &operator=(font &&) = delete;
58
63 [[nodiscard]] virtual bool loaded() const noexcept = 0;
64
68 [[nodiscard]] virtual tt::glyph_id find_glyph(char32_t c) const noexcept = 0;
69
73 [[nodiscard]] font_glyph_ids find_glyph(grapheme g) const noexcept;
74
82 virtual std::optional<tt::glyph_id> load_glyph(tt::glyph_id glyph_id, graphic_path &path) const noexcept = 0;
83
92 virtual bool load_glyph_metrics(
94 glyph_metrics &metrics,
95 tt::glyph_id lookahead_glyph_id = tt::glyph_id{}) const noexcept = 0;
96
97 [[nodiscard]] font_variant font_variant() const noexcept
98 {
99 return {weight, italic};
100 }
101
102 [[nodiscard]] friend std::string to_string(font const &rhs) noexcept
103 {
104 return std::format(
105 "{} - {}: {}{}{}{}{} {} num-code-points={}",
106 rhs.family_name,
107 rhs.sub_family_name,
108 rhs.monospace ? 'M' : '_',
109 rhs.serif ? 'S' : '_',
110 rhs.italic ? 'I' : '_',
111 rhs.condensed ? 'C' : '_',
112 to_char(rhs.weight),
113 rhs.optical_size,
114 rhs.unicode_mask.size());
115 }
116};
117
118} // namespace tt
119
120namespace std {
121
122template<typename CharT>
123struct formatter<tt::font, CharT> : formatter<std::string_view, CharT> {
124 auto format(tt::font const &t, auto &fc)
125 {
126 return formatter<string_view, CharT>::format(to_string(t), fc);
127 }
128};
129
130} // namespace std
STL namespace.
A path is a vector graphics object.
Definition graphic_path.hpp:28
Definition tagged_id.hpp:18
Definition font.hpp:28
std::vector< tt::font * > fallback_chain
List of fonts to use as a fallback for this font.
Definition font.hpp:50
std::string family_name
The description is filled with information parsed from the font.
Definition font.hpp:32
virtual bool load_glyph_metrics(tt::glyph_id glyph_id, glyph_metrics &metrics, tt::glyph_id lookahead_glyph_id=tt::glyph_id{}) const noexcept=0
virtual tt::glyph_id find_glyph(char32_t c) const noexcept=0
Get the glyph for a code-point.
virtual std::optional< tt::glyph_id > load_glyph(tt::glyph_id glyph_id, graphic_path &path) const noexcept=0
virtual bool loaded() const noexcept=0
Return if the font is loaded.
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 glyph_metrics.hpp:17
Definition grapheme.hpp:21
A mask of unicode code-points.
Definition unicode_mask.hpp:101
T to_string(T... args)