예제 #1
0
def test_check_family_max_4_fonts_per_family_name():
    from fontbakery.profiles.name import \
        com_adobe_fonts_check_family_max_4_fonts_per_family_name as check

    base_path = portable_path("data/test/source-sans-pro/OTF")

    font_names = [
        'SourceSansPro-Black.otf', 'SourceSansPro-BlackIt.otf',
        'SourceSansPro-Bold.otf', 'SourceSansPro-BoldIt.otf',
        'SourceSansPro-ExtraLight.otf', 'SourceSansPro-ExtraLightIt.otf',
        'SourceSansPro-It.otf', 'SourceSansPro-Light.otf',
        'SourceSansPro-LightIt.otf', 'SourceSansPro-Regular.otf',
        'SourceSansPro-Semibold.otf', 'SourceSansPro-SemiboldIt.otf'
    ]

    font_paths = [os.path.join(base_path, n) for n in font_names]

    test_fonts = [TTFont(x) for x in font_paths]

    # try fonts with correct family name grouping
    assert_PASS(check(test_fonts))

    # now set 5 of the fonts to have the same family name
    for font in test_fonts[:5]:
        name_records = font['name'].names
        for name_record in name_records:
            if name_record.nameID == 1:
                # print(repr(name_record.string))
                name_record.string = 'foobar'.encode('utf-16be')

    assert_results_contain(check(test_fonts), FAIL, 'too-many')
예제 #2
0
def test_check_name_postscript_name_consistency():
    from fontbakery.profiles.name import \
        com_adobe_fonts_check_name_postscript_name_consistency as check

    base_path = portable_path("data/test/source-sans-pro/TTF")
    font_path = os.path.join(base_path, 'SourceSansPro-Regular.ttf')
    test_font = TTFont(font_path)

    # SourceSansPro-Regular only has one name ID 6 entry (for Windows),
    # let's add another one for Mac that matches the Windows entry:
    test_font['name'].setName(
        'SourceSansPro-Regular',
        NameID.POSTSCRIPT_NAME,
        PlatformID.MACINTOSH,
        MacintoshEncodingID.ROMAN,
        MacintoshLanguageID.ENGLISH
    )
    assert_PASS(check(test_font))

    # ...now let's change the Mac name ID 6 entry to something else:
    test_font['name'].setName(
        'YetAnotherFontName',
        NameID.POSTSCRIPT_NAME,
        PlatformID.MACINTOSH,
        MacintoshEncodingID.ROMAN,
        MacintoshLanguageID.ENGLISH
    )
    assert_results_contain(check(test_font),
                           FAIL, 'inconsistency')
예제 #3
0
def test_check_family_bold_italic_unique_for_nameid1():
    """Check that OS/2.fsSelection bold/italic settings are unique within each
    Compatible Family group (i.e. group of up to 4 with same NameID1)"""
    from fontbakery.profiles.os2 import \
      com_adobe_fonts_check_family_bold_italic_unique_for_nameid1 as check
    from fontbakery.constants import FsSelection

    base_path = portable_path("data/test/source-sans-pro/OTF")

    # these fonts have the same NameID1
    font_names = [
        'SourceSansPro-Regular.otf', 'SourceSansPro-Bold.otf',
        'SourceSansPro-It.otf', 'SourceSansPro-BoldIt.otf'
    ]

    font_paths = [os.path.join(base_path, n) for n in font_names]
    test_fonts = [TTFont(x) for x in font_paths]

    # the family should be correctly constructed
    assert_PASS(check(test_fonts))

    # now hack the italic font to also have the bold bit set
    test_fonts[2]['OS/2'].fsSelection |= FsSelection.BOLD

    # we should get a failure due to two fonts with both bold & italic set
    message = assert_results_contain(
        check(test_fonts), FAIL, None)  # FIXME: This needs a message keyword!
    assert message == ("Family 'Source Sans Pro' has 2 fonts (should be no"
                       " more than 1) with the same OS/2.fsSelection"
                       " bold & italic settings: Bold=True, Italic=True")
예제 #4
0
def test_check_family_consistent_upm_new_style():
    # these fonts have a consistent unitsPerEm of 1000:
    check = CheckTester(adobefonts_profile,
                        "com.adobe.fonts/check/family/consistent_upm")

    filenames = ['SourceSansPro-Regular.otf',
                 'SourceSansPro-Bold.otf',
                 'SourceSansPro-It.otf']
    fonts = [os.path.join(portable_path("data/test/source-sans-pro/OTF"), filename)
                 for filename in filenames]

    # try fonts with consistent UPM (i.e. 1000)
    assert_PASS(check(fonts))

    ttFonts = check['ttFonts']
    # now try with one font with a different UPM (i.e. 2048)
    ttFonts[1]['head'].unitsPerEm = 2048
    assert_results_contain(check(ttFonts),
                           FAIL, None) # FIXME: This needs a message keyword