name
: Naming Table
- class fontTools.ttLib.tables._n_a_m_e.NameRecord[source]
Bases:
object
- getEncoding(default='ascii')[source]
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.
- toBytes(errors='strict')[source]
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='strict')
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.
- toUnicode(errors='strict')[source]
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.
- class fontTools.ttLib.tables._n_a_m_e.NameRecordVisitor[source]
Bases:
TTVisitor
- TABLES = ('GSUB', 'GPOS', 'fvar', 'CPAL', 'STAT')
- defaultStop = False
- classmethod register(clazzes)
- classmethod register_attr(clazzes, attrs)
- classmethod register_attrs(clazzes_attrs)
- visit(obj, *args, **kwargs)
This is the main entry to the visitor. The visitor will visit object obj.
The visitor will first determine if there is a registered (via @register()) visit function for the type of object. If there is, it will be called, and (visitor, obj, *args, **kwargs) will be passed to the user visit function.
If there is no user-registered visit function, of if there is and it returns True, or it returns None (or doesn’t return anything) and visitor.defaultStop is False (default), then the visitor will proceed to dispatch to one of self.visitObject(), self.visitList(), self.visitDict(), or self.visitLeaf() (any of which can be overriden in a subclass).
- visitAttr(obj, attr, value, *args, **kwargs)
Called to visit an attribute of an object.
- visitDict(obj, *args, **kwargs)
Called to visit any value that is a dictionary.
- visitLeaf(obj, *args, **kwargs)
Called to visit any value that is not an object, list, or dictionary.
- visitList(obj, *args, **kwargs)
Called to visit any value that is a list.
- visitObject(obj, *args, **kwargs)
Called to visit an object. This function loops over all non-private attributes of the objects and calls any user-registered (via @register_attr() or @register_attrs()) visit() functions.
If there is no user-registered visit function, of if there is and it returns True, or it returns None (or doesn’t return anything) and visitor.defaultStop is False (default), then the visitor will proceed to call self.visitAttr()
- class fontTools.ttLib.tables._n_a_m_e.table__n_a_m_e(tag=None)[source]
Bases:
DefaultTable
- addMultilingualName(names, ttFont=None, nameID=None, windows=True, mac=True, minNameID=0)[source]
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)[source]
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.
- dependencies = ['ltag']
- findMultilingualName(names, windows=True, mac=True, minNameID=0, ttFont=None)[source]
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.
- merge(m, tables)
- mergeMap = {'names': <function first>, 'tableTag': <function equal>}
- prune_post_subset(font, options)
- removeNames(nameID=None, platformID=None, platEncID=None, langID=None)[source]
Remove any name records identified by the given combination of ‘nameID’, ‘platformID’, ‘platEncID’ and ‘langID’.
- static removeUnusedNames(ttFont)[source]
Remove any name records which are not in NameID range 0-255 and not utilized within the font itself.
- setName(string, nameID, platformID, platEncID, langID)[source]
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.