Skip to content

Commit dbe6de9

Browse files
author
black-isort-bot
committed
[skip ci]: black/isort
1 parent 3136ef2 commit dbe6de9

File tree

2 files changed

+18
-36
lines changed

2 files changed

+18
-36
lines changed

PyPDFForm/filler.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""Contains helpers for filling a PDF form."""
33

44
from io import BytesIO
5-
from typing import Dict, cast, Union, Tuple
5+
from typing import Dict, Tuple, Union, cast
66

77
from pypdf import PdfReader, PdfWriter
88
from pypdf.generic import DictionaryObject
@@ -30,18 +30,12 @@
3030

3131

3232
def check_radio_handler(
33-
widget: dict,
34-
middleware: Union[Checkbox, Radio],
35-
radio_button_tracker: dict
36-
) -> Tuple[
37-
Text, Union[float, int], Union[float, int], bool
38-
]:
33+
widget: dict, middleware: Union[Checkbox, Radio], radio_button_tracker: dict
34+
) -> Tuple[Text, Union[float, int], Union[float, int], bool]:
3935
"""Handles draw parameters for checkbox and radio button widgets."""
4036

4137
font_size = (
42-
checkbox_radio_font_size(widget)
43-
if middleware.size is None
44-
else middleware.size
38+
checkbox_radio_font_size(widget) if middleware.size is None else middleware.size
4539
)
4640
to_draw = checkbox_radio_to_draw(middleware, font_size)
4741
x, y = get_draw_checkbox_radio_coordinates(widget, to_draw)
@@ -59,9 +53,7 @@ def check_radio_handler(
5953

6054

6155
def signature_image_handler(
62-
widget: dict,
63-
middleware: Union[Signature, Image],
64-
images_to_draw: list
56+
widget: dict, middleware: Union[Signature, Image], images_to_draw: list
6557
) -> bool:
6658
"""Handles draw parameters for signature and image widgets."""
6759

@@ -70,9 +62,7 @@ def signature_image_handler(
7062
if stream is not None:
7163
any_image_to_draw = True
7264
stream = any_image_to_jpg(stream)
73-
x, y, width, height = get_draw_image_coordinates_resolutions(
74-
widget
75-
)
65+
x, y, width, height = get_draw_image_coordinates_resolutions(widget)
7666
images_to_draw.append(
7767
[
7868
stream,
@@ -87,16 +77,11 @@ def signature_image_handler(
8777

8878

8979
def text_handler(
90-
widget: dict,
91-
middleware: Text
92-
) -> Tuple[
93-
Text, Union[float, int], Union[float, int], bool
94-
]:
80+
widget: dict, middleware: Text
81+
) -> Tuple[Text, Union[float, int], Union[float, int], bool]:
9582
"""Handles draw parameters for text field widgets."""
9683

97-
middleware.text_line_x_coordinates = get_text_line_x_coordinates(
98-
widget, middleware
99-
)
84+
middleware.text_line_x_coordinates = get_text_line_x_coordinates(widget, middleware)
10085
x, y = get_draw_text_coordinates(widget, middleware)
10186
to_draw = middleware
10287
text_needs_to_be_drawn = True
@@ -147,7 +132,9 @@ def fill(
147132
widget_dict, widgets[key], images_to_draw[page]
148133
)
149134
else:
150-
to_draw, x, y, text_needs_to_be_drawn = text_handler(widget_dict, widgets[key])
135+
to_draw, x, y, text_needs_to_be_drawn = text_handler(
136+
widget_dict, widgets[key]
137+
)
151138

152139
if all(
153140
[

PyPDFForm/template.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,7 @@ def split_characters_into_lines(
306306
for each in characters:
307307
line_extended = f"{current_line} {each}" if current_line else each
308308
if (
309-
stringWidth(
310-
line_extended, middleware.font, middleware.font_size
311-
)
309+
stringWidth(line_extended, middleware.font, middleware.font_size)
312310
<= width
313311
):
314312
current_line = line_extended
@@ -324,9 +322,7 @@ def split_characters_into_lines(
324322
return lines
325323

326324

327-
def adjust_each_line(
328-
lines: List[str], middleware: Text, width: float
329-
) -> List[str]:
325+
def adjust_each_line(lines: List[str], middleware: Text, width: float) -> List[str]:
330326
"""
331327
Given a list of strings which is the return value of
332328
`split_characters_into_lines`, further adjusts each line
@@ -339,10 +335,7 @@ def adjust_each_line(
339335
tracker = ""
340336
for char in each:
341337
check = tracker + char
342-
if (
343-
stringWidth(check, middleware.font, middleware.font_size)
344-
> width
345-
):
338+
if stringWidth(check, middleware.font, middleware.font_size) > width:
346339
result.append(tracker)
347340
tracker = char
348341
else:
@@ -383,7 +376,9 @@ def get_paragraph_lines(widget: dict, widget_middleware: Text) -> List[str]:
383376
width = abs(float(widget[Rect][0]) - float(widget[Rect][2]))
384377

385378
split_by_new_line_symbol = value.split(NEW_LINE_SYMBOL)
386-
lines = split_characters_into_lines(split_by_new_line_symbol, widget_middleware, width)
379+
lines = split_characters_into_lines(
380+
split_by_new_line_symbol, widget_middleware, width
381+
)
387382

388383
return adjust_each_line(lines, widget_middleware, width)
389384

0 commit comments

Comments
 (0)