Skip to content

Commit

Permalink
release v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisschellekens committed Sep 4, 2022
1 parent 06f64f5 commit 8e94fad
Show file tree
Hide file tree
Showing 931 changed files with 4,198 additions and 10,181 deletions.
5 changes: 3 additions & 2 deletions borb/io/filter/lzw_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@ def decode(self, input: bytes):
continue

# normal behaviour
x: bytearray = bytearray()
if code < self._table_index:
x: bytearray = self._lookup_table[code]
x = self._lookup_table[code]
bytes_out += x
self._add_to_lookup_table(self._lookup_table[prev_code], x[0:1])
prev_code = code
else:
x: bytearray = self._lookup_table[prev_code]
x = self._lookup_table[prev_code]
x = x + x[0:1]
bytes_out += x
self._add_to_lookup_table(x, bytearray())
Expand Down
5 changes: 3 additions & 2 deletions borb/io/filter/run_length_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ def decode(bytes_in: bytes) -> bytes:
break
# If the length byte is in the range 0 to 127, the following length + 1 (1 to 128)
# bytes shall be copied literally during decompression.
length: int = 0
if 0 <= b <= 127:
length: int = b + 1
length = b + 1
i += 1
for j in range(0, length):
bytes_out.append(bytes_in[i + j])
Expand All @@ -56,7 +57,7 @@ def decode(bytes_in: bytes) -> bytes:
# If length is in the range 129 to 255, the following single
# byte shall be copied 257 - length (2 to 128) times during decompression
if 129 <= b <= 255:
length: int = 257 - b
length = 257 - b
i += 1
for _ in range(0, length):
bytes_out.append(bytes_in[i])
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)
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)
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)
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)
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)
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)
tmp.set_parent(parent_object) # type: ignore[attr-defined]

# return
return tmp
13 changes: 7 additions & 6 deletions borb/io/read/tokenize/low_level_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ def next_token(self) -> Optional[Token]:
return Token(self._io_source.tell() - 1, TokenType.END_ARRAY, b"]")

# NAME
out_str: bytearray = bytearray()
if ch == b"/":
out_str: bytearray = bytearray(b"/")
out_str = bytearray(b"/")
out_pos = self._io_source.tell() - 1
while True:
ch = self._next_byte()
Expand All @@ -144,7 +145,7 @@ def next_token(self) -> Optional[Token]:

# COMMENT
if ch == b"%":
out_str: bytearray = bytearray([])
out_str = bytearray([])
out_pos = self._io_source.tell() - 1
while len(ch) != 0 and ch != b"\r" and ch != b"\n":
out_str += ch
Expand All @@ -167,7 +168,7 @@ def next_token(self) -> Optional[Token]:
return Token(out_pos, TokenType.HEX_STRING, b"<>")

# HEX_STRING
out_str: bytearray = bytearray(b"<")
out_str = bytearray(b"<")
out_str += ch
while True:
ch = self._next_byte()
Expand All @@ -180,7 +181,7 @@ def next_token(self) -> Optional[Token]:

# NUMBER
if self._is_pseudo_digit(ch):
out_str: bytearray = bytearray([])
out_str = bytearray([])
out_pos = self._io_source.tell() - 1
while len(ch) != 0 and self._is_pseudo_digit(ch):
out_str += ch
Expand All @@ -192,7 +193,7 @@ def next_token(self) -> Optional[Token]:
# STRING
if ch == b"(":
bracket_nesting_level = 1
out_str: bytearray = bytearray(b"(")
out_str = bytearray(b"(")
out_pos = self._io_source.tell() - 1
while True:
ch = self._next_byte()
Expand All @@ -216,7 +217,7 @@ def next_token(self) -> Optional[Token]:
return Token(out_pos, TokenType.STRING, bytes(out_str))

# OTHER
out_str: bytearray = bytearray([])
out_str = bytearray([])
out_pos = self._io_source.tell() - 1
while len(ch) != 0 and not self._is_delimiter(ch):
out_str += ch
Expand Down
2 changes: 1 addition & 1 deletion borb/io/read/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def evaluate(self, xs: typing.List[oDecimal]) -> typing.List[oDecimal]:
# Each output value rj, for 0 £ j < n, shall then be decoded:
rs_prime: typing.List[oDecimal] = [
Function._interpolate(
rs[j], oDecimal(0), 2 ** bps - 1, decode[2 * j], decode[2 * j + 1]
rs[j], oDecimal(0), 2**bps - 1, decode[2 * j], decode[2 * j + 1]
)
for j in range(0, len(rs))
]
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.32
borb version 2.1.0
Joris Schellekens
2 changes: 1 addition & 1 deletion borb/io/write/document/document_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def transform(
DocumentTransformer._invalidate_all_references(object_to_transform)

# set /ID
random_id = HexadecimalString("%032x" % random.randrange(16 ** 32))
random_id = HexadecimalString("%032x" % random.randrange(16**32))
if "ID" not in object_to_transform["XRef"]["Trailer"]:
# fmt: off
object_to_transform["XRef"]["Trailer"][Name("ID")] = List().set_is_inline(True) # type: ignore [attr-defined]
Expand Down
5 changes: 2 additions & 3 deletions borb/io/write/font/subset_show_text_with_glyph_positioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
element of array shall be either a string or a number.
"""
import typing
from decimal import Decimal
from typing import List

from borb.io.read.types import AnyPDFType, Name, String, HexadecimalString
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 Expand Up @@ -85,7 +84,7 @@ def invoke(
obj = operands[0][i]

# adjust
if isinstance(obj, Decimal):
if isinstance(obj, bDecimal):
operands_out.append(obj)
continue

Expand Down
6 changes: 3 additions & 3 deletions borb/io/write/font/subsetter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import typing
import zlib

from fontTools.subset import Subsetter as fSubsetter
from fontTools.ttLib import TTFont
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, String, Stream
from borb.io.read.types import Decimal as bDecimal, Name
from borb.io.write.font.character_set_listener import CharacterSetListener
from borb.io.write.font.copy_command_operator import CopyCommandOperator
from borb.io.write.font.subset_show_text_with_glyph_positioning import (
Expand Down
11 changes: 8 additions & 3 deletions borb/io/write/image/image_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def _convert_to_rgb_mode(self, image: PILImage.Image) -> PILImage.Image:
image_out = image_out.convert("RGBA")
if image_out.mode in ["RGBA", "LA"]:
fill_color = (255, 255, 255) # new background color
background = PILImage.new(image_out.mode[:-1], image_out.size, fill_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.paste(image_out, image_out.split()[-1]) # omit transparency
image_out = background

Expand All @@ -46,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())
image_out.set_reference(image.get_reference()) # type: ignore[attr-defined]

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

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

# start object if needed
started_object = False
Expand Down
4 changes: 2 additions & 2 deletions borb/io/write/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ def get_reference(
"""
is_unique: bool = False
try:
is_unique = object.is_unique()
is_unique = object.is_unique() # type: ignore[union-attr]
except:
pass
obj_id = id(object)
if (not is_unique) and 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]
return cached_indirect_object.get_reference() # type: ignore[union-attr]

