Skip to content

Commit

Permalink
Start working on #182
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Mar 1, 2023
1 parent cd79ac2 commit 3eda6d1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Host,
DataTree,
VersionTargetVar,
V8StatusFile,
V8StatusFileName,
BinaryTargetVar,
BinaryTarget_None,
VerStatusFileName,
Expand Down Expand Up @@ -53,7 +53,7 @@ def install_handler():
else:
req_ver = int(req_ver)

had_v8 = (pl_dir / V8StatusFile).exists()
had_v8 = (pl_dir / V8StatusFileName).exists()
use_v8 = bool(int( os.environ.get("PDFIUM_USE_V8", 0) ))

if curr_ver != req_ver or had_v8 != use_v8:
Expand Down
8 changes: 3 additions & 5 deletions setupsrc/pypdfium2_setup/packaging_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
BinaryTarget_Auto = "auto"
BindingsFileName = "raw.py"
VerStatusFileName = ".pdfium_version.txt"
V8StatusFile = ".pdfium_is_v8.txt"
V8StatusFileName = ".pdfium_is_v8.txt"
HomeDir = Path.home()
SourceTree = Path(__file__).parents[2]
DataTree = SourceTree / "data"
Expand Down Expand Up @@ -255,10 +255,8 @@ def emplace_platfiles(pl_name):

ver_changes = dict()
ver_changes["V_LIBPDFIUM"] = ver_file.read_text().strip()
if pl_name == PlatformNames.sourcebuild:
ver_changes["V_BUILDNAME"] = "source"
else:
ver_changes["V_BUILDNAME"] = "pdfium-binaries"
ver_changes["V_BUILDNAME"] = "source" if pl_name == PlatformNames.sourcebuild else "pdfium-binaries"
ver_changes["V_PDFIUM_IS_V8"] = (pl_dir / V8StatusFileName).exists()
set_versions(ver_changes)

clean_platfiles()
Expand Down
4 changes: 2 additions & 2 deletions setupsrc/pypdfium2_setup/update_pdfium.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Host,
DataTree,
VerStatusFileName,
V8StatusFile,
V8StatusFileName,
ReleaseNames,
BinaryPlatforms,
ReleaseURL,
Expand Down Expand Up @@ -60,7 +60,7 @@ def _get_package(pl_name, version, robust, use_v8):
raise

if use_v8:
(pl_dir / V8StatusFile).touch(exist_ok=True)
(pl_dir / V8StatusFileName).touch(exist_ok=True)

return pl_name, fp

Expand Down
2 changes: 1 addition & 1 deletion src/pypdfium2/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_parser():
main_parser.add_argument(
"--version", "-v",
action = "version",
version = f"pypdfium2 {V_PYPDFIUM2} (libpdfium {V_LIBPDFIUM}, {V_BUILDNAME} build)",
version = f"pypdfium2 {V_PYPDFIUM2} (libpdfium {V_LIBPDFIUM}, {V_BUILDNAME} {'v8' if V_PDFIUM_IS_V8 else ''} build)",
)
subparsers = main_parser.add_subparsers(dest="subcommand")

Expand Down
25 changes: 16 additions & 9 deletions src/pypdfium2/_helpers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from concurrent.futures import ProcessPoolExecutor

import pypdfium2.raw as pdfium_c
from pypdfium2.version import V_PDFIUM_IS_V8
from pypdfium2._helpers.misc import PdfiumError
from pypdfium2._helpers.page import PdfPage
from pypdfium2._helpers.pageobjects import PdfObject
Expand Down Expand Up @@ -90,16 +91,10 @@ def __init__(
AutoCloseable.__init__(self, self._close_impl, self._data_holder, self._data_closer)

self.formenv = None
self.formtype = pdfium_c.FORMTYPE_NONE
self._has_forms = False
if may_init_forms:
self.formtype = pdfium_c.FPDF_GetFormType(self)
self._has_forms = self.formtype != pdfium_c.FORMTYPE_NONE # TODO maybe make public?
if self._has_forms:
formconfig = pdfium_c.FPDF_FORMFILLINFO(version=2)
raw = pdfium_c.FPDFDOC_InitFormFillEnvironment(self, formconfig)
self.formenv = PdfFormEnv(raw, formconfig, self)
else:
self.formtype = pdfium_c.FORMTYPE_NONE
self._has_forms = False
self._init_forms()


@property
Expand Down Expand Up @@ -139,6 +134,18 @@ def __delitem__(self, i):
self.del_page(i)


def _init_forms(self):
self.formtype = pdfium_c.FPDF_GetFormType(self)
self._has_forms = self.formtype != pdfium_c.FORMTYPE_NONE # TODO make public?
if self._has_forms:
if V_PDFIUM_IS_V8:
# BUG(182): would need a caller-provided form config ...
raise RuntimeError("pypdfium2's helpers do not support forms with V8 enabled binaries yet.")
formconfig = pdfium_c.FPDF_FORMFILLINFO(version=2)
raw = pdfium_c.FPDFDOC_InitFormFillEnvironment(self, formconfig)
self.formenv = PdfFormEnv(raw, formconfig, self)


@classmethod
def new(cls):
"""
Expand Down
5 changes: 3 additions & 2 deletions src/pypdfium2/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: 2023 geisserml <[email protected]>
# SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause

__all__ = ["V_PYPDFIUM2", "V_LIBPDFIUM", "V_BUILDNAME"]
__all__ = ["V_PYPDFIUM2", "V_LIBPDFIUM", "V_BUILDNAME", "V_PDFIUM_IS_V8"]

V_MAJOR = 4
V_MINOR = 0
Expand All @@ -19,4 +19,5 @@
#: String describing the included PDFium binary's origin (pdfium-binaries, sourcebuild)
V_BUILDNAME = "pdfium-binaries"

# TODO add info whether it's a V8 build or not
#: Whether the included PDFium binary was built with V8 support or not
V_PDFIUM_IS_V8 = False

0 comments on commit 3eda6d1

Please sign in to comment.