68
68
##############################################################################
69
69
# FONTS
70
70
71
- def get_unicode_index (symbol , nonMath = False ):
71
+ def get_unicode_index (symbol , non_math = False ):
72
72
"""get_unicode_index(symbol, [bool]) -> integer
73
73
74
74
Return the integer index (from the Unicode table) of symbol. *symbol*
75
75
can be a single unicode character, a TeX command (i.e. r'\pi'), or a
76
76
Type1 symbol name (i.e. 'phi').
77
- If nonMath is True, the current symbol should be treated as a non-math symbol.
77
+ If non_math is True, the current symbol should be treated as a non-math symbol.
78
78
"""
79
+ # for a non-math symbol, simply return its unicode index
80
+ if non_math :
81
+ return ord (symbol )
79
82
# From UTF #25: U+2212 minus sign is the preferred
80
83
# representation of the unary and binary minus sign rather than
81
84
# the ASCII-derived U+002D hyphen-minus, because minus sign is
82
85
# unambiguous and because it is rendered with a more desirable
83
86
# length, usually longer than a hyphen.
84
- # Hyphens in texts will not be affected.
85
- if not nonMath and symbol == '-' :
87
+ if symbol == '-' :
86
88
return 0x2212
87
89
try :# This will succeed if symbol is a single unicode char
88
90
return ord (symbol )
@@ -440,7 +442,7 @@ def get_kern(self, font1, fontclass1, sym1, fontsize1,
440
442
"""
441
443
return 0.
442
444
443
- def get_metrics (self , font , font_class , sym , fontsize , dpi , nonMath = False ):
445
+ def get_metrics (self , font , font_class , sym , fontsize , dpi , non_math = False ):
444
446
"""
445
447
*font*: one of the TeX font names::
446
448
@@ -454,7 +456,7 @@ def get_metrics(self, font, font_class, sym, fontsize, dpi, nonMath=False):
454
456
455
457
*dpi*: current dots-per-inch
456
458
457
- *nonMath *: whether sym is a nonMath character
459
+ *non_math *: whether sym is a non-math character
458
460
459
461
Returns an object with the following attributes:
460
462
@@ -470,7 +472,7 @@ def get_metrics(self, font, font_class, sym, fontsize, dpi, nonMath=False):
470
472
the glyph. This corresponds to TeX's definition of
471
473
"height".
472
474
"""
473
- info = self ._get_info (font , font_class , sym , fontsize , dpi , nonMath )
475
+ info = self ._get_info (font , font_class , sym , fontsize , dpi , non_math )
474
476
return info .metrics
475
477
476
478
def set_canvas_size (self , w , h , d ):
@@ -586,14 +588,14 @@ def _get_offset(self, font, glyph, fontsize, dpi):
586
588
return ((glyph .height / 64.0 / 2.0 ) + (fontsize / 3.0 * dpi / 72.0 ))
587
589
return 0.
588
590
589
- def _get_info (self , fontname , font_class , sym , fontsize , dpi , nonMath = False ):
591
+ def _get_info (self , fontname , font_class , sym , fontsize , dpi , non_math = False ):
590
592
key = fontname , font_class , sym , fontsize , dpi
591
593
bunch = self .glyphd .get (key )
592
594
if bunch is not None :
593
595
return bunch
594
596
595
597
font , num , symbol_name , fontsize , slanted = \
596
- self ._get_glyph (fontname , font_class , sym , fontsize , nonMath )
598
+ self ._get_glyph (fontname , font_class , sym , fontsize , non_math )
597
599
598
600
font .set_size (fontsize , dpi )
599
601
glyph = font .load_char (
@@ -683,7 +685,7 @@ def __init__(self, *args, **kwargs):
683
685
684
686
_slanted_symbols = set (r"\int \oint" .split ())
685
687
686
- def _get_glyph (self , fontname , font_class , sym , fontsize , nonMath = False ):
688
+ def _get_glyph (self , fontname , font_class , sym , fontsize , non_math = False ):
687
689
symbol_name = None
688
690
font = None
689
691
if fontname in self .fontmap and sym in latex_to_bakoma :
@@ -703,7 +705,7 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, nonMath=False):
703
705
704
706
if symbol_name is None :
705
707
return self ._stix_fallback ._get_glyph (
706
- fontname , font_class , sym , fontsize , nonMath )
708
+ fontname , font_class , sym , fontsize , non_math )
707
709
708
710
return font , num , symbol_name , fontsize , slanted
709
711
@@ -800,7 +802,7 @@ def __init__(self, *args, **kwargs):
800
802
def _map_virtual_font (self , fontname , font_class , uniindex ):
801
803
return fontname , uniindex
802
804
803
- def _get_glyph (self , fontname , font_class , sym , fontsize , nonMath = False ):
805
+ def _get_glyph (self , fontname , font_class , sym , fontsize , non_math = False ):
804
806
found_symbol = False
805
807
806
808
if self .use_cmex :
@@ -811,7 +813,7 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, nonMath=False):
811
813
812
814
if not found_symbol :
813
815
try :
814
- uniindex = get_unicode_index (sym , nonMath )
816
+ uniindex = get_unicode_index (sym , non_math )
815
817
found_symbol = True
816
818
except ValueError :
817
819
uniindex = ord ('?' )
@@ -904,11 +906,11 @@ def __init__(self, *args, **kwargs):
904
906
self .fontmap [key ] = fullpath
905
907
self .fontmap [name ] = fullpath
906
908
907
- def _get_glyph (self , fontname , font_class , sym , fontsize , nonMath = False ):
909
+ def _get_glyph (self , fontname , font_class , sym , fontsize , non_math = False ):
908
910
""" Override prime symbol to use Bakoma """
909
911
if sym == r'\prime' :
910
912
return self .bakoma ._get_glyph (fontname ,
911
- font_class , sym , fontsize , nonMath )
913
+ font_class , sym , fontsize , non_math )
912
914
else :
913
915
# check whether the glyph is available in the display font
914
916
uniindex = get_unicode_index (sym )
@@ -917,10 +919,10 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, nonMath=False):
917
919
glyphindex = font .get_char_index (uniindex )
918
920
if glyphindex != 0 :
919
921
return super (DejaVuFonts , self )._get_glyph ('ex' ,
920
- font_class , sym , fontsize , nonMath )
922
+ font_class , sym , fontsize , non_math )
921
923
# otherwise return regular glyph
922
924
return super (DejaVuFonts , self )._get_glyph (fontname ,
923
- font_class , sym , fontsize , nonMath )
925
+ font_class , sym , fontsize , non_math )
924
926
925
927
926
928
class DejaVuSerifFonts (DejaVuFonts ):
@@ -1128,7 +1130,7 @@ def _get_font(self, font):
1128
1130
self .fonts [cached_font .get_fontname ()] = cached_font
1129
1131
return cached_font
1130
1132
1131
- def _get_info (self , fontname , font_class , sym , fontsize , dpi , nonMath = False ):
1133
+ def _get_info (self , fontname , font_class , sym , fontsize , dpi , non_math = False ):
1132
1134
'load the cmfont, metrics and glyph with caching'
1133
1135
key = fontname , sym , fontsize , dpi
1134
1136
tup = self .glyphd .get (key )
@@ -1454,15 +1456,15 @@ class Char(Node):
1454
1456
from width) must be converted into a :class:`Kern` node when the
1455
1457
:class:`Char` is added to its parent :class:`Hlist`.
1456
1458
"""
1457
- def __init__ (self , c , state , nonMath = False ):
1459
+ def __init__ (self , c , state , non_math = False ):
1458
1460
Node .__init__ (self )
1459
1461
self .c = c
1460
1462
self .font_output = state .font_output
1461
1463
self .font = state .font
1462
1464
self .font_class = state .font_class
1463
1465
self .fontsize = state .fontsize
1464
1466
self .dpi = state .dpi
1465
- self .nonMath = nonMath
1467
+ self .non_math = non_math
1466
1468
# The real width, height and depth will be set during the
1467
1469
# pack phase, after we know the real fontsize
1468
1470
self ._update_metrics ()
@@ -1472,7 +1474,7 @@ def __internal_repr__(self):
1472
1474
1473
1475
def _update_metrics (self ):
1474
1476
metrics = self ._metrics = self .font_output .get_metrics (
1475
- self .font , self .font_class , self .c , self .fontsize , self .dpi , self .nonMath )
1477
+ self .font , self .font_class , self .c , self .fontsize , self .dpi , self .non_math )
1476
1478
if self .c == ' ' :
1477
1479
self .width = metrics .advance
1478
1480
else :
@@ -2594,7 +2596,7 @@ def math(self, s, loc, toks):
2594
2596
def non_math (self , s , loc , toks ):
2595
2597
#~ print "non_math", toks
2596
2598
s = toks [0 ].replace (r'\$' , '$' )
2597
- symbols = [Char (c , self .get_state (), nonMath = True ) for c in s ]
2599
+ symbols = [Char (c , self .get_state (), non_math = True ) for c in s ]
2598
2600
hlist = Hlist (symbols )
2599
2601
# We're going into math now, so set font to 'it'
2600
2602
self .push_state ()
0 commit comments