Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be2945f

Browse files
committed
Deprecated classes in dviread
1 parent 68d6b79 commit be2945f

File tree

9 files changed

+802
-758
lines changed

9 files changed

+802
-758
lines changed

lib/matplotlib/_dviread.py

Lines changed: 599 additions & 0 deletions
Large diffs are not rendered by default.

lib/matplotlib/_dviread_vf.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import logging
2+
from functools import partial
3+
4+
from matplotlib.dviread import Dvi, _dvistate
5+
from matplotlib import _dviread
6+
7+
8+
_log = logging.getLogger(__name__)
9+
10+
11+
class Vf(Dvi):
12+
r"""
13+
A virtual font (\*.vf file) containing subroutines for dvi files.
14+
15+
Parameters
16+
----------
17+
filename : str or path-like
18+
19+
Notes
20+
-----
21+
The virtual font format is a derivative of dvi:
22+
http://mirrors.ctan.org/info/knuth/virtual-fonts
23+
This class reuses some of the machinery of `Dvi`
24+
but replaces the `_read` loop and dispatch mechanism.
25+
26+
Examples
27+
--------
28+
::
29+
30+
vf = Vf(filename)
31+
glyph = vf[code]
32+
glyph.text, glyph.boxes, glyph.width
33+
"""
34+
35+
def __init__(self, filename):
36+
super().__init__(filename, 0)
37+
try:
38+
self._first_font = None
39+
self._chars = {}
40+
self._read()
41+
finally:
42+
self.close()
43+
44+
def __getitem__(self, code):
45+
return self._chars[code]
46+
47+
def _read(self):
48+
"""
49+
Read one page from the file. Return True if successful,
50+
False if there were no more pages.
51+
"""
52+
packet_char, packet_ends = None, None
53+
packet_len, packet_width = None, None
54+
while True:
55+
byte = self.file.read(1)[0]
56+
# If we are in a packet, execute the dvi instructions
57+
if self.state is _dvistate.inpage:
58+
byte_at = self.file.tell()-1
59+
if byte_at == packet_ends:
60+
self._finalize_packet(packet_char, packet_width)
61+
packet_len, packet_char, packet_width = None, None, None
62+
# fall through to out-of-packet code
63+
elif byte_at > packet_ends:
64+
raise ValueError("Packet length mismatch in vf file")
65+
else:
66+
if byte in (139, 140) or byte >= 243:
67+
raise ValueError(
68+
"Inappropriate opcode %d in vf file" % byte)
69+
Dvi._dtable[byte](self, byte)
70+
continue
71+
72+
# We are outside a packet
73+
if byte < 242: # a short packet (length given by byte)
74+
packet_len = byte
75+
packet_char, packet_width = self._arg(1), self._arg(3)
76+
packet_ends = self._init_packet(byte)
77+
self.state = _dvistate.inpage
78+
elif byte == 242: # a long packet
79+
packet_len, packet_char, packet_width = \
80+
[self._arg(x) for x in (4, 4, 4)]
81+
self._init_packet(packet_len)
82+
elif 243 <= byte <= 246:
83+
k = self._arg(byte - 242, byte == 246)
84+
c, s, d, a, l = [self._arg(x) for x in (4, 4, 4, 1, 1)]
85+
self._fnt_def_real(k, c, s, d, a, l)
86+
if self._first_font is None:
87+
self._first_font = k
88+
elif byte == 247: # preamble
89+
i, k = self._arg(1), self._arg(1)
90+
x = self.file.read(k)
91+
cs, ds = self._arg(4), self._arg(4)
92+
self._pre(i, x, cs, ds)
93+
elif byte == 248: # postamble (just some number of 248s)
94+
break
95+
else:
96+
raise ValueError("Unknown vf opcode %d" % byte)
97+
98+
def _init_packet(self, pl):
99+
if self.state != _dvistate.outer:
100+
raise ValueError("Misplaced packet in vf file")
101+
self.h, self.v, self.w, self.x, self.y, self.z = 0, 0, 0, 0, 0, 0
102+
self.stack, self.text, self.boxes = [], [], []
103+
self.f = self._first_font
104+
return self.file.tell() + pl
105+
106+
def _finalize_packet(self, packet_char, packet_width):
107+
self._chars[packet_char] = _dviread.Page(
108+
text=self.text, boxes=self.boxes, width=packet_width,
109+
height=None, descent=None)
110+
self.state = _dvistate.outer
111+
112+
def _pre(self, i, x, cs, ds):
113+
if self.state is not _dvistate.pre:
114+
raise ValueError("pre command in middle of vf file")
115+
if i != 202:
116+
raise ValueError("Unknown vf format %d" % i)
117+
if len(x):
118+
_log.debug('vf file comment: %s', x)
119+
self.state = _dvistate.outer
120+
# cs = checksum, ds = design size
121+
122+
123+
_vffile = partial(_dviread._fontfile, Vf, ".vf")

lib/matplotlib/backends/backend_pdf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from matplotlib.font_manager import findfont, get_font
3737
from matplotlib.afm import AFM
3838
import matplotlib.type1font as type1font
39+
import matplotlib._dviread as _dviread
3940
import matplotlib.dviread as dviread
4041
from matplotlib.ft2font import (FIXED_WIDTH, ITALIC, LOAD_NO_SCALE,
4142
LOAD_NO_HINTING, KERNING_UNFITTED, FT2Font)
@@ -891,7 +892,8 @@ def dviFontName(self, dvifont):
891892
if dvi_info is not None:
892893
return dvi_info.pdfname
893894

894-
tex_font_map = dviread.PsfontsMap(dviread._find_tex_file('pdftex.map'))
895+
tex_font_map = _dviread.PsfontsMap(
896+
_dviread._find_tex_file('pdftex.map'))
895897
psfont = tex_font_map[dvifont.texname]
896898
if psfont.filename is None:
897899
raise ValueError(
@@ -966,7 +968,7 @@ def _embedTeXFont(self, fontinfo):
966968
fontdict['Encoding'] = {
967969
'Type': Name('Encoding'),
968970
'Differences': [
969-
0, *map(Name, dviread._parse_enc(fontinfo.encodingfile))],
971+
0, *map(Name, _dviread._parse_enc(fontinfo.encodingfile))],
970972
}
971973

972974
# If no file is specified, stop short

0 commit comments

Comments
 (0)