From 96f03a31195cb8e2c876695e5bc009c8f10afee8 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 6 Dec 2023 18:56:09 -0700 Subject: [PATCH] Prevent breaking long words on generic labels --- generic_label.py | 4 ++-- main.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generic_label.py b/generic_label.py index 3edb750..10f07b2 100644 --- a/generic_label.py +++ b/generic_label.py @@ -2,7 +2,7 @@ from PIL import Image, ImageEnhance, ImageFont, ImageDraw import textwrap text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' -text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.' +text = 'Extension cables' MARGIN = 50 MAX_W, MAX_H, PAD = 1285 - (MARGIN*2), 635 - (MARGIN*2), 5 @@ -17,7 +17,7 @@ def fit_text(text, font_size): for cols in range(100, 1, -4): print('trying size', font_size, 'cols', cols) - paragraph = textwrap.wrap(text, width=cols) + paragraph = textwrap.wrap(text, width=cols, break_long_words=False) total_h = -PAD total_w = 0 diff --git a/main.py b/main.py index 684b148..c8a8995 100755 --- a/main.py +++ b/main.py @@ -337,7 +337,7 @@ def print_generic_label(text): font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', font_size) for cols in range(100, 1, -4): - paragraph = textwrap.wrap(text, width=cols) + paragraph = textwrap.wrap(text, width=cols, break_long_words=False) total_h = -PAD total_w = 0