Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb151a85

Browse files
committed
Deprecated classes in dviread
1 parent68d6b79 commitb151a85

File tree

10 files changed

+803
-759
lines changed

10 files changed

+803
-759
lines changed

‎lib/matplotlib/_dviread.py

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

‎lib/matplotlib/_dviread_dispatch.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
fromfunctoolsimportpartial,wraps
2+
importlogging
3+
4+
_log=logging.getLogger(__name__)
5+
6+
# Opcode argument parsing
7+
#
8+
# Each of the following functions takes a Dvi object and delta,
9+
# which is the difference between the opcode and the minimum opcode
10+
# with the same meaning. Dvi opcodes often encode the number of
11+
# argument bytes in this delta.
12+
13+
def_arg_raw(dvi,delta):
14+
"""Return *delta* without reading anything more from the dvi file."""
15+
returndelta
16+
17+
18+
def_arg(nbytes,signed,dvi,_):
19+
"""
20+
Read *nbytes* bytes, returning the bytes interpreted as a signed integer
21+
if *signed* is true, unsigned otherwise.
22+
"""
23+
returndvi._arg(nbytes,signed)
24+
25+
26+
def_arg_slen(dvi,delta):
27+
"""
28+
Read *delta* bytes, returning None if *delta* is zero, and the bytes
29+
interpreted as a signed integer otherwise.
30+
"""
31+
ifdelta==0:
32+
returnNone
33+
returndvi._arg(delta,True)
34+
35+
36+
def_arg_slen1(dvi,delta):
37+
"""
38+
Read *delta*+1 bytes, returning the bytes interpreted as signed.
39+
"""
40+
returndvi._arg(delta+1,True)
41+
42+
43+
def_arg_ulen1(dvi,delta):
44+
"""
45+
Read *delta*+1 bytes, returning the bytes interpreted as unsigned.
46+
"""
47+
returndvi._arg(delta+1,False)
48+
49+
50+
def_arg_olen1(dvi,delta):
51+
"""
52+
Read *delta*+1 bytes, returning the bytes interpreted as
53+
unsigned integer for 0<=*delta*<3 and signed if *delta*==3.
54+
"""
55+
returndvi._arg(delta+1,delta==3)
56+
57+
58+
_arg_mapping=dict(raw=_arg_raw,
59+
u1=partial(_arg,1,False),
60+
u4=partial(_arg,4,False),
61+
s4=partial(_arg,4,True),
62+
slen=_arg_slen,
63+
olen1=_arg_olen1,
64+
slen1=_arg_slen1,
65+
ulen1=_arg_ulen1)
66+
67+
68+
def_dispatch(table,min,max=None,state=None,args=('raw',)):
69+
"""
70+
Decorator for dispatch by opcode. Sets the values in *table*
71+
from *min* to *max* to this method, adds a check that the Dvi state
72+
matches *state* if not None, reads arguments from the file according
73+
to *args*.
74+
75+
Parameters
76+
----------
77+
table : dict[int, callable]
78+
The dispatch table to be filled in.
79+
80+
min, max : int
81+
Range of opcodes that calls the registered function; *max* defaults to
82+
*min*.
83+
84+
state : _dvistate, optional
85+
State of the Dvi object in which these opcodes are allowed.
86+
87+
args : list[str], default: ['raw']
88+
Sequence of argument specifications:
89+
90+
- 'raw': opcode minus minimum
91+
- 'u1': read one unsigned byte
92+
- 'u4': read four bytes, treat as an unsigned number
93+
- 's4': read four bytes, treat as a signed number
94+
- 'slen': read (opcode - minimum) bytes, treat as signed
95+
- 'slen1': read (opcode - minimum + 1) bytes, treat as signed
96+
- 'ulen1': read (opcode - minimum + 1) bytes, treat as unsigned
97+
- 'olen1': read (opcode - minimum + 1) bytes, treat as unsigned
98+
if under four bytes, signed if four bytes
99+
"""
100+
defdecorate(method):
101+
get_args= [_arg_mapping[x]forxinargs]
102+
103+
@wraps(method)
104+
defwrapper(self,byte):
105+
ifstateisnotNoneandself.state!=state:
106+
raiseValueError("state precondition failed")
107+
returnmethod(self,*[f(self,byte-min)forfinget_args])
108+
ifmaxisNone:
109+
table[min]=wrapper
110+
else:
111+
foriinrange(min,max+1):
112+
asserttable[i]isNone
113+
table[i]=wrapper
114+
returnwrapper
115+
returndecorate

‎lib/matplotlib/_dviread_vf.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
importlogging
2+
fromfunctoolsimportpartial
3+
4+
frommatplotlib.dvireadimportDvi,_dvistate
5+
frommatplotlibimport_dviread
6+
7+
8+
_log=logging.getLogger(__name__)
9+
10+
11+
classVf(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+
returnself._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+
whileTrue:
55+
byte=self.file.read(1)[0]
56+
# If we are in a packet, execute the dvi instructions
57+
ifself.stateis_dvistate.inpage:
58+
byte_at=self.file.tell()-1
59+
ifbyte_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+
elifbyte_at>packet_ends:
64+
raiseValueError("Packet length mismatch in vf file")
65+
else:
66+
ifbytein (139,140)orbyte>=243:
67+
raiseValueError(
68+
"Inappropriate opcode %d in vf file"%byte)
69+
Dvi._dtable[byte](self,byte)
70+
continue
71+
72+
# We are outside a packet
73+
ifbyte<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+
elifbyte==242:# a long packet
79+
packet_len,packet_char,packet_width= \
80+
[self._arg(x)forxin (4,4,4)]
81+
self._init_packet(packet_len)
82+
elif243<=byte<=246:
83+
k=self._arg(byte-242,byte==246)
84+
c,s,d,a,l= [self._arg(x)forxin (4,4,4,1,1)]
85+
self._fnt_def_real(k,c,s,d,a,l)
86+
ifself._first_fontisNone:
87+
self._first_font=k
88+
elifbyte==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+
elifbyte==248:# postamble (just some number of 248s)
94+
break
95+
else:
96+
raiseValueError("Unknown vf opcode %d"%byte)
97+
98+
def_init_packet(self,pl):
99+
ifself.state!=_dvistate.outer:
100+
raiseValueError("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+
returnself.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+
ifself.stateisnot_dvistate.pre:
114+
raiseValueError("pre command in middle of vf file")
115+
ifi!=202:
116+
raiseValueError("Unknown vf format %d"%i)
117+
iflen(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
frommatplotlib.font_managerimportfindfont,get_font
3737
frommatplotlib.afmimportAFM
3838
importmatplotlib.type1fontastype1font
39+
importmatplotlib._dvireadas_dviread
3940
importmatplotlib.dvireadasdviread
4041
frommatplotlib.ft2fontimport (FIXED_WIDTH,ITALIC,LOAD_NO_SCALE,
4142
LOAD_NO_HINTING,KERNING_UNFITTED,FT2Font)
@@ -891,7 +892,8 @@ def dviFontName(self, dvifont):
891892
ifdvi_infoisnotNone:
892893
returndvi_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
ifpsfont.filenameisNone:
897899
raiseValueError(
@@ -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)

[8]ページ先頭

©2009-2025 Movatter.jp