Skip to content

Commit

Permalink
[skip ci]: black/isort
Browse files Browse the repository at this point in the history
  • Loading branch information
black-isort-bot committed Mar 25, 2024
1 parent 5d048b9 commit 2171bb3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 54 deletions.
34 changes: 8 additions & 26 deletions PyPDFForm/coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pypdf import PdfReader
from reportlab.pdfbase.pdfmetrics import stringWidth

from .constants import (Rect,
COORDINATE_GRID_FONT_SIZE_MARGIN_RATIO, DEFAULT_FONT)
from .constants import (COORDINATE_GRID_FONT_SIZE_MARGIN_RATIO, DEFAULT_FONT,
Rect)
from .middleware.text import Text
from .template import (get_char_rect_width, get_widget_alignment,
is_text_multiline)
Expand All @@ -23,14 +23,8 @@ def get_draw_checkbox_radio_coordinates(
"""Returns coordinates to draw at given a PDF form checkbox/radio widget."""

string_height = widget_middleware.font_size * 96 / 72
width_mid_point = (
float(widget[Rect][0])
+ float(widget[Rect][2])
) / 2
height_mid_point = (
float(widget[Rect][1])
+ float(widget[Rect][3])
) / 2
width_mid_point = (float(widget[Rect][0]) + float(widget[Rect][2])) / 2
height_mid_point = (float(widget[Rect][1]) + float(widget[Rect][3])) / 2

return (
width_mid_point
Expand All @@ -53,14 +47,8 @@ def get_draw_sig_coordinates_resolutions(

x = float(widget[Rect][0])
y = float(widget[Rect][1])
width = abs(
float(widget[Rect][0])
- float(widget[Rect][2])
)
height = abs(
float(widget[Rect][1])
- float(widget[Rect][3])
)
width = abs(float(widget[Rect][0]) - float(widget[Rect][2]))
height = abs(float(widget[Rect][1]) - float(widget[Rect][3]))

return x, y, width, height

Expand Down Expand Up @@ -97,10 +85,7 @@ def get_draw_text_coordinates(
x = float(widget[Rect][0])

if int(alignment) != 0:
width_mid_point = (
float(widget[Rect][0])
+ float(widget[Rect][2])
) / 2
width_mid_point = (float(widget[Rect][0]) + float(widget[Rect][2])) / 2
string_width = stringWidth(
text_value,
widget_middleware.font,
Expand Down Expand Up @@ -128,10 +113,7 @@ def get_draw_text_coordinates(
) / 2

string_height = widget_middleware.font_size * 96 / 72
height_mid_point = (
float(widget[Rect][1])
+ float(widget[Rect][3])
) / 2
height_mid_point = (float(widget[Rect][1]) + float(widget[Rect][3])) / 2
y = (height_mid_point - string_height / 2 + height_mid_point) / 2
if is_text_multiline(widget):
y = float(widget[Rect][3]) - string_height / 1.5
Expand Down
17 changes: 5 additions & 12 deletions PyPDFForm/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from reportlab.pdfbase.pdfmetrics import registerFont, standardFonts
from reportlab.pdfbase.ttfonts import TTFError, TTFont

from .constants import (Rect, DEFAULT_FONT,
FONT_COLOR_IDENTIFIER, FONT_SIZE_IDENTIFIER)
from .constants import (DEFAULT_FONT, FONT_COLOR_IDENTIFIER,
FONT_SIZE_IDENTIFIER, Rect)
from .patterns import TEXT_FIELD_APPEARANCE_PATTERNS
from .utils import traverse_pattern

Expand Down Expand Up @@ -82,10 +82,7 @@ def text_field_font_size(widget: dict) -> Union[float, int]:
given a text field widget.
"""

height = abs(
float(widget[Rect][1])
- float(widget[Rect][3])
)
height = abs(float(widget[Rect][1]) - float(widget[Rect][3]))

return height * 2 / 3

Expand All @@ -96,12 +93,8 @@ def checkbox_radio_font_size(widget: dict) -> Union[float, int]:
given a checkbox/radio button widget.
"""

area = abs(
float(widget[Rect][0])
- float(widget[Rect][2])
) * abs(
float(widget[Rect][1])
- float(widget[Rect][3])
area = abs(float(widget[Rect][0]) - float(widget[Rect][2])) * abs(
float(widget[Rect][1]) - float(widget[Rect][3])
)

return sqrt(area) * 72 / 96
Expand Down
21 changes: 5 additions & 16 deletions PyPDFForm/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from pypdf import PdfReader
from reportlab.pdfbase.pdfmetrics import stringWidth

from .constants import (Rect, COMB, DEFAULT_FONT_SIZE,
MULTILINE, NEW_LINE_SYMBOL, MaxLen,
WIDGET_TYPES)
from .constants import (COMB, DEFAULT_FONT_SIZE, MULTILINE, NEW_LINE_SYMBOL,
WIDGET_TYPES, MaxLen, Rect)
from .font import (auto_detect_font, get_text_field_font_color,
get_text_field_font_size, text_field_font_size)
from .middleware.checkbox import Checkbox
Expand Down Expand Up @@ -206,11 +205,7 @@ def construct_widget(widget: dict, key: str) -> Union[WIDGET_TYPES, None]:
def get_text_field_max_length(widget: dict) -> Union[int, None]:
"""Returns the max length of the text field if presented or None."""

return (
int(widget[MaxLen]) or None
if MaxLen in widget
else None
)
return int(widget[MaxLen]) or None if MaxLen in widget else None


def check_field_flag_bit(widget: dict, bit: int) -> bool:
Expand Down Expand Up @@ -269,10 +264,7 @@ def get_button_style(widget: dict) -> Union[str, None]:
def get_char_rect_width(widget: dict, widget_middleware: Text) -> float:
"""Returns rectangular width of each character for combed text fields."""

rect_width = abs(
float(widget[Rect][0])
- float(widget[Rect][2])
)
rect_width = abs(float(widget[Rect][0]) - float(widget[Rect][2]))
return rect_width / widget_middleware.max_length


Expand Down Expand Up @@ -306,10 +298,7 @@ def get_paragraph_lines(widget: dict, widget_middleware: Text) -> List[str]:
if widget_middleware.max_length is not None:
value = value[: widget_middleware.max_length]

width = abs(
float(widget[Rect][0])
- float(widget[Rect][2])
)
width = abs(float(widget[Rect][0]) - float(widget[Rect][2]))

split_by_new_line_symbol = value.split(NEW_LINE_SYMBOL)
for line in split_by_new_line_symbol:
Expand Down

0 comments on commit 2171bb3

Please sign in to comment.