From 4a79faaa1e49eb05158bb45617786340374b039f Mon Sep 17 00:00:00 2001 From: Anders Madsen <28491857+Axedyson@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:15:05 +0200 Subject: [PATCH 1/2] Use stringWidth from reportlab pdf modules --- src/aihawk_easy_applier.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/aihawk_easy_applier.py b/src/aihawk_easy_applier.py index 35ec76da..6e1fe609 100644 --- a/src/aihawk_easy_applier.py +++ b/src/aihawk_easy_applier.py @@ -11,6 +11,7 @@ from reportlab.lib.pagesizes import A4 from reportlab.pdfgen import canvas from selenium.common.exceptions import NoSuchElementException, TimeoutException +from reportlab.pdfbase.pdfmetrics import stringWidth from selenium.webdriver import ActionChains from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys @@ -536,11 +537,11 @@ def split_text_by_width(text, font, font_size, max_width): wrapped_lines = [] for line in text.splitlines(): - if utils.stringWidth(line, font, font_size) > max_width: + if stringWidth(line, font, font_size) > max_width: words = line.split() new_line = "" for word in words: - if utils.stringWidth(new_line + word + " ", font, font_size) <= max_width: + if stringWidth(new_line + word + " ", font, font_size) <= max_width: new_line += word + " " else: wrapped_lines.append(new_line.strip()) From cb2735762eeb871b37e001cff80440a5e4e79520 Mon Sep 17 00:00:00 2001 From: Anders Madsen <28491857+Axedyson@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:19:57 +0200 Subject: [PATCH 2/2] Remove stringWidth from utils as it is not needed --- src/utils.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/utils.py b/src/utils.py index 46454e47..a14089d1 100644 --- a/src/utils.py +++ b/src/utils.py @@ -166,7 +166,3 @@ def printyellow(text): reset = "\033[0m" logger.debug("Printing text in yellow: %s", text) print(f"{yellow}{text}{reset}") - -def stringWidth(text, font, font_size): - bbox = font.getbbox(text) - return bbox[2] - bbox[0] \ No newline at end of file