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 Oct 17, 2023
1 parent a953bca commit af31eea
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
16 changes: 11 additions & 5 deletions PyPDFForm/core/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ def get_text_field_font_size(element: pdfrw.PdfDict) -> Union[float, int]:
return result


def get_text_field_font_color(element: pdfrw.PdfDict) -> Union[Tuple[float, float, float], None]:
def get_text_field_font_color(
element: pdfrw.PdfDict,
) -> Union[Tuple[float, float, float], None]:
"""Returns the font color tuple of the text field if presented or black."""

result = (0, 0, 0)
Expand All @@ -167,12 +169,16 @@ def get_text_field_font_color(element: pdfrw.PdfDict) -> Union[Tuple[float, floa
if constants.FONT_COLOR_IDENTIFIER not in text_appearance:
return result

text_appearance = text_appearance.replace("(", "").replace(")", "").split(" ")
text_appearance = (
text_appearance.replace("(", "").replace(")", "").split(" ")
)
for i, val in enumerate(text_appearance):
if val == constants.FONT_COLOR_IDENTIFIER.replace(" ", ""):
result = (float(text_appearance[i - 3]),
float(text_appearance[i - 2]),
float(text_appearance[i - 1]))
result = (
float(text_appearance[i - 3]),
float(text_appearance[i - 2]),
float(text_appearance[i - 1]),
)
break

return result
Expand Down
4 changes: 3 additions & 1 deletion PyPDFForm/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def update_text_field_attributes(
_element
) or font_size_core.text_field_font_size(_element)
if elements[key].font_color is None:
elements[key].font_color = template.get_text_field_font_color(_element)
elements[key].font_color = template.get_text_field_font_color(
_element
)
if (
template.is_text_multiline(_element)
and elements[key].text_wrap_length is None
Expand Down
4 changes: 1 addition & 3 deletions PyPDFForm/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def __init__(
if isinstance(each, Text):
each.font = kwargs.get("global_font", constants.GLOBAL_FONT)
each.font_size = kwargs.get("global_font_size")
each.font_color = kwargs.get(
"global_font_color"
)
each.font_color = kwargs.get("global_font_color")

def read(self) -> bytes:
"""Reads the file stream of a PDF form."""
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def sejda_template_complex(pdf_samples):

@pytest.fixture
def sample_template_with_font_colors(pdf_samples):
with open(os.path.join(pdf_samples, "sample_template_with_font_colors.pdf"), "rb+") as f:
with open(
os.path.join(pdf_samples, "sample_template_with_font_colors.pdf"), "rb+"
) as f:
return f.read()


Expand Down
6 changes: 2 additions & 4 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,15 @@ def test_version(pdf_samples):
assert obj.version is None


def test_fill_font_color(
sample_template_with_font_colors, pdf_samples, request
):
def test_fill_font_color(sample_template_with_font_colors, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "test_fill_font_color.pdf")
with open(expected_path, "rb+") as f:
obj = PyPDFForm(sample_template_with_font_colors).fill(
{
"red_12": "red",
"green_14": "green",
"blue_16": "blue",
"mixed_auto": "mixed"
"mixed_auto": "mixed",
},
)

Expand Down

0 comments on commit af31eea

Please sign in to comment.