How to use the fontbakery.message.Message 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
font_fullname = get_name_entry_strings(ttFont, NameID.FULL_FONT_NAME)
    if len(font_familyname) == 0 or len(font_fullname) == 0:
      yield SKIP, ("Font lacks familyname and/or"
                   " fullname entries in name table.")
      # FIXME: This is the same SKIP condition as in check/106
      #        so we definitely need to address them with a common condition!
    else:
      font_familyname = font_familyname[0]
      font_fullname = font_fullname[0]

      if bool(ttFont["head"].macStyle & MacStyle.ITALIC):
        yield FAIL, Message("bad-macstyle",
                            ("METADATA.pb style has been set to normal"
                             " but font macStyle is improperly set."))
      elif font_familyname.split("-")[-1].endswith('Italic'):
        yield FAIL, Message("familyname-italic",
                            ("Font macStyle indicates a non-Italic font, but"
                             " nameID {} (FONT_FAMILY_NAME: \"{}\") ends with"
                             " \"Italic\".").format(NameID.FONT_FAMILY_NAME,
                                                    font_familyname))
      elif font_fullname.split("-")[-1].endswith("Italic"):
        yield FAIL, Message("fullfont-italic",
                            ("Font macStyle indicates a non-Italic font but"
                             " nameID {} (FULL_FONT_NAME: \"{}\") ends with"
                             " \"Italic\".").format(NameID.FULL_FONT_NAME,
                                                    font_fullname))
      else:
        yield PASS, ("METADATA.pb font.style \"normal\""
                     " matches font internals.")
github googlefonts / fontbakery / Lib / fontbakery / profiles / name.py View on Github external
def com_google_fonts_check_name_no_copyright_on_description(ttFont):
  """Description strings in the name table must not contain copyright info."""
  failed = False
  for name in ttFont['name'].names:
    if 'opyright' in name.string.decode(name.getEncoding())\
       and name.nameID == NameID.DESCRIPTION:
      failed = True

  if failed:
    yield FAIL,\
          Message("copyright-on-description",
                  f"Some namerecords with"
                  f" ID={NameID.DESCRIPTION} (NameID.DESCRIPTION)"
                  f" containing copyright info should be removed"
                  f" (perhaps these were added by a longstanding"
                  f" FontLab Studio 5.x bug that copied"
                  f" copyright notices to them.)")
  else:
    yield PASS, ("Description strings in the name table"
                 " do not contain any copyright string.")
github googlefonts / fontbakery / Lib / fontbakery / specifications / googlefonts.py View on Github external
def com_google_fonts_check_092(ttFont, font_metadata):
  """Checks METADATA.pb font.name field matches
     family name declared on the name table.
  """
  from fontbakery.utils import get_name_entry_strings

  familynames = get_name_entry_strings(ttFont, NameID.FONT_FAMILY_NAME)
  if len(familynames) == 0:
    yield FAIL, Message("missing",
                        ("This font lacks a FONT_FAMILY_NAME entry"
                         " (nameID={}) in the name"
                         " table.").format(NameID.FONT_FAMILY_NAME))
  else:
    if font_metadata.name not in familynames:
      yield FAIL, Message("mismatch",
                          ("Unmatched family name in font:"
                           " TTF has \"{}\" while METADATA.pb"
                           " has \"{}\"").format(familynames[0],
                                                 font_metadata.name))
    else:
      yield PASS, ("Family name \"{}\" is identical"
                   " in METADATA.pb and on the"
                   " TTF file.").format(font_metadata.name)
github googlefonts / fontbakery / Lib / fontbakery / profiles / name.py View on Github external
elif len(fullfontname) == 0:
    yield FAIL,\
          Message("no-full-font-name",
                  "Font lacks a NameID.FULL_FONT_NAME"
                  " entry in the 'name' table.")
  else:
    # we probably should check all found values are equivalent.
    # and, in that case, then performing the rest of the check
    # with only the first occurences of the name entries
    # will suffice:
    fullfontname = fullfontname[0]
    familyname = familyname[0]

    if not fullfontname.startswith(familyname):
      yield FAIL,\
            Message("does-not",
                    f"On the 'name' table, the full font name"
                    f" (NameID {NameID.FULL_FONT_NAME}"
                    f" - FULL_FONT_NAME: '{familyname}')"
                    f" does not begin with font family name"
                    f" (NameID {NameID.FONT_FAMILY_NAME}"
                    f" - FONT_FAMILY_NAME: '{fullfontname}')")
    else:
      yield PASS, "Full font name begins with the font family name."
github googlefonts / fontbakery / Lib / fontbakery / profiles / name.py View on Github external
def com_adobe_fonts_check_name_postscript_vs_cff(ttFont):
  """CFF table FontName must match name table ID 6 (PostScript name)."""
  cff_names = ttFont['CFF '].cff.fontNames
  if len(cff_names) != 1:
    yield ERROR, ("Unexpected number of font names in CFF table.")
    return

  passed = True
  cff_name = cff_names[0]
  for entry in ttFont['name'].names:
    if entry.nameID == NameID.POSTSCRIPT_NAME:
      postscript_name = entry.toUnicode()
      if postscript_name != cff_name:
        passed = False
        yield FAIL,\
              Message("mismatch",
                      f"Name table PostScript name '{postscript_name}' "
                      f"does not match CFF table FontName '{cff_name}'.")

  if passed:
    yield PASS, ("Name table PostScript name matches CFF table FontName.")
github googlefonts / fontbakery / Lib / fontbakery / profiles / cmap.py View on Github external
for ttFont in ttFonts:
    cmap = None
    for table in ttFont['cmap'].tables:
      if table.format == 4:
        cmap = table
        break
    # Could a font lack a format 4 cmap table ?
    # If we ever find one of those, it would crash the check here.
    # Then we'd have to yield a FAIL regarding the missing table entry.
    if not encoding:
      encoding = cmap.platEncID
    if encoding != cmap.platEncID:
      failed = True
  if failed:
    yield FAIL,\
          Message("mismatch",
                  "Fonts have different unicode encodings.")
  else:
    yield PASS, "Fonts have equal unicode encodings."
github googlefonts / fontbakery / Lib / fontbakery / specifications / googlefonts.py View on Github external
def com_google_fonts_check_108(ttFont, font_metadata):
  """METADATA.pb font.name and font.full_name fields match
     the values declared on the name table?
  """
  from fontbakery.utils import get_name_entry_strings

  font_familyname = get_name_entry_strings(ttFont, NameID.FONT_FAMILY_NAME)[0]
  font_fullname = get_name_entry_strings(ttFont, NameID.FULL_FONT_NAME)[0]
  # FIXME: common condition/name-id check as in the two previous checks.

  if font_fullname != font_metadata.full_name:
    yield FAIL, Message("fullname-mismatch",
                        ("METADATA.pb: Fullname (\"{}\")"
                         " does not match name table"
                         " entry \"{}\" !").format(font_metadata.full_name,
                                                   font_fullname))
  elif font_familyname != font_metadata.name:
    yield FAIL, Message("familyname-mismatch",
                        ("METADATA.pb Family name \"{}\")"
                         " does not match name table"
                         " entry \"{}\" !").format(font_metadata.name,
                                                   font_familyname))
  else:
    yield PASS, ("METADATA.pb familyname and fullName fields"
                 " match corresponding name table entries.")
github googlefonts / fontbakery / Lib / fontbakery / specifications / googlefonts.py View on Github external
def com_google_fonts_check_130(ttFont, style):
  """Checking post.italicAngle value."""
  failed = False
  value = ttFont["post"].italicAngle

  # Checking that italicAngle <= 0
  if value > 0:
    failed = True
    yield FAIL, Message("positive",
                        ("The value of post.italicAngle must be"
                         " changed from {} to {}.").format(value, -value))

  # Checking that italicAngle is less than 20 degrees:
  if abs(value) > 20:
    failed = True
    yield FAIL, Message(">20 degrees",
                        ("The value of post.italicAngle must be"
                         " changed from {} to -20.").format(value))

  # Checking if italicAngle matches font style:
  if "Italic" in style:
    if ttFont['post'].italicAngle == 0:
      failed = True
      yield FAIL, Message("zero-italic",
                          ("Font is italic, so post.italicAngle"
github googlefonts / fontbakery / Lib / fontbakery / profiles / glyf.py View on Github external
if diff < 0:
      yield FAIL,\
            Message("unreachable-data",
                    f"Glyf table has unreachable data at the end of the table."
                    f" Expected glyf table length {expected_glyphs} (from loca"
                    f" table), got length {actual_glyphs}"
                    f" (difference: {diff})")
    elif not diff:  # negative diff -> exception below
      yield PASS, "There is no unused data at the end of the glyf table."
    else:
      raise Exception("Bug: fontTools did not raise an expected exception.")
  except fontTools.ttLib.TTLibError as error:
    if "not enough 'glyf' table data" in format(error):
      yield FAIL,\
            Message("missing-data",
                    f"Loca table references data beyond"
                    f" the end of the glyf table."
                    f" Expected glyf table length {expected_glyphs}"
                    f" (from loca table).")
    else:
      raise Exception("Bug: Unexpected fontTools exception.")
github googlefonts / fontbakery / Lib / fontbakery / specifications / googlefonts.py View on Github external
" You should set it to your own 4 character code,"
    " and register that code with Microsoft at"
    " https://www.microsoft.com"
  "/typography/links/vendorlist.aspx")

  vid = ttFont['OS/2'].achVendID
  bad_vids = ['UKWN', 'ukwn', 'PfEd']
  if vid is None:
    yield FAIL, Message("not set", "OS/2 VendorID is not set." +
                                   SUGGEST_MICROSOFT_VENDORLIST_WEBSITE)
  elif vid in bad_vids:
    yield FAIL, Message("bad", ("OS/2 VendorID is '{}',"
                                " a font editor default.").format(vid) +
                                SUGGEST_MICROSOFT_VENDORLIST_WEBSITE)
  elif vid not in registered_vendor_ids.keys():
    yield WARN, Message("unknown", ("OS/2 VendorID value '{}' is not"
                                    " a known registered id.").format(vid) +
                                    SUGGEST_MICROSOFT_VENDORLIST_WEBSITE)
  else:
    yield PASS, f"OS/2 VendorID '{vid}' looks good!"