konvajs / konva

Konva.js is an HTML5 Canvas JavaScript framework that extends the 2d context by enabling canvas interactivity for desktop and mobile applications.
http://konvajs.org/
Other
11.61k stars 924 forks source link

Text wrong line break if have Chinese and english word #1746

Open david43 opened 7 months ago

david43 commented 7 months ago

demo: https://codepen.io/david43/pen/rNbZwjb if text mixed Chinese and Eng,the line break will wrong. 未命名 set text wrap:"char" can fix this issue, but eng word also broken.

lavrton commented 6 months ago

I think I will mark it as "won't fix" for now. Konva breaks by space character . I am not sure what will be the fast implementation from Konva side to automatically handle different languages.

luin commented 2 months ago

A quick solution would be checking if the language of a char uses spaces as word boundaries. (e.g. /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/gu) and split by chars for those languages.

lavrton commented 2 months ago

Interested in making a pull request with a test?