From 7281fe8b924215743927c341fe4dc7c411947608 Mon Sep 17 00:00:00 2001 From: Jinge Li <9894243+chinapandaman@users.noreply.github.com> Date: Mon, 27 May 2024 22:18:02 +0000 Subject: [PATCH 1/2] PPF-624: ignore max length --- PyPDFForm/template.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/PyPDFForm/template.py b/PyPDFForm/template.py index b9eacdac..5d33a72e 100644 --- a/PyPDFForm/template.py +++ b/PyPDFForm/template.py @@ -134,7 +134,8 @@ def update_text_field_attributes( if not is_paragraph else DEFAULT_FONT_SIZE ) - should_adjust_font_size = is_paragraph and not template_font_size + should_adjust_font_size = (not template_font_size + and widgets[key].max_length is None) if widgets[key].font_color is None: widgets[key].font_color = get_text_field_font_color(_widget) if is_paragraph and widgets[key].text_wrap_length is None: @@ -142,8 +143,11 @@ def update_text_field_attributes( widgets[key].text_wrap_length = get_paragraph_auto_wrap_length( widgets[key] ) - if widgets[key].value and should_adjust_font_size: + if widgets[key].value and should_adjust_font_size: + if is_paragraph: adjust_paragraph_font_size(_widget, widgets[key]) + else: + adjust_text_field_font_size(_widget, widgets[key]) @lru_cache() @@ -413,3 +417,19 @@ def adjust_paragraph_font_size(widget: dict, widget_middleware: Text) -> None: ): widget_middleware.font_size -= FONT_SIZE_REDUCE_STEP widget_middleware.text_lines = get_paragraph_lines(widget, widget_middleware) + + +def adjust_text_field_font_size(widget: dict, widget_middleware: Text) -> None: + """Reduces the font size of a text field until texts fits.""" + + width = abs(float(widget[Rect][0]) - float(widget[Rect][2])) + + while( + widget_middleware.font_size > FONT_SIZE_REDUCE_STEP + and stringWidth( + widget_middleware.value, + widget_middleware.font, + widget_middleware.font_size + ) > width + ): + widget_middleware.font_size -= FONT_SIZE_REDUCE_STEP From 36443b8b9509503e6279e349414c30e1a808dd54 Mon Sep 17 00:00:00 2001 From: Jinge Li <9894243+chinapandaman@users.noreply.github.com> Date: Mon, 27 May 2024 22:20:24 +0000 Subject: [PATCH 2/2] PPF-624: update test cases --- ...estate-power-of-attorney-form_expected.pdf | Bin 45489 -> 45485 bytes pdf_samples/widget/create_widget_sejda.pdf | Bin 187571 -> 187569 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/pdf_samples/scenario/existed/illinois-real-estate-power-of-attorney-form_expected.pdf b/pdf_samples/scenario/existed/illinois-real-estate-power-of-attorney-form_expected.pdf index 5006f1c561f9a0011519265eca7c5534d45f5d0b..c6af0dbd8a5573f3c7a93ac400a1b8e28db98fa4 100644 GIT binary patch delta 159 zcmdn^m}%`}rVVd>84V_1Snjx4-)}-FpRt~inLQ}eeTk{#s(I878VL- zhK7137L&g(*5fhOGcf@xGSf4hY`8>&$--!J?2_X=cBYmJ1|Xo2r@#efm>8LvnPZ4q b8XKXDnOK@yOitS9#%X58rK;-c@5TiH!Z#_u delta 135 zcmZ4cm}%o8BI37^Su~4*=DgOzp;UZo`r>inW2H6nTeVCP!!s_N?R G#svV5IDtu)+tNtE*vL%J!r0h&ds9Et z2P-~fFvl3A#L!F+tZMq)Q%vlP7SorWVltY(@g$Q9kBOnFf|0SA9#EU{cJ|Xua)P#| t3I-sckf*=}q7BU~EX)ni#4L8yo2vTUb~sgyeE*B$ZZ9=R3_5z;0}+X9iNtdYVa2(AHeR00b2B6u3aN np_zq+xe=O}g)zt$kTgP_g|Vrb!SsYXOr9K;T&k+B{%%|V5acU&