mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2026-02-24 21:35:03 -07:00
FIX: Daily tips display issue in CJK
Jira: STUDIO-13921 Change-Id: I5c4fef910749a31acff4650413390051d2aabf84 (cherry picked from commit 9e5f2a89fe1ce7f7eeee892be8c48099a288646f)
This commit is contained in:
parent
3d7bf13932
commit
8dd88df97b
1 changed files with 21 additions and 6 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue