Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a8d35d4

Browse files
committed
converted afm docstrings
svn path=/trunk/matplotlib/; revision=5648
1 parent fb44630 commit a8d35d4

4 files changed

Lines changed: 57 additions & 44 deletions

File tree

doc/api/afm_api.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
**************
2+
matplotlib afm
3+
**************
4+
5+
6+
:mod:`matplotlib.afm`
7+
=====================
8+
9+
.. automodule:: matplotlib.afm
10+
:members:
11+
:undoc-members:
12+
:show-inheritance:

doc/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
.. toctree::
1313

1414
matplotlib_configuration_api.rst
15+
afm_api.rst
1516
artist_api.rst
1617
figure_api.rst
1718
axes_api.rst

doc/devel/outline.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ numerix/__init__ needs conversion
111111
projections/__init__ needs conversion
112112
projections/geo needs conversion
113113
projections/polar needs conversion
114-
afm needs conversion
114+
afm converted
115115
artist needs conversion
116116
axes needs conversion
117117
axis needs conversion

lib/matplotlib/afm.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
3) Did more than I needed and it was easier to write my own than
1212
figure out how to just get what I needed from theirs
1313
14-
It is pretty easy to use, and requires only built-in python libs
14+
It is pretty easy to use, and requires only built-in python libs:
1515
1616
>>> from afm import AFM
1717
>>> fh = file('ptmr8a.afm')
@@ -31,7 +31,7 @@
3131
3232
3333
AUTHOR:
34-
John D. Hunter <[email protected]>
34+
John D. Hunter <[email protected]>
3535
"""
3636

3737
import sys, os
@@ -56,7 +56,7 @@ def _to_bool(s):
5656
def _sanity_check(fh):
5757
"""
5858
Check if the file at least looks like AFM.
59-
If not, raise RuntimeError.
59+
If not, raise :exc:`RuntimeError`.
6060
"""
6161

6262
# Remember the file position in case the caller wants to
@@ -77,9 +77,12 @@ def _sanity_check(fh):
7777
def _parse_header(fh):
7878
"""
7979
Reads the font metrics header (up to the char metrics) and returns
80-
a dictionary mapping key to val. val will be converted to the
81-
appropriate python type as necessary; eg 'False'->False, '0'->0,
82-
'-168 -218 1000 898'-> [-168, -218, 1000, 898]
80+
a dictionary mapping *key* to *val*. *val* will be converted to the
81+
appropriate python type as necessary; eg:
82+
83+
* 'False'->False
84+
* '0'->0
85+
* '-168 -218 1000 898'-> [-168, -218, 1000, 898]
8386
8487
Dictionary keys are
8588
@@ -142,14 +145,12 @@ def _parse_header(fh):
142145
def _parse_char_metrics(fh):
143146
"""
144147
Return a character metric dictionary. Keys are the ASCII num of
145-
the character, values are a (wx, name, bbox) tuple, where
146-
147-
wx is the character width
148-
name is the postscript language name
149-
bbox (llx, lly, urx, ury)
148+
the character, values are a (*wx*, *name*, *bbox*) tuple, where
149+
*wx* is the character width, *name* is the postscript language
150+
name, and *bbox* is a (*llx*, *lly*, *urx*, *ury*) tuple.
150151
151-
This function is incomplete per the standard, but thus far parse
152-
all the sample afm files I have
152+
This function is incomplete per the standard, but thus far parses
153+
all the sample afm files tried.
153154
"""
154155

155156
ascii_d = {}
@@ -176,12 +177,11 @@ def _parse_char_metrics(fh):
176177

