Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use the name head/tail prohibited and add more symbos.
  • Loading branch information
cyx2015s committed Jul 27, 2025
commit 5d7bb1095e6cdb91c739c69384ffa8567e489e7e
8 changes: 4 additions & 4 deletions imgui_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5429,9 +5429,9 @@ const char* ImFont::CalcWordWrapPosition(float size, const char* text, const cha
last_char_is_cjk = false;
last_char_is_init = false;
}
else if (ImCharIsTermW(c))
else if (ImCharIsHeadProhibitedW(c))
{
// Terminators can overflow, at most once.
// Can overflow, at most once.
line_width += word_width + blank_width;
word_width = 0.0f;
blank_width = char_width;
Expand All @@ -5443,7 +5443,7 @@ const char* ImFont::CalcWordWrapPosition(float size, const char* text, const cha
}
else
{
if (ImCharIsInitW(c))
if (ImCharIsTailProhibitedW(c))
{
line_width += word_width + blank_width;
word_width = blank_width = 0.0f;
Expand All @@ -5462,7 +5462,7 @@ const char* ImFont::CalcWordWrapPosition(float size, const char* text, const cha
// CJK characters are not separated by spaces, so we treat them as a single word.
// This is a very simple heuristic, but it works for most cases.
last_char_is_cjk = 0x3003 <= c && c <= 0xFFFF;
last_char_is_init = ImCharIsInitW(c);
last_char_is_init = ImCharIsTailProhibitedW(c);
word_width += char_width;
if (inside_word)
{
Expand Down
16 changes: 8 additions & 8 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,14 @@ IM_MSVC_RUNTIME_CHECKS_OFF
inline char ImToUpper(char c) { return (c >= 'a' && c <= 'z') ? c &= ~32 : c; }
inline bool ImCharIsBlankA(char c) { return c == ' ' || c == '\t'; }
inline bool ImCharIsBlankW(unsigned int c) { return c == ' ' || c == '\t' || c == 0x3000; }
// Terminators: Chinese punctuations that should not appear at the start of line.
// Only include characters can be typed within 1 or 2 hits on a standard Chinese keyboard.
// List: ~!)】、:;’”,。》」?
inline bool ImCharIsTermW(unsigned int c) { return c == 0xff5e || c == 0xff01 || c == 0xff09 || c == 0x3011 || c == 0x3001 || c == 0xff1a || c == 0xff1b || c == 0x2019 || c == 0x201d || c == 0xff0c || c == 0x3002 || c == 0x300b || c == 0x300d || c == 0xff1f; }
// Initializers: Chinese punctuations that should not appear at the end of line.
// Only include characters can be typed within 1 or 2 hits on a standard Chinese keyboard.
// List: (【《「
inline bool ImCharIsInitW(unsigned int c) { return c == 0xff08 || c == 0x3010 || c == 0x300a || c == 0x300c; }
// Head Prohibited: Punctuations that should not appear at the start of line.
// Only include characters can be typed within 1 or 2 hits on a standard keyboard.
// List: ~!)】、:;’”,。》」
inline bool ImCharIsHeadProhibitedW(unsigned int c) { return c == 0xff5e || c == 0xff01 || c == 0xff09 || c == 0x3011 || c == 0x3001 || c == 0xff1a || c == 0xff1b || c == 0x2019 || c == 0x201d || c == 0xff0c || c == 0x3002 || c == 0x300b || c == 0x300d || c == 0x300f || c == 0xff1f; }
// Tail Prohibited: Punctuations that should not appear at the end of line.
// Only include characters can be typed within 1 or 2 hits on a standard keyboard.
// List: (【《「
inline bool ImCharIsTailProhibitedW(unsigned int c) { return c == 0xff08 || c == 0x3010 || c == 0x300a || c == 0x300c || c == 0x300e; }
inline bool ImCharIsXdigitA(char c) { return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); }
IM_MSVC_RUNTIME_CHECKS_RESTORE

Expand Down