| [ Web Proxy ] |
| Viewing: https://matplotlib.org/stable/api/_as_gen/../../gallery/scales/../pyplots/../../api/dviread.html | [Back] [Original] |
matplotlib.dviread#A module for reading dvi files output by TeX. Several limitations make this not (currently) useful as a general-purpose dvi preprocessor, but it is currently used by the pdf backend for processing usetex text.
Interface:
with Dvi(filename, 72) as dvi:
# iterate over pages:
for page in dvi:
w, h, d = page.width, page.height, page.descent
for x, y, font, glyph, width in page.text:
fontname = font.texname
pointsize = font.size
...
for x, y, height, width in page.boxes:
...
Bases: object
A reader for a dvi ("device-independent") file, as produced by TeX.
The current implementation can only iterate through pages in order, and does not even attempt to verify the postamble.
This class can be used as a context manager to close the underlying file upon exit. Pages can be read via iteration. Here is an overly simple way to extract text without trying to detect whitespace:
>>> with matplotlib.dviread.Dvi('input.dvi', 72) as dvi:
... for page in dvi:
... print(''.join(chr(t.glyph) for t in page.text))
Read the data from the file named filename and convert TeX's internal units to units of dpi per inch. dpi only sets the units and does not limit the resolution. Use None to return TeX's internal units.
Bases: object
Encapsulation of a font that a DVI file can refer to.
This class holds a font's texname and size, supports comparison, and knows the widths of glyphs in the same units as the AFM file. There are also internal attributes (for use by dviread.py) that are not used for comparison.
The size is in Adobe points (converted from TeX points).
Factor by which the font is scaled from its natural size.
TeX font metrics for this font
Name of the font as used internally in the DVI file, as an ASCII
bytestring. This is usually very different from any external font
names; PsfontsMap can be used to find the external name of the font.
A TeX "virtual font" file, or None if this font is not virtual.
fnamestrA fake filename
Size of the font in Adobe points, converted from the slightly smaller TeX points.
A fake filename
Bases: tuple
Create new instance of PsFont(texname, psname, effects, encoding, filename)
Alias for field number 2
Alias for field number 3
Alias for field number 4
Alias for field number 1
Alias for field number 0
Bases: object
A psfonts.map formatted file, mapping TeX fonts to PS fonts.
Notes
For historical reasons, TeX knows many Type-1 fonts by different names than the outside world. (For one thing, the names have to fit in eight characters.) Also, TeX's native fonts are not Type-1 but Metafont, which is nontrivial to convert to PostScript except as a bitmap. While high-quality conversions to Type-1 format exist and are shipped with modern TeX distributions, we need to know which Type-1 fonts are the counterparts of which native fonts. For these reasons a mapping is needed from internal font names to font file names.
A texmf tree typically includes mapping files called e.g.
psfonts.map, pdftex.map, or dvipdfm.map.
The file psfonts.map is used by dvips,
pdftex.map by pdfTeX, and dvipdfm.map
by dvipdfm. psfonts.map might avoid embedding
the 35 PostScript fonts (i.e., have no filename for them, as in
the Times-Bold example above), while the pdf-related files perhaps
only avoid the "Base 14" pdf fonts. But the user may have
configured these files differently.
Examples
>>> map = PsfontsMap(find_tex_file('pdftex.map'))
>>> entry = map[b'ptmbo8r']
>>> entry.texname
b'ptmbo8r'
>>> entry.psname
b'Times-Bold'
>>> entry.encoding
'/usr/local/texlive/2008/texmf-dist/fonts/enc/dvips/base/8r.enc'
>>> entry.effects
{'slant': 0.16700000000000001}
>>> entry.filename
Bases: object
Metrics of a glyph, with TeX semantics.
TeX metrics have different semantics from FreeType metrics: tex_width
corresponds to FreeType's advance (i.e., including whitespace padding);
tex_height to bearingY (how much the glyph extends over the baseline);
tex_depth to height - bearingY (how much the glyph extends under the
baseline, as a positive number).
Bases: object
A TeX Font Metric file.
This implementation covers only the bare minimum needed by the Dvi class.
Used for verifying against the dvi file.
Design size of the font (in 12.20 TeX points); unused because it is overridden by the scale factor specified in the dvi file.
Bases: Dvi
A virtual font (*.vf file) containing subroutines for dvi files.
Notes
The virtual font format is a derivative of dvi:
http://mirrors.ctan.org/info/knuth/virtual-fonts
This class reuses some of the machinery of Dvi
but replaces the _read loop and dispatch mechanism.
Examples
vf = Vf(filename)
glyph = vf[code]
glyph.text, glyph.boxes, glyph.width
Read the data from the file named filename and convert TeX's internal units to units of dpi per inch. dpi only sets the units and does not limit the resolution. Use None to return TeX's internal units.
Find a file in the texmf tree using kpathsea.
The kpathsea library, provided by most existing TeX distributions, both on Unix-like systems and on Windows (MikTeX), is invoked via a long-lived luatex process if luatex is installed, or via kpsewhich otherwise.
If the file is not found.
| Web Proxy Viewer | New URL | Original Page |