示例#1
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
    status, message = list(check(test_fonts))[-1]
    assert status == PASS

    # 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
    status, message = list(check(test_fonts))[-1]
    expected_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"
    assert message == expected_message
    assert status == FAIL
示例#2
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
    status, message = list(check(test_fonts))[-1]
    assert status == PASS

    # 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')

    status, message = list(check(test_fonts))[-1]
    assert status == FAIL and message.code == "too-many"
示例#3
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,
    WindowsEncodingID.UNICODE_BMP,
    ENGLISH_LANG_ID
  )
  status, message = list(check(test_font))[-1]
  assert status == PASS

  # ...now let's change the Mac name ID 6 entry to something else:
  test_font['name'].setName(
    'YetAnotherFontName',
    NameID.POSTSCRIPT_NAME,
    PlatformID.MACINTOSH,
    WindowsEncodingID.UNICODE_BMP,
    ENGLISH_LANG_ID
  )
  status, message = list(check(test_font))[-1]
  assert status == FAIL
示例#4
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
  status, message = list(check(test_fonts))[-1]
  assert status == PASS

  # 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
  status, message = list(check(test_fonts))[-1]
  expected_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"
  assert message == expected_message
  assert status == FAIL
示例#5
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)
    status, message = list(check(test_font))[-1]
    assert status == PASS

    # ...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)
    status, message = list(check(test_font))[-1]
    assert status == FAIL and message.code == "inconsistency"
示例#6
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
  status, message = list(check(test_fonts))[-1]
  assert status == PASS

  # 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')

  status, message = list(check(test_fonts))[-1]
  assert status == FAIL