Ejemplo n.º 1
0
def test_percent_cmd_ttf_file_30_percent_adobe_approach(capsys):
    try:
        from fontline.app import main
        fontpath = os.path.join('tests', 'testingfiles',
                                'SourceCodePro-Regular.ttf')
        testpath = os.path.join('tests', 'testingfiles',
                                'SourceCodePro-Regular-test.ttf')
        newfont_path = os.path.join(
            'tests', 'testingfiles',
            'SourceCodePro-Regular-test-linegap30.ttf')
        create_test_file(fontpath)
        assert file_exists(testpath) is True
        sys.argv = ['font-line', 'percent', '30', testpath]
        main()

        assert file_exists(newfont_path)

        tt = ttLib.TTFont(newfont_path)

        os2_typo_ascender = tt['OS/2'].sTypoAscender
        os2_typo_descender = tt['OS/2'].sTypoDescender
        os2_win_ascent = tt['OS/2'].usWinAscent
        os2_win_descent = tt['OS/2'].usWinDescent
        os2_typo_linegap = tt['OS/2'].sTypoLineGap
        hhea_ascent = tt['hhea'].ascent
        hhea_descent = tt['hhea'].descent
        hhea_linegap = tt['hhea'].lineGap
        units_per_em = tt['head'].unitsPerEm

        assert os2_typo_ascender == 750
        assert os2_typo_descender == -250
        assert os2_win_ascent == 1005
        assert os2_win_descent == 294
        assert units_per_em == 1000
        assert os2_typo_linegap == 0
        assert hhea_ascent == 1005
        assert hhea_descent == -294
        assert hhea_linegap == 0

        erase_test_file(testpath)
        erase_test_file(newfont_path)
    except Exception as e:
        # cleanup test files
        if file_exists(testpath):
            erase_test_file(testpath)
        if file_exists(newfont_path):
            erase_test_file(newfont_path)
        raise e
Ejemplo n.º 2
0
def test_percent_cmd_otf_file_10_percent_default_approach(capsys):
    try:
        from fontline.app import main
        fontpath = os.path.join('tests', 'testingfiles', 'Hack-Regular.otf')
        testpath = os.path.join('tests', 'testingfiles',
                                'Hack-Regular-test.otf')
        newfont_path = os.path.join('tests', 'testingfiles',
                                    'Hack-Regular-test-linegap10.otf')
        create_test_file(fontpath)
        assert file_exists(testpath) is True
        sys.argv = ['font-line', 'percent', '10', testpath]
        main()

        assert file_exists(newfont_path)

        tt = ttLib.TTFont(newfont_path)

        os2_typo_ascender = tt['OS/2'].sTypoAscender
        os2_typo_descender = tt['OS/2'].sTypoDescender
        os2_win_ascent = tt['OS/2'].usWinAscent
        os2_win_descent = tt['OS/2'].usWinDescent
        os2_typo_linegap = tt['OS/2'].sTypoLineGap
        hhea_ascent = tt['hhea'].ascent
        hhea_descent = tt['hhea'].descent
        hhea_linegap = tt['hhea'].lineGap
        units_per_em = tt['head'].unitsPerEm

        assert os2_typo_ascender == 1556
        assert os2_typo_descender == -492
        assert os2_win_ascent == 1658
        assert os2_win_descent == 594
        assert units_per_em == 2048
        assert os2_typo_linegap == 204
        assert hhea_ascent == 1658
        assert hhea_descent == -594
        assert hhea_linegap == 0

        erase_test_file(testpath)
        erase_test_file(newfont_path)
    except Exception as e:
        # cleanup test files
        if file_exists(testpath):
            erase_test_file(testpath)
        if file_exists(newfont_path):
            erase_test_file(newfont_path)
        raise e
Ejemplo n.º 3
0
def test_percent_cmd_otf_file_10_percent(capsys):
    try:
        from fontline.app import main
        fontpath = os.path.join('tests', 'testingfiles', 'Hack-Regular.otf')
        testpath = os.path.join('tests', 'testingfiles', 'Hack-Regular-test.otf')
        newfont_path = os.path.join('tests', 'testingfiles', 'Hack-Regular-test-linegap10.otf')
        create_test_file(fontpath)
        assert file_exists(testpath) is True
        sys.argv = ['font-line', 'percent', '10', testpath]
        main()

        assert file_exists(newfont_path)

        tt = ttLib.TTFont(newfont_path)

        os2_typo_ascender = tt['OS/2'].__dict__['sTypoAscender']
        os2_typo_descender = tt['OS/2'].__dict__['sTypoDescender']
        os2_win_ascent = tt['OS/2'].__dict__['usWinAscent']
        os2_win_descent = tt['OS/2'].__dict__['usWinDescent']
        os2_typo_linegap = tt['OS/2'].__dict__['sTypoLineGap']
        hhea_ascent = tt['hhea'].__dict__['ascent']
        hhea_descent = tt['hhea'].__dict__['descent']
        hhea_linegap = tt['hhea'].__dict__['lineGap']
        units_per_em = tt['head'].__dict__['unitsPerEm']

        assert os2_typo_ascender == 1556
        assert os2_typo_descender == -492
        assert os2_win_ascent == 1658
        assert os2_win_descent == 594
        assert units_per_em == 2048
        assert os2_typo_linegap == 204
        assert hhea_ascent == 1658
        assert hhea_descent == -594
        assert hhea_linegap == 0

        erase_test_file(testpath)
        erase_test_file(newfont_path)
    except Exception as e:
        # cleanup test files
        if file_exists(testpath):
            erase_test_file(testpath)
        if file_exists(newfont_path):
            erase_test_file(newfont_path)
        raise e
Ejemplo n.º 4
0
def test_percent_cmd_ttf_file_30_percent_adobe_approach(capsys):
    try:
        from fontline.app import main
        fontpath = os.path.join('tests', 'testingfiles', 'SourceCodePro-Regular.ttf')
        testpath = os.path.join('tests', 'testingfiles', 'SourceCodePro-Regular-test.ttf')
        newfont_path = os.path.join('tests', 'testingfiles', 'SourceCodePro-Regular-test-linegap30.ttf')
        create_test_file(fontpath)
        assert file_exists(testpath) is True
        sys.argv = ['font-line', 'percent', '30', testpath]
        main()

        assert file_exists(newfont_path)

        tt = ttLib.TTFont(newfont_path)

        os2_typo_ascender = tt['OS/2'].sTypoAscender
        os2_typo_descender = tt['OS/2'].sTypoDescender
        os2_win_ascent = tt['OS/2'].usWinAscent
        os2_win_descent = tt['OS/2'].usWinDescent
        os2_typo_linegap = tt['OS/2'].sTypoLineGap
        hhea_ascent = tt['hhea'].ascent
        hhea_descent = tt['hhea'].descent
        hhea_linegap = tt['hhea'].lineGap
        units_per_em = tt['head'].unitsPerEm

        assert os2_typo_ascender == 750
        assert os2_typo_descender == -250
        assert os2_win_ascent == 1005
        assert os2_win_descent == 294
        assert units_per_em == 1000
        assert os2_typo_linegap == 0
        assert hhea_ascent == 1005
        assert hhea_descent == -294
        assert hhea_linegap == 0

        erase_test_file(testpath)
        erase_test_file(newfont_path)
    except Exception as e:
        # cleanup test files
        if file_exists(testpath):
            erase_test_file(testpath)
        if file_exists(newfont_path):
            erase_test_file(newfont_path)
        raise e
Ejemplo n.º 5
0
def main():
    """Defines the logic for the `font-line` command line executable"""
    c = Command()

    if c.does_not_validate_missing_args():
        stderr("[font-line] ERROR: Please include one or more arguments with your command.")
        sys.exit(1)

    if c.is_help_request():
        stdout(settings.HELP)
        sys.exit(0)
    elif c.is_version_request():
        stdout(settings.VERSION)
        sys.exit(0)
    elif c.is_usage_request():
        stdout(settings.USAGE)
        sys.exit(0)

    # REPORT sub-command
    if c.subcmd == "report":
        if c.argc < 2:
            stderr("[font-line] ERROR: Missing file path argument(s) after the report subcommand.")
            sys.exit(1)
        else:
            for fontpath in c.argv[1:]:
                # test for existence of file on path
                if file_exists(fontpath):
                    # test that filepath includes file of a supported file type
                    if is_supported_filetype(fontpath):
                        stdout(get_font_report(fontpath))
                    else:
                        stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a supported font file type.")
                else:
                    stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a valid filepath.")
    # PERCENT sub-command
    elif c.subcmd == "percent":
        if c.argc < 3:
            stderr("[font-line] ERROR: Not enough arguments.")
            sys.exit(1)
        else:
            percent = c.argv[1]
            # test the percent integer argument
            try:
                percent_int = int(percent)  # test that the argument can be cast to an integer value
                if percent_int <= 0:
                    stderr("[font-line] ERROR: Please enter a percent value that is greater than zero.")
                    sys.exit(1)
                if percent_int > 100:
                    stdout("[font-line] Warning: You entered a percent value over 100%. Please confirm that this is "
                           "your intended metrics modification.")
            except ValueError:
                stderr("[font-line] ERROR: You entered '" + percent + "'. This argument needs to be an integer value.")
                sys.exit(1)
            for fontpath in c.argv[2:]:
                if file_exists(fontpath):
                    if is_supported_filetype(fontpath):
                        if modify_linegap_percent(fontpath, percent) is True:
                            outpath = get_linegap_percent_filepath(fontpath, percent)
                            stdout("[font-line] '" + fontpath + "' successfully modified to '" + outpath + "'.")
                        else:  # pragma: no cover
                            stderr("[font-line] ERROR: Unsuccessful modification of '" + fontpath + "'.")
                    else:
                        stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a supported font file type.")
                else:
                    stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a valid filepath.")
    else:
        stderr("[font-lines] ERROR: You used an unsupported argument to the executable. Please review the"
               " `font-line --help` documentation and try again.")
        sys.exit(1)
Ejemplo n.º 6
0
def main():
    """Defines the logic for the `font-line` command line executable"""
    c = Command()

    if c.does_not_validate_missing_args():
        stderr(
            "[font-line] ERROR: Please include one or more arguments with your command."
        )
        sys.exit(1)

    if c.is_help_request():
        stdout(settings.HELP)
        sys.exit(0)
    elif c.is_version_request():
        stdout(settings.VERSION)
        sys.exit(0)
    elif c.is_usage_request():
        stdout(settings.USAGE)
        sys.exit(0)

    # REPORT sub-command
    if c.subcmd == "report":
        if c.argc < 2:
            stderr(
                "[font-line] ERROR: Missing file path argument(s) after the "
                "report subcommand.")
            sys.exit(1)
        else:
            for fontpath in c.argv[1:]:
                # test for existence of file on path
                if file_exists(fontpath):
                    # test that filepath includes file of a supported file type
                    if is_supported_filetype(fontpath):
                        stdout(get_font_report(fontpath))
                    else:
                        stderr(
                            "[font-line] ERROR: '" + fontpath +
                            "' does not appear to be a supported font file type."
                        )
                else:
                    stderr("[font-line] ERROR: '" + fontpath +
                           "' does not appear to be a valid filepath.")
    # PERCENT sub-command
    elif c.subcmd == "percent":
        if c.argc < 3:
            stderr("[font-line] ERROR: Not enough arguments.")
            sys.exit(1)
        else:
            percent = c.argv[1]
            # test the percent integer argument
            try:
                percent_int = int(
                    percent
                )  # test that the argument can be cast to an integer value
                if percent_int <= 0:
                    stderr(
                        "[font-line] ERROR: Please enter a percent value that is "
                        "greater than zero.")
                    sys.exit(1)
                if percent_int > 100:
                    stdout(
                        "[font-line] Warning: You entered a percent value over 100%. "
                        "Please confirm that this is your intended metrics modification."
                    )
            except ValueError:
                stderr("[font-line] ERROR: You entered '" + percent +
                       "'. This argument needs to be an integer value.")
                sys.exit(1)
            for fontpath in c.argv[2:]:
                if file_exists(fontpath):
                    if is_supported_filetype(fontpath):
                        if modify_linegap_percent(fontpath, percent) is True:
                            outpath = get_linegap_percent_filepath(
                                fontpath, percent)
                            stdout("[font-line] '" + fontpath +
                                   "' successfully modified to '" + outpath +
                                   "'.")
                        else:  # pragma: no cover
                            stderr(
                                "[font-line] ERROR: Unsuccessful modification of '"
                                + fontpath + "'.")
                    else:
                        stderr(
                            "[font-line] ERROR: '" + fontpath +
                            "' does not appear to be a supported font file type."
                        )
                else:
                    stderr("[font-line] ERROR: '" + fontpath +
                           "' does not appear to be a valid filepath.")
    else:
        stderr(
            "[font-lines] ERROR: You used an unsupported argument to the executable. "
            "Please review the `font-line --help` documentation and try again."
        )
        sys.exit(1)