Skip to content

Commit

Permalink
Expand constructor assignments
Browse files Browse the repository at this point in the history
This is longer, but cleaner.
Imagine you have to edit it and assignment order gets wrong :P

BTW, normalize PdfFormEnv constructor param order.
  • Loading branch information
mara004 committed Apr 4, 2024
1 parent ccfe923 commit 2360165
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/pypdfium2/_helpers/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class PdfAttachment (pdfium_i.AutoCastable):


def __init__(self, raw, pdf):
self.raw, self.pdf = raw, pdf
self.raw = raw
self.pdf = pdf


def get_name(self):
Expand Down
18 changes: 12 additions & 6 deletions src/pypdfium2/_helpers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def init_forms(self, config=None):
raw = pdfium_c.FPDFDOC_InitFormFillEnvironment(self, config)
if not raw:
raise PdfiumError(f"Initializing form env failed for document {self}.")
self.formenv = PdfFormEnv(raw, config, self)
self.formenv = PdfFormEnv(raw, self, config)
self._add_kid(self.formenv)

if formtype in (pdfium_c.FORMTYPE_XFA_FULL, pdfium_c.FORMTYPE_XFA_FOREGROUND):
Expand Down Expand Up @@ -543,8 +543,10 @@ class PdfFormEnv (pdfium_i.AutoCloseable):
Parent document this form env belongs to.
"""

def __init__(self, raw, config, pdf):
self.raw, self.config, self.pdf = raw, config, pdf
def __init__(self, raw, pdf, config):
self.raw = raw
self.pdf = pdf
self.config = config
super().__init__(PdfFormEnv._close_impl, self.config, self.pdf)

@property
Expand All @@ -568,7 +570,8 @@ class PdfXObject (pdfium_i.AutoCloseable):
"""

def __init__(self, raw, pdf):
self.raw, self.pdf = raw, pdf
self.raw = raw
self.pdf = pdf
super().__init__(pdfium_c.FPDF_CloseXObject)

@property
Expand Down Expand Up @@ -629,7 +632,9 @@ class PdfBookmark (pdfium_i.AutoCastable):
"""

def __init__(self, raw, pdf, level):
self.raw, self.pdf, self.level = raw, pdf, level
self.raw = raw
self.pdf = pdf
self.level = level

def get_title(self):
"""
Expand Down Expand Up @@ -670,7 +675,8 @@ class PdfDest (pdfium_i.AutoCastable):
"""

def __init__(self, raw, pdf):
self.raw, self.pdf = raw, pdf
self.raw = raw
self.pdf = pdf

def get_index(self):
"""
Expand Down
3 changes: 0 additions & 3 deletions src/pypdfium2/_helpers/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,14 @@ class PdfMatrix:
def __init__(self, a=1, b=0, c=0, d=1, e=0, f=0):
self.a, self.b, self.c, self.d, self.e, self.f = a, b, c, d, e, f


def __repr__(self):
return f"PdfMatrix{self.get()}"


def __eq__(self, other):
if type(self) is not type(other):
return False
return (self.get() == other.get())


@property
def _as_parameter_(self):
return ctypes.byref( self.to_raw() )
Expand Down
4 changes: 3 additions & 1 deletion src/pypdfium2/_helpers/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class PdfPage (pdfium_i.AutoCloseable):
"""

def __init__(self, raw, pdf, formenv):
self.raw, self.pdf, self.formenv = raw, pdf, formenv
self.raw = raw
self.pdf = pdf
self.formenv = formenv
super().__init__(PdfPage._close_impl, self.formenv)


Expand Down
5 changes: 4 additions & 1 deletion src/pypdfium2/_helpers/pageobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ def __new__(cls, raw, *args, **kwargs):

def __init__(self, raw, page=None, pdf=None, level=0):

self.raw, self.page, self.pdf, self.level = raw, page, pdf, level
self.raw = raw
self.page = page
self.pdf = pdf
self.level = level

if page is not None:
if self.pdf is None:
Expand Down

0 comments on commit 2360165

Please sign in to comment.