Exemplo n.º 1
0
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'])
Exemplo n.º 2
0
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])
Exemplo n.º 3
0
def test_restore_contour_order_warning(input_font, expected_font):
    """
    Test the warning message outputted with
    unsuccessful restore_contour_order.
    """
    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)
    stderr_path = runner(CMD + ['-s', '-f', in_path, '-o', "e", '=all',
                                'o', '_' + out_path])
    assert get_font_format(out_path) == get_font_format(in_path)
    assert differ([expected_path, out_path, '-r', r'^\s*<point'])
    with open(stderr_path, 'rb') as f:
        output = f.read()
    assert (b'Warning: duplicated start point on contour 3 at 616, 597 of '
            b'glyph cid51107.') in output
Exemplo n.º 4
0
def get_options(args):
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter, description=__doc__)
    parser.add_argument('--version', action='version', version=__version__)
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        default=0,
                        help='verbose mode\n'
                        'Use -vv for debug mode')
    parser.add_argument(
        '-r',
        '--report',
        action='store_true',
        help="report the TTC's fonts and tables (no files are written)",
    )
    parser.add_argument(
        'ttc_path',
        metavar='TTC FONT',
        type=validate_path,
        help='path to TTC font',
    )
    options = parser.parse_args(args)

    if not options.verbose:
        level = "WARNING"
    elif options.verbose == 1:
        level = "INFO"
    else:
        level = "DEBUG"
    logging.basicConfig(level=level)

    if get_font_format(options.ttc_path) != 'TTC':
        parser.error('The input file is not an OpenType Collection font.')

    return options
Exemplo n.º 5
0
def get_options(args):
    parser = argparse.ArgumentParser(
        formatter_class=InlineHelpFormatter,
        description=__doc__
    )
    parser.add_argument(
        '--version',
        action='version',
        version=__version__
    )
    parser.add_argument(
        '-q',
        '--quiet-mode',
        action='store_true',
        help='run in quiet mode'
    )
    parser.add_argument(
        '--no-overlap-checks',
        action='store_true',
        help='turn off path overlap checks'
    )
    parser.add_argument(
        '--no-basic-checks',
        action='store_true',
        help='turn off the following checks:\n'
             '- coincident points\n'
             '- colinear line segments\n'
             '- flat curves (straight segments with unnecessary control '
             'points)'
    )
    parser.add_argument(
        '--min-area',
        metavar='NUMBER',
        type=int,
        default=25,
        help='minimum area for a tiny outline\n'
             'Default is %(default)s square units. Subpaths with a bounding '
             'box less than this will be reported, and deleted if the -e '
             'option is used.'
    )
    parser.add_argument(
        '--tolerance',
        metavar='NUMBER',
        type=int,
        default=0,
        help='maximum allowed deviation from a straight line\n'
             'Default is %(default)s design space units. This is used to '
             'test whether the control points of a curve define a flat '
             'curve, and whether colinear line segments define a '
             'straight line.'
    )
    parser.add_argument(
        '-g',
        '--glyph-list',
        help='specify a list of glyphs to check\n'
             'Check only the specified list of glyphs. The list must be '
             'comma-delimited. The glyph IDs may be glyph indexes '
             'or glyph names. There must be no white-space in the '
             'glyph list.\n'
             'Example:\n'
             '    checkoutlinesufo -g A,B,C,69 MyFont.ufo'
    )
    parser.add_argument(
        '-f',
        '--glyph-file',
        metavar='FILE_PATH',
        type=validate_path,
        help='specify a file containing a list of glyphs to check\n'
             'Check only specific glyphs listed in a file. The '
             'file must contain a comma-delimited list of glyph '
             'identifiers. Any number of space, tab, and new-line '
             'characters are permitted between glyph names and commas.'
    )
    parser.add_argument(
        '-d',
        '--decimal',
        action='store_true',
        help='do NOT round point coordinates to integer'
    )
    parser.add_argument(
        '-e',
        '--error-correction-mode',
        action='store_true',
        help='correct reported problems\n'
             'The original font is modified. If the font is UFO, the outlines '
             'in the default layer are left untouched and a layer containing '
             'the modified version of the glyphs is added. The new layer is '
             f"named: '{PROCD_GLYPHS_LAYER}'"
    )
    ufo_opts = parser.add_argument_group('UFO-only options')
    ufo_opts.add_argument(
        '-w',
        '--write-to-default-layer',
        action='store_true',
        help='write the modified glyphs to the default layer instead of '
             f"'{PROCD_GLYPHS_LAYER}'"
    )
    ufo_opts.add_argument(
        '--clear-hash-map',
        action='store_true',
        help='delete the hashes file\n'
             'By default, a file containing compact descriptions '
             '(a.k.a. hashes) of the glyphs is saved inside the '
             'UFO on the first time the font is checked. Storing '
             'these hashes allows checkoutlinesufo to be much faster '
             'on successive checks of the same UFO (because the '
             'tool will skip processing glyphs that were not '
             'modified since the last time the font was checked).'
    )
    ufo_opts.add_argument(
        '--all',
        action='store_true',
        help='force all glyphs to be processed\n'
             'Makes the tool ignore the stored hashes thus checking all the '
             'glyphs, even if they have already been processed.'
    )
    parser.add_argument(
        'font_path',
        metavar='FONT_PATH',
        type=validate_path,
        help='Path to UFO, OTF, CFF, or Type 1 font'
    )

    parsed_args = parser.parse_args(args)

    font_format = get_font_format(parsed_args.font_path)
    if font_format not in ('UFO', 'OTF', 'CFF', 'PFA', 'PFB', 'PFC'):
        parser.error('Font format is not supported.')

    options = COOptions()

    if parsed_args.glyph_list:
        options.glyph_list += parse_glyph_list_arg(parsed_args.glyph_list)

    if parsed_args.glyph_file:
        gf = open(parsed_args.glyph_file)
        glyph_string = gf.read()
        glyph_string = glyph_string.strip()
        gf.close()
        options.glyph_list += parse_glyph_list_arg(glyph_string)

    if parsed_args.no_overlap_checks:
        options.test_list.remove(do_overlap_removal)
    if parsed_args.no_basic_checks:
        options.test_list.remove(do_cleanup)

    options.font_path = parsed_args.font_path
    options.font_format = font_format
    options.allow_changes = parsed_args.error_correction_mode
    options.quiet_mode = parsed_args.quiet_mode
    options.min_area = parsed_args.min_area
    options.tolerance = parsed_args.tolerance
    options.allow_decimal_coords = parsed_args.decimal
    options.check_all = parsed_args.all
    options.clear_hash_map = parsed_args.clear_hash_map
    options.write_to_default_layer = parsed_args.write_to_default_layer

    return options
def _validate_font_path(path_str):
    vpath = os.path.abspath(os.path.realpath(path_str))
    return os.path.isfile(vpath) and (get_font_format(vpath) == 'TTF')
Exemplo n.º 7
0
def _validate_font_path(path_str):
    vpath = os.path.abspath(os.path.realpath(path_str))
    if os.path.isfile(vpath) and (get_font_format(vpath) == 'TTF'):
        return vpath
    raise argparse.ArgumentTypeError(
        f"'{path_str}' is not a valid TrueType font file path.")
Exemplo n.º 8
0
def test_get_font_format(filename, fontformat):
    assert get_font_format(get_input_path(filename)) == fontformat