forked from adobe-type-tools/afdko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotatefont_test.py
124 lines (101 loc) · 3.88 KB
/
rotatefont_test.py
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
import pytest
import subprocess
from runner import main as runner
from differ import main as differ
from test_utils import (get_input_path, get_expected_path, get_temp_file_path,
generate_ps_dump)
TOOL = 'rotatefont'
CMD = ['-t', TOOL]
# -----
# Tests
# -----
@pytest.mark.parametrize('arg', ['-h', '-v', '-u'])
def test_exit_known_option(arg):
assert subprocess.call([TOOL, arg]) == 0
@pytest.mark.parametrize('arg', ['-z', '-foo'])
def test_exit_unknown_option(arg):
assert subprocess.call([TOOL, arg]) == 1
@pytest.mark.parametrize('i, matrix', [
# scale glyphs horizontally by a factor of 2,
# condense glyphs vertically by a factor three-quarters,
# move glyphs left by 100, and up by 200.
(1, '2.0 0 0 0.75 100 200'),
# rotate glyphs clockwise 90 degrees around origin point (0,0)
# move glyphs up by 1000
(2, '0 -1.0 1.0 0 0 1000'),
# oblique glyphs, slanting at a slope of 2 units horizontally for every
# 10 units of height
(3, '1.0 0 .2 1.0 0 0'),
])
@pytest.mark.parametrize('font_filename', ['font.pfa', 'cidfont.ps'])
def test_matrix(font_filename, i, matrix):
matrix_values = [f'_{val}' for val in matrix.split()]
font_path = get_input_path(font_filename)
actual_path = get_temp_file_path()
runner(CMD + ['-a', '-f', font_path, actual_path,
'-o', 't1', 'matrix'] + matrix_values)
ext = 'pfa'
skip = ['-s', '%ADOt1write:']
if 'cid' in font_filename:
ext = 'ps'
expected_path = get_expected_path(f'matrix{i}.{ext}')
if ext == 'ps':
actual_path = generate_ps_dump(actual_path)
expected_path = generate_ps_dump(expected_path)
assert differ([expected_path, actual_path] + skip)
@pytest.mark.parametrize('i, rt_args', [
(1, '26 105 -77'),
(2, '-11 -56 98'),
])
@pytest.mark.parametrize('font_filename', ['font.pfa', 'cidfont.ps'])
def test_rt_fd_options(font_filename, i, rt_args):
fd_args = []
ext = 'pfa'
skip = ['-s', '%ADOt1write:']
if 'cid' in font_filename:
fd_args = ['fd', f'_{i}']
ext = 'ps'
rt_values = [f'_{val}' for val in rt_args.split()]
font_path = get_input_path(font_filename)
actual_path = get_temp_file_path()
runner(CMD + ['-a', '-f', font_path, actual_path,
'-o', 't1', 'rt'] + rt_values + fd_args)
expected_path = get_expected_path(f'rotatrans{i}.{ext}')
if ext == 'ps':
actual_path = generate_ps_dump(actual_path)
expected_path = generate_ps_dump(expected_path)
assert differ([expected_path, actual_path] + skip)
@pytest.mark.parametrize('font_filename', ['font.pfa', 'cidfont.ps'])
def test_rtf_option(font_filename):
ext = 'pfa'
rtf_filename = 'rotate.txt'
skip = ['-s', '%ADOt1write:']
if 'cid' in font_filename:
ext = 'ps'
rtf_filename = 'cidrotate.txt'
rtf_path = get_input_path(rtf_filename)
font_path = get_input_path(font_filename)
actual_path = get_temp_file_path()
runner(CMD + ['-a', '-f', font_path, actual_path,
'-o', 't1', 'rt', '_45', '_0', '_0',
'rtf', f'_{rtf_path}'])
expected_path = get_expected_path(f'rotafile.{ext}')
if ext == 'ps':
actual_path = generate_ps_dump(actual_path)
expected_path = generate_ps_dump(expected_path)
assert differ([expected_path, actual_path] + skip)
def test_glyph_limit_error_bug1338():
"""
Testing font with 65535 glyphs for
string INDEX limit exceeded error
instead of segfault error
"""
rtf_path = get_input_path("bug1338/bug1338-map.txt")
font_path = get_input_path("bug1338/bug1338-font.pfa")
actual_path = get_temp_file_path()
cmd = CMD + ['-a', '-f', font_path, actual_path,
'-o', 't1',
'rtf', f'_{rtf_path}']
with pytest.raises(subprocess.CalledProcessError) as err:
runner(cmd)
assert err.value.returncode == 35