support full-width unicode characters#274
Merged
AydinHassan merged 1 commit intophp-school:masterfrom Aug 2, 2023
Merged
Conversation
AsuraO3O
approved these changes
Aug 2, 2023
Member
|
Nice! looks good to me |
AydinHassan
approved these changes
Aug 2, 2023
Member
|
Don't suppose you know how to make it work with emojis? For example if you take a look at $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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since full-width characters will break the UI, we should detect the visual width of the string using
mb_strwidthinstead ofmb_strlen.mb_strlenwhen you are detecting the string length for word counting.mb_strwidthwhen you are detecting the string width on the screen.I replace all the
mb_strlenintomb_strwidthbecause 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 字元以及其他全型字元將不會造成跑版。