How to use the fontbakery.callable.check function in fontbakery

To help you get started, we’ve selected a few fontbakery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googlefonts / fontbakery / Lib / fontbakery / specifications / googlefonts.py View on Github external
@check(
  id = 'com.google.fonts/check/070'
)
def com_google_fonts_check_070(ttFont):
  """Font has all expected currency sign characters?"""

  def font_has_char(ttFont, codepoint):
    for subtable in ttFont['cmap'].tables:
      if codepoint in subtable.cmap:
        return True
    #otherwise
    return False

  failed = False

  OPTIONAL = {
    #TODO: Do we want to check for this one?
github googlefonts / fontbakery / Lib / fontbakery / profiles / universal.py View on Github external
@check(
  id = 'com.google.fonts/check/mandatory_glyphs',
  rationale = """
    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.
  """
)
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()
github googlefonts / fontbakery / Lib / fontbakery / profiles / name.py View on Github external
@check(
  id = 'com.adobe.fonts/check/family/max_4_fonts_per_family_name',
  rationale = """
    Per the OpenType spec:
    'The Font Family name ... should be shared among at most four fonts that differ only in weight or style ...'
  """,
)
def com_adobe_fonts_check_family_max_4_fonts_per_family_name(ttFonts):
  """Verify that each group of fonts with the same nameID 1
  has maximum of 4 fonts"""
  from collections import Counter
  from fontbakery.utils import get_name_entry_strings

  family_names = list()
  for ttFont in ttFonts:
    names_list = get_name_entry_strings(ttFont,
                                        NameID.FONT_FAMILY_NAME,
github googlefonts / fontbakery / Lib / fontbakery / profiles / post.py View on Github external
@check(
  id = 'com.google.fonts/check/post_table_version'
)
def com_google_fonts_check_post_table_version(ttFont, is_ttf):
  """Font has correct post table version (2 for TTF, 3 for OTF)?"""
  formatType = ttFont['post'].formatType
  if is_ttf:
    expected = 2
  else:
    expected = 3
  if formatType != expected:
    yield FAIL, ("Post table should be version {} instead of {}."
                 " More info at https://github.com/google/fonts/"
                 "issues/215").format(expected, formatType)
  else:
    yield PASS, f"Font has post table version {expected}."
github googlefonts / fontbakery / Lib / fontbakery / specifications / googlefonts.py View on Github external
@check(
  id = 'com.google.fonts/check/varfont/has_MVAR',
  rationale = """
  Per the OpenType spec, the MVAR tables contain
  variation data for metadata otherwise in tables
  such as OS/2 and hhea; if not present, then
  the default values in those tables will apply
  to all instances, which can effect text layout.

  Thus, MVAR tables should be present and correct
  in all variable fonts since text layout software
  depends on these values.
  """, # FIX-ME: Clarify this rationale text.
       #         See: https://github.com/googlefonts/fontbakery/issues/2118#issuecomment-432108560
  conditions = ['is_variable_font'],
  misc_metadata = {
    'request': 'https://github.com/googlefonts/fontbakery/issues/2118'
github googlefonts / fontbakery / Lib / fontbakery / profiles / fvar.py View on Github external
@check(
  id = 'com.google.fonts/check/varfont/wght_valid_range',
  rationale = """
    According to the Open-Type spec's registered design-variation tag 'wght' available at https://docs.microsoft.com/en-gb/typography/opentype/spec/dvaraxistag_wght

    On the 'wght' (Weight) axis, the valid coordinate range is 1-1000.
  """,
  conditions = ['is_variable_font'],
  misc_metadata = {
    'request': 'https://github.com/googlefonts/fontbakery/issues/2264'
  }
)
def com_google_fonts_check_varfont_wght_valid_range(ttFont):
  """The variable font 'wght' (Weight) axis coordinate
     must be within spec range of 1 to 1000 on all instances."""

  Failed = False
github googlefonts / fontbakery / Lib / fontbakery / specifications / googlefonts.py View on Github external
@check(
  id = 'com.google.fonts/check/varfont/has_HVAR',
  rationale = """
  Not having a HVAR table can lead to costly
  text-layout operations on some platforms,
  which we want to avoid.

  So, all variable fonts on the Google Fonts
  collection should have an HVAR with valid values.

  More info on the HVAR table can be found at:
  https://docs.microsoft.com/en-us/typography/opentype/spec/otvaroverview#variation-data-tables-and-miscellaneous-requirements
  """, # FIX-ME: We should clarify which are these
       #         platforms in which there can be issues
       #         with costly text-layout operations
       #         when an HVAR table is missing!
  conditions = ['is_variable_font'],
github googlefonts / fontbakery / Lib / fontbakery / profiles / fvar.py View on Github external
@check(
  id = 'com.google.fonts/check/varfont/regular_ital_coord',
  rationale = """
    According to the Open-Type spec's registered design-variation tag 'ital' available at https://docs.microsoft.com/en-gb/typography/opentype/spec/dvaraxistag_ital

    If a variable font has a 'ital' (Italic) axis, then the coordinate of its 'Regular' instance is required to be zero.
  """,
  conditions = ['is_variable_font',
                'regular_ital_coord'],
  misc_metadata = {
    'request': 'https://github.com/googlefonts/fontbakery/issues/1707'
  }
)
def com_google_fonts_check_varfont_regular_ital_coord(ttFont, regular_ital_coord):
  """The variable font 'ital' (Italic) axis coordinate must be zero on the
  'Regular' instance."""
github googlefonts / fontbakery / Lib / fontbakery / profiles / gpos.py View on Github external
@check(
  id = 'com.google.fonts/check/gpos_kerning_info'
)
def com_google_fonts_check_gpos_kerning_info(ttFont):
  """Does GPOS table have kerning information?"""
  if not has_kerning_info(ttFont):
    yield WARN,\
          Message("lacks-kern-info",
                  "GPOS table lacks kerning information.")
  else:
    yield PASS, "GPOS table has got kerning information."
github googlefonts / fontbakery / Lib / fontbakery / profiles / adobefonts.py View on Github external
@check(
  id = 'com.adobe.fonts/check/find_empty_letters',
  rationale = """
    Font language, script, and character set tagging approaches typically have an underlying assumption that letters (i.e. characters with Unicode general category 'Ll', 'Lm', 'Lo', 'Lt', or 'Lu', which includes CJK ideographs and Hangul syllables) with entries in the 'cmap' table have glyphs with ink (with a few exceptions, notably the Hangul "filler" characters).

    This check is intended to identify fonts in which such letters have been mapped to empty glyphs (typically done as a form of subsetting). Letters with empty glyphs should have their entries removed from the 'cmap' table, even if the empty glyphs are left in place (e.g. for CID consistency).
  """
)
def com_adobe_fonts_check_find_empty_letters(ttFont):
    """Letters in font have glyphs that are not empty?"""
    cmap = ttFont.getBestCmap()
    passed = True

    # http://unicode.org/reports/tr44/#General_Category_Values
    letter_categories = {
        'Ll', 'Lm', 'Lo', 'Lt', 'Lu',
    }