HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
text_shaper_char.hpp
1// Copyright Take Vos 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 "text_style.hpp"
8#include "glyph_ids.hpp"
9#include "glyph_metrics.hpp"
10#include "font.hpp"
11#include "../unicode/unicode_description.hpp"
12#include "../unicode/grapheme.hpp"
13#include "../geometry/point.hpp"
14#include "../geometry/axis_aligned_rectangle.hpp"
15
16namespace hi::inline v1 {
17class font_book;
18
20public:
23 hi::grapheme grapheme;
24
27 hi::text_style style;
28
31 float dpi_scale = 1.0f;
32
43 hi::glyph_ids glyph;
44
49 hi::glyph_metrics metrics;
50
53 size_t line_nr;
54
57 size_t column_nr;
58
66
88
92
97 unicode_bidi_class direction;
98
105 unicode_script script;
106
109 float scale = 1.0f;
110
116 float width = 0.0f;
117
120 bool is_trailing_white_space = false;
121
128 bool glyph_is_initial = false;
129
130 [[nodiscard]] text_shaper_char(hi::grapheme const &grapheme, text_style const &style, float dpi_scale) noexcept;
131
137 void initialize_glyph(hi::font_book &font_book, hi::font const &font) noexcept;
138
144 void initialize_glyph(hi::font_book &font_book) noexcept;
145
154 void replace_glyph(char32_t code_point) noexcept;
155
158 [[nodiscard]] hi::font_metrics font_metrics() const noexcept
159 {
160 return scale * glyph.font().metrics;
161 }
162
163 [[nodiscard]] vector2 get_kerning(text_shaper_char const &next) const noexcept
164 {
165 if (&(glyph.font()) != &(next.glyph.font()) or scale != next.scale or not glyph.has_num_glyphs<1>() or
166 not next.glyph.has_num_glyphs<1>()) {
167 return vector2{};
168 } else {
169 hilet kerning = glyph.font().get_kerning(glyph.get_single(), next.glyph.get_single());
170 return scale * kerning;
171 }
172 }
173
174 [[nodiscard]] friend bool operator==(text_shaper_char const &lhs, char32_t const &rhs) noexcept
175 {
176 return lhs.grapheme == rhs;
177 }
178
179 [[nodiscard]] friend bool operator==(text_shaper_char const &lhs, char const &rhs) noexcept
180 {
181 return lhs.grapheme == rhs;
182 }
183
184private:
187 void set_glyph(hi::glyph_ids &&new_glyph) noexcept;
188};
189
190} // namespace hi::inline v1
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Definition font.hpp:34
font_book keeps track of multiple fonts.
Definition font_book.hpp:30
Definition text_shaper_char.hpp:19
size_t line_nr
The line number where this character is located, counting from top to bottom line.
Definition text_shaper_char.hpp:53
void initialize_glyph(hi::font_book &font_book) noexcept
Initialize the glyph based on the grapheme.
unicode_bidi_class direction
The text direction for this glyph.
Definition text_shaper_char.hpp:97
hi::font_metrics font_metrics() const noexcept
Get the scaled font metrics for this character.
Definition text_shaper_char.hpp:158
void initialize_glyph(hi::font_book &font_book, hi::font const &font) noexcept
Initialize the glyph based on the grapheme.
unicode_script script
The script of this character.
Definition text_shaper_char.hpp:105
hi::grapheme grapheme
The grapheme.
Definition text_shaper_char.hpp:23
hi::glyph_ids glyph
The glyph representing one or more graphemes.
Definition text_shaper_char.hpp:43
point2 position
Position of the character.
Definition text_shaper_char.hpp:65
hi::glyph_metrics metrics
The glyph metrics of the currently glyph.
Definition text_shaper_char.hpp:49
size_t column_nr
The column number where the character is located on the line, counting from left to right in display ...
Definition text_shaper_char.hpp:57
unicode_description const * description
The unicode description of the grapheme.
Definition text_shaper_char.hpp:91
aarectangle rectangle
The rectangle for this character.
Definition text_shaper_char.hpp:87
hi::text_style style
The style of how to display the grapheme.
Definition text_shaper_char.hpp:27
void replace_glyph(char32_t code_point) noexcept
Called by the bidi-algorithm to mirror glyphs.
Definition text_style.hpp:175
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:41
Description of a unicode code point.
Definition unicode_description.hpp:33
T next(T... args)