Skip to content

Fix missing font error when using MiKTeX #28340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions lib/matplotlib/dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
self.dpi = dpi
self.fonts = {}
self.state = _dvistate.pre
self._missing_font = None

def __enter__(self):
"""Context manager enter method, does nothing."""
Expand Down Expand Up @@ -337,6 +338,8 @@
while True:
byte = self.file.read(1)[0]
self._dtable[byte](self, byte)
if self._missing_font:
raise self._missing_font

Check warning on line 342 in lib/matplotlib/dviread.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/dviread.py#L342

Added line #L342 was not covered by tests
name = self._dtable[byte].__name__
if name == "_push":
down_stack.append(down_stack[-1])
Expand Down Expand Up @@ -364,11 +367,15 @@
@_dispatch(min=0, max=127, state=_dvistate.inpage)
def _set_char_immediate(self, char):
self._put_char_real(char)
if isinstance(self.fonts[self.f], FileNotFoundError):
return

Check warning on line 371 in lib/matplotlib/dviread.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/dviread.py#L371

Added line #L371 was not covered by tests
self.h += self.fonts[self.f]._width_of(char)

@_dispatch(min=128, max=131, state=_dvistate.inpage, args=('olen1',))
def _set_char(self, char):
self._put_char_real(char)
if isinstance(self.fonts[self.f], FileNotFoundError):
return

Check warning on line 378 in lib/matplotlib/dviread.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/dviread.py#L378

Added line #L378 was not covered by tests
self.h += self.fonts[self.f]._width_of(char)

@_dispatch(132, state=_dvistate.inpage, args=('s4', 's4'))
Expand All @@ -382,7 +389,9 @@

def _put_char_real(self, char):
font = self.fonts[self.f]
if font._vf is None:
if isinstance(font, FileNotFoundError):
self._missing_font = font

Check warning on line 393 in lib/matplotlib/dviread.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/dviread.py#L393

Added line #L393 was not covered by tests
elif font._vf is None:
self.text.append(Text(self.h, self.v, font, char,
font._width_of(char)))
else:
Expand Down Expand Up @@ -486,7 +495,16 @@
def _fnt_def_real(self, k, c, s, d, a, l):
n = self.file.read(a + l)
fontname = n[-l:].decode('ascii')
tfm = _tfmfile(fontname)
try:
tfm = _tfmfile(fontname)
except FileNotFoundError as exc:

Check warning on line 500 in lib/matplotlib/dviread.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/dviread.py#L500

Added line #L500 was not covered by tests
# Explicitly allow defining missing fonts for Vf support; we only
# register an error when trying to load a glyph from a missing font
# and throw that error in Dvi._read. For Vf, _finalize_packet
# checks whether a missing glyph has been used, and in that case
# skips the glyph definition.
self.fonts[k] = exc
return

Check warning on line 507 in lib/matplotlib/dviread.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/dviread.py#L506-L507

Added lines #L506 - L507 were not covered by tests
if c != 0 and tfm.checksum != 0 and c != tfm.checksum:
raise ValueError('tfm checksum mismatch: %s' % n)
try:
Expand Down Expand Up @@ -712,12 +730,14 @@
self.h, self.v, self.w, self.x, self.y, self.z = 0, 0, 0, 0, 0, 0
self.stack, self.text, self.boxes = [], [], []
self.f = self._first_font
self._missing_font = None
return self.file.tell() + pl

def _finalize_packet(self, packet_char, packet_width):
self._chars[packet_char] = Page(
text=self.text, boxes=self.boxes, width=packet_width,
height=None, descent=None)
if not self._missing_font: # Otherwise we don't have full glyph definition.
self._chars[packet_char] = Page(
text=self.text, boxes=self.boxes, width=packet_width,
height=None, descent=None)
self.state = _dvistate.outer

def _pre(self, i, x, cs, ds):
Expand Down
Loading