diff --git a/src/slic3r/GUI/DailyTips.cpp b/src/slic3r/GUI/DailyTips.cpp index 2e5b99e8b2..5630b2474a 100644 --- a/src/slic3r/GUI/DailyTips.cpp +++ b/src/slic3r/GUI/DailyTips.cpp @@ -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 { ImGuiWrapper& imgui = *wxGetApp().imgui(); @@ -164,11 +179,7 @@ void DailyTipsDataRenderer::render_text(const ImVec2& start_pos, const ImVec2& s ImGui::SetCursorPos(start_pos); imgui.text(title_line); - bool is_zh = false; - for (int i = 0; i < content_lines.size() - 1; i += 2) { - if ((content_lines[i] & 0x80) && (content_lines[i + 1] & 0x80)) - is_zh = true; - } + bool is_zh = has_cjk(content_lines); if (!is_zh) { // problem in Chinese with spaces 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()); wrapped_text->Hide(); 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(); wrapped_text->Destroy(); ImGui::SetCursorPosX(start_pos.x);