Skip to content

Commit

Permalink
Update fill_textbox to better respect rect.width
Browse files Browse the repository at this point in the history
The function norm_words in fill_textbox had a bug in its last loop, appending n+1 characters when actually measuring width of n characters.
It led to a bug in fill_texbox when you tried to write a single word mostly composed of "wide" letters (M,m, W, w...), causing the written text to exceed the given rect.

The fix was just to replace n+1 by n.
  • Loading branch information
ellacroix authored and jamie-lemon committed Aug 3, 2023
1 parent 5683869 commit 253f9cd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fitz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4356,10 +4356,10 @@ def norm_words(width, words):
while n > 0:
wl = sum(wl_lst[:n])
if wl <= width:
nwords.append(w[: n + 1])
nwords.append(w[:n])
word_lengths.append(wl)
w = w[n + 1 :]
wl_lst = wl_lst[n + 1 :]
w = w[n:]
wl_lst = wl_lst[n:]
n = len(wl_lst)
else:
n -= 1
Expand Down

0 comments on commit 253f9cd

Please sign in to comment.