<divid="unreleased-message"> You are reading an old version of the documentation (v3.2.0). For the latest version see <ahref="https://matplotlib.org/stable/api/afm_api.html">https://matplotlib.org/stable/api/afm_api.html</a></div>
<spanid="matplotlib-afm"></span><h1><codeclass="docutils literal notranslate"><spanclass="pre">matplotlib.afm</span></code><aclass="headerlink" href="#module-matplotlib.afm" title="Permalink to this headline">¶</a></h1>
<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 this, it was decided not to go with them because they were either:</p>
<olclass="arabic simple">
<li>copyrighted or used a non-BSD compatible license</li>
<li>had too many dependencies and a free standing lib was needed</li>
<li>did more than needed and it was easier to write afresh rather than
figure out how to get just what was needed.</li>
</ol>
<p>It is pretty easy to use, and requires only built-in python libs:</p>
<spanclass="gp">>>> </span><spanclass="n">afm</span><spanclass="o">.</span><spanclass="n">string_width_height</span><spanclass="p">(</span><spanclass="s1">'What the heck?'</span><spanclass="p">)</span>
<p>As in the Adobe Font Metrics File Format Specification, all dimensions
are given in units of 1/1000 of the scale factor (point size) of the font
being used.</p>
<dlclass="class">
<dtid="matplotlib.afm.AFM">
<emclass="property">class </em><codeclass="descclassname">matplotlib.afm.</code><codeclass="descname">AFM</code><spanclass="sig-paren">(</span><em>fh</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.afm.AFM" title="Permalink to this definition">¶</a></dt>
<p>Parse the AFM file in file object <em>fh</em>.</p>
<dlclass="method">
<dtid="matplotlib.afm.AFM.family_name">
<emclass="property">property </em><codeclass="descname">family_name</code><aclass="headerlink" href="#matplotlib.afm.AFM.family_name" title="Permalink to this definition">¶</a></dt>
<dd><p>The font family name, e.g., 'Times'.</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.afm.AFM.get_angle">
<codeclass="descname">get_angle</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_angle"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.afm.AFM.get_angle" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the fontangle as float.</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.afm.AFM.get_bbox_char">
<codeclass="descname">get_bbox_char</code><spanclass="sig-paren">(</span><em>self</em>, <em>c</em>, <em>isord=False</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_bbox_char"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.afm.AFM.get_bbox_char" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="method">
<dtid="matplotlib.afm.AFM.get_capheight">
<codeclass="descname">get_capheight</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_capheight"><spanclass="viewcode-link">[source]</span></a><aclass="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>
<dlclass="method">
<dtid="matplotlib.afm.AFM.get_familyname">
<codeclass="descname">get_familyname</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_familyname"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.afm.AFM.get_familyname" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the font family name, e.g., 'Times'.</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.afm.AFM.get_fontname">
<codeclass="descname">get_fontname</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_fontname"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.afm.AFM.get_fontname" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the font name, e.g., 'Times-Roman'.</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.afm.AFM.get_fullname">
<codeclass="descname">get_fullname</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_fullname"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.afm.AFM.get_fullname" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the font full name, e.g., 'Times-Roman'.</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.afm.AFM.get_height_char">
<codeclass="descname">get_height_char</code><spanclass="sig-paren">(</span><em>self</em>, <em>c</em>, <em>isord=False</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_height_char"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.afm.AFM.get_height_char" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the bounding box (ink) height of character <em>c</em> (space is 0).</p>
<codeclass="descname">get_horizontal_stem_width</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_horizontal_stem_width"><spanclass="viewcode-link">[source]</span></a><aclass="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>
<dlclass="method">
<dtid="matplotlib.afm.AFM.get_kern_dist">
<codeclass="descname">get_kern_dist</code><spanclass="sig-paren">(</span><em>self</em>, <em>c1</em>, <em>c2</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_kern_dist"><spanclass="viewcode-link">[source]</span></a><aclass="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>
<codeclass="descname">get_kern_dist_from_name</code><spanclass="sig-paren">(</span><em>self</em>, <em>name1</em>, <em>name2</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_kern_dist_from_name"><spanclass="viewcode-link">[source]</span></a><aclass="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>
<dlclass="method">
<dtid="matplotlib.afm.AFM.get_name_char">
<codeclass="descname">get_name_char</code><spanclass="sig-paren">(</span><em>self</em>, <em>c</em>, <em>isord=False</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_name_char"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.afm.AFM.get_name_char" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the name of the character, i.e., ';' is 'semicolon'.</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.afm.AFM.get_str_bbox">
<codeclass="descname">get_str_bbox</code><spanclass="sig-paren">(</span><em>self</em>, <em>s</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_str_bbox"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.afm.AFM.get_str_bbox" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">get_str_bbox_and_descent</code><spanclass="sig-paren">(</span><em>self</em>, <em>s</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_str_bbox_and_descent"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.afm.AFM.get_str_bbox_and_descent" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the string bounding box and the maximal descent.</p>
<codeclass="descname">get_underline_thickness</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_underline_thickness"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.afm.AFM.get_underline_thickness" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the underline thickness as float.</p>
<codeclass="descname">get_vertical_stem_width</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_vertical_stem_width"><spanclass="viewcode-link">[source]</span></a><aclass="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>
<dlclass="method">
<dtid="matplotlib.afm.AFM.get_weight">
<codeclass="descname">get_weight</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_weight"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.afm.AFM.get_weight" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the font weight, e.g., 'Bold' or 'Roman'.</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.afm.AFM.get_width_char">
<codeclass="descname">get_width_char</code><spanclass="sig-paren">(</span><em>self</em>, <em>c</em>, <em>isord=False</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_width_char"><spanclass="viewcode-link">[source]</span></a><aclass="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>
<codeclass="descname">get_width_from_char_name</code><spanclass="sig-paren">(</span><em>self</em>, <em>name</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_width_from_char_name"><spanclass="viewcode-link">[source]</span></a><aclass="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>
<dlclass="method">
<dtid="matplotlib.afm.AFM.get_xheight">
<codeclass="descname">get_xheight</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.get_xheight"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.afm.AFM.get_xheight" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the xheight as float.</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.afm.AFM.string_width_height">
<codeclass="descname">string_width_height</code><spanclass="sig-paren">(</span><em>self</em>, <em>s</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/afm.html#AFM.string_width_height"><spanclass="viewcode-link">[source]</span></a><aclass="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>
<dlclass="class">
<dtid="matplotlib.afm.CharMetrics">
<emclass="property">class </em><codeclass="descclassname">matplotlib.afm.</code><codeclass="descname">CharMetrics</code><aclass="headerlink" href="#matplotlib.afm.CharMetrics" title="Permalink to this definition">¶</a></dt>
<p>Represents the character metrics of a single character.</p>
<pclass="rubric">Notes</p>
<p>The fields do currently only describe a subset of character metrics
information defined in the AFM standard.</p>
<p>Create new instance of CharMetrics(width, name, bbox)</p>
<dlclass="attribute">
<dtid="matplotlib.afm.CharMetrics.bbox">
<codeclass="descname">bbox</code><aclass="headerlink" href="#matplotlib.afm.CharMetrics.bbox" title="Permalink to this definition">¶</a></dt>
<dd><p>The bbox of the character (B) as a tuple (<em>llx</em>, <em>lly</em>, <em>urx</em>, <em>ury</em>).</p>
</dd></dl>
<dlclass="attribute">
<dtid="matplotlib.afm.CharMetrics.name">
<codeclass="descname">name</code><aclass="headerlink" href="#matplotlib.afm.CharMetrics.name" title="Permalink to this definition">¶</a></dt>
<dd><p>The character name (N).</p>
</dd></dl>
<dlclass="attribute">
<dtid="matplotlib.afm.CharMetrics.width">
<codeclass="descname">width</code><aclass="headerlink" href="#matplotlib.afm.CharMetrics.width" title="Permalink to this definition">¶</a></dt>
<dd><p>The character width (WX).</p>
</dd></dl>
</dd></dl>
<dlclass="class">
<dtid="matplotlib.afm.CompositePart">
<emclass="property">class </em><codeclass="descclassname">matplotlib.afm.</code><codeclass="descname">CompositePart</code><aclass="headerlink" href="#matplotlib.afm.CompositePart" title="Permalink to this definition">¶</a></dt>