@@ -422,9 +422,9 @@ def _put_char_real(self, char):
422
422
self .text .append (Text (self .h , self .v , font , char ,
423
423
font ._width_of (char )))
424
424
else :
425
- scale = font ._scale
425
+ scale = font .scale
426
426
for x , y , f , g , w in font ._vf [char ].text :
427
- newf = DviFont (scale = _mul2012 (scale , f ._scale ),
427
+ newf = DviFont (scale = _mul2012 (scale , f .scale ),
428
428
tfm = f ._tfm , texname = f .texname , vf = f ._vf )
429
429
self .text .append (Text (self .h + _mul2012 (x , scale ),
430
430
self .v + _mul2012 (y , scale ),
@@ -580,16 +580,19 @@ class DviFont(object):
580
580
----------
581
581
582
582
scale : float
583
- Factor by which the font is scaled from its natural size.
584
- tfm : Tfm
585
- TeX font metrics for this font
583
+ Factor by which the font is scaled from its natural size,
584
+ represented as an integer in 20.12 fixed-point format.
585
+ tfm : Tfm, may be None if widths given
586
+ TeX Font Metrics file for this font
586
587
texname : bytes
587
588
Name of the font as used internally by TeX and friends, as an
588
589
ASCII bytestring. This is usually very different from any external
589
590
font names, and :class:`dviread.PsfontsMap` can be used to find
590
591
the external name of the font.
591
- vf : Vf
592
+ vf : Vf or None
592
593
A TeX "virtual font" file, or None if this font is not virtual.
594
+ widths : list of integers, optional
595
+ Widths for this font. Overrides the widths read from the tfm file.
593
596
594
597
Attributes
595
598
----------
@@ -598,26 +601,37 @@ class DviFont(object):
598
601
size : float
599
602
Size of the font in Adobe points, converted from the slightly
600
603
smaller TeX points.
604
+ scale : int
605
+ Factor by which the font is scaled from its natural size,
606
+ represented as an integer in 20.12 fixed-point format.
601
607
widths : list
602
608
Widths of glyphs in glyph-space units, typically 1/1000ths of
603
609
the point size.
604
610
605
611
"""
606
- __slots__ = ('texname' , 'size' , 'widths' , '_scale ' , '_vf' , '_tfm' )
612
+ __slots__ = ('texname' , 'size' , 'widths' , 'scale ' , '_vf' , '_tfm' )
607
613
608
- def __init__ (self , scale , tfm , texname , vf ):
614
+ def __init__ (self , scale , tfm , texname , vf , widths = None ):
609
615
if not isinstance (texname , bytes ):
610
616
raise ValueError ("texname must be a bytestring, got %s"
611
617
% type (texname ))
612
- self ._scale , self ._tfm , self .texname , self ._vf = \
613
- scale , tfm , texname , vf
618
+ self .scale , self ._tfm , self .texname , self ._vf , self . widths = \
619
+ scale , tfm , texname , vf , widths
614
620
self .size = scale * (72.0 / (72.27 * 2 ** 16 ))
615
- try :
616
- nchars = max (tfm .width ) + 1
617
- except ValueError :
618
- nchars = 0
619
- self .widths = [(1000 * tfm .width .get (char , 0 )) >> 20
620
- for char in range (nchars )]
621
+
622
+ if self .widths is None :
623
+ try :
624
+ nchars = max (tfm .width ) + 1
625
+ except ValueError :
626
+ nchars = 0
627
+ self .widths = [(1000 * tfm .width .get (char , 0 )) >> 20
628
+ for char in range (nchars )]
629
+
630
+ def __repr__ (self ):
631
+ return '<DviFont %s *%f>' % (self .texname , self .scale / 2 ** 20 )
632
+
633
+ def __hash__ (self ):
634
+ return 1001 * hash (self .texname ) + hash (self .size )
621
635
622
636
def __eq__ (self , other ):
623
637
return self .__class__ == other .__class__ and \
@@ -633,7 +647,7 @@ def _width_of(self, char):
633
647
634
648
width = self ._tfm .width .get (char , None )
635
649
if width is not None :
636
- return _mul2012 (width , self ._scale )
650
+ return _mul2012 (width , self .scale )
637
651
_log .debug ('No width for char %d in font %s.' , char , self .texname )
638
652
return 0
639
653
@@ -651,7 +665,7 @@ def _height_depth_of(self, char):
651
665
name , char , self .texname )
652
666
result .append (0 )
653
667
else :
654
- result .append (_mul2012 (value , self ._scale ))
668
+ result .append (_mul2012 (value , self .scale ))
655
669
return result
656
670
657
671
@@ -1374,7 +1388,7 @@ def _fontfile(cls, suffix, texname):
1374
1388
fPrev = None
1375
1389
for x , y , f , c , w in page .text :
1376
1390
if f != fPrev :
1377
- print ('font' , f .texname , 'scaled' , f ._scale / pow (2.0 , 20 ))
1391
+ print ('font' , f .texname , 'scaled' , f .scale / pow (2.0 , 20 ))
1378
1392
fPrev = f
1379
1393
print (x , y , c , 32 <= c < 128 and chr (c ) or '.' , w )
1380
1394
for x , y , w , h in page .boxes :
0 commit comments