Skip to content

Commit

Permalink
Ignore zero width words when using ALIGN_JUSTIFY
Browse files Browse the repository at this point in the history
Fixes #68
  • Loading branch information
britzl committed Mar 10, 2021
1 parent 2f32b42 commit 160f61b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions richtext/richtext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,19 @@ local function position_words(words, line_width, line_height, position, settings
end

local spacing = 0
if settings.align == M.ALIGN_JUSTIFY and #words > 1 then
if settings.align == M.ALIGN_JUSTIFY then
local words_width = 0
local word_count = 0
for i=1,#words do
local word = words[i]
words_width = words_width + word.metrics.total_width
if word.metrics.total_width > 0 then
words_width = words_width + word.metrics.total_width
word_count = word_count + 1
end
end
if word_count > 1 then
spacing = (settings.width - words_width) / (word_count - 1)
end
spacing = (settings.width - words_width) / (#words - 1)
end
for i=1,#words do
local word = words[i]
Expand Down

0 comments on commit 160f61b

Please sign in to comment.