From b084120c0dbf8864e9a684efc0b641a06b3606ef Mon Sep 17 00:00:00 2001 From: Rob Date: Wed, 24 Jun 2026 07:48:50 +0200 Subject: [PATCH] fix: empty field: Qualifikation and Funktion --- src/writer.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/writer.py b/src/writer.py index 0ca606c..a46231c 100644 --- a/src/writer.py +++ b/src/writer.py @@ -173,6 +173,11 @@ def _fill_pdf_pages( MULTILINE_FIELDS = {"Tätigkeiten_Field", "Dienstreisen_Field"} TEXTBOX_WIDTH_PT = 400 # Breite der Textbox in Punkt + # Felder mit automatischer Schriftgrößen-Anpassung bei langem Text + AUTOSCALE_FIELDS = {"Qualifikation_Field", "Funktion_Field"} + AUTOSCALE_MAX_CHARS = 35 # ab dieser Länge wird verkleinert + AUTOSCALE_MIN_FACTOR = 0.75 # minimale Schriftgröße relativ zum Original + for m in mapping: if m.pdf_field is None: continue @@ -199,6 +204,15 @@ def _fill_pdf_pages( if not formatted: continue + # Automatische Schriftgrößen-Anpassung für lange Texte + if m.pdf_field in AUTOSCALE_FIELDS and len(formatted) > AUTOSCALE_MAX_CHARS: + text_width = fitz.get_text_length(formatted, fontname="helv", fontsize=fontsize) + available_width = rect.width + if text_width > available_width: + factor = available_width / text_width + factor = max(factor, AUTOSCALE_MIN_FACTOR) + fontsize = fontsize * factor + # Mehrzeilige Felder: Zeilenweise per insert_text schreiben if m.pdf_field in MULTILINE_FIELDS: # Doppelte Leerzeilen entfernen