Skip to content

Commit

Permalink
Merge pull request #510 from chinapandaman/PPF-438
Browse files Browse the repository at this point in the history
PPF-438: v3 revamp
  • Loading branch information
chinapandaman authored Feb 17, 2024
2 parents aec93b0 + 19062e7 commit b6e3d9e
Show file tree
Hide file tree
Showing 22 changed files with 200 additions and 215 deletions.
File renamed without changes.
27 changes: 26 additions & 1 deletion PyPDFForm/core/constants.py → PyPDFForm/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# -*- coding: utf-8 -*-
"""Contains constants used for core layer."""
"""Contains library constants."""

from typing import Union

from .middleware.checkbox import Checkbox
from .middleware.dropdown import Dropdown
from .middleware.radio import Radio
from .middleware.signature import Signature
from .middleware.text import Text

VERSION_IDENTIFIERS = [
b"%PDF-1.0",
b"%PDF-1.1",
b"%PDF-1.2",
b"%PDF-1.3",
b"%PDF-1.4",
b"%PDF-1.5",
b"%PDF-1.6",
b"%PDF-1.7",
b"%PDF-2.0",
]
VERSION_IDENTIFIER_PREFIX = b"%PDF-"

WIDGET_TYPES = Union[Text, Checkbox, Radio, Dropdown, Signature]

DEPRECATION_NOTICE = "{} will be deprecated soon. Use {} instead."

ANNOTATION_FIELD_KEY = "/T"
ANNOTATION_RECTANGLE_KEY = "/Rect"
Expand Down
5 changes: 3 additions & 2 deletions PyPDFForm/core/coordinate.py → PyPDFForm/coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
from pypdf import PdfReader
from reportlab.pdfbase.pdfmetrics import stringWidth

from ..middleware.text import Text
from .constants import (ANNOTATION_RECTANGLE_KEY,
COORDINATE_GRID_FONT_SIZE_MARGIN_RATIO, DEFAULT_FONT)
from .middleware.text import Text
from .template import (get_char_rect_width, get_widget_alignment,
is_text_multiline)
from .utils import stream_to_io
from .watermark import create_watermarks_and_draw, merge_watermarks_with_pdf
from .watermark import (create_watermarks_and_draw,
merge_watermarks_with_pdf)


def get_draw_checkbox_radio_coordinates(
Expand Down
Empty file removed PyPDFForm/core/__init__.py
Empty file.
8 changes: 4 additions & 4 deletions PyPDFForm/core/filler.py → PyPDFForm/filler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

from typing import Dict

from ..middleware.checkbox import Checkbox
from ..middleware.constants import WIDGET_TYPES
from ..middleware.radio import Radio
from ..middleware.signature import Signature
from .constants import WIDGET_TYPES
from .coordinate import (get_draw_checkbox_radio_coordinates,
get_draw_sig_coordinates_resolutions,
get_draw_text_coordinates,
Expand All @@ -16,6 +13,9 @@
from .template import get_widget_key, get_widgets_by_page
from .utils import checkbox_radio_to_draw
from .watermark import create_watermarks_and_draw, merge_watermarks_with_pdf
from .middleware.checkbox import Checkbox
from .middleware.radio import Radio
from .middleware.signature import Signature


def fill(
Expand Down
6 changes: 1 addition & 5 deletions PyPDFForm/core/font.py → PyPDFForm/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
from reportlab.pdfbase.ttfonts import TTFError, TTFont

from .constants import (ANNOTATION_RECTANGLE_KEY, DEFAULT_FONT,
DEFAULT_FONT_SIZE, FONT_COLOR_IDENTIFIER,
FONT_COLOR_IDENTIFIER,
FONT_SIZE_IDENTIFIER)
from .patterns import TEXT_FIELD_APPEARANCE_PATTERNS
from .template import is_text_multiline
from .utils import traverse_pattern


Expand Down Expand Up @@ -84,9 +83,6 @@ def text_field_font_size(widget: dict) -> Union[float, int]:
given a text field widget.
"""

if is_text_multiline(widget):
return DEFAULT_FONT_SIZE

height = abs(
float(widget[ANNOTATION_RECTANGLE_KEY][1])
- float(widget[ANNOTATION_RECTANGLE_KEY][3])
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion PyPDFForm/middleware/checkbox.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Contains checkbox middleware."""

from .widget import Widget
from .base import Widget


class Checkbox(Widget):
Expand Down
27 changes: 0 additions & 27 deletions PyPDFForm/middleware/constants.py

This file was deleted.

2 changes: 1 addition & 1 deletion PyPDFForm/middleware/dropdown.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Contains dropdown middleware."""

from .widget import Widget
from .base import Widget


class Dropdown(Widget):
Expand Down
2 changes: 1 addition & 1 deletion PyPDFForm/middleware/radio.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Contains radio middleware."""

from .widget import Widget
from .base import Widget


class Radio(Widget):
Expand Down
4 changes: 2 additions & 2 deletions PyPDFForm/middleware/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from os.path import expanduser
from typing import BinaryIO, Union

from .adapter import fp_or_f_obj_or_stream_to_stream
from .widget import Widget
from ..adapter import fp_or_f_obj_or_stream_to_stream
from .base import Widget


class Signature(Widget):
Expand Down
134 changes: 0 additions & 134 deletions PyPDFForm/middleware/template.py

This file was deleted.

2 changes: 1 addition & 1 deletion PyPDFForm/middleware/text.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Contains text middleware."""

from .widget import Widget
from .base import Widget


class Text(Widget):
Expand Down
10 changes: 5 additions & 5 deletions PyPDFForm/core/patterns.py → PyPDFForm/patterns.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# -*- coding: utf-8 -*-
"""Contains patterns used for identifying properties of widgets."""

from ..middleware.checkbox import Checkbox
from ..middleware.dropdown import Dropdown
from ..middleware.radio import Radio
from ..middleware.signature import Signature
from ..middleware.text import Text
from .constants import (ANNOTATION_FIELD_KEY, BUTTON_IDENTIFIER,
BUTTON_STYLE_IDENTIFIER, CHOICE_FIELD_IDENTIFIER,
CHOICES_IDENTIFIER, FIELD_FLAG_KEY, PARENT_KEY,
Expand All @@ -14,6 +9,11 @@
TEXT_FIELD_APPEARANCE_IDENTIFIER,
TEXT_FIELD_IDENTIFIER, WIDGET_SUBTYPE_KEY,
WIDGET_TYPE_KEY)
from .middleware.checkbox import Checkbox
from .middleware.dropdown import Dropdown
from .middleware.radio import Radio
from .middleware.signature import Signature
from .middleware.text import Text

WIDGET_TYPE_PATTERNS = [
(
Expand Down
Loading

0 comments on commit b6e3d9e

Please sign in to comment.