Having problem with CJK line breaking(& zero-width space).

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Posts: 18
Joined: Sat Jan 25, 2020 4:11 pm

Having problem with CJK line breaking(& zero-width space).

Post by qwdqwqwffqw »

LOVE offers 'printf' and 'font:getWrap' for word wrapping, and it works great on Latin alphabets. However, it does not breaks line between east asian letter.

* For Chinese and Japanese (and perhaps some other languages), you often have to indicate where line break may 'naturally' happen between specific letters when it is needed (e.g. between words).
* For Korean, it is much more common practice to allow line-breaking between every Hangul letter(it is also default setting of web browsers and most commercial programs, but not on LOVE).

For both cases, zero-width space should be simple solution for proper formatting. However, this doesn't work as expected : it occupies same width as normal space letter, and does not allow line breaking. To say, it works as if it's another letter or non-breaking space.

Maybe for Korean, something like this can be possible :

Code: Select all

font, limit = love.graphics.setNewFont("font.ttf"), 300
text = "AAAA AAA AAAA A AAAAA AAAA" -- consider A's as Korean Hangul letters.
lines = []
while #text > 0 do
	_, wt = font:getWrap(text, limit)
	line = wt[1] -- shortest possible line
	while #line < #text do
		line2 = line .. utf8_next_letter(text, #line)
		if font:getWidth(line2) < limit then
			line = line2
		else -- we can not add more letter in this line.
			lines[#lines+1] = line2
			text = text:sub(#line2+1)
return lines = [] -- wrapped texts.
But it still seems overly complex way to handle this.

Is there any workaround to problems above?
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], slime and 4 guests