Skip to content

Commit

Permalink
release v2.0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisschellekens committed Aug 7, 2022
1 parent b6a8278 commit 06f64f5
Show file tree
Hide file tree
Showing 640 changed files with 721 additions and 442 deletions.
96 changes: 48 additions & 48 deletions borb/io/read/postfix/postfix_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ def evaluate(s: str, args: typing.List[Decimal]) -> typing.List[Decimal]:
continue
# exp
if operator == "exp":
assert (
len(stk) >= 1
), "Unable to apply operator exp, stack underflow"
# fmt: off
assert len(stk) >= 1, "Unable to apply operator exp, stack underflow"
# fmt: on
x = stk[-1]
assert isinstance(x, Decimal)
stk.pop(len(stk) - 1)
Expand All @@ -247,9 +247,9 @@ def evaluate(s: str, args: typing.List[Decimal]) -> typing.List[Decimal]:
continue
# floor
if operator == "floor":
assert (
len(stk) >= 1
), "Unable to apply operator floor, stack underflow"
# fmt: off
assert len(stk) >= 1, "Unable to apply operator floor, stack underflow"
# fmt: on
x = stk[-1]
assert isinstance(x, Decimal)
stk.pop(len(stk) - 1)
Expand Down Expand Up @@ -279,18 +279,18 @@ def evaluate(s: str, args: typing.List[Decimal]) -> typing.List[Decimal]:
continue
# idiv
if operator == "idiv":
assert (
len(stk) >= 2
), "Unable to apply operator idiv, stack underflow"
# fmt: off
assert len(stk) >= 2, "Unable to apply operator idiv, stack underflow"
# fmt: on
x = stk[-1]
y = stk[-2]
assert isinstance(x, Decimal)
assert isinstance(y, Decimal)
stk.pop(len(stk) - 1)
stk.pop(len(stk) - 1)
assert x != Decimal(
0
), "Unable to apply operator idiv, division by zero"
# fmt: off
assert x != Decimal(0), "Unable to apply operator idiv, division by zero"
# fmt: on
stk.append(Decimal(int(y / x)))
continue
# le
Expand All @@ -314,9 +314,9 @@ def evaluate(s: str, args: typing.List[Decimal]) -> typing.List[Decimal]:
continue
# log
if operator == "log":
assert (
len(stk) >= 1
), "Unable to apply operator log, stack underflow"
# fmt: off
assert len(stk) >= 1, "Unable to apply operator log, stack underflow"
# fmt: on
x = stk[-1]
assert isinstance(x, Decimal)
stk.pop(len(stk) - 1)
Expand All @@ -335,25 +335,25 @@ def evaluate(s: str, args: typing.List[Decimal]) -> typing.List[Decimal]:
continue
# mod
if operator == "mod":
assert (
len(stk) >= 2
), "Unable to apply operator mod, stack underflow"
# fmt: off
assert len(stk) >= 2, "Unable to apply operator mod, stack underflow"
# fmt: on
x = stk[-1]
y = stk[-2]
assert isinstance(x, Decimal)
assert isinstance(y, Decimal)
stk.pop(len(stk) - 1)
stk.pop(len(stk) - 1)
assert y != Decimal(
0
), "Unable to apply operator mod, division by zero"
# fmt: off
assert y != Decimal(0), "Unable to apply operator mod, division by zero"
# fmt: on
stk.append(Decimal(int(y) % int(x)))
continue
# mul
if operator == "mul":
assert (
len(stk) >= 2
), "Unable to apply operator mul, stack underflow"
# fmt: off
assert len(stk) >= 2, "Unable to apply operator mul, stack underflow"
# fmt: on
x = stk[-1]
y = stk[-2]
assert isinstance(x, Decimal)
Expand All @@ -373,19 +373,19 @@ def evaluate(s: str, args: typing.List[Decimal]) -> typing.List[Decimal]:
continue
# neg
if operator == "neg":
assert (
len(stk) >= 1
), "Unable to apply operator neg, stack underflow"
# fmt: off
assert len(stk) >= 1, "Unable to apply operator neg, stack underflow"
# fmt: on
x = stk[-1]
assert isinstance(x, Decimal)
stk.pop(len(stk) - 1)
stk.append(-x)
continue
# not
if operator == "not":
assert (
len(stk) >= 1
), "Unable to apply operator not, stack underflow"
# fmt: off
assert len(stk) >= 1, "Unable to apply operator not, stack underflow"
# fmt: on
x = stk[-1]
assert isinstance(x, bool)
stk.pop(len(stk) - 1)
Expand All @@ -404,46 +404,46 @@ def evaluate(s: str, args: typing.List[Decimal]) -> typing.List[Decimal]:
continue
# pop
if operator == "pop":
assert (
len(stk) >= 1
), "Unable to apply operator pop, stack underflow"
# fmt: off
assert len(stk) >= 1, "Unable to apply operator pop, stack underflow"
# fmt: on
stk.pop(-1)
continue
# round
if operator == "round":
assert (
len(stk) >= 1
), "Unable to apply operator round, stack underflow"
# fmt: off
assert len(stk) >= 1, "Unable to apply operator round, stack underflow"
# fmt: on
x = stk[-1]
assert isinstance(x, Decimal)
stk.pop(len(stk) - 1)
stk.append(Decimal(round(x)))
continue
# sin
if operator == "sin":
assert (
len(stk) >= 1
), "Unable to apply operator sin, stack underflow"
# fmt: off
assert len(stk) >= 1, "Unable to apply operator sin, stack underflow"
# fmt: on
x = stk[-1]
assert isinstance(x, Decimal)
stk.pop(len(stk) - 1)
stk.append(Decimal(sin(degrees(x))))
continue
# sqrt
if operator == "sqrt":
assert (
len(stk) >= 1
), "Unable to apply operator sqrt, stack underflow"
# fmt: off
assert len(stk) >= 1, "Unable to apply operator sqrt, stack underflow"
# fmt: on
x = stk[-1]
assert isinstance(x, Decimal)
stk.pop(len(stk) - 1)
stk.append(Decimal(sqrt(x)))
continue
# sub
if operator == "sub":
assert (
len(stk) >= 2
), "Unable to apply operator sub, stack underflow"
# fmt: off
assert len(stk) >= 2, "Unable to apply operator sub, stack underflow"
# fmt: on
x = stk[-1]
y = stk[-2]
assert isinstance(x, Decimal)
Expand All @@ -458,9 +458,9 @@ def evaluate(s: str, args: typing.List[Decimal]) -> typing.List[Decimal]:
continue
# xor
if operator == "xor":
assert (
len(stk) >= 2
), "Unable to apply operator xor, stack underflow"
# fmt: off
assert len(stk) >= 2, "Unable to apply operator xor, stack underflow"
# fmt: on
x = stk[-1]
y = stk[-2]
assert isinstance(x, bool)
Expand Down
2 changes: 1 addition & 1 deletion borb/io/write/ascii_art/ascii_logo.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
borb version 2.0.31
borb version 2.0.32
Joris Schellekens
6 changes: 4 additions & 2 deletions borb/io/write/document/document_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ def transform(
This method writes a Document object to a byte stream
"""
# write header
assert context is not None
assert context.destination is not None
# fmt: off
assert context is not None, "A WriteTransformerState must be defined in order to write Document objects."
assert context.destination is not None, "A WriteTransformerState must be defined in order to write Document objects."
# fmt: on

context.destination.write(b"%PDF-1.7\n")
context.destination.write(b"%")
Expand Down
6 changes: 3 additions & 3 deletions borb/io/write/page/pages_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def transform(
"""
This method writes a /Pages Dictionary to a byte stream
"""
# fmt: off
assert isinstance(object_to_transform, Dictionary)
assert (
context is not None
), "A WriteTransformerState must be defined in order to write Pages Dictionary objects."
assert context is not None, "A WriteTransformerState must be defined in order to write Pages Dictionary objects."
# fmt: on

# /Kids can be written immediately
object_to_transform[Name("Kids")].set_is_inline(True) # type: ignore [attr-defined]
Expand Down
8 changes: 4 additions & 4 deletions borb/io/write/reference/xref_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def transform(
assert isinstance(object_to_transform, XREF)
assert "Trailer" in object_to_transform
assert isinstance(object_to_transform["Trailer"], Dictionary)
assert (
context is not None
), "A WriteTransformerState must be defined in order to write XREF objects."
assert context.destination is not None
# fmt: off
assert context is not None, "A WriteTransformerState must be defined in order to write XREF objects."
assert context.destination is not None, "A WriteTransformerState must be defined in order to write XREF objects."
# fmt: on

# Transform the Trailer dictionary (replacing objects by references)
# we do this upfront because the normal write_dictionary_transformer will write the dictionary first,
Expand Down
12 changes: 8 additions & 4 deletions borb/io/write/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ def _start_object(
It also does some bookkeeping to ensure the byte offset is stored in the XREF
"""
# get offset position
assert context is not None
assert context.destination is not None
# fmt: off
assert context is not None, "A WriteTransformerState must be defined in order to write indirect objects."
assert context.destination is not None, "A WriteTransformerState must be defined in order to write indirect objects."
# fmt: on
byte_offset = context.destination.tell()

# update offset
Expand All @@ -146,8 +148,10 @@ def _end_object(
This function writes the "endobj" bytes whenever a direct object needs to be closed
"""
# write endobj
assert context is not None
assert context.destination is not None
# fmt: off
assert context is not None, "A WriteTransformerState must be defined in order to write indirect objects."
assert context.destination is not None, "A WriteTransformerState must be defined in order to write indirect objects."
# fmt: on
context.destination.write(bytes("endobj\n\n", "latin1"))

@staticmethod
Expand Down
9 changes: 4 additions & 5 deletions borb/io/write/xmp/xmp_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ def transform(
This method writes an ET.Element (representing XMP meta information) to a byte stream
"""
assert isinstance(object_to_transform, ET.Element)
assert (
context is not None
), "A WriteTransformerState must be defined in order to write XMP objects."
assert context.destination is not None
assert context.destination
# fmt: off
assert context is not None, "A WriteTransformerState must be defined in order to write XMP objects."
assert context.destination is not None, "A WriteTransformerState must be defined in order to write XMP objects."
# fmt: on

# build stream
out_value = Stream()
Expand Down
1 change: 1 addition & 0 deletions borb/pdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
from .canvas.layout.table.table import Table, TableCell
from .canvas.layout.table.fixed_column_width_table import FixedColumnWidthTable
from .canvas.layout.table.flexible_column_width_table import FlexibleColumnWidthTable
from .canvas.layout.table.table_util import TableUtil

# List
from .canvas.layout.list.list import List
Expand Down
17 changes: 5 additions & 12 deletions borb/pdf/canvas/layout/forms/check_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from borb.io.read.types import Boolean, Decimal
from borb.io.read.types import Decimal as bDecimal
from borb.io.read.types import String as bString
from borb.io.read.types import Dictionary, List, Name, Stream, String
from borb.pdf.canvas.color.color import Color, HexColor, RGBColor
from borb.pdf.canvas.font.simple_font.font_type_1 import StandardType1Font
Expand Down Expand Up @@ -97,20 +98,12 @@ def _init_widget_dictionary(self, page: Page, layout_box: Rectangle) -> None:
self._widget_dictionary[Name("F")] = bDecimal(4)
self._widget_dictionary[Name("Rect")] = List().set_is_inline(True) # type: ignore [attr-defined]
self._widget_dictionary["Rect"].append(bDecimal(layout_box.x))
self._widget_dictionary["Rect"].append(
bDecimal(layout_box.y + layout_box.height - self._font_size - 2)
)
self._widget_dictionary["Rect"].append(
bDecimal(layout_box.x + layout_box.width)
)
self._widget_dictionary["Rect"].append(
bDecimal(layout_box.y + layout_box.height)
)
self._widget_dictionary["Rect"].append(bDecimal(layout_box.y + layout_box.height - self._font_size - 2))
self._widget_dictionary["Rect"].append(bDecimal(layout_box.x + layout_box.width))
self._widget_dictionary["Rect"].append(bDecimal(layout_box.y + layout_box.height))
self._widget_dictionary[Name("FT")] = Name("Btn")
self._widget_dictionary[Name("P")] = catalog
self._widget_dictionary[
Name("T")
] = self._field_name or self._get_auto_generated_field_name(page)
self._widget_dictionary[Name("T")] = bString(self._field_name or self._get_auto_generated_field_name(page))
self._widget_dictionary[Name("V")] = Name("Yes")
self._widget_dictionary[Name("DR")] = widget_resources

Expand Down
8 changes: 4 additions & 4 deletions borb/pdf/canvas/layout/layout_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def __init__(
self._border_left = border_left

# border radii
assert border_radius_top_right >= 0
assert border_radius_top_left >= 0
assert border_radius_bottom_left >= 0
assert border_radius_bottom_right >= 0
assert border_radius_top_right >= 0, "border_radius_top_right must be a non-negative integer"
assert border_radius_top_left >= 0, "border_radius_top_left must be a non-negative integer"
assert border_radius_bottom_left >= 0, "border_radius_bottom_left must be a non-negative integer"
assert border_radius_bottom_right >= 0, "border_radius_bottom_right must be a non-negative integer"
self._border_radius_top_left: Decimal = border_radius_top_left
self._border_radius_top_right: Decimal = border_radius_top_right
self._border_radius_bottom_right: Decimal = border_radius_bottom_right
Expand Down
Loading

0 comments on commit 06f64f5

Please sign in to comment.