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:
withDvi(filename,72)asdvi:# iterate over pages:forpageindvi:w,h,d=page.
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:
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.
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).
Parameters:
scale : float
Factor by which the font is scaled from its natural size.
metrics : Tfm | TtfMetrics
TeX font metrics for this font
texname : bytes
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.
vf : Vf
A TeX "virtual font" file, or None if this font is not virtual.
A psfonts.map formatted file, mapping TeX fonts to PS fonts.
Parameters:
filename : str or path-like
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.
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).
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.
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.