Skip to content

Commit

Permalink
release v2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisschellekens committed Sep 11, 2022
1 parent 8e94fad commit a4cad84
Show file tree
Hide file tree
Showing 482 changed files with 1,793 additions and 477 deletions.
2 changes: 1 addition & 1 deletion borb/datastructure/disjoint_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def pop(self, x: Any) -> "disjointset":
"""
Remove an element from this disjointset
"""
return self
raise NotImplementedError()

def sets(self) -> List[List[Any]]:
"""
Expand Down
2 changes: 1 addition & 1 deletion borb/io/read/image/ccitt_fax_image_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def transform(
add_base_methods(tmp)

# set parent
tmp.set_parent(parent_object) # type: ignore[attr-defined]
tmp.set_parent(parent_object) # type: ignore[attr-defined]

# return
return tmp
2 changes: 1 addition & 1 deletion borb/io/read/image/compressed_jpeg_image_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def transform(
add_base_methods(tmp)

# set parent
tmp.set_parent(parent_object) # type: ignore[attr-defined]
tmp.set_parent(parent_object) # type: ignore[attr-defined]

# return
return tmp
2 changes: 1 addition & 1 deletion borb/io/read/image/grayscale_image_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def transform(
add_base_methods(tmp)

# set parent
tmp.set_parent(parent_object) # type: ignore[attr-defined]
tmp.set_parent(parent_object) # type: ignore[attr-defined]

# return
return tmp
2 changes: 1 addition & 1 deletion borb/io/read/image/jbig2_image_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def transform(
add_base_methods(tmp)

# set parent
tmp.set_parent(parent_object) # type: ignore[attr-defined]
tmp.set_parent(parent_object) # type: ignore[attr-defined]

# return
return tmp
2 changes: 1 addition & 1 deletion borb/io/read/image/jpeg_2000_image_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def transform(
add_base_methods(tmp)

# set parent
tmp.set_parent(parent_object) # type: ignore[attr-defined]
tmp.set_parent(parent_object) # type: ignore[attr-defined]

# return
return tmp
2 changes: 1 addition & 1 deletion borb/io/read/image/jpeg_image_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def transform(
add_base_methods(tmp)

# set parent
tmp.set_parent(parent_object) # type: ignore[attr-defined]
tmp.set_parent(parent_object) # type: ignore[attr-defined]

# return
return tmp
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.1.0
borb version 2.1.1
Joris Schellekens
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
import typing
from typing import List

from borb.io.read.types import AnyPDFType, Name, String, HexadecimalString, Decimal as bDecimal
from borb.io.read.types import (
AnyPDFType,
Name,
String,
HexadecimalString,
Decimal as bDecimal,
)
from borb.io.write.font.copy_command_operator import CopyCommandOperator
from borb.pdf.canvas.font.font import Font
from borb.pdf.canvas.operator.text.show_text_with_glyph_positioning import (
Expand Down
4 changes: 2 additions & 2 deletions borb/io/write/font/subsetter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import typing
import zlib

from fontTools.subset import Subsetter as fSubsetter # type: ignore[import]
from fontTools.ttLib import TTFont # type: ignore[import]
from fontTools.subset import Subsetter as fSubsetter # type: ignore[import]
from fontTools.ttLib import TTFont # type: ignore[import]

from borb.io.read.types import Decimal as bDecimal, Name
from borb.io.write.font.character_set_listener import CharacterSetListener
Expand Down
12 changes: 6 additions & 6 deletions borb/io/write/image/image_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def _convert_to_rgb_mode(self, image: PILImage.Image) -> PILImage.Image:
if image_out.mode in ["RGBA", "LA"]:
fill_color = (255, 255, 255) # new background color
non_alpha_mode: str = image_out.mode[:-1]
background = PILImage.new(non_alpha_mode, # type: ignore[arg-type]
image_out.size,
fill_color)
background = PILImage.new(
non_alpha_mode, image_out.size, fill_color # type: ignore[arg-type]
)
background.paste(image_out, image_out.split()[-1]) # omit transparency
image_out = background

Expand All @@ -49,7 +49,7 @@ def _convert_to_rgb_mode(self, image: PILImage.Image) -> PILImage.Image:

# add methods
add_base_methods(image_out)
image_out.set_reference(image.get_reference()) # type: ignore[attr-defined]
image_out.set_reference(image.get_reference()) # type: ignore[attr-defined]

# return
return image_out
Expand Down Expand Up @@ -100,8 +100,8 @@ def transform(
out_value[Name("Bytes")] = contents

# copy reference
out_value.set_reference( # type: ignore [attr-defined]
object_to_transform.get_reference() # type: ignore [union-attr]
out_value.set_reference( # type: ignore [attr-defined]
object_to_transform.get_reference() # type: ignore [union-attr]
)

# start object if needed
Expand Down
6 changes: 4 additions & 2 deletions borb/io/write/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,13 @@ def get_reference(
"""
is_unique: bool = False
try:
is_unique = object.is_unique() # type: ignore[union-attr]
is_unique = object.is_unique() # type: ignore[union-attr]
except:
pass

