Exemple #1
0
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_options_dir():
    input_dir = get_temp_dir_path()
    output_dir = get_temp_dir_path()
    font_path = _get_test_ttf_path()
    in_font_path = copy2(font_path, input_dir)
    ttfdecomp.main(['-d', input_dir, '-o', output_dir, '-v'])
    out_file = in_font_path.replace(input_dir, output_dir)
    font = TTFont(out_file)
    assert font['maxp'].maxComponentElements == 0
Exemple #3
0
    def open(self, use_hash_map):
        font_path = self.font_path

        if self.font_format == 'UFO':
            self.font_type = UFO_FONT_TYPE
            ufotools.validateLayers(font_path)
            self.defcon_font = defcon.Font(font_path)
            self.ufo_format = self.defcon_font.ufoFormatVersionTuple
            self.use_hash_map = use_hash_map
            self.ufo_font_hash_data = ufotools.UFOFontData(
                font_path,
                self.use_hash_map,
                programName=ufotools.kCheckOutlineName)
            self.ufo_font_hash_data.readHashMap()

        else:
            print("Converting to temp UFO font...")
            self.temp_ufo_path = temp_path = get_temp_dir_path('font.ufo')

            if not run_shell_command(['tx', '-ufo', font_path, temp_path]):
                raise FocusFontError('Failed to convert input font to UFO.')

            try:
                self.defcon_font = defcon.Font(temp_path)
            except UFOLibError:
                raise

            if self.font_format == 'OTF':
                self.font_type = OTF_FONT_TYPE
            elif self.font_format == 'CFF':
                self.font_type = CFF_FONT_TYPE
            else:
                self.font_type = TYPE1_FONT_TYPE

        return self.defcon_font
def test_remove_overlap_ufo(args, ufo_filename, expct_label):
    actual_path = get_temp_dir_path(ufo_filename)
    copytree(get_input_path(ufo_filename), actual_path)
    runner(CMD + ['-f', actual_path, '-o'] + args)
    expct_filename = f'{ufo_filename[:-4]}-{expct_label}'
    expected_path = get_expected_path(expct_filename)
    assert differ([expected_path, actual_path])
Exemple #5
0
def test_get_temp_dir_path(path_comp):
    pth = get_temp_dir_path(path_comp)
    if path_comp:
        assert path.basename(pth) == path_comp
        assert path.isdir(path.dirname(pth))
    else:
        assert path.isdir(pth)
def test_cjk_var():
    """
    Builds all OTFs for the 'CJKVar' project and then diffs two of them.
    """
    input_dir = get_input_path('CJKVar')
    temp_dir = get_temp_dir_path('CJKVar')
    copytree(input_dir, temp_dir)
    ds_path = os.path.join(temp_dir, 'CJKVar.designspace')
    runner(CMD + ['-o', 'd', f'_{ds_path}', '=mkot',
                  'omitDSIG,-omitMacNames', 'vv'])

    otf1_path = os.path.join(
        temp_dir, 'Normal', 'Master_8', 'MasterSet_Kanji-w600.00.otf')
    otf2_path = os.path.join(
        temp_dir, 'Condensed', 'Master_8', 'MasterSet_Kanji_75-w600.00.otf')

    for otf_path in (otf1_path, otf2_path):
        actual_ttx = generate_ttx_dump(otf_path)
        expected_ttx = get_expected_path(
            os.path.basename(otf_path)[:-3] + 'ttx')
        assert differ([expected_ttx, actual_ttx,
                       '-s',
                       '<ttFont sfntVersion' + SPLIT_MARKER +
                       '    <checkSumAdjustment value=' + SPLIT_MARKER +
                       '    <created value=' + SPLIT_MARKER +
                       '    <modified value=',
                       '-r', r'^\s+Version.*;hotconv.*;makeotfexe'])
Exemple #7
0
def test_output_is_folder_only_bug281(input_filename):
    # makeotf will output a default-named font to the folder
    input_path = get_input_path(input_filename)
    temp_dir = get_temp_dir_path()
    expected_path = os.path.join(temp_dir, OTF_NAME)
    assert os.path.exists(expected_path) is False
    runner(CMD + ['-o', 'f', f'_{input_path}', 'o', f'_{temp_dir}'])
    assert os.path.isfile(expected_path)
Exemple #8
0
def test_wildcard_inputs():
    fnames = ['latincid', 'sans', 'serif']
    paths = map(get_input_path, ['latincid.otf*', 'sans.ot?', 'serif.ot[cf]'])
    out_dir = get_temp_dir_path()
    out_paths = [path.join(out_dir, f'{fname}.ttf') for fname in fnames]
    assert all(map(path.exists, out_paths)) is False
    otf2ttf(['-o', out_dir, *paths])
    assert all(map(path.exists, out_paths)) is True
def test_run_invalid_ufo():
    ttf_path = _get_test_ttf_path()
    temp_dir = get_temp_dir_path()
    save_path = get_temp_file_path(directory=temp_dir)
    ufo_path = save_path + '.ufo'
    copy2(ttf_path, save_path)
    copy2(ttf_path, ufo_path)
    assert ttfcomp.main([save_path]) == 1
Exemple #10
0
def test_ufo_with_trailing_slash_bug280(input_filename):
    # makeotf will now save the OTF alongside the UFO instead of inside of it
    ufo_path = get_input_path(input_filename)
    temp_dir = get_temp_dir_path()
    tmp_ufo_path = os.path.join(temp_dir, input_filename)
    copytree(ufo_path, tmp_ufo_path)
    runner(CMD + ['-o', 'f', f'_{tmp_ufo_path}{os.sep}'])
    expected_path = os.path.join(temp_dir, OTF_NAME)
    assert os.path.isfile(expected_path)
def test_compatibility_vf():
    input_dir = get_input_path('bug816')
    temp_dir = get_temp_dir_path('bug816var')
    copytree(input_dir, temp_dir)
    ds_path = os.path.join(temp_dir, 'bug816.designspace')
    runner(CMD + ['-o', 'c', 'd', f'_{ds_path}'])
    actual_path = os.path.join(temp_dir, 'bug816.otf')
    actual_ttx = generate_ttx_dump(actual_path, ['CFF2'])
    expected_ttx = get_expected_path('bug816.ttx')
    assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
Exemple #12
0
def test_skip_ttf_in_ttc(filename):
    input_path = get_input_path(f'{filename}.ttc')
    out_path = path.join(get_temp_dir_path(), f'{filename}.ttc')
    msg_path = runner(CMD + [
        '-s', '-e', '-o', 'o', f'_{out_path}', '=post-format', '_2', '-f',
        input_path
    ])
    with open(msg_path, 'rb') as f:
        output = f.read()
    assert b'WARNING: Not a OpenType font (bad sfntVersion)' in output
Exemple #13
0
def test_pdf_single_glyph():
    input_path = get_input_path("bug1218.otf")
    pdf_filename = "bug1218.pdf"
    expected_path = get_expected_path(pdf_filename)
    output_dir = get_temp_dir_path()
    output_path = os.path.join(output_dir, pdf_filename)

    runner(CMD + ['-a', '-o', 'pdf', '1', '-f', input_path, output_path])

    assert differ([expected_path, output_path, '-s', *PDF_SKIP])
Exemple #14
0
def test_convert(from_format, to_format):
    from_ext = _get_extension(from_format)
    to_ext = _get_extension(to_format)

    # input filename
    from_filename = from_format + from_ext

    # expected filename
    exp_filename = from_format + to_ext

    # runner args
    if 'ufo' in to_format:
        save_path = get_temp_dir_path('font.ufo')
    else:
        save_path = get_temp_file_path()

    # diff mode
    if to_format == 'cff':
        diff_mode = ['-m', 'bin']
    else:
        diff_mode = []

    # skip items
    regex_skip = []
    skip = []
    if to_format == 'afm':
        skip = ['Comment Creation Date:' + SPLIT_MARKER + 'Comment Copyright']
    elif to_format == 'pdf':
        skip = PDF_SKIP[:]
        regex_skip = PDF_SKIP_REGEX[:]
    elif to_format == 'ps':
        skip = PS_SKIP[:]
    elif to_format == 'type1':
        skip = PFA_SKIP[:]
    if skip:
        skip.insert(0, '-s')
    if regex_skip:
        for regex in regex_skip:
            skip.append('-r')
            skip.append(regex)

    # format arg fix
    if to_format in ('ufo2', 'ufo3'):
        format_arg = 'ufo'
    elif to_format == 'type1':
        format_arg = 't1'
    else:
        format_arg = to_format

    runner(CMD + [
        '-a', '-f',
        get_input_path(from_filename), save_path, '-o', format_arg
    ])
    expected_path = get_expected_path(exp_filename)
    assert differ([expected_path, save_path] + skip + diff_mode)
