<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>afm (Adobe Font Metrics interface) — Matplotlib v1.1.1 documentation</title> <link rel="stylesheet" href="../_static/mpl.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '1.1.1', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Matplotlib v1.1.1 documentation" href="../_static/opensearch.xml"/> <link rel="top" title="Matplotlib v1.1.1 documentation" href="../index.html" /> <link rel="up" title="The Matplotlib API" href="index.html" /> <link rel="next" title="animation" href="animation_api.html" /> <link rel="prev" title="configuration" href="matplotlib_configuration_api.html" /> </head> <body> <!-- Piwik --> <script type="text/javascript"> if ("matplotlib.sourceforge.net" == document.location.hostname || "matplotlib.sf.net" == document.location.hostname) { var pkBaseURL = (("https:" == document.location.protocol) ? "https://apps.sourceforge.net/piwik/matplotlib/" : "http://apps.sourceforge.net/piwik/matplotlib/"); document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E")); } </script> <script type="text/javascript"> if ("matplotlib.sourceforge.net" == document.location.hostname || "matplotlib.sf.net" == document.location.hostname) { piwik_action_name = ''; piwik_idsite = 1; piwik_url = pkBaseURL + "piwik.php"; piwik_log(piwik_action_name, piwik_idsite, piwik_url); document.write(unescape('%3Cobject%3E%3Cnoscript%3E%3Cp%3E%3Cimg src="http://apps.sourceforge.net/piwik/matplotlib/piwik.php?idsite=1" alt="piwik"/%3E%3C/p%3E%3C/noscript%3E%3C/object%3E')); } </script> <!-- End Piwik Tag --> <link rel="shortcut icon" href="_static/favicon.ico"> <div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px"> <a href="../index.html"><img src="../_static/logo2.png" border="0" alt="matplotlib"/></a> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="animation_api.html" title="animation" accesskey="N">next</a> |</li> <li class="right" > <a href="matplotlib_configuration_api.html" title="configuration" accesskey="P">previous</a> |</li> <li><a href="../index.html">home</a>| </li> <li><a href="../search.html">search</a>| </li> <li><a href="../examples/index.html">examples</a>| </li> <li><a href="../gallery.html">gallery</a>| </li> <li><a href="../contents.html">docs</a> »</li> <li><a href="index.html" accesskey="U">The Matplotlib API</a> »</li> </ul> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">afm (Adobe Font Metrics interface)</a><ul> <li><a class="reference internal" href="#module-matplotlib.afm"><tt class="docutils literal"><span class="pre">matplotlib.afm</span></tt></a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="matplotlib_configuration_api.html" title="previous chapter">configuration</a></p> <h4>Next topic</h4> <p class="topless"><a href="animation_api.html" title="next chapter">animation</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/api/afm_api.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" size="18" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="afm-adobe-font-metrics-interface"> <h1>afm (Adobe Font Metrics interface)<a class="headerlink" href="#afm-adobe-font-metrics-interface" title="Permalink to this headline">¶</a></h1> <div class="section" id="module-matplotlib.afm"> <span id="matplotlib-afm"></span><h2><a class="reference internal" href="#module-matplotlib.afm" title="matplotlib.afm"><tt class="xref py py-mod docutils literal"><span class="pre">matplotlib.afm</span></tt></a><a class="headerlink" href="#module-matplotlib.afm" title="Permalink to this headline">¶</a></h2> <p>This is a python interface to Adobe Font Metrics Files. Although a number of other python implementations exist (and may be more complete than mine) I decided not to go with them because either they were either</p> <blockquote> <div><ol class="arabic simple"> <li>copyrighted or used a non-BSD compatible license</li> <li>had too many dependencies and I wanted a free standing lib</li> <li>Did more than I needed and it was easier to write my own than figure out how to just get what I needed from theirs</li> </ol> </div></blockquote> <p>It is pretty easy to use, and requires only built-in python libs:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">afm</span> <span class="kn">import</span> <span class="n">AFM</span> <span class="gp">>>> </span><span class="n">fh</span> <span class="o">=</span> <span class="nb">file</span><span class="p">(</span><span class="s">'ptmr8a.afm'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">afm</span> <span class="o">=</span> <span class="n">AFM</span><span class="p">(</span><span class="n">fh</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">afm</span><span class="o">.</span><span class="n">string_width_height</span><span class="p">(</span><span class="s">'What the heck?'</span><span class="p">)</span> <span class="go">(6220.0, 683)</span> <span class="gp">>>> </span><span class="n">afm</span><span class="o">.</span><span class="n">get_fontname</span><span class="p">()</span> <span class="go">'Times-Roman'</span> <span class="gp">>>> </span><span class="n">afm</span><span class="o">.</span><span class="n">get_kern_dist</span><span class="p">(</span><span class="s">'A'</span><span class="p">,</span> <span class="s">'f'</span><span class="p">)</span> <span class="go">0</span> <span class="gp">>>> </span><span class="n">afm</span><span class="o">.</span><span class="n">get_kern_dist</span><span class="p">(</span><span class="s">'A'</span><span class="p">,</span> <span class="s">'y'</span><span class="p">)</span> <span class="go">-92.0</span> <span class="gp">>>> </span><span class="n">afm</span><span class="o">.</span><span class="n">get_bbox_char</span><span class="p">(</span><span class="s">'!'</span><span class="p">)</span> <span class="go">[130, -9, 238, 676]</span> <span class="gp">>>> </span><span class="n">afm</span><span class="o">.</span><span class="n">get_bbox_font</span><span class="p">()</span> <span class="go">[-168, -218, 1000, 898]</span> </pre></div> </div> <dl class="docutils"> <dt>AUTHOR:</dt> <dd>John D. Hunter <<a class="reference external" href="mailto:jdh2358%40gmail.com">jdh2358<span>@</span>gmail<span>.</span>com</a>></dd> </dl> <dl class="class"> <dt id="matplotlib.afm.AFM"> <em class="property">class </em><tt class="descclassname">matplotlib.afm.</tt><tt class="descname">AFM</tt><big>(</big><em>fh</em><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM" title="Permalink to this definition">¶</a></dt> <dd><p>Parse the AFM file in file object <em>fh</em></p> <dl class="method"> <dt id="matplotlib.afm.AFM.get_angle"> <tt class="descname">get_angle</tt><big>(</big><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_angle" title="Permalink to this definition">¶</a></dt> <dd><p>Return the fontangle as float</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_bbox_char"> <tt class="descname">get_bbox_char</tt><big>(</big><em>c</em>, <em>isord=False</em><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_bbox_char" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_capheight"> <tt class="descname">get_capheight</tt><big>(</big><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_capheight" title="Permalink to this definition">¶</a></dt> <dd><p>Return the cap height as float</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_familyname"> <tt class="descname">get_familyname</tt><big>(</big><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_familyname" title="Permalink to this definition">¶</a></dt> <dd><p>Return the font family name, eg, ‘Times’</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_fontname"> <tt class="descname">get_fontname</tt><big>(</big><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_fontname" title="Permalink to this definition">¶</a></dt> <dd><p>Return the font name, eg, ‘Times-Roman’</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_fullname"> <tt class="descname">get_fullname</tt><big>(</big><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_fullname" title="Permalink to this definition">¶</a></dt> <dd><p>Return the font full name, eg, ‘Times-Roman’</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_height_char"> <tt class="descname">get_height_char</tt><big>(</big><em>c</em>, <em>isord=False</em><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_height_char" title="Permalink to this definition">¶</a></dt> <dd><p>Get the height of character <em>c</em> from the bounding box. This is the ink height (space is 0)</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_horizontal_stem_width"> <tt class="descname">get_horizontal_stem_width</tt><big>(</big><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_horizontal_stem_width" title="Permalink to this definition">¶</a></dt> <dd><p>Return the standard horizontal stem width as float, or <em>None</em> if not specified in AFM file.</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_kern_dist"> <tt class="descname">get_kern_dist</tt><big>(</big><em>c1</em>, <em>c2</em><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_kern_dist" title="Permalink to this definition">¶</a></dt> <dd><p>Return the kerning pair distance (possibly 0) for chars <em>c1</em> and <em>c2</em></p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_kern_dist_from_name"> <tt class="descname">get_kern_dist_from_name</tt><big>(</big><em>name1</em>, <em>name2</em><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_kern_dist_from_name" title="Permalink to this definition">¶</a></dt> <dd><p>Return the kerning pair distance (possibly 0) for chars <em>name1</em> and <em>name2</em></p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_name_char"> <tt class="descname">get_name_char</tt><big>(</big><em>c</em>, <em>isord=False</em><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_name_char" title="Permalink to this definition">¶</a></dt> <dd><p>Get the name of the character, ie, ‘;’ is ‘semicolon’</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_str_bbox"> <tt class="descname">get_str_bbox</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_str_bbox" title="Permalink to this definition">¶</a></dt> <dd><p>Return the string bounding box</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_str_bbox_and_descent"> <tt class="descname">get_str_bbox_and_descent</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_str_bbox_and_descent" title="Permalink to this definition">¶</a></dt> <dd><p>Return the string bounding box</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_underline_thickness"> <tt class="descname">get_underline_thickness</tt><big>(</big><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_underline_thickness" title="Permalink to this definition">¶</a></dt> <dd><p>Return the underline thickness as float</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_vertical_stem_width"> <tt class="descname">get_vertical_stem_width</tt><big>(</big><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_vertical_stem_width" title="Permalink to this definition">¶</a></dt> <dd><p>Return the standard vertical stem width as float, or <em>None</em> if not specified in AFM file.</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_weight"> <tt class="descname">get_weight</tt><big>(</big><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_weight" title="Permalink to this definition">¶</a></dt> <dd><p>Return the font weight, eg, ‘Bold’ or ‘Roman’</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_width_char"> <tt class="descname">get_width_char</tt><big>(</big><em>c</em>, <em>isord=False</em><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_width_char" title="Permalink to this definition">¶</a></dt> <dd><p>Get the width of the character from the character metric WX field</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_width_from_char_name"> <tt class="descname">get_width_from_char_name</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_width_from_char_name" title="Permalink to this definition">¶</a></dt> <dd><p>Get the width of the character from a type1 character name</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.get_xheight"> <tt class="descname">get_xheight</tt><big>(</big><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.get_xheight" title="Permalink to this definition">¶</a></dt> <dd><p>Return the xheight as float</p> </dd></dl> <dl class="method"> <dt id="matplotlib.afm.AFM.string_width_height"> <tt class="descname">string_width_height</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#matplotlib.afm.AFM.string_width_height" title="Permalink to this definition">¶</a></dt> <dd><p>Return the string width (including kerning) and string height as a (<em>w</em>, <em>h</em>) tuple.</p> </dd></dl> </dd></dl> <dl class="function"> <dt id="matplotlib.afm.parse_afm"> <tt class="descclassname">matplotlib.afm.</tt><tt class="descname">parse_afm</tt><big>(</big><em>fh</em><big>)</big><a class="headerlink" href="#matplotlib.afm.parse_afm" title="Permalink to this definition">¶</a></dt> <dd><p>Parse the Adobe Font Metics file in file handle <em>fh</em>. Return value is a (<em>dhead</em>, <em>dcmetrics</em>, <em>dkernpairs</em>, <em>dcomposite</em>) tuple where <em>dhead</em> is a <tt class="xref py py-func docutils literal"><span class="pre">_parse_header()</span></tt> dict, <em>dcmetrics</em> is a <tt class="xref py py-func docutils literal"><span class="pre">_parse_composites()</span></tt> dict, <em>dkernpairs</em> is a <tt class="xref py py-func docutils literal"><span class="pre">_parse_kern_pairs()</span></tt> dict (possibly {}), and <em>dcomposite</em> is a <tt class="xref py py-func docutils literal"><span class="pre">_parse_composites()</span></tt> dict (possibly {})</p> </dd></dl> </div> </div> </div> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="animation_api.html" title="animation" >next</a> |</li> <li class="right" > <a href="matplotlib_configuration_api.html" title="configuration" >previous</a> |</li> <li><a href="../index.html">home</a>| </li> <li><a href="../search.html">search</a>| </li> <li><a href="../examples/index.html">examples</a>| </li> <li><a href="../gallery.html">gallery</a>| </li> <li><a href="../contents.html">docs</a> »</li> <li><a href="index.html" >The Matplotlib API</a> »</li> </ul> </div> <div class="footer"> © Copyright 2008, John Hunter, Darren Dale, Michael Droettboom. Last updated on Oct 04, 2012. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7. </div> </body> </html>