# look through existing indirect object hashes
obj_hash: int = self._hash(object)
Expand Down
67 changes: 30 additions & 37 deletions borb/pdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,6 @@
address: [email protected]
"""

# Document, Page, PDF
from .document.document import Document
from .page.page import Page
from .pdf import PDF

# PageLayout
from .canvas.layout.page_layout.page_layout import PageLayout
from .canvas.layout.page_layout.multi_column_layout import SingleColumnLayout
from .canvas.layout.page_layout.multi_column_layout import MultiColumnLayout
from .canvas.layout.layout_element import Alignment

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

# Image
from .canvas.layout.image.image import Image
from .canvas.layout.image.chart import Chart
from .canvas.layout.image.barcode import Barcode
from .canvas.layout.image.barcode import BarcodeType

# Shape
from .canvas.layout.shape.shape import Shape
from .canvas.layout.shape.disjoint_shape import DisjointShape

# Table
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
from .canvas.layout.list.ordered_list import OrderedList
from .canvas.layout.list.unordered_list import UnorderedList
from .canvas.layout.list.roman_list import RomanNumeralOrderedList

# Color
from .canvas.color.color import (
Color,
Expand All @@ -91,3 +54,33 @@
X11Color,
)
from .canvas.color.pantone import Pantone
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
from .pdf import PDF
9 changes: 4 additions & 5 deletions borb/pdf/canvas/color/farrow_and_ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
Farrow & Ball is a British manufacturer of paints and wallpapers largely based upon historic colour palettes and archives.
The company is particularly well known for the unusual names of its products.
"""
from decimal import Decimal

import typing
from decimal import Decimal

from borb.pdf import RGBColor, HexColor, Color
from borb.pdf.canvas.color.color import Color, HexColor, RGBColor


class FarrowAndBall:
class FarrowAndBall(HexColor):
"""
Farrow & Ball is a British manufacturer of paints and wallpapers largely based upon historic colour palettes and archives.
The company is particularly well known for the unusual names of its products.
Expand Down Expand Up @@ -165,7 +164,7 @@ def get_name(self) -> str:
return self.color_name

@staticmethod
def find_nearest_pantone_color(color: Color) -> "FarrowAndBall":
def find_nearest_farrow_and_ball_color(color: Color) -> "FarrowAndBall":
"""
This function find the nearest `Farrow and Ball` equivalent for a given Color
"""
Expand Down
18 changes: 8 additions & 10 deletions borb/pdf/canvas/event/chunk_of_text_render_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,14 @@ def __init__(self, graphics_state: CanvasGraphicsState, raw_bytes: String):
+ graphics_state.font.get_ascent() * Decimal(0.001),
Decimal(1),
)
self.set_bounding_box(
Rectangle(
min(p0[0], p1[0]),
min(p0[1], p1[1]),
abs(p1[0] - p0[0]),
abs(p1[1] - p0[1]),
)
self._previous_layout_box = Rectangle(
min(p0[0], p1[0]),
min(p0[1], p1[1]),
abs(p1[0] - p0[0]),
abs(p1[1] - p0[1]),
)
else:
self.set_bounding_box(self._baseline_bounding_box)
self._previous_layout_box = self._baseline_bounding_box

# calculate space character width estimate
current_font: Font = graphics_state.font
Expand Down Expand Up @@ -162,7 +160,7 @@ def split_on_glyphs(self) -> typing.List["ChunkOfTextRenderEvent"]:
e._baseline_bounding_box = Rectangle(
p0[0], p0[1], p1[0] - p0[0], p1[1] - p0[1]
)
e.bounding_box = e._baseline_bounding_box
e._previous_layout_box = e._baseline_bounding_box

# change bounding box (descent)
if g.uses_descent():
Expand All @@ -176,7 +174,7 @@ def split_on_glyphs(self) -> typing.List["ChunkOfTextRenderEvent"]:
y + font.get_ascent() * Decimal(0.001),
Decimal(1),
)
e.bounding_box = Rectangle(
e._previous_layout_box = Rectangle(
min(p0[0], p1[0]),
min(p0[1], p1[1]),
abs(p1[0] - p0[0]),
Expand Down
Loading

0 comments on commit 8e94fad

Please sign in to comment.