Exemple #15
0
def test_stat_axis_not_in_fvar():
    """
    Fail if fvar axes are missing from STAT
    """
    input_dir = get_input_path('STAT_tests')
    temp_dir = get_temp_dir_path('STAT_tests')
    copytree(input_dir, temp_dir)
    ds_path = os.path.join(temp_dir,
                           'STAT_axis_missing/STAT_axis_missing.designspace')
    with pytest.raises(subprocess.CalledProcessError):
        runner(CMD + ['-o', 'd', f'_{ds_path}'])
def test_ignore_contour_order(input_font, expected_font):
    """
    Test the '--ignore-contour-order' option.
    """
    in_path = get_input_path(input_font)
    out_path = os.path.join(get_temp_dir_path(), input_font)
    expected_path = get_expected_path(expected_font)
    runner(CMD + ['-f', in_path, '-o', '=ignore-contour-order', '=all', 'e',
                  'q', 'o', '_' + out_path])
    assert get_font_format(out_path) == get_font_format(in_path)
    assert differ([expected_path, out_path, '-r', r'^\s*<point'])
def test_output_file_option(input_font, expected_font):
    """
    Test the '-o' (output file) option.
    """
    in_path = get_input_path(input_font)
    out_path = os.path.join(get_temp_dir_path(), input_font)
    expected_path = get_expected_path(expected_font)
    runner(CMD + ['-f', in_path, '-o', 'e', 'o', '_' + out_path])

    assert get_font_format(out_path) == get_font_format(in_path)
    assert differ([expected_path, out_path])
def test_run_without_output_path():
    ttf_path = _get_test_ttf_path()
    temp_dir = get_temp_dir_path()
    save_path = get_temp_file_path(directory=temp_dir)
    copy2(ttf_path, save_path)
    ttfdecomp.main([save_path])
    font = TTFont(save_path)
    gtable = font['glyf']

    composites = [gtable[gl].isComposite() for gl in font.glyphOrder]
    assert not any(composites)
Exemple #19
0
def test_stat_axis_values_range():
    """
    Fail if STAT axis values are outside range defined in fvar
    """
    input_dir = get_input_path('STAT_tests')
    temp_dir = get_temp_dir_path('STAT_tests')
    copytree(input_dir, temp_dir)
    ds_path = os.path.join(temp_dir,
                           'STAT_axis_ranges/STAT_axis_ranges.designspace')
    with pytest.raises(subprocess.CalledProcessError):
        runner(CMD + ['-o', 'd', f'_{ds_path}'])
def test_subset_vf():
    input_dir = get_input_path('bug817')
    temp_dir = get_temp_dir_path('bug817var')
    copytree(input_dir, temp_dir)
    ds_path = os.path.join(temp_dir, 'bug817.designspace')
    subset_path = os.path.join(temp_dir, 'bug817.subset')
    runner(CMD + ['-o', 'd', f'_{ds_path}', 'i', f'_{subset_path}'])
    actual_path = os.path.join(temp_dir, 'bug817.otf')
    actual_ttx = generate_ttx_dump(actual_path, ['GSUB'])
    expected_ttx = get_expected_path('bug817.ttx')
    assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
Exemple #21
0
def test_nonstd_fontmatrix(fmt):
    input_path = get_input_path("nonstdfmtx.otf")
    txt_filename = f"nonstdfmtx_{fmt}.txt"
    expected_path = get_expected_path(txt_filename)
    output_dir = get_temp_dir_path()
    bin_output = os.path.join(output_dir, f"nonstdfmtx.{fmt}")
    output_path = os.path.join(output_dir, txt_filename)
    runner(CMD + ['-a', '-o', fmt, '*S', '*b', '-f', input_path, bin_output])
    runner(CMD + ['-a', '-o', 'dump', '-f', bin_output, output_path])
    skip = "## Filename "
    assert differ([expected_path, output_path, '-s', skip])
def test_cjk_vf():
    input_dir = get_input_path('CJKVar')
    temp_dir = get_temp_dir_path('CJKVar')
    copytree(input_dir, temp_dir)
    ds_path = os.path.join(temp_dir, 'CJKVar.designspace')
    runner(CMD + ['-o', 'd', f'_{ds_path}'])
    actual_path = os.path.join(temp_dir, 'CJKVar.otf')
    actual_ttx = generate_ttx_dump(actual_path,
                                   ['CFF2', 'HVAR', 'avar', 'fvar'])
    expected_ttx = get_expected_path('CJKVar.ttx')
    assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
