How to use the fontbakery.constants.PlatformID 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 / name.py View on Github external
def com_google_fonts_check_name_line_breaks(ttFont):
  """Name table entries should not contain line-breaks."""
  failed = False
  for name in ttFont["name"].names:
    string = name.string.decode(name.getEncoding())
    if "\n" in string:
      failed = True
      yield FAIL,\
            Message("line-break",
                    f"Name entry {NameID(name.nameID).name}"
                    f" on platform {PlatformID(name.platformID).name}"
                    f" contains a line-break.")
  if not failed:
    yield PASS, ("Name table entries are all single-line"
                 " (no line-breaks found).")
github googlefonts / fontbakery / Lib / fontbakery / utils.py View on Github external
def get_font_glyph_data(font):
    """Return information for each glyph in a font"""
    from fontbakery.constants import (PlatformID,
                                      WindowsEncodingID)
    font_data = []

    try:
        subtable = font['cmap'].getcmap(PlatformID.WINDOWS,
                                        WindowsEncodingID.UNICODE_BMP)
        if not subtable:
          # Well... Give it a chance here...
          # It may be using a different Encoding_ID value
          subtable = font['cmap'].tables[0]

        cmap = subtable.cmap
    except:
        return None

    cmap_reversed = dict(zip(cmap.values(), cmap.keys()))

    for glyph_name in font.getGlyphSet().keys():
        if glyph_name in cmap_reversed:
            uni_glyph = cmap_reversed[glyph_name]
            contours = glyph_contour_count(font, glyph_name)
github googlefonts / fontbakery / Lib / fontbakery / profiles / name.py View on Github external
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,
                                        PlatformID.WINDOWS,
                                        WindowsEncodingID.UNICODE_BMP,
                                        WindowsLanguageID.ENGLISH_USA)
    # names_list may contain multiple entries.
    # We use set() below to remove the duplicates and only store
    # the unique family name(s) used for a given font
    names_set = set(names_list)
    family_names.extend(names_set)

  passed = True
  counter = Counter(family_names)
  for family_name, count in counter.items():
    if count > 4:
      passed = False
      yield FAIL,\
            Message("too-many",
                    f"Family '{family_name}' has {count} fonts"
github googlefonts / fontbakery / Lib / fontbakery / utils.py View on Github external
def name_entry_id(name):
  from fontbakery.constants import (NameID,
                                    PlatformID)
  return "[{}({}):{}({})]".format(NameID(name.nameID).name,
                                  name.nameID,
                                  PlatformID(name.platformID).name,
                                  name.platformID)
github googlefonts / fontbakery / Lib / fontbakery / specifications / googlefonts.py View on Github external
if nameRecord.nameID == NameID.LICENSE_DESCRIPTION:
      entry_found = True
      value = nameRecord.toUnicode()
      if value != placeholder:
        failed = True
        yield FAIL, Message("wrong", \
                            ("License file {} exists but"
                             " NameID {} (LICENSE DESCRIPTION) value"
                             " on platform {} ({})"
                             " is not specified for that."
                             " Value was: \"{}\""
                             " Must be changed to \"{}\""
                             "").format(license,
                                        NameID.LICENSE_DESCRIPTION,
                                        nameRecord.platformID,
                                        PlatformID(nameRecord.platformID).name,
                                        unidecode(value),
                                        unidecode(placeholder)))
  if not entry_found:
    yield FAIL, Message("missing", \
                        ("Font lacks NameID {} "
                         "(LICENSE DESCRIPTION). A proper licensing entry"
                         " must be set.").format(NameID.LICENSE_DESCRIPTION))
  elif not failed:
    yield PASS, "Licensing entry on name table is correctly set."
github googlefonts / fontbakery / Lib / fontbakery / specifications / googlefonts.py View on Github external
def com_google_fonts_check_158(ttFont,
                               style_with_spaces,
                               familyname_with_spaces):
  """ Check name table: FONT_SUBFAMILY_NAME entries. """
  from fontbakery.utils import name_entry_id

  failed = False
  for name in ttFont['name'].names:
    if name.nameID == NameID.FONT_SUBFAMILY_NAME:
      if name.platformID == PlatformID.MACINTOSH:
        expected_value = style_with_spaces

      elif name.platformID == PlatformID.WINDOWS:
        if style_with_spaces in ["Bold", "Bold Italic"]:
          expected_value = style_with_spaces
        else:
          if "Italic" in style_with_spaces:
            expected_value = "Italic"
          else:
            expected_value = "Regular"
      else:
        yield FAIL, Message("invalid-entry",
                            ("Font should not have a "
                             "{} entry!").format(name_entry_id(name)))
        failed = True
        continue

      string = name.string.decode(name.getEncoding()).strip()
      if string != expected_value: