Skip to content

Commit

Permalink
release v2.0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisschellekens committed Sep 5, 2021
1 parent 1c2ab56 commit 47cba64
Show file tree
Hide file tree
Showing 269 changed files with 633 additions and 595 deletions.
551 changes: 287 additions & 264 deletions LICENSE.md → LICENSE

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# ![borb logo](https://github.com/jorisschellekens/borb/raw/master/readme_img/logo/borb_64.png) borb
# ![borb logo](https://github.com/jorisschellekens/borb/raw/master/logo/borb_64.png) borb


[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
Expand Down
98 changes: 98 additions & 0 deletions borb/io/read/any_object_transformer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# !/usr/bin/env python
# -*- coding: utf-8 -*-

"""
This implementation of ReadBaseTransformer aggregates all
other implementations of ReadBaseTransformer
"""
import io
import typing
from typing import Any, Optional, Union

from borb.io.read.font.font_dictionary_transformer import FontDictionaryTransformer
from borb.io.read.function.function_dictionary_transformer import FunctionDictionaryTransformer
from borb.io.read.image.ccitt_fax_image_transformer import CCITTFaxImageTransformer
from borb.io.read.image.compressed_jpeg_image_transformer import CompressedJPEGImageTransformer
from borb.io.read.image.grayscale_image_transformer import GrayscaleImageTransformer
from borb.io.read.image.jbig2_image_transformer import JBIG2ImageTransformer
from borb.io.read.image.jpeg_2000_image_transformer import JPEG2000ImageTransformer
from borb.io.read.image.jpeg_image_transformer import JPEGImageTransformer
from borb.io.read.metadata.xmp_metadata_transformer import XMPMetadataTransformer
from borb.io.read.object.array_transformer import ArrayTransformer
from borb.io.read.object.dictionary_transformer import DictionaryTransformer
from borb.io.read.object.stream_transformer import StreamTransformer
from borb.io.read.page.page_dictionary_transformer import PageDictionaryTransformer
from borb.io.read.page.root_dictionary_transformer import RootDictionaryTransformer
from borb.io.read.primitive.number_transformer import NumberTransformer
from borb.io.read.primitive.string_transformer import StringTransformer
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.reference.reference_transformer import ReferenceTransformer
from borb.io.read.reference.xref_transformer import XREFTransformer
from borb.io.read.types import AnyPDFType
from borb.pdf.canvas.event.event_listener import EventListener


class AnyObjectTransformer(Transformer):
"""
This implementation of ReadBaseTransformer aggregates all other implementations
of ReadBaseTransformer
"""

def __init__(self):
super().__init__()
self.add_child_transformer(XREFTransformer())
# XMP
self.add_child_transformer(XMPMetadataTransformer())
# fonts
self.add_child_transformer(FontDictionaryTransformer())
# images
self.add_child_transformer(CCITTFaxImageTransformer())
self.add_child_transformer(GrayscaleImageTransformer())
self.add_child_transformer(JBIG2ImageTransformer())
self.add_child_transformer(JPEG2000ImageTransformer())
self.add_child_transformer(JPEGImageTransformer())
self.add_child_transformer(CompressedJPEGImageTransformer())
# pages
self.add_child_transformer(RootDictionaryTransformer())
self.add_child_transformer(PageDictionaryTransformer())
# references
self.add_child_transformer(ReferenceTransformer())
# primitives
self.add_child_transformer(FunctionDictionaryTransformer())
self.add_child_transformer(StreamTransformer())
self.add_child_transformer(StringTransformer())
self.add_child_transformer(NumberTransformer())
# objects
self.add_child_transformer(DictionaryTransformer())
self.add_child_transformer(ArrayTransformer())

def can_be_transformed(
self, object: Union[io.BufferedIOBase, io.RawIOBase, io.BytesIO, AnyPDFType]
) -> bool:
"""
This function returns True if the object to be transformed can be transformed by this ReadAnyObjectTransformer
"""
return isinstance(object, io.IOBase)

def transform(
self,
object_to_transform: Union[io.BufferedIOBase, io.RawIOBase, AnyPDFType],
parent_object: Any,
context: Optional[ReadTransformerState] = None,
event_listeners: typing.List[EventListener] = [],
) -> Any:
"""
This function reads an object from a byte stream.
The object being read depends on the implementation of ReadAnyObjectTransformer.
"""
if context is None:
return super().transform(
object_to_transform,
parent_object,
ReadTransformerState(),
event_listeners,
)
else:
return super().transform(
object_to_transform, parent_object, context, event_listeners
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# -*- coding: utf-8 -*-

"""
This implementation of ReadBaseTransformer is responsible for reading a Font object
This implementation of BaseTransformer is responsible for reading a Font object
"""
import io
import typing
from typing import Any, Optional, Union

from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType, Dictionary, Stream
from borb.pdf.canvas.event.event_listener import EventListener
from borb.pdf.canvas.font.composite_font.cid_font_type_0 import CIDType0Font
Expand All @@ -20,13 +20,13 @@
from borb.pdf.canvas.font.simple_font.true_type_font import TrueTypeFont


class ReadFontDictionaryTransformer(ReadBaseTransformer):
class FontDictionaryTransformer(Transformer):
"""
This implementation of ReadBaseTransformer is responsible for reading a Font object
"""

def __init__(self):
super(ReadFontDictionaryTransformer, self).__init__()
super(FontDictionaryTransformer, self).__init__()
self._accept_true_type_standard_14_fonts: bool = True

def can_be_transformed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from typing import Any, Optional, Union

from borb.io.filter.stream_decode_util import decode_stream
from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType, Dictionary, Function, Name, Reference, Stream
from borb.pdf.canvas.event.event_listener import EventListener


class FunctionDictionaryTransformer(ReadBaseTransformer):
class FunctionDictionaryTransformer(Transformer):
"""
This implementation of ReadBaseTransformer is responsible for reading a Function Dictionary
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import typing
from typing import Any, Optional, Union

from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType, Stream, add_base_methods
from borb.pdf.canvas.event.event_listener import EventListener
from PIL import Image # type: ignore [import]

logger = logging.getLogger(__name__)


class ReadCCITTFaxImageTransformer(ReadBaseTransformer):
class CCITTFaxImageTransformer(Transformer):
"""
This implementation of ReadBaseTransformer is responsible for reading CCITT fax images
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
from typing import Any, Optional, Union

from borb.io.filter.stream_decode_util import decode_stream
from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType, Name, Stream, add_base_methods
from borb.pdf.canvas.event.event_listener import EventListener
from PIL import Image # type: ignore [import]

logger = logging.getLogger(__name__)


class ReadCompressedJPEGImageTransformer(ReadBaseTransformer):
class CompressedJPEGImageTransformer(Transformer):
"""
This implementation of ReadBaseTransformer is responsible for reading a jpeg image object
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
from typing import Any, Optional, Union

from borb.io.filter.stream_decode_util import decode_stream
from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType, Reference, Stream, add_base_methods
from borb.pdf.canvas.event.event_listener import EventListener
from PIL import Image # type: ignore [import]

logger = logging.getLogger(__name__)


class ReadGrayscaleImageTransformer(ReadBaseTransformer):
class GrayscaleImageTransformer(Transformer):
"""
This implementation of ReadBaseTransformer is responsible for reading a grayscale image object
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import typing
from typing import Any, Optional, Union

from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType, Stream, add_base_methods
from borb.pdf.canvas.event.event_listener import EventListener
from PIL import Image # type: ignore [import]

logger = logging.getLogger(__name__)


class ReadJBIG2ImageTransformer(ReadBaseTransformer):
class JBIG2ImageTransformer(Transformer):
"""
This implementation of ReadBaseTransformer is responsible for reading a jbig2 image object
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import typing
from typing import Any, Optional, Union

from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType, Stream, add_base_methods
from borb.pdf.canvas.event.event_listener import EventListener
from PIL import Image # type: ignore [import]

logger = logging.getLogger(__name__)


class ReadJPEG2000ImageTransformer(ReadBaseTransformer):
class JPEG2000ImageTransformer(Transformer):
"""
This implementation of ReadBaseTransformer is responsible for reading a jpeg2000 image object
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import typing
from typing import Any, Optional, Union

from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType, Stream, add_base_methods
from borb.pdf.canvas.event.event_listener import EventListener
from PIL import Image # type: ignore [import]

logger = logging.getLogger(__name__)


class ReadJPEGImageTransformer(ReadBaseTransformer):
class JPEGImageTransformer(Transformer):
"""
This implementation of ReadBaseTransformer is responsible for reading a jpeg image object
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
import xml.etree.ElementTree as ET
from typing import Any, Optional, Union

from borb.io.read.object.read_stream_transformer import ReadStreamTransformer
from borb.io.read.read_base_transformer import ReadTransformerState
from borb.io.read.object.stream_transformer import StreamTransformer
from borb.io.read.transformer import ReadTransformerState
from borb.io.read.types import AnyPDFType, Element, Stream
from borb.pdf.canvas.event.event_listener import EventListener

logger = logging.getLogger(__name__)


class ReadXMPMetadataTransformer(ReadStreamTransformer):
class XMPMetadataTransformer(StreamTransformer):
"""
A metadata stream may be attached to a document through the Metadata entry in the document catalogue
(see 7.7.2, “Document Catalog”). The metadata framework provides a date stamp for metadata expressed in
Expand Down Expand Up @@ -65,7 +65,7 @@ def transform(
"""

# delegate to super (ReadStreamTransformer)
out_value = super(ReadXMPMetadataTransformer, self).transform(
out_value = super(XMPMetadataTransformer, self).transform(
object_to_transform=object_to_transform,
parent_object=parent_object,
context=context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import typing
from typing import Any, Optional, Union

from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType, List
from borb.pdf.canvas.event.event_listener import EventListener


class ReadArrayTransformer(ReadBaseTransformer):
class ArrayTransformer(Transformer):
"""
This implementation of BaseTransformer converts a PDFArray to a List
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import typing
from typing import Any, Optional, Union

from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType, Dictionary
from borb.pdf.canvas.event.event_listener import EventListener


class ReadDictionaryTransformer(ReadBaseTransformer):
class DictionaryTransformer(Transformer):
"""
This implementation of ReadBaseTransformer is responsible for reading a Dictionary object
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from typing import Any, Optional, Union

from borb.io.filter.stream_decode_util import decode_stream
from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType, Reference, Stream
from borb.pdf.canvas.event.event_listener import EventListener


class ReadStreamTransformer(ReadBaseTransformer):
class StreamTransformer(Transformer):
"""
This implementation of ReadBaseTransformer is responsible for reading Stream objects
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import zlib
from typing import Any, Dict, Optional, Union

from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType
from borb.io.read.types import Decimal as pDecimal
from borb.io.read.types import Dictionary, List, Name, Stream
Expand All @@ -21,7 +21,7 @@
from borb.pdf.page.page import Page


class ReadPageDictionaryTransformer(ReadBaseTransformer):
class PageDictionaryTransformer(Transformer):
"""
This implementation of ReadBaseTransformer is responsible for reading Page objects
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import typing
from typing import Any, Dict, List, Optional, Union

from borb.io.read.object.read_dictionary_transformer import ReadDictionaryTransformer
from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.object.dictionary_transformer import DictionaryTransformer
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType, Decimal, Dictionary
from borb.io.read.types import List as pList
from borb.io.read.types import Name
from borb.pdf.canvas.event.event_listener import EventListener
from borb.pdf.page.page import Page


class ReadRootDictionaryTransformer(ReadBaseTransformer):
class RootDictionaryTransformer(Transformer):
"""
This implementation of ReadBaseTransformer is responsible for reading the \Catalog object
"""
Expand Down Expand Up @@ -53,7 +53,7 @@ def transform(
# convert using Dictionary transformer
transformed_root_dictionary: Optional[Dictionary] = None
for t in self.get_root_transformer().get_children():
if isinstance(t, ReadDictionaryTransformer):
if isinstance(t, DictionaryTransformer):
transformed_root_dictionary = t.transform(
object_to_transform, parent_object, context, []
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import typing
from typing import Any, Optional, Union

from borb.io.read.read_base_transformer import ReadBaseTransformer, ReadTransformerState
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType, Decimal
from borb.pdf.canvas.event.event_listener import EventListener


class ReadNumberTransformer(ReadBaseTransformer):
class NumberTransformer(Transformer):
"""
This implementation of ReadBaseTransformer is responsible for reading Decimal objects
"""
Expand Down
Loading

0 comments on commit 47cba64

Please sign in to comment.