From 96cbe91b78903410894fad4f2e055ea657cb4010 Mon Sep 17 00:00:00 2001 From: Philipp Klaus Date: Mon, 11 Sep 2017 12:01:20 +0200 Subject: [PATCH] =?UTF-8?q?empty=20line=20=E2=86=92=20line=20containing=20?= =?UTF-8?q?'=20'=20(workaround=20for=20#5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- brother_ql_web.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/brother_ql_web.py b/brother_ql_web.py index d139362..cedd1f5 100755 --- a/brother_ql_web.py +++ b/brother_ql_web.py @@ -110,6 +110,13 @@ def create_label_im(text, **kwargs): im_font = ImageFont.truetype(kwargs['font_path'], kwargs['font_size']) im = Image.new('L', (20, 20), 'white') draw = ImageDraw.Draw(im) + # workaround for a bug in multiline_textsize() + # when there are empty lines in the text: + lines = [] + for line in text.split('\n'): + if line == '': line = ' ' + lines.append(line) + text = '\n'.join(lines) linesize = im_font.getsize(text) textsize = draw.multiline_textsize(text, font=im_font) width, height = kwargs['width'], kwargs['height']