code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def keys(self): """Returns the list of tables in the font, along with the ``GlyphOrder`` pseudo-table.""" keys = list(self.tables.keys()) if self.reader: for key in list(self.reader.keys()): if key not in keys: keys.append(key) if "GlyphOr...
Returns the list of tables in the font, along with the ``GlyphOrder`` pseudo-table.
keys
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def ensureDecompiled(self, recurse=None): """Decompile all the tables, even if a TTFont was opened in 'lazy' mode.""" for tag in self.keys(): table = self[tag] if recurse is None: recurse = self.lazy is not False if recurse and hasattr(table, "ensureDe...
Decompile all the tables, even if a TTFont was opened in 'lazy' mode.
ensureDecompiled
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def get(self, tag, default=None): """Returns the table if it exists or (optionally) a default if it doesn't.""" try: return self[tag] except KeyError: return default
Returns the table if it exists or (optionally) a default if it doesn't.
get
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def setGlyphOrder(self, glyphOrder): """Set the glyph order Args: glyphOrder ([str]): List of glyph names in order. """ self.glyphOrder = glyphOrder if hasattr(self, "_reverseGlyphOrderDict"): del self._reverseGlyphOrderDict if self.isLoaded("...
Set the glyph order Args: glyphOrder ([str]): List of glyph names in order.
setGlyphOrder
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def getGlyphOrder(self): """Returns a list of glyph names ordered by their position in the font.""" try: return self.glyphOrder except AttributeError: pass if "CFF " in self: cff = self["CFF "] self.glyphOrder = cff.getGlyphOrder() ...
Returns a list of glyph names ordered by their position in the font.
getGlyphOrder
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def getGlyphName(self, glyphID): """Returns the name for the glyph with the given ID. If no name is available, synthesises one with the form ``glyphXXXXX``` where ```XXXXX`` is the zero-padded glyph ID. """ try: return self.getGlyphOrder()[glyphID] except Ind...
Returns the name for the glyph with the given ID. If no name is available, synthesises one with the form ``glyphXXXXX``` where ```XXXXX`` is the zero-padded glyph ID.
getGlyphName
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def getGlyphNameMany(self, lst): """Converts a list of glyph IDs into a list of glyph names.""" glyphOrder = self.getGlyphOrder() cnt = len(glyphOrder) return [glyphOrder[gid] if gid < cnt else "glyph%.5d" % gid for gid in lst]
Converts a list of glyph IDs into a list of glyph names.
getGlyphNameMany
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def getGlyphID(self, glyphName): """Returns the ID of the glyph with the given name.""" try: return self.getReverseGlyphMap()[glyphName] except KeyError: if glyphName[:5] == "glyph": try: return int(glyphName[5:]) except...
Returns the ID of the glyph with the given name.
getGlyphID
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def getGlyphIDMany(self, lst): """Converts a list of glyph names into a list of glyph IDs.""" d = self.getReverseGlyphMap() try: return [d[glyphName] for glyphName in lst] except KeyError: getGlyphID = self.getGlyphID return [getGlyphID(glyphName) for ...
Converts a list of glyph names into a list of glyph IDs.
getGlyphIDMany
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def getReverseGlyphMap(self, rebuild=False): """Returns a mapping of glyph names to glyph IDs.""" if rebuild or not hasattr(self, "_reverseGlyphOrderDict"): self._buildReverseGlyphOrderDict() return self._reverseGlyphOrderDict
Returns a mapping of glyph names to glyph IDs.
getReverseGlyphMap
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def _writeTable(self, tag, writer, done, tableCache=None): """Internal helper function for self.save(). Keeps track of inter-table dependencies. """ if tag in done: return tableClass = getTableClass(tag) for masterTable in tableClass.dependencies: ...
Internal helper function for self.save(). Keeps track of inter-table dependencies.
_writeTable
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def getTableData(self, tag): """Returns the binary representation of a table. If the table is currently loaded and in memory, the data is compiled to binary and returned; if it is not currently loaded, the binary data is read from the font file and returned. """ tag = Ta...
Returns the binary representation of a table. If the table is currently loaded and in memory, the data is compiled to binary and returned; if it is not currently loaded, the binary data is read from the font file and returned.
getTableData
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def getGlyphSet( self, preferCFF=True, location=None, normalized=False, recalcBounds=True ): """Return a generic GlyphSet, which is a dict-like object mapping glyph names to glyph objects. The returned glyph objects have a ``.draw()`` method that supports the Pen protocol, and will ...
Return a generic GlyphSet, which is a dict-like object mapping glyph names to glyph objects. The returned glyph objects have a ``.draw()`` method that supports the Pen protocol, and will have an attribute named 'width'. If the font is CFF-based, the outlines will be taken from the ``CFF...
getGlyphSet
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def normalizeLocation(self, location): """Normalize a ``location`` from the font's defined axes space (also known as user space) into the normalized (-1..+1) space. It applies ``avar`` mapping if the font contains an ``avar`` table. The ``location`` parameter should be a dictionary mapp...
Normalize a ``location`` from the font's defined axes space (also known as user space) into the normalized (-1..+1) space. It applies ``avar`` mapping if the font contains an ``avar`` table. The ``location`` parameter should be a dictionary mapping four-letter variation tags to their fl...
normalizeLocation
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def getBestCmap( self, cmapPreferences=( (3, 10), (0, 6), (0, 4), (3, 1), (0, 3), (0, 2), (0, 1), (0, 0), ), ): """Returns the 'best' Unicode cmap dictionary available in the font ...
Returns the 'best' Unicode cmap dictionary available in the font or ``None``, if no Unicode cmap subtable is available. By default it will search for the following (platformID, platEncID) pairs in order:: (3, 10), # Windows Unicode full repertoire ...
getBestCmap
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def getTableModule(tag): """Fetch the packer/unpacker module for a table. Return None when no module is found. """ from . import tables pyTag = tagToIdentifier(tag) try: __import__("fontTools.ttLib.tables." + pyTag) except ImportError as err: # If pyTag is found in the Impor...
Fetch the packer/unpacker module for a table. Return None when no module is found.
getTableModule
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def registerCustomTableClass(tag, moduleName, className=None): """Register a custom packer/unpacker class for a table. The 'moduleName' must be an importable module. If no 'className' is given, it is derived from the tag, for example it will be ``table_C_U_S_T_`` for a 'CUST' tag. The registered t...
Register a custom packer/unpacker class for a table. The 'moduleName' must be an importable module. If no 'className' is given, it is derived from the tag, for example it will be ``table_C_U_S_T_`` for a 'CUST' tag. The registered table class should be a subclass of :py:class:`fontTools.ttLib.tabl...
registerCustomTableClass
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def getCustomTableClass(tag): """Return the custom table class for tag, if one has been registered with 'registerCustomTableClass()'. Else return None. """ if tag not in _customTableRegistry: return None import importlib moduleName, className = _customTableRegistry[tag] module = imp...
Return the custom table class for tag, if one has been registered with 'registerCustomTableClass()'. Else return None.
getCustomTableClass
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def getTableClass(tag): """Fetch the packer/unpacker class for a table.""" tableClass = getCustomTableClass(tag) if tableClass is not None: return tableClass module = getTableModule(tag) if module is None: from .tables.DefaultTable import DefaultTable return DefaultTable ...
Fetch the packer/unpacker class for a table.
getTableClass
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def getClassTag(klass): """Fetch the table tag for a class object.""" name = klass.__name__ assert name[:6] == "table_" name = name[6:] # Chop 'table_' return identifierToTag(name)
Fetch the table tag for a class object.
getClassTag
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def tagToIdentifier(tag): """Convert a table tag to a valid (but UGLY) python identifier, as well as a filename that's guaranteed to be unique even on a caseless file system. Each character is mapped to two characters. Lowercase letters get an underscore before the letter, uppercase letters get an u...
Convert a table tag to a valid (but UGLY) python identifier, as well as a filename that's guaranteed to be unique even on a caseless file system. Each character is mapped to two characters. Lowercase letters get an underscore before the letter, uppercase letters get an underscore after the letter. Trail...
tagToIdentifier
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def tagToXML(tag): """Similarly to tagToIdentifier(), this converts a TT tag to a valid XML element name. Since XML element names are case sensitive, this is a fairly simple/readable translation. """ import re tag = Tag(tag) if tag == "OS/2": return "OS_2" elif tag == "GlyphOrde...
Similarly to tagToIdentifier(), this converts a TT tag to a valid XML element name. Since XML element names are case sensitive, this is a fairly simple/readable translation.
tagToXML
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def sortedTagList(tagList, tableOrder=None): """Return a sorted copy of tagList, sorted according to the OpenType specification, or according to a custom tableOrder. If given and not None, tableOrder needs to be a list of tag names. """ tagList = sorted(tagList) if tableOrder is None: if...
Return a sorted copy of tagList, sorted according to the OpenType specification, or according to a custom tableOrder. If given and not None, tableOrder needs to be a list of tag names.
sortedTagList
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def reorderFontTables(inFile, outFile, tableOrder=None, checkChecksums=False): """Rewrite a font file, ordering the tables as recommended by the OpenType specification 1.4. """ inFile.seek(0) outFile.seek(0) reader = SFNTReader(inFile, checkChecksums=checkChecksums) writer = SFNTWriter( ...
Rewrite a font file, ordering the tables as recommended by the OpenType specification 1.4.
reorderFontTables
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def maxPowerOfTwo(x): """Return the highest exponent of two, so that (2 ** exponent) <= x. Return 0 if x is 0. """ exponent = 0 while x: x = x >> 1 exponent = exponent + 1 return max(exponent - 1, 0)
Return the highest exponent of two, so that (2 ** exponent) <= x. Return 0 if x is 0.
maxPowerOfTwo
python
fonttools/fonttools
Lib/fontTools/ttLib/ttFont.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttFont.py
MIT
def draw(self, pen): """Draw the glyph onto ``pen``. See fontTools.pens.basePen for details how that works. """ glyph, offset = self._getGlyphAndOffset() with self.glyphSet.pushDepth() as depth: if depth: offset = 0 # Offset should only apply at top-...
Draw the glyph onto ``pen``. See fontTools.pens.basePen for details how that works.
draw
python
fonttools/fonttools
Lib/fontTools/ttLib/ttGlyphSet.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttGlyphSet.py
MIT
def drawPoints(self, pen): """Draw the glyph onto ``pen``. See fontTools.pens.pointPen for details how that works. """ glyph, offset = self._getGlyphAndOffset() with self.glyphSet.pushDepth() as depth: if depth: offset = 0 # Offset should only apply ...
Draw the glyph onto ``pen``. See fontTools.pens.pointPen for details how that works.
drawPoints
python
fonttools/fonttools
Lib/fontTools/ttLib/ttGlyphSet.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttGlyphSet.py
MIT
def _draw(self, pen, isPointPen): """Draw the glyph onto ``pen``. See fontTools.pens.basePen for details how that works. """ from fontTools.ttLib.tables.otTables import ( VarComponentFlags, NO_VARIATION_INDEX, ) glyphSet = self.glyphSet va...
Draw the glyph onto ``pen``. See fontTools.pens.basePen for details how that works.
_draw
python
fonttools/fonttools
Lib/fontTools/ttLib/ttGlyphSet.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/ttGlyphSet.py
MIT
def __getitem__(self, tag): """Fetch the raw table data. Reconstruct transformed tables.""" entry = self.tables[Tag(tag)] if not hasattr(entry, "data"): if entry.transformed: entry.data = self.reconstructTable(tag) else: entry.data = entry....
Fetch the raw table data. Reconstruct transformed tables.
__getitem__
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def reconstructTable(self, tag): """Reconstruct table named 'tag' from transformed data.""" entry = self.tables[Tag(tag)] rawData = entry.loadData(self.transformBuffer) if tag == "glyf": # no need to pad glyph data when reconstructing padding = self.padding if has...
Reconstruct table named 'tag' from transformed data.
reconstructTable
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def _reconstructGlyf(self, data, padding=None): """Return recostructed glyf table data, and set the corresponding loca's locations. Optionally pad glyph offsets to the specified number of bytes. """ self.ttFont["loca"] = WOFF2LocaTable() glyfTable = self.ttFont["glyf"] = WOFF2Gly...
Return recostructed glyf table data, and set the corresponding loca's locations. Optionally pad glyph offsets to the specified number of bytes.
_reconstructGlyf
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def _decompileTable(self, tag): """Decompile table data and store it inside self.ttFont.""" data = self[tag] if self.ttFont.isLoaded(tag): return self.ttFont[tag] tableClass = getTableClass(tag) table = tableClass(tag) self.ttFont.tables[tag] = table t...
Decompile table data and store it inside self.ttFont.
_decompileTable
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def __setitem__(self, tag, data): """Associate new entry named 'tag' with raw table data.""" if tag in self.tables: raise TTLibError("cannot rewrite '%s' table" % tag) if tag == "DSIG": # always drop DSIG table, since the encoding process can invalidate it sel...
Associate new entry named 'tag' with raw table data.
__setitem__
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def close(self): """All tags must have been specified. Now write the table data and directory.""" if len(self.tables) != self.numTables: raise TTLibError( "wrong number of tables; expected %d, found %d" % (self.numTables, len(self.tables)) ) ...
All tags must have been specified. Now write the table data and directory.
close
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def _normaliseGlyfAndLoca(self, padding=4): """Recompile glyf and loca tables, aligning glyph offsets to multiples of 'padding' size. Update the head table's 'indexToLocFormat' accordingly while compiling loca. """ if self.sfntVersion == "OTTO": return for ta...
Recompile glyf and loca tables, aligning glyph offsets to multiples of 'padding' size. Update the head table's 'indexToLocFormat' accordingly while compiling loca.
_normaliseGlyfAndLoca
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def _setHeadTransformFlag(self): """Set bit 11 of 'head' table flags to indicate that the font has undergone a lossless modifying transform. Re-compile head table data.""" self._decompileTable("head") self.ttFont["head"].flags |= 1 << 11 self._compileTable("head")
Set bit 11 of 'head' table flags to indicate that the font has undergone a lossless modifying transform. Re-compile head table data.
_setHeadTransformFlag
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def _decompileTable(self, tag): """Fetch table data, decompile it, and store it inside self.ttFont.""" tag = Tag(tag) if tag not in self.tables: raise TTLibError("missing required table: %s" % tag) if self.ttFont.isLoaded(tag): return data = self.tables[ta...
Fetch table data, decompile it, and store it inside self.ttFont.
_decompileTable
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def _calcSFNTChecksumsLengthsAndOffsets(self): """Compute the 'original' SFNT checksums, lengths and offsets for checksum adjustment calculation. Return the total size of the uncompressed font. """ offset = sfntDirectorySize + sfntDirectoryEntrySize * len(self.tables) for tag, en...
Compute the 'original' SFNT checksums, lengths and offsets for checksum adjustment calculation. Return the total size of the uncompressed font.
_calcSFNTChecksumsLengthsAndOffsets
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def transformTable(self, tag): """Return transformed table data, or None if some pre-conditions aren't met -- in which case, the non-transformed table data will be used. """ if tag == "loca": data = b"" elif tag == "glyf": for tag in ("maxp", "head", "loca...
Return transformed table data, or None if some pre-conditions aren't met -- in which case, the non-transformed table data will be used.
transformTable
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def _calcTotalSize(self): """Calculate total size of WOFF2 font, including any meta- and/or private data.""" offset = self.directorySize for entry in self.tables.values(): offset += len(entry.toString()) offset += self.totalCompressedSize offset = (offset + 3) & ~3 ...
Calculate total size of WOFF2 font, including any meta- and/or private data.
_calcTotalSize
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def _calcFlavorDataOffsetsAndSize(self, start): """Calculate offsets and lengths for any meta- and/or private data.""" offset = start data = self.flavorData if data.metaData: self.metaOrigLength = len(data.metaData) self.metaOffset = offset self.compre...
Calculate offsets and lengths for any meta- and/or private data.
_calcFlavorDataOffsetsAndSize
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def _getVersion(self): """Return the WOFF2 font's (majorVersion, minorVersion) tuple.""" data = self.flavorData if data.majorVersion is not None and data.minorVersion is not None: return data.majorVersion, data.minorVersion else: # if None, return 'fontRevision' f...
Return the WOFF2 font's (majorVersion, minorVersion) tuple.
_getVersion
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def _writeFlavorData(self): """Write metadata and/or private data using appropiate padding.""" compressedMetaData = self.compressedMetaData privData = self.flavorData.privData if compressedMetaData and privData: compressedMetaData = pad(compressedMetaData, size=4) if ...
Write metadata and/or private data using appropiate padding.
_writeFlavorData
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def getKnownTagIndex(tag): """Return index of 'tag' in woff2KnownTags list. Return 63 if not found.""" for i in range(len(woff2KnownTags)): if tag == woff2KnownTags[i]: return i return woff2UnknownTagIndex
Return index of 'tag' in woff2KnownTags list. Return 63 if not found.
getKnownTagIndex
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def transformed(self): """Return True if the table has any transformation, else return False.""" # For all tables in a font, except for 'glyf' and 'loca', the transformation # version 0 indicates the null transform (where the original table data is # passed directly to the Brotli compres...
Return True if the table has any transformation, else return False.
transformed
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def __init__(self, reader=None, data=None, transformedTables=None): """Data class that holds the WOFF2 header major/minor version, any metadata or private data (as bytes strings), and the set of table tags that have transformations applied (if reader is not None), or will have once the W...
Data class that holds the WOFF2 header major/minor version, any metadata or private data (as bytes strings), and the set of table tags that have transformations applied (if reader is not None), or will have once the WOFF2 font is compiled. Args: reader: an SFNTReader (or...
__init__
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def unpackBase128(data): r"""Read one to five bytes from UIntBase128-encoded input string, and return a tuple containing the decoded integer plus any leftover data. >>> unpackBase128(b'\x3f\x00\x00') == (63, b"\x00\x00") True >>> unpackBase128(b'\x8f\xff\xff\xff\x7f')[0] == 4294967295 True ...
Read one to five bytes from UIntBase128-encoded input string, and return a tuple containing the decoded integer plus any leftover data. >>> unpackBase128(b'\x3f\x00\x00') == (63, b"\x00\x00") True >>> unpackBase128(b'\x8f\xff\xff\xff\x7f')[0] == 4294967295 True >>> unpackBase128(b'\x80\x80\x3f'...
unpackBase128
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def base128Size(n): """Return the length in bytes of a UIntBase128-encoded sequence with value n. >>> base128Size(0) 1 >>> base128Size(24567) 3 >>> base128Size(2**32-1) 5 """ assert n >= 0 size = 1 while n >= 128: size += 1 n >>= 7 return size
Return the length in bytes of a UIntBase128-encoded sequence with value n. >>> base128Size(0) 1 >>> base128Size(24567) 3 >>> base128Size(2**32-1) 5
base128Size
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def packBase128(n): r"""Encode unsigned integer in range 0 to 2**32-1 (inclusive) to a string of bytes using UIntBase128 variable-length encoding. Produce the shortest possible encoding. >>> packBase128(63) == b"\x3f" True >>> packBase128(2**32-1) == b'\x8f\xff\xff\xff\x7f' True """ ...
Encode unsigned integer in range 0 to 2**32-1 (inclusive) to a string of bytes using UIntBase128 variable-length encoding. Produce the shortest possible encoding. >>> packBase128(63) == b"\x3f" True >>> packBase128(2**32-1) == b'\x8f\xff\xff\xff\x7f' True
packBase128
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def unpack255UShort(data): """Read one to three bytes from 255UInt16-encoded input string, and return a tuple containing the decoded integer plus any leftover data. >>> unpack255UShort(bytechr(252))[0] 252 Note that some numbers (e.g. 506) can have multiple encodings: >>> unpack255UShort(struc...
Read one to three bytes from 255UInt16-encoded input string, and return a tuple containing the decoded integer plus any leftover data. >>> unpack255UShort(bytechr(252))[0] 252 Note that some numbers (e.g. 506) can have multiple encodings: >>> unpack255UShort(struct.pack("BB", 254, 0))[0] 506 ...
unpack255UShort
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def pack255UShort(value): r"""Encode unsigned integer in range 0 to 65535 (inclusive) to a bytestring using 255UInt16 variable-length encoding. >>> pack255UShort(252) == b'\xfc' True >>> pack255UShort(506) == b'\xfe\x00' True >>> pack255UShort(762) == b'\xfd\x02\xfa' True """ if...
Encode unsigned integer in range 0 to 65535 (inclusive) to a bytestring using 255UInt16 variable-length encoding. >>> pack255UShort(252) == b'\xfc' True >>> pack255UShort(506) == b'\xfe\x00' True >>> pack255UShort(762) == b'\xfd\x02\xfa' True
pack255UShort
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def compress(input_file, output_file, transform_tables=None): """Compress OpenType font to WOFF2. Args: input_file: a file path, file or file-like object (open in binary mode) containing an OpenType font (either CFF- or TrueType-flavored). output_file: a file path, f...
Compress OpenType font to WOFF2. Args: input_file: a file path, file or file-like object (open in binary mode) containing an OpenType font (either CFF- or TrueType-flavored). output_file: a file path, file or file-like object where to save the compres...
compress
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def decompress(input_file, output_file): """Decompress WOFF2 font to OpenType font. Args: input_file: a file path, file or file-like object (open in binary mode) containing a compressed WOFF2 font. output_file: a file path, file or file-like object where to save the ...
Decompress WOFF2 font to OpenType font. Args: input_file: a file path, file or file-like object (open in binary mode) containing a compressed WOFF2 font. output_file: a file path, file or file-like object where to save the decompressed OpenType font. ...
decompress
python
fonttools/fonttools
Lib/fontTools/ttLib/woff2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/woff2.py
MIT
def main(args=None): """Open/save fonts with TTFont() or TTCollection() ./fonttools ttLib [-oFILE] [-yNUMBER] files... If multiple files are given on the command-line, they are each opened (as a font or collection), and added to the font list. If -o (output-file) argument is given, the font...
Open/save fonts with TTFont() or TTCollection() ./fonttools ttLib [-oFILE] [-yNUMBER] files... If multiple files are given on the command-line, they are each opened (as a font or collection), and added to the font list. If -o (output-file) argument is given, the font list is then saved to t...
main
python
fonttools/fonttools
Lib/fontTools/ttLib/__main__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/__main__.py
MIT
def decompile(self, data, font): """Create an object from the binary data. Called automatically on access.""" from . import otTables reader = OTTableReader(data, tableTag=self.tableTag) tableClass = getattr(otTables, self.tableTag) self.table = tableClass() self.table.de...
Create an object from the binary data. Called automatically on access.
decompile
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otBase.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otBase.py
MIT
def compile(self, font): """Compiles the table into binary. Called automatically on save.""" # General outline: # Create a top-level OTTableWriter for the GPOS/GSUB table. # Call the compile method for the the table # for each 'converter' record in the table converter list ...
Compiles the table into binary. Called automatically on save.
compile
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otBase.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otBase.py
MIT
def getDataLength(self): """Return the length of this table in bytes, without subtables.""" l = 0 for item in self.items: if hasattr(item, "getCountData"): l += item.size elif hasattr(item, "subWriter"): l += item.offsetSize els...
Return the length of this table in bytes, without subtables.
getDataLength
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otBase.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otBase.py
MIT
def getData(self): """Assemble the data for this writer/table, without subtables.""" items = list(self.items) # make a shallow copy pos = self.pos numItems = len(items) for i in range(numItems): item = items[i] if hasattr(item, "subWriter"): ...
Assemble the data for this writer/table, without subtables.
getData
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otBase.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otBase.py
MIT
def getDataForHarfbuzz(self): """Assemble the data for this writer/table with all offset field set to 0""" items = list(self.items) packFuncs = {2: packUShort, 3: packUInt24, 4: packULong} for i, item in enumerate(items): if hasattr(item, "subWriter"): # Offse...
Assemble the data for this writer/table with all offset field set to 0
getDataForHarfbuzz
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otBase.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otBase.py
MIT
def getAllDataUsingHarfbuzz(self, tableTag): """The Whole table is represented as a Graph. Assemble graph data and call Harfbuzz repacker to pack the table. Harfbuzz repacker is faster and retain as much sub-table sharing as possible, see also: https://github.com/harfbuzz/harfbuzz/blob/m...
The Whole table is represented as a Graph. Assemble graph data and call Harfbuzz repacker to pack the table. Harfbuzz repacker is faster and retain as much sub-table sharing as possible, see also: https://github.com/harfbuzz/harfbuzz/blob/main/docs/repacker.md The input format for hb.rep...
getAllDataUsingHarfbuzz
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otBase.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otBase.py
MIT
def getAllData(self, remove_duplicate=True): """Assemble all data, including all subtables.""" if remove_duplicate: internedTables = {} self._doneWriting(internedTables) tables = [] extTables = [] done = {} self._gatherTables(tables, extTables, don...
Assemble all data, including all subtables.
getAllData
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otBase.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otBase.py
MIT
def iterSubTables(self) -> Iterator[SubTableEntry]: """Yield (name, value, index) namedtuples for all subtables of current table. A sub-table is an instance of BaseTable (or subclass thereof) that is a child of self, the current parent table. The tuples also contain the attribute name (...
Yield (name, value, index) namedtuples for all subtables of current table. A sub-table is an instance of BaseTable (or subclass thereof) that is a child of self, the current parent table. The tuples also contain the attribute name (str) of the of parent table to get a subtable, and opti...
iterSubTables
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otBase.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otBase.py
MIT
def getVariableAttrs(cls: BaseTable, fmt: Optional[int] = None) -> Tuple[str]: """Return sequence of variable table field names (can be empty). Attributes are deemed "variable" when their otData.py's description contain 'VarIndexBase + {offset}', e.g. COLRv1 PaintVar* tables. """ if not issubclass(...
Return sequence of variable table field names (can be empty). Attributes are deemed "variable" when their otData.py's description contain 'VarIndexBase + {offset}', e.g. COLRv1 PaintVar* tables.
getVariableAttrs
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otBase.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otBase.py
MIT
def buildConverters(tableSpec, tableNamespace): """Given a table spec from otData.py, build a converter object for each field of the table. This is called for each table in otData.py, and the results are assigned to the corresponding class in otTables.py.""" converters = [] convertersByName = {} ...
Given a table spec from otData.py, build a converter object for each field of the table. This is called for each table in otData.py, and the results are assigned to the corresponding class in otTables.py.
buildConverters
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otConverters.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otConverters.py
MIT
def readArray(self, reader, font, tableDict, count): """Read an array of values from the reader.""" lazy = font.lazy and count > 8 if lazy: recordSize = self.getRecordSize(reader) if recordSize is NotImplemented: lazy = False if not lazy: ...
Read an array of values from the reader.
readArray
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otConverters.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otConverters.py
MIT
def getVarIndexOffset(self) -> Optional[int]: """If description has `VarIndexBase + {offset}`, return the offset else None.""" m = self.varIndexBasePlusOffsetRE.search(self.description) if not m: return None return int(m.group(1))
If description has `VarIndexBase + {offset}`, return the offset else None.
getVarIndexOffset
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otConverters.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otConverters.py
MIT
def _read_uint32var(data, i): """Read a variable-length number from data starting at index i. Return the number and the next index. """ b0 = data[i] if b0 < 0x80: return b0, i + 1 elif b0 < 0xC0: return (b0 - 0x80) << 8 | data[i + 1], i + 2 elif b0 < 0xE0: return (b...
Read a variable-length number from data starting at index i. Return the number and the next index.
_read_uint32var
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otTables.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otTables.py
MIT
def _write_uint32var(v): """Write a variable-length number. Return the data. """ if v < 0x80: return struct.pack(">B", v) elif v < 0x4000: return struct.pack(">H", (v | 0x8000)) elif v < 0x200000: return struct.pack(">L", (v | 0xC00000))[1:] elif v < 0x10000000: ...
Write a variable-length number. Return the data.
_write_uint32var
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otTables.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otTables.py
MIT
def traverse(self, colr: COLR, callback): """Depth-first traversal of graph rooted at self, callback on each node.""" if not callable(callback): raise TypeError("callback must be callable") for path in dfs_base_table( self, iter_subtables_fn=lambda paint: paint.iterPaint...
Depth-first traversal of graph rooted at self, callback on each node.
traverse
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otTables.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otTables.py
MIT
def fixLookupOverFlows(ttf, overflowRecord): """Either the offset from the LookupList to a lookup overflowed, or an offset from a lookup to a subtable overflowed. The table layout is:: GPSO/GUSB Script List Feature List LookUpList Looku...
Either the offset from the LookupList to a lookup overflowed, or an offset from a lookup to a subtable overflowed. The table layout is:: GPSO/GUSB Script List Feature List LookUpList Lookup[0] and contents SubT...
fixLookupOverFlows
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otTables.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otTables.py
MIT
def fixSubTableOverFlows(ttf, overflowRecord): """ An offset has overflowed within a sub-table. We need to divide this subtable into smaller parts. """ table = ttf[overflowRecord.tableType].table lookup = table.LookupList.Lookup[overflowRecord.LookupListIndex] subIndex = overflowRecord.SubTableI...
An offset has overflowed within a sub-table. We need to divide this subtable into smaller parts.
fixSubTableOverFlows
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otTables.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otTables.py
MIT
def dfs_base_table( root: BaseTable, root_accessor: Optional[str] = None, skip_root: bool = False, predicate: Optional[Callable[[SubTablePath], bool]] = None, iter_subtables_fn: Optional[ Callable[[BaseTable], Iterable[BaseTable.SubTableEntry]] ] = None, ) -> Iterable[SubTablePath]: ...
Depth-first search tree of BaseTables. Args: root (BaseTable): the root of the tree. root_accessor (Optional[str]): attribute name for the root table, if any (mostly useful for debugging). skip_root (Optional[bool]): if True, the root itself is not visited, only its ...
dfs_base_table
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otTraverse.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otTraverse.py
MIT
def bfs_base_table( root: BaseTable, root_accessor: Optional[str] = None, skip_root: bool = False, predicate: Optional[Callable[[SubTablePath], bool]] = None, iter_subtables_fn: Optional[ Callable[[BaseTable], Iterable[BaseTable.SubTableEntry]] ] = None, ) -> Iterable[SubTablePath]: ...
Breadth-first search tree of BaseTables. Args: root the root of the tree. root_accessor (Optional[str]): attribute name for the root table, if any (mostly useful for debugging). skip_root (Optional[bool]): if True, the root itself is not visited, only its ...
bfs_base_table
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/otTraverse.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/otTraverse.py
MIT
def getUnicodeRanges(self): """Return the set of 'ulUnicodeRange*' bits currently enabled.""" bits = set() ul1, ul2 = self.ulUnicodeRange1, self.ulUnicodeRange2 ul3, ul4 = self.ulUnicodeRange3, self.ulUnicodeRange4 for i in range(32): if ul1 & (1 << i): ...
Return the set of 'ulUnicodeRange*' bits currently enabled.
getUnicodeRanges
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/O_S_2f_2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/O_S_2f_2.py
MIT
def setUnicodeRanges(self, bits): """Set the 'ulUnicodeRange*' fields to the specified 'bits'.""" ul1, ul2, ul3, ul4 = 0, 0, 0, 0 for bit in bits: if 0 <= bit < 32: ul1 |= 1 << bit elif 32 <= bit < 64: ul2 |= 1 << (bit - 32) eli...
Set the 'ulUnicodeRange*' fields to the specified 'bits'.
setUnicodeRanges
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/O_S_2f_2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/O_S_2f_2.py
MIT
def recalcUnicodeRanges(self, ttFont, pruneOnly=False): """Intersect the codepoints in the font's Unicode cmap subtables with the Unicode block ranges defined in the OpenType specification (v1.7), and set the respective 'ulUnicodeRange*' bits if there is at least ONE intersection. ...
Intersect the codepoints in the font's Unicode cmap subtables with the Unicode block ranges defined in the OpenType specification (v1.7), and set the respective 'ulUnicodeRange*' bits if there is at least ONE intersection. If 'pruneOnly' is True, only clear unused bits with NO intersecti...
recalcUnicodeRanges
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/O_S_2f_2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/O_S_2f_2.py
MIT
def getCodePageRanges(self): """Return the set of 'ulCodePageRange*' bits currently enabled.""" bits = set() if self.version < 1: return bits ul1, ul2 = self.ulCodePageRange1, self.ulCodePageRange2 for i in range(32): if ul1 & (1 << i): bit...
Return the set of 'ulCodePageRange*' bits currently enabled.
getCodePageRanges
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/O_S_2f_2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/O_S_2f_2.py
MIT
def setCodePageRanges(self, bits): """Set the 'ulCodePageRange*' fields to the specified 'bits'.""" ul1, ul2 = 0, 0 for bit in bits: if 0 <= bit < 32: ul1 |= 1 << bit elif 32 <= bit < 64: ul2 |= 1 << (bit - 32) else: ...
Set the 'ulCodePageRange*' fields to the specified 'bits'.
setCodePageRanges
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/O_S_2f_2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/O_S_2f_2.py
MIT
def recalcAvgCharWidth(self, ttFont): """Recalculate xAvgCharWidth using metrics from ttFont's 'hmtx' table. Set it to 0 if the unlikely event 'hmtx' table is not found. """ avg_width = 0 hmtx = ttFont.get("hmtx") if hmtx is not None: widths = [width for widt...
Recalculate xAvgCharWidth using metrics from ttFont's 'hmtx' table. Set it to 0 if the unlikely event 'hmtx' table is not found.
recalcAvgCharWidth
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/O_S_2f_2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/O_S_2f_2.py
MIT
def intersectUnicodeRanges(unicodes, inverse=False): """Intersect a sequence of (int) Unicode codepoints with the Unicode block ranges defined in the OpenType specification v1.7, and return the set of 'ulUnicodeRanges' bits for which there is at least ONE intersection. If 'inverse' is True, return the t...
Intersect a sequence of (int) Unicode codepoints with the Unicode block ranges defined in the OpenType specification v1.7, and return the set of 'ulUnicodeRanges' bits for which there is at least ONE intersection. If 'inverse' is True, return the the bits for which there is NO intersection. >>> interse...
intersectUnicodeRanges
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/O_S_2f_2.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/O_S_2f_2.py
MIT
def __bool__(self) -> bool: """ >>> p = Program() >>> bool(p) False >>> bc = array.array("B", [0]) >>> p.fromBytecode(bc) >>> bool(p) True >>> p.bytecode.pop() 0 >>> bool(p) False >>> p = Program() >>> asm =...
>>> p = Program() >>> bool(p) False >>> bc = array.array("B", [0]) >>> p.fromBytecode(bc) >>> bool(p) True >>> p.bytecode.pop() 0 >>> bool(p) False >>> p = Program() >>> asm = ['SVTCA[0]'] >>> p.fromAssembl...
__bool__
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/ttProgram.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/ttProgram.py
MIT
def decompileDeltas_(numDeltas, data, offset=0): """(numDeltas, data, offset) --> ([delta, delta, ...], newOffset)""" result = [] pos = offset while len(result) < numDeltas if numDeltas is not None else pos < len(data): runHeader = data[pos] pos += 1 n...
(numDeltas, data, offset) --> ([delta, delta, ...], newOffset)
decompileDeltas_
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/TupleVariation.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/TupleVariation.py
MIT
def getCoordWidth(self): """Return 2 if coordinates are (x, y) as in gvar, 1 if single values as in cvar, or 0 if empty. """ firstDelta = next((c for c in self.coordinates if c is not None), None) if firstDelta is None: return 0 # empty or has no impact if ty...
Return 2 if coordinates are (x, y) as in gvar, 1 if single values as in cvar, or 0 if empty.
getCoordWidth
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/TupleVariation.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/TupleVariation.py
MIT
def _getOffsets(self): """ Calculate offsets to VDMX_Group records. For each ratRange return a list of offset values from the beginning of the VDMX table to a VDMX_Group. """ lenHeader = sstruct.calcsize(VDMX_HeaderFmt) lenRatRange = sstruct.calcsize(VDMX_RatRange...
Calculate offsets to VDMX_Group records. For each ratRange return a list of offset values from the beginning of the VDMX table to a VDMX_Group.
_getOffsets
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/V_D_M_X_.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/V_D_M_X_.py
MIT
def getcmap(self, platformID, platEncID): """Returns the first subtable which matches the given platform and encoding. Args: platformID (int): The platform ID. Use 0 for Unicode, 1 for Macintosh (deprecated for new fonts), 2 for ISO (deprecated) and 3 for Windows...
Returns the first subtable which matches the given platform and encoding. Args: platformID (int): The platform ID. Use 0 for Unicode, 1 for Macintosh (deprecated for new fonts), 2 for ISO (deprecated) and 3 for Windows. encodingID (int): Encoding ID. Inte...
getcmap
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_c_m_a_p.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_c_m_a_p.py
MIT
def getBestCmap( self, cmapPreferences=( (3, 10), (0, 6), (0, 4), (3, 1), (0, 3), (0, 2), (0, 1), (0, 0), ), ): """Returns the 'best' Unicode cmap dictionary available in the font ...
Returns the 'best' Unicode cmap dictionary available in the font or ``None``, if no Unicode cmap subtable is available. By default it will search for the following (platformID, platEncID) pairs in order:: (3, 10), # Windows Unicode full repertoire ...
getBestCmap
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_c_m_a_p.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_c_m_a_p.py
MIT
def buildReversed(self): """Builds a reverse mapping dictionary Iterates over all Unicode cmap tables and returns a dictionary mapping glyphs to sets of codepoints, such as:: { 'one': {0x31} 'A': {0x41,0x391} } ...
Builds a reverse mapping dictionary Iterates over all Unicode cmap tables and returns a dictionary mapping glyphs to sets of codepoints, such as:: { 'one': {0x31} 'A': {0x41,0x391} } The values are sets of Unicode...
buildReversed
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_c_m_a_p.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_c_m_a_p.py
MIT
def isUnicode(self): """Returns true if the characters are interpreted as Unicode codepoints.""" return self.platformID == 0 or ( self.platformID == 3 and self.platEncID in [0, 1, 10] )
Returns true if the characters are interpreted as Unicode codepoints.
isUnicode
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_c_m_a_p.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_c_m_a_p.py
MIT
def setGlyphOrder(self, glyphOrder): """Sets the glyph order Args: glyphOrder ([str]): List of glyph names in order. """ self.glyphOrder = glyphOrder self._reverseGlyphOrder = {}
Sets the glyph order Args: glyphOrder ([str]): List of glyph names in order.
setGlyphOrder
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_g_l_y_f.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_g_l_y_f.py
MIT
def getGlyphID(self, glyphName): """Returns the ID of the glyph with the given name. Raises a ``ValueError`` if the glyph is not found in the font. """ glyphOrder = self.glyphOrder id = getattr(self, "_reverseGlyphOrder", {}).get(glyphName) if id is None or id >= len(gly...
Returns the ID of the glyph with the given name. Raises a ``ValueError`` if the glyph is not found in the font.
getGlyphID
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_g_l_y_f.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_g_l_y_f.py
MIT
def _getPhantomPoints(self, glyphName, hMetrics, vMetrics=None): """Compute the four "phantom points" for the given glyph from its bounding box and the horizontal and vertical advance widths and sidebearings stored in the ttFont's "hmtx" and "vmtx" tables. 'hMetrics' should be ttFont['h...
Compute the four "phantom points" for the given glyph from its bounding box and the horizontal and vertical advance widths and sidebearings stored in the ttFont's "hmtx" and "vmtx" tables. 'hMetrics' should be ttFont['hmtx'].metrics. 'vMetrics' should be ttFont['vmtx'].metrics if there...
_getPhantomPoints
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_g_l_y_f.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_g_l_y_f.py
MIT
def _getCoordinatesAndControls( self, glyphName, hMetrics, vMetrics=None, *, round=otRound ): """Return glyph coordinates and controls as expected by "gvar" table. The coordinates includes four "phantom points" for the glyph metrics, as mandated by the "gvar" spec. The glyp...
Return glyph coordinates and controls as expected by "gvar" table. The coordinates includes four "phantom points" for the glyph metrics, as mandated by the "gvar" spec. The glyph controls is a namedtuple with the following attributes: - numberOfContours: -1 for composite glyphs...
_getCoordinatesAndControls
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_g_l_y_f.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_g_l_y_f.py
MIT
def _setCoordinates(self, glyphName, coord, hMetrics, vMetrics=None): """Set coordinates and metrics for the given glyph. "coord" is an array of GlyphCoordinates which must include the "phantom points" as the last four coordinates. Both the horizontal/vertical advances and left/top sid...
Set coordinates and metrics for the given glyph. "coord" is an array of GlyphCoordinates which must include the "phantom points" as the last four coordinates. Both the horizontal/vertical advances and left/top sidebearings in "hmtx" and "vmtx" tables (if any) are updated from four phan...
_setCoordinates
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_g_l_y_f.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_g_l_y_f.py
MIT
def _synthesizeVMetrics(self, glyphName, ttFont, defaultVerticalOrigin): """This method is wrong and deprecated. For rationale see: https://github.com/fonttools/fonttools/pull/2266/files#r613569473 """ vMetrics = getattr(ttFont.get("vmtx"), "metrics", None) if vMetrics is...
This method is wrong and deprecated. For rationale see: https://github.com/fonttools/fonttools/pull/2266/files#r613569473
_synthesizeVMetrics
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_g_l_y_f.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_g_l_y_f.py
MIT
def getPhantomPoints(self, glyphName, ttFont, defaultVerticalOrigin=None): """Old public name for self._getPhantomPoints(). See: https://github.com/fonttools/fonttools/pull/2266""" hMetrics = ttFont["hmtx"].metrics vMetrics = self._synthesizeVMetrics(glyphName, ttFont, defaultVerticalOri...
Old public name for self._getPhantomPoints(). See: https://github.com/fonttools/fonttools/pull/2266
getPhantomPoints
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_g_l_y_f.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_g_l_y_f.py
MIT
def getCoordinatesAndControls(self, glyphName, ttFont, defaultVerticalOrigin=None): """Old public name for self._getCoordinatesAndControls(). See: https://github.com/fonttools/fonttools/pull/2266""" hMetrics = ttFont["hmtx"].metrics vMetrics = self._synthesizeVMetrics(glyphName, ttFont, ...
Old public name for self._getCoordinatesAndControls(). See: https://github.com/fonttools/fonttools/pull/2266
getCoordinatesAndControls
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_g_l_y_f.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_g_l_y_f.py
MIT
def setCoordinates(self, glyphName, ttFont): """Old public name for self._setCoordinates(). See: https://github.com/fonttools/fonttools/pull/2266""" hMetrics = ttFont["hmtx"].metrics vMetrics = getattr(ttFont.get("vmtx"), "metrics", None) self._setCoordinates(glyphName, hMetrics,...
Old public name for self._setCoordinates(). See: https://github.com/fonttools/fonttools/pull/2266
setCoordinates
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_g_l_y_f.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_g_l_y_f.py
MIT
def flagBest(x, y, onCurve): """For a given x,y delta pair, returns the flag that packs this pair most efficiently, as well as the number of byte cost of such flag.""" flag = flagOnCurve if onCurve else 0 cost = 0 # do x if x == 0: flag = flag | flagXsame elif -255 <= x <= 255: ...
For a given x,y delta pair, returns the flag that packs this pair most efficiently, as well as the number of byte cost of such flag.
flagBest
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_g_l_y_f.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_g_l_y_f.py
MIT
def recalcBounds(self, glyfTable, *, boundsDone=None): """Recalculates the bounds of the glyph. Each glyph object stores its bounding box in the ``xMin``/``yMin``/``xMax``/``yMax`` attributes. These bounds must be recomputed when the ``coordinates`` change. The ``table__g_l_y_f`` bounds...
Recalculates the bounds of the glyph. Each glyph object stores its bounding box in the ``xMin``/``yMin``/``xMax``/``yMax`` attributes. These bounds must be recomputed when the ``coordinates`` change. The ``table__g_l_y_f`` bounds must be provided to resolve component bounds.
recalcBounds
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_g_l_y_f.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_g_l_y_f.py
MIT
def tryRecalcBoundsComposite(self, glyfTable, *, boundsDone=None): """Try recalculating the bounds of a composite glyph that has certain constrained properties. Namely, none of the components have a transform other than an integer translate, and none uses the anchor points. Each...
Try recalculating the bounds of a composite glyph that has certain constrained properties. Namely, none of the components have a transform other than an integer translate, and none uses the anchor points. Each glyph object stores its bounding box in the ``xMin``/``yMin``/``xMax`...
tryRecalcBoundsComposite
python
fonttools/fonttools
Lib/fontTools/ttLib/tables/_g_l_y_f.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/ttLib/tables/_g_l_y_f.py
MIT