# `name`: Naming table

The `name` table is an OpenType table.

class fontTools.ttLib.tables._n_a_m_e.table__n_a_m_e(tag=None)

  Bases: `DefaultTable`

  Naming table

  The `name` table is used to store a variety of strings that can be associated with user-facing font information. Records in the `name` table can be tagged with language tags to support multilingual naming and can support platform-specific character-encoding variants.

  See also https://learn.microsoft.com/en-us/typography/opentype/spec/name

  dependencies = ['ltag']
  decompile(data, ttFont)
  compile(ttFont)
  toXML(writer, ttFont)
  fromXML(name, attrs, content, ttFont)
  getName(nameID: int, platformID: int, platEncID: int, langID: int | None = None) → NameRecord | None
  getDebugName(nameID: int) → str | None
  getFirstDebugName(nameIDs)
  getBestFamilyName()
  getBestSubFamilyName()
  getBestFullName()
  setName(string, nameID, platformID, platEncID, langID)

    Set the ‘string’ for the name record identified by ‘nameID’, ‘platformID’, ‘platEncID’ and ‘langID’. If a record with that nameID doesn’t exist, create it and append to the name table.

    ‘string’ can be of type str (unicode in PY2) or bytes. In the latter case, it is assumed to be already encoded with the correct plaform-specific encoding identified by the (platformID, platEncID, langID) triplet. A warning is issued to prevent unexpected results.

  removeNames(nameID=None, platformID=None, platEncID=None, langID=None)

    Remove any name records identified by the given combination of ‘nameID’, ‘platformID’, ‘platEncID’ and ‘langID’.

  static removeUnusedNames(ttFont)

    Remove any name records which are not in NameID range 0-255 and not utilized within the font itself.

  findMultilingualName(names, windows=True, mac=True, minNameID=0, ttFont=None)

    Return the name ID of an existing multilingual name that matches the ‘names’ dictionary, or None if not found.

    ‘names’ is a dictionary with the name in multiple languages, such as {‘en’: ‘Pale’, ‘de’: ‘Blaß’, ‘de-CH’: ‘Blass’}. The keys can be arbitrary IETF BCP 47 language codes; the values are Unicode strings.

    If ‘windows’ is True, the returned name ID is guaranteed exist for all requested languages for platformID=3 and platEncID=1. If ‘mac’ is True, the returned name ID is guaranteed to exist for all requested languages for platformID=1 and platEncID=0.

    The returned name ID will not be less than the ‘minNameID’ argument.

  addMultilingualName(names, ttFont=None, nameID=None, windows=True, mac=True, minNameID=0)

    Add a multilingual name, returning its name ID

    ‘names’ is a dictionary with the name in multiple languages, such as {‘en’: ‘Pale’, ‘de’: ‘Blaß’, ‘de-CH’: ‘Blass’}. The keys can be arbitrary IETF BCP 47 language codes; the values are Unicode strings.

    ‘ttFont’ is the TTFont to which the names are added, or None. If present, the font’s ‘ltag’ table can get populated to store exotic language codes, which allows encoding names that otherwise cannot get encoded at all.

    ‘nameID’ is the name ID to be used, or None to let the library find an existing set of name records that match, or pick an unused name ID.

    If ‘windows’ is True, a platformID=3 name record will be added. If ‘mac’ is True, a platformID=1 name record will be added.

    If the ‘nameID’ argument is None, the created nameID will not be less than the ‘minNameID’ argument.

  addName(string, platforms=((1, 0, 0), (3, 1, 1033)), minNameID=255)

    Add a new name record containing ‘string’ for each (platformID, platEncID, langID) tuple specified in the ‘platforms’ list.

    The nameID is assigned in the range between ‘minNameID’+1 and 32767 (inclusive), following the last nameID in the name table. If no ‘platforms’ are specified, two English name records are added, one for the Macintosh (platformID=0), and one for the Windows platform (3).

    The ‘string’ must be a Unicode string, so it can be encoded with different, platform-specific encodings.

    Return the new nameID.

  mergeMap = {'names': <function first>, 'tableTag': <function equal>}
  prune_post_subset(font, options)

fontTools.ttLib.tables._n_a_m_e.makeName(string, nameID, platformID, platEncID, langID)

class fontTools.ttLib.tables._n_a_m_e.NameRecord

  Bases: `object`

  getEncoding(default='ascii')

    Returns the Python encoding name for this name entry based on its platformID, platEncID, and langID. If encoding for these values is not known, by default ‘ascii’ is returned. That can be overriden by passing a value to the default argument.

  encodingIsUnicodeCompatible()
  isUnicode()
  toUnicode(errors: str = 'strict') → str

    If self.string is a Unicode string, return it; otherwise try decoding the bytes in self.string to a Unicode string using the encoding of this entry as returned by self.getEncoding(); Note that self.getEncoding() returns ‘ascii’ if the encoding is unknown to the library.

    Certain heuristics are performed to recover data from bytes that are ill-formed in the chosen encoding, or that otherwise look misencoded (mostly around bad UTF-16BE encoded bytes, or bytes that look like UTF-16BE but marked otherwise). If the bytes are ill-formed and the heuristics fail, the error is handled according to the errors parameter to this function, which is passed to the underlying decode() function; by default it throws a UnicodeDecodeError exception.

    Note: The mentioned heuristics mean that roundtripping a font to XML and back to binary might recover some misencoded data whereas just loading the font and saving it back will not change them.

  toBytes(errors='strict')

    If self.string is a bytes object, return it; otherwise try encoding the Unicode string in self.string to bytes using the encoding of this entry as returned by self.getEncoding(); Note that self.getEncoding() returns ‘ascii’ if the encoding is unknown to the library.

    If the Unicode string cannot be encoded to bytes in the chosen encoding, the error is handled according to the errors parameter to this function, which is passed to the underlying encode() function; by default it throws a UnicodeEncodeError exception.

  toStr(errors: str = 'strict') → str

    If self.string is a Unicode string, return it; otherwise try decoding the bytes in self.string to a Unicode string using the encoding of this entry as returned by self.getEncoding(); Note that self.getEncoding() returns ‘ascii’ if the encoding is unknown to the library.

    Certain heuristics are performed to recover data from bytes that are ill-formed in the chosen encoding, or that otherwise look misencoded (mostly around bad UTF-16BE encoded bytes, or bytes that look like UTF-16BE but marked otherwise). If the bytes are ill-formed and the heuristics fail, the error is handled according to the errors parameter to this function, which is passed to the underlying decode() function; by default it throws a UnicodeDecodeError exception.

    Note: The mentioned heuristics mean that roundtripping a font to XML and back to binary might recover some misencoded data whereas just loading the font and saving it back will not change them.

  toXML(writer, ttFont)
  fromXML(name, attrs, content, ttFont)

class fontTools.ttLib.tables._n_a_m_e.NameRecordVisitor

  Bases: `TTVisitor`

  TABLES = ('GSUB', 'GPOS', 'fvar', 'CPAL', 'STAT')