Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support full-width unicode characters #274

Merged
merged 1 commit into from Aug 2, 2023

Conversation

mingtsay
Copy link
Contributor

@mingtsay mingtsay commented Aug 2, 2023

Since full-width characters will break the UI, we should detect the visual width of the string using mb_strwidth instead of mb_strlen.

  • Use mb_strlen when you are detecting the string length for word counting.
  • Use mb_strwidth when you are detecting the string width on the screen.

I replace all the mb_strlen into mb_strwidth because none of them are used to detecting the string length for word counting. They all are used to get the string width on the screen.

You may now use this commit to make CJK characters perfectly fit in the dialog. 😃

正體中文:由於 mb_strlen 是用來計算字串中的字元數量而非寬度,因此需將所有計算字串寬度的函數中的實作都改成使用 mb_strwidth 才不會造成跑版。現有的 mb_strlen 經人工檢視後發現,用途皆為計算寬度而非字數,因此我將該些實作全部從 mb_strlen 改成 mb_strwidth,如此 CJK 字元以及其他全型字元將不會造成跑版。

@AydinHassan
Copy link
Member

Nice! looks good to me

@AydinHassan AydinHassan merged commit 0cdb162 into php-school:master Aug 2, 2023
11 checks passed
@AydinHassan
Copy link
Member

Don't suppose you know how to make it work with emojis? For example if you take a look at examples/crazy-redraw.php and replace:

$items[] = new LineBreakItem(array_rand(array_flip(['♥', '★', '^'])), rand(1, 3));

with:

$items[] = new LineBreakItem(array_rand(array_flip(['❤️', '★', '^'])), rand(1, 3));

It doesn't look good lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants