How to use the fontbakery.checkrunner.WARN 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 / profiles / gdef.py View on Github external
elif "GDEF" not in ttFont:
    yield WARN, Message("GDEF-missing",
                        ("GDEF table is missing, but it is mandatory"
                         " to declare it on fonts that provide ligature"
                         " glyphs because the caret (text cursor)"
                         " positioning for each ligature must be"
                         " provided in this table."))
  else:
    lig_caret_list = ttFont["GDEF"].table.LigCaretList
    if lig_caret_list is None:
      missing = set(ligature_glyphs)
    else:
      missing = set(ligature_glyphs) - set(lig_caret_list.Coverage.glyphs)

    if lig_caret_list is None or lig_caret_list.LigGlyphCount == 0:
      yield WARN, Message("lacks-caret-pos",
                          ("This font lacks caret position values for"
                           " ligature glyphs on its GDEF table."))
    elif missing:
      missing = "\n\t- ".join(missing)
      yield WARN, Message("incomplete-caret-pos-data",
                          ("This font lacks caret positioning"
                           " values for these ligature glyphs:"
                           f"\n\t- {missing}\n\n  "))
    else:
      yield PASS, "Looks good!"
github googlefonts / fontbakery / Lib / fontbakery / profiles / fontval.py View on Github external
except ValueError:
          pass

    # And, finally, the log messages are emitted:
    if data["errortype"] == "P":
      yield PASS, report_message(msg, data["details"])

    elif data["errortype"] == "E":
      status = FAIL
      for substring in downgrade_to_warn:
        if substring in msg:
          status = WARN
      yield status, report_message(msg, data["details"])

    elif data["errortype"] == "W":
      yield WARN, report_message(msg, data["details"])

    else:
      yield INFO, report_message(msg, data["details"])
github googlefonts / fontbakery / Lib / fontbakery / profiles / fvar.py View on Github external
def com_google_fonts_check_varfont_regular_opsz_coord(ttFont, regular_opsz_coord):
  """The variable font 'opsz' (Optical Size) axis coordinate should be between
  9 and 13 on the 'Regular' instance."""

  if regular_opsz_coord >= 9 and regular_opsz_coord <= 13:
    yield PASS, ("Regular:opsz coordinate ({regular_opsz_coord}) looks good.")
  else:
    yield WARN,\
          Message("out-of-range",
                  f'The "opsz" (Optical Size) coordinate'
                  f' on the "Regular" instance is recommended'
github googlefonts / fontbakery / Lib / fontbakery / profiles / hhea.py View on Github external
def com_google_fonts_check_linegaps(ttFont):
  """Checking Vertical Metric Linegaps."""
  if ttFont["hhea"].lineGap != 0:
    yield WARN,\
          Message("hhea",
                  "hhea lineGap is not equal to 0.")
  elif ttFont["OS/2"].sTypoLineGap != 0:
    yield WARN,\
          Message("OS/2",
                  "OS/2 sTypoLineGap is not equal to 0.")
  else:
    yield PASS, "OS/2 sTypoLineGap and hhea lineGap are both 0."
github googlefonts / fontbakery / Lib / fontbakery / profiles / name.py View on Github external
def com_google_fonts_check_name_rfn(ttFont):
  """Name table strings must not contain the string 'Reserved Font Name'."""
  failed = False
  for entry in ttFont["name"].names:
    string = entry.toUnicode()
    if "reserved font name" in string.lower():
      yield WARN,\
            Message("rfn",
                    f'Name table entry ("{string}")'
                    f' contains "Reserved Font Name".'
                    f' This is an error except in a few specific rare cases.')
      failed = True
  if not failed:
    yield PASS, ('None of the name table strings'
                 ' contain "Reserved Font Name".')
github googlefonts / fontbakery / Lib / fontbakery / profiles / os2.py View on Github external
difference = abs(current_value - expected_value)

  # We accept matches and off-by-ones due to rounding as correct.
  if current_value == expected_value or difference == 1:
    yield PASS, "OS/2 xAvgCharWidth value is correct."
  elif difference < ACCEPTABLE_ERROR:
    yield INFO, (f"OS/2 xAvgCharWidth is {current_value} but it should be"
                 f" {expected_value} which corresponds to {calculation_rule}."
                 f" These are similar values, which"
                 f" may be a symptom of the slightly different"
                 f" calculation of the xAvgCharWidth value in"
                 f" font editors. There's further discussion on"
                 f" this at https://github.com/googlefonts/fontbakery"
                 f"/issues/1622")
  else:
    yield WARN, (f"OS/2 xAvgCharWidth is {current_value} but it should be"
                 f" {expected_value} which corresponds to {calculation_rule}.")
github googlefonts / fontbakery / Lib / fontbakery / profiles / universal.py View on Github external
def com_google_fonts_check_ftxvalidator_is_available(ftxvalidator_is_available):
  """Is the command `ftxvalidator` (Apple Font Tool Suite) available?"""
  if ftxvalidator_is_available:
    return PASS, "ftxvalidator is available."
  else:
    return WARN, "ftxvalidator is not available."
github googlefonts / fontbakery / Lib / fontbakery / profiles / adobefonts.py View on Github external
passed = False
    if passed:
        yield PASS, "No empty glyphs for letters found."


# ToDo: add many more checks...

profile.auto_register(globals())

com_google_fonts_check_dsig_adobefonts = profile.check_log_override(
    'com.google.fonts/check/dsig'
  , reason='For Adobe this issue is not as severe '\
            + 'as assessed in the original check.'
  , overrides = (
        (   'lacks-signature' # override_target -> a specific Message.code (string)
          , WARN # new_status -> None: keep old status
          , None # new_message_string -> None: keep old message
          )
    ,)
)

com_google_fonts_check_whitespace_glyphs_adobefonts = profile.check_log_override(
    'com.google.fonts/check/whitespace_glyphs'
  , overrides = (('missing-whitespace-glyphs', WARN, None),)
)

com_google_fonts_check_valid_glyphnames_adobefonts = profile.check_log_override(
    'com.google.fonts/check/valid_glyphnames'
  , overrides = (('found-invalid-names', WARN, None),)
)

profile.test_expected_checks(ADOBEFONTS_PROFILE_CHECKS, exclusive=True)
github googlefonts / fontbakery / Lib / fontbakery / profiles / ufo_sources.py View on Github external
def com_daltonmaag_check_recommended_fields(ufo_font):
  """Check that recommended fields are present in the UFO fontinfo."""
  recommended_fields = []

  for field in [
      "postscriptUnderlineThickness", "postscriptUnderlinePosition",
      "versionMajor", "versionMinor", "styleName", "copyright",
      "openTypeOS2Panose"
  ]:
    if ufo_font.info.__dict__.get("_" + field) is None:
      recommended_fields.append(field)

  if recommended_fields:
    yield WARN, f"Recommended field(s) missing: {recommended_fields}"
  else:
    yield PASS, "Recommended fields present."
github googlefonts / fontbakery / Lib / fontbakery / profiles / glyf.py View on Github external
out_of_bounds = []
  for glyphName in ttFont['glyf'].keys():
    glyph = ttFont['glyf'][glyphName]
    coords = glyph.getCoordinates(ttFont['glyf'])[0]
    for x, y in coords:
      if round(x) < glyph.xMin or round(x) > glyph.xMax or \
         round(y) < glyph.yMin or round(y) > glyph.yMax or \
         abs(x) > 32766 or abs(y) > 32766:
        failed = True
        out_of_bounds.append((glyphName, x, y))

  if failed:
    formatted_list = "\t* " + pretty_print_list(out_of_bounds,
                                                shorten=10,
                                                sep="\n\t* ")
    yield WARN,\
          Message("points-out-of-bounds",
                  f"The following glyphs have coordinates"
                  f" which are out of bounds:\n"
                  f"{formatted_list}\n"
                  f"\n"
                  f"This happens a lot when points are not extremes,"
                  f" which is usually bad. However, fixing this alert"
                  f" by adding points on extremes may do more harm"
                  f" than good, especially with italics,"
                  f" calligraphic-script, handwriting, rounded and"
                  f" other fonts. So it is common to ignore this message.")
  else:
    yield PASS, "All glyph paths have coordinates within bounds!"