|
| 1 | +from nose.tools import assert_equal |
| 2 | +import matplotlib.dviread as dr |
| 3 | +import os.path |
| 4 | + |
| 5 | +original_find_tex_file = dr.find_tex_file |
| 6 | + |
| 7 | +def setup(): |
| 8 | + dr.find_tex_file = lambda x: x |
| 9 | + |
| 10 | +def teardown(): |
| 11 | + dr.find_tex_file = original_find_tex_file |
| 12 | + |
| 13 | +def test_PsfontsMap(): |
| 14 | + filename = os.path.join( |
| 15 | + os.path.dirname(__file__), |
| 16 | + 'baseline_images', 'dviread', 'test.map') |
| 17 | + fontmap = dr.PsfontsMap(filename) |
| 18 | + # Check all properties of a few fonts |
| 19 | + for n in [1, 2, 3, 4, 5]: |
| 20 | + key = 'TeXfont%d' % n |
| 21 | + entry = fontmap[key] |
| 22 | + assert_equal(entry.texname, key) |
| 23 | + assert_equal(entry.psname, 'PSfont%d' % n) |
| 24 | + if n not in [3, 5]: |
| 25 | + assert_equal(entry.encoding, 'font%d.enc' % n) |
| 26 | + elif n == 3: |
| 27 | + assert_equal(entry.encoding, 'enc3.foo') |
| 28 | + # We don't care about the encoding of TeXfont5, which specifies |
| 29 | + # multiple encodings. |
| 30 | + if n not in [1, 5]: |
| 31 | + assert_equal(entry.filename, 'font%d.pfa' % n) |
| 32 | + else: |
| 33 | + assert_equal(entry.filename, 'font%d.pfb' % n) |
| 34 | + if n == 4: |
| 35 | + assert_equal(entry.effects, {'slant': -0.1, 'extend': 2.2}) |
| 36 | + else: |
| 37 | + assert_equal(entry.effects, {}) |
| 38 | + # Some special cases |
| 39 | + entry = fontmap['TeXfont6'] |
| 40 | + assert_equal(entry.filename, None) |
| 41 | + assert_equal(entry.encoding, None) |
| 42 | + entry = fontmap['TeXfont7'] |
| 43 | + assert_equal(entry.filename, None) |
| 44 | + assert_equal(entry.encoding, 'font7.enc') |
| 45 | + entry = fontmap['TeXfont8'] |
| 46 | + assert_equal(entry.filename, 'font8.pfb') |
| 47 | + assert_equal(entry.encoding, None) |
| 48 | + entry = fontmap['TeXfont9'] |
| 49 | + assert_equal(entry.filename, '/absolute/font9.pfb') |
| 50 | + |
0 commit comments