Skip to content

Commit 160f61b

Browse files
committed
Ignore zero width words when using ALIGN_JUSTIFY
Fixes #68
1 parent 2f32b42 commit 160f61b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

richtext/richtext.lua

+9-3
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,19 @@ local function position_words(words, line_width, line_height, position, settings
136136
end
137137

138138
local spacing = 0
139-
if settings.align == M.ALIGN_JUSTIFY and #words > 1 then
139+
if settings.align == M.ALIGN_JUSTIFY then
140140
local words_width = 0
141+
local word_count = 0
141142
for i=1,#words do
142143
local word = words[i]
143-
words_width = words_width + word.metrics.total_width
144+
if word.metrics.total_width > 0 then
145+
words_width = words_width + word.metrics.total_width
146+
word_count = word_count + 1
147+
end
148+
end
149+
if word_count > 1 then
150+
spacing = (settings.width - words_width) / (word_count - 1)
144151
end
145-
spacing = (settings.width - words_width) / (#words - 1)
146152
end
147153
for i=1,#words do
148154
local word = words[i]

0 commit comments

Comments
 (0)