@@ -715,15 +715,6 @@ def _pre(self, i, x, cs, ds):
715715 # cs = checksum, ds = design size
716716
717717
718- def _fix2comp (num ):
719- """Convert from two's complement to negative."""
720- assert 0 <= num < 2 ** 32
721- if num & 2 ** 31 :
722- return num - 2 ** 32
723- else :
724- return num
725-
726-
727718def _mul2012 (num1 , num2 ):
728719 """Multiply two numbers in 20.12 fixed point format."""
729720 # Separated into a function because >> has surprising precedence
@@ -757,29 +748,23 @@ def __init__(self, filename):
757748 _log .debug ('opening tfm file %s' , filename )
758749 with open (filename , 'rb' ) as file :
759750 header1 = file .read (24 )
760- lh , bc , ec , nw , nh , nd = \
761- struct .unpack ('!6H' , header1 [2 :14 ])
751+ lh , bc , ec , nw , nh , nd = struct .unpack ('!6H' , header1 [2 :14 ])
762752 _log .debug ('lh=%d, bc=%d, ec=%d, nw=%d, nh=%d, nd=%d' ,
763753 lh , bc , ec , nw , nh , nd )
764754 header2 = file .read (4 * lh )
765- self .checksum , self .design_size = \
766- struct .unpack ('!2I' , header2 [:8 ])
755+ self .checksum , self .design_size = struct .unpack ('!2I' , header2 [:8 ])
767756 # there is also encoding information etc.
768757 char_info = file .read (4 * (ec - bc + 1 ))
769- widths = file .read (4 * nw )
770- heights = file .read (4 * nh )
771- depths = file .read (4 * nd )
772-
758+ widths = struct .unpack (f'!{ nw } i' , file .read (4 * nw ))
759+ heights = struct .unpack (f'!{ nh } i' , file .read (4 * nh ))
760+ depths = struct .unpack (f'!{ nd } i' , file .read (4 * nd ))
773761 self .width , self .height , self .depth = {}, {}, {}
774- widths , heights , depths = \
775- [struct .unpack ('!%dI' % (len (x )/ 4 ), x )
776- for x in (widths , heights , depths )]
777762 for idx , char in enumerate (range (bc , ec + 1 )):
778763 byte0 = char_info [4 * idx ]
779764 byte1 = char_info [4 * idx + 1 ]
780- self .width [char ] = _fix2comp ( widths [byte0 ])
781- self .height [char ] = _fix2comp ( heights [byte1 >> 4 ])
782- self .depth [char ] = _fix2comp ( depths [byte1 & 0xf ])
765+ self .width [char ] = widths [byte0 ]
766+ self .height [char ] = heights [byte1 >> 4 ]
767+ self .depth [char ] = depths [byte1 & 0xf ]
783768
784769
785770PsFont = namedtuple ('PsFont' , 'texname psname effects encoding filename' )
0 commit comments