예제 #1
0
def com_google_fonts_check_whitespace_ink(ttFont):
    """Whitespace glyphs have ink?"""
    from fontbakery.utils import (get_glyph_name, glyph_has_ink)

    # This checks that certain glyphs are empty.
    # Some, but not all, are Unicode whitespace.

    # code-points for all Unicode whitespace chars
    # (according to Unicode 11.0 property list):
    WHITESPACE_CHARACTERS = {
        0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x0020, 0x0085, 0x00A0, 0x1680,
        0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008,
        0x2009, 0x200A, 0x2028, 0x2029, 0x202F, 0x205F, 0x3000
    }

    # Code-points that do not have whitespace property, but
    # should not have a drawing.
    EXTRA_NON_DRAWING = {0x180E, 0x200B, 0x2060, 0xFEFF}

    # Make the set of non drawing characters.
    # OGHAM SPACE MARK U+1680 is removed as it is
    # a whitespace that should have a drawing.
    NON_DRAWING = WHITESPACE_CHARACTERS | EXTRA_NON_DRAWING - {0x1680}

    passed = True
    for codepoint in sorted(NON_DRAWING):
        g = get_glyph_name(ttFont, codepoint)
        if g is not None and glyph_has_ink(ttFont, g):
            passed = False
            yield FAIL,\
                  Message('has-ink',
                          f'Glyph "{g}" has ink.'
                          f' It needs to be replaced by an empty glyph.')
    if passed:
        yield PASS, "There is no whitespace glyph with ink."
예제 #2
0
def com_google_fonts_check_mandatory_glyphs(ttFont):
    """Font contains '.notdef' as its first glyph?"""
    from fontbakery.utils import glyph_has_ink

    passed = True
    if ttFont.getGlyphOrder()[0] != ".notdef":
        passed = False
        yield WARN,\
              Message('first-glyph',
                      "Font should contain the .notdef glyph as the first glyph.")

    if ".notdef" in ttFont.getBestCmap().values():
        passed = False
        yield WARN,\
              Message('codepoint',
                      f"Glyph '.notdef' should not have a Unicode codepoint value assigned,"
                      f" but got 0x{ttFont.getBestCmap().values()['.notdef']:04X}.")

    if not glyph_has_ink(ttFont, ".notdef"):
        passed = False
        yield WARN,\
              Message('empty',
                      "Glyph '.notdef' should contain a drawing, but it is empty.")

    if passed:
        yield PASS, "OK"
예제 #3
0
def com_google_fonts_check_mandatory_glyphs(ttFont):
  """Font contains .notdef as first glyph?

  The OpenType specification v1.8.2 recommends that the first glyph is the
  .notdef glyph without a codepoint assigned and with a drawing.

  https://docs.microsoft.com/en-us/typography/opentype/spec/recom#glyph-0-the-notdef-glyph

  Pre-v1.8, it was recommended that a font should also contain a .null, CR and
  space glyph. This might have been relevant for applications on MacOS 9.
  """
  from fontbakery.utils import glyph_has_ink

  if (
    ttFont.getGlyphOrder()[0] == ".notdef"
    and ".notdef" not in ttFont.getBestCmap().values()
    and glyph_has_ink(ttFont, ".notdef")
  ):
    yield PASS, (
      "Font contains the .notdef glyph as the first glyph, it does "
      "not have a Unicode value assigned and contains a drawing."
    )
  else:
    yield WARN, (
      "Font should contain the .notdef glyph as the first glyph, "
      "it should not have a Unicode value assigned and should "
      "contain a drawing."
    )
예제 #4
0
def com_google_fonts_check_mandatory_glyphs(ttFont):
  """Font contains .notdef as first glyph?

  The OpenType specification v1.8.2 recommends that the first glyph is the
  .notdef glyph without a codepoint assigned and with a drawing.

  https://docs.microsoft.com/en-us/typography/opentype/spec/recom#glyph-0-the-notdef-glyph

  Pre-v1.8, it was recommended that a font should also contain a .null, CR and
  space glyph. This might have been relevant for applications on MacOS 9.
  """
  from fontbakery.utils import glyph_has_ink

  if (
    ttFont.getGlyphOrder()[0] == ".notdef"
    and ".notdef" not in ttFont.getBestCmap().values()
    and glyph_has_ink(ttFont, ".notdef")
  ):
    yield PASS, (
      "Font contains the .notdef glyph as the first glyph, it does "
      "not have a Unicode value assigned and contains a drawing."
    )
  else:
    yield WARN, (
      "Font should contain the .notdef glyph as the first glyph, "
      "it should not have a Unicode value assigned and should "
      "contain a drawing."
    )
