Skip to content

Commit bdef78f

Browse files
committed
Parse {lua,xe}tex-generated dvi in dviread.
1 parent 99a521b commit bdef78f

File tree

9 files changed

+1436
-110
lines changed

9 files changed

+1436
-110
lines changed

lib/matplotlib/backends/backend_pdf.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -996,11 +996,11 @@ def _embedTeXFont(self, fontinfo):
996996

997997
# Widths
998998
widthsObject = self.reserveObject('font widths')
999-
tfm = fontinfo.dvifont._tfm
999+
font_metrics = fontinfo.dvifont._metrics
10001000
# convert from TeX's 12.20 representation to 1/1000 text space units.
1001-
widths = [(1000 * metrics.tex_width) >> 20
1002-
if (metrics := tfm.get_metrics(char)) else 0
1003-
for char in range(max(tfm._glyph_metrics, default=-1) + 1)]
1001+
widths = [(1000 * glyph_metrics.tex_width) >> 20
1002+
if (glyph_metrics := font_metrics.get_metrics(char)) else 0
1003+
for char in range(max(font_metrics._glyph_metrics, default=-1) + 1)]
10041004
self.writeObject(widthsObject, widths)
10051005

10061006
# Font dictionary

lib/matplotlib/dviread.py

+212-86
Large diffs are not rendered by default.

lib/matplotlib/dviread.pyi

+19-2
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,27 @@ class Dvi:
5858

5959
class DviFont:
6060
texname: bytes
61-
size: float
6261
def __init__(
63-
self, scale: float, tfm: Tfm, texname: bytes, vf: Vf | None
62+
self, scale: float, metrics: Tfm | TtfMetrics, texname: bytes, vf: Vf | None
6463
) -> None: ...
64+
@classmethod
65+
def from_luatex(cls, scale: float, texname: bytes): ...
66+
@classmethod
67+
def from_xetex(
68+
cls, scale: float, texname: bytes, subfont: int, effects: dict[str, float]
69+
): ...
6570
def __eq__(self, other: object) -> bool: ...
6671
def __ne__(self, other: object) -> bool: ...
6772
@property
73+
def size(self) -> float: ...
74+
@property
6875
def widths(self) -> list[int]: ...
76+
@property
77+
def path(self) -> Path: ...
78+
@property
79+
def subfont(self) -> int: ...
80+
@property
81+
def effects(self) -> dict[str, float]: ...
6982

7083
class Vf(Dvi):
7184
def __init__(self, filename: str | os.PathLike) -> None: ...
@@ -91,6 +104,10 @@ class Tfm:
91104
@property
92105
def depth(self) -> dict[int, int]: ...
93106

107+
class TtfMetrics:
108+
def __init__(self, filename: str | os.PathLike) -> None: ...
109+
def get_metrics(self, idx: int) -> TexMetrics: ...
110+
94111
class PsFont(NamedTuple):
95112
texname: bytes
96113
psname: bytes

0 commit comments

Comments
 (0)