HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
unicode_bidi.hpp
1// Copyright Take Vos 2020-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
6#pragma once
7
8#include "unicode_bidi_class.hpp"
9#include "unicode_description.hpp"
10
11namespace tt {
12namespace detail {
13
17 size_t index;
18
22 char32_t code_point;
23
28
32 unicode_bidi_class direction;
33
37 unicode_bidi_class bidi_class;
38
42
43 [[nodiscard]] unicode_bidi_char_info(size_t index, char32_t code_point) noexcept :
45 {
46 description = &unicode_description_find(code_point);
49 }
50
54 [[nodiscard]] unicode_bidi_char_info(size_t index, unicode_bidi_class bidi_class) noexcept :
55 index(index),
56 code_point(U'\ufffd'),
60 description(nullptr)
61 {
62 }
63};
64
65using unicode_bidi_char_info_vector = std::vector<unicode_bidi_char_info>;
66using unicode_bidi_char_info_iterator = unicode_bidi_char_info_vector::iterator;
67using unicode_bidi_char_info_const_iterator = unicode_bidi_char_info_vector::const_iterator;
68
71
72 characters_type characters;
73
74 template<typename... Args>
75 void emplace_character(Args &&...args) noexcept
76 {
77 characters.emplace_back(std::forward<Args>(args)...);
78 }
79};
80
81template<typename OutputIt, typename SetCodePoint>
82static void unicode_bidi_L4(
83 unicode_bidi_char_info_iterator first,
84 unicode_bidi_char_info_iterator last,
85 OutputIt output_it,
86 SetCodePoint set_code_point) noexcept
87{
88 for (auto it = first; it != last; ++it, ++output_it) {
89 if (it->direction == unicode_bidi_class::R && it->description->bidi_bracket_type() != unicode_bidi_bracket_type::n) {
90 set_code_point(*output_it, it->description->bidi_mirrored_glyph());
91 }
92 }
93}
94
96 unicode_bidi_class force_paragraph_direction = unicode_bidi_class::unknown;
97 bool enable_mirrored_brackets = true;
98 bool enable_line_separator = true;
99};
100
101[[nodiscard]] unicode_bidi_char_info_iterator unicode_bidi_P1(
102 unicode_bidi_char_info_iterator first,
103 unicode_bidi_char_info_iterator last,
104 unicode_bidi_test_parameters test_parameters = {}) noexcept;
105
106} // namespace detail
107
131template<typename It, typename GetCodePoint, typename SetCodePoint>
132It unicode_bidi(
133 It first,
134 It last,
135 GetCodePoint get_code_point,
136 SetCodePoint set_code_point,
137 detail::unicode_bidi_test_parameters test_parameters = {})
138{
139 auto proxy = detail::unicode_bidi_char_info_vector{};
140 proxy.reserve(std::distance(first, last));
141
142 size_t index = 0;
143 for (auto it = first; it != last; ++it) {
144 proxy.emplace_back(index++, get_code_point(*it));
145 }
146
147 auto proxy_last = detail::unicode_bidi_P1(std::begin(proxy), std::end(proxy), test_parameters);
148 last = shuffle_by_index(first, last, std::begin(proxy), proxy_last, [](ttlet &item) {
149 return item.index;
150 });
151
152 detail::unicode_bidi_L4(std::begin(proxy), proxy_last, first, set_code_point);
153 return last;
154}
155
156} // namespace tt
Definition unicode_bidi.hpp:14
char32_t code_point
The current code point.
Definition unicode_bidi.hpp:22
unicode_bidi_class bidi_class
The original bidi class of the code-point.
Definition unicode_bidi.hpp:37
size_t index
Index from the first character in the original list.
Definition unicode_bidi.hpp:17
int8_t embedding_level
The embedding level.
Definition unicode_bidi.hpp:27
unicode_description const * description
Description of the code-point.
Definition unicode_bidi.hpp:41
unicode_bidi_char_info(size_t index, unicode_bidi_class bidi_class) noexcept
Constructor for testing to bypass normal initialization.
Definition unicode_bidi.hpp:54
unicode_bidi_class direction
Current computed direction of the code-point.
Definition unicode_bidi.hpp:32
Definition unicode_bidi.hpp:69
Definition unicode_bidi.hpp:95
Description of a unicode code point.
Definition unicode_description.hpp:63
constexpr unicode_bidi_class bidi_class() const noexcept
The bidi class of this code-point This function is used by the bidirectional algorithm to figure out ...
Definition unicode_description.hpp:135
T begin(T... args)
T distance(T... args)
T emplace_back(T... args)
T end(T... args)