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_set.hpp"
8#include "text_style.hpp"
9#include "../font/font.hpp"
10#include "../unicode/unicode.hpp"
11#include "../geometry/geometry.hpp"
12#include "../units/units.hpp"
13#include "../macros.hpp"
14
15hi_export_module(hikogui.text.text_shaper_char);
16
17hi_export namespace hi::inline v1 {
18
19class text_shaper_char {
20public:
23 hi::grapheme grapheme;
24
27 hi::text_style style;
28
31 unit::pixel_density pixel_density;
32
44
49 hi::glyph_metrics metrics;
50
53 size_t line_nr;
54
57 size_t column_nr;
58
66
87 aarectangle rectangle;
88
91 unicode_general_category general_category;
92
97 unicode_bidi_class direction;
98
105 iso_15924 script;
106
110
116 float width = 0.0f;
117
121
128 bool glyph_is_initial = false;
129
130 [[nodiscard]] text_shaper_char(hi::grapheme const& grapheme, text_style_set const& style, unit::pixel_density pixel_density) noexcept :
132 style(style[grapheme.attributes()]),
136 general_category(ucd_get_general_category(grapheme.starter()))
137 {
138 }
139
146 {
147 if (not glyph_is_initial) {
148 set_glyph(find_glyph(font, grapheme));
149
150 width = metrics.advance;
151 glyph_is_initial = true;
152 }
153 }
154
160 void initialize_glyph() noexcept
161 {
162 return initialize_glyph(style.font_chain()[0]);
163 }
164
173 void replace_glyph(char32_t code_point) noexcept
174 {
175 set_glyph(find_glyph(glyphs.font, code_point));
176 glyph_is_initial = false;
177 }
178
181 [[nodiscard]] font_metrics_px font_metrics() const noexcept
182 {
183 hi_axiom(not glyphs.font.empty());
184 return font_size * glyphs.font->metrics;
185 }
186
187 [[nodiscard]] friend bool operator==(text_shaper_char const& lhs, char32_t const& rhs) noexcept
188 {
189 return lhs.grapheme == rhs;
190 }
191
192 [[nodiscard]] friend bool operator==(text_shaper_char const& lhs, char const& rhs) noexcept
193 {
194 return lhs.grapheme == rhs;
195 }
196
197private:
200 void set_glyph(hi::font_glyph_ids&& new_glyphs) noexcept
201 {
202 glyphs = std::move(new_glyphs);
203 hi_axiom(not glyphs.font.empty());
204 font_size = round(style.size() * pixel_density, glyphs.font_metrics().x_height);
205 metrics = font_size.in(unit::pixels_per_em) * glyphs.front_glyph_metrics();
206 }
207};
208
209} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
font_glyph_ids find_glyph(font_id font, grapheme grapheme) noexcept
Find a glyph using the given code-point.
Definition font_book.hpp:362
Definition font_font.hpp:32
Definition font_glyph_ids.hpp:17
An identifier for a font-family that was registered with HikoGUI.
Definition font_id.hpp:23
A high-level geometric point Part of the high-level vec, point, mat and color types.
Definition point2.hpp:28
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
unicode_bidi_class direction
The text direction for this glyph.
Definition text_shaper_char.hpp:97
hi::grapheme grapheme
The grapheme.
Definition text_shaper_char.hpp:23
void initialize_glyph() noexcept
Initialize the glyph based on the grapheme.
Definition text_shaper_char.hpp:160
bool is_trailing_white_space
Set to true if this glyph is a white space at the end of a line.
Definition text_shaper_char.hpp:120
au::Quantity< unit::PixelsPerEm, float > font_size
The font size in pixels, rounded so that the x-height is rounded to the nearest pixel.
Definition text_shaper_char.hpp:109
bool glyph_is_initial
The glyph is the initial glyph.
Definition text_shaper_char.hpp:128
hi::font_glyph_ids glyphs
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 current starter glyph.
Definition text_shaper_char.hpp:49
font_metrics_px font_metrics() const noexcept
Get the scaled font metrics for this character.
Definition text_shaper_char.hpp:181
iso_15924 script
The script of this character.
Definition text_shaper_char.hpp:105
unicode_general_category general_category
The general category of this grapheme.
Definition text_shaper_char.hpp:91
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
float width
The width used for this grapheme when folding lines.
Definition text_shaper_char.hpp:116
unit::pixel_density pixel_density
The scale to resize the font's size to match the physical display.
Definition text_shaper_char.hpp:31
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_shaper_char.hpp:173
void initialize_glyph(hi::font_id font) noexcept
Initialize the glyph based on the grapheme.
Definition text_shaper_char.hpp:145
Definition au.hh:3518
T max(T... args)
T move(T... args)
T round(T... args)