Exemple #23
0
def test_multiple_inputs():
    fname1 = 'latincid'
    fname2 = 'sans'
    path1 = get_input_path(f'{fname1}.otf')
    path2 = get_input_path(f'{fname2}.otf')
    out_dir = get_temp_dir_path()
    out_path1 = path.join(out_dir, f'{fname1}.ttf')
    out_path2 = path.join(out_dir, f'{fname2}.ttf')
    assert all([path.exists(out_path1), path.exists(out_path2)]) is False
    otf2ttf(['-o', out_dir, path1, path2])
    assert all([path.exists(out_path1), path.exists(out_path2)]) is True
def test_regression_bug1315():
    """
    Test for uneccessary duplicated start point error messages.
    """
    in_path = get_input_path('bug1315.ufo')
    out_path = os.path.join(get_temp_dir_path(), 'bug1315.ufo')
    stderr_path = runner(CMD + ['-s', '-f', in_path, '-o', "e", '=all',
                                'o', '_' + out_path])
    with open(stderr_path, 'rb') as f:
        output = f.read()
    print(output)
    assert (b'Warning: duplicated start point on contour ') not in output
Exemple #25
0
def test_bug1003(capfd):
    """
    Check that "the input set requires compatibilization" message is in
    stderr when run without '-c' option.
    """
    input_dir = get_input_path('bug1003')
    temp_dir = get_temp_dir_path('bug1003var')
    copytree(input_dir, temp_dir)
    ds_path = os.path.join(temp_dir, 'bug1003.designspace')
    runner(CMD + ['-o', 'd', f'_{ds_path}'])
    captured = capfd.readouterr()
    assert "The input set requires compatibilization" in captured.err
def test_run_without_output_path():
    ttf_path = _get_test_ttf_path()
    ufo_path = _get_test_ufo_path()
    temp_dir = get_temp_dir_path()
    tmp_ufo_path = os.path.join(temp_dir, os.path.basename(ufo_path))
    save_path = get_temp_file_path(directory=temp_dir)
    copy2(ttf_path, save_path)
    copytree(ufo_path, tmp_ufo_path)
    ttfcomp.main([save_path])
    gtable = TTFont(save_path)['glyf']
    assert gtable['agrave'].isComposite() is False
    assert gtable['aacute'].isComposite() is True
def test_bug790():
    """
    Test case where the result of overlap removal resulted in coincident points
    at contour start. Previously caused a crash when attempting to set start
    point on the second point.
    """
    ufoname = 'bug790.ufo'
    actual_path = get_temp_dir_path(ufoname)
    copytree(get_input_path(ufoname), actual_path)
    runner(CMD + ['-f', actual_path, '-o', 'e'])
    expected_path = get_expected_path(ufoname)
    assert differ([expected_path, actual_path])
Exemple #28
0
def test_bug1003_compat():
    """
    Check that file is properly built when '-c' is specified.
    """
    input_dir = get_input_path('bug1003')
    temp_dir = get_temp_dir_path('bug1003cvar')
    copytree(input_dir, temp_dir)
    ds_path = os.path.join(temp_dir, 'bug1003.designspace')
    runner(CMD + ['-o', 'c' 'd', f'_{ds_path}'])
    actual_path = os.path.join(temp_dir, 'bug1003.otf')
    actual_ttx = generate_ttx_dump(actual_path, ['CFF2'])
    expected_ttx = get_expected_path('bug1003.ttx')
    assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
Exemple #29
0
def test_path_with_non_ascii_chars_bug222(input_filename):
    temp_dir = get_temp_dir_path('á意ê  ï薨õ 巽ù')
    os.makedirs(temp_dir)
    assert os.path.isdir(temp_dir)
    input_path = get_input_path(input_filename)
    temp_path = os.path.join(temp_dir, input_filename)
    if os.path.isdir(input_path):
        copytree(input_path, temp_path)
    else:
        copy2(input_path, temp_path)
    expected_path = os.path.join(temp_dir, OTF_NAME)
    assert os.path.exists(expected_path) is False
    runner(CMD + ['-o', 'f', f'_{temp_path}'])
    assert os.path.isfile(expected_path)
Exemple #30
0
def test_no_psname_convert_to_ufo_bug437(font_format):
    if 'cid' in font_format:
        file_ext = 'ps'
    elif 'ufo' in font_format:
        file_ext = 'ufo'
    else:
        file_ext = 'pfa'

    font_path = get_input_path(f'{font_format}-noPSname.{file_ext}')
    expected_path = get_expected_path(f'bug437/{font_format}.ufo')
    save_path = get_temp_dir_path(f'{font_format}.ufo')

    runner(CMD + ['-a', '-o', 'ufo', '-f', font_path, save_path])
    assert differ([expected_path, save_path])