-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathafm_api.html
More file actions
328 lines (281 loc) · 18.5 KB
/
afm_api.html
File metadata and controls
328 lines (281 loc) · 18.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<!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 1.4.0 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.4.0',
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 1.4.0 documentation"
href="../_static/opensearch.xml"/>
<link rel="top" title="Matplotlib 1.4.0 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="The top level matplotlib module" href="matplotlib_configuration_api.html" />
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet" type="text/css">
<link rel="canonical" href="https://matplotlib.org/stable/api/afm_api.html" />
<script data-domain="matplotlib.org" defer="defer" src="https://views.scientific-python.org/js/script.js"></script>
</head>
<body>
<div id="unreleased-message"> You are reading an old version of the documentation (v1.4.0). For the latest version see <a href="https://matplotlib.org/stable/api/afm_api.html">https://matplotlib.org/stable/api/afm_api.html</a></div>
<link rel="shortcut icon" href="/_static/favicon.ico">
<!-- The "Fork me on github" ribbon -->
<img style="float: right; margin-bottom: -40px; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" usemap="#ribbonmap"/>
<map name="ribbonmap">
<area shape="poly" coords="15,0,148,-1,148,135" href="https://github.com/matplotlib/matplotlib" title="Fork me on GitHub" />
</map>
<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="The top level matplotlib module"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">home</a>| </li>
<li><a href="../examples/index.html">examples</a>| </li>
<li><a href="../gallery.html">gallery</a>| </li>
<li><a href="pyplot_summary.html">pyplot</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">The top level <tt class="docutils literal"><span class="pre">matplotlib</span></tt> module</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="animation_api.html"
title="next chapter">animation</a></p>
<div role="note" aria-label="source link">
<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>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<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 this, it was decided not to go with them because 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 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>
</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">matplotlib</span> <span class="kn">import</span> <span class="n">rcParams</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">os.path</span>
<span class="gp">>>> </span><span class="n">afm_fname</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">rcParams</span><span class="p">[</span><span class="s">'datapath'</span><span class="p">],</span>
<span class="gp">... </span> <span class="s">'fonts'</span><span class="p">,</span> <span class="s">'afm'</span><span class="p">,</span> <span class="s">'ptmr8a.afm'</span><span class="p">)</span>
<span class="go">>>></span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">matplotlib.afm</span> <span class="kn">import</span> <span class="n">AFM</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="nb">open</span><span class="p">(</span><span class="n">afm_fname</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, 694)</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>
</pre></div>
</div>
<dl class="class">
<dt id="matplotlib.afm.AFM">
<em class="property">class </em><tt class="descclassname">matplotlib.afm.</tt><tt class="descname">AFM</tt><span class="sig-paren">(</span><em>fh</em><span class="sig-paren">)</span><a class="headerlink" href="#matplotlib.afm.AFM" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p>
<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><span class="sig-paren">(</span><span class="sig-paren">)</span><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><span class="sig-paren">(</span><em>c</em>, <em>isord=False</em><span class="sig-paren">)</span><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><span class="sig-paren">(</span><span class="sig-paren">)</span><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><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="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>
<dl class="method">
<dt id="matplotlib.afm.AFM.get_fontname">
<tt class="descname">get_fontname</tt><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="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>
<dl class="method">
<dt id="matplotlib.afm.AFM.get_fullname">
<tt class="descname">get_fullname</tt><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="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>
<dl class="method">
<dt id="matplotlib.afm.AFM.get_height_char">
<tt class="descname">get_height_char</tt><span class="sig-paren">(</span><em>c</em>, <em>isord=False</em><span class="sig-paren">)</span><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><span class="sig-paren">(</span><span class="sig-paren">)</span><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><span class="sig-paren">(</span><em>c1</em>, <em>c2</em><span class="sig-paren">)</span><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><span class="sig-paren">(</span><em>name1</em>, <em>name2</em><span class="sig-paren">)</span><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><span class="sig-paren">(</span><em>c</em>, <em>isord=False</em><span class="sig-paren">)</span><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><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><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><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><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><span class="sig-paren">(</span><span class="sig-paren">)</span><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><span class="sig-paren">(</span><span class="sig-paren">)</span><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><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="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>
<dl class="method">
<dt id="matplotlib.afm.AFM.get_width_char">
<tt class="descname">get_width_char</tt><span class="sig-paren">(</span><em>c</em>, <em>isord=False</em><span class="sig-paren">)</span><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><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><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><span class="sig-paren">(</span><span class="sig-paren">)</span><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><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><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><span class="sig-paren">(</span><em>fh</em><span class="sig-paren">)</span><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="footer">
© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the matplotlib development team; 2012 - 2014 The matplotlib development team.
Last updated on Sep 02, 2014.
Created using <a
href="http://sphinx-doc.org/">Sphinx</a> 1.3a0.
</div>
</body>
</html>