# look up object by ID
obj_id = id(object)
if (not is_unique) and obj_id in context.indirect_objects_by_id:
if obj_id in context.indirect_objects_by_id:
cached_indirect_object: AnyPDFType = context.indirect_objects_by_id[obj_id]
assert not isinstance(cached_indirect_object, Reference)
return cached_indirect_object.get_reference() # type: ignore[union-attr]
Expand Down
7 changes: 7 additions & 0 deletions borb/pdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,36 @@
from .canvas.layout.image.barcode import Barcode
from .canvas.layout.image.barcode import BarcodeType
from .canvas.layout.image.chart import Chart

# Image
from .canvas.layout.image.image import Image
from .canvas.layout.layout_element import Alignment

# List
from .canvas.layout.list.list import List
from .canvas.layout.list.ordered_list import OrderedList
from .canvas.layout.list.roman_list import RomanNumeralOrderedList
from .canvas.layout.list.unordered_list import UnorderedList
from .canvas.layout.page_layout.multi_column_layout import MultiColumnLayout
from .canvas.layout.page_layout.multi_column_layout import SingleColumnLayout

# PageLayout
from .canvas.layout.page_layout.page_layout import PageLayout

# Shape
from .canvas.layout.shape.connected_shape import ConnectedShape
from .canvas.layout.shape.disconnected_shape import DisconnectedShape
from .canvas.layout.table.fixed_column_width_table import FixedColumnWidthTable
from .canvas.layout.table.flexible_column_width_table import FlexibleColumnWidthTable

# Table
from .canvas.layout.table.table import Table, TableCell
from .canvas.layout.table.table_util import TableUtil
from .canvas.layout.text.heading import Heading

# Paragraph
from .canvas.layout.text.paragraph import Paragraph

# Document, Page, PDF
from .document.document import Document
from .page.page import Page
Expand Down
6 changes: 3 additions & 3 deletions borb/pdf/canvas/event/image_render_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class ImageRenderEvent(Event):
This implementation of Event is triggered when an Image has been processed using a Do instruction
"""

def __init__(self, graphics_state: CanvasGraphicsState, image: PILImage): # type: ignore[valid-type]
self._image: PILImage = image # type: ignore[valid-type]
def __init__(self, graphics_state: CanvasGraphicsState, image: PILImage): # type: ignore[valid-type]
self._image: PILImage = image # type: ignore[valid-type]

# calculate position
v = graphics_state.ctm.cross(Decimal(0), Decimal(0), Decimal(1))
Expand All @@ -30,7 +30,7 @@ def __init__(self, graphics_state: CanvasGraphicsState, image: PILImage): # ty
self._width: Decimal = max(abs(v[0]), Decimal(1))
self._height: Decimal = max(abs(v[1]), Decimal(1))

def get_image(self) -> PILImage: # type: ignore[valid-type]
def get_image(self) -> PILImage: # type: ignore[valid-type]
"""
Get the (source) Image
This Image may have different dimensions than
Expand Down
28 changes: 10 additions & 18 deletions borb/pdf/canvas/layout/forms/drop_down_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ def _init_widget_dictionary(self, page: Page, layout_box: Rectangle) -> None:
)

# widget resource dictionary
widget_resources: Dictionary = Dictionary()
widget_resources: Dictionary = Dictionary().set_is_unique(True) # type: ignore [attr-defined]
widget_resources[Name("Font")] = page["Resources"]["Font"]

# widget normal appearance
widget_normal_appearance: Stream = Stream()
widget_normal_appearance: Stream = Stream().set_is_unique(True) # type: ignore [attr-defined]
widget_normal_appearance[Name("Type")] = Name("XObject")
widget_normal_appearance[Name("Subtype")] = Name("Form")
widget_normal_appearance[Name("BBox")] = List().set_is_inline(True) # type: ignore [attr-defined]
Expand All @@ -80,7 +80,7 @@ def _init_widget_dictionary(self, page: Page, layout_box: Rectangle) -> None:
widget_normal_appearance[Name("Resources")] = widget_resources
bts = bytes(
"1 1 1 rg 0 0 %f %f re f* /Tx BMC EMC"
% (layout_box.width, self._font_size),
% (float(layout_box.width), float(self._font_size)),
"latin1",
)
widget_normal_appearance[Name("DecodedBytes")] = bts
Expand All @@ -89,39 +89,31 @@ def _init_widget_dictionary(self, page: Page, layout_box: Rectangle) -> None:
widget_normal_appearance[Name("Length")] = bDecimal(len(bts))

# widget appearance dictionary
widget_appearance_dictionary: Dictionary = Dictionary()
widget_appearance_dictionary: Dictionary = Dictionary().set_is_unique(True) # type: ignore [attr-defined]
widget_appearance_dictionary.set_is_unique(True) # type: ignore [attr-defined]
widget_appearance_dictionary[Name("N")] = widget_normal_appearance

# get Catalog
catalog: Dictionary = page.get_root()["XRef"]["Trailer"]["Root"] # type: ignore [attr-defined]

# widget dictionary
self._widget_dictionary = Dictionary()
self._widget_dictionary.set_is_unique(True) # type: ignore [attr-defined]
self._widget_dictionary = Dictionary().set_is_unique(True) # type: ignore [attr-defined]
self._widget_dictionary.set_is_unique(True) # type: ignore [attr-defined]
self._widget_dictionary[Name("Type")] = Name("Annot")
self._widget_dictionary[Name("Subtype")] = Name("Widget")
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("Ch")
self._widget_dictionary[Name("P")] = catalog
self._widget_dictionary[Name("Opt")] = List()
for x in self._possible_values:
self._widget_dictionary["Opt"].append(String(x))
self._widget_dictionary[Name("Ff")] = bDecimal(131072)
self._widget_dictionary[Name("T")] = String(
self._field_name or self._get_auto_generated_field_name(page)
)
self._widget_dictionary[Name("T")] = String(self._field_name or self._get_auto_generated_field_name(page))
self._widget_dictionary[Name("V")] = String(self._value)
self._widget_dictionary[Name("DV")] = String(self._default_value)
self._widget_dictionary[Name("DR")] = widget_resources
Expand Down
24 changes: 10 additions & 14 deletions borb/pdf/canvas/layout/forms/push_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,18 @@ def _init_widget_dictionary(self, page: Page) -> None:

# init page and font resources
assert self._font_size is not None
font_resource_name: Name = self._get_font_resource_name(
StandardType1Font("Helvetica"), page
)
font_resource_name: Name = self._get_font_resource_name(StandardType1Font("Helvetica"), page)

# widget resource dictionary
widget_resources: Dictionary = Dictionary()
widget_resources: Dictionary = Dictionary().set_is_unique(True) # type: ignore [attr-defined]
widget_resources[Name("Font")] = page["Resources"]["Font"]

# get Catalog
catalog: Dictionary = page.get_root()["XRef"]["Trailer"]["Root"] # type: ignore [attr-defined]

# widget dictionary
# fmt: off
self._widget_dictionary = Dictionary()
self._widget_dictionary = Dictionary().set_is_unique(True) # type: ignore [attr-defined]
self._widget_dictionary.set_is_unique(True) # type: ignore [attr-defined]
self._widget_dictionary[Name("AA")] = Dictionary()
self._widget_dictionary[Name("AA")][Name("D")] = Dictionary()
Expand All @@ -110,7 +108,7 @@ def _init_widget_dictionary(self, page: Page) -> None:

# create normal appearance
# fmt: off
self._widget_dictionary[Name("AP")] = Dictionary()
self._widget_dictionary[Name("AP")] = Dictionary().set_is_unique(True) # type: ignore [attr-defined]
self._widget_dictionary[Name("AP")][Name("N")] = Stream()
self._widget_dictionary[Name("AP")][Name("N")][Name("Type")] = Name("XObject")
self._widget_dictionary[Name("AP")][Name("N")][Name("Subtype")] = Name("Form")
Expand All @@ -131,7 +129,7 @@ def _init_widget_dictionary(self, page: Page) -> None:

# create default appearance
# fmt: off
self._widget_dictionary[Name("DA")] = String("0.23921 0.23921 0.23921 rg /%s %f Tf" % (font_resource_name, self._font_size))
self._widget_dictionary[Name("DA")] = String("0.23921 0.23921 0.23921 rg /%s %f Tf" % (font_resource_name, float(self._font_size)))
self._widget_dictionary[Name("DR")] = widget_resources
# fmt: on

Expand Down Expand Up @@ -270,7 +268,7 @@ def _init_widget_dictionary(self, page: Page) -> None:

# build JavaScript stream object
# fmt: off
javascript_stream = Stream()
javascript_stream = Stream().set_is_unique(True) # type: ignore [attr-defined]
javascript_stream[Name("Type")] = Name("JavaScript")
javascript_stream[Name("DecodedBytes")] = bytes(self._javascript, "latin1")
javascript_stream[Name("Bytes")] = zlib.compress(javascript_stream[Name("DecodedBytes")], 9)
Expand All @@ -279,10 +277,8 @@ def _init_widget_dictionary(self, page: Page) -> None:
# fmt: on

# modify action dictionary of PushButton (super)
# fmt: off
if self._widget_dictionary is not None:
self._widget_dictionary[Name("AA")][Name("D")][Name("S")] = Name(
"JavaScript"
)
self._widget_dictionary[Name("AA")][Name("D")][
Name("JS")
] = javascript_stream
self._widget_dictionary[Name("AA")][Name("D")][Name("S")] = Name("JavaScript")
self._widget_dictionary[Name("AA")][Name("D")][Name("JS")] = javascript_stream
# fmt: on
Loading

0 comments on commit a4cad84

Please sign in to comment.