From 58407a4445befaf21770b85bdc230902793ab8bf Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 2 Jul 2010 12:43:14 -0600 Subject: [PATCH] Fix infinite loop in default cover generation. Fixes #6061 (0.7.6 "calibre-parallel.exe has stopped working" when converting from some PDFs to epub) --- src/calibre/utils/magick_draw.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/calibre/utils/magick_draw.py b/src/calibre/utils/magick_draw.py index 2a259301db..0962afe807 100644 --- a/src/calibre/utils/magick_draw.py +++ b/src/calibre/utils/magick_draw.py @@ -65,6 +65,9 @@ class TextLine(object): self.bottom_margin = bottom_margin self.font_path = font_path + def __repr__(self): + return u'TextLine:%r:%f'%(self.text, self.font_size) + def alloc_wand(name): ans = getattr(p, name)() if ans < 0: @@ -120,6 +123,10 @@ def draw_centered_text(img, dw, text, top, margin=10): tokens = text.split(' ') while tokens: line, tokens = _get_line(img, dw, tokens, img_width-2*margin) + if not line: + # Could not fit the first token on the line + line = tokens[:1] + tokens = tokens[1:] bottom = draw_centered_line(img, dw, ' '.join(line), top) top = bottom return top