mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-19 11:23:42 +00:00
FIX: Daily tips display issue in CJK
Jira: STUDIO-13921 Change-Id: I5c4fef910749a31acff4650413390051d2aabf84 (cherry picked from commit 9e5f2a89fe1ce7f7eeee892be8c48099a288646f)
This commit is contained in:
@@ -145,6 +145,21 @@ void DailyTipsDataRenderer::render_img(const ImVec2& start_pos, const ImVec2& si
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool has_cjk(const std::string &text)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < text.size() - 2; ++i) {
|
||||||
|
unsigned char c1 = text[i];
|
||||||
|
unsigned char c2 = text[i + 1];
|
||||||
|
unsigned char c3 = text[i + 2];
|
||||||
|
|
||||||
|
if ((c1 & 0xF0) == 0xE0 && (c2 & 0xC0) == 0x80 && (c3 & 0xC0) == 0x80) {
|
||||||
|
int codepoint = ((c1 & 0x0F) << 12 | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
|
||||||
|
if (codepoint >= 0x3000 && codepoint <= 0x9FFF) { return true; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void DailyTipsDataRenderer::render_text(const ImVec2& start_pos, const ImVec2& size) const
|
void DailyTipsDataRenderer::render_text(const ImVec2& start_pos, const ImVec2& size) const
|
||||||
{
|
{
|
||||||
ImGuiWrapper& imgui = *wxGetApp().imgui();
|
ImGuiWrapper& imgui = *wxGetApp().imgui();
|
||||||
@@ -164,11 +179,7 @@ void DailyTipsDataRenderer::render_text(const ImVec2& start_pos, const ImVec2& s
|
|||||||
ImGui::SetCursorPos(start_pos);
|
ImGui::SetCursorPos(start_pos);
|
||||||
imgui.text(title_line);
|
imgui.text(title_line);
|
||||||
|
|
||||||
bool is_zh = false;
|
bool is_zh = has_cjk(content_lines);
|
||||||
for (int i = 0; i < content_lines.size() - 1; i += 2) {
|
|
||||||
if ((content_lines[i] & 0x80) && (content_lines[i + 1] & 0x80))
|
|
||||||
is_zh = true;
|
|
||||||
}
|
|
||||||
if (!is_zh) {
|
if (!is_zh) {
|
||||||
// problem in Chinese with spaces
|
// problem in Chinese with spaces
|
||||||
ImGui::SetCursorPosX(start_pos.x);
|
ImGui::SetCursorPosX(start_pos.x);
|
||||||
@@ -178,7 +189,11 @@ void DailyTipsDataRenderer::render_text(const ImVec2& start_pos, const ImVec2& s
|
|||||||
Label* wrapped_text = new Label(wxGetApp().GetTopWindow());
|
Label* wrapped_text = new Label(wxGetApp().GetTopWindow());
|
||||||
wrapped_text->Hide();
|
wrapped_text->Hide();
|
||||||
wrapped_text->SetLabelText(wxString::FromUTF8(content_lines));
|
wrapped_text->SetLabelText(wxString::FromUTF8(content_lines));
|
||||||
wrapped_text->Wrap(size.x + ImGui::CalcTextSize("A").x * 5.0f);
|
float wrap_width = size.x + ImGui::CalcTextSize("A").x * 5.0f;
|
||||||
|
#ifdef __APPLE__
|
||||||
|
wrap_width /= 2.0f;
|
||||||
|
#endif
|
||||||
|
wrapped_text->Wrap(wrap_width);
|
||||||
std::string wrapped_content_lines = wrapped_text->GetLabel().ToUTF8().data();
|
std::string wrapped_content_lines = wrapped_text->GetLabel().ToUTF8().data();
|
||||||
wrapped_text->Destroy();
|
wrapped_text->Destroy();
|
||||||
ImGui::SetCursorPosX(start_pos.x);
|
ImGui::SetCursorPosX(start_pos.x);
|
||||||
|
|||||||
Reference in New Issue
Block a user