Skip to content

Commit b49c6dc

Browse files
committed
Rename the confusingly named dviread._mul2012.
Dvi fixed-point values are in 12.20 format (12 bits before the decimal point, 20 bits after -- see e.g. the 20-bit bitshifts scattered in the dviread module), not 20.12. Rename the helper function accordingly.
1 parent 41bb3e5 commit b49c6dc

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

lib/matplotlib/dviread.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,14 @@ def _put_char_real(self, char):
398398
else:
399399
scale = font._scale
400400
for x, y, f, g, w in font._vf[char].text:
401-
newf = DviFont(scale=_mul2012(scale, f._scale),
401+
newf = DviFont(scale=_mul1220(scale, f._scale),
402402
tfm=f._tfm, texname=f.texname, vf=f._vf)
403-
self.text.append(Text(self.h + _mul2012(x, scale),
404-
self.v + _mul2012(y, scale),
403+
self.text.append(Text(self.h + _mul1220(x, scale),
404+
self.v + _mul1220(y, scale),
405405
newf, g, newf._width_of(g)))
406-
self.boxes.extend([Box(self.h + _mul2012(x, scale),
407-
self.v + _mul2012(y, scale),
408-
_mul2012(a, scale), _mul2012(b, scale))
406+
self.boxes.extend([Box(self.h + _mul1220(x, scale),
407+
self.v + _mul1220(y, scale),
408+
_mul1220(a, scale), _mul1220(b, scale))
409409
for x, y, a, b in font._vf[char].boxes])
410410

411411
@_dispatch(137, state=_dvistate.inpage, args=('s4', 's4'))
@@ -606,7 +606,7 @@ def _width_of(self, char):
606606
"""Width of char in dvi units."""
607607
width = self._tfm.width.get(char, None)
608608
if width is not None:
609-
return _mul2012(width, self._scale)
609+
return _mul1220(width, self._scale)
610610
_log.debug('No width for char %d in font %s.', char, self.texname)
611611
return 0
612612

@@ -621,7 +621,7 @@ def _height_depth_of(self, char):
621621
name, char, self.texname)
622622
result.append(0)
623623
else:
624-
result.append(_mul2012(value, self._scale))
624+
result.append(_mul1220(value, self._scale))
625625
# cmsyXX (symbols font) glyph 0 ("minus") has a nonzero descent
626626
# so that TeX aligns equations properly
627627
# (https://tex.stackexchange.com/q/526103/)
@@ -755,8 +755,8 @@ def _pre(self, i, x, cs, ds):
755755
# cs = checksum, ds = design size
756756

757757

758-
def _mul2012(num1, num2):
759-
"""Multiply two numbers in 20.12 fixed point format."""
758+
def _mul1220(num1, num2):
759+
"""Multiply two numbers in 12.20 fixed point format."""
760760
# Separated into a function because >> has surprising precedence
761761
return (num1*num2) >> 20
762762

lib/matplotlib/dviread.pyi

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ class Dvi:
5656
class DviFont:
5757
texname: bytes
5858
size: float
59-
widths: list[int]
6059
def __init__(
6160
self, scale: float, tfm: Tfm, texname: bytes, vf: Vf | None
6261
) -> None: ...
6362
def __eq__(self, other: object) -> bool: ...
6463
def __ne__(self, other: object) -> bool: ...
64+
@property
65+
def widths(self) -> list[int]: ...
6566

6667
class Vf(Dvi):
6768
def __init__(self, filename: str | os.PathLike) -> None: ...

0 commit comments

Comments
 (0)