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

Commit1c6e116

Browse files
committed
Added keyword argument to PsfontsMap to allow find_tex_file
1 parent478baf9 commit1c6e116

File tree

5 files changed

+55
-193
lines changed

5 files changed

+55
-193
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Classes, functions, and named tuples in ``dviread`` deprecated
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The classes
5+
- ``DviFont``,
6+
- ``Vf``,
7+
- ``Tfm``,
8+
the function
9+
- ``find_tex_file``
10+
and the named tuples
11+
- ``Box``,
12+
- ``Page``,
13+
- ``Text``
14+
from the module ``matplotlib.dviread`` are considered internal and public
15+
access is deprecated.
16+
17+
18+
Module ``texmanager`` deprecated
19+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20+
21+
The module ``matplotlib.texmanager`` is considered internal and public access
22+
is deprecated.

‎lib/matplotlib/_dviread.py

Lines changed: 0 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"""
1919

2020
fromcollectionsimportnamedtuple
21-
importenum
2221
fromfunctoolsimportlru_cache,partial,wraps
2322
importlogging
2423
importos
@@ -297,186 +296,6 @@ def __init__(self, filename):
297296
self.depth[char]=depths[byte1&0xf]
298297

299298

300-
PsFont=namedtuple('PsFont','texname psname effects encoding filename')
301-
302-
303-
classPsfontsMap:
304-
"""
305-
A psfonts.map formatted file, mapping TeX fonts to PS fonts.
306-
307-
Parameters
308-
----------
309-
filename : str or path-like
310-
311-
Notes
312-
-----
313-
For historical reasons, TeX knows many Type-1 fonts by different
314-
names than the outside world. (For one thing, the names have to
315-
fit in eight characters.) Also, TeX's native fonts are not Type-1
316-
but Metafont, which is nontrivial to convert to PostScript except
317-
as a bitmap. While high-quality conversions to Type-1 format exist
318-
and are shipped with modern TeX distributions, we need to know
319-
which Type-1 fonts are the counterparts of which native fonts. For
320-
these reasons a mapping is needed from internal font names to font
321-
file names.
322-
323-
A texmf tree typically includes mapping files called e.g.
324-
:file:`psfonts.map`, :file:`pdftex.map`, or :file:`dvipdfm.map`.
325-
The file :file:`psfonts.map` is used by :program:`dvips`,
326-
:file:`pdftex.map` by :program:`pdfTeX`, and :file:`dvipdfm.map`
327-
by :program:`dvipdfm`. :file:`psfonts.map` might avoid embedding
328-
the 35 PostScript fonts (i.e., have no filename for them, as in
329-
the Times-Bold example above), while the pdf-related files perhaps
330-
only avoid the "Base 14" pdf fonts. But the user may have
331-
configured these files differently.
332-
333-
Examples
334-
--------
335-
>>> map = PsfontsMap(find_tex_file('pdftex.map'))
336-
>>> entry = map[b'ptmbo8r']
337-
>>> entry.texname
338-
b'ptmbo8r'
339-
>>> entry.psname
340-
b'Times-Bold'
341-
>>> entry.encoding
342-
'/usr/local/texlive/2008/texmf-dist/fonts/enc/dvips/base/8r.enc'
343-
>>> entry.effects
344-
{'slant': 0.16700000000000001}
345-
>>> entry.filename
346-
"""
347-
__slots__= ('_filename','_unparsed','_parsed')
348-
349-
# Create a filename -> PsfontsMap cache, so that calling
350-
# `PsfontsMap(filename)` with the same filename a second time immediately
351-
# returns the same object.
352-
@lru_cache()
353-
def__new__(cls,filename):
354-
self=object.__new__(cls)
355-
self._filename=os.fsdecode(filename)
356-
# Some TeX distributions have enormous pdftex.map files which would
357-
# take hundreds of milliseconds to parse, but it is easy enough to just
358-
# store the unparsed lines (keyed by the first word, which is the
359-
# texname) and parse them on-demand.
360-
withopen(filename,'rb')asfile:
361-
self._unparsed= {}
362-
forlineinfile:
363-
tfmname=line.split(b' ',1)[0]
364-
self._unparsed.setdefault(tfmname, []).append(line)
365-
self._parsed= {}
366-
returnself
367-
368-
def__getitem__(self,texname):
369-
assertisinstance(texname,bytes)
370-
iftexnameinself._unparsed:
371-
forlineinself._unparsed.pop(texname):
372-
ifself._parse_and_cache_line(line):
373-
break
374-
try:
375-
returnself._parsed[texname]
376-
exceptKeyError:
377-
raiseLookupError(
378-
f"An associated PostScript font (required by Matplotlib) "
379-
f"could not be found for TeX font{texname.decode('ascii')!r} "
380-
f"in{self._filename!r}; this problem can often be solved by "
381-
f"installing a suitable PostScript font package in your TeX "
382-
f"package manager")fromNone
383-
384-
def_parse_and_cache_line(self,line):
385-
"""
386-
Parse a line in the font mapping file.
387-
388-
The format is (partially) documented at
389-
http://mirrors.ctan.org/systems/doc/pdftex/manual/pdftex-a.pdf
390-
https://tug.org/texinfohtml/dvips.html#psfonts_002emap
391-
Each line can have the following fields:
392-
393-
- tfmname (first, only required field),
394-
- psname (defaults to tfmname, must come immediately after tfmname if
395-
present),
396-
- fontflags (integer, must come immediately after psname if present,
397-
ignored by us),
398-
- special (SlantFont and ExtendFont, only field that is double-quoted),
399-
- fontfile, encodingfile (optional, prefixed by <, <<, or <[; << always
400-
precedes a font, <[ always precedes an encoding, < can precede either
401-
but then an encoding file must have extension .enc; < and << also
402-
request different font subsetting behaviors but we ignore that; < can
403-
be separated from the filename by whitespace).
404-
405-
special, fontfile, and encodingfile can appear in any order.
406-
"""
407-
# If the map file specifies multiple encodings for a font, we
408-
# follow pdfTeX in choosing the last one specified. Such
409-
# entries are probably mistakes but they have occurred.
410-
# https://tex.stackexchange.com/q/10826/
411-
412-
ifnotlineorline.startswith((b" ",b"%",b"*",b";",b"#")):
413-
return
414-
tfmname=basename=special=encodingfile=fontfile=None
415-
is_subsetted=is_t1=is_truetype=False
416-
matches=re.finditer(br'"([^"]*)(?:"|$)|(\S+)',line)
417-
formatchinmatches:
418-
quoted,unquoted=match.groups()
419-
ifunquoted:
420-
ifunquoted.startswith(b"<<"):# font
421-
fontfile=unquoted[2:]
422-
elifunquoted.startswith(b"<["):# encoding
423-
encodingfile=unquoted[2:]
424-
elifunquoted.startswith(b"<"):# font or encoding
425-
word= (
426-
# <foo => foo
427-
unquoted[1:]
428-
# < by itself => read the next word
429-
ornext(filter(None,next(matches).groups())))
430-
ifword.endswith(b".enc"):
431-
encodingfile=word
432-
else:
433-
fontfile=word
434-
is_subsetted=True
435-
eliftfmnameisNone:
436-
tfmname=unquoted
437-
elifbasenameisNone:
438-
basename=unquoted
439-
elifquoted:
440-
special=quoted
441-
effects= {}
442-
ifspecial:
443-
words=reversed(special.split())
444-
forwordinwords:
445-
ifword==b"SlantFont":
446-
effects["slant"]=float(next(words))
447-
elifword==b"ExtendFont":
448-
effects["extend"]=float(next(words))
449-
450-
# Verify some properties of the line that would cause it to be ignored
451-
# otherwise.
452-
iffontfileisnotNone:
453-
iffontfile.endswith((b".ttf",b".ttc")):
454-
is_truetype=True
455-
elifnotfontfile.endswith(b".otf"):
456-
is_t1=True
457-
elifbasenameisnotNone:
458-
is_t1=True
459-
ifis_truetypeandis_subsettedandencodingfileisNone:
460-
return
461-
ifnotis_t1and ("slant"ineffectsor"extend"ineffects):
462-
return
463-
ifabs(effects.get("slant",0))>1:
464-
return
465-
ifabs(effects.get("extend",0))>2:
466-
return
467-
468-
ifbasenameisNone:
469-
basename=tfmname
470-
ifencodingfileisnotNone:
471-
encodingfile=_find_tex_file(encodingfile)
472-
iffontfileisnotNone:
473-
fontfile=_find_tex_file(fontfile)
474-
self._parsed[tfmname]=PsFont(
475-
texname=tfmname,psname=basename,effects=effects,
476-
encoding=encodingfile,filename=fontfile)
477-
returnTrue
478-
479-
480299
def_parse_enc(path):
481300
r"""
482301
Parse a \*.enc file referenced from a psfonts.map style file.

‎lib/matplotlib/backends/backend_pdf.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
fromPILimportImage
2727

2828
importmatplotlibasmpl
29-
frommatplotlibimport_api,_text_helpers,cbook
29+
frommatplotlibimport_api,_dviread,_text_helpers,cbook,dviread
3030
frommatplotlib._pylab_helpersimportGcf
3131
frommatplotlib.backend_basesimport (
3232
_Backend,FigureCanvasBase,FigureManagerBase,GraphicsContextBase,
@@ -36,8 +36,6 @@
3636
frommatplotlib.font_managerimportfindfont,get_font
3737
frommatplotlib.afmimportAFM
3838
importmatplotlib.type1fontastype1font
39-
importmatplotlib._dvireadas_dviread
40-
importmatplotlib.dvireadasdviread
4139
frommatplotlib.ft2fontimport (FIXED_WIDTH,ITALIC,LOAD_NO_SCALE,
4240
LOAD_NO_HINTING,KERNING_UNFITTED,FT2Font)
4341
frommatplotlib.mathtextimportMathTextParser
@@ -892,8 +890,7 @@ def dviFontName(self, dvifont):
892890
ifdvi_infoisnotNone:
893891
returndvi_info.pdfname
894892

895-
tex_font_map=_dviread.PsfontsMap(
896-
_dviread._find_tex_file('pdftex.map'))
893+
tex_font_map=dviread.PsfontsMap()
897894
psfont=tex_font_map[dvifont.texname]
898895
ifpsfont.filenameisNone:
899896
raiseValueError(

‎lib/matplotlib/dviread.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,26 @@
2626

2727
importnumpyasnp
2828

29-
frommatplotlibimport_api,cbook,_dviread,_dviread_vf
29+
frommatplotlibimport_api,_dviread
3030

3131
_log=logging.getLogger(__name__)
3232

33+
34+
@_api.caching_module_getattr
35+
class__getattr__:
36+
locals().update({
37+
name:_api.deprecated("3.6")(
38+
property(lambdaself,_mod=_dviread,_name=name:getattr(_mod,_name)))
39+
fornamein ["Book","Page","Text","DviFont","Tfm",
40+
"find_tex_file"]})
41+
42+
@_api.deprecated("3.6")
43+
classVf:
44+
def__init__(self,filename):
45+
frommatplotlibimport_vf
46+
return_vf.Vf(filename)
47+
48+
3349
# Many dvi related files are looked for by external processes, require
3450
# additional parsing, and are used many times per rendering, which is why they
3551
# are cached using lru_cache().
@@ -357,7 +373,8 @@ def _fnt_def_real(self, k, c, s, d, a, l):
357373
ifc!=0andtfm.checksum!=0andc!=tfm.checksum:
358374
raiseValueError('tfm checksum mismatch: %s'%n)
359375
try:
360-
vf=_dviread_vf._vffile(fontname)
376+
frommatplotlib._vfimport_vffile
377+
vf=_vffile(fontname)
361378
exceptFileNotFoundError:
362379
vf=None
363380
self.fonts[k]=_dviread.DviFont(scale=s,tfm=tfm,texname=n,vf=vf)
@@ -406,6 +423,10 @@ class PsfontsMap:
406423
----------
407424
filename : str or path-like
408425
426+
find_tex_file : bool (default False)
427+
If ``True``, *filename* is looked up in the tex build directory.
428+
If ``False`` (default), *filename* must be a fully qualified path.
429+
409430
Notes
410431
-----
411432
For historical reasons, TeX knows many Type-1 fonts by different
@@ -430,7 +451,7 @@ class PsfontsMap:
430451
431452
Examples
432453
--------
433-
>>> map = PsfontsMap(find_tex_file('pdftex.map'))
454+
>>> map = PsfontsMap('pdftex.map', find_tex_file=True)
434455
>>> entry = map[b'ptmbo8r']
435456
>>> entry.texname
436457
b'ptmbo8r'
@@ -448,9 +469,12 @@ class PsfontsMap:
448469
# `PsfontsMap(filename)` with the same filename a second time immediately
449470
# returns the same object.
450471
@lru_cache()
451-
def__new__(cls,filename):
472+
def__new__(cls,filename,*,find_tex_file=False):
452473
self=object.__new__(cls)
453-
self._filename=os.fsdecode(filename)
474+
iffind_tex_file:
475+
self._filename=os.fsdecode(_dviread.find_tex_file(filename))
476+
else:
477+
self._filename=os.fsdecode(filename)
454478
# Some TeX distributions have enormous pdftex.map files which would
455479
# take hundreds of milliseconds to parse, but it is easy enough to just
456480
# store the unparsed lines (keyed by the first word, which is the
@@ -584,7 +608,7 @@ def _parse_and_cache_line(self, line):
584608
parser.add_argument("dpi",nargs="?",type=float,default=None)
585609
args=parser.parse_args()
586610
withDvi(args.filename,args.dpi)asdvi:
587-
fontmap=PsfontsMap(_dviread._find_tex_file('pdftex.map'))
611+
fontmap=PsfontsMap("pdftex.map",find_tex_file=True)
588612
forpageindvi:
589613
print(f"=== new page === "
590614
f"(w:{page.width}, h:{page.height}, d:{page.descent})")

‎lib/matplotlib/textpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
279279
@staticmethod
280280
@functools.lru_cache(50)
281281
def_get_ps_font_and_encoding(texname):
282-
tex_font_map=dviread.get_tex_font_map('pdftex.map')
282+
tex_font_map=dviread.PsfontsMap('pdftex.map',find_tex_file=True)
283283
psfont=tex_font_map[texname]
284284
ifpsfont.filenameisNone:
285285
raiseValueError(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp