Repository navigation
fix: word wrap breaks next to Chinese and Japanese characters - #2084
Merged
Merged
Conversation
Word wrap only broke at spaces and dashes, so text that mixes Chinese or Japanese with a latin word was cut at the only space, far from the edge, and a latin word next to them was split in the middle. These scripts have no spaces between words: a line can now break next to any of their characters, except before closing punctuation and after opening punctuation. Korean uses spaces and keeps breaking at them. Refs konvajs#1746
…aracter before 々 ゝ ゞ ヽ ヾ 〻 〃 repeat the character before them, so a line must not start with one, and neither may halfwidth 。 、 ・ or a fullwidth %. They are not closing punctuation, so the general-category classes missed them and 人々 wrapped as 人 / 々, which Chrome never does. The rule that a line can end before a space now lives in isBreak with the other break rules instead of in a separate guard of the wrap loop. Breaks are unchanged. The Konva日本語 test case passed before the fix as well, so it is replaced by one that breaks between a latin word and a Chinese character. The latin case duplicated existing tests and is dropped.
The tests assumed a CJK glyph is wider than a latin letter, so the latin word that moves to the next line fit there. Where no CJK font is installed the glyphs are narrow placeholder boxes, as on the CI runners for skia and Chrome, and the word was cut. Each width now fits every line the assertion expects, and the filled-line case asserts only the line it is about. Every case passes with narrow and wide CJK glyphs and fails on the old wrap code.
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.
Follow-up to #1746, where you asked for a PR with a test.
wrap: 'word'only breaks at spaces and dashes, so mixed text is cut at the only space, far from the edge:With no space on the line, a latin word next to them was split in the middle instead (
畫布Ko/nva).Chinese and Japanese have no spaces between words, so a line can now break next to any of their characters, except before closing punctuation and after opening punctuation. Korean uses spaces and keeps breaking at them. Text with no Chinese, Japanese or fullwidth characters takes the same breaks as before. The check only runs when a line needs wrapping and adds no measuring.
I ran the unit tests on node-canvas and skia, but not
test:browser.