177178
def _parse_kern_pairs(fh):
178179
"""
179-
Return a kern pairs dictionary; keys are (char1, char2) tuples and
180+
Return a kern pairs dictionary; keys are (*char1*, *char2*) tuples and
180181
values are the kern pair value. For example, a kern pairs line like
182+
``KPX A y -50``
181183
182-
KPX A y -50
183-
184-
will be represented as
184+
will be represented as::
185185
186186
d[ ('A', 'y') ] = -50
187187
@@ -210,13 +210,13 @@ def _parse_kern_pairs(fh):
210210
def _parse_composites(fh):
211211
"""
212212
Return a composites dictionary. Keys are the names of the
213-
composites. vals are a num parts list of composite information,
214-
with each element being a (name, dx, dy) tuple. Thus if a
213+
composites. Values are a num parts list of composite information,
214+
with each element being a (*name*, *dx*, *dy*) tuple. Thus a
215215
composites line reading:
216216
217217
CC Aacute 2 ; PCC A 0 0 ; PCC acute 160 170 ;
218218
219-
will be represented as
219+
will be represented as::
220220
221221
d['Aacute'] = [ ('A', 0, 0), ('acute', 160, 170) ]
222222
@@ -245,9 +245,10 @@ def _parse_optional(fh):
245245
"""
246246
Parse the optional fields for kern pair data and composites
247247
248-
return value is a kernDict, compositeDict which are the return
249-
values from parse_kern_pairs, and parse_composites if the data
250-
exists, or empty dicts otherwise
248+
return value is a (*kernDict*, *compositeDict*) which are the
249+
return values from :func:`_parse_kern_pairs`, and
250+
:func:`_parse_composites` if the data exists, or empty dicts
251+
otherwise
251252
"""
252253
optional = {
253254
'StartKernData' : _parse_kern_pairs,
@@ -269,13 +270,12 @@ def _parse_optional(fh):
269270

270271
def parse_afm(fh):
271272
"""
272-
Parse the Adobe Font Metics file in file handle fh
273-
Return value is a (dhead, dcmetrics, dkernpairs, dcomposite) tuple where
274-
275-
dhead : a parse_header dict
276-
dcmetrics : a parse_composites dict
277-
dkernpairs : a parse_kern_pairs dict, possibly {}
278-
dcomposite : a parse_composites dict , possibly {}
273+
Parse the Adobe Font Metics file in file handle *fh*. Return value
274+
is a (*dhead*, *dcmetrics*, *dkernpairs*, *dcomposite*) tuple where
275+
*dhead* is a :func:`_parse_header` dict, *dcmetrics* is a
276+
:func:`_parse_composites` dict, *dkernpairs* is a
277+
:func:`_parse_kern_pairs` dict (possibly {}), and *dcomposite* is a
278+
:func:`_parse_composites` dict (possibly {})
279279
"""
280280
_sanity_check(fh)
281281
dhead = _parse_header(fh)
@@ -288,7 +288,7 @@ class AFM:
288288

289289
def __init__(self, fh):
290290
"""
291-
Parse the AFM file in file object fh
291+
Parse the AFM file in file object *fh*
292292
"""
293293
(dhead, dcmetrics_ascii, dcmetrics_name, dkernpairs, dcomposite) = \
294294
parse_afm(fh)
@@ -307,7 +307,7 @@ def get_bbox_char(self, c, isord=False):
307307
def string_width_height(self, s):
308308
"""
309309
Return the string width (including kerning) and string height
310-
as a w,h tuple
310+
as a (*w*, *h*) tuple.
311311
"""
312312
if not len(s): return 0,0
313313
totalw = 0
@@ -404,39 +404,39 @@ def get_width_from_char_name(self, name):
404404

405405
def get_height_char(self, c, isord=False):
406406
"""
407-
Get the height of character c from the bounding box. This is
408-
the ink height (space is 0)
407+
Get the height of character *c* from the bounding box. This
408+
is the ink height (space is 0)
409409
"""
410410
if not isord: c=ord(c)
411411
wx, name, bbox = self._metrics[c]
412412
return bbox[-1]
413413

414414
def get_kern_dist(self, c1, c2):
415415
"""
416-
Return the kerning pair distance (possibly 0) for chars c1 and
417-
c2
416+
Return the kerning pair distance (possibly 0) for chars *c1*
417+
and *c2*
418418
"""
419419
name1, name2 = self.get_name_char(c1), self.get_name_char(c2)
420420
return self.get_kern_dist_from_name(name1, name2)
421421

422422
def get_kern_dist_from_name(self, name1, name2):
423423
"""
424-
Return the kerning pair distance (possibly 0) for chars c1 and
425-
c2
424+
Return the kerning pair distance (possibly 0) for chars
425+
*name1* and *name2*
426426
"""
427427
try: return self._kern[ (name1, name2) ]
428428
except: return 0
429429

430430
def get_fontname(self):
431-
"Return the font name, eg, Times-Roman"
431+
"Return the font name, eg, 'Times-Roman'"
432432
return self._header['FontName']
433433

434434
def get_fullname(self):
435-
"Return the font full name, eg, Times-Roman"
435+
"Return the font full name, eg, 'Times-Roman'"
436436
return self._header['FullName']
437437

438438
def get_familyname(self):
439-
"Return the font family name, eg, Times"
439+
"Return the font family name, eg, 'Times'"
440440
return self._header['FamilyName']
441441

442442
def get_weight(self):
@@ -461,14 +461,14 @@ def get_underline_thickness(self):
461461

462462
def get_horizontal_stem_width(self):
463463
"""
464-
Return the standard horizontal stem width as float, or None if
464+
Return the standard horizontal stem width as float, or *None* if
465465
not specified in AFM file.
466466
"""
467467
return self._header.get('StdHW', None)
468468

469469
def get_vertical_stem_width(self):
470470
"""
471-
Return the standard vertical stem width as float, or None if
471+
Return the standard vertical stem width as float, or *None* if
472472
not specified in AFM file.
473473
"""
474474
return self._header.get('StdVW', None)

0 commit comments

Comments
 (0)