285 lines (261 with data), 17.2 kB
@header@
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="matplotlib.html"><font color="#ffffff">matplotlib</font></a>.dviread</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jdhunter/dev/lib64/python2.5/site-packages/matplotlib/dviread.py">/home/jdhunter/dev/lib64/python2.5/site-packages/matplotlib/dviread.py</a></font></td></tr></table>
<p><tt>An experimental module for reading dvi files output by TeX. Several<br>
limitations make this not (currently) useful as a general-purpose dvi<br>
preprocessor.<br>
<br>
Interface::<br>
<br>
dvi = <a href="#Dvi">Dvi</a>(filename, 72)<br>
for page in dvi: # iterate over pages<br>
w, h, d = page.width, page.height, page.descent<br>
for x,y,font,glyph,width in page.text:<br>
fontname = font.texname<br>
pointsize = font.size<br>
...<br>
for x,y,height,width in page.boxes:<br>
...</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="matplotlib.html">matplotlib</a><br>
<a href="matplotlib.cbook.html">matplotlib.cbook</a><br>
</td><td width="25%" valign=top><a href="numpy.html">numpy</a><br>
<a href="os.html">os</a><br>
</td><td width="25%" valign=top><a href="struct.html">struct</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="matplotlib.dviread.html#Dvi">Dvi</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="matplotlib.dviread.html#Vf">Vf</a>
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="matplotlib.dviread.html#DviFont">DviFont</a>
</font></dt><dt><font face="helvetica, arial"><a href="matplotlib.dviread.html#Encoding">Encoding</a>
</font></dt><dt><font face="helvetica, arial"><a href="matplotlib.dviread.html#PsfontsMap">PsfontsMap</a>
</font></dt><dt><font face="helvetica, arial"><a href="matplotlib.dviread.html#Tfm">Tfm</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Dvi">class <strong>Dvi</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>A dvi ("device-independent") file, as produced by TeX.<br>
The current implementation only reads the first page and does not<br>
even attempt to verify the postamble.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Dvi-__init__"><strong>__init__</strong></a>(self, filename, dpi)</dt><dd><tt>Initialize the <a href="__builtin__.html#object">object</a>. This takes the filename as input and<br>
opens the file; actually reading the file happens when<br>
iterating through the pages of the file.</tt></dd></dl>
<dl><dt><a name="Dvi-__iter__"><strong>__iter__</strong></a>(self)</dt><dd><tt>Iterate through the pages of the file.<br>
<br>
Returns (text, pages) pairs, where:<br>
text is a list of (x, y, fontnum, glyphnum, width) tuples<br>
boxes is a list of (x, y, height, width) tuples<br>
<br>
The coordinates are transformed into a standard Cartesian<br>
coordinate system at the dpi value given when initializing.<br>
The coordinates are floating point numbers, but otherwise<br>
precision is not lost and coordinate values are not clipped to<br>
integers.</tt></dd></dl>
<dl><dt><a name="Dvi-close"><strong>close</strong></a>(self)</dt><dd><tt>Close the underlying file if it is open.</tt></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="DviFont">class <strong>DviFont</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Object that holds a font's texname and size, supports comparison,<br>
and knows the widths of glyphs in the same units as the AFM file.<br>
There are also internal attributes (for use by dviread.py) that<br>
are _not_ used for comparison.<br>
<br>
The size is in Adobe points (converted from TeX points).<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="DviFont-__eq__"><strong>__eq__</strong></a>(self, other)</dt></dl>
<dl><dt><a name="DviFont-__init__"><strong>__init__</strong></a>(self, scale, tfm, texname, vf)</dt></dl>
<dl><dt><a name="DviFont-__ne__"><strong>__ne__</strong></a>(self, other)</dt></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>size</strong></dt>
</dl>
<dl><dt><strong>texname</strong></dt>
</dl>
<dl><dt><strong>widths</strong></dt>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Encoding">class <strong>Encoding</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Parses a \*.enc file referenced from a psfonts.map style file.<br>
The format this class understands is a very limited subset of<br>
PostScript.<br>
<br>
Usage (subject to change)::<br>
<br>
for name in <a href="#Encoding">Encoding</a>(filename):<br>
whatever(name)<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Encoding-__init__"><strong>__init__</strong></a>(self, filename)</dt></dl>
<dl><dt><a name="Encoding-__iter__"><strong>__iter__</strong></a>(self)</dt></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>encoding</strong></dt>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="PsfontsMap">class <strong>PsfontsMap</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>A psfonts.map formatted file, mapping TeX fonts to PS fonts.<br>
Usage: map = <a href="#PsfontsMap">PsfontsMap</a>('.../psfonts.map'); map['cmr10']<br>
<br>
For historical reasons, TeX knows many Type-1 fonts by different<br>
names than the outside world. (For one thing, the names have to<br>
fit in eight characters.) Also, TeX's native fonts are not Type-1<br>
but Metafont, which is nontrivial to convert to PostScript except<br>
as a bitmap. While high-quality conversions to Type-1 format exist<br>
and are shipped with modern TeX distributions, we need to know<br>
which Type-1 fonts are the counterparts of which native fonts. For<br>
these reasons a mapping is needed from internal font names to font<br>
file names.<br>
<br>
A texmf tree typically includes mapping files called e.g.<br>
psfonts.map, pdftex.map, dvipdfm.map. psfonts.map is used by<br>
dvips, pdftex.map by pdfTeX, and dvipdfm.map by dvipdfm.<br>
psfonts.map might avoid embedding the 35 PostScript fonts, while<br>
the pdf-related files perhaps only avoid the "Base 14" pdf fonts.<br>
But the user may have configured these files differently.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="PsfontsMap-__getitem__"><strong>__getitem__</strong></a>(self, texname)</dt></dl>
<dl><dt><a name="PsfontsMap-__init__"><strong>__init__</strong></a>(self, filename)</dt></dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Tfm">class <strong>Tfm</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>A TeX Font Metric file. This implementation covers only the bare<br>
minimum needed by the <a href="#Dvi">Dvi</a> class.<br>
<br>
Attributes:<br>
<br>
checksum: for verifying against dvi file<br>
<br>
design_size: design size of the font (in what units?)<br>
<br>
width[i]: width of character \#i, needs to be scaled<br>
by the factor specified in the dvi file<br>
(this is a dict because indexing may not start from 0)<br>
<br>
height[i], depth[i]: height and depth of character \#i<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Tfm-__init__"><strong>__init__</strong></a>(self, filename)</dt></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>checksum</strong></dt>
</dl>
<dl><dt><strong>depth</strong></dt>
</dl>
<dl><dt><strong>design_size</strong></dt>
</dl>
<dl><dt><strong>height</strong></dt>
</dl>
<dl><dt><strong>width</strong></dt>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Vf">class <strong>Vf</strong></a>(<a href="matplotlib.dviread.html#Dvi">Dvi</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>A virtual font (\*.vf file) containing subroutines for dvi files.<br>
<br>
Usage::<br>
<br>
vf = <a href="#Vf">Vf</a>(filename)<br>
glyph = vf[code]<br>
glyph.text, glyph.boxes, glyph.width<br> </tt></td></tr>
<tr><td> </td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="matplotlib.dviread.html#Vf">Vf</a></dd>
<dd><a href="matplotlib.dviread.html#Dvi">Dvi</a></dd>
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="Vf-__getitem__"><strong>__getitem__</strong></a>(self, code)</dt></dl>
<dl><dt><a name="Vf-__init__"><strong>__init__</strong></a>(self, filename)</dt></dl>
<hr>
Methods inherited from <a href="matplotlib.dviread.html#Dvi">Dvi</a>:<br>
<dl><dt><a name="Vf-__iter__"><strong>__iter__</strong></a>(self)</dt><dd><tt>Iterate through the pages of the file.<br>
<br>
Returns (text, pages) pairs, where:<br>
text is a list of (x, y, fontnum, glyphnum, width) tuples<br>
boxes is a list of (x, y, height, width) tuples<br>
<br>
The coordinates are transformed into a standard Cartesian<br>
coordinate system at the dpi value given when initializing.<br>
The coordinates are floating point numbers, but otherwise<br>
precision is not lost and coordinate values are not clipped to<br>
integers.</tt></dd></dl>
<dl><dt><a name="Vf-close"><strong>close</strong></a>(self)</dt><dd><tt>Close the underlying file if it is open.</tt></dd></dl>
<hr>
Data descriptors inherited from <a href="matplotlib.dviread.html#Dvi">Dvi</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-find_tex_file"><strong>find_tex_file</strong></a>(filename, format<font color="#909090">=None</font>)</dt><dd><tt>Call kpsewhich to find a file in the texmf tree.<br>
If format is not None, it is used as the value for the --format option.<br>
See the kpathsea documentation for more information.<br>
<br>
Apparently most existing TeX distributions on Unix-like systems<br>
use kpathsea. I hear MikTeX (a popular distribution on Windows)<br>
doesn't use kpathsea, so what do we do? (TODO)</tt></dd></dl>
</td></tr></table>
@footer@