Skip to content

Commit

Permalink
release v2.1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisschellekens committed Nov 11, 2023
1 parent dcaaa69 commit 4365c9e
Show file tree
Hide file tree
Showing 957 changed files with 238,898 additions and 642 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,6 @@ dmypy.json
.prof

# secrets
tests/populate_keyring.py
tests/secrets.py

# End of https://www.toptal.com/developers/gitignore/api/python,pycharm
5 changes: 3 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
include borb/io/write/document/resources/*.icm
include borb/license/public_keys/*.pem
include borb/pdf/canvas/font/composite_font/cmaps/*
include borb/pdf/canvas/font/simple_font/afm/*.afm
include borb/pdf/canvas/layout/emoji/resources/*.png
include borb/pdf/canvas/layout/geography/geojson/*.geojson
include borb/pdf/canvas/layout/hyphenation/resources/*.json
include borb/pdf/canvas/lipsum/resources/*.json
include borb/license/public_keys/*.pem
include borb/pdf/canvas/lipsum/resources/*.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Corpus Coverage : 100.0%](https://img.shields.io/badge/corpus%20coverage-100.0%25-green)]()
[![Text Extraction : 93.1%](https://img.shields.io/badge/text%20extraction-93.1%25-green)]()
[![Public Method Documentation : 100%](https://img.shields.io/badge/public%20method%20documentation-100%25-green)]()
[![Number of Tests : 634](https://img.shields.io/badge/number%20of%20tests-634-green)]()
[![Number of Tests : 735](https://img.shields.io/badge/number%20of%20tests-735-green)]()
[![Python : 3.8 | 3.9 | 3.10 ](https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10-green)]()

[![Downloads](https://pepy.tech/badge/borb)](https://pepy.tech/project/borb)
Expand Down
2 changes: 1 addition & 1 deletion borb/io/filter/stream_decode_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
of its stream dictionary
"""
import typing
from decimal import Decimal

from borb.io.filter.ascii85_decode import ASCII85Decode
from borb.io.filter.flate_decode import FlateDecode
from borb.io.filter.lzw_decode import LZWDecode
from borb.io.filter.run_length_decode import RunLengthDecode
from borb.io.read.types import Decimal
from borb.io.read.types import Dictionary
from borb.io.read.types import List
from borb.io.read.types import Name
Expand Down
8 changes: 4 additions & 4 deletions borb/io/read/encryption/standard_security_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from borb.io.read.pdf_object import PDFObject
from borb.io.read.types import AnyPDFType
from borb.io.read.types import Boolean
from borb.io.read.types import Decimal
from borb.io.read.types import Decimal as bDecimal
from borb.io.read.types import Dictionary
from borb.io.read.types import HexadecimalString
from borb.io.read.types import Name
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(
# in the document, using the rules specified by the CF, StmF, and StrF entries.
# The default value if this entry is omitted shall be 0, but when present should be a
# value of 1 or greater.
self._v = int(encryption_dictionary.get("V", Decimal(0)))
self._v = int(encryption_dictionary.get("V", bDecimal(0)))

# (Required) A 32-byte string, based on the user password, that shall be
# used in determining whether to prompt the user for a password and, if so,
Expand Down Expand Up @@ -102,13 +102,13 @@ def __init__(
# (Optional; PDF 1.4; only if V is 2 or 3) The length of the encryption key, in bits.
# The value shall be a multiple of 8, in the range 40 to 128. Default value: 40.
# fmt: off
self._key_length: int = int(encryption_dictionary.get("Length", Decimal(40)))
self._key_length: int = int(encryption_dictionary.get("Length", bDecimal(40)))
assert self._key_length % 8 == 0, "The length of the encryption key, in bits must be a multiple of 8."
# fmt: on

# (Required) A number specifying which revision of the standard security
# handler shall be used to interpret this dictionary
self._revision: int = int(encryption_dictionary.get("R", Decimal(0)))
self._revision: int = int(encryption_dictionary.get("R", bDecimal(0)))

# (Optional; meaningful only when the value of V is 4; PDF 1.5) Indicates
# whether the document-level metadata stream (see 14.3.2, "Metadata
Expand Down
4 changes: 2 additions & 2 deletions borb/io/read/page/root_dictionary_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from borb.io.read.transformer import ReadTransformerState
from borb.io.read.transformer import Transformer
from borb.io.read.types import AnyPDFType
from borb.io.read.types import Decimal
from borb.io.read.types import Decimal as bDecimal
from borb.io.read.types import Dictionary
from borb.io.read.types import List as bList
from borb.io.read.types import Name
Expand Down Expand Up @@ -56,7 +56,7 @@ def _re_order_pages(self, root_dictionary: dict) -> None:
root_dictionary["Pages"][Name("Kids")] = bList()
for p in pages_in_order:
root_dictionary["Pages"]["Kids"].append(p)
root_dictionary["Pages"][Name("Count")] = Decimal(len(pages_in_order))
root_dictionary["Pages"][Name("Count")] = bDecimal(len(pages_in_order))

#
# PRIVATE
Expand Down
43 changes: 13 additions & 30 deletions borb/io/read/pdf_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
should be persisted, as well as some methods to traverse the object-graph.
"""
import copy
import decimal
import typing
from types import MethodType

import PIL

import borb.io.read.types


class PDFObject:
"""
Expand Down Expand Up @@ -40,27 +43,19 @@ def _to_json(self, memo_dict={}) -> typing.Any:
return self

# Boolean
from borb.io.read.types import Boolean

if isinstance(self, Boolean):
if isinstance(self, borb.io.read.types.Boolean):
return bool(self)

# CanvasOperatorName
from borb.io.read.types import CanvasOperatorName

if isinstance(self, CanvasOperatorName):
if isinstance(self, borb.io.read.types.CanvasOperatorName):
return str(self)

# (borb) Decimal
from borb.io.read.types import Decimal

if isinstance(self, Decimal):
if isinstance(self, borb.io.read.types.Decimal):
return float(self)

# (decimal) Decimal
from decimal import Decimal as oDecimal

if isinstance(self, oDecimal):
if isinstance(self, decimal.Decimal):
return float(self)

# float, int
Expand All @@ -72,9 +67,7 @@ def _to_json(self, memo_dict={}) -> typing.Any:
return str(self)

# Dictionary
from borb.io.read.types import Dictionary

if isinstance(self, Dictionary):
if isinstance(self, borb.io.read.types.Dictionary):
out: typing.Dict[str, typing.Any] = {}
memo_dict[id(self)] = out
for k, v in self.items():
Expand All @@ -90,17 +83,13 @@ def _to_json(self, memo_dict={}) -> typing.Any:
return dict_out

# Element
from borb.io.read.types import Element

if isinstance(self, Element):
if isinstance(self, borb.io.read.types.Element):
from borb.io.read.types import ET

return str(ET.tostring(self))

# Name
from borb.io.read.types import Name

if isinstance(self, Name):
if isinstance(self, borb.io.read.types.Name):
return str(self)

# Stream
Expand All @@ -110,28 +99,22 @@ def _to_json(self, memo_dict={}) -> typing.Any:
# DUPLICATE: Dictionary

# String
from borb.io.read.types import String

if isinstance(self, String):
if isinstance(self, borb.io.read.types.String):
return str(self)

# HexadecimalString
# DUPLICATE: String

# List
from borb.io.read.types import List

if isinstance(self, List):
if isinstance(self, borb.io.read.types.List):
list_out: typing.List[typing.Any] = []
memo_dict[id(self)] = list_out
for v in self:
list_out.append(PDFObject._to_json(v, memo_dict))
return list_out

# Reference
from borb.io.read.types import Reference

if isinstance(self, Reference):
if isinstance(self, borb.io.read.types.Reference):
return "%d %d R" % (self.generation_number or 0, self.object_number or 0)

# PIL.Image.Image
Expand Down
8 changes: 4 additions & 4 deletions borb/io/read/primitive/number_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from borb.io.read.transformer import ReadTransformerState
from borb.io.read.transformer import Transformer
from borb.io.read.types import AnyPDFType
from borb.io.read.types import Decimal
from borb.io.read.types import Decimal as bDecimal
from borb.pdf.canvas.event.event_listener import EventListener


Expand Down Expand Up @@ -38,7 +38,7 @@ def can_be_transformed(
"""
This function returns True if the object to be transformed is a Decimal object
"""
return isinstance(object, Decimal)
return isinstance(object, bDecimal)

def transform(
self,
Expand All @@ -51,6 +51,6 @@ def transform(
This function reads a Decimal from a byte stream
"""
# fmt: off
assert isinstance(object_to_transform, Decimal), "object_to_transform must be of type Decimal"
return Decimal(object_to_transform).set_parent(parent_object)
assert isinstance(object_to_transform, bDecimal), "object_to_transform must be of type Decimal"
return bDecimal(object_to_transform).set_parent(parent_object)
# fmt: on
4 changes: 2 additions & 2 deletions borb/io/read/tokenize/high_level_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from borb.io.read.types import AnyPDFType
from borb.io.read.types import Boolean
from borb.io.read.types import CanvasOperatorName
from borb.io.read.types import Decimal
from borb.io.read.types import Decimal as bDecimal
from borb.io.read.types import Dictionary
from borb.io.read.types import HexadecimalString
from borb.io.read.types import List
Expand Down Expand Up @@ -237,7 +237,7 @@ def read_object(self, xref: typing.Optional["XREF"] = None) -> typing.Optional[A
# numbers
if token.get_token_type() == TokenType.NUMBER:
self.seek(self.tell() + len(token.get_text()))
return Decimal(Decimal(token.get_text()))
return bDecimal(token.get_text())

# boolean
if token.get_token_type() == TokenType.OTHER and token.get_text() in [
Expand Down
2 changes: 1 addition & 1 deletion borb/io/write/primitive/number_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
This implementation of WriteBaseTransformer is responsible for writing Decimal objects
"""
import typing
from decimal import Decimal

from borb.io.read.types import AnyPDFType
from borb.io.read.types import Decimal
from borb.io.write.transformer import Transformer
from borb.io.write.transformer import WriteTransformerState

Expand Down
6 changes: 3 additions & 3 deletions borb/io/write/reference/xref_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import typing

from borb.io.read.types import AnyPDFType
from borb.io.read.types import Decimal
from borb.io.read.types import Decimal as bDecimal
from borb.io.read.types import Dictionary
from borb.io.read.types import Name
from borb.io.read.types import Reference
Expand Down Expand Up @@ -121,7 +121,7 @@ def transform(
if ("Trailer" in object_to_transform and "Size" in object_to_transform["Trailer"]):
trailer_out[Name("Size")] = object_to_transform["Trailer"]["Size"]
else:
trailer_out[Name("Size")] = Decimal(0) # we'll recalculate this later anyway
trailer_out[Name("Size")] = bDecimal(0) # we'll recalculate this later anyway
# fmt: on

# /ID
Expand Down Expand Up @@ -160,7 +160,7 @@ def transform(
)

# update /Size
trailer_out[Name("Size")] = Decimal(
trailer_out[Name("Size")] = bDecimal(
sum([len(v) for k, v in context.indirect_objects_by_hash.items()]) + 1
)

Expand Down
2 changes: 1 addition & 1 deletion borb/license/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ def get_version() -> str:
This function returns the current borb version
:return: the current borb version
"""
return "2.1.18"
return "2.1.19"
Loading

0 comments on commit 4365c9e

Please sign in to comment.