mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 23:46:24 -06:00
ENH:update mo of dailytip
Change-Id: I168159af60bbda827d24238f656aeaa192fd4299
This commit is contained in:
parent
f968374b46
commit
16e7993a65
14 changed files with 1563 additions and 13 deletions
|
@ -590,6 +590,76 @@ void NotificationManager::HintNotification::count_spaces()
|
|||
m_window_width = m_line_height * 25;
|
||||
}
|
||||
|
||||
static int get_utf8_seq_length(const char* seq, size_t size)
|
||||
{
|
||||
int length = 0;
|
||||
unsigned char c = seq[0];
|
||||
if (c < 0x80) { // 0x00-0x7F
|
||||
// is ASCII letter
|
||||
length++;
|
||||
}
|
||||
// Bytes 0x80 to 0xBD are trailer bytes in a multibyte sequence.
|
||||
// pos is in the middle of a utf-8 sequence. Add the utf-8 trailer bytes.
|
||||
else if (c < 0xC0) { // 0x80-0xBF
|
||||
length++;
|
||||
while (length < size) {
|
||||
c = seq[length];
|
||||
if (c < 0x80 || c >= 0xC0) {
|
||||
break; // prevent overrun
|
||||
}
|
||||
length++; // add a utf-8 trailer byte
|
||||
}
|
||||
}
|
||||
// Bytes 0xC0 to 0xFD are header bytes in a multibyte sequence.
|
||||
// The number of one bits above the topmost zero bit indicates the number of bytes (including this one) in the whole sequence.
|
||||
else if (c < 0xE0) { // 0xC0-0xDF
|
||||
// add a utf-8 sequence (2 bytes)
|
||||
if (2 > size) {
|
||||
return size; // prevent overrun
|
||||
}
|
||||
length += 2;
|
||||
}
|
||||
else if (c < 0xF0) { // 0xE0-0xEF
|
||||
// add a utf-8 sequence (3 bytes)
|
||||
if (3 > size) {
|
||||
return size; // prevent overrun
|
||||
}
|
||||
length += 3;
|
||||
}
|
||||
else if (c < 0xF8) { // 0xF0-0xF7
|
||||
// add a utf-8 sequence (4 bytes)
|
||||
if (4 > size) {
|
||||
return size; // prevent overrun
|
||||
}
|
||||
length += 4;
|
||||
}
|
||||
else if (c < 0xFC) { // 0xF8-0xFB
|
||||
// add a utf-8 sequence (5 bytes)
|
||||
if (5 > size) {
|
||||
return size; // prevent overrun
|
||||
}
|
||||
length += 5;
|
||||
}
|
||||
else if (c < 0xFE) { // 0xFC-0xFD
|
||||
// add a utf-8 sequence (6 bytes)
|
||||
if (6 > size) {
|
||||
return size; // prevent overrun
|
||||
}
|
||||
length += 6;
|
||||
}
|
||||
else { // 0xFE-0xFF
|
||||
// not a utf-8 sequence
|
||||
length++;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
static int get_utf8_seq_length(const std::string& text, size_t pos)
|
||||
{
|
||||
assert(pos < text.size());
|
||||
return get_utf8_seq_length(text.c_str() + pos, text.size() - pos);
|
||||
}
|
||||
|
||||
void NotificationManager::HintNotification::count_lines()
|
||||
{
|
||||
std::string text = m_text1;
|
||||
|
@ -630,7 +700,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) {
|
||||
//letter_count += get_utf8_sequence_length(text, last_end + letter_count);
|
||||
letter_count += get_utf8_seq_length(text, last_end + letter_count);
|
||||
}
|
||||
m_endlines.push_back(last_end + letter_count);
|
||||
last_end += letter_count;
|
||||
|
@ -702,7 +772,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) {
|
||||
//letter_count += get_utf8_sequence_length(text, last_end + letter_count);
|
||||
letter_count += get_utf8_seq_length(text, last_end + letter_count);
|
||||
}
|
||||
m_endlines2.push_back(last_end + letter_count);
|
||||
last_end += letter_count;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue