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 "../font/module.hpp"
9#include "../unicode/unicode_description.hpp"
10#include "../unicode/grapheme.hpp"
11#include "../geometry/module.hpp"
12
13namespace hi::inline v1 {
14class font_book;
15
17public:
20 hi::grapheme grapheme;
21
24 hi::text_style style;
25
28 float dpi_scale = 1.0f;
29
40 hi::glyph_ids glyph;
41
46 hi::glyph_metrics metrics;
47
50 size_t line_nr;
51
54 size_t column_nr;
55
63
84 aarectangle rectangle;
85
89
95
102 unicode_script script;
103
106 float scale = 1.0f;
107
113 float width = 0.0f;
114
117 bool is_trailing_white_space = false;
118
125 bool glyph_is_initial = false;
126
127 [[nodiscard]] text_shaper_char(hi::grapheme const &grapheme, text_style const &style, float dpi_scale) noexcept;
128
134 void initialize_glyph(hi::font_book const &font_book, hi::font const &font) noexcept;
135
141 void initialize_glyph(hi::font_book &font_book) noexcept;
142
151 void replace_glyph(char32_t code_point) noexcept;
152
155 [[nodiscard]] hi::font_metrics font_metrics() const noexcept
156 {
157 return scale * glyph.font().metrics;
158 }
159
160 [[nodiscard]] vector2 get_kerning(text_shaper_char const &next) const noexcept
161 {
162 if (&(glyph.font()) != &(next.glyph.font()) or scale != next.scale or not glyph.has_num_glyphs<1>() or
163 not next.glyph.has_num_glyphs<1>()) {
164 return vector2{};
165 } else {
166 hilet kerning = glyph.font().get_kerning(glyph.get_single(), next.glyph.get_single());
167 return scale * kerning;
168 }
169 }
170
171 [[nodiscard]] friend bool operator==(text_shaper_char const &lhs, char32_t const &rhs) noexcept
172 {
173 return lhs.grapheme == rhs;
174 }
175
176 [[nodiscard]] friend bool operator==(text_shaper_char const &lhs, char const &rhs) noexcept
177 {
178 return lhs.grapheme == rhs;
179 }
180
181private:
184 void set_glyph(hi::glyph_ids &&new_glyph) noexcept;
185};
186
187} // namespace hi::inline v1
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
unicode_bidi_class
Bidirectional class Unicode Standard Annex #9: https://unicode.org/reports/tr9/.
Definition unicode_bidi_class.hpp:16
Definition font.hpp:31
font_book keeps track of multiple fonts.
Definition font_book.hpp:31
Definition text_shaper_char.hpp:16
size_t line_nr
The line number where this character is located, counting from top to bottom line.
Definition text_shaper_char.hpp:50
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:94
hi::font_metrics font_metrics() const noexcept
Get the scaled font metrics for this character.
Definition text_shaper_char.hpp:155
unicode_script script
The script of this character.
Definition text_shaper_char.hpp:102
hi::grapheme grapheme
The grapheme.
Definition text_shaper_char.hpp:20
hi::glyph_ids glyph
The glyph representing one or more graphemes.
Definition text_shaper_char.hpp:40
point2 position
Position of the character.
Definition text_shaper_char.hpp:62
hi::glyph_metrics metrics
The glyph metrics of the currently glyph.
Definition text_shaper_char.hpp:46
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:54
unicode_description const * description
The unicode description of the grapheme.
Definition text_shaper_char.hpp:88
aarectangle rectangle
The rectangle for this character.
Definition text_shaper_char.hpp:84
void initialize_glyph(hi::font_book const &font_book, hi::font const &font) noexcept
Initialize the glyph based on the grapheme.
hi::text_style style
The style of how to display the grapheme.
Definition text_shaper_char.hpp:24
void replace_glyph(char32_t code_point) noexcept
Called by the bidi-algorithm to mirror glyphs.
Definition text_style.hpp:173
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:39
Description of a unicode code point.
Definition unicode_description.hpp:31
T next(T... args)