diff options
author | David Kocik <kocikdav@gmail.com> | 2022-01-05 14:37:07 +0300 |
---|---|---|
committer | David Kocik <kocikdav@gmail.com> | 2022-01-05 16:45:56 +0300 |
commit | 3f14484ecacf881e9fb66b5e19b8d9ec9381f113 (patch) | |
tree | d88998678ab7c8c12d100cd5c14413eb306871c9 /src/slic3r/GUI | |
parent | fff862a5ae4b013f9a4ca20161b514f7fb0574e8 (diff) |
Moved Odaki's implemetation of searching for end of utf8 sequence to separate function.
+ Fix of 0xC0 in trailer bytes
followup on fff862a5ae4b013f9a4ca20161b514f7fb0574e8
Diffstat (limited to 'src/slic3r/GUI')
-rw-r--r-- | src/slic3r/GUI/HintNotification.cpp | 102 | ||||
-rw-r--r-- | src/slic3r/GUI/NotificationManager.cpp | 2 |
2 files changed, 3 insertions, 101 deletions
diff --git a/src/slic3r/GUI/HintNotification.cpp b/src/slic3r/GUI/HintNotification.cpp index 91c9d71c8..291ce8f40 100644 --- a/src/slic3r/GUI/HintNotification.cpp +++ b/src/slic3r/GUI/HintNotification.cpp @@ -615,56 +615,7 @@ void NotificationManager::HintNotification::count_lines() float width_of_a = ImGui::CalcTextSize("a").x; int letter_count = (int)((m_window_width - m_window_width_offset) / width_of_a); while (last_end + letter_count < text.size() && ImGui::CalcTextSize(text.substr(last_end, letter_count).c_str()).x < m_window_width - m_window_width_offset) { - size_t text_size = text.size(); - size_t current_position = last_end + letter_count; - unsigned char c = text[current_position]; - if (c < 0x80) { // 0x00-0x7F - // add ASCII letter - letter_count++; - } else if (c < 0xC0) { // 0x80-0xBF - // it is in the middle of a utf-8 sequence. add the utf-8 trailer bytes. - letter_count++; - while (last_end + letter_count < text.size()) { - c = text[last_end + letter_count]; - if (c < 0x80 || c > 0xC0) { - break; // prevent overrun - } - letter_count++; // add a utf-8 trailer byte - } - } else if (c < 0xE0) { // 0xC0-0xDF - // add a utf-8 sequence (2 bytes) - if (current_position + 2 > text_size) { - break; // prevent overrun - } - letter_count += 2; - } else if (c < 0xF0) { // 0xE0-0xEF - // add a utf-8 sequence (3 bytes) - if (current_position + 3 > text_size) { - break; // prevent overrun - } - letter_count += 3; - } else if (c < 0xF8) { // 0xF0-0xF7 - // add a utf-8 sequence (4 bytes) - if (current_position + 4 > text_size) { - break; // prevent overrun - } - letter_count += 4; - } else if (c < 0xFC) { // 0xF8-0xFB - // add a utf-8 sequence (5 bytes) - if (current_position + 5 > text_size) { - break; // prevent overrun - } - letter_count += 5; - } else if (c < 0xFE) { // 0xFC-0xFD - // add a utf-8 sequence (6 bytes) - if (current_position + 6 > text_size) { - break; // prevent overrun - } - letter_count += 6; - } else { // 0xFE-0xFF - // not a utf-8 sequence - letter_count++; - } + letter_count += get_utf8_sequence_length(text, last_end + letter_count); } m_endlines.push_back(last_end + letter_count); last_end += letter_count; @@ -734,56 +685,7 @@ void NotificationManager::HintNotification::count_lines() float width_of_a = ImGui::CalcTextSize("a").x; int letter_count = (int)((m_window_width - m_window_width_offset - size_of_last_line) / width_of_a); while (last_end + letter_count < text.size() && ImGui::CalcTextSize(text.substr(last_end, letter_count).c_str()).x < m_window_width - m_window_width_offset - size_of_last_line) { - size_t text_size = text.size(); - size_t current_position = last_end + letter_count; - unsigned char c = text[current_position]; - if (c < 0x80) { // 0x00-0x7F - // add ASCII letter - letter_count++; - } else if (c < 0xC0) { // 0x80-0xBF - // it is in the middle of a utf-8 sequence. add the utf-8 trailer bytes. - letter_count++; - while (last_end + letter_count < text.size()) { - c = text[last_end + letter_count]; - if (c < 0x80 || c > 0xC0) { - break; // prevent overrun - } - letter_count++; // add a utf-8 trailer byte - } - } else if (c < 0xE0) { // 0xC0-0xDF - // add a utf-8 sequence (2 bytes) - if (current_position + 2 > text_size) { - break; // prevent overrun - } - letter_count += 2; - } else if (c < 0xF0) { // 0xE0-0xEF - // add a utf-8 sequence (3 bytes) - if (current_position + 3 > text_size) { - break; // prevent overrun - } - letter_count += 3; - } else if (c < 0xF8) { // 0xF0-0xF7 - // add a utf-8 sequence (4 bytes) - if (current_position + 4 > text_size) { - break; // prevent overrun - } - letter_count += 4; - } else if (c < 0xFC) { // 0xF8-0xFB - // add a utf-8 sequence (5 bytes) - if (current_position + 5 > text_size) { - break; // prevent overrun - } - letter_count += 5; - } else if (c < 0xFE) { // 0xFC-0xFD - // add a utf-8 sequence (6 bytes) - if (current_position + 6 > text_size) { - break; // prevent overrun - } - letter_count += 6; - } else { // 0xFE-0xFF - // not a utf-8 sequence - letter_count++; - } + letter_count += get_utf8_sequence_length(text, last_end + letter_count); } m_endlines2.push_back(last_end + letter_count); last_end += letter_count; diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index 66c22cb9b..aab0dbbab 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -301,7 +301,7 @@ void NotificationManager::PopNotification::count_lines() float width_of_a = ImGui::CalcTextSize("a").x; int letter_count = (int)((m_window_width - m_window_width_offset) / width_of_a); while (last_end + letter_count < text.size() && ImGui::CalcTextSize(text.substr(last_end, letter_count).c_str()).x < m_window_width - m_window_width_offset) { - letter_count++; + letter_count += get_utf8_sequence_length(text, last_end + letter_count); } m_endlines.push_back(last_end + letter_count); last_end += letter_count; |