HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
font_glyph_ids.hpp
1// Copyright Take Vos 2023.
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_id.hpp"
8#include "font_id.hpp"
9#include "font_metrics.hpp"
10#include "../container/container.hpp"
11#include "../macros.hpp"
12
13hi_export_module(hikogui.font : font_glyphs_ids);
14
15hi_export namespace hi { inline namespace v1 {
16
18 using container_type = lean_vector<glyph_id>;
19 using iterator = container_type::iterator;
20 using const_iterator = container_type::const_iterator;
21
22 hi::font_id font = {};
23 container_type glyphs = {};
24
25 font_glyph_ids(font_glyph_ids const&) noexcept = default;
26 font_glyph_ids(font_glyph_ids &&) noexcept = default;
27 font_glyph_ids& operator=(font_glyph_ids const&) noexcept = default;
28 font_glyph_ids& operator=(font_glyph_ids &&) noexcept = default;
29 constexpr font_glyph_ids() noexcept = default;
30 [[nodiscard]] friend bool operator==(font_glyph_ids const&, font_glyph_ids const&) noexcept = default;
31
33 font(font), glyphs(std::move(glyphs))
34 {
35 hi_axiom(not this->font.empty());
36 hi_axiom(not this->glyphs.empty());
37 for (auto glyph_id : this->glyphs) {
38 hi_axiom(not glyph_id.empty());
39 }
40 }
41
42 [[nodiscard]] constexpr bool empty() const noexcept
43 {
44 return font.empty();
45 }
46
47 constexpr explicit operator bool() const noexcept
48 {
49 return not empty();
50 }
51
52 [[nodiscard]] iterator begin() noexcept
53 {
54 return glyphs.begin();
55 }
56
57 [[nodiscard]] iterator end() noexcept
58 {
59 return glyphs.end();
60 }
61
62 [[nodiscard]] const_iterator begin() const noexcept
63 {
64 return glyphs.begin();
65 }
66
67 [[nodiscard]] const_iterator end() const noexcept
68 {
69 return glyphs.end();
70 }
71
72 [[nodiscard]] const_iterator cbegin() const noexcept
73 {
74 return glyphs.cbegin();
75 }
76
77 [[nodiscard]] const_iterator cend() const noexcept
78 {
79 return glyphs.cend();
80 }
81
82 [[nodiscard]] glyph_id front() const
83 {
84 hi_axiom(not glyphs.empty());
85 return glyphs.front();
86 }
87
88 [[nodiscard]] glyph_id back() const
89 {
90 hi_axiom(not glyphs.empty());
91 return glyphs.back();
92 }
93
94 [[nodiscard]] glyph_id operator[](size_t i) const
95 {
96 return glyphs[i];
97 }
98
99 [[nodiscard]] font_metrics_em const& font_metrics() const
100 {
101 hi_axiom(not font.empty());
102 return font->metrics;
103 }
104
105 [[nodiscard]] hi::glyph_metrics glyph_metrics(size_t i) const
106 {
107 hi_axiom(i < glyphs.size());
108 hi_axiom(not font.empty());
109 return font->get_metrics(glyphs[i]);
110 }
111
112 [[nodiscard]] hi::glyph_metrics front_glyph_metrics() const
113 {
114 return glyph_metrics(0);
115 }
116};
117
118
119}}
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22
Lean-vector with (SVO) short-vector-optimization.
Definition lean_vector.hpp:36
Definition font_glyph_ids.hpp:17
An identifier for a font-family that was registered with HikoGUI.
Definition font_id.hpp:23
The identifier of a glyph in a font-file.
Definition glyph_id.hpp:22
T move(T... args)