1import glob 2import os 3 4import pytest 5 6from fontTools import tfmLib 7 8DATA_DIR = os.path.join(os.path.dirname(__file__), "data") 9 10 11@pytest.mark.parametrize("path", glob.glob(f"{DATA_DIR}/cm*.tfm")) 12def test_read(path): 13 tfm = tfmLib.TFM(path) 14 assert tfm.designsize == 10.0 15 assert tfm.fontdimens 16 assert len(tfm.fontdimens) >= 7 17 assert tfm.extraheader == {} 18 assert tfm.right_boundary_char is None 19 assert tfm.left_boundary_char is None 20 assert len(tfm.chars) == 128 21 22 23def test_read_boundary_char(): 24 path = os.path.join(DATA_DIR, "dummy-space.tfm") 25 tfm = tfmLib.TFM(path) 26 assert tfm.right_boundary_char == 1 27 assert tfm.left_boundary_char == 256 28 29 30def test_read_fontdimens_vanilla(): 31 path = os.path.join(DATA_DIR, "cmr10.tfm") 32 tfm = tfmLib.TFM(path) 33 assert tfm.fontdimens == { 34 "SLANT": 0.0, 35 "SPACE": 0.33333396911621094, 36 "STRETCH": 0.16666698455810547, 37 "SHRINK": 0.11111164093017578, 38 "XHEIGHT": 0.4305553436279297, 39 "QUAD": 1.0000028610229492, 40 "EXTRASPACE": 0.11111164093017578, 41 } 42 43 44def test_read_fontdimens_mathex(): 45 path = os.path.join(DATA_DIR, "cmex10.tfm") 46 tfm = tfmLib.TFM(path) 47 assert tfm.fontdimens == { 48 "SLANT": 0.0, 49 "SPACE": 0.0, 50 "STRETCH": 0.0, 51 "SHRINK": 0.0, 52 "XHEIGHT": 0.4305553436279297, 53 "QUAD": 1.0000028610229492, 54 "EXTRASPACE": 0.0, 55 "DEFAULTRULETHICKNESS": 0.03999900817871094, 56 "BIGOPSPACING1": 0.11111164093017578, 57 "BIGOPSPACING2": 0.16666698455810547, 58 "BIGOPSPACING3": 0.19999980926513672, 59 "BIGOPSPACING4": 0.6000003814697266, 60 "BIGOPSPACING5": 0.10000038146972656, 61 } 62 63 64def test_read_fontdimens_mathsy(): 65 path = os.path.join(DATA_DIR, "cmsy10.tfm") 66 tfm = tfmLib.TFM(path) 67 assert tfm.fontdimens == { 68 "SLANT": 0.25, 69 "SPACE": 0.0, 70 "STRETCH": 0.0, 71 "SHRINK": 0.0, 72 "XHEIGHT": 0.4305553436279297, 73 "QUAD": 1.0000028610229492, 74 "EXTRASPACE": 0.0, 75 "NUM1": 0.6765079498291016, 76 "NUM2": 0.39373207092285156, 77 "NUM3": 0.44373130798339844, 78 "DENOM1": 0.6859512329101562, 79 "DENOM2": 0.34484100341796875, 80 "SUP1": 0.41289234161376953, 81 "SUP2": 0.36289215087890625, 82 "SUP3": 0.28888893127441406, 83 "SUB1": 0.14999961853027344, 84 "SUB2": 0.24721717834472656, 85 "SUBDROP": 0.05000019073486328, 86 "SUPDROP": 0.3861083984375, 87 "DELIM1": 2.3899993896484375, 88 "DELIM2": 1.010000228881836, 89 "AXISHEIGHT": 0.25, 90 } 91