|
1 | 1 | """
|
2 | 2 | This is a python interface to Adobe Font Metrics Files. Although a
|
3 | 3 | number of other python implementations exist, and may be more complete
|
4 |
| -than this, it was decided not to go with them because they were |
5 |
| -either: |
| 4 | +than this, it was decided not to go with them because they were either: |
6 | 5 |
|
7 |
| - 1) copyrighted or used a non-BSD compatible license |
8 |
| -
|
9 |
| - 2) had too many dependencies and a free standing lib was needed |
10 |
| -
|
11 |
| - 3) Did more than needed and it was easier to write afresh rather than |
12 |
| - figure out how to get just what was needed. |
| 6 | +1) copyrighted or used a non-BSD compatible license |
| 7 | +2) had too many dependencies and a free standing lib was needed |
| 8 | +3) did more than needed and it was easier to write afresh rather than |
| 9 | + figure out how to get just what was needed. |
13 | 10 |
|
14 | 11 | It is pretty easy to use, and requires only built-in python libs:
|
15 | 12 |
|
16 |
| - >>> import matplotlib as mpl |
17 |
| - >>> import os.path |
18 |
| - >>> afm_fname = os.path.join(mpl.get_data_path(), |
19 |
| - ... 'fonts', 'afm', 'ptmr8a.afm') |
20 |
| - >>> |
21 |
| - >>> from matplotlib.afm import AFM |
22 |
| - >>> with open(afm_fname, 'rb') as fh: |
23 |
| - ... afm = AFM(fh) |
24 |
| - >>> afm.string_width_height('What the heck?') |
25 |
| - (6220.0, 694) |
26 |
| - >>> afm.get_fontname() |
27 |
| - 'Times-Roman' |
28 |
| - >>> afm.get_kern_dist('A', 'f') |
29 |
| - 0 |
30 |
| - >>> afm.get_kern_dist('A', 'y') |
31 |
| - -92.0 |
32 |
| - >>> afm.get_bbox_char('!') |
33 |
| - [130, -9, 238, 676] |
| 13 | +>>> import matplotlib as mpl |
| 14 | +>>> from pathlib import Path |
| 15 | +>>> afm_path = Path(mpl.get_data_path(), 'fonts', 'afm', 'ptmr8a.afm') |
| 16 | +>>> |
| 17 | +>>> from matplotlib.afm import AFM |
| 18 | +>>> with afm_path.open('rb') as fh: |
| 19 | +... afm = AFM(fh) |
| 20 | +>>> afm.string_width_height('What the heck?') |
| 21 | +(6220.0, 694) |
| 22 | +>>> afm.get_fontname() |
| 23 | +'Times-Roman' |
| 24 | +>>> afm.get_kern_dist('A', 'f') |
| 25 | +0 |
| 26 | +>>> afm.get_kern_dist('A', 'y') |
| 27 | +-92.0 |
| 28 | +>>> afm.get_bbox_char('!') |
| 29 | +[130, -9, 238, 676] |
34 | 30 |
|
35 | 31 | As in the Adobe Font Metrics File Format Specification, all dimensions
|
36 | 32 | are given in units of 1/1000 of the scale factor (point size) of the font
|
|
0 commit comments