Skip to content

Commit c82ea40

Browse files
author
black-isort-bot
committed
[skip ci]: black/isort
1 parent 8fb462c commit c82ea40

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

PyPDFForm/core/filler.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,12 @@ def fill(
109109
texts_to_draw[page].append(
110110
[
111111
elements[key],
112-
TemplateCore().get_draw_text_coordinates(_element, elements[key])[0],
113-
TemplateCore().get_draw_text_coordinates(_element, elements[key])[1],
112+
TemplateCore().get_draw_text_coordinates(
113+
_element, elements[key]
114+
)[0],
115+
TemplateCore().get_draw_text_coordinates(
116+
_element, elements[key]
117+
)[1],
114118
]
115119
)
116120
if sejda:
@@ -268,7 +272,9 @@ def fill_v2(
268272
_element, elements[key]
269273
)
270274
else:
271-
x, y = TemplateCore().get_draw_text_coordinates(_element, elements[key])
275+
x, y = TemplateCore().get_draw_text_coordinates(
276+
_element, elements[key]
277+
)
272278

273279
texts_to_draw[page].append(
274280
[

PyPDFForm/core/template.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -295,24 +295,25 @@ def get_draw_checkbox_radio_coordinates_v2(
295295

296296
@staticmethod
297297
def get_draw_text_coordinates(
298-
element: "pdfrw.PdfDict",
299-
element_middleware: "ElementMiddleware"
298+
element: "pdfrw.PdfDict", element_middleware: "ElementMiddleware"
300299
) -> Tuple[Union[float, int], Union[float, int]]:
301300
"""Returns coordinates to draw text at given a PDF form text element."""
302301

303302
x = float(element[TemplateCoreConstants().annotation_rectangle_key][0])
304303
y = (
305-
float(element[TemplateCoreConstants().annotation_rectangle_key][1])
306-
+ float(element[TemplateCoreConstants().annotation_rectangle_key][3])
307-
) / 2 - 2
304+
float(element[TemplateCoreConstants().annotation_rectangle_key][1])
305+
+ float(element[TemplateCoreConstants().annotation_rectangle_key][3])
306+
) / 2 - 2
308307

309-
alignment = element[TemplateCoreConstants().text_field_alignment_identifier] or 0
308+
alignment = (
309+
element[TemplateCoreConstants().text_field_alignment_identifier] or 0
310+
)
310311
if int(alignment) == 1:
311312
length = len(element_middleware.value)
312313
width = element_middleware.font_size * length * 96 / 72
313314
c_half_width = (
314-
float(element[TemplateCoreConstants().annotation_rectangle_key][0])
315-
+ float(element[TemplateCoreConstants().annotation_rectangle_key][2])
315+
float(element[TemplateCoreConstants().annotation_rectangle_key][0])
316+
+ float(element[TemplateCoreConstants().annotation_rectangle_key][2])
316317
) / 2
317318
x = (c_half_width - width / 2.9 + c_half_width) / 2
318319

tests/functional/scenario/test_issues.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ def test_pdf_form_with_pages_without_elements_v1(issue_pdf_directory):
2828

2929

3030
def test_pdf_form_with_central_aligned_text_fields(issue_pdf_directory):
31-
obj = PyPDFForm2(
32-
os.path.join(issue_pdf_directory, "PPF-285.pdf")
33-
).fill({
34-
"name": "Hans Mustermann",
35-
"fulladdress": "Musterstr. 12, 82903 Musterdorf, Musterland",
36-
"advisorname": "Karl Test"
37-
})
31+
obj = PyPDFForm2(os.path.join(issue_pdf_directory, "PPF-285.pdf")).fill(
32+
{
33+
"name": "Hans Mustermann",
34+
"fulladdress": "Musterstr. 12, 82903 Musterdorf, Musterland",
35+
"advisorname": "Karl Test",
36+
}
37+
)
3838

3939
with open(os.path.join(issue_pdf_directory, "PPF-285-expected.pdf"), "rb+") as f:
4040
expected = f.read()

0 commit comments

Comments
 (0)