7#include "unicode_grapheme_cluster_break.hpp"
8#include "unicode_description.hpp"
10namespace hi::inline
v1 {
13 unicode_grapheme_cluster_break previous = unicode_grapheme_cluster_break::Other;
15 bool first_character =
true;
16 bool in_extended_pictograph =
false;
20 previous = unicode_grapheme_cluster_break::Other;
22 first_character =
true;
23 in_extended_pictograph =
false;
36template<
typename It,
typename ItEnd>
42 for (
auto it = first; it != last; ++it) {
43 hilet opertunity =
breaks_grapheme(*it, state) ? unicode_break_opportunity::yes : unicode_break_opportunity::no;
44 r.push_back(opertunity);
47 r.push_back(unicode_break_opportunity::yes);
66void wrap_lines(
auto first,
auto last,
float max_width,
auto get_width,
auto get_code_point,
auto set_code_point)
noexcept
68 using enum unicode_general_category;
70 auto it_at_last_space = last;
71 float width_at_last_space = 0.0;
72 float current_width = 0.0;
74 for (
auto it = first; it != last; ++it) {
75 hilet code_point = get_code_point(*it);
76 hilet description = unicode_description::find(code_point);
77 hilet general_category = description->general_category();
79 if (general_category == Zp || general_category == Zl) {
81 it_at_last_space = last;
82 width_at_last_space = 0.0f;
86 }
else if (general_category == Zs) {
88 it_at_last_space = it;
89 width_at_last_space = current_width;
92 current_width += get_width(*it);
93 if (current_width >= max_width && it_at_last_space != last) {
95 set_code_point(*it, U
'\u2028');
96 it_at_last_space = last;
97 width_at_last_space = 0.0f;
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
bool breaks_grapheme(char32_t code_point, grapheme_break_state &state) noexcept
Check if for a grapheme break before the given code-point.
void wrap_lines(auto first, auto last, float max_width, auto get_width, auto get_code_point, auto set_code_point) noexcept
Wrap lines in text that are too wide.
Definition unicode_text_segmentation.hpp:66
Definition unicode_text_segmentation.hpp:12