22from binascii import Error as BinasciiError
33from binascii import unhexlify
44from math import ceil
5- from typing import Any , Dict , List , Tuple , Union , cast
5+ from typing import Any , Union , cast
66
77from ._codecs import adobe_glyphs , charset_encoding
88from ._utils import logger_error , logger_warning
1919# code freely inspired from @twiggy ; see #711
2020def build_char_map (
2121 font_name : str , space_width : float , obj : DictionaryObject
22- ) -> Tuple [str , float , Union [str , Dict [int , str ]], Dict [Any , Any ], DictionaryObject ]:
22+ ) -> tuple [str , float , Union [str , dict [int , str ]], dict [Any , Any ], DictionaryObject ]:
2323 """
2424 Determine information about a font.
2525
@@ -42,7 +42,7 @@ def build_char_map(
4242
4343def build_char_map_from_dict (
4444 space_width : float , ft : DictionaryObject
45- ) -> Tuple [str , float , Union [str , Dict [int , str ]], Dict [Any , Any ]]:
45+ ) -> tuple [str , float , Union [str , dict [int , str ]], dict [Any , Any ]]:
4646 """
4747 Determine information about a font.
4848
@@ -73,15 +73,15 @@ def build_char_map_from_dict(
7373
7474
7575# used when missing data, e.g. font def missing
76- unknown_char_map : Tuple [str , float , Union [str , Dict [int , str ]], Dict [Any , Any ]] = (
76+ unknown_char_map : tuple [str , float , Union [str , dict [int , str ]], dict [Any , Any ]] = (
7777 "Unknown" ,
7878 9999 ,
7979 dict .fromkeys (range (256 ), "�" ),
8080 {},
8181)
8282
8383
84- _predefined_cmap : Dict [str , str ] = {
84+ _predefined_cmap : dict [str , str ] = {
8585 "/Identity-H" : "utf-16-be" ,
8686 "/Identity-V" : "utf-16-be" ,
8787 "/GB-EUC-H" : "gbk" ,
@@ -104,7 +104,7 @@ def build_char_map_from_dict(
104104}
105105
106106# manually extracted from http://mirrors.ctan.org/fonts/adobe/afm/Adobe-Core35_AFMs-229.tar.gz
107- _default_fonts_space_width : Dict [str , int ] = {
107+ _default_fonts_space_width : dict [str , int ] = {
108108 "/Courier" : 600 ,
109109 "/Courier-Bold" : 600 ,
110110 "/Courier-BoldOblique" : 600 ,
@@ -128,7 +128,7 @@ def build_char_map_from_dict(
128128
129129def get_encoding (
130130 ft : DictionaryObject
131- ) -> Tuple [Union [str , Dict [int , str ]], Dict [Any , Any ]]:
131+ ) -> tuple [Union [str , dict [int , str ]], dict [Any , Any ]]:
132132 encoding = _parse_encoding (ft )
133133 map_dict , int_entry = _parse_to_unicode (ft )
134134
@@ -146,8 +146,8 @@ def get_encoding(
146146
147147def _parse_encoding (
148148 ft : DictionaryObject
149- ) -> Union [str , Dict [int , str ]]:
150- encoding : Union [str , List [str ], Dict [int , str ]] = []
149+ ) -> Union [str , dict [int , str ]]:
150+ encoding : Union [str , list [str ], dict [int , str ]] = []
151151 if "/Encoding" not in ft :
152152 if "/BaseFont" in ft and cast (str , ft ["/BaseFont" ]) in charset_encoding :
153153 encoding = dict (
@@ -205,13 +205,13 @@ def _parse_encoding(
205205
206206def _parse_to_unicode (
207207 ft : DictionaryObject
208- ) -> Tuple [ Dict [Any , Any ], List [int ]]:
208+ ) -> tuple [ dict [Any , Any ], list [int ]]:
209209 # will store all translation code
210210 # and map_dict[-1] we will have the number of bytes to convert
211- map_dict : Dict [Any , Any ] = {}
211+ map_dict : dict [Any , Any ] = {}
212212
213213 # will provide the list of cmap keys as int to correct encoding
214- int_entry : List [int ] = []
214+ int_entry : list [int ] = []
215215
216216 if "/ToUnicode" not in ft :
217217 if ft .get ("/Subtype" , "" ) == "/Type1" :
@@ -220,7 +220,7 @@ def _parse_to_unicode(
220220 process_rg : bool = False
221221 process_char : bool = False
222222 multiline_rg : Union [
223- None , Tuple [int , int ]
223+ None , tuple [int , int ]
224224 ] = None # tuple = (current_char, remaining size) ; cf #1285 for example of file
225225 cm = prepare_cm (ft )
226226 for line in cm .split (b"\n " ):
@@ -237,7 +237,7 @@ def _parse_to_unicode(
237237
238238
239239def get_actual_str_key (
240- value_char : str , encoding : Union [str , Dict [int , str ]], map_dict : Dict [Any , Any ]
240+ value_char : str , encoding : Union [str , dict [int , str ]], map_dict : dict [Any , Any ]
241241) -> str :
242242 key_dict = {}
243243 if isinstance (encoding , dict ):
@@ -292,10 +292,10 @@ def process_cm_line(
292292 line : bytes ,
293293 process_rg : bool ,
294294 process_char : bool ,
295- multiline_rg : Union [None , Tuple [int , int ]],
296- map_dict : Dict [Any , Any ],
297- int_entry : List [int ],
298- ) -> Tuple [bool , bool , Union [None , Tuple [int , int ]]]:
295+ multiline_rg : Union [None , tuple [int , int ]],
296+ map_dict : dict [Any , Any ],
297+ int_entry : list [int ],
298+ ) -> tuple [bool , bool , Union [None , tuple [int , int ]]]:
299299 if line == b"" or line [0 ] == 37 : # 37 = %
300300 return process_rg , process_char , multiline_rg
301301 line = line .replace (b"\t " , b" " )
@@ -319,10 +319,10 @@ def process_cm_line(
319319
320320def parse_bfrange (
321321 line : bytes ,
322- map_dict : Dict [Any , Any ],
323- int_entry : List [int ],
324- multiline_rg : Union [None , Tuple [int , int ]],
325- ) -> Union [None , Tuple [int , int ]]:
322+ map_dict : dict [Any , Any ],
323+ int_entry : list [int ],
324+ multiline_rg : Union [None , tuple [int , int ]],
325+ ) -> Union [None , tuple [int , int ]]:
326326 lst = [x for x in line .split (b" " ) if x ]
327327 closure_found = False
328328 if multiline_rg is not None :
@@ -377,7 +377,7 @@ def parse_bfrange(
377377 return None if closure_found else (a , b )
378378
379379
380- def parse_bfchar (line : bytes , map_dict : Dict [Any , Any ], int_entry : List [int ]) -> None :
380+ def parse_bfchar (line : bytes , map_dict : dict [Any , Any ], int_entry : list [int ]) -> None :
381381 lst = [x for x in line .split (b" " ) if x ]
382382 map_dict [- 1 ] = len (lst [0 ]) // 2
383383 while len (lst ) > 1 :
@@ -401,8 +401,8 @@ def parse_bfchar(line: bytes, map_dict: Dict[Any, Any], int_entry: List[int]) ->
401401
402402def build_font_width_map (
403403 ft : DictionaryObject , default_font_width : float
404- ) -> Dict [Any , float ]:
405- font_width_map : Dict [Any , float ] = {}
404+ ) -> dict [Any , float ]:
405+ font_width_map : dict [Any , float ] = {}
406406 st : int = 0
407407 en : int = 0
408408 try :
@@ -482,7 +482,7 @@ def build_font_width_map(
482482
483483
484484def compute_space_width (
485- font_width_map : Dict [Any , float ], space_char : str
485+ font_width_map : dict [Any , float ], space_char : str
486486) -> float :
487487 try :
488488 sp_width = font_width_map [space_char ]
@@ -497,7 +497,7 @@ def compute_space_width(
497497
498498
499499def compute_font_width (
500- font_width_map : Dict [Any , float ],
500+ font_width_map : dict [Any , float ],
501501 char : str
502502) -> float :
503503 char_width : float = 0.0
@@ -513,9 +513,9 @@ def compute_font_width(
513513
514514def _type1_alternative (
515515 ft : DictionaryObject ,
516- map_dict : Dict [Any , Any ],
517- int_entry : List [int ],
518- ) -> Tuple [ Dict [Any , Any ], List [int ]]:
516+ map_dict : dict [Any , Any ],
517+ int_entry : list [int ],
518+ ) -> tuple [ dict [Any , Any ], list [int ]]:
519519 if "/FontDescriptor" not in ft :
520520 return map_dict , int_entry
521521 ft_desc = cast (DictionaryObject , ft ["/FontDescriptor" ]).get ("/FontFile" )
0 commit comments