@@ -144,7 +144,7 @@ class Transformation:
144144 Represent a 2D transformation.
145145
146146 The transformation between two coordinate systems is represented by a 3-by-3
147- transformation matrix matrix with the following form::
147+ transformation matrix with the following form::
148148
149149 a b 0
150150 c d 0
@@ -467,7 +467,7 @@ def __getitem__(
467467 len_self = len (lst )
468468 if index < 0 :
469469 # support negative indexes
470- index = len_self + index
470+ index + = len_self
471471 if index < 0 or index >= len_self :
472472 raise IndexError ("Sequence index out of range" )
473473 return self .get_function (lst [index ])
@@ -575,7 +575,7 @@ def create_blank_page(
575575 """
576576 page = PageObject (pdf )
577577
578- # Creates a new page (cf PDF Reference 7.7.3.3)
578+ # Creates a new page (cf PDF Reference § 7.7.3.3)
579579 page .__setitem__ (NameObject (PG .TYPE ), NameObject ("/Page" ))
580580 page .__setitem__ (NameObject (PG .PARENT ), NullObject ())
581581 page .__setitem__ (NameObject (PG .RESOURCES ), DictionaryObject ())
@@ -907,7 +907,7 @@ def _merge_resources(
907907 pdf = self .indirect_reference .pdf
908908 is_pdf_writer = hasattr (
909909 pdf , "_add_object"
910- ) # ---------- expect isinstance(pdf,PdfWriter)
910+ ) # expect isinstance(pdf, PdfWriter)
911911 except (AssertionError , AttributeError ):
912912 pdf = None
913913 is_pdf_writer = False
@@ -927,8 +927,8 @@ def compute_unique_key(base_key: str) -> Tuple[str, bool]:
927927
928928 """
929929 value = page2res .raw_get (base_key )
930- # TODO : possible improvement : in case of writer, the indirect_reference
931- # can not be found because translated : this may be improved
930+ # TODO: a possible improvement for writer, the indirect_reference
931+ # cannot be found because translated
932932
933933 # try the current key first (e.g. "foo"), but otherwise iterate
934934 # through "foo-0", "foo-1", etc. new_res can contain only finitely
@@ -1097,7 +1097,7 @@ def replace_contents(
10971097 assert content is not None , "mypy"
10981098 content .indirect_reference = self [
10991099 PG .CONTENTS
1100- ].indirect_reference # TODO: in a future may required generation management
1100+ ].indirect_reference # TODO: in the future may require generation management
11011101 try :
11021102 self .indirect_reference .pdf ._objects [
11031103 content .indirect_reference .idnum - 1 # type: ignore
@@ -1147,7 +1147,7 @@ def _merge_page(
11471147 assert isinstance (self .indirect_reference , IndirectObject )
11481148 if hasattr (
11491149 self .indirect_reference .pdf , "_add_object"
1150- ): # ---------- to detect PdfWriter
1150+ ): # to detect PdfWriter
11511151 return self ._merge_page_writer (
11521152 page2 , page2transformation , ctm , over , expand
11531153 )
@@ -1683,7 +1683,7 @@ def page_number(self) -> Optional[int]:
16831683 Read-only property which returns the page number within the PDF file.
16841684
16851685 Returns:
1686- int : page number; None if the page is not attached to a PDF.
1686+ Page number; None if the page is not attached to a PDF.
16871687
16881688 """
16891689 if self .indirect_reference is None :
@@ -1837,7 +1837,7 @@ def _extract_text(
18371837 try :
18381838 objr = obj
18391839 while NameObject (PG .RESOURCES ) not in objr :
1840- # /Resources can be inherited sometimes so we look to parents
1840+ # /Resources can be inherited so we look to parents
18411841 objr = objr ["/Parent" ].get_object ()
18421842 # If no parents then no /Resources will be available,
18431843 # so an exception will be raised
@@ -1900,8 +1900,8 @@ def process_operation(operator: bytes, operands: List[Any]) -> None:
19001900 nonlocal char_scale , space_scale , _space_width , TL , font_size , cmap
19011901 nonlocal orientations , rtl_dir , visitor_text , output , text , _actual_str_size
19021902
1903- check_crlf_space : bool = False
19041903 str_widths : float = 0.0
1904+
19051905 # Table 5.4 page 405
19061906 if operator == b"BT" :
19071907 tm_matrix = [1.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 ]
@@ -1919,6 +1919,7 @@ def process_operation(operator: bytes, operands: List[Any]) -> None:
19191919 text = ""
19201920 memo_cm = cm_matrix .copy ()
19211921 memo_tm = tm_matrix .copy ()
1922+
19221923 # Table 4.7 "Graphics state operators", page 219
19231924 # cm_matrix calculation is reserved for later
19241925 elif operator == b"q" :
@@ -1957,6 +1958,7 @@ def process_operation(operator: bytes, operands: List[Any]) -> None:
19571958 )
19581959 memo_cm = cm_matrix .copy ()
19591960 memo_tm = tm_matrix .copy ()
1961+
19601962 # Table 5.2 page 398
19611963 elif operator == b"Tz" :
19621964 char_scale = float (operands [0 ]) / 100 if operands else 1.0
@@ -2005,7 +2007,6 @@ def process_operation(operator: bytes, operands: List[Any]) -> None:
20052007 pass # keep previous size
20062008 # Table 5.5 page 406
20072009 elif operator == b"Td" :
2008- check_crlf_space = True
20092010 # A special case is a translating only tm:
20102011 # tm = [1, 0, 0, 1, e, f]
20112012 # i.e. tm[4] += tx, tm[5] += ty.
@@ -2015,18 +2016,15 @@ def process_operation(operator: bytes, operands: List[Any]) -> None:
20152016 str_widths = compute_str_widths (_actual_str_size ["str_widths" ])
20162017 _actual_str_size ["str_widths" ] = 0.0
20172018 elif operator == b"Tm" :
2018- check_crlf_space = True
20192019 tm_matrix = [float (operand ) for operand in operands [:6 ]]
20202020 str_widths = compute_str_widths (_actual_str_size ["str_widths" ])
20212021 _actual_str_size ["str_widths" ] = 0.0
20222022 elif operator == b"T*" :
2023- check_crlf_space = True
20242023 tm_matrix [4 ] -= TL * tm_matrix [2 ]
20252024 tm_matrix [5 ] -= TL * tm_matrix [3 ]
20262025 str_widths = compute_str_widths (_actual_str_size ["str_widths" ])
20272026 _actual_str_size ["str_widths" ] = 0.0
20282027 elif operator == b"Tj" :
2029- check_crlf_space = True
20302028 text , rtl_dir , _actual_str_size = self ._handle_tj (
20312029 text ,
20322030 operands ,
@@ -2043,7 +2041,7 @@ def process_operation(operator: bytes, operands: List[Any]) -> None:
20432041 else :
20442042 return
20452043
2046- if check_crlf_space :
2044+ if operator in { b"Td" , b"Tm" , b"T*" , b"Tj" } :
20472045 try :
20482046 text , output , cm_prev , tm_prev = crlf_space_check (
20492047 text ,
@@ -2421,7 +2419,7 @@ def _get_fonts(self) -> Tuple[Set[str], Set[str]]:
24212419 Get the names of embedded fonts and unembedded fonts.
24222420
24232421 Returns:
2424- A tuple (Set of embedded fonts, set of unembedded fonts)
2422+ A tuple (set of embedded fonts, set of unembedded fonts)
24252423
24262424 """
24272425 obj = self .get_object ()
@@ -2518,7 +2516,7 @@ def __getitem__(
25182516 len_self = len (self )
25192517 if index < 0 :
25202518 # support negative indexes
2521- index = len_self + index
2519+ index + = len_self
25222520 if index < 0 or index >= len_self :
25232521 raise IndexError ("Sequence index out of range" )
25242522 return self .get_function (index )
@@ -2537,8 +2535,8 @@ def __delitem__(self, index: Union[int, slice]) -> None:
25372535 len_self = len (self )
25382536 if index < 0 :
25392537 # support negative indexes
2540- index = len_self + index
2541- if index < 0 or index >= len_self :
2538+ index + = len_self
2539+ if not ( 0 <= index < len_self ) :
25422540 raise IndexError ("Index out of range" )
25432541 ind = self [index ].indirect_reference
25442542 assert ind is not None
0 commit comments