Skip to content

Commit

Permalink
Merge pull request #730 from chinapandaman/PPF-729
Browse files Browse the repository at this point in the history
PPF-729: support alpha band for create widget color params
  • Loading branch information
chinapandaman authored Sep 21, 2024
2 parents 92aceef + 10b302a commit 49f5c95
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[MESSAGES CONTROL]
disable=C0103, R0913, R0902, R0903, R0914, C0209, C0123
disable=C0103, R0913, R0902, R0903, R0914, C0209, C0123, R0917
1 change: 1 addition & 0 deletions PyPDFForm/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(
value[0],
value[1],
value[2],
value[3] if len(value) == 4 else 1,
)
self.acro_form_params[param] = value
elif user_input in self.NONE_DEFAULTS:
Expand Down
6 changes: 3 additions & 3 deletions docs/prepare.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ new_form = PdfWrapper("dummy.pdf").create_widget(
font="Courier", # optional
font_size=15, # optional
font_color=(1, 0, 0), # optional
bg_color=(0, 0, 1), # optional
bg_color=(0, 0, 1, 1), # optional, (r, g, b, alpha)
border_color=(1, 0, 0), # optional
border_width=5, # optional
alignment=0, # optional, 0=left, 1=center, 2=right
Expand All @@ -65,7 +65,7 @@ new_form = PdfWrapper("dummy.pdf").create_widget(
size=30, # optional
button_style="check", # optional
tick_color=(0, 1, 0), # optional
bg_color=(0, 0, 1), # optional
bg_color=(0, 0, 1, 1), # optional, (r, g, b, alpha)
border_color=(1, 0, 0), # optional
border_width=5 # optional
)
Expand Down Expand Up @@ -100,7 +100,7 @@ new_form = PdfWrapper("dummy.pdf").create_widget(
font="Courier", # optional
font_size=15, # optional
font_color=(1, 0, 0), # optional
bg_color=(0, 0, 1), # optional
bg_color=(0, 0, 1, 1), # optional, (r, g, b, alpha)
border_color=(1, 0, 0), # optional
border_width=5 # optional
)
Expand Down
Binary file added pdf_samples/widget/create_text_alpha_bg_color.pdf
Binary file not shown.
22 changes: 22 additions & 0 deletions tests/test_create_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,28 @@ def test_create_text_default(template_stream, pdf_samples, request):
assert obj.stream == expected


def test_create_text_alpha_bg_color(template_stream, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "widget", "create_text_alpha_bg_color.pdf")
with open(expected_path, "rb+") as f:
obj = PdfWrapper(template_stream).create_widget(
"text",
"foo",
1,
100,
100,
bg_color=(0, 0, 1, 0),
)
assert obj.schema["properties"]["foo"]["type"] == "string"

request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()

expected = f.read()

assert len(obj.stream) == len(expected)
assert obj.stream == expected


def test_create_text_align_center(template_stream, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "widget", "create_text_align_center.pdf")
with open(expected_path, "rb+") as f:
Expand Down

0 comments on commit 49f5c95

Please sign in to comment.