예제 #5
0
def test_glyph_has_ink():
  from fontbakery.utils import glyph_has_ink
  from fontTools.ttLib import TTFont

  print()  # so next line doesn't start with '.....'

  cff_test_font = TTFont(
    'data/test/source-sans-pro/OTF/SourceSansPro-Regular.otf')
  print('Test if CFF glyph with ink has ink')
  assert(glyph_has_ink(cff_test_font, '.notdef') is True)
  print('Test if CFF glyph without ink has ink')
  assert(glyph_has_ink(cff_test_font, 'space') is False)

  ttf_test_font = TTFont(
    'data/test/source-sans-pro/TTF/SourceSansPro-Regular.ttf')
  print('Test if TTF glyph with ink has ink')
  assert(glyph_has_ink(ttf_test_font, '.notdef') is True)
  print('Test if TTF glyph without ink has ink')
  assert(glyph_has_ink(ttf_test_font, 'space') is False)
예제 #6
0
def com_google_fonts_check_mandatory_glyphs(ttFont):
    """Font contains .notdef as first glyph?"""
    from fontbakery.utils import glyph_has_ink

    if (ttFont.getGlyphOrder()[0] == ".notdef"
            and ".notdef" not in ttFont.getBestCmap().values()
            and glyph_has_ink(ttFont, ".notdef")):
        yield PASS, (
            "Font contains the .notdef glyph as the first glyph, it does "
            "not have a Unicode value assigned and contains a drawing.")
    else:
        yield WARN, (
            "Font should contain the .notdef glyph as the first glyph, "
            "it should not have a Unicode value assigned and should "
            "contain a drawing.")
예제 #7
0
def com_google_fonts_check_049(ttFont):
    """Whitespace glyphs have ink?"""
    from fontbakery.utils import get_glyph_name, glyph_has_ink

    # code-points for all "whitespace" chars:
    WHITESPACE_CHARACTERS = [
        0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x0020, 0x0085, 0x00A0, 0x1680,
        0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008,
        0x2009, 0x200A, 0x2028, 0x2029, 0x202F, 0x205F, 0x3000, 0x180E, 0x200B,
        0x2060, 0xFEFF
    ]
    failed = False
    for codepoint in WHITESPACE_CHARACTERS:
        g = get_glyph_name(ttFont, codepoint)
        if g is not None and glyph_has_ink(ttFont, g):
            failed = True
            yield FAIL, ("Glyph \"{}\" has ink."
                         " It needs to be replaced by"
                         " an empty glyph.").format(g)
    if not failed:
        yield PASS, "There is no whitespace glyph with ink."
예제 #8
0
def com_google_fonts_check_whitespace_ink(ttFont):
  """Whitespace glyphs have ink?"""
  from fontbakery.utils import get_glyph_name, glyph_has_ink

  # code-points for all "whitespace" chars:
  WHITESPACE_CHARACTERS = [
      0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x0020, 0x0085, 0x00A0, 0x1680,
      0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008,
      0x2009, 0x200A, 0x2028, 0x2029, 0x202F, 0x205F, 0x3000, 0x180E, 0x200B,
      0x2060, 0xFEFF
  ]
  failed = False
  for codepoint in WHITESPACE_CHARACTERS:
    g = get_glyph_name(ttFont, codepoint)
    if g is not None and glyph_has_ink(ttFont, g):
      failed = True
      yield FAIL, ("Glyph \"{}\" has ink."
                   " It needs to be replaced by"
                   " an empty glyph.").format(g)
  if not failed:
    yield PASS, "There is no whitespace glyph with ink."
예제 #9
0
def test_glyph_has_ink():
  from fontbakery.utils import glyph_has_ink
  from fontTools.ttLib import TTFont

  print()  # so next line doesn't start with '.....'

  cff_test_font = TTFont(TEST_FILE("source-sans-pro/OTF/SourceSansPro-Regular.otf"))
  print('Test if CFF glyph with ink has ink')
  assert(glyph_has_ink(cff_test_font, '.notdef') is True)
  print('Test if CFF glyph without ink has ink')
  assert(glyph_has_ink(cff_test_font, 'space') is False)

  ttf_test_font = TTFont(TEST_FILE("source-sans-pro/TTF/SourceSansPro-Regular.ttf"))
  print('Test if TTF glyph with ink has ink')
  assert(glyph_has_ink(ttf_test_font, '.notdef') is True)
  print('Test if TTF glyph without ink has ink')
  assert(glyph_has_ink(ttf_test_font, 'space') is False)

  cff2_test_font = TTFont(TEST_FILE("source-sans-pro/VAR/SourceSansVariable-Roman.otf"))
  print('Test if CFF2 glyph with ink has ink')
  assert(glyph_has_ink(cff2_test_font, '.notdef') is True)
  print('Test if CFF2 glyph without ink has ink')
  assert(glyph_has_ink(cff2_test_font, 'space') is False)