def test_cidkeyed_read_write(arg, input, output, expected): """ Tests reading & writing CID-Keyed fonts in tx (uforead & ufowrite) CID -> UFO (one-way test) UFO -> CID (one-way test) CID -> UFO -> CID (round-trip test) UFO -> CID -> UFO (round-trip test) """ folder = "cid_roundtrip/" input_path = get_input_path(folder + input) output_dir = get_temp_dir_path() output_path = os.path.join(output_dir, output) expected_path = get_expected_path(folder + expected) if isinstance(arg, tuple): # round-trip tests runner(CMD + ['-a', '-o', arg[0], '-f', input_path, output_path]) final_output_dir = get_temp_dir_path() final_output_path = os.path.join(final_output_dir, output) runner(CMD + ['-a', '-o', arg[1], '-f', output_path, final_output_path]) output_path = final_output_path else: # one-way tests runner(CMD + ['-a', '-o', arg, '-f', input_path, output_path]) if '.subset' in expected_path: expected_path = generate_ps_dump(expected_path) output_path = generate_ps_dump(output_path) assert differ([expected_path, output_path])
def test_lib_removes_outlines_bug1366(): input_path = get_input_path("bug1366.ufo") expected_path = get_expected_path("bug1366.pfa") output_path = get_temp_file_path() subprocess.call([TOOL, '-t1', '-o', output_path, input_path]) expected_path = generate_ps_dump(expected_path) output_path = generate_ps_dump(output_path) assert differ([expected_path, output_path, '-s', PFA_SKIP[0]])
def test_remove_hints_bug180(): font_path = get_input_path('cid.otf') cid_path = get_temp_file_path() runner(CMD + ['-a', '-o', 't1', 'n', '-f', font_path, cid_path]) expected_path = get_expected_path('cid_nohints.ps') expected_path = generate_ps_dump(expected_path) actual_path = generate_ps_dump(cid_path) skip = ['-s'] + PS_SKIP2 assert differ([expected_path, actual_path] + skip)
def test_basic_hinting(font_filename, opt): arg = [] head, tail = os.path.splitext(font_filename) if opt: if opt == 'fi': _copy_fontinfo_file() else: arg = [opt] expected_filename = f'{head}-{opt}{tail}' else: expected_filename = f'{head}{tail}' if 'ufo' in font_filename: actual_path = get_temp_dir_path() else: actual_path = get_temp_file_path() diff_mode = [] if tail in {'.cff', '.pfb'}: diff_mode = ['-m', 'bin'] runner(CMD + ['-f', get_input_path(font_filename), '-o', 'o', f'_{actual_path}'] + arg) skip = [] if tail == '.otf': fi = '' if opt == 'fi': fi = '-' + opt expected_filename = os.path.splitext(font_filename)[0] + fi + '.ttx' actual_path = generate_ttx_dump(generalizeCFF(actual_path), ['CFF ']) skip = ['-l', '2'] # <ttFont sfntVersion= elif tail in {'.pfa', '.pfb'}: skip = ['-s', r'%ADOt1write:'] elif tail == '.ps': actual_path = generate_ps_dump(actual_path) skip = ['-s', r'%ADOt1write:'] elif tail == '.cff': actual_path = generalizeCFF(actual_path, do_sfnt=False) expected_path = get_expected_path(expected_filename) if tail == '.ps': expected_path = generate_ps_dump(expected_path) assert differ([expected_path, actual_path] + diff_mode + skip)
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)
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)
def test_convert_to_cid(): font1_filename = 'font1.pfa' font2_filename = 'font2.pfa' font3_filename = 'font3.pfa' alias1_filename = 'alias1.txt' alias2_filename = 'alias2.txt' alias3_filename = 'alias3.txt' fontinfo_filename = 'cidfontinfo.txt' actual_path = get_temp_file_path() expected_path = get_expected_path('cidfont.ps') runner(CMD + ['-o', 'cid', '-f', fontinfo_filename, actual_path, alias1_filename, font1_filename, alias2_filename, font2_filename, alias3_filename, font3_filename]) actual_path = generate_ps_dump(actual_path) expected_path = generate_ps_dump(expected_path) assert differ([expected_path, actual_path, '-s', r'%ADOt1write:'])
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)