diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/__init__.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bc344c2d0c94850985e88c7c0543b723314dc1ec Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/__init__.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/__main__.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/__main__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c9b6f83cd407d2c25e9d1efc42a2f2025541dc03 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/__main__.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/macUtils.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/macUtils.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..71e7f7714d482445d19cd68244638aa3296448ce Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/macUtils.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/removeOverlaps.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/removeOverlaps.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..821566b69546f7500c2709499b90dc5b79e06984 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/removeOverlaps.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/reorderGlyphs.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/reorderGlyphs.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b9470c5e6df2193fc6d1502d635854d547b59089 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/reorderGlyphs.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/scaleUpem.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/scaleUpem.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..94dacfbd5382fe2c82f2fdcad70906d5897273fd Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/scaleUpem.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/sfnt.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/sfnt.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a0cb535fa866966804a7775454615e7f743ed3d1 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/sfnt.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/standardGlyphOrder.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/standardGlyphOrder.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0518ab2bdb7785f9a31321ceaf89bffad0fb569d Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/standardGlyphOrder.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttCollection.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttCollection.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7571244a2debee35e3df99ed8bf709dfe05ec98f Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttCollection.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttFont.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttFont.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4dee38d5903fac0166ddc2c33f504c5c35d16c3c Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttFont.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttGlyphSet.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttGlyphSet.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d15af0d3855333df5a33fa506a4d45e740732a8e Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttGlyphSet.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttVisitor.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttVisitor.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bd863f40ddcfd80fe5bb6a4f0ce5c1c59de806a5 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttVisitor.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/woff2.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/woff2.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b943187b20d8a5a2b347b3fb9b776e851c48a136 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/woff2.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/BitmapGlyphMetrics.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/BitmapGlyphMetrics.py new file mode 100644 index 0000000000000000000000000000000000000000..10b4f828213b8320d54eefed3d5e66f2ba532101 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/BitmapGlyphMetrics.py @@ -0,0 +1,64 @@ +# Since bitmap glyph metrics are shared between EBLC and EBDT +# this class gets its own python file. +from fontTools.misc import sstruct +from fontTools.misc.textTools import safeEval +import logging + + +log = logging.getLogger(__name__) + +bigGlyphMetricsFormat = """ + > # big endian + height: B + width: B + horiBearingX: b + horiBearingY: b + horiAdvance: B + vertBearingX: b + vertBearingY: b + vertAdvance: B +""" + +smallGlyphMetricsFormat = """ + > # big endian + height: B + width: B + BearingX: b + BearingY: b + Advance: B +""" + + +class BitmapGlyphMetrics(object): + def toXML(self, writer, ttFont): + writer.begintag(self.__class__.__name__) + writer.newline() + for metricName in sstruct.getformat(self.__class__.binaryFormat)[1]: + writer.simpletag(metricName, value=getattr(self, metricName)) + writer.newline() + writer.endtag(self.__class__.__name__) + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + metricNames = set(sstruct.getformat(self.__class__.binaryFormat)[1]) + for element in content: + if not isinstance(element, tuple): + continue + name, attrs, content = element + # Make sure this is a metric that is needed by GlyphMetrics. + if name in metricNames: + vars(self)[name] = safeEval(attrs["value"]) + else: + log.warning( + "unknown name '%s' being ignored in %s.", + name, + self.__class__.__name__, + ) + + +class BigGlyphMetrics(BitmapGlyphMetrics): + binaryFormat = bigGlyphMetricsFormat + + +class SmallGlyphMetrics(BitmapGlyphMetrics): + binaryFormat = smallGlyphMetricsFormat diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_F_F_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_F_F_.py new file mode 100644 index 0000000000000000000000000000000000000000..3d974ced88e9d9a1e9c0494c4d0eac996ec315b8 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_F_F_.py @@ -0,0 +1,61 @@ +from io import BytesIO +from fontTools import cffLib +from . import DefaultTable + + +class table_C_F_F_(DefaultTable.DefaultTable): + """Compact Font Format table (version 1) + + The ``CFF`` table embeds a CFF-formatted font. The CFF font format + predates OpenType and could be used as a standalone font file, but the + ``CFF`` table is also used to package CFF fonts into an OpenType + container. + + .. note:: + ``CFF`` has been succeeded by ``CFF2``, which eliminates much of + the redundancy incurred by embedding CFF version 1 in an OpenType + font. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/cff + """ + + def __init__(self, tag=None): + DefaultTable.DefaultTable.__init__(self, tag) + self.cff = cffLib.CFFFontSet() + self._gaveGlyphOrder = False + + def decompile(self, data, otFont): + self.cff.decompile(BytesIO(data), otFont, isCFF2=False) + assert len(self.cff) == 1, "can't deal with multi-font CFF tables." + + def compile(self, otFont): + f = BytesIO() + self.cff.compile(f, otFont, isCFF2=False) + return f.getvalue() + + def haveGlyphNames(self): + if hasattr(self.cff[self.cff.fontNames[0]], "ROS"): + return False # CID-keyed font + else: + return True + + def getGlyphOrder(self): + if self._gaveGlyphOrder: + from fontTools import ttLib + + raise ttLib.TTLibError("illegal use of getGlyphOrder()") + self._gaveGlyphOrder = True + return self.cff[self.cff.fontNames[0]].getGlyphOrder() + + def setGlyphOrder(self, glyphOrder): + pass + # XXX + # self.cff[self.cff.fontNames[0]].setGlyphOrder(glyphOrder) + + def toXML(self, writer, otFont): + self.cff.toXML(writer) + + def fromXML(self, name, attrs, content, otFont): + if not hasattr(self, "cff"): + self.cff = cffLib.CFFFontSet() + self.cff.fromXML(name, attrs, content, otFont) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_F_F__2.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_F_F__2.py new file mode 100644 index 0000000000000000000000000000000000000000..ff07682d24f0399b6579f529ae70cf4fd87abf21 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_F_F__2.py @@ -0,0 +1,26 @@ +from io import BytesIO +from fontTools.ttLib.tables.C_F_F_ import table_C_F_F_ + + +class table_C_F_F__2(table_C_F_F_): + """Compact Font Format version 2 table + + The ``CFF2`` table contains glyph data for a CFF2-flavored OpenType + font. + + .. note:: + ``CFF2`` is the successor to ``CFF``, and eliminates much of + the redundancy incurred by embedding CFF version 1 in an OpenType + font. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/cff2 + """ + + def decompile(self, data, otFont): + self.cff.decompile(BytesIO(data), otFont, isCFF2=True) + assert len(self.cff) == 1, "can't deal with multi-font CFF tables." + + def compile(self, otFont): + f = BytesIO() + self.cff.compile(f, otFont, isCFF2=True) + return f.getvalue() diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_O_L_R_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_O_L_R_.py new file mode 100644 index 0000000000000000000000000000000000000000..266a11c41dffc5eed42ee446c0268373104cbf7a --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_O_L_R_.py @@ -0,0 +1,165 @@ +# Copyright 2013 Google, Inc. All Rights Reserved. +# +# Google Author(s): Behdad Esfahbod + +from fontTools.misc.textTools import safeEval +from . import DefaultTable + + +class table_C_O_L_R_(DefaultTable.DefaultTable): + """Color table + + The ``COLR`` table defines color presentation of outline glyphs. It must + be used in concert with the ``CPAL`` table, which contains the color + descriptors used. + + This table is structured so that you can treat it like a dictionary keyed by glyph name. + + ``ttFont['COLR'][]`` will return the color layers for any glyph. + + ``ttFont['COLR'][] = `` will set the color layers for any glyph. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/colr + """ + + @staticmethod + def _decompileColorLayersV0(table): + if not table.LayerRecordArray: + return {} + colorLayerLists = {} + layerRecords = table.LayerRecordArray.LayerRecord + numLayerRecords = len(layerRecords) + for baseRec in table.BaseGlyphRecordArray.BaseGlyphRecord: + baseGlyph = baseRec.BaseGlyph + firstLayerIndex = baseRec.FirstLayerIndex + numLayers = baseRec.NumLayers + assert firstLayerIndex + numLayers <= numLayerRecords + layers = [] + for i in range(firstLayerIndex, firstLayerIndex + numLayers): + layerRec = layerRecords[i] + layers.append(LayerRecord(layerRec.LayerGlyph, layerRec.PaletteIndex)) + colorLayerLists[baseGlyph] = layers + return colorLayerLists + + def _toOTTable(self, ttFont): + from . import otTables + from fontTools.colorLib.builder import populateCOLRv0 + + tableClass = getattr(otTables, self.tableTag) + table = tableClass() + table.Version = self.version + + populateCOLRv0( + table, + { + baseGlyph: [(layer.name, layer.colorID) for layer in layers] + for baseGlyph, layers in self.ColorLayers.items() + }, + glyphMap=ttFont.getReverseGlyphMap(rebuild=True), + ) + return table + + def decompile(self, data, ttFont): + from .otBase import OTTableReader + from . import otTables + + # We use otData to decompile, but we adapt the decompiled otTables to the + # existing COLR v0 API for backward compatibility. + reader = OTTableReader(data, tableTag=self.tableTag) + tableClass = getattr(otTables, self.tableTag) + table = tableClass() + table.decompile(reader, ttFont) + + self.version = table.Version + if self.version == 0: + self.ColorLayers = self._decompileColorLayersV0(table) + else: + # for new versions, keep the raw otTables around + self.table = table + + def compile(self, ttFont): + from .otBase import OTTableWriter + + if hasattr(self, "table"): + table = self.table + else: + table = self._toOTTable(ttFont) + + writer = OTTableWriter(tableTag=self.tableTag) + table.compile(writer, ttFont) + return writer.getAllData() + + def toXML(self, writer, ttFont): + if hasattr(self, "table"): + self.table.toXML2(writer, ttFont) + else: + writer.simpletag("version", value=self.version) + writer.newline() + for baseGlyph in sorted(self.ColorLayers.keys(), key=ttFont.getGlyphID): + writer.begintag("ColorGlyph", name=baseGlyph) + writer.newline() + for layer in self.ColorLayers[baseGlyph]: + layer.toXML(writer, ttFont) + writer.endtag("ColorGlyph") + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + if name == "version": # old COLR v0 API + setattr(self, name, safeEval(attrs["value"])) + elif name == "ColorGlyph": + if not hasattr(self, "ColorLayers"): + self.ColorLayers = {} + glyphName = attrs["name"] + for element in content: + if isinstance(element, str): + continue + layers = [] + for element in content: + if isinstance(element, str): + continue + layer = LayerRecord() + layer.fromXML(element[0], element[1], element[2], ttFont) + layers.append(layer) + self.ColorLayers[glyphName] = layers + else: # new COLR v1 API + from . import otTables + + if not hasattr(self, "table"): + tableClass = getattr(otTables, self.tableTag) + self.table = tableClass() + self.table.fromXML(name, attrs, content, ttFont) + self.table.populateDefaults() + self.version = self.table.Version + + def __getitem__(self, glyphName): + if not isinstance(glyphName, str): + raise TypeError(f"expected str, found {type(glyphName).__name__}") + return self.ColorLayers[glyphName] + + def __setitem__(self, glyphName, value): + if not isinstance(glyphName, str): + raise TypeError(f"expected str, found {type(glyphName).__name__}") + if value is not None: + self.ColorLayers[glyphName] = value + elif glyphName in self.ColorLayers: + del self.ColorLayers[glyphName] + + def __delitem__(self, glyphName): + del self.ColorLayers[glyphName] + + +class LayerRecord(object): + def __init__(self, name=None, colorID=None): + self.name = name + self.colorID = colorID + + def toXML(self, writer, ttFont): + writer.simpletag("layer", name=self.name, colorID=self.colorID) + writer.newline() + + def fromXML(self, eltname, attrs, content, ttFont): + for name, value in attrs.items(): + if name == "name": + setattr(self, name, value) + else: + setattr(self, name, safeEval(value)) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_P_A_L_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_P_A_L_.py new file mode 100644 index 0000000000000000000000000000000000000000..5ec8c843c516f2ac31bbbc9ff2dd0166a3a0e159 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_P_A_L_.py @@ -0,0 +1,305 @@ +# Copyright 2013 Google, Inc. All Rights Reserved. +# +# Google Author(s): Behdad Esfahbod + +from fontTools.misc.textTools import bytesjoin, safeEval +from . import DefaultTable +import array +from collections import namedtuple +import struct +import sys + + +class table_C_P_A_L_(DefaultTable.DefaultTable): + """Color Palette table + + The ``CPAL`` table contains a set of one or more color palettes. The color + records in each palette can be referenced by the ``COLR`` table to specify + the colors used in a color glyph. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/cpal + """ + + NO_NAME_ID = 0xFFFF + DEFAULT_PALETTE_TYPE = 0 + + def __init__(self, tag=None): + DefaultTable.DefaultTable.__init__(self, tag) + self.palettes = [] + self.paletteTypes = [] + self.paletteLabels = [] + self.paletteEntryLabels = [] + + def decompile(self, data, ttFont): + ( + self.version, + self.numPaletteEntries, + numPalettes, + numColorRecords, + goffsetFirstColorRecord, + ) = struct.unpack(">HHHHL", data[:12]) + assert ( + self.version <= 1 + ), "Version of CPAL table is higher than I know how to handle" + self.palettes = [] + pos = 12 + for i in range(numPalettes): + startIndex = struct.unpack(">H", data[pos : pos + 2])[0] + assert startIndex + self.numPaletteEntries <= numColorRecords + pos += 2 + palette = [] + ppos = goffsetFirstColorRecord + startIndex * 4 + for j in range(self.numPaletteEntries): + palette.append(Color(*struct.unpack(">BBBB", data[ppos : ppos + 4]))) + ppos += 4 + self.palettes.append(palette) + if self.version == 0: + offsetToPaletteTypeArray = 0 + offsetToPaletteLabelArray = 0 + offsetToPaletteEntryLabelArray = 0 + else: + pos = 12 + numPalettes * 2 + ( + offsetToPaletteTypeArray, + offsetToPaletteLabelArray, + offsetToPaletteEntryLabelArray, + ) = struct.unpack(">LLL", data[pos : pos + 12]) + self.paletteTypes = self._decompileUInt32Array( + data, + offsetToPaletteTypeArray, + numPalettes, + default=self.DEFAULT_PALETTE_TYPE, + ) + self.paletteLabels = self._decompileUInt16Array( + data, offsetToPaletteLabelArray, numPalettes, default=self.NO_NAME_ID + ) + self.paletteEntryLabels = self._decompileUInt16Array( + data, + offsetToPaletteEntryLabelArray, + self.numPaletteEntries, + default=self.NO_NAME_ID, + ) + + def _decompileUInt16Array(self, data, offset, numElements, default=0): + if offset == 0: + return [default] * numElements + result = array.array("H", data[offset : offset + 2 * numElements]) + if sys.byteorder != "big": + result.byteswap() + assert len(result) == numElements, result + return result.tolist() + + def _decompileUInt32Array(self, data, offset, numElements, default=0): + if offset == 0: + return [default] * numElements + result = array.array("I", data[offset : offset + 4 * numElements]) + if sys.byteorder != "big": + result.byteswap() + assert len(result) == numElements, result + return result.tolist() + + def compile(self, ttFont): + colorRecordIndices, colorRecords = self._compileColorRecords() + paletteTypes = self._compilePaletteTypes() + paletteLabels = self._compilePaletteLabels() + paletteEntryLabels = self._compilePaletteEntryLabels() + numColorRecords = len(colorRecords) // 4 + offsetToFirstColorRecord = 12 + len(colorRecordIndices) + if self.version >= 1: + offsetToFirstColorRecord += 12 + header = struct.pack( + ">HHHHL", + self.version, + self.numPaletteEntries, + len(self.palettes), + numColorRecords, + offsetToFirstColorRecord, + ) + if self.version == 0: + dataList = [header, colorRecordIndices, colorRecords] + else: + pos = offsetToFirstColorRecord + len(colorRecords) + if len(paletteTypes) == 0: + offsetToPaletteTypeArray = 0 + else: + offsetToPaletteTypeArray = pos + pos += len(paletteTypes) + if len(paletteLabels) == 0: + offsetToPaletteLabelArray = 0 + else: + offsetToPaletteLabelArray = pos + pos += len(paletteLabels) + if len(paletteEntryLabels) == 0: + offsetToPaletteEntryLabelArray = 0 + else: + offsetToPaletteEntryLabelArray = pos + pos += len(paletteLabels) + header1 = struct.pack( + ">LLL", + offsetToPaletteTypeArray, + offsetToPaletteLabelArray, + offsetToPaletteEntryLabelArray, + ) + dataList = [ + header, + colorRecordIndices, + header1, + colorRecords, + paletteTypes, + paletteLabels, + paletteEntryLabels, + ] + return bytesjoin(dataList) + + def _compilePalette(self, palette): + assert len(palette) == self.numPaletteEntries + pack = lambda c: struct.pack(">BBBB", c.blue, c.green, c.red, c.alpha) + return bytesjoin([pack(color) for color in palette]) + + def _compileColorRecords(self): + colorRecords, colorRecordIndices, pool = [], [], {} + for palette in self.palettes: + packedPalette = self._compilePalette(palette) + if packedPalette in pool: + index = pool[packedPalette] + else: + index = len(colorRecords) + colorRecords.append(packedPalette) + pool[packedPalette] = index + colorRecordIndices.append(struct.pack(">H", index * self.numPaletteEntries)) + return bytesjoin(colorRecordIndices), bytesjoin(colorRecords) + + def _compilePaletteTypes(self): + if self.version == 0 or not any(self.paletteTypes): + return b"" + assert len(self.paletteTypes) == len(self.palettes) + result = bytesjoin([struct.pack(">I", ptype) for ptype in self.paletteTypes]) + assert len(result) == 4 * len(self.palettes) + return result + + def _compilePaletteLabels(self): + if self.version == 0 or all(l == self.NO_NAME_ID for l in self.paletteLabels): + return b"" + assert len(self.paletteLabels) == len(self.palettes) + result = bytesjoin([struct.pack(">H", label) for label in self.paletteLabels]) + assert len(result) == 2 * len(self.palettes) + return result + + def _compilePaletteEntryLabels(self): + if self.version == 0 or all( + l == self.NO_NAME_ID for l in self.paletteEntryLabels + ): + return b"" + assert len(self.paletteEntryLabels) == self.numPaletteEntries + result = bytesjoin( + [struct.pack(">H", label) for label in self.paletteEntryLabels] + ) + assert len(result) == 2 * self.numPaletteEntries + return result + + def toXML(self, writer, ttFont): + numPalettes = len(self.palettes) + paletteLabels = {i: nameID for (i, nameID) in enumerate(self.paletteLabels)} + paletteTypes = {i: typ for (i, typ) in enumerate(self.paletteTypes)} + writer.simpletag("version", value=self.version) + writer.newline() + writer.simpletag("numPaletteEntries", value=self.numPaletteEntries) + writer.newline() + for index, palette in enumerate(self.palettes): + attrs = {"index": index} + paletteType = paletteTypes.get(index, self.DEFAULT_PALETTE_TYPE) + paletteLabel = paletteLabels.get(index, self.NO_NAME_ID) + if self.version > 0 and paletteLabel != self.NO_NAME_ID: + attrs["label"] = paletteLabel + if self.version > 0 and paletteType != self.DEFAULT_PALETTE_TYPE: + attrs["type"] = paletteType + writer.begintag("palette", **attrs) + writer.newline() + if ( + self.version > 0 + and paletteLabel != self.NO_NAME_ID + and ttFont + and "name" in ttFont + ): + name = ttFont["name"].getDebugName(paletteLabel) + if name is not None: + writer.comment(name) + writer.newline() + assert len(palette) == self.numPaletteEntries + for cindex, color in enumerate(palette): + color.toXML(writer, ttFont, cindex) + writer.endtag("palette") + writer.newline() + if self.version > 0 and not all( + l == self.NO_NAME_ID for l in self.paletteEntryLabels + ): + writer.begintag("paletteEntryLabels") + writer.newline() + for index, label in enumerate(self.paletteEntryLabels): + if label != self.NO_NAME_ID: + writer.simpletag("label", index=index, value=label) + if self.version > 0 and label and ttFont and "name" in ttFont: + name = ttFont["name"].getDebugName(label) + if name is not None: + writer.comment(name) + writer.newline() + writer.endtag("paletteEntryLabels") + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + if name == "palette": + self.paletteLabels.append(int(attrs.get("label", self.NO_NAME_ID))) + self.paletteTypes.append(int(attrs.get("type", self.DEFAULT_PALETTE_TYPE))) + palette = [] + for element in content: + if isinstance(element, str): + continue + attrs = element[1] + color = Color.fromHex(attrs["value"]) + palette.append(color) + self.palettes.append(palette) + elif name == "paletteEntryLabels": + colorLabels = {} + for element in content: + if isinstance(element, str): + continue + elementName, elementAttr, _ = element + if elementName == "label": + labelIndex = safeEval(elementAttr["index"]) + nameID = safeEval(elementAttr["value"]) + colorLabels[labelIndex] = nameID + self.paletteEntryLabels = [ + colorLabels.get(i, self.NO_NAME_ID) + for i in range(self.numPaletteEntries) + ] + elif "value" in attrs: + value = safeEval(attrs["value"]) + setattr(self, name, value) + if name == "numPaletteEntries": + self.paletteEntryLabels = [self.NO_NAME_ID] * self.numPaletteEntries + + +class Color(namedtuple("Color", "blue green red alpha")): + def hex(self): + return "#%02X%02X%02X%02X" % (self.red, self.green, self.blue, self.alpha) + + def __repr__(self): + return self.hex() + + def toXML(self, writer, ttFont, index=None): + writer.simpletag("color", value=self.hex(), index=index) + writer.newline() + + @classmethod + def fromHex(cls, value): + if value[0] == "#": + value = value[1:] + red = int(value[0:2], 16) + green = int(value[2:4], 16) + blue = int(value[4:6], 16) + alpha = int(value[6:8], 16) if len(value) >= 8 else 0xFF + return cls(red=red, green=green, blue=blue, alpha=alpha) + + @classmethod + def fromRGBA(cls, red, green, blue, alpha): + return cls(red=red, green=green, blue=blue, alpha=alpha) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/D__e_b_g.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/D__e_b_g.py new file mode 100644 index 0000000000000000000000000000000000000000..cb1653d79d4f99ad729b25c96346459c40a4681e --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/D__e_b_g.py @@ -0,0 +1,35 @@ +import json +from textwrap import indent + +from . import DefaultTable +from fontTools.misc.textTools import tostr + + +class table_D__e_b_g(DefaultTable.DefaultTable): + def __init__(self, tag=None): + DefaultTable.DefaultTable.__init__(self, tag) + self.data = {} + + def decompile(self, data, ttFont): + self.data = json.loads(data) + + def compile(self, ttFont): + return json.dumps(self.data).encode("utf-8") + + def toXML(self, writer, ttFont): + # make sure json indentation inside CDATA block matches XMLWriter's + data = json.dumps(self.data, indent=len(writer.indentwhite)) + prefix = tostr(writer.indentwhite) * (writer.indentlevel + 1) + # but don't indent the first json line so it's adjacent to ` None: + if tag is None: + tag = getClassTag(self.__class__) + self.tableTag = Tag(tag) + + def decompile(self, data: bytes, ttFont: TTFont) -> None: + self.data = data + + def compile(self, ttFont: TTFont) -> bytes: + return self.data + + def toXML( + self, writer: XMLWriter, ttFont: TTFont, **kwargs: dict[str, Any] + ) -> None: + if hasattr(self, "ERROR"): + writer.comment("An error occurred during the decompilation of this table") + writer.newline() + writer.comment(self.ERROR) + writer.newline() + writer.begintag("hexdata") + writer.newline() + writer.dumphex(self.compile(ttFont)) + writer.endtag("hexdata") + writer.newline() + + def fromXML( + self, name: str, attrs: dict[str, str], content: str, ttFont: TTFont + ) -> None: + from fontTools import ttLib + from fontTools.misc.textTools import readHex + + if name != "hexdata": + raise ttLib.TTLibError("can't handle '%s' element" % name) + self.decompile(readHex(content), ttFont) + + def __repr__(self) -> str: + return "<'%s' table at %x>" % (self.tableTag, id(self)) + + def __eq__(self, other: Any) -> bool: + if type(self) != type(other): + return NotImplemented + return self.__dict__ == other.__dict__ + + def __ne__(self, other: Any) -> bool: + result = self.__eq__(other) + return result if result is NotImplemented else not result diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G_D_E_F_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G_D_E_F_.py new file mode 100644 index 0000000000000000000000000000000000000000..922a9cb2063777cae486a3369d3d6380f9f626cf --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G_D_E_F_.py @@ -0,0 +1,13 @@ +from .otBase import BaseTTXConverter + + +class table_G_D_E_F_(BaseTTXConverter): + """Glyph Definition table + + The ``GDEF`` table stores various glyph properties that are used + by OpenType Layout. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/gdef + """ + + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G_V_A_R_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G_V_A_R_.py new file mode 100644 index 0000000000000000000000000000000000000000..889b1f2a3bd712b68140a6b9102e732ce794587c --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G_V_A_R_.py @@ -0,0 +1,5 @@ +from ._g_v_a_r import table__g_v_a_r + + +class table_G_V_A_R_(table__g_v_a_r): + gid_size = 3 diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G__l_o_c.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G__l_o_c.py new file mode 100644 index 0000000000000000000000000000000000000000..4c3d78ab2e4b993708a83c13efe45c3c4a1eaf92 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G__l_o_c.py @@ -0,0 +1,85 @@ +from fontTools.misc import sstruct +from fontTools.misc.textTools import safeEval +from . import DefaultTable +import array +import sys + + +Gloc_header = """ + > # big endian + version: 16.16F # Table version + flags: H # bit 0: 1=long format, 0=short format + # bit 1: 1=attribute names, 0=no names + numAttribs: H # NUmber of attributes +""" + + +class table_G__l_o_c(DefaultTable.DefaultTable): + """Graphite Index to Glyph Atttributes table + + See also https://graphite.sil.org/graphite_techAbout#graphite-font-tables + """ + + dependencies = ["Glat"] + + def __init__(self, tag=None): + DefaultTable.DefaultTable.__init__(self, tag) + self.attribIds = None + self.numAttribs = 0 + + def decompile(self, data, ttFont): + _, data = sstruct.unpack2(Gloc_header, data, self) + flags = self.flags + del self.flags + self.locations = array.array("I" if flags & 1 else "H") + self.locations.frombytes(data[: len(data) - self.numAttribs * (flags & 2)]) + if sys.byteorder != "big": + self.locations.byteswap() + self.attribIds = array.array("H") + if flags & 2: + self.attribIds.frombytes(data[-self.numAttribs * 2 :]) + if sys.byteorder != "big": + self.attribIds.byteswap() + + def compile(self, ttFont): + data = sstruct.pack( + Gloc_header, + dict( + version=1.0, + flags=(bool(self.attribIds) << 1) + (self.locations.typecode == "I"), + numAttribs=self.numAttribs, + ), + ) + if sys.byteorder != "big": + self.locations.byteswap() + data += self.locations.tobytes() + if sys.byteorder != "big": + self.locations.byteswap() + if self.attribIds: + if sys.byteorder != "big": + self.attribIds.byteswap() + data += self.attribIds.tobytes() + if sys.byteorder != "big": + self.attribIds.byteswap() + return data + + def set(self, locations): + long_format = max(locations) >= 65536 + self.locations = array.array("I" if long_format else "H", locations) + + def toXML(self, writer, ttFont): + writer.simpletag("attributes", number=self.numAttribs) + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + if name == "attributes": + self.numAttribs = int(safeEval(attrs["number"])) + + def __getitem__(self, index): + return self.locations[index] + + def __len__(self): + return len(self.locations) + + def __iter__(self): + return iter(self.locations) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/H_V_A_R_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/H_V_A_R_.py new file mode 100644 index 0000000000000000000000000000000000000000..48e7fd67cf0f89e5dc6057e5cbae7f07324a0402 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/H_V_A_R_.py @@ -0,0 +1,13 @@ +from .otBase import BaseTTXConverter + + +class table_H_V_A_R_(BaseTTXConverter): + """Horizontal Metrics Variations table + + The ``HVAR`` table contains variations in horizontal glyph metrics + in variable fonts. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/hvar + """ + + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/J_S_T_F_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/J_S_T_F_.py new file mode 100644 index 0000000000000000000000000000000000000000..b185f30f3a9a2978c1d4278b920f69969fe79b97 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/J_S_T_F_.py @@ -0,0 +1,13 @@ +from .otBase import BaseTTXConverter + + +class table_J_S_T_F_(BaseTTXConverter): + """Justification table + + The ``JSTF`` table contains glyph substitution and positioning + data used to perform text justification. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/jstf + """ + + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/L_T_S_H_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/L_T_S_H_.py new file mode 100644 index 0000000000000000000000000000000000000000..e691c06e9bfdc270127c2a5be33acf6505177d85 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/L_T_S_H_.py @@ -0,0 +1,58 @@ +from fontTools.misc.textTools import safeEval +from . import DefaultTable +import struct +import array + +# XXX I've lowered the strictness, to make sure Apple's own Chicago +# XXX gets through. They're looking into it, I hope to raise the standards +# XXX back to normal eventually. + + +class table_L_T_S_H_(DefaultTable.DefaultTable): + """Linear Threshold table + + The ``LTSH`` table contains per-glyph settings indicating the ppem sizes + at which the advance width metric should be scaled linearly, despite the + effects of any TrueType instructions that might otherwise alter the + advance width. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/ltsh + """ + + def decompile(self, data, ttFont): + version, numGlyphs = struct.unpack(">HH", data[:4]) + data = data[4:] + assert version == 0, "unknown version: %s" % version + assert (len(data) % numGlyphs) < 4, "numGlyphs doesn't match data length" + # ouch: the assertion is not true in Chicago! + # assert numGlyphs == ttFont['maxp'].numGlyphs + yPels = array.array("B") + yPels.frombytes(data) + self.yPels = {} + for i in range(numGlyphs): + self.yPels[ttFont.getGlyphName(i)] = yPels[i] + + def compile(self, ttFont): + version = 0 + names = list(self.yPels.keys()) + numGlyphs = len(names) + yPels = [0] * numGlyphs + # ouch: the assertion is not true in Chicago! + # assert len(self.yPels) == ttFont['maxp'].numGlyphs == numGlyphs + for name in names: + yPels[ttFont.getGlyphID(name)] = self.yPels[name] + yPels = array.array("B", yPels) + return struct.pack(">HH", version, numGlyphs) + yPels.tobytes() + + def toXML(self, writer, ttFont): + names = sorted(self.yPels.keys()) + for name in names: + writer.simpletag("yPel", name=name, value=self.yPels[name]) + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + if not hasattr(self, "yPels"): + self.yPels = {} + if name != "yPel": + return # ignore unknown tags + self.yPels[attrs["name"]] = safeEval(attrs["value"]) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/M_V_A_R_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/M_V_A_R_.py new file mode 100644 index 0000000000000000000000000000000000000000..c7e7e90fb49965b962f502a3ac9135a1c00b0374 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/M_V_A_R_.py @@ -0,0 +1,13 @@ +from .otBase import BaseTTXConverter + + +class table_M_V_A_R_(BaseTTXConverter): + """Metrics Variations table + + The ``MVAR`` table contains variation information for font-wide + metrics in a variable font. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/mvar + """ + + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/O_S_2f_2.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/O_S_2f_2.py new file mode 100644 index 0000000000000000000000000000000000000000..9a7e5f70bb99a37ad5f1260d62b7406df9361771 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/O_S_2f_2.py @@ -0,0 +1,752 @@ +from fontTools.misc import sstruct +from fontTools.misc.roundTools import otRound +from fontTools.misc.textTools import safeEval, num2binary, binary2num +from fontTools.ttLib.tables import DefaultTable +import bisect +import logging + + +log = logging.getLogger(__name__) + +# panose classification + +panoseFormat = """ + bFamilyType: B + bSerifStyle: B + bWeight: B + bProportion: B + bContrast: B + bStrokeVariation: B + bArmStyle: B + bLetterForm: B + bMidline: B + bXHeight: B +""" + + +class Panose(object): + def __init__(self, **kwargs): + _, names, _ = sstruct.getformat(panoseFormat) + for name in names: + setattr(self, name, kwargs.pop(name, 0)) + for k in kwargs: + raise TypeError(f"Panose() got an unexpected keyword argument {k!r}") + + def toXML(self, writer, ttFont): + formatstring, names, fixes = sstruct.getformat(panoseFormat) + for name in names: + writer.simpletag(name, value=getattr(self, name)) + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + setattr(self, name, safeEval(attrs["value"])) + + +# 'sfnt' OS/2 and Windows Metrics table - 'OS/2' + +OS2_format_0 = """ + > # big endian + version: H # version + xAvgCharWidth: h # average character width + usWeightClass: H # degree of thickness of strokes + usWidthClass: H # aspect ratio + fsType: H # type flags + ySubscriptXSize: h # subscript horizontal font size + ySubscriptYSize: h # subscript vertical font size + ySubscriptXOffset: h # subscript x offset + ySubscriptYOffset: h # subscript y offset + ySuperscriptXSize: h # superscript horizontal font size + ySuperscriptYSize: h # superscript vertical font size + ySuperscriptXOffset: h # superscript x offset + ySuperscriptYOffset: h # superscript y offset + yStrikeoutSize: h # strikeout size + yStrikeoutPosition: h # strikeout position + sFamilyClass: h # font family class and subclass + panose: 10s # panose classification number + ulUnicodeRange1: L # character range + ulUnicodeRange2: L # character range + ulUnicodeRange3: L # character range + ulUnicodeRange4: L # character range + achVendID: 4s # font vendor identification + fsSelection: H # font selection flags + usFirstCharIndex: H # first unicode character index + usLastCharIndex: H # last unicode character index + sTypoAscender: h # typographic ascender + sTypoDescender: h # typographic descender + sTypoLineGap: h # typographic line gap + usWinAscent: H # Windows ascender + usWinDescent: H # Windows descender +""" + +OS2_format_1_addition = """ + ulCodePageRange1: L + ulCodePageRange2: L +""" + +OS2_format_2_addition = ( + OS2_format_1_addition + + """ + sxHeight: h + sCapHeight: h + usDefaultChar: H + usBreakChar: H + usMaxContext: H +""" +) + +OS2_format_5_addition = ( + OS2_format_2_addition + + """ + usLowerOpticalPointSize: H + usUpperOpticalPointSize: H +""" +) + +bigendian = " > # big endian\n" + +OS2_format_1 = OS2_format_0 + OS2_format_1_addition +OS2_format_2 = OS2_format_0 + OS2_format_2_addition +OS2_format_5 = OS2_format_0 + OS2_format_5_addition +OS2_format_1_addition = bigendian + OS2_format_1_addition +OS2_format_2_addition = bigendian + OS2_format_2_addition +OS2_format_5_addition = bigendian + OS2_format_5_addition + + +class table_O_S_2f_2(DefaultTable.DefaultTable): + """OS/2 and Windows Metrics table + + The ``OS/2`` table contains a variety of font-wide metrics and + parameters that may be useful to an operating system or other + software for system-integration purposes. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/os2 + """ + + dependencies = ["head"] + + def decompile(self, data, ttFont): + dummy, data = sstruct.unpack2(OS2_format_0, data, self) + + if self.version == 1: + dummy, data = sstruct.unpack2(OS2_format_1_addition, data, self) + elif self.version in (2, 3, 4): + dummy, data = sstruct.unpack2(OS2_format_2_addition, data, self) + elif self.version == 5: + dummy, data = sstruct.unpack2(OS2_format_5_addition, data, self) + self.usLowerOpticalPointSize /= 20 + self.usUpperOpticalPointSize /= 20 + elif self.version != 0: + from fontTools import ttLib + + raise ttLib.TTLibError( + "unknown format for OS/2 table: version %s" % self.version + ) + if len(data): + log.warning("too much 'OS/2' table data") + + self.panose = sstruct.unpack(panoseFormat, self.panose, Panose()) + + def compile(self, ttFont): + self.updateFirstAndLastCharIndex(ttFont) + panose = self.panose + head = ttFont["head"] + if (self.fsSelection & 1) and not (head.macStyle & 1 << 1): + log.warning( + "fsSelection bit 0 (italic) and " + "head table macStyle bit 1 (italic) should match" + ) + if (self.fsSelection & 1 << 5) and not (head.macStyle & 1): + log.warning( + "fsSelection bit 5 (bold) and " + "head table macStyle bit 0 (bold) should match" + ) + if (self.fsSelection & 1 << 6) and (self.fsSelection & 1 + (1 << 5)): + log.warning( + "fsSelection bit 6 (regular) is set, " + "bits 0 (italic) and 5 (bold) must be clear" + ) + if self.version < 4 and self.fsSelection & 0b1110000000: + log.warning( + "fsSelection bits 7, 8 and 9 are only defined in " + "OS/2 table version 4 and up: version %s", + self.version, + ) + self.panose = sstruct.pack(panoseFormat, self.panose) + if self.version == 0: + data = sstruct.pack(OS2_format_0, self) + elif self.version == 1: + data = sstruct.pack(OS2_format_1, self) + elif self.version in (2, 3, 4): + data = sstruct.pack(OS2_format_2, self) + elif self.version == 5: + d = self.__dict__.copy() + d["usLowerOpticalPointSize"] = round(self.usLowerOpticalPointSize * 20) + d["usUpperOpticalPointSize"] = round(self.usUpperOpticalPointSize * 20) + data = sstruct.pack(OS2_format_5, d) + else: + from fontTools import ttLib + + raise ttLib.TTLibError( + "unknown format for OS/2 table: version %s" % self.version + ) + self.panose = panose + return data + + def toXML(self, writer, ttFont): + writer.comment( + "The fields 'usFirstCharIndex' and 'usLastCharIndex'\n" + "will be recalculated by the compiler" + ) + writer.newline() + if self.version == 1: + format = OS2_format_1 + elif self.version in (2, 3, 4): + format = OS2_format_2 + elif self.version == 5: + format = OS2_format_5 + else: + format = OS2_format_0 + formatstring, names, fixes = sstruct.getformat(format) + for name in names: + value = getattr(self, name) + if name == "panose": + writer.begintag("panose") + writer.newline() + value.toXML(writer, ttFont) + writer.endtag("panose") + elif name in ( + "ulUnicodeRange1", + "ulUnicodeRange2", + "ulUnicodeRange3", + "ulUnicodeRange4", + "ulCodePageRange1", + "ulCodePageRange2", + ): + writer.simpletag(name, value=num2binary(value)) + elif name in ("fsType", "fsSelection"): + writer.simpletag(name, value=num2binary(value, 16)) + elif name == "achVendID": + writer.simpletag(name, value=repr(value)[1:-1]) + else: + writer.simpletag(name, value=value) + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + if name == "panose": + self.panose = panose = Panose() + for element in content: + if isinstance(element, tuple): + name, attrs, content = element + panose.fromXML(name, attrs, content, ttFont) + elif name in ( + "ulUnicodeRange1", + "ulUnicodeRange2", + "ulUnicodeRange3", + "ulUnicodeRange4", + "ulCodePageRange1", + "ulCodePageRange2", + "fsType", + "fsSelection", + ): + setattr(self, name, binary2num(attrs["value"])) + elif name == "achVendID": + setattr(self, name, safeEval("'''" + attrs["value"] + "'''")) + else: + setattr(self, name, safeEval(attrs["value"])) + + def updateFirstAndLastCharIndex(self, ttFont): + if "cmap" not in ttFont: + return + codes = set() + for table in getattr(ttFont["cmap"], "tables", []): + if table.isUnicode(): + codes.update(table.cmap.keys()) + if codes: + minCode = min(codes) + maxCode = max(codes) + # USHORT cannot hold codepoints greater than 0xFFFF + self.usFirstCharIndex = min(0xFFFF, minCode) + self.usLastCharIndex = min(0xFFFF, maxCode) + + # misspelled attributes kept for legacy reasons + + @property + def usMaxContex(self): + return self.usMaxContext + + @usMaxContex.setter + def usMaxContex(self, value): + self.usMaxContext = value + + @property + def fsFirstCharIndex(self): + return self.usFirstCharIndex + + @fsFirstCharIndex.setter + def fsFirstCharIndex(self, value): + self.usFirstCharIndex = value + + @property + def fsLastCharIndex(self): + return self.usLastCharIndex + + @fsLastCharIndex.setter + def fsLastCharIndex(self, value): + self.usLastCharIndex = value + + 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): + bits.add(i) + if ul2 & (1 << i): + bits.add(i + 32) + if ul3 & (1 << i): + bits.add(i + 64) + if ul4 & (1 << i): + bits.add(i + 96) + return bits + + 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) + elif 64 <= bit < 96: + ul3 |= 1 << (bit - 64) + elif 96 <= bit < 123: + ul4 |= 1 << (bit - 96) + else: + raise ValueError("expected 0 <= int <= 122, found: %r" % bit) + self.ulUnicodeRange1, self.ulUnicodeRange2 = ul1, ul2 + self.ulUnicodeRange3, self.ulUnicodeRange4 = ul3, ul4 + + 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. + If 'pruneOnly' is True, only clear unused bits with NO intersection. + """ + unicodes = set() + for table in ttFont["cmap"].tables: + if table.isUnicode(): + unicodes.update(table.cmap.keys()) + if pruneOnly: + empty = intersectUnicodeRanges(unicodes, inverse=True) + bits = self.getUnicodeRanges() - empty + else: + bits = intersectUnicodeRanges(unicodes) + self.setUnicodeRanges(bits) + return bits + + 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): + bits.add(i) + if ul2 & (1 << i): + bits.add(i + 32) + return bits + + 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: + raise ValueError(f"expected 0 <= int <= 63, found: {bit:r}") + if self.version < 1: + self.version = 1 + self.ulCodePageRange1, self.ulCodePageRange2 = ul1, ul2 + + def recalcCodePageRanges(self, ttFont, pruneOnly=False): + unicodes = set() + for table in ttFont["cmap"].tables: + if table.isUnicode(): + unicodes.update(table.cmap.keys()) + bits = calcCodePageRanges(unicodes) + if pruneOnly: + bits &= self.getCodePageRanges() + # when no codepage ranges can be enabled, fall back to enabling bit 0 + # (Latin 1) so that the font works in MS Word: + # https://github.com/googlei18n/fontmake/issues/468 + if not bits: + bits = {0} + self.setCodePageRanges(bits) + return bits + + 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 width, _ in hmtx.metrics.values() if width > 0] + if widths: + avg_width = otRound(sum(widths) / len(widths)) + self.xAvgCharWidth = avg_width + return avg_width + + +# Unicode ranges data from the OpenType OS/2 table specification v1.7 + +OS2_UNICODE_RANGES = ( + (("Basic Latin", (0x0000, 0x007F)),), + (("Latin-1 Supplement", (0x0080, 0x00FF)),), + (("Latin Extended-A", (0x0100, 0x017F)),), + (("Latin Extended-B", (0x0180, 0x024F)),), + ( + ("IPA Extensions", (0x0250, 0x02AF)), + ("Phonetic Extensions", (0x1D00, 0x1D7F)), + ("Phonetic Extensions Supplement", (0x1D80, 0x1DBF)), + ), + ( + ("Spacing Modifier Letters", (0x02B0, 0x02FF)), + ("Modifier Tone Letters", (0xA700, 0xA71F)), + ), + ( + ("Combining Diacritical Marks", (0x0300, 0x036F)), + ("Combining Diacritical Marks Supplement", (0x1DC0, 0x1DFF)), + ), + (("Greek and Coptic", (0x0370, 0x03FF)),), + (("Coptic", (0x2C80, 0x2CFF)),), + ( + ("Cyrillic", (0x0400, 0x04FF)), + ("Cyrillic Supplement", (0x0500, 0x052F)), + ("Cyrillic Extended-A", (0x2DE0, 0x2DFF)), + ("Cyrillic Extended-B", (0xA640, 0xA69F)), + ), + (("Armenian", (0x0530, 0x058F)),), + (("Hebrew", (0x0590, 0x05FF)),), + (("Vai", (0xA500, 0xA63F)),), + (("Arabic", (0x0600, 0x06FF)), ("Arabic Supplement", (0x0750, 0x077F))), + (("NKo", (0x07C0, 0x07FF)),), + (("Devanagari", (0x0900, 0x097F)),), + (("Bengali", (0x0980, 0x09FF)),), + (("Gurmukhi", (0x0A00, 0x0A7F)),), + (("Gujarati", (0x0A80, 0x0AFF)),), + (("Oriya", (0x0B00, 0x0B7F)),), + (("Tamil", (0x0B80, 0x0BFF)),), + (("Telugu", (0x0C00, 0x0C7F)),), + (("Kannada", (0x0C80, 0x0CFF)),), + (("Malayalam", (0x0D00, 0x0D7F)),), + (("Thai", (0x0E00, 0x0E7F)),), + (("Lao", (0x0E80, 0x0EFF)),), + (("Georgian", (0x10A0, 0x10FF)), ("Georgian Supplement", (0x2D00, 0x2D2F))), + (("Balinese", (0x1B00, 0x1B7F)),), + (("Hangul Jamo", (0x1100, 0x11FF)),), + ( + ("Latin Extended Additional", (0x1E00, 0x1EFF)), + ("Latin Extended-C", (0x2C60, 0x2C7F)), + ("Latin Extended-D", (0xA720, 0xA7FF)), + ), + (("Greek Extended", (0x1F00, 0x1FFF)),), + ( + ("General Punctuation", (0x2000, 0x206F)), + ("Supplemental Punctuation", (0x2E00, 0x2E7F)), + ), + (("Superscripts And Subscripts", (0x2070, 0x209F)),), + (("Currency Symbols", (0x20A0, 0x20CF)),), + (("Combining Diacritical Marks For Symbols", (0x20D0, 0x20FF)),), + (("Letterlike Symbols", (0x2100, 0x214F)),), + (("Number Forms", (0x2150, 0x218F)),), + ( + ("Arrows", (0x2190, 0x21FF)), + ("Supplemental Arrows-A", (0x27F0, 0x27FF)), + ("Supplemental Arrows-B", (0x2900, 0x297F)), + ("Miscellaneous Symbols and Arrows", (0x2B00, 0x2BFF)), + ), + ( + ("Mathematical Operators", (0x2200, 0x22FF)), + ("Supplemental Mathematical Operators", (0x2A00, 0x2AFF)), + ("Miscellaneous Mathematical Symbols-A", (0x27C0, 0x27EF)), + ("Miscellaneous Mathematical Symbols-B", (0x2980, 0x29FF)), + ), + (("Miscellaneous Technical", (0x2300, 0x23FF)),), + (("Control Pictures", (0x2400, 0x243F)),), + (("Optical Character Recognition", (0x2440, 0x245F)),), + (("Enclosed Alphanumerics", (0x2460, 0x24FF)),), + (("Box Drawing", (0x2500, 0x257F)),), + (("Block Elements", (0x2580, 0x259F)),), + (("Geometric Shapes", (0x25A0, 0x25FF)),), + (("Miscellaneous Symbols", (0x2600, 0x26FF)),), + (("Dingbats", (0x2700, 0x27BF)),), + (("CJK Symbols And Punctuation", (0x3000, 0x303F)),), + (("Hiragana", (0x3040, 0x309F)),), + ( + ("Katakana", (0x30A0, 0x30FF)), + ("Katakana Phonetic Extensions", (0x31F0, 0x31FF)), + ), + (("Bopomofo", (0x3100, 0x312F)), ("Bopomofo Extended", (0x31A0, 0x31BF))), + (("Hangul Compatibility Jamo", (0x3130, 0x318F)),), + (("Phags-pa", (0xA840, 0xA87F)),), + (("Enclosed CJK Letters And Months", (0x3200, 0x32FF)),), + (("CJK Compatibility", (0x3300, 0x33FF)),), + (("Hangul Syllables", (0xAC00, 0xD7AF)),), + (("Non-Plane 0 *", (0xD800, 0xDFFF)),), + (("Phoenician", (0x10900, 0x1091F)),), + ( + ("CJK Unified Ideographs", (0x4E00, 0x9FFF)), + ("CJK Radicals Supplement", (0x2E80, 0x2EFF)), + ("Kangxi Radicals", (0x2F00, 0x2FDF)), + ("Ideographic Description Characters", (0x2FF0, 0x2FFF)), + ("CJK Unified Ideographs Extension A", (0x3400, 0x4DBF)), + ("CJK Unified Ideographs Extension B", (0x20000, 0x2A6DF)), + ("Kanbun", (0x3190, 0x319F)), + ), + (("Private Use Area (plane 0)", (0xE000, 0xF8FF)),), + ( + ("CJK Strokes", (0x31C0, 0x31EF)), + ("CJK Compatibility Ideographs", (0xF900, 0xFAFF)), + ("CJK Compatibility Ideographs Supplement", (0x2F800, 0x2FA1F)), + ), + (("Alphabetic Presentation Forms", (0xFB00, 0xFB4F)),), + (("Arabic Presentation Forms-A", (0xFB50, 0xFDFF)),), + (("Combining Half Marks", (0xFE20, 0xFE2F)),), + ( + ("Vertical Forms", (0xFE10, 0xFE1F)), + ("CJK Compatibility Forms", (0xFE30, 0xFE4F)), + ), + (("Small Form Variants", (0xFE50, 0xFE6F)),), + (("Arabic Presentation Forms-B", (0xFE70, 0xFEFF)),), + (("Halfwidth And Fullwidth Forms", (0xFF00, 0xFFEF)),), + (("Specials", (0xFFF0, 0xFFFF)),), + (("Tibetan", (0x0F00, 0x0FFF)),), + (("Syriac", (0x0700, 0x074F)),), + (("Thaana", (0x0780, 0x07BF)),), + (("Sinhala", (0x0D80, 0x0DFF)),), + (("Myanmar", (0x1000, 0x109F)),), + ( + ("Ethiopic", (0x1200, 0x137F)), + ("Ethiopic Supplement", (0x1380, 0x139F)), + ("Ethiopic Extended", (0x2D80, 0x2DDF)), + ), + (("Cherokee", (0x13A0, 0x13FF)),), + (("Unified Canadian Aboriginal Syllabics", (0x1400, 0x167F)),), + (("Ogham", (0x1680, 0x169F)),), + (("Runic", (0x16A0, 0x16FF)),), + (("Khmer", (0x1780, 0x17FF)), ("Khmer Symbols", (0x19E0, 0x19FF))), + (("Mongolian", (0x1800, 0x18AF)),), + (("Braille Patterns", (0x2800, 0x28FF)),), + (("Yi Syllables", (0xA000, 0xA48F)), ("Yi Radicals", (0xA490, 0xA4CF))), + ( + ("Tagalog", (0x1700, 0x171F)), + ("Hanunoo", (0x1720, 0x173F)), + ("Buhid", (0x1740, 0x175F)), + ("Tagbanwa", (0x1760, 0x177F)), + ), + (("Old Italic", (0x10300, 0x1032F)),), + (("Gothic", (0x10330, 0x1034F)),), + (("Deseret", (0x10400, 0x1044F)),), + ( + ("Byzantine Musical Symbols", (0x1D000, 0x1D0FF)), + ("Musical Symbols", (0x1D100, 0x1D1FF)), + ("Ancient Greek Musical Notation", (0x1D200, 0x1D24F)), + ), + (("Mathematical Alphanumeric Symbols", (0x1D400, 0x1D7FF)),), + ( + ("Private Use (plane 15)", (0xF0000, 0xFFFFD)), + ("Private Use (plane 16)", (0x100000, 0x10FFFD)), + ), + ( + ("Variation Selectors", (0xFE00, 0xFE0F)), + ("Variation Selectors Supplement", (0xE0100, 0xE01EF)), + ), + (("Tags", (0xE0000, 0xE007F)),), + (("Limbu", (0x1900, 0x194F)),), + (("Tai Le", (0x1950, 0x197F)),), + (("New Tai Lue", (0x1980, 0x19DF)),), + (("Buginese", (0x1A00, 0x1A1F)),), + (("Glagolitic", (0x2C00, 0x2C5F)),), + (("Tifinagh", (0x2D30, 0x2D7F)),), + (("Yijing Hexagram Symbols", (0x4DC0, 0x4DFF)),), + (("Syloti Nagri", (0xA800, 0xA82F)),), + ( + ("Linear B Syllabary", (0x10000, 0x1007F)), + ("Linear B Ideograms", (0x10080, 0x100FF)), + ("Aegean Numbers", (0x10100, 0x1013F)), + ), + (("Ancient Greek Numbers", (0x10140, 0x1018F)),), + (("Ugaritic", (0x10380, 0x1039F)),), + (("Old Persian", (0x103A0, 0x103DF)),), + (("Shavian", (0x10450, 0x1047F)),), + (("Osmanya", (0x10480, 0x104AF)),), + (("Cypriot Syllabary", (0x10800, 0x1083F)),), + (("Kharoshthi", (0x10A00, 0x10A5F)),), + (("Tai Xuan Jing Symbols", (0x1D300, 0x1D35F)),), + ( + ("Cuneiform", (0x12000, 0x123FF)), + ("Cuneiform Numbers and Punctuation", (0x12400, 0x1247F)), + ), + (("Counting Rod Numerals", (0x1D360, 0x1D37F)),), + (("Sundanese", (0x1B80, 0x1BBF)),), + (("Lepcha", (0x1C00, 0x1C4F)),), + (("Ol Chiki", (0x1C50, 0x1C7F)),), + (("Saurashtra", (0xA880, 0xA8DF)),), + (("Kayah Li", (0xA900, 0xA92F)),), + (("Rejang", (0xA930, 0xA95F)),), + (("Cham", (0xAA00, 0xAA5F)),), + (("Ancient Symbols", (0x10190, 0x101CF)),), + (("Phaistos Disc", (0x101D0, 0x101FF)),), + ( + ("Carian", (0x102A0, 0x102DF)), + ("Lycian", (0x10280, 0x1029F)), + ("Lydian", (0x10920, 0x1093F)), + ), + (("Domino Tiles", (0x1F030, 0x1F09F)), ("Mahjong Tiles", (0x1F000, 0x1F02F))), +) + + +_unicodeStarts = [] +_unicodeValues = [None] + + +def _getUnicodeRanges(): + # build the ranges of codepoints for each unicode range bit, and cache result + if not _unicodeStarts: + unicodeRanges = [ + (start, (stop, bit)) + for bit, blocks in enumerate(OS2_UNICODE_RANGES) + for _, (start, stop) in blocks + ] + for start, (stop, bit) in sorted(unicodeRanges): + _unicodeStarts.append(start) + _unicodeValues.append((stop, bit)) + return _unicodeStarts, _unicodeValues + + +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 the bits for which there is NO intersection. + + >>> intersectUnicodeRanges([0x0410]) == {9} + True + >>> intersectUnicodeRanges([0x0410, 0x1F000]) == {9, 57, 122} + True + >>> intersectUnicodeRanges([0x0410, 0x1F000], inverse=True) == ( + ... set(range(len(OS2_UNICODE_RANGES))) - {9, 57, 122}) + True + """ + unicodes = set(unicodes) + unicodestarts, unicodevalues = _getUnicodeRanges() + bits = set() + for code in unicodes: + stop, bit = unicodevalues[bisect.bisect(unicodestarts, code)] + if code <= stop: + bits.add(bit) + # The spec says that bit 57 ("Non Plane 0") implies that there's + # at least one codepoint beyond the BMP; so I also include all + # the non-BMP codepoints here + if any(0x10000 <= code < 0x110000 for code in unicodes): + bits.add(57) + return set(range(len(OS2_UNICODE_RANGES))) - bits if inverse else bits + + +def calcCodePageRanges(unicodes): + """Given a set of Unicode codepoints (integers), calculate the + corresponding OS/2 CodePage range bits. + This is a direct translation of FontForge implementation: + https://github.com/fontforge/fontforge/blob/7b2c074/fontforge/tottf.c#L3158 + """ + bits = set() + hasAscii = set(range(0x20, 0x7E)).issubset(unicodes) + hasLineart = ord("┤") in unicodes + + for uni in unicodes: + if uni == ord("Þ") and hasAscii: + bits.add(0) # Latin 1 + elif uni == ord("Ľ") and hasAscii: + bits.add(1) # Latin 2: Eastern Europe + if hasLineart: + bits.add(58) # Latin 2 + elif uni == ord("Б"): + bits.add(2) # Cyrillic + if ord("Ѕ") in unicodes and hasLineart: + bits.add(57) # IBM Cyrillic + if ord("╜") in unicodes and hasLineart: + bits.add(49) # MS-DOS Russian + elif uni == ord("Ά"): + bits.add(3) # Greek + if hasLineart and ord("½") in unicodes: + bits.add(48) # IBM Greek + if hasLineart and ord("√") in unicodes: + bits.add(60) # Greek, former 437 G + elif uni == ord("İ") and hasAscii: + bits.add(4) # Turkish + if hasLineart: + bits.add(56) # IBM turkish + elif uni == ord("א"): + bits.add(5) # Hebrew + if hasLineart and ord("√") in unicodes: + bits.add(53) # Hebrew + elif uni == ord("ر"): + bits.add(6) # Arabic + if ord("√") in unicodes: + bits.add(51) # Arabic + if hasLineart: + bits.add(61) # Arabic; ASMO 708 + elif uni == ord("ŗ") and hasAscii: + bits.add(7) # Windows Baltic + if hasLineart: + bits.add(59) # MS-DOS Baltic + elif uni == ord("₫") and hasAscii: + bits.add(8) # Vietnamese + elif uni == ord("ๅ"): + bits.add(16) # Thai + elif uni == ord("エ"): + bits.add(17) # JIS/Japan + elif uni == ord("ㄅ"): + bits.add(18) # Chinese: Simplified + elif uni == ord("ㄱ"): + bits.add(19) # Korean wansung + elif uni == ord("央"): + bits.add(20) # Chinese: Traditional + elif uni == ord("곴"): + bits.add(21) # Korean Johab + elif uni == ord("♥") and hasAscii: + bits.add(30) # OEM Character Set + # TODO: Symbol bit has a special meaning (check the spec), we need + # to confirm if this is wanted by default. + # elif chr(0xF000) <= char <= chr(0xF0FF): + # codepageRanges.add(31) # Symbol Character Set + elif uni == ord("þ") and hasAscii and hasLineart: + bits.add(54) # MS-DOS Icelandic + elif uni == ord("╚") and hasAscii: + bits.add(62) # WE/Latin 1 + bits.add(63) # US + elif hasAscii and hasLineart and ord("√") in unicodes: + if uni == ord("Å"): + bits.add(50) # MS-DOS Nordic + elif uni == ord("é"): + bits.add(52) # MS-DOS Canadian French + elif uni == ord("õ"): + bits.add(55) # MS-DOS Portuguese + + if hasAscii and ord("‰") in unicodes and ord("∑") in unicodes: + bits.add(29) # Macintosh Character Set (US Roman) + + return bits + + +if __name__ == "__main__": + import doctest, sys + + sys.exit(doctest.testmod().failed) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/S_T_A_T_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/S_T_A_T_.py new file mode 100644 index 0000000000000000000000000000000000000000..86e1271a9817ecb71b663e60ffa685cbf9205bd5 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/S_T_A_T_.py @@ -0,0 +1,15 @@ +from .otBase import BaseTTXConverter + + +class table_S_T_A_T_(BaseTTXConverter): + """Style Attributes table + + The ``STAT`` table records stylistic or typeface-design attributes that + differentiate the individual fonts within a font family from one another. + Those attributes can be used to assist users when navigating the style + variations of a variable font or a family of static fonts. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/stat + """ + + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/S__i_l_l.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/S__i_l_l.py new file mode 100644 index 0000000000000000000000000000000000000000..61106ea5284ac67219590d87544d44e2e1f970c2 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/S__i_l_l.py @@ -0,0 +1,92 @@ +from fontTools.misc import sstruct +from fontTools.misc.fixedTools import floatToFixedToStr +from fontTools.misc.textTools import safeEval +from . import DefaultTable +from . import grUtils +import struct + +Sill_hdr = """ + > + version: 16.16F +""" + + +class table_S__i_l_l(DefaultTable.DefaultTable): + """Graphite Languages table + + See also https://graphite.sil.org/graphite_techAbout#graphite-font-tables + """ + + def __init__(self, tag=None): + DefaultTable.DefaultTable.__init__(self, tag) + self.langs = {} + + def decompile(self, data, ttFont): + (_, data) = sstruct.unpack2(Sill_hdr, data, self) + self.version = float(floatToFixedToStr(self.version, precisionBits=16)) + (numLangs,) = struct.unpack(">H", data[:2]) + data = data[8:] + maxsetting = 0 + langinfo = [] + for i in range(numLangs): + (langcode, numsettings, offset) = struct.unpack( + ">4sHH", data[i * 8 : (i + 1) * 8] + ) + offset = int(offset / 8) - (numLangs + 1) + langcode = langcode.replace(b"\000", b"") + langinfo.append((langcode.decode("utf-8"), numsettings, offset)) + maxsetting = max(maxsetting, offset + numsettings) + data = data[numLangs * 8 :] + finfo = [] + for i in range(maxsetting): + (fid, val, _) = struct.unpack(">LHH", data[i * 8 : (i + 1) * 8]) + finfo.append((fid, val)) + self.langs = {} + for c, n, o in langinfo: + self.langs[c] = [] + for i in range(o, o + n): + self.langs[c].append(finfo[i]) + + def compile(self, ttFont): + ldat = b"" + fdat = b"" + offset = len(self.langs) + for c, inf in sorted(self.langs.items()): + ldat += struct.pack(">4sHH", c.encode("utf8"), len(inf), 8 * offset + 20) + for fid, val in inf: + fdat += struct.pack(">LHH", fid, val, 0) + offset += len(inf) + ldat += struct.pack(">LHH", 0x80808080, 0, 8 * offset + 20) + return ( + sstruct.pack(Sill_hdr, self) + + grUtils.bininfo(len(self.langs)) + + ldat + + fdat + ) + + def toXML(self, writer, ttFont): + writer.simpletag("version", version=self.version) + writer.newline() + for c, inf in sorted(self.langs.items()): + writer.begintag("lang", name=c) + writer.newline() + for fid, val in inf: + writer.simpletag("feature", fid=grUtils.num2tag(fid), val=val) + writer.newline() + writer.endtag("lang") + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + if name == "version": + self.version = float(safeEval(attrs["version"])) + elif name == "lang": + c = attrs["name"] + self.langs[c] = [] + for element in content: + if not isinstance(element, tuple): + continue + tag, a, subcontent = element + if tag == "feature": + self.langs[c].append( + (grUtils.tag2num(a["fid"]), int(safeEval(a["val"]))) + ) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I_C_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I_C_.py new file mode 100644 index 0000000000000000000000000000000000000000..14e353cde58b739660b10fe666e26492f5a0069f --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I_C_.py @@ -0,0 +1,14 @@ +""" TSI{B,C,D,J,P,S,V} are private tables used by Microsoft Visual TrueType (VTT) +tool to store its table source data. + +TSIC contains the source text for the Variation CVT window and data for +the ``cvar`` table. + +See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables +""" + +from .otBase import BaseTTXConverter + + +class table_T_S_I_C_(BaseTTXConverter): + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I_S_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I_S_.py new file mode 100644 index 0000000000000000000000000000000000000000..91f36e7c019087f954a7fa779df045a9097fa289 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I_S_.py @@ -0,0 +1,13 @@ +""" TSI{B,C,D,J,P,S,V} are private tables used by Microsoft Visual TrueType (VTT) +tool to store its table source data. + +TSIS contains the source text for the ``GSUB`` table. + +See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables +""" + +from .T_S_I_V_ import table_T_S_I_V_ + + +class table_T_S_I_S_(table_T_S_I_V_): + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__0.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__0.py new file mode 100644 index 0000000000000000000000000000000000000000..d60e783c60873c85487463f151dc25f061cde97f --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__0.py @@ -0,0 +1,70 @@ +"""TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT) +tool to store its hinting source data. + +TSI0 is the index table containing the lengths and offsets for the glyph +programs and 'extra' programs ('fpgm', 'prep', and 'cvt') that are contained +in the TSI1 table. + +See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables +""" + +import logging +import struct + +from . import DefaultTable + +log = logging.getLogger(__name__) + +tsi0Format = ">HHL" + + +def fixlongs(glyphID, textLength, textOffset): + return int(glyphID), int(textLength), textOffset + + +class table_T_S_I__0(DefaultTable.DefaultTable): + dependencies = ["TSI1"] + + def decompile(self, data, ttFont): + numGlyphs = ttFont["maxp"].numGlyphs + indices = [] + size = struct.calcsize(tsi0Format) + numEntries = len(data) // size + if numEntries != numGlyphs + 5: + diff = numEntries - numGlyphs - 5 + log.warning( + "Number of glyphPrograms differs from the number of glyphs in the font " + f"by {abs(diff)} ({numEntries - 5} programs vs. {numGlyphs} glyphs)." + ) + for _ in range(numEntries): + glyphID, textLength, textOffset = fixlongs( + *struct.unpack(tsi0Format, data[:size]) + ) + indices.append((glyphID, textLength, textOffset)) + data = data[size:] + assert len(data) == 0 + assert indices[-5] == (0xFFFE, 0, 0xABFC1F34), "bad magic number" + self.indices = indices[:-5] + self.extra_indices = indices[-4:] + + def compile(self, ttFont): + if not hasattr(self, "indices"): + # We have no corresponding table (TSI1 or TSI3); let's return + # no data, which effectively means "ignore us". + return b"" + data = b"" + for index, textLength, textOffset in self.indices: + data = data + struct.pack(tsi0Format, index, textLength, textOffset) + data = data + struct.pack(tsi0Format, 0xFFFE, 0, 0xABFC1F34) + for index, textLength, textOffset in self.extra_indices: + data = data + struct.pack(tsi0Format, index, textLength, textOffset) + return data + + def set(self, indices, extra_indices): + # gets called by 'TSI1' or 'TSI3' + self.indices = indices + self.extra_indices = extra_indices + + def toXML(self, writer, ttFont): + writer.comment("This table will be calculated by the compiler") + writer.newline() diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__1.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__1.py new file mode 100644 index 0000000000000000000000000000000000000000..19537dac9c512dc009a159cb25bb926eebca61ed --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__1.py @@ -0,0 +1,163 @@ +""" TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT) +tool to store its hinting source data. + +TSI1 contains the text of the glyph programs in the form of low-level assembly +code, as well as the 'extra' programs 'fpgm', 'ppgm' (i.e. 'prep'), and 'cvt'. + +See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables +""" + +from . import DefaultTable +from fontTools.misc.loggingTools import LogMixin +from fontTools.misc.textTools import strjoin, tobytes, tostr + + +class table_T_S_I__1(LogMixin, DefaultTable.DefaultTable): + extras = {0xFFFA: "ppgm", 0xFFFB: "cvt", 0xFFFC: "reserved", 0xFFFD: "fpgm"} + + indextable = "TSI0" + + def decompile(self, data, ttFont): + totalLength = len(data) + indextable = ttFont[self.indextable] + for indices, isExtra in zip( + (indextable.indices, indextable.extra_indices), (False, True) + ): + programs = {} + for i, (glyphID, textLength, textOffset) in enumerate(indices): + if isExtra: + name = self.extras[glyphID] + else: + name = ttFont.getGlyphName(glyphID) + if textOffset > totalLength: + self.log.warning("textOffset > totalLength; %r skipped" % name) + continue + if textLength < 0x8000: + # If the length stored in the record is less than 32768, then use + # that as the length of the record. + pass + elif textLength == 0x8000: + # If the length is 32768, compute the actual length as follows: + isLast = i == (len(indices) - 1) + if isLast: + if isExtra: + # For the last "extra" record (the very last record of the + # table), the length is the difference between the total + # length of the TSI1 table and the textOffset of the final + # record. + nextTextOffset = totalLength + else: + # For the last "normal" record (the last record just prior + # to the record containing the "magic number"), the length + # is the difference between the textOffset of the record + # following the "magic number" (0xFFFE) record (i.e. the + # first "extra" record), and the textOffset of the last + # "normal" record. + nextTextOffset = indextable.extra_indices[0][2] + else: + # For all other records with a length of 0x8000, the length is + # the difference between the textOffset of the record in + # question and the textOffset of the next record. + nextTextOffset = indices[i + 1][2] + assert nextTextOffset >= textOffset, "entries not sorted by offset" + if nextTextOffset > totalLength: + self.log.warning( + "nextTextOffset > totalLength; %r truncated" % name + ) + nextTextOffset = totalLength + textLength = nextTextOffset - textOffset + else: + from fontTools import ttLib + + raise ttLib.TTLibError( + "%r textLength (%d) must not be > 32768" % (name, textLength) + ) + text = data[textOffset : textOffset + textLength] + assert len(text) == textLength + text = tostr(text, encoding="utf-8") + if text: + programs[name] = text + if isExtra: + self.extraPrograms = programs + else: + self.glyphPrograms = programs + + def compile(self, ttFont): + if not hasattr(self, "glyphPrograms"): + self.glyphPrograms = {} + self.extraPrograms = {} + data = b"" + indextable = ttFont[self.indextable] + glyphNames = ttFont.getGlyphOrder() + + indices = [] + for i, name in enumerate(glyphNames): + if len(data) % 2: + data = ( + data + b"\015" + ) # align on 2-byte boundaries, fill with return chars. Yum. + if name in self.glyphPrograms: + text = tobytes(self.glyphPrograms[name], encoding="utf-8") + else: + text = b"" + textLength = len(text) + if textLength >= 0x8000: + textLength = 0x8000 + indices.append((i, textLength, len(data))) + data = data + text + + extra_indices = [] + for code, name in sorted(self.extras.items()): + if len(data) % 2: + data = ( + data + b"\015" + ) # align on 2-byte boundaries, fill with return chars. + if name in self.extraPrograms: + text = tobytes(self.extraPrograms[name], encoding="utf-8") + else: + text = b"" + textLength = len(text) + if textLength >= 0x8000: + textLength = 0x8000 + extra_indices.append((code, textLength, len(data))) + data = data + text + indextable.set(indices, extra_indices) + return data + + def toXML(self, writer, ttFont): + names = sorted(self.glyphPrograms.keys()) + writer.newline() + for name in names: + text = self.glyphPrograms[name] + if not text: + continue + writer.begintag("glyphProgram", name=name) + writer.newline() + writer.write_noindent(text.replace("\r", "\n")) + writer.newline() + writer.endtag("glyphProgram") + writer.newline() + writer.newline() + extra_names = sorted(self.extraPrograms.keys()) + for name in extra_names: + text = self.extraPrograms[name] + if not text: + continue + writer.begintag("extraProgram", name=name) + writer.newline() + writer.write_noindent(text.replace("\r", "\n")) + writer.newline() + writer.endtag("extraProgram") + writer.newline() + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + if not hasattr(self, "glyphPrograms"): + self.glyphPrograms = {} + self.extraPrograms = {} + lines = strjoin(content).replace("\r", "\n").split("\n") + text = "\r".join(lines[1:-1]) + if name == "glyphProgram": + self.glyphPrograms[attrs["name"]] = text + elif name == "extraProgram": + self.extraPrograms[attrs["name"]] = text diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__2.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__2.py new file mode 100644 index 0000000000000000000000000000000000000000..63608c60414c8e6cfd67aa6ab46caf4f14a918e1 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__2.py @@ -0,0 +1,17 @@ +""" TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT) +tool to store its hinting source data. + +TSI2 is the index table containing the lengths and offsets for the glyph +programs that are contained in the TSI3 table. It uses the same format as +the TSI0 table. + +See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables +""" + +from fontTools import ttLib + +superclass = ttLib.getTableClass("TSI0") + + +class table_T_S_I__2(superclass): + dependencies = ["TSI3"] diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__3.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__3.py new file mode 100644 index 0000000000000000000000000000000000000000..e866826db488d178833836f203f5e634cbdfbd3f --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__3.py @@ -0,0 +1,22 @@ +""" TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT) +tool to store its hinting source data. + +TSI3 contains the text of the glyph programs in the form of 'VTTTalk' code. + +See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables +""" + +from fontTools import ttLib + +superclass = ttLib.getTableClass("TSI1") + + +class table_T_S_I__3(superclass): + extras = { + 0xFFFA: "reserved0", + 0xFFFB: "reserved1", + 0xFFFC: "reserved2", + 0xFFFD: "reserved3", + } + + indextable = "TSI2" diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__5.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__5.py new file mode 100644 index 0000000000000000000000000000000000000000..8aa382e43ca0e4bb33994d2e093459a09ba12a9b --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__5.py @@ -0,0 +1,60 @@ +"""TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT) +tool to store its hinting source data. + +TSI5 contains the VTT character groups. + +See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables +""" + +import array +import logging +import sys + +from fontTools.misc.textTools import safeEval + +from . import DefaultTable + +log = logging.getLogger(__name__) + + +class table_T_S_I__5(DefaultTable.DefaultTable): + def decompile(self, data, ttFont): + numGlyphs = ttFont["maxp"].numGlyphs + a = array.array("H") + a.frombytes(data) + if sys.byteorder != "big": + a.byteswap() + self.glyphGrouping = {} + numEntries = len(data) // 2 + if numEntries != numGlyphs: + diff = numEntries - numGlyphs + log.warning( + "Number of entries differs from the number of glyphs in the font " + f"by {abs(diff)} ({numEntries} entries vs. {numGlyphs} glyphs)." + ) + for i in range(numEntries): + self.glyphGrouping[ttFont.getGlyphName(i)] = a[i] + + def compile(self, ttFont): + glyphNames = ttFont.getGlyphOrder() + a = array.array("H") + for glyphName in glyphNames: + a.append(self.glyphGrouping.get(glyphName, 0)) + if sys.byteorder != "big": + a.byteswap() + return a.tobytes() + + def toXML(self, writer, ttFont): + names = sorted(self.glyphGrouping.keys()) + for glyphName in names: + writer.simpletag( + "glyphgroup", name=glyphName, value=self.glyphGrouping[glyphName] + ) + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + if not hasattr(self, "glyphGrouping"): + self.glyphGrouping = {} + if name != "glyphgroup": + return + self.glyphGrouping[attrs["name"]] = safeEval(attrs["value"]) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/V_A_R_C_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/V_A_R_C_.py new file mode 100644 index 0000000000000000000000000000000000000000..afc1497d14ffd4aed6668af4cb0587135e5562f9 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/V_A_R_C_.py @@ -0,0 +1,12 @@ +from .otBase import BaseTTXConverter + + +class table_V_A_R_C_(BaseTTXConverter): + """Variable Components table + + The ``VARC`` table contains variation information for composite glyphs. + + See also https://github.com/harfbuzz/boring-expansion-spec/blob/main/VARC.md + """ + + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/V_O_R_G_.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/V_O_R_G_.py new file mode 100644 index 0000000000000000000000000000000000000000..2c53acba431059f58f86dbb1b89755a03f699f94 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/V_O_R_G_.py @@ -0,0 +1,165 @@ +from fontTools.misc.textTools import bytesjoin, safeEval +from . import DefaultTable +import struct + + +class table_V_O_R_G_(DefaultTable.DefaultTable): + """Vertical Origin table + + The ``VORG`` table contains the vertical origin of each glyph + in a `CFF` or `CFF2` font. + + This table is structured so that you can treat it like a dictionary keyed by glyph name. + + ``ttFont['VORG'][]`` will return the vertical origin for any glyph. + + ``ttFont['VORG'][] = `` will set the vertical origin for any glyph. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/vorg + """ + + def decompile(self, data, ttFont): + self.getGlyphName = ( + ttFont.getGlyphName + ) # for use in get/set item functions, for access by GID + ( + self.majorVersion, + self.minorVersion, + self.defaultVertOriginY, + self.numVertOriginYMetrics, + ) = struct.unpack(">HHhH", data[:8]) + assert ( + self.majorVersion <= 1 + ), "Major version of VORG table is higher than I know how to handle" + data = data[8:] + vids = [] + gids = [] + pos = 0 + for i in range(self.numVertOriginYMetrics): + gid, vOrigin = struct.unpack(">Hh", data[pos : pos + 4]) + pos += 4 + gids.append(gid) + vids.append(vOrigin) + + self.VOriginRecords = vOrig = {} + glyphOrder = ttFont.getGlyphOrder() + try: + names = [glyphOrder[gid] for gid in gids] + except IndexError: + getGlyphName = self.getGlyphName + names = map(getGlyphName, gids) + + for name, vid in zip(names, vids): + vOrig[name] = vid + + def compile(self, ttFont): + vorgs = list(self.VOriginRecords.values()) + names = list(self.VOriginRecords.keys()) + nameMap = ttFont.getReverseGlyphMap() + try: + gids = [nameMap[name] for name in names] + except KeyError: + nameMap = ttFont.getReverseGlyphMap(rebuild=True) + gids = [nameMap[name] for name in names] + vOriginTable = list(zip(gids, vorgs)) + self.numVertOriginYMetrics = len(vorgs) + vOriginTable.sort() # must be in ascending GID order + dataList = [struct.pack(">Hh", rec[0], rec[1]) for rec in vOriginTable] + header = struct.pack( + ">HHhH", + self.majorVersion, + self.minorVersion, + self.defaultVertOriginY, + self.numVertOriginYMetrics, + ) + dataList.insert(0, header) + data = bytesjoin(dataList) + return data + + def toXML(self, writer, ttFont): + writer.simpletag("majorVersion", value=self.majorVersion) + writer.newline() + writer.simpletag("minorVersion", value=self.minorVersion) + writer.newline() + writer.simpletag("defaultVertOriginY", value=self.defaultVertOriginY) + writer.newline() + writer.simpletag("numVertOriginYMetrics", value=self.numVertOriginYMetrics) + writer.newline() + vOriginTable = [] + glyphNames = self.VOriginRecords.keys() + for glyphName in glyphNames: + try: + gid = ttFont.getGlyphID(glyphName) + except: + assert 0, ( + "VORG table contains a glyph name not in ttFont.getGlyphNames(): " + + str(glyphName) + ) + vOriginTable.append([gid, glyphName, self.VOriginRecords[glyphName]]) + vOriginTable.sort() + for entry in vOriginTable: + vOriginRec = VOriginRecord(entry[1], entry[2]) + vOriginRec.toXML(writer, ttFont) + + def fromXML(self, name, attrs, content, ttFont): + if not hasattr(self, "VOriginRecords"): + self.VOriginRecords = {} + self.getGlyphName = ( + ttFont.getGlyphName + ) # for use in get/set item functions, for access by GID + if name == "VOriginRecord": + vOriginRec = VOriginRecord() + for element in content: + if isinstance(element, str): + continue + name, attrs, content = element + vOriginRec.fromXML(name, attrs, content, ttFont) + self.VOriginRecords[vOriginRec.glyphName] = vOriginRec.vOrigin + elif "value" in attrs: + setattr(self, name, safeEval(attrs["value"])) + + def __getitem__(self, glyphSelector): + if isinstance(glyphSelector, int): + # its a gid, convert to glyph name + glyphSelector = self.getGlyphName(glyphSelector) + + if glyphSelector not in self.VOriginRecords: + return self.defaultVertOriginY + + return self.VOriginRecords[glyphSelector] + + def __setitem__(self, glyphSelector, value): + if isinstance(glyphSelector, int): + # its a gid, convert to glyph name + glyphSelector = self.getGlyphName(glyphSelector) + + if value != self.defaultVertOriginY: + self.VOriginRecords[glyphSelector] = value + elif glyphSelector in self.VOriginRecords: + del self.VOriginRecords[glyphSelector] + + def __delitem__(self, glyphSelector): + del self.VOriginRecords[glyphSelector] + + +class VOriginRecord(object): + def __init__(self, name=None, vOrigin=None): + self.glyphName = name + self.vOrigin = vOrigin + + def toXML(self, writer, ttFont): + writer.begintag("VOriginRecord") + writer.newline() + writer.simpletag("glyphName", value=self.glyphName) + writer.newline() + writer.simpletag("vOrigin", value=self.vOrigin) + writer.newline() + writer.endtag("VOriginRecord") + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + value = attrs["value"] + if name == "glyphName": + setattr(self, name, value) + else: + setattr(self, name, safeEval(value)) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__init__.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..fd98db78223bb7a62e46ceeedfbd33ce293d5919 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__init__.py @@ -0,0 +1,94 @@ +# DON'T EDIT! This file is generated by MetaTools/buildTableList.py. +def _moduleFinderHint(): + """Dummy function to let modulefinder know what tables may be + dynamically imported. Generated by MetaTools/buildTableList.py. + + >>> _moduleFinderHint() + """ + from . import B_A_S_E_ + from . import C_B_D_T_ + from . import C_B_L_C_ + from . import C_F_F_ + from . import C_F_F__2 + from . import C_O_L_R_ + from . import C_P_A_L_ + from . import D_S_I_G_ + from . import D__e_b_g + from . import E_B_D_T_ + from . import E_B_L_C_ + from . import F_F_T_M_ + from . import F__e_a_t + from . import G_D_E_F_ + from . import G_P_O_S_ + from . import G_S_U_B_ + from . import G_V_A_R_ + from . import G__l_a_t + from . import G__l_o_c + from . import H_V_A_R_ + from . import J_S_T_F_ + from . import L_T_S_H_ + from . import M_A_T_H_ + from . import M_V_A_R_ + from . import O_S_2f_2 + from . import S_T_A_T_ + from . import S_V_G_ + from . import S__i_l_f + from . import S__i_l_l + from . import T_S_I_B_ + from . import T_S_I_C_ + from . import T_S_I_D_ + from . import T_S_I_J_ + from . import T_S_I_P_ + from . import T_S_I_S_ + from . import T_S_I_V_ + from . import T_S_I__0 + from . import T_S_I__1 + from . import T_S_I__2 + from . import T_S_I__3 + from . import T_S_I__5 + from . import T_T_F_A_ + from . import V_A_R_C_ + from . import V_D_M_X_ + from . import V_O_R_G_ + from . import V_V_A_R_ + from . import _a_n_k_r + from . import _a_v_a_r + from . import _b_s_l_n + from . import _c_i_d_g + from . import _c_m_a_p + from . import _c_v_a_r + from . import _c_v_t + from . import _f_e_a_t + from . import _f_p_g_m + from . import _f_v_a_r + from . import _g_a_s_p + from . import _g_c_i_d + from . import _g_l_y_f + from . import _g_v_a_r + from . import _h_d_m_x + from . import _h_e_a_d + from . import _h_h_e_a + from . import _h_m_t_x + from . import _k_e_r_n + from . import _l_c_a_r + from . import _l_o_c_a + from . import _l_t_a_g + from . import _m_a_x_p + from . import _m_e_t_a + from . import _m_o_r_t + from . import _m_o_r_x + from . import _n_a_m_e + from . import _o_p_b_d + from . import _p_o_s_t + from . import _p_r_e_p + from . import _p_r_o_p + from . import _s_b_i_x + from . import _t_r_a_k + from . import _v_h_e_a + from . import _v_m_t_x + + +if __name__ == "__main__": + import doctest, sys + + sys.exit(doctest.testmod().failed) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/B_A_S_E_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/B_A_S_E_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b97f4488704ef7140c5f1b7de7b423652c1dba0d Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/B_A_S_E_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_F_F_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_F_F_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d95dac37614a4a8c1656038aa1e063839c9f93a5 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_F_F_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_F_F__2.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_F_F__2.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..feee56775322ce7bb39e7e1b21e82707ce4b1755 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_F_F__2.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_P_A_L_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_P_A_L_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d58e19a338896edcb8379645571c041b1a1e077e Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_P_A_L_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/E_B_D_T_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/E_B_D_T_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..711f5dd3490e3188ed57c1fa206da3f0d11d172d Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/E_B_D_T_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/E_B_L_C_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/E_B_L_C_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4f966cd280df4f8551681196d70b9cdfde66884a Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/E_B_L_C_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/F_F_T_M_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/F_F_T_M_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..19bfd5ec80e34bd9276c4c353fcc281e60a89830 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/F_F_T_M_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/F__e_a_t.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/F__e_a_t.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f296e83586af3a3dca63613c3654279a18b30657 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/F__e_a_t.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/G__l_a_t.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/G__l_a_t.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0523bbd853391a7b64a91af6421289ad82beff49 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/G__l_a_t.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/H_V_A_R_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/H_V_A_R_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1334cae79c11eee84d47ad2fbefe3bcedca3042a Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/H_V_A_R_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/M_A_T_H_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/M_A_T_H_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2bd5cee6617ff26414aa2132e704eb47d13721f6 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/M_A_T_H_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/O_S_2f_2.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/O_S_2f_2.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5b925f6de9814279b82055e0029cc265c95747c2 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/O_S_2f_2.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/S_T_A_T_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/S_T_A_T_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8c3bcbd616ea9f2f6fae8eb3985ee969ca28195d Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/S_T_A_T_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/S__i_l_l.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/S__i_l_l.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dc6c7a3c42503b5ca77c4970d87c13feee8cf69a Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/S__i_l_l.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I_J_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I_J_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..72aec2f8413e740fb76f14670f0653bcdf2dd638 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I_J_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I_V_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I_V_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..76ce14e20fd9fd886de08ef3318ad4a1dcab6547 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I_V_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I__0.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I__0.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8e79039f681c346a49512a48a766a8ebf7b2e471 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I__0.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I__2.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I__2.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3ed65bf3994ef2004aaa6ecd3f0353467123b3e6 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I__2.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I__3.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I__3.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8208bf857aefdd446cdd594cebedc156b9339fdd Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_S_I__3.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_T_F_A_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_T_F_A_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4c4daa6acbf0d44ba0451203b5176b2f24897dc4 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/T_T_F_A_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/TupleVariation.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/TupleVariation.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..47bdd2c35497f501c4319af384ade213a18c10b3 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/TupleVariation.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/V_D_M_X_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/V_D_M_X_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5228a30f217f27bf7f696d2d4d9516a6cac8571a Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/V_D_M_X_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/V_O_R_G_.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/V_O_R_G_.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dcf6e6579f4d7635f6654c024cb823db484d128f Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/V_O_R_G_.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_a_n_k_r.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_a_n_k_r.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..226c2269d0b1501d4bb70056c1f4540c2cff1e11 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_a_n_k_r.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_b_s_l_n.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_b_s_l_n.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..424612dd54b04ad7bf909630852b83fb11c144a1 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_b_s_l_n.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_c_v_t.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_c_v_t.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..baee206d85f0a31d22cb267dece423da27820315 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_c_v_t.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_f_e_a_t.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_f_e_a_t.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0c4120ed0824756a8cdec5731b3597117a7c604d Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_f_e_a_t.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_f_v_a_r.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_f_v_a_r.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5838a9807d49ded440f17c97795eefc2b862eb3d Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_f_v_a_r.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_g_a_s_p.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_g_a_s_p.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e5f74cb3c1a983624481c15f6818d949e28714a4 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_g_a_s_p.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_g_c_i_d.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_g_c_i_d.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0219044d3615218f4eb008b83f466dd985bd6dff Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_g_c_i_d.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_h_d_m_x.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_h_d_m_x.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cbff35976c0fd7ce5742940c4398762fa8fc71b1 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_h_d_m_x.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_k_e_r_n.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_k_e_r_n.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..370a870eb4c2c881b7d774c9a2ebe336c0b7055f Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_k_e_r_n.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_l_c_a_r.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_l_c_a_r.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..95346a8f90ca6af797db956efc96048b624bfe64 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_l_c_a_r.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_l_t_a_g.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_l_t_a_g.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6e8fddb540b053e58a5ca51b0aa073e7c370b59c Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_l_t_a_g.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_m_a_x_p.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_m_a_x_p.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e2c75384fd873505902fd219c50140e18c198fcc Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_m_a_x_p.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_m_e_t_a.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_m_e_t_a.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0493ae59d858c136a07fdfea9029e89df5c5567c Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_m_e_t_a.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_o_p_b_d.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_o_p_b_d.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e77642bef71af40c30d16bd21ce9180b5d6975d8 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_o_p_b_d.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_p_o_s_t.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_p_o_s_t.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ce901fb9e7167cff8558bad69a7f08fd8137d907 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_p_o_s_t.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_p_r_e_p.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_p_r_e_p.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8e612f87194dc0893fde141638c4d68e619be6ea Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/_p_r_e_p.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/asciiTable.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/asciiTable.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3bc55f6c66361b4669c8037d88441358380d50ef Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/asciiTable.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/otData.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/otData.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2116996eda2826cf9344325aec398cfa793d6c00 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/otData.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/sbixGlyph.cpython-311.pyc b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/sbixGlyph.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..182b3fbe384ec64ef88168169511043db96a4675 Binary files /dev/null and b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/sbixGlyph.cpython-311.pyc differ diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_a_n_k_r.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_a_n_k_r.py new file mode 100644 index 0000000000000000000000000000000000000000..5466d42d4117f9935b54def71e5351fa1a0ee6ab --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_a_n_k_r.py @@ -0,0 +1,15 @@ +from .otBase import BaseTTXConverter + + +class table__a_n_k_r(BaseTTXConverter): + """Anchor Point table + + The anchor point table provides a way to define anchor points. + These are points within the coordinate space of a given glyph, + independent of the control points used to render the glyph. + Anchor points are used in conjunction with the ``kerx`` table. + + See also https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6ankr.html + """ + + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_b_s_l_n.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_b_s_l_n.py new file mode 100644 index 0000000000000000000000000000000000000000..85796b0a0479d26104a3fb63d9fe6085be29853a --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_b_s_l_n.py @@ -0,0 +1,15 @@ +from .otBase import BaseTTXConverter + + +# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6bsln.html +class table__b_s_l_n(BaseTTXConverter): + """Baseline table + + The AAT ``bsln`` table is similar in purpose to the OpenType ``BASE`` + table; it stores per-script baselines to support automatic alignment + of lines of text. + + See also https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6bsln.html + """ + + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_c_v_a_r.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_c_v_a_r.py new file mode 100644 index 0000000000000000000000000000000000000000..872710c8f0c93ade86e8be8640205a91b7b397af --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_c_v_a_r.py @@ -0,0 +1,94 @@ +from . import DefaultTable +from fontTools.misc import sstruct +from fontTools.misc.textTools import bytesjoin +from fontTools.ttLib.tables.TupleVariation import ( + compileTupleVariationStore, + decompileTupleVariationStore, + TupleVariation, +) + + +# https://www.microsoft.com/typography/otspec/cvar.htm +# https://www.microsoft.com/typography/otspec/otvarcommonformats.htm +# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6cvar.html + +CVAR_HEADER_FORMAT = """ + > # big endian + majorVersion: H + minorVersion: H + tupleVariationCount: H + offsetToData: H +""" + +CVAR_HEADER_SIZE = sstruct.calcsize(CVAR_HEADER_FORMAT) + + +class table__c_v_a_r(DefaultTable.DefaultTable): + """Control Value Table (CVT) variations table + + The ``cvar`` table contains variations for the values in a ``cvt`` + table. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/cvar + """ + + dependencies = ["cvt ", "fvar"] + + def __init__(self, tag=None): + DefaultTable.DefaultTable.__init__(self, tag) + self.majorVersion, self.minorVersion = 1, 0 + self.variations = [] + + def compile(self, ttFont, useSharedPoints=False): + tupleVariationCount, tuples, data = compileTupleVariationStore( + variations=[v for v in self.variations if v.hasImpact()], + pointCount=len(ttFont["cvt "].values), + axisTags=[axis.axisTag for axis in ttFont["fvar"].axes], + sharedTupleIndices={}, + useSharedPoints=useSharedPoints, + ) + header = { + "majorVersion": self.majorVersion, + "minorVersion": self.minorVersion, + "tupleVariationCount": tupleVariationCount, + "offsetToData": CVAR_HEADER_SIZE + len(tuples), + } + return b"".join([sstruct.pack(CVAR_HEADER_FORMAT, header), tuples, data]) + + def decompile(self, data, ttFont): + axisTags = [axis.axisTag for axis in ttFont["fvar"].axes] + header = {} + sstruct.unpack(CVAR_HEADER_FORMAT, data[0:CVAR_HEADER_SIZE], header) + self.majorVersion = header["majorVersion"] + self.minorVersion = header["minorVersion"] + assert self.majorVersion == 1, self.majorVersion + self.variations = decompileTupleVariationStore( + tableTag=self.tableTag, + axisTags=axisTags, + tupleVariationCount=header["tupleVariationCount"], + pointCount=len(ttFont["cvt "].values), + sharedTuples=None, + data=data, + pos=CVAR_HEADER_SIZE, + dataPos=header["offsetToData"], + ) + + def fromXML(self, name, attrs, content, ttFont): + if name == "version": + self.majorVersion = int(attrs.get("major", "1")) + self.minorVersion = int(attrs.get("minor", "0")) + elif name == "tuple": + valueCount = len(ttFont["cvt "].values) + var = TupleVariation({}, [None] * valueCount) + self.variations.append(var) + for tupleElement in content: + if isinstance(tupleElement, tuple): + tupleName, tupleAttrs, tupleContent = tupleElement + var.fromXML(tupleName, tupleAttrs, tupleContent) + + def toXML(self, writer, ttFont): + axisTags = [axis.axisTag for axis in ttFont["fvar"].axes] + writer.simpletag("version", major=self.majorVersion, minor=self.minorVersion) + writer.newline() + for var in self.variations: + var.toXML(writer, axisTags) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_g_a_s_p.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_g_a_s_p.py new file mode 100644 index 0000000000000000000000000000000000000000..1f605771e9b7d98da4384e0d6a5f692646f6c07d --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_g_a_s_p.py @@ -0,0 +1,63 @@ +from fontTools.misc.textTools import safeEval +from . import DefaultTable +import struct + + +GASP_SYMMETRIC_GRIDFIT = 0x0004 +GASP_SYMMETRIC_SMOOTHING = 0x0008 +GASP_DOGRAY = 0x0002 +GASP_GRIDFIT = 0x0001 + + +class table__g_a_s_p(DefaultTable.DefaultTable): + """Grid-fitting and Scan-conversion Procedure table + + The ``gasp`` table defines the preferred rasterization settings for + the font when rendered on monochrome and greyscale output devices. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/gasp + """ + + def decompile(self, data, ttFont): + self.version, numRanges = struct.unpack(">HH", data[:4]) + assert 0 <= self.version <= 1, "unknown 'gasp' format: %s" % self.version + data = data[4:] + self.gaspRange = {} + for i in range(numRanges): + rangeMaxPPEM, rangeGaspBehavior = struct.unpack(">HH", data[:4]) + self.gaspRange[int(rangeMaxPPEM)] = int(rangeGaspBehavior) + data = data[4:] + assert not data, "too much data" + + def compile(self, ttFont): + version = 0 # ignore self.version + numRanges = len(self.gaspRange) + data = b"" + items = sorted(self.gaspRange.items()) + for rangeMaxPPEM, rangeGaspBehavior in items: + data = data + struct.pack(">HH", rangeMaxPPEM, rangeGaspBehavior) + if rangeGaspBehavior & ~(GASP_GRIDFIT | GASP_DOGRAY): + version = 1 + data = struct.pack(">HH", version, numRanges) + data + return data + + def toXML(self, writer, ttFont): + items = sorted(self.gaspRange.items()) + for rangeMaxPPEM, rangeGaspBehavior in items: + writer.simpletag( + "gaspRange", + [ + ("rangeMaxPPEM", rangeMaxPPEM), + ("rangeGaspBehavior", rangeGaspBehavior), + ], + ) + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + if name != "gaspRange": + return + if not hasattr(self, "gaspRange"): + self.gaspRange = {} + self.gaspRange[safeEval(attrs["rangeMaxPPEM"])] = safeEval( + attrs["rangeGaspBehavior"] + ) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_k_e_r_n.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_k_e_r_n.py new file mode 100644 index 0000000000000000000000000000000000000000..cdbaebedc63db51ecfb06601c9673f08f74a445b --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_k_e_r_n.py @@ -0,0 +1,289 @@ +from fontTools.ttLib import getSearchRange +from fontTools.misc.textTools import safeEval, readHex +from fontTools.misc.fixedTools import fixedToFloat as fi2fl, floatToFixed as fl2fi +from . import DefaultTable +import struct +import sys +import array +import logging + + +log = logging.getLogger(__name__) + + +class table__k_e_r_n(DefaultTable.DefaultTable): + """Kerning table + + The ``kern`` table contains values that contextually adjust the inter-glyph + spacing for the glyphs in a ``glyf`` table. + + Note that similar contextual spacing adjustments can also be stored + in the "kern" feature of a ``GPOS`` table. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/kern + """ + + def getkern(self, format): + for subtable in self.kernTables: + if subtable.format == format: + return subtable + return None # not found + + def decompile(self, data, ttFont): + version, nTables = struct.unpack(">HH", data[:4]) + apple = False + if (len(data) >= 8) and (version == 1): + # AAT Apple's "new" format. Hm. + version, nTables = struct.unpack(">LL", data[:8]) + self.version = fi2fl(version, 16) + data = data[8:] + apple = True + else: + self.version = version + data = data[4:] + self.kernTables = [] + for i in range(nTables): + if self.version == 1.0: + # Apple + length, coverage, subtableFormat = struct.unpack(">LBB", data[:6]) + else: + # in OpenType spec the "version" field refers to the common + # subtable header; the actual subtable format is stored in + # the 8-15 mask bits of "coverage" field. + # This "version" is always 0 so we ignore it here + _, length, subtableFormat, coverage = struct.unpack(">HHBB", data[:6]) + if nTables == 1 and subtableFormat == 0: + # The "length" value is ignored since some fonts + # (like OpenSans and Calibri) have a subtable larger than + # its value. + (nPairs,) = struct.unpack(">H", data[6:8]) + calculated_length = (nPairs * 6) + 14 + if length != calculated_length: + log.warning( + "'kern' subtable longer than defined: " + "%d bytes instead of %d bytes" % (calculated_length, length) + ) + length = calculated_length + if subtableFormat not in kern_classes: + subtable = KernTable_format_unkown(subtableFormat) + else: + subtable = kern_classes[subtableFormat](apple) + subtable.decompile(data[:length], ttFont) + self.kernTables.append(subtable) + data = data[length:] + + def compile(self, ttFont): + if hasattr(self, "kernTables"): + nTables = len(self.kernTables) + else: + nTables = 0 + if self.version == 1.0: + # AAT Apple's "new" format. + data = struct.pack(">LL", fl2fi(self.version, 16), nTables) + else: + data = struct.pack(">HH", self.version, nTables) + if hasattr(self, "kernTables"): + for subtable in self.kernTables: + data = data + subtable.compile(ttFont) + return data + + def toXML(self, writer, ttFont): + writer.simpletag("version", value=self.version) + writer.newline() + for subtable in self.kernTables: + subtable.toXML(writer, ttFont) + + def fromXML(self, name, attrs, content, ttFont): + if name == "version": + self.version = safeEval(attrs["value"]) + return + if name != "kernsubtable": + return + if not hasattr(self, "kernTables"): + self.kernTables = [] + format = safeEval(attrs["format"]) + if format not in kern_classes: + subtable = KernTable_format_unkown(format) + else: + apple = self.version == 1.0 + subtable = kern_classes[format](apple) + self.kernTables.append(subtable) + subtable.fromXML(name, attrs, content, ttFont) + + +class KernTable_format_0(object): + # 'version' is kept for backward compatibility + version = format = 0 + + def __init__(self, apple=False): + self.apple = apple + + def decompile(self, data, ttFont): + if not self.apple: + version, length, subtableFormat, coverage = struct.unpack(">HHBB", data[:6]) + if version != 0: + from fontTools.ttLib import TTLibError + + raise TTLibError("unsupported kern subtable version: %d" % version) + tupleIndex = None + # Should we also assert length == len(data)? + data = data[6:] + else: + length, coverage, subtableFormat, tupleIndex = struct.unpack( + ">LBBH", data[:8] + ) + data = data[8:] + assert self.format == subtableFormat, "unsupported format" + self.coverage = coverage + self.tupleIndex = tupleIndex + + self.kernTable = kernTable = {} + + nPairs, searchRange, entrySelector, rangeShift = struct.unpack( + ">HHHH", data[:8] + ) + data = data[8:] + + datas = array.array("H", data[: 6 * nPairs]) + if sys.byteorder != "big": + datas.byteswap() + it = iter(datas) + glyphOrder = ttFont.getGlyphOrder() + for k in range(nPairs): + left, right, value = next(it), next(it), next(it) + if value >= 32768: + value -= 65536 + try: + kernTable[(glyphOrder[left], glyphOrder[right])] = value + except IndexError: + # Slower, but will not throw an IndexError on an invalid + # glyph id. + kernTable[(ttFont.getGlyphName(left), ttFont.getGlyphName(right))] = ( + value + ) + if len(data) > 6 * nPairs + 4: # Ignore up to 4 bytes excess + log.warning( + "excess data in 'kern' subtable: %d bytes", len(data) - 6 * nPairs + ) + + def compile(self, ttFont): + nPairs = min(len(self.kernTable), 0xFFFF) + searchRange, entrySelector, rangeShift = getSearchRange(nPairs, 6) + searchRange &= 0xFFFF + entrySelector = min(entrySelector, 0xFFFF) + rangeShift = min(rangeShift, 0xFFFF) + data = struct.pack(">HHHH", nPairs, searchRange, entrySelector, rangeShift) + + # yeehee! (I mean, turn names into indices) + try: + reverseOrder = ttFont.getReverseGlyphMap() + kernTable = sorted( + (reverseOrder[left], reverseOrder[right], value) + for ((left, right), value) in self.kernTable.items() + ) + except KeyError: + # Slower, but will not throw KeyError on invalid glyph id. + getGlyphID = ttFont.getGlyphID + kernTable = sorted( + (getGlyphID(left), getGlyphID(right), value) + for ((left, right), value) in self.kernTable.items() + ) + + for left, right, value in kernTable: + data = data + struct.pack(">HHh", left, right, value) + + if not self.apple: + version = 0 + length = len(data) + 6 + if length >= 0x10000: + log.warning( + '"kern" subtable overflow, ' + "truncating length value while preserving pairs." + ) + length &= 0xFFFF + header = struct.pack(">HHBB", version, length, self.format, self.coverage) + else: + if self.tupleIndex is None: + # sensible default when compiling a TTX from an old fonttools + # or when inserting a Windows-style format 0 subtable into an + # Apple version=1.0 kern table + log.warning("'tupleIndex' is None; default to 0") + self.tupleIndex = 0 + length = len(data) + 8 + header = struct.pack( + ">LBBH", length, self.coverage, self.format, self.tupleIndex + ) + return header + data + + def toXML(self, writer, ttFont): + attrs = dict(coverage=self.coverage, format=self.format) + if self.apple: + if self.tupleIndex is None: + log.warning("'tupleIndex' is None; default to 0") + attrs["tupleIndex"] = 0 + else: + attrs["tupleIndex"] = self.tupleIndex + writer.begintag("kernsubtable", **attrs) + writer.newline() + items = sorted(self.kernTable.items()) + for (left, right), value in items: + writer.simpletag("pair", [("l", left), ("r", right), ("v", value)]) + writer.newline() + writer.endtag("kernsubtable") + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + self.coverage = safeEval(attrs["coverage"]) + subtableFormat = safeEval(attrs["format"]) + if self.apple: + if "tupleIndex" in attrs: + self.tupleIndex = safeEval(attrs["tupleIndex"]) + else: + # previous fontTools versions didn't export tupleIndex + log.warning("Apple kern subtable is missing 'tupleIndex' attribute") + self.tupleIndex = None + else: + self.tupleIndex = None + assert subtableFormat == self.format, "unsupported format" + if not hasattr(self, "kernTable"): + self.kernTable = {} + for element in content: + if not isinstance(element, tuple): + continue + name, attrs, content = element + self.kernTable[(attrs["l"], attrs["r"])] = safeEval(attrs["v"]) + + def __getitem__(self, pair): + return self.kernTable[pair] + + def __setitem__(self, pair, value): + self.kernTable[pair] = value + + def __delitem__(self, pair): + del self.kernTable[pair] + + +class KernTable_format_unkown(object): + def __init__(self, format): + self.format = format + + def decompile(self, data, ttFont): + self.data = data + + def compile(self, ttFont): + return self.data + + def toXML(self, writer, ttFont): + writer.begintag("kernsubtable", format=self.format) + writer.newline() + writer.comment("unknown 'kern' subtable format") + writer.newline() + writer.dumphex(self.data) + writer.endtag("kernsubtable") + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + self.decompile(readHex(content), ttFont) + + +kern_classes = {0: KernTable_format_0} diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_l_c_a_r.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_l_c_a_r.py new file mode 100644 index 0000000000000000000000000000000000000000..bbb32d23d9d636361117e068fb7846d319f1b52c --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_l_c_a_r.py @@ -0,0 +1,13 @@ +from .otBase import BaseTTXConverter + + +class table__l_c_a_r(BaseTTXConverter): + """Ligature Caret table + + The AAT ``lcar`` table stores division points within ligatures, which applications + can use to position carets properly between the logical parts of the ligature. + + See also https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6lcar.html + """ + + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_l_o_c_a.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_l_o_c_a.py new file mode 100644 index 0000000000000000000000000000000000000000..f0b12fe57ee7ba2aafa1ea4d5aa503e14134b9af --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_l_o_c_a.py @@ -0,0 +1,70 @@ +from . import DefaultTable +import sys +import array +import logging + + +log = logging.getLogger(__name__) + + +class table__l_o_c_a(DefaultTable.DefaultTable): + """Index to Location table + + The ``loca`` table stores the offsets in the ``glyf`` table that correspond + to the descriptions of each glyph. The glyphs are references by Glyph ID. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/loca + """ + + dependencies = ["glyf"] + + def decompile(self, data, ttFont): + longFormat = ttFont["head"].indexToLocFormat + if longFormat: + format = "I" + else: + format = "H" + locations = array.array(format) + locations.frombytes(data) + if sys.byteorder != "big": + locations.byteswap() + if not longFormat: + locations = array.array("I", (2 * l for l in locations)) + if len(locations) < (ttFont["maxp"].numGlyphs + 1): + log.warning( + "corrupt 'loca' table, or wrong numGlyphs in 'maxp': %d %d", + len(locations) - 1, + ttFont["maxp"].numGlyphs, + ) + self.locations = locations + + def compile(self, ttFont): + try: + max_location = max(self.locations) + except AttributeError: + self.set([]) + max_location = 0 + if max_location < 0x20000 and all(l % 2 == 0 for l in self.locations): + locations = array.array("H") + for location in self.locations: + locations.append(location // 2) + ttFont["head"].indexToLocFormat = 0 + else: + locations = array.array("I", self.locations) + ttFont["head"].indexToLocFormat = 1 + if sys.byteorder != "big": + locations.byteswap() + return locations.tobytes() + + def set(self, locations): + self.locations = array.array("I", locations) + + def toXML(self, writer, ttFont): + writer.comment("The 'loca' table will be calculated by the compiler") + writer.newline() + + def __getitem__(self, index): + return self.locations[index] + + def __len__(self): + return len(self.locations) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_l_t_a_g.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_l_t_a_g.py new file mode 100644 index 0000000000000000000000000000000000000000..fc47cd648bc7b6be6b4ca3011c5125cc2e1d897e --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_l_t_a_g.py @@ -0,0 +1,72 @@ +from fontTools.misc.textTools import bytesjoin, tobytes, safeEval +from . import DefaultTable +import struct + +# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6ltag.html + + +class table__l_t_a_g(DefaultTable.DefaultTable): + """Language Tag table + + The AAT ``ltag`` table contains mappings between the numeric codes used + in the language field of the ``name`` table and IETF language tags. + + See also https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6ltag.html + """ + + def __init__(self, tag=None): + DefaultTable.DefaultTable.__init__(self, tag) + self.version, self.flags = 1, 0 + self.tags = [] + + def addTag(self, tag): + """Add 'tag' to the list of langauge tags if not already there. + + Returns the integer index of 'tag' in the list of all tags. + """ + try: + return self.tags.index(tag) + except ValueError: + self.tags.append(tag) + return len(self.tags) - 1 + + def decompile(self, data, ttFont): + self.version, self.flags, numTags = struct.unpack(">LLL", data[:12]) + assert self.version == 1 + self.tags = [] + for i in range(numTags): + pos = 12 + i * 4 + offset, length = struct.unpack(">HH", data[pos : pos + 4]) + tag = data[offset : offset + length].decode("ascii") + self.tags.append(tag) + + def compile(self, ttFont): + dataList = [struct.pack(">LLL", self.version, self.flags, len(self.tags))] + stringPool = "" + for tag in self.tags: + offset = stringPool.find(tag) + if offset < 0: + offset = len(stringPool) + stringPool = stringPool + tag + offset = offset + 12 + len(self.tags) * 4 + dataList.append(struct.pack(">HH", offset, len(tag))) + dataList.append(tobytes(stringPool)) + return bytesjoin(dataList) + + def toXML(self, writer, ttFont): + writer.simpletag("version", value=self.version) + writer.newline() + writer.simpletag("flags", value=self.flags) + writer.newline() + for tag in self.tags: + writer.simpletag("LanguageTag", tag=tag) + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + if not hasattr(self, "tags"): + self.tags = [] + if name == "LanguageTag": + self.tags.append(attrs["tag"]) + elif "value" in attrs: + value = safeEval(attrs["value"]) + setattr(self, name, value) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_m_a_x_p.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_m_a_x_p.py new file mode 100644 index 0000000000000000000000000000000000000000..c1576a578f22c375ad4c5c4534b38162329aadde --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_m_a_x_p.py @@ -0,0 +1,147 @@ +from fontTools.misc import sstruct +from fontTools.misc.textTools import safeEval +from . import DefaultTable + +maxpFormat_0_5 = """ + > # big endian + tableVersion: i + numGlyphs: H +""" + +maxpFormat_1_0_add = """ + > # big endian + maxPoints: H + maxContours: H + maxCompositePoints: H + maxCompositeContours: H + maxZones: H + maxTwilightPoints: H + maxStorage: H + maxFunctionDefs: H + maxInstructionDefs: H + maxStackElements: H + maxSizeOfInstructions: H + maxComponentElements: H + maxComponentDepth: H +""" + + +class table__m_a_x_p(DefaultTable.DefaultTable): + """Maximum Profile table + + The ``maxp`` table contains the memory requirements for the data in + the font. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/maxp + """ + + dependencies = ["glyf"] + + def decompile(self, data, ttFont): + dummy, data = sstruct.unpack2(maxpFormat_0_5, data, self) + self.numGlyphs = int(self.numGlyphs) + if self.tableVersion != 0x00005000: + dummy, data = sstruct.unpack2(maxpFormat_1_0_add, data, self) + assert len(data) == 0 + + def compile(self, ttFont): + if "glyf" in ttFont: + if ttFont.isLoaded("glyf") and ttFont.recalcBBoxes: + self.recalc(ttFont) + else: + pass # CFF + self.numGlyphs = len(ttFont.getGlyphOrder()) + if self.tableVersion != 0x00005000: + self.tableVersion = 0x00010000 + data = sstruct.pack(maxpFormat_0_5, self) + if self.tableVersion == 0x00010000: + data = data + sstruct.pack(maxpFormat_1_0_add, self) + return data + + def recalc(self, ttFont): + """Recalculate the font bounding box, and most other maxp values except + for the TT instructions values. Also recalculate the value of bit 1 + of the flags field and the font bounding box of the 'head' table. + """ + glyfTable = ttFont["glyf"] + hmtxTable = ttFont["hmtx"] + headTable = ttFont["head"] + self.numGlyphs = len(glyfTable) + INFINITY = 100000 + xMin = +INFINITY + yMin = +INFINITY + xMax = -INFINITY + yMax = -INFINITY + maxPoints = 0 + maxContours = 0 + maxCompositePoints = 0 + maxCompositeContours = 0 + maxComponentElements = 0 + maxComponentDepth = 0 + allXMinIsLsb = 1 + for glyphName in ttFont.getGlyphOrder(): + g = glyfTable[glyphName] + if g.numberOfContours: + if hmtxTable[glyphName][1] != g.xMin: + allXMinIsLsb = 0 + xMin = min(xMin, g.xMin) + yMin = min(yMin, g.yMin) + xMax = max(xMax, g.xMax) + yMax = max(yMax, g.yMax) + if g.numberOfContours > 0: + nPoints, nContours = g.getMaxpValues() + maxPoints = max(maxPoints, nPoints) + maxContours = max(maxContours, nContours) + elif g.isComposite(): + nPoints, nContours, componentDepth = g.getCompositeMaxpValues( + glyfTable + ) + maxCompositePoints = max(maxCompositePoints, nPoints) + maxCompositeContours = max(maxCompositeContours, nContours) + maxComponentElements = max(maxComponentElements, len(g.components)) + maxComponentDepth = max(maxComponentDepth, componentDepth) + if xMin == +INFINITY: + headTable.xMin = 0 + headTable.yMin = 0 + headTable.xMax = 0 + headTable.yMax = 0 + else: + headTable.xMin = xMin + headTable.yMin = yMin + headTable.xMax = xMax + headTable.yMax = yMax + self.maxPoints = maxPoints + self.maxContours = maxContours + self.maxCompositePoints = maxCompositePoints + self.maxCompositeContours = maxCompositeContours + self.maxComponentElements = maxComponentElements + self.maxComponentDepth = maxComponentDepth + if allXMinIsLsb: + headTable.flags = headTable.flags | 0x2 + else: + headTable.flags = headTable.flags & ~0x2 + + def testrepr(self): + items = sorted(self.__dict__.items()) + print(". . . . . . . . .") + for combo in items: + print(" %s: %s" % combo) + print(". . . . . . . . .") + + def toXML(self, writer, ttFont): + if self.tableVersion != 0x00005000: + writer.comment("Most of this table will be recalculated by the compiler") + writer.newline() + formatstring, names, fixes = sstruct.getformat(maxpFormat_0_5) + if self.tableVersion != 0x00005000: + formatstring, names_1_0, fixes = sstruct.getformat(maxpFormat_1_0_add) + names = {**names, **names_1_0} + for name in names: + value = getattr(self, name) + if name == "tableVersion": + value = hex(value) + writer.simpletag(name, value=value) + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + setattr(self, name, safeEval(attrs["value"])) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_m_e_t_a.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_m_e_t_a.py new file mode 100644 index 0000000000000000000000000000000000000000..c5cea1b993e8e15968065f9a50b27784fcf4eb8c --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_m_e_t_a.py @@ -0,0 +1,112 @@ +from fontTools.misc import sstruct +from fontTools.misc.textTools import bytesjoin, strjoin, readHex +from fontTools.ttLib import TTLibError +from . import DefaultTable + +# Apple's documentation of 'meta': +# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6meta.html + +META_HEADER_FORMAT = """ + > # big endian + version: L + flags: L + dataOffset: L + numDataMaps: L +""" + + +DATA_MAP_FORMAT = """ + > # big endian + tag: 4s + dataOffset: L + dataLength: L +""" + + +class table__m_e_t_a(DefaultTable.DefaultTable): + """Metadata table + + The ``meta`` table contains various metadata values for the font. Each + category of metadata in the table is identified by a four-character tag. + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/meta + """ + + def __init__(self, tag=None): + DefaultTable.DefaultTable.__init__(self, tag) + self.data = {} + + def decompile(self, data, ttFont): + headerSize = sstruct.calcsize(META_HEADER_FORMAT) + header = sstruct.unpack(META_HEADER_FORMAT, data[0:headerSize]) + if header["version"] != 1: + raise TTLibError("unsupported 'meta' version %d" % header["version"]) + dataMapSize = sstruct.calcsize(DATA_MAP_FORMAT) + for i in range(header["numDataMaps"]): + dataMapOffset = headerSize + i * dataMapSize + dataMap = sstruct.unpack( + DATA_MAP_FORMAT, data[dataMapOffset : dataMapOffset + dataMapSize] + ) + tag = dataMap["tag"] + offset = dataMap["dataOffset"] + self.data[tag] = data[offset : offset + dataMap["dataLength"]] + if tag in ["dlng", "slng"]: + self.data[tag] = self.data[tag].decode("utf-8") + + def compile(self, ttFont): + keys = sorted(self.data.keys()) + headerSize = sstruct.calcsize(META_HEADER_FORMAT) + dataOffset = headerSize + len(keys) * sstruct.calcsize(DATA_MAP_FORMAT) + header = sstruct.pack( + META_HEADER_FORMAT, + { + "version": 1, + "flags": 0, + "dataOffset": dataOffset, + "numDataMaps": len(keys), + }, + ) + dataMaps = [] + dataBlocks = [] + for tag in keys: + if tag in ["dlng", "slng"]: + data = self.data[tag].encode("utf-8") + else: + data = self.data[tag] + dataMaps.append( + sstruct.pack( + DATA_MAP_FORMAT, + {"tag": tag, "dataOffset": dataOffset, "dataLength": len(data)}, + ) + ) + dataBlocks.append(data) + dataOffset += len(data) + return bytesjoin([header] + dataMaps + dataBlocks) + + def toXML(self, writer, ttFont): + for tag in sorted(self.data.keys()): + if tag in ["dlng", "slng"]: + writer.begintag("text", tag=tag) + writer.newline() + writer.write(self.data[tag]) + writer.newline() + writer.endtag("text") + writer.newline() + else: + writer.begintag("hexdata", tag=tag) + writer.newline() + data = self.data[tag] + if min(data) >= 0x20 and max(data) <= 0x7E: + writer.comment("ascii: " + data.decode("ascii")) + writer.newline() + writer.dumphex(data) + writer.endtag("hexdata") + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + if name == "hexdata": + self.data[attrs["tag"]] = readHex(content) + elif name == "text" and attrs["tag"] in ["dlng", "slng"]: + self.data[attrs["tag"]] = strjoin(content).strip() + else: + raise TTLibError("can't handle '%s' element" % name) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_m_o_r_t.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_m_o_r_t.py new file mode 100644 index 0000000000000000000000000000000000000000..5e5fa77ce73fff4906d92610afd9914eb2b61a3c --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_m_o_r_t.py @@ -0,0 +1,14 @@ +from .otBase import BaseTTXConverter + + +# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6mort.html +class table__m_o_r_t(BaseTTXConverter): + """The AAT ``mort`` table contains glyph transformations used for script shaping and + for various other optional smart features. + + Note: ``mort`` has been deprecated in favor of the newer ``morx`` table. + + See also https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6mort.html + """ + + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_o_p_b_d.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_o_p_b_d.py new file mode 100644 index 0000000000000000000000000000000000000000..b4c5f568290e20563992de91c7a0f5e6928652bf --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_o_p_b_d.py @@ -0,0 +1,14 @@ +from .otBase import BaseTTXConverter + + +# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6opbd.html +class table__o_p_b_d(BaseTTXConverter): + """Optical Bounds table + + The AAT ``opbd`` table contains optical boundary points for glyphs, which + applications can use for the visual alignment of lines of text. + + See also https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6opbd.html + """ + + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_p_r_o_p.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_p_r_o_p.py new file mode 100644 index 0000000000000000000000000000000000000000..1d7de8098de797268cd14607939e78e0c5c7bf5a --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_p_r_o_p.py @@ -0,0 +1,12 @@ +from .otBase import BaseTTXConverter + + +# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6prop.html +class table__p_r_o_p(BaseTTXConverter): + """The AAT ``prop`` table can store a variety of per-glyph properties, such as + Unicode directionality or whether glyphs are non-spacing marks. + + See also https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6prop.html + """ + + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_s_b_i_x.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_s_b_i_x.py new file mode 100644 index 0000000000000000000000000000000000000000..a282ea9a60d1a1e5f58747db6079d7c493504295 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/_s_b_i_x.py @@ -0,0 +1,129 @@ +from fontTools.misc import sstruct +from fontTools.misc.textTools import safeEval, num2binary, binary2num +from . import DefaultTable +from .sbixStrike import Strike + + +sbixHeaderFormat = """ + > + version: H # Version number (set to 1) + flags: H # The only two bits used in the flags field are bits 0 + # and 1. For historical reasons, bit 0 must always be 1. + # Bit 1 is a sbixDrawOutlines flag and is interpreted as + # follows: + # 0: Draw only 'sbix' bitmaps + # 1: Draw both 'sbix' bitmaps and outlines, in that + # order + numStrikes: L # Number of bitmap strikes to follow +""" +sbixHeaderFormatSize = sstruct.calcsize(sbixHeaderFormat) + + +sbixStrikeOffsetFormat = """ + > + strikeOffset: L # Offset from begining of table to data for the + # individual strike +""" +sbixStrikeOffsetFormatSize = sstruct.calcsize(sbixStrikeOffsetFormat) + + +class table__s_b_i_x(DefaultTable.DefaultTable): + """Standard Bitmap Graphics table + + The ``sbix`` table stores bitmap image data in standard graphics formats + like JPEG, PNG, or TIFF. The glyphs for which the ``sbix`` table provides + data are indexed by Glyph ID. For each such glyph, the ``sbix`` table can + hold different data for different sizes, called "strikes." + + See also https://learn.microsoft.com/en-us/typography/opentype/spec/sbix + """ + + def __init__(self, tag=None): + DefaultTable.DefaultTable.__init__(self, tag) + self.version = 1 + self.flags = 1 + self.numStrikes = 0 + self.strikes = {} + self.strikeOffsets = [] + + def decompile(self, data, ttFont): + # read table header + sstruct.unpack(sbixHeaderFormat, data[:sbixHeaderFormatSize], self) + # collect offsets to individual strikes in self.strikeOffsets + for i in range(self.numStrikes): + current_offset = sbixHeaderFormatSize + i * sbixStrikeOffsetFormatSize + offset_entry = sbixStrikeOffset() + sstruct.unpack( + sbixStrikeOffsetFormat, + data[current_offset : current_offset + sbixStrikeOffsetFormatSize], + offset_entry, + ) + self.strikeOffsets.append(offset_entry.strikeOffset) + + # decompile Strikes + for i in range(self.numStrikes - 1, -1, -1): + current_strike = Strike(rawdata=data[self.strikeOffsets[i] :]) + data = data[: self.strikeOffsets[i]] + current_strike.decompile(ttFont) + # print " Strike length: %xh" % len(bitmapSetData) + # print "Number of Glyph entries:", len(current_strike.glyphs) + if current_strike.ppem in self.strikes: + from fontTools import ttLib + + raise ttLib.TTLibError("Pixel 'ppem' must be unique for each Strike") + self.strikes[current_strike.ppem] = current_strike + + # after the glyph data records have been extracted, we don't need the offsets anymore + del self.strikeOffsets + del self.numStrikes + + def compile(self, ttFont): + sbixData = b"" + self.numStrikes = len(self.strikes) + sbixHeader = sstruct.pack(sbixHeaderFormat, self) + + # calculate offset to start of first strike + setOffset = sbixHeaderFormatSize + sbixStrikeOffsetFormatSize * self.numStrikes + + for si in sorted(self.strikes.keys()): + current_strike = self.strikes[si] + current_strike.compile(ttFont) + # append offset to this strike to table header + current_strike.strikeOffset = setOffset + sbixHeader += sstruct.pack(sbixStrikeOffsetFormat, current_strike) + setOffset += len(current_strike.data) + sbixData += current_strike.data + + return sbixHeader + sbixData + + def toXML(self, xmlWriter, ttFont): + xmlWriter.simpletag("version", value=self.version) + xmlWriter.newline() + xmlWriter.simpletag("flags", value=num2binary(self.flags, 16)) + xmlWriter.newline() + for i in sorted(self.strikes.keys()): + self.strikes[i].toXML(xmlWriter, ttFont) + + def fromXML(self, name, attrs, content, ttFont): + if name == "version": + setattr(self, name, safeEval(attrs["value"])) + elif name == "flags": + setattr(self, name, binary2num(attrs["value"])) + elif name == "strike": + current_strike = Strike() + for element in content: + if isinstance(element, tuple): + name, attrs, content = element + current_strike.fromXML(name, attrs, content, ttFont) + self.strikes[current_strike.ppem] = current_strike + else: + from fontTools import ttLib + + raise ttLib.TTLibError("can't handle '%s' element" % name) + + +# Helper classes + + +class sbixStrikeOffset(object): + pass diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/asciiTable.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/asciiTable.py new file mode 100644 index 0000000000000000000000000000000000000000..6f81c526b372b268b253da47c337715e316ee4d4 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/asciiTable.py @@ -0,0 +1,20 @@ +from fontTools.misc.textTools import strjoin, tobytes, tostr +from . import DefaultTable + + +class asciiTable(DefaultTable.DefaultTable): + def toXML(self, writer, ttFont): + data = tostr(self.data) + # removing null bytes. XXX needed?? + data = data.split("\0") + data = strjoin(data) + writer.begintag("source") + writer.newline() + writer.write_noindent(data) + writer.newline() + writer.endtag("source") + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + lines = strjoin(content).split("\n") + self.data = tobytes("\n".join(lines[1:-1])) diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/grUtils.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/grUtils.py new file mode 100644 index 0000000000000000000000000000000000000000..785684b1eb30a76ae598bfe46416d4556fc422a0 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/grUtils.py @@ -0,0 +1,92 @@ +import struct, warnings + +try: + import lz4 +except ImportError: + lz4 = None +else: + import lz4.block + +# old scheme for VERSION < 0.9 otherwise use lz4.block + + +def decompress(data): + (compression,) = struct.unpack(">L", data[4:8]) + scheme = compression >> 27 + size = compression & 0x07FFFFFF + if scheme == 0: + pass + elif scheme == 1 and lz4: + res = lz4.block.decompress(struct.pack("L", (scheme << 27) + (len(data) & 0x07FFFFFF)) + if scheme == 0: + return data + elif scheme == 1 and lz4: + res = lz4.block.compress( + data, mode="high_compression", compression=16, store_size=False + ) + return hdr + res + else: + warnings.warn("Table failed to compress by unsupported compression scheme") + return data + + +def _entries(attrs, sameval): + ak = 0 + vals = [] + lastv = 0 + for k, v in attrs: + if len(vals) and (k != ak + 1 or (sameval and v != lastv)): + yield (ak - len(vals) + 1, len(vals), vals) + vals = [] + ak = k + vals.append(v) + lastv = v + yield (ak - len(vals) + 1, len(vals), vals) + + +def entries(attributes, sameval=False): + g = _entries(sorted(attributes.items(), key=lambda x: int(x[0])), sameval) + return g + + +def bininfo(num, size=1): + if num == 0: + return struct.pack(">4H", 0, 0, 0, 0) + srange = 1 + select = 0 + while srange <= num: + srange *= 2 + select += 1 + select -= 1 + srange //= 2 + srange *= size + shift = num * size - srange + return struct.pack(">4H", num, srange, select, shift) + + +def num2tag(n): + if n < 0x200000: + return str(n) + else: + return ( + struct.unpack("4s", struct.pack(">L", n))[0].replace(b"\000", b"").decode() + ) + + +def tag2num(n): + try: + return int(n) + except ValueError: + n = (n + " ")[:4] + return struct.unpack(">L", n.encode("ascii"))[0] diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/otData.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/otData.py new file mode 100644 index 0000000000000000000000000000000000000000..f538aeb48ca5515edfb36d012da5f2661b6e832d --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/otData.py @@ -0,0 +1,6400 @@ +otData = [ + # + # common + # + ("LookupOrder", []), + ( + "ScriptList", + [ + ("uint16", "ScriptCount", None, None, "Number of ScriptRecords"), + ( + "struct", + "ScriptRecord", + "ScriptCount", + 0, + "Array of ScriptRecords -listed alphabetically by ScriptTag", + ), + ], + ), + ( + "ScriptRecord", + [ + ("Tag", "ScriptTag", None, None, "4-byte ScriptTag identifier"), + ( + "Offset", + "Script", + None, + None, + "Offset to Script table-from beginning of ScriptList", + ), + ], + ), + ( + "Script", + [ + ( + "Offset", + "DefaultLangSys", + None, + None, + "Offset to DefaultLangSys table-from beginning of Script table-may be NULL", + ), + ( + "uint16", + "LangSysCount", + None, + None, + "Number of LangSysRecords for this script-excluding the DefaultLangSys", + ), + ( + "struct", + "LangSysRecord", + "LangSysCount", + 0, + "Array of LangSysRecords-listed alphabetically by LangSysTag", + ), + ], + ), + ( + "LangSysRecord", + [ + ("Tag", "LangSysTag", None, None, "4-byte LangSysTag identifier"), + ( + "Offset", + "LangSys", + None, + None, + "Offset to LangSys table-from beginning of Script table", + ), + ], + ), + ( + "LangSys", + [ + ( + "Offset", + "LookupOrder", + None, + None, + "= NULL (reserved for an offset to a reordering table)", + ), + ( + "uint16", + "ReqFeatureIndex", + None, + None, + "Index of a feature required for this language system- if no required features = 0xFFFF", + ), + ( + "uint16", + "FeatureCount", + None, + None, + "Number of FeatureIndex values for this language system-excludes the required feature", + ), + ( + "uint16", + "FeatureIndex", + "FeatureCount", + 0, + "Array of indices into the FeatureList-in arbitrary order", + ), + ], + ), + ( + "FeatureList", + [ + ( + "uint16", + "FeatureCount", + None, + None, + "Number of FeatureRecords in this table", + ), + ( + "struct", + "FeatureRecord", + "FeatureCount", + 0, + "Array of FeatureRecords-zero-based (first feature has FeatureIndex = 0)-listed alphabetically by FeatureTag", + ), + ], + ), + ( + "FeatureRecord", + [ + ("Tag", "FeatureTag", None, None, "4-byte feature identification tag"), + ( + "Offset", + "Feature", + None, + None, + "Offset to Feature table-from beginning of FeatureList", + ), + ], + ), + ( + "Feature", + [ + ( + "Offset", + "FeatureParams", + None, + None, + "= NULL (reserved for offset to FeatureParams)", + ), + ( + "uint16", + "LookupCount", + None, + None, + "Number of LookupList indices for this feature", + ), + ( + "uint16", + "LookupListIndex", + "LookupCount", + 0, + "Array of LookupList indices for this feature -zero-based (first lookup is LookupListIndex = 0)", + ), + ], + ), + ("FeatureParams", []), + ( + "FeatureParamsSize", + [ + ( + "DeciPoints", + "DesignSize", + None, + None, + "The design size in 720/inch units (decipoints).", + ), + ( + "uint16", + "SubfamilyID", + None, + None, + "Serves as an identifier that associates fonts in a subfamily.", + ), + ("NameID", "SubfamilyNameID", None, None, "Subfamily NameID."), + ( + "DeciPoints", + "RangeStart", + None, + None, + "Small end of recommended usage range (exclusive) in 720/inch units.", + ), + ( + "DeciPoints", + "RangeEnd", + None, + None, + "Large end of recommended usage range (inclusive) in 720/inch units.", + ), + ], + ), + ( + "FeatureParamsStylisticSet", + [ + ("uint16", "Version", None, None, "Set to 0."), + ("NameID", "UINameID", None, None, "UI NameID."), + ], + ), + ( + "FeatureParamsCharacterVariants", + [ + ("uint16", "Format", None, None, "Set to 0."), + ("NameID", "FeatUILabelNameID", None, None, "Feature UI label NameID."), + ( + "NameID", + "FeatUITooltipTextNameID", + None, + None, + "Feature UI tooltip text NameID.", + ), + ("NameID", "SampleTextNameID", None, None, "Sample text NameID."), + ("uint16", "NumNamedParameters", None, None, "Number of named parameters."), + ( + "NameID", + "FirstParamUILabelNameID", + None, + None, + "First NameID of UI feature parameters.", + ), + ( + "uint16", + "CharCount", + None, + None, + "Count of characters this feature provides glyph variants for.", + ), + ( + "uint24", + "Character", + "CharCount", + 0, + "Unicode characters for which this feature provides glyph variants.", + ), + ], + ), + ( + "LookupList", + [ + ("uint16", "LookupCount", None, None, "Number of lookups in this table"), + ( + "Offset", + "Lookup", + "LookupCount", + 0, + "Array of offsets to Lookup tables-from beginning of LookupList -zero based (first lookup is Lookup index = 0)", + ), + ], + ), + ( + "Lookup", + [ + ( + "uint16", + "LookupType", + None, + None, + "Different enumerations for GSUB and GPOS", + ), + ("LookupFlag", "LookupFlag", None, None, "Lookup qualifiers"), + ( + "uint16", + "SubTableCount", + None, + None, + "Number of SubTables for this lookup", + ), + ( + "Offset", + "SubTable", + "SubTableCount", + 0, + "Array of offsets to SubTables-from beginning of Lookup table", + ), + ( + "uint16", + "MarkFilteringSet", + None, + "LookupFlag & 0x0010", + "If set, indicates that the lookup table structure is followed by a MarkFilteringSet field. The layout engine skips over all mark glyphs not in the mark filtering set indicated.", + ), + ], + ), + ( + "CoverageFormat1", + [ + ("uint16", "CoverageFormat", None, None, "Format identifier-format = 1"), + ("uint16", "GlyphCount", None, None, "Number of glyphs in the GlyphArray"), + ( + "GlyphID", + "GlyphArray", + "GlyphCount", + 0, + "Array of GlyphIDs-in numerical order", + ), + ], + ), + ( + "CoverageFormat2", + [ + ("uint16", "CoverageFormat", None, None, "Format identifier-format = 2"), + ("uint16", "RangeCount", None, None, "Number of RangeRecords"), + ( + "struct", + "RangeRecord", + "RangeCount", + 0, + "Array of glyph ranges-ordered by Start GlyphID", + ), + ], + ), + ( + "RangeRecord", + [ + ("GlyphID", "Start", None, None, "First GlyphID in the range"), + ("GlyphID", "End", None, None, "Last GlyphID in the range"), + ( + "uint16", + "StartCoverageIndex", + None, + None, + "Coverage Index of first GlyphID in range", + ), + ], + ), + ( + "ClassDefFormat1", + [ + ("uint16", "ClassFormat", None, None, "Format identifier-format = 1"), + ( + "GlyphID", + "StartGlyph", + None, + None, + "First GlyphID of the ClassValueArray", + ), + ("uint16", "GlyphCount", None, None, "Size of the ClassValueArray"), + ( + "uint16", + "ClassValueArray", + "GlyphCount", + 0, + "Array of Class Values-one per GlyphID", + ), + ], + ), + ( + "ClassDefFormat2", + [ + ("uint16", "ClassFormat", None, None, "Format identifier-format = 2"), + ("uint16", "ClassRangeCount", None, None, "Number of ClassRangeRecords"), + ( + "struct", + "ClassRangeRecord", + "ClassRangeCount", + 0, + "Array of ClassRangeRecords-ordered by Start GlyphID", + ), + ], + ), + ( + "ClassRangeRecord", + [ + ("GlyphID", "Start", None, None, "First GlyphID in the range"), + ("GlyphID", "End", None, None, "Last GlyphID in the range"), + ("uint16", "Class", None, None, "Applied to all glyphs in the range"), + ], + ), + ( + "Device", + [ + ("uint16", "StartSize", None, None, "Smallest size to correct-in ppem"), + ("uint16", "EndSize", None, None, "Largest size to correct-in ppem"), + ( + "uint16", + "DeltaFormat", + None, + None, + "Format of DeltaValue array data: 1, 2, or 3", + ), + ( + "DeltaValue", + "DeltaValue", + None, + "DeltaFormat in (1,2,3)", + "Array of compressed data", + ), + ], + ), + # + # gpos + # + ( + "GPOS", + [ + ( + "Version", + "Version", + None, + None, + "Version of the GPOS table- 0x00010000 or 0x00010001", + ), + ( + "Offset", + "ScriptList", + None, + None, + "Offset to ScriptList table-from beginning of GPOS table", + ), + ( + "Offset", + "FeatureList", + None, + None, + "Offset to FeatureList table-from beginning of GPOS table", + ), + ( + "Offset", + "LookupList", + None, + None, + "Offset to LookupList table-from beginning of GPOS table", + ), + ( + "LOffset", + "FeatureVariations", + None, + "Version >= 0x00010001", + "Offset to FeatureVariations table-from beginning of GPOS table", + ), + ], + ), + ( + "SinglePosFormat1", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of SinglePos subtable", + ), + ( + "uint16", + "ValueFormat", + None, + None, + "Defines the types of data in the ValueRecord", + ), + ( + "ValueRecord", + "Value", + None, + None, + "Defines positioning value(s)-applied to all glyphs in the Coverage table", + ), + ], + ), + ( + "SinglePosFormat2", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 2"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of SinglePos subtable", + ), + ( + "uint16", + "ValueFormat", + None, + None, + "Defines the types of data in the ValueRecord", + ), + ("uint16", "ValueCount", None, None, "Number of ValueRecords"), + ( + "ValueRecord", + "Value", + "ValueCount", + 0, + "Array of ValueRecords-positioning values applied to glyphs", + ), + ], + ), + ( + "PairPosFormat1", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of PairPos subtable-only the first glyph in each pair", + ), + ( + "uint16", + "ValueFormat1", + None, + None, + "Defines the types of data in ValueRecord1-for the first glyph in the pair -may be zero (0)", + ), + ( + "uint16", + "ValueFormat2", + None, + None, + "Defines the types of data in ValueRecord2-for the second glyph in the pair -may be zero (0)", + ), + ("uint16", "PairSetCount", None, None, "Number of PairSet tables"), + ( + "Offset", + "PairSet", + "PairSetCount", + 0, + "Array of offsets to PairSet tables-from beginning of PairPos subtable-ordered by Coverage Index", + ), + ], + ), + ( + "PairSet", + [ + ("uint16", "PairValueCount", None, None, "Number of PairValueRecords"), + ( + "struct", + "PairValueRecord", + "PairValueCount", + 0, + "Array of PairValueRecords-ordered by GlyphID of the second glyph", + ), + ], + ), + ( + "PairValueRecord", + [ + ( + "GlyphID", + "SecondGlyph", + None, + None, + "GlyphID of second glyph in the pair-first glyph is listed in the Coverage table", + ), + ( + "ValueRecord", + "Value1", + None, + None, + "Positioning data for the first glyph in the pair", + ), + ( + "ValueRecord", + "Value2", + None, + None, + "Positioning data for the second glyph in the pair", + ), + ], + ), + ( + "PairPosFormat2", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 2"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of PairPos subtable-for the first glyph of the pair", + ), + ( + "uint16", + "ValueFormat1", + None, + None, + "ValueRecord definition-for the first glyph of the pair-may be zero (0)", + ), + ( + "uint16", + "ValueFormat2", + None, + None, + "ValueRecord definition-for the second glyph of the pair-may be zero (0)", + ), + ( + "Offset", + "ClassDef1", + None, + None, + "Offset to ClassDef table-from beginning of PairPos subtable-for the first glyph of the pair", + ), + ( + "Offset", + "ClassDef2", + None, + None, + "Offset to ClassDef table-from beginning of PairPos subtable-for the second glyph of the pair", + ), + ( + "uint16", + "Class1Count", + None, + None, + "Number of classes in ClassDef1 table-includes Class0", + ), + ( + "uint16", + "Class2Count", + None, + None, + "Number of classes in ClassDef2 table-includes Class0", + ), + ( + "struct", + "Class1Record", + "Class1Count", + 0, + "Array of Class1 records-ordered by Class1", + ), + ], + ), + ( + "Class1Record", + [ + ( + "struct", + "Class2Record", + "Class2Count", + 0, + "Array of Class2 records-ordered by Class2", + ), + ], + ), + ( + "Class2Record", + [ + ( + "ValueRecord", + "Value1", + None, + None, + "Positioning for first glyph-empty if ValueFormat1 = 0", + ), + ( + "ValueRecord", + "Value2", + None, + None, + "Positioning for second glyph-empty if ValueFormat2 = 0", + ), + ], + ), + ( + "CursivePosFormat1", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of CursivePos subtable", + ), + ("uint16", "EntryExitCount", None, None, "Number of EntryExit records"), + ( + "struct", + "EntryExitRecord", + "EntryExitCount", + 0, + "Array of EntryExit records-in Coverage Index order", + ), + ], + ), + ( + "EntryExitRecord", + [ + ( + "Offset", + "EntryAnchor", + None, + None, + "Offset to EntryAnchor table-from beginning of CursivePos subtable-may be NULL", + ), + ( + "Offset", + "ExitAnchor", + None, + None, + "Offset to ExitAnchor table-from beginning of CursivePos subtable-may be NULL", + ), + ], + ), + ( + "MarkBasePosFormat1", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "MarkCoverage", + None, + None, + "Offset to MarkCoverage table-from beginning of MarkBasePos subtable", + ), + ( + "Offset", + "BaseCoverage", + None, + None, + "Offset to BaseCoverage table-from beginning of MarkBasePos subtable", + ), + ("uint16", "ClassCount", None, None, "Number of classes defined for marks"), + ( + "Offset", + "MarkArray", + None, + None, + "Offset to MarkArray table-from beginning of MarkBasePos subtable", + ), + ( + "Offset", + "BaseArray", + None, + None, + "Offset to BaseArray table-from beginning of MarkBasePos subtable", + ), + ], + ), + ( + "BaseArray", + [ + ("uint16", "BaseCount", None, None, "Number of BaseRecords"), + ( + "struct", + "BaseRecord", + "BaseCount", + 0, + "Array of BaseRecords-in order of BaseCoverage Index", + ), + ], + ), + ( + "BaseRecord", + [ + ( + "Offset", + "BaseAnchor", + "ClassCount", + 0, + "Array of offsets (one per class) to Anchor tables-from beginning of BaseArray table-ordered by class-zero-based", + ), + ], + ), + ( + "MarkLigPosFormat1", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "MarkCoverage", + None, + None, + "Offset to Mark Coverage table-from beginning of MarkLigPos subtable", + ), + ( + "Offset", + "LigatureCoverage", + None, + None, + "Offset to Ligature Coverage table-from beginning of MarkLigPos subtable", + ), + ("uint16", "ClassCount", None, None, "Number of defined mark classes"), + ( + "Offset", + "MarkArray", + None, + None, + "Offset to MarkArray table-from beginning of MarkLigPos subtable", + ), + ( + "Offset", + "LigatureArray", + None, + None, + "Offset to LigatureArray table-from beginning of MarkLigPos subtable", + ), + ], + ), + ( + "LigatureArray", + [ + ( + "uint16", + "LigatureCount", + None, + None, + "Number of LigatureAttach table offsets", + ), + ( + "Offset", + "LigatureAttach", + "LigatureCount", + 0, + "Array of offsets to LigatureAttach tables-from beginning of LigatureArray table-ordered by LigatureCoverage Index", + ), + ], + ), + ( + "LigatureAttach", + [ + ( + "uint16", + "ComponentCount", + None, + None, + "Number of ComponentRecords in this ligature", + ), + ( + "struct", + "ComponentRecord", + "ComponentCount", + 0, + "Array of Component records-ordered in writing direction", + ), + ], + ), + ( + "ComponentRecord", + [ + ( + "Offset", + "LigatureAnchor", + "ClassCount", + 0, + "Array of offsets (one per class) to Anchor tables-from beginning of LigatureAttach table-ordered by class-NULL if a component does not have an attachment for a class-zero-based array", + ), + ], + ), + ( + "MarkMarkPosFormat1", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "Mark1Coverage", + None, + None, + "Offset to Combining Mark Coverage table-from beginning of MarkMarkPos subtable", + ), + ( + "Offset", + "Mark2Coverage", + None, + None, + "Offset to Base Mark Coverage table-from beginning of MarkMarkPos subtable", + ), + ( + "uint16", + "ClassCount", + None, + None, + "Number of Combining Mark classes defined", + ), + ( + "Offset", + "Mark1Array", + None, + None, + "Offset to MarkArray table for Mark1-from beginning of MarkMarkPos subtable", + ), + ( + "Offset", + "Mark2Array", + None, + None, + "Offset to Mark2Array table for Mark2-from beginning of MarkMarkPos subtable", + ), + ], + ), + ( + "Mark2Array", + [ + ("uint16", "Mark2Count", None, None, "Number of Mark2 records"), + ( + "struct", + "Mark2Record", + "Mark2Count", + 0, + "Array of Mark2 records-in Coverage order", + ), + ], + ), + ( + "Mark2Record", + [ + ( + "Offset", + "Mark2Anchor", + "ClassCount", + 0, + "Array of offsets (one per class) to Anchor tables-from beginning of Mark2Array table-zero-based array", + ), + ], + ), + ( + "PosLookupRecord", + [ + ( + "uint16", + "SequenceIndex", + None, + None, + "Index to input glyph sequence-first glyph = 0", + ), + ( + "uint16", + "LookupListIndex", + None, + None, + "Lookup to apply to that position-zero-based", + ), + ], + ), + ( + "ContextPosFormat1", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of ContextPos subtable", + ), + ("uint16", "PosRuleSetCount", None, None, "Number of PosRuleSet tables"), + ( + "Offset", + "PosRuleSet", + "PosRuleSetCount", + 0, + "Array of offsets to PosRuleSet tables-from beginning of ContextPos subtable-ordered by Coverage Index", + ), + ], + ), + ( + "PosRuleSet", + [ + ("uint16", "PosRuleCount", None, None, "Number of PosRule tables"), + ( + "Offset", + "PosRule", + "PosRuleCount", + 0, + "Array of offsets to PosRule tables-from beginning of PosRuleSet-ordered by preference", + ), + ], + ), + ( + "PosRule", + [ + ( + "uint16", + "GlyphCount", + None, + None, + "Number of glyphs in the Input glyph sequence", + ), + ("uint16", "PosCount", None, None, "Number of PosLookupRecords"), + ( + "GlyphID", + "Input", + "GlyphCount", + -1, + "Array of input GlyphIDs-starting with the second glyph", + ), + ( + "struct", + "PosLookupRecord", + "PosCount", + 0, + "Array of positioning lookups-in design order", + ), + ], + ), + ( + "ContextPosFormat2", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 2"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of ContextPos subtable", + ), + ( + "Offset", + "ClassDef", + None, + None, + "Offset to ClassDef table-from beginning of ContextPos subtable", + ), + ("uint16", "PosClassSetCount", None, None, "Number of PosClassSet tables"), + ( + "Offset", + "PosClassSet", + "PosClassSetCount", + 0, + "Array of offsets to PosClassSet tables-from beginning of ContextPos subtable-ordered by class-may be NULL", + ), + ], + ), + ( + "PosClassSet", + [ + ( + "uint16", + "PosClassRuleCount", + None, + None, + "Number of PosClassRule tables", + ), + ( + "Offset", + "PosClassRule", + "PosClassRuleCount", + 0, + "Array of offsets to PosClassRule tables-from beginning of PosClassSet-ordered by preference", + ), + ], + ), + ( + "PosClassRule", + [ + ("uint16", "GlyphCount", None, None, "Number of glyphs to be matched"), + ("uint16", "PosCount", None, None, "Number of PosLookupRecords"), + ( + "uint16", + "Class", + "GlyphCount", + -1, + "Array of classes-beginning with the second class-to be matched to the input glyph sequence", + ), + ( + "struct", + "PosLookupRecord", + "PosCount", + 0, + "Array of positioning lookups-in design order", + ), + ], + ), + ( + "ContextPosFormat3", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 3"), + ( + "uint16", + "GlyphCount", + None, + None, + "Number of glyphs in the input sequence", + ), + ("uint16", "PosCount", None, None, "Number of PosLookupRecords"), + ( + "Offset", + "Coverage", + "GlyphCount", + 0, + "Array of offsets to Coverage tables-from beginning of ContextPos subtable", + ), + ( + "struct", + "PosLookupRecord", + "PosCount", + 0, + "Array of positioning lookups-in design order", + ), + ], + ), + ( + "ChainContextPosFormat1", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of ContextPos subtable", + ), + ( + "uint16", + "ChainPosRuleSetCount", + None, + None, + "Number of ChainPosRuleSet tables", + ), + ( + "Offset", + "ChainPosRuleSet", + "ChainPosRuleSetCount", + 0, + "Array of offsets to ChainPosRuleSet tables-from beginning of ContextPos subtable-ordered by Coverage Index", + ), + ], + ), + ( + "ChainPosRuleSet", + [ + ( + "uint16", + "ChainPosRuleCount", + None, + None, + "Number of ChainPosRule tables", + ), + ( + "Offset", + "ChainPosRule", + "ChainPosRuleCount", + 0, + "Array of offsets to ChainPosRule tables-from beginning of ChainPosRuleSet-ordered by preference", + ), + ], + ), + ( + "ChainPosRule", + [ + ( + "uint16", + "BacktrackGlyphCount", + None, + None, + "Total number of glyphs in the backtrack sequence (number of glyphs to be matched before the first glyph)", + ), + ( + "GlyphID", + "Backtrack", + "BacktrackGlyphCount", + 0, + "Array of backtracking GlyphID's (to be matched before the input sequence)", + ), + ( + "uint16", + "InputGlyphCount", + None, + None, + "Total number of glyphs in the input sequence (includes the first glyph)", + ), + ( + "GlyphID", + "Input", + "InputGlyphCount", + -1, + "Array of input GlyphIDs (start with second glyph)", + ), + ( + "uint16", + "LookAheadGlyphCount", + None, + None, + "Total number of glyphs in the look ahead sequence (number of glyphs to be matched after the input sequence)", + ), + ( + "GlyphID", + "LookAhead", + "LookAheadGlyphCount", + 0, + "Array of lookahead GlyphID's (to be matched after the input sequence)", + ), + ("uint16", "PosCount", None, None, "Number of PosLookupRecords"), + ( + "struct", + "PosLookupRecord", + "PosCount", + 0, + "Array of PosLookupRecords (in design order)", + ), + ], + ), + ( + "ChainContextPosFormat2", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 2"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of ChainContextPos subtable", + ), + ( + "Offset", + "BacktrackClassDef", + None, + None, + "Offset to ClassDef table containing backtrack sequence context-from beginning of ChainContextPos subtable", + ), + ( + "Offset", + "InputClassDef", + None, + None, + "Offset to ClassDef table containing input sequence context-from beginning of ChainContextPos subtable", + ), + ( + "Offset", + "LookAheadClassDef", + None, + None, + "Offset to ClassDef table containing lookahead sequence context-from beginning of ChainContextPos subtable", + ), + ( + "uint16", + "ChainPosClassSetCount", + None, + None, + "Number of ChainPosClassSet tables", + ), + ( + "Offset", + "ChainPosClassSet", + "ChainPosClassSetCount", + 0, + "Array of offsets to ChainPosClassSet tables-from beginning of ChainContextPos subtable-ordered by input class-may be NULL", + ), + ], + ), + ( + "ChainPosClassSet", + [ + ( + "uint16", + "ChainPosClassRuleCount", + None, + None, + "Number of ChainPosClassRule tables", + ), + ( + "Offset", + "ChainPosClassRule", + "ChainPosClassRuleCount", + 0, + "Array of offsets to ChainPosClassRule tables-from beginning of ChainPosClassSet-ordered by preference", + ), + ], + ), + ( + "ChainPosClassRule", + [ + ( + "uint16", + "BacktrackGlyphCount", + None, + None, + "Total number of glyphs in the backtrack sequence (number of glyphs to be matched before the first glyph)", + ), + ( + "uint16", + "Backtrack", + "BacktrackGlyphCount", + 0, + "Array of backtracking classes(to be matched before the input sequence)", + ), + ( + "uint16", + "InputGlyphCount", + None, + None, + "Total number of classes in the input sequence (includes the first class)", + ), + ( + "uint16", + "Input", + "InputGlyphCount", + -1, + "Array of input classes(start with second class; to be matched with the input glyph sequence)", + ), + ( + "uint16", + "LookAheadGlyphCount", + None, + None, + "Total number of classes in the look ahead sequence (number of classes to be matched after the input sequence)", + ), + ( + "uint16", + "LookAhead", + "LookAheadGlyphCount", + 0, + "Array of lookahead classes(to be matched after the input sequence)", + ), + ("uint16", "PosCount", None, None, "Number of PosLookupRecords"), + ( + "struct", + "PosLookupRecord", + "PosCount", + 0, + "Array of PosLookupRecords (in design order)", + ), + ], + ), + ( + "ChainContextPosFormat3", + [ + ("uint16", "PosFormat", None, None, "Format identifier-format = 3"), + ( + "uint16", + "BacktrackGlyphCount", + None, + None, + "Number of glyphs in the backtracking sequence", + ), + ( + "Offset", + "BacktrackCoverage", + "BacktrackGlyphCount", + 0, + "Array of offsets to coverage tables in backtracking sequence, in glyph sequence order", + ), + ( + "uint16", + "InputGlyphCount", + None, + None, + "Number of glyphs in input sequence", + ), + ( + "Offset", + "InputCoverage", + "InputGlyphCount", + 0, + "Array of offsets to coverage tables in input sequence, in glyph sequence order", + ), + ( + "uint16", + "LookAheadGlyphCount", + None, + None, + "Number of glyphs in lookahead sequence", + ), + ( + "Offset", + "LookAheadCoverage", + "LookAheadGlyphCount", + 0, + "Array of offsets to coverage tables in lookahead sequence, in glyph sequence order", + ), + ("uint16", "PosCount", None, None, "Number of PosLookupRecords"), + ( + "struct", + "PosLookupRecord", + "PosCount", + 0, + "Array of PosLookupRecords,in design order", + ), + ], + ), + ( + "ExtensionPosFormat1", + [ + ("uint16", "ExtFormat", None, None, "Format identifier. Set to 1."), + ( + "uint16", + "ExtensionLookupType", + None, + None, + "Lookup type of subtable referenced by ExtensionOffset (i.e. the extension subtable).", + ), + ("LOffset", "ExtSubTable", None, None, "Offset to SubTable"), + ], + ), + # ('ValueRecord', [ + # ('int16', 'XPlacement', None, None, 'Horizontal adjustment for placement-in design units'), + # ('int16', 'YPlacement', None, None, 'Vertical adjustment for placement-in design units'), + # ('int16', 'XAdvance', None, None, 'Horizontal adjustment for advance-in design units (only used for horizontal writing)'), + # ('int16', 'YAdvance', None, None, 'Vertical adjustment for advance-in design units (only used for vertical writing)'), + # ('Offset', 'XPlaDevice', None, None, 'Offset to Device table for horizontal placement-measured from beginning of PosTable (may be NULL)'), + # ('Offset', 'YPlaDevice', None, None, 'Offset to Device table for vertical placement-measured from beginning of PosTable (may be NULL)'), + # ('Offset', 'XAdvDevice', None, None, 'Offset to Device table for horizontal advance-measured from beginning of PosTable (may be NULL)'), + # ('Offset', 'YAdvDevice', None, None, 'Offset to Device table for vertical advance-measured from beginning of PosTable (may be NULL)'), + # ]), + ( + "AnchorFormat1", + [ + ("uint16", "AnchorFormat", None, None, "Format identifier-format = 1"), + ("int16", "XCoordinate", None, None, "Horizontal value-in design units"), + ("int16", "YCoordinate", None, None, "Vertical value-in design units"), + ], + ), + ( + "AnchorFormat2", + [ + ("uint16", "AnchorFormat", None, None, "Format identifier-format = 2"), + ("int16", "XCoordinate", None, None, "Horizontal value-in design units"), + ("int16", "YCoordinate", None, None, "Vertical value-in design units"), + ("uint16", "AnchorPoint", None, None, "Index to glyph contour point"), + ], + ), + ( + "AnchorFormat3", + [ + ("uint16", "AnchorFormat", None, None, "Format identifier-format = 3"), + ("int16", "XCoordinate", None, None, "Horizontal value-in design units"), + ("int16", "YCoordinate", None, None, "Vertical value-in design units"), + ( + "Offset", + "XDeviceTable", + None, + None, + "Offset to Device table for X coordinate- from beginning of Anchor table (may be NULL)", + ), + ( + "Offset", + "YDeviceTable", + None, + None, + "Offset to Device table for Y coordinate- from beginning of Anchor table (may be NULL)", + ), + ], + ), + ( + "MarkArray", + [ + ("uint16", "MarkCount", None, None, "Number of MarkRecords"), + ( + "struct", + "MarkRecord", + "MarkCount", + 0, + "Array of MarkRecords-in Coverage order", + ), + ], + ), + ( + "MarkRecord", + [ + ("uint16", "Class", None, None, "Class defined for this mark"), + ( + "Offset", + "MarkAnchor", + None, + None, + "Offset to Anchor table-from beginning of MarkArray table", + ), + ], + ), + # + # gsub + # + ( + "GSUB", + [ + ( + "Version", + "Version", + None, + None, + "Version of the GSUB table- 0x00010000 or 0x00010001", + ), + ( + "Offset", + "ScriptList", + None, + None, + "Offset to ScriptList table-from beginning of GSUB table", + ), + ( + "Offset", + "FeatureList", + None, + None, + "Offset to FeatureList table-from beginning of GSUB table", + ), + ( + "Offset", + "LookupList", + None, + None, + "Offset to LookupList table-from beginning of GSUB table", + ), + ( + "LOffset", + "FeatureVariations", + None, + "Version >= 0x00010001", + "Offset to FeatureVariations table-from beginning of GSUB table", + ), + ], + ), + ( + "SingleSubstFormat1", + [ + ("uint16", "SubstFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of Substitution table", + ), + ( + "uint16", + "DeltaGlyphID", + None, + None, + "Add to original GlyphID modulo 65536 to get substitute GlyphID", + ), + ], + ), + ( + "SingleSubstFormat2", + [ + ("uint16", "SubstFormat", None, None, "Format identifier-format = 2"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of Substitution table", + ), + ( + "uint16", + "GlyphCount", + None, + None, + "Number of GlyphIDs in the Substitute array", + ), + ( + "GlyphID", + "Substitute", + "GlyphCount", + 0, + "Array of substitute GlyphIDs-ordered by Coverage Index", + ), + ], + ), + ( + "MultipleSubstFormat1", + [ + ("uint16", "SubstFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of Substitution table", + ), + ( + "uint16", + "SequenceCount", + None, + None, + "Number of Sequence table offsets in the Sequence array", + ), + ( + "Offset", + "Sequence", + "SequenceCount", + 0, + "Array of offsets to Sequence tables-from beginning of Substitution table-ordered by Coverage Index", + ), + ], + ), + ( + "Sequence", + [ + ( + "uint16", + "GlyphCount", + None, + None, + "Number of GlyphIDs in the Substitute array. This should always be greater than 0.", + ), + ( + "GlyphID", + "Substitute", + "GlyphCount", + 0, + "String of GlyphIDs to substitute", + ), + ], + ), + ( + "AlternateSubstFormat1", + [ + ("uint16", "SubstFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of Substitution table", + ), + ( + "uint16", + "AlternateSetCount", + None, + None, + "Number of AlternateSet tables", + ), + ( + "Offset", + "AlternateSet", + "AlternateSetCount", + 0, + "Array of offsets to AlternateSet tables-from beginning of Substitution table-ordered by Coverage Index", + ), + ], + ), + ( + "AlternateSet", + [ + ( + "uint16", + "GlyphCount", + None, + None, + "Number of GlyphIDs in the Alternate array", + ), + ( + "GlyphID", + "Alternate", + "GlyphCount", + 0, + "Array of alternate GlyphIDs-in arbitrary order", + ), + ], + ), + ( + "LigatureSubstFormat1", + [ + ("uint16", "SubstFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of Substitution table", + ), + ("uint16", "LigSetCount", None, None, "Number of LigatureSet tables"), + ( + "Offset", + "LigatureSet", + "LigSetCount", + 0, + "Array of offsets to LigatureSet tables-from beginning of Substitution table-ordered by Coverage Index", + ), + ], + ), + ( + "LigatureSet", + [ + ("uint16", "LigatureCount", None, None, "Number of Ligature tables"), + ( + "Offset", + "Ligature", + "LigatureCount", + 0, + "Array of offsets to Ligature tables-from beginning of LigatureSet table-ordered by preference", + ), + ], + ), + ( + "Ligature", + [ + ("GlyphID", "LigGlyph", None, None, "GlyphID of ligature to substitute"), + ("uint16", "CompCount", None, None, "Number of components in the ligature"), + ( + "GlyphID", + "Component", + "CompCount", + -1, + "Array of component GlyphIDs-start with the second component-ordered in writing direction", + ), + ], + ), + ( + "SubstLookupRecord", + [ + ( + "uint16", + "SequenceIndex", + None, + None, + "Index into current glyph sequence-first glyph = 0", + ), + ( + "uint16", + "LookupListIndex", + None, + None, + "Lookup to apply to that position-zero-based", + ), + ], + ), + ( + "ContextSubstFormat1", + [ + ("uint16", "SubstFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of Substitution table", + ), + ( + "uint16", + "SubRuleSetCount", + None, + None, + "Number of SubRuleSet tables-must equal GlyphCount in Coverage table", + ), + ( + "Offset", + "SubRuleSet", + "SubRuleSetCount", + 0, + "Array of offsets to SubRuleSet tables-from beginning of Substitution table-ordered by Coverage Index", + ), + ], + ), + ( + "SubRuleSet", + [ + ("uint16", "SubRuleCount", None, None, "Number of SubRule tables"), + ( + "Offset", + "SubRule", + "SubRuleCount", + 0, + "Array of offsets to SubRule tables-from beginning of SubRuleSet table-ordered by preference", + ), + ], + ), + ( + "SubRule", + [ + ( + "uint16", + "GlyphCount", + None, + None, + "Total number of glyphs in input glyph sequence-includes the first glyph", + ), + ("uint16", "SubstCount", None, None, "Number of SubstLookupRecords"), + ( + "GlyphID", + "Input", + "GlyphCount", + -1, + "Array of input GlyphIDs-start with second glyph", + ), + ( + "struct", + "SubstLookupRecord", + "SubstCount", + 0, + "Array of SubstLookupRecords-in design order", + ), + ], + ), + ( + "ContextSubstFormat2", + [ + ("uint16", "SubstFormat", None, None, "Format identifier-format = 2"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of Substitution table", + ), + ( + "Offset", + "ClassDef", + None, + None, + "Offset to glyph ClassDef table-from beginning of Substitution table", + ), + ("uint16", "SubClassSetCount", None, None, "Number of SubClassSet tables"), + ( + "Offset", + "SubClassSet", + "SubClassSetCount", + 0, + "Array of offsets to SubClassSet tables-from beginning of Substitution table-ordered by class-may be NULL", + ), + ], + ), + ( + "SubClassSet", + [ + ( + "uint16", + "SubClassRuleCount", + None, + None, + "Number of SubClassRule tables", + ), + ( + "Offset", + "SubClassRule", + "SubClassRuleCount", + 0, + "Array of offsets to SubClassRule tables-from beginning of SubClassSet-ordered by preference", + ), + ], + ), + ( + "SubClassRule", + [ + ( + "uint16", + "GlyphCount", + None, + None, + "Total number of classes specified for the context in the rule-includes the first class", + ), + ("uint16", "SubstCount", None, None, "Number of SubstLookupRecords"), + ( + "uint16", + "Class", + "GlyphCount", + -1, + "Array of classes-beginning with the second class-to be matched to the input glyph class sequence", + ), + ( + "struct", + "SubstLookupRecord", + "SubstCount", + 0, + "Array of Substitution lookups-in design order", + ), + ], + ), + ( + "ContextSubstFormat3", + [ + ("uint16", "SubstFormat", None, None, "Format identifier-format = 3"), + ( + "uint16", + "GlyphCount", + None, + None, + "Number of glyphs in the input glyph sequence", + ), + ("uint16", "SubstCount", None, None, "Number of SubstLookupRecords"), + ( + "Offset", + "Coverage", + "GlyphCount", + 0, + "Array of offsets to Coverage table-from beginning of Substitution table-in glyph sequence order", + ), + ( + "struct", + "SubstLookupRecord", + "SubstCount", + 0, + "Array of SubstLookupRecords-in design order", + ), + ], + ), + ( + "ChainContextSubstFormat1", + [ + ("uint16", "SubstFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of Substitution table", + ), + ( + "uint16", + "ChainSubRuleSetCount", + None, + None, + "Number of ChainSubRuleSet tables-must equal GlyphCount in Coverage table", + ), + ( + "Offset", + "ChainSubRuleSet", + "ChainSubRuleSetCount", + 0, + "Array of offsets to ChainSubRuleSet tables-from beginning of Substitution table-ordered by Coverage Index", + ), + ], + ), + ( + "ChainSubRuleSet", + [ + ( + "uint16", + "ChainSubRuleCount", + None, + None, + "Number of ChainSubRule tables", + ), + ( + "Offset", + "ChainSubRule", + "ChainSubRuleCount", + 0, + "Array of offsets to ChainSubRule tables-from beginning of ChainSubRuleSet table-ordered by preference", + ), + ], + ), + ( + "ChainSubRule", + [ + ( + "uint16", + "BacktrackGlyphCount", + None, + None, + "Total number of glyphs in the backtrack sequence (number of glyphs to be matched before the first glyph)", + ), + ( + "GlyphID", + "Backtrack", + "BacktrackGlyphCount", + 0, + "Array of backtracking GlyphID's (to be matched before the input sequence)", + ), + ( + "uint16", + "InputGlyphCount", + None, + None, + "Total number of glyphs in the input sequence (includes the first glyph)", + ), + ( + "GlyphID", + "Input", + "InputGlyphCount", + -1, + "Array of input GlyphIDs (start with second glyph)", + ), + ( + "uint16", + "LookAheadGlyphCount", + None, + None, + "Total number of glyphs in the look ahead sequence (number of glyphs to be matched after the input sequence)", + ), + ( + "GlyphID", + "LookAhead", + "LookAheadGlyphCount", + 0, + "Array of lookahead GlyphID's (to be matched after the input sequence)", + ), + ("uint16", "SubstCount", None, None, "Number of SubstLookupRecords"), + ( + "struct", + "SubstLookupRecord", + "SubstCount", + 0, + "Array of SubstLookupRecords (in design order)", + ), + ], + ), + ( + "ChainContextSubstFormat2", + [ + ("uint16", "SubstFormat", None, None, "Format identifier-format = 2"), + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table-from beginning of Substitution table", + ), + ( + "Offset", + "BacktrackClassDef", + None, + None, + "Offset to glyph ClassDef table containing backtrack sequence data-from beginning of Substitution table", + ), + ( + "Offset", + "InputClassDef", + None, + None, + "Offset to glyph ClassDef table containing input sequence data-from beginning of Substitution table", + ), + ( + "Offset", + "LookAheadClassDef", + None, + None, + "Offset to glyph ClassDef table containing lookahead sequence data-from beginning of Substitution table", + ), + ( + "uint16", + "ChainSubClassSetCount", + None, + None, + "Number of ChainSubClassSet tables", + ), + ( + "Offset", + "ChainSubClassSet", + "ChainSubClassSetCount", + 0, + "Array of offsets to ChainSubClassSet tables-from beginning of Substitution table-ordered by input class-may be NULL", + ), + ], + ), + ( + "ChainSubClassSet", + [ + ( + "uint16", + "ChainSubClassRuleCount", + None, + None, + "Number of ChainSubClassRule tables", + ), + ( + "Offset", + "ChainSubClassRule", + "ChainSubClassRuleCount", + 0, + "Array of offsets to ChainSubClassRule tables-from beginning of ChainSubClassSet-ordered by preference", + ), + ], + ), + ( + "ChainSubClassRule", + [ + ( + "uint16", + "BacktrackGlyphCount", + None, + None, + "Total number of glyphs in the backtrack sequence (number of glyphs to be matched before the first glyph)", + ), + ( + "uint16", + "Backtrack", + "BacktrackGlyphCount", + 0, + "Array of backtracking classes(to be matched before the input sequence)", + ), + ( + "uint16", + "InputGlyphCount", + None, + None, + "Total number of classes in the input sequence (includes the first class)", + ), + ( + "uint16", + "Input", + "InputGlyphCount", + -1, + "Array of input classes(start with second class; to be matched with the input glyph sequence)", + ), + ( + "uint16", + "LookAheadGlyphCount", + None, + None, + "Total number of classes in the look ahead sequence (number of classes to be matched after the input sequence)", + ), + ( + "uint16", + "LookAhead", + "LookAheadGlyphCount", + 0, + "Array of lookahead classes(to be matched after the input sequence)", + ), + ("uint16", "SubstCount", None, None, "Number of SubstLookupRecords"), + ( + "struct", + "SubstLookupRecord", + "SubstCount", + 0, + "Array of SubstLookupRecords (in design order)", + ), + ], + ), + ( + "ChainContextSubstFormat3", + [ + ("uint16", "SubstFormat", None, None, "Format identifier-format = 3"), + ( + "uint16", + "BacktrackGlyphCount", + None, + None, + "Number of glyphs in the backtracking sequence", + ), + ( + "Offset", + "BacktrackCoverage", + "BacktrackGlyphCount", + 0, + "Array of offsets to coverage tables in backtracking sequence, in glyph sequence order", + ), + ( + "uint16", + "InputGlyphCount", + None, + None, + "Number of glyphs in input sequence", + ), + ( + "Offset", + "InputCoverage", + "InputGlyphCount", + 0, + "Array of offsets to coverage tables in input sequence, in glyph sequence order", + ), + ( + "uint16", + "LookAheadGlyphCount", + None, + None, + "Number of glyphs in lookahead sequence", + ), + ( + "Offset", + "LookAheadCoverage", + "LookAheadGlyphCount", + 0, + "Array of offsets to coverage tables in lookahead sequence, in glyph sequence order", + ), + ("uint16", "SubstCount", None, None, "Number of SubstLookupRecords"), + ( + "struct", + "SubstLookupRecord", + "SubstCount", + 0, + "Array of SubstLookupRecords, in design order", + ), + ], + ), + ( + "ExtensionSubstFormat1", + [ + ("uint16", "ExtFormat", None, None, "Format identifier. Set to 1."), + ( + "uint16", + "ExtensionLookupType", + None, + None, + "Lookup type of subtable referenced by ExtensionOffset (i.e. the extension subtable).", + ), + ( + "LOffset", + "ExtSubTable", + None, + None, + "Array of offsets to Lookup tables-from beginning of LookupList -zero based (first lookup is Lookup index = 0)", + ), + ], + ), + ( + "ReverseChainSingleSubstFormat1", + [ + ("uint16", "SubstFormat", None, None, "Format identifier-format = 1"), + ( + "Offset", + "Coverage", + None, + 0, + "Offset to Coverage table - from beginning of Substitution table", + ), + ( + "uint16", + "BacktrackGlyphCount", + None, + None, + "Number of glyphs in the backtracking sequence", + ), + ( + "Offset", + "BacktrackCoverage", + "BacktrackGlyphCount", + 0, + "Array of offsets to coverage tables in backtracking sequence, in glyph sequence order", + ), + ( + "uint16", + "LookAheadGlyphCount", + None, + None, + "Number of glyphs in lookahead sequence", + ), + ( + "Offset", + "LookAheadCoverage", + "LookAheadGlyphCount", + 0, + "Array of offsets to coverage tables in lookahead sequence, in glyph sequence order", + ), + ( + "uint16", + "GlyphCount", + None, + None, + "Number of GlyphIDs in the Substitute array", + ), + ( + "GlyphID", + "Substitute", + "GlyphCount", + 0, + "Array of substitute GlyphIDs-ordered by Coverage index", + ), + ], + ), + # + # gdef + # + ( + "GDEF", + [ + ( + "Version", + "Version", + None, + None, + "Version of the GDEF table- 0x00010000, 0x00010002, or 0x00010003", + ), + ( + "Offset", + "GlyphClassDef", + None, + None, + "Offset to class definition table for glyph type-from beginning of GDEF header (may be NULL)", + ), + ( + "Offset", + "AttachList", + None, + None, + "Offset to list of glyphs with attachment points-from beginning of GDEF header (may be NULL)", + ), + ( + "Offset", + "LigCaretList", + None, + None, + "Offset to list of positioning points for ligature carets-from beginning of GDEF header (may be NULL)", + ), + ( + "Offset", + "MarkAttachClassDef", + None, + None, + "Offset to class definition table for mark attachment type-from beginning of GDEF header (may be NULL)", + ), + ( + "Offset", + "MarkGlyphSetsDef", + None, + "Version >= 0x00010002", + "Offset to the table of mark set definitions-from beginning of GDEF header (may be NULL)", + ), + ( + "LOffset", + "VarStore", + None, + "Version >= 0x00010003", + "Offset to variation store (may be NULL)", + ), + ], + ), + ( + "AttachList", + [ + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table - from beginning of AttachList table", + ), + ( + "uint16", + "GlyphCount", + None, + None, + "Number of glyphs with attachment points", + ), + ( + "Offset", + "AttachPoint", + "GlyphCount", + 0, + "Array of offsets to AttachPoint tables-from beginning of AttachList table-in Coverage Index order", + ), + ], + ), + ( + "AttachPoint", + [ + ( + "uint16", + "PointCount", + None, + None, + "Number of attachment points on this glyph", + ), + ( + "uint16", + "PointIndex", + "PointCount", + 0, + "Array of contour point indices -in increasing numerical order", + ), + ], + ), + ( + "LigCaretList", + [ + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table - from beginning of LigCaretList table", + ), + ("uint16", "LigGlyphCount", None, None, "Number of ligature glyphs"), + ( + "Offset", + "LigGlyph", + "LigGlyphCount", + 0, + "Array of offsets to LigGlyph tables-from beginning of LigCaretList table-in Coverage Index order", + ), + ], + ), + ( + "LigGlyph", + [ + ( + "uint16", + "CaretCount", + None, + None, + "Number of CaretValues for this ligature (components - 1)", + ), + ( + "Offset", + "CaretValue", + "CaretCount", + 0, + "Array of offsets to CaretValue tables-from beginning of LigGlyph table-in increasing coordinate order", + ), + ], + ), + ( + "CaretValueFormat1", + [ + ("uint16", "CaretValueFormat", None, None, "Format identifier-format = 1"), + ("int16", "Coordinate", None, None, "X or Y value, in design units"), + ], + ), + ( + "CaretValueFormat2", + [ + ("uint16", "CaretValueFormat", None, None, "Format identifier-format = 2"), + ("uint16", "CaretValuePoint", None, None, "Contour point index on glyph"), + ], + ), + ( + "CaretValueFormat3", + [ + ("uint16", "CaretValueFormat", None, None, "Format identifier-format = 3"), + ("int16", "Coordinate", None, None, "X or Y value, in design units"), + ( + "Offset", + "DeviceTable", + None, + None, + "Offset to Device table for X or Y value-from beginning of CaretValue table", + ), + ], + ), + ( + "MarkGlyphSetsDef", + [ + ("uint16", "MarkSetTableFormat", None, None, "Format identifier == 1"), + ("uint16", "MarkSetCount", None, None, "Number of mark sets defined"), + ( + "LOffset", + "Coverage", + "MarkSetCount", + 0, + "Array of offsets to mark set coverage tables.", + ), + ], + ), + # + # base + # + ( + "BASE", + [ + ( + "Version", + "Version", + None, + None, + "Version of the BASE table-initially 0x00010000", + ), + ( + "Offset", + "HorizAxis", + None, + None, + "Offset to horizontal Axis table-from beginning of BASE table-may be NULL", + ), + ( + "Offset", + "VertAxis", + None, + None, + "Offset to vertical Axis table-from beginning of BASE table-may be NULL", + ), + ( + "LOffset", + "VarStore", + None, + "Version >= 0x00010001", + "Offset to variation store (may be NULL)", + ), + ], + ), + ( + "Axis", + [ + ( + "Offset", + "BaseTagList", + None, + None, + "Offset to BaseTagList table-from beginning of Axis table-may be NULL", + ), + ( + "Offset", + "BaseScriptList", + None, + None, + "Offset to BaseScriptList table-from beginning of Axis table", + ), + ], + ), + ( + "BaseTagList", + [ + ( + "uint16", + "BaseTagCount", + None, + None, + "Number of baseline identification tags in this text direction-may be zero (0)", + ), + ( + "Tag", + "BaselineTag", + "BaseTagCount", + 0, + "Array of 4-byte baseline identification tags-must be in alphabetical order", + ), + ], + ), + ( + "BaseScriptList", + [ + ( + "uint16", + "BaseScriptCount", + None, + None, + "Number of BaseScriptRecords defined", + ), + ( + "struct", + "BaseScriptRecord", + "BaseScriptCount", + 0, + "Array of BaseScriptRecords-in alphabetical order by BaseScriptTag", + ), + ], + ), + ( + "BaseScriptRecord", + [ + ("Tag", "BaseScriptTag", None, None, "4-byte script identification tag"), + ( + "Offset", + "BaseScript", + None, + None, + "Offset to BaseScript table-from beginning of BaseScriptList", + ), + ], + ), + ( + "BaseScript", + [ + ( + "Offset", + "BaseValues", + None, + None, + "Offset to BaseValues table-from beginning of BaseScript table-may be NULL", + ), + ( + "Offset", + "DefaultMinMax", + None, + None, + "Offset to MinMax table- from beginning of BaseScript table-may be NULL", + ), + ( + "uint16", + "BaseLangSysCount", + None, + None, + "Number of BaseLangSysRecords defined-may be zero (0)", + ), + ( + "struct", + "BaseLangSysRecord", + "BaseLangSysCount", + 0, + "Array of BaseLangSysRecords-in alphabetical order by BaseLangSysTag", + ), + ], + ), + ( + "BaseLangSysRecord", + [ + ( + "Tag", + "BaseLangSysTag", + None, + None, + "4-byte language system identification tag", + ), + ( + "Offset", + "MinMax", + None, + None, + "Offset to MinMax table-from beginning of BaseScript table", + ), + ], + ), + ( + "BaseValues", + [ + ( + "uint16", + "DefaultIndex", + None, + None, + "Index number of default baseline for this script-equals index position of baseline tag in BaselineArray of the BaseTagList", + ), + ( + "uint16", + "BaseCoordCount", + None, + None, + "Number of BaseCoord tables defined-should equal BaseTagCount in the BaseTagList", + ), + ( + "Offset", + "BaseCoord", + "BaseCoordCount", + 0, + "Array of offsets to BaseCoord-from beginning of BaseValues table-order matches BaselineTag array in the BaseTagList", + ), + ], + ), + ( + "MinMax", + [ + ( + "Offset", + "MinCoord", + None, + None, + "Offset to BaseCoord table-defines minimum extent value-from the beginning of MinMax table-may be NULL", + ), + ( + "Offset", + "MaxCoord", + None, + None, + "Offset to BaseCoord table-defines maximum extent value-from the beginning of MinMax table-may be NULL", + ), + ( + "uint16", + "FeatMinMaxCount", + None, + None, + "Number of FeatMinMaxRecords-may be zero (0)", + ), + ( + "struct", + "FeatMinMaxRecord", + "FeatMinMaxCount", + 0, + "Array of FeatMinMaxRecords-in alphabetical order, by FeatureTableTag", + ), + ], + ), + ( + "FeatMinMaxRecord", + [ + ( + "Tag", + "FeatureTableTag", + None, + None, + "4-byte feature identification tag-must match FeatureTag in FeatureList", + ), + ( + "Offset", + "MinCoord", + None, + None, + "Offset to BaseCoord table-defines minimum extent value-from beginning of MinMax table-may be NULL", + ), + ( + "Offset", + "MaxCoord", + None, + None, + "Offset to BaseCoord table-defines maximum extent value-from beginning of MinMax table-may be NULL", + ), + ], + ), + ( + "BaseCoordFormat1", + [ + ("uint16", "BaseCoordFormat", None, None, "Format identifier-format = 1"), + ("int16", "Coordinate", None, None, "X or Y value, in design units"), + ], + ), + ( + "BaseCoordFormat2", + [ + ("uint16", "BaseCoordFormat", None, None, "Format identifier-format = 2"), + ("int16", "Coordinate", None, None, "X or Y value, in design units"), + ("GlyphID", "ReferenceGlyph", None, None, "GlyphID of control glyph"), + ( + "uint16", + "BaseCoordPoint", + None, + None, + "Index of contour point on the ReferenceGlyph", + ), + ], + ), + ( + "BaseCoordFormat3", + [ + ("uint16", "BaseCoordFormat", None, None, "Format identifier-format = 3"), + ("int16", "Coordinate", None, None, "X or Y value, in design units"), + ( + "Offset", + "DeviceTable", + None, + None, + "Offset to Device table for X or Y value", + ), + ], + ), + # + # jstf + # + ( + "JSTF", + [ + ( + "Version", + "Version", + None, + None, + "Version of the JSTF table-initially set to 0x00010000", + ), + ( + "uint16", + "JstfScriptCount", + None, + None, + "Number of JstfScriptRecords in this table", + ), + ( + "struct", + "JstfScriptRecord", + "JstfScriptCount", + 0, + "Array of JstfScriptRecords-in alphabetical order, by JstfScriptTag", + ), + ], + ), + ( + "JstfScriptRecord", + [ + ("Tag", "JstfScriptTag", None, None, "4-byte JstfScript identification"), + ( + "Offset", + "JstfScript", + None, + None, + "Offset to JstfScript table-from beginning of JSTF Header", + ), + ], + ), + ( + "JstfScript", + [ + ( + "Offset", + "ExtenderGlyph", + None, + None, + "Offset to ExtenderGlyph table-from beginning of JstfScript table-may be NULL", + ), + ( + "Offset", + "DefJstfLangSys", + None, + None, + "Offset to Default JstfLangSys table-from beginning of JstfScript table-may be NULL", + ), + ( + "uint16", + "JstfLangSysCount", + None, + None, + "Number of JstfLangSysRecords in this table- may be zero (0)", + ), + ( + "struct", + "JstfLangSysRecord", + "JstfLangSysCount", + 0, + "Array of JstfLangSysRecords-in alphabetical order, by JstfLangSysTag", + ), + ], + ), + ( + "JstfLangSysRecord", + [ + ("Tag", "JstfLangSysTag", None, None, "4-byte JstfLangSys identifier"), + ( + "Offset", + "JstfLangSys", + None, + None, + "Offset to JstfLangSys table-from beginning of JstfScript table", + ), + ], + ), + ( + "ExtenderGlyph", + [ + ( + "uint16", + "GlyphCount", + None, + None, + "Number of Extender Glyphs in this script", + ), + ( + "GlyphID", + "ExtenderGlyph", + "GlyphCount", + 0, + "GlyphIDs-in increasing numerical order", + ), + ], + ), + ( + "JstfLangSys", + [ + ( + "uint16", + "JstfPriorityCount", + None, + None, + "Number of JstfPriority tables", + ), + ( + "Offset", + "JstfPriority", + "JstfPriorityCount", + 0, + "Array of offsets to JstfPriority tables-from beginning of JstfLangSys table-in priority order", + ), + ], + ), + ( + "JstfPriority", + [ + ( + "Offset", + "ShrinkageEnableGSUB", + None, + None, + "Offset to Shrinkage Enable JstfGSUBModList table-from beginning of JstfPriority table-may be NULL", + ), + ( + "Offset", + "ShrinkageDisableGSUB", + None, + None, + "Offset to Shrinkage Disable JstfGSUBModList table-from beginning of JstfPriority table-may be NULL", + ), + ( + "Offset", + "ShrinkageEnableGPOS", + None, + None, + "Offset to Shrinkage Enable JstfGPOSModList table-from beginning of JstfPriority table-may be NULL", + ), + ( + "Offset", + "ShrinkageDisableGPOS", + None, + None, + "Offset to Shrinkage Disable JstfGPOSModList table-from beginning of JstfPriority table-may be NULL", + ), + ( + "Offset", + "ShrinkageJstfMax", + None, + None, + "Offset to Shrinkage JstfMax table-from beginning of JstfPriority table -may be NULL", + ), + ( + "Offset", + "ExtensionEnableGSUB", + None, + None, + "Offset to Extension Enable JstfGSUBModList table-may be NULL", + ), + ( + "Offset", + "ExtensionDisableGSUB", + None, + None, + "Offset to Extension Disable JstfGSUBModList table-from beginning of JstfPriority table-may be NULL", + ), + ( + "Offset", + "ExtensionEnableGPOS", + None, + None, + "Offset to Extension Enable JstfGSUBModList table-may be NULL", + ), + ( + "Offset", + "ExtensionDisableGPOS", + None, + None, + "Offset to Extension Disable JstfGSUBModList table-from beginning of JstfPriority table-may be NULL", + ), + ( + "Offset", + "ExtensionJstfMax", + None, + None, + "Offset to Extension JstfMax table-from beginning of JstfPriority table -may be NULL", + ), + ], + ), + ( + "JstfGSUBModList", + [ + ( + "uint16", + "LookupCount", + None, + None, + "Number of lookups for this modification", + ), + ( + "uint16", + "GSUBLookupIndex", + "LookupCount", + 0, + "Array of LookupIndex identifiers in GSUB-in increasing numerical order", + ), + ], + ), + ( + "JstfGPOSModList", + [ + ( + "uint16", + "LookupCount", + None, + None, + "Number of lookups for this modification", + ), + ( + "uint16", + "GPOSLookupIndex", + "LookupCount", + 0, + "Array of LookupIndex identifiers in GPOS-in increasing numerical order", + ), + ], + ), + ( + "JstfMax", + [ + ( + "uint16", + "LookupCount", + None, + None, + "Number of lookup Indices for this modification", + ), + ( + "Offset", + "Lookup", + "LookupCount", + 0, + "Array of offsets to GPOS-type lookup tables-from beginning of JstfMax table-in design order", + ), + ], + ), + # + # STAT + # + ( + "STAT", + [ + ( + "Version", + "Version", + None, + None, + "Version of the table-initially set to 0x00010000, currently 0x00010002.", + ), + ( + "uint16", + "DesignAxisRecordSize", + None, + None, + "Size in bytes of each design axis record", + ), + ("uint16", "DesignAxisCount", None, None, "Number of design axis records"), + ( + "LOffsetTo(AxisRecordArray)", + "DesignAxisRecord", + None, + None, + "Offset in bytes from the beginning of the STAT table to the start of the design axes array", + ), + ("uint16", "AxisValueCount", None, None, "Number of axis value tables"), + ( + "LOffsetTo(AxisValueArray)", + "AxisValueArray", + None, + None, + "Offset in bytes from the beginning of the STAT table to the start of the axes value offset array", + ), + ( + "NameID", + "ElidedFallbackNameID", + None, + "Version >= 0x00010001", + "NameID to use when all style attributes are elided.", + ), + ], + ), + ( + "AxisRecordArray", + [ + ("AxisRecord", "Axis", "DesignAxisCount", 0, "Axis records"), + ], + ), + ( + "AxisRecord", + [ + ( + "Tag", + "AxisTag", + None, + None, + "A tag identifying the axis of design variation", + ), + ( + "NameID", + "AxisNameID", + None, + None, + 'The name ID for entries in the "name" table that provide a display string for this axis', + ), + ( + "uint16", + "AxisOrdering", + None, + None, + "A value that applications can use to determine primary sorting of face names, or for ordering of descriptors when composing family or face names", + ), + ( + "uint8", + "MoreBytes", + "DesignAxisRecordSize", + -8, + "Extra bytes. Set to empty array.", + ), + ], + ), + ( + "AxisValueArray", + [ + ("Offset", "AxisValue", "AxisValueCount", 0, "Axis values"), + ], + ), + ( + "AxisValueFormat1", + [ + ("uint16", "Format", None, None, "Format, = 1"), + ( + "uint16", + "AxisIndex", + None, + None, + "Index into the axis record array identifying the axis of design variation to which the axis value record applies.", + ), + ("STATFlags", "Flags", None, None, "Flags."), + ("NameID", "ValueNameID", None, None, ""), + ("Fixed", "Value", None, None, ""), + ], + ), + ( + "AxisValueFormat2", + [ + ("uint16", "Format", None, None, "Format, = 2"), + ( + "uint16", + "AxisIndex", + None, + None, + "Index into the axis record array identifying the axis of design variation to which the axis value record applies.", + ), + ("STATFlags", "Flags", None, None, "Flags."), + ("NameID", "ValueNameID", None, None, ""), + ("Fixed", "NominalValue", None, None, ""), + ("Fixed", "RangeMinValue", None, None, ""), + ("Fixed", "RangeMaxValue", None, None, ""), + ], + ), + ( + "AxisValueFormat3", + [ + ("uint16", "Format", None, None, "Format, = 3"), + ( + "uint16", + "AxisIndex", + None, + None, + "Index into the axis record array identifying the axis of design variation to which the axis value record applies.", + ), + ("STATFlags", "Flags", None, None, "Flags."), + ("NameID", "ValueNameID", None, None, ""), + ("Fixed", "Value", None, None, ""), + ("Fixed", "LinkedValue", None, None, ""), + ], + ), + ( + "AxisValueFormat4", + [ + ("uint16", "Format", None, None, "Format, = 4"), + ( + "uint16", + "AxisCount", + None, + None, + "The total number of axes contributing to this axis-values combination.", + ), + ("STATFlags", "Flags", None, None, "Flags."), + ("NameID", "ValueNameID", None, None, ""), + ( + "struct", + "AxisValueRecord", + "AxisCount", + 0, + "Array of AxisValue records that provide the combination of axis values, one for each contributing axis. ", + ), + ], + ), + ( + "AxisValueRecord", + [ + ( + "uint16", + "AxisIndex", + None, + None, + "Index into the axis record array identifying the axis of design variation to which the axis value record applies.", + ), + ("Fixed", "Value", None, None, "A numeric value for this attribute value."), + ], + ), + # + # Variation fonts + # + # GSUB/GPOS FeatureVariations + ( + "FeatureVariations", + [ + ( + "Version", + "Version", + None, + None, + "Version of the table-initially set to 0x00010000", + ), + ( + "uint32", + "FeatureVariationCount", + None, + None, + "Number of records in the FeatureVariationRecord array", + ), + ( + "struct", + "FeatureVariationRecord", + "FeatureVariationCount", + 0, + "Array of FeatureVariationRecord", + ), + ], + ), + ( + "FeatureVariationRecord", + [ + ( + "LOffset", + "ConditionSet", + None, + None, + "Offset to a ConditionSet table, from beginning of the FeatureVariations table.", + ), + ( + "LOffset", + "FeatureTableSubstitution", + None, + None, + "Offset to a FeatureTableSubstitution table, from beginning of the FeatureVariations table", + ), + ], + ), + ( + "ConditionList", + [ + ( + "uint32", + "ConditionCount", + None, + None, + "Number of condition tables in the ConditionTable array", + ), + ( + "LOffset", + "ConditionTable", + "ConditionCount", + 0, + "Array of offset to condition tables, from the beginning of the ConditionList table.", + ), + ], + ), + ( + "ConditionSet", + [ + ( + "uint16", + "ConditionCount", + None, + None, + "Number of condition tables in the ConditionTable array", + ), + ( + "LOffset", + "ConditionTable", + "ConditionCount", + 0, + "Array of offset to condition tables, from the beginning of the ConditionSet table.", + ), + ], + ), + ( + "ConditionTableFormat1", + [ + ("uint16", "Format", None, None, "Format, = 1"), + ( + "uint16", + "AxisIndex", + None, + None, + "Index for the variation axis within the fvar table, base 0.", + ), + ( + "F2Dot14", + "FilterRangeMinValue", + None, + None, + "Minimum normalized axis value of the font variation instances that satisfy this condition.", + ), + ( + "F2Dot14", + "FilterRangeMaxValue", + None, + None, + "Maximum value that satisfies this condition.", + ), + ], + ), + ( + "ConditionTableFormat2", + [ + ("uint16", "Format", None, None, "Format, = 2"), + ( + "int16", + "DefaultValue", + None, + None, + "Value at default instance.", + ), + ( + "uint32", + "VarIdx", + None, + None, + "Variation index to vary the value based on current designspace location.", + ), + ], + ), + ( + "ConditionTableFormat3", + [ + ("uint16", "Format", None, None, "Format, = 3"), + ( + "uint8", + "ConditionCount", + None, + None, + "Index for the variation axis within the fvar table, base 0.", + ), + ( + "Offset24", + "ConditionTable", + "ConditionCount", + 0, + "Array of condition tables for this conjunction (AND) expression.", + ), + ], + ), + ( + "ConditionTableFormat4", + [ + ("uint16", "Format", None, None, "Format, = 4"), + ( + "uint8", + "ConditionCount", + None, + None, + "Index for the variation axis within the fvar table, base 0.", + ), + ( + "Offset24", + "ConditionTable", + "ConditionCount", + 0, + "Array of condition tables for this disjunction (OR) expression.", + ), + ], + ), + ( + "ConditionTableFormat5", + [ + ("uint16", "Format", None, None, "Format, = 5"), + ( + "Offset24", + "ConditionTable", + None, + None, + "Condition to negate.", + ), + ], + ), + ( + "FeatureTableSubstitution", + [ + ( + "Version", + "Version", + None, + None, + "Version of the table-initially set to 0x00010000", + ), + ( + "uint16", + "SubstitutionCount", + None, + None, + "Number of records in the FeatureVariationRecords array", + ), + ( + "FeatureTableSubstitutionRecord", + "SubstitutionRecord", + "SubstitutionCount", + 0, + "Array of FeatureTableSubstitutionRecord", + ), + ], + ), + ( + "FeatureTableSubstitutionRecord", + [ + ("uint16", "FeatureIndex", None, None, "The feature table index to match."), + ( + "LOffset", + "Feature", + None, + None, + "Offset to an alternate feature table, from start of the FeatureTableSubstitution table.", + ), + ], + ), + # VariationStore + ( + "VarRegionAxis", + [ + ("F2Dot14", "StartCoord", None, None, ""), + ("F2Dot14", "PeakCoord", None, None, ""), + ("F2Dot14", "EndCoord", None, None, ""), + ], + ), + ( + "VarRegion", + [ + ("struct", "VarRegionAxis", "RegionAxisCount", 0, ""), + ], + ), + ( + "VarRegionList", + [ + ("uint16", "RegionAxisCount", None, None, ""), + ("uint16", "RegionCount", None, None, ""), + ("VarRegion", "Region", "RegionCount", 0, ""), + ], + ), + ( + "VarData", + [ + ("uint16", "ItemCount", None, None, ""), + ("uint16", "NumShorts", None, None, ""), + ("uint16", "VarRegionCount", None, None, ""), + ("uint16", "VarRegionIndex", "VarRegionCount", 0, ""), + ("VarDataValue", "Item", "ItemCount", 0, ""), + ], + ), + ( + "VarStore", + [ + ("uint16", "Format", None, None, "Set to 1."), + ("LOffset", "VarRegionList", None, None, ""), + ("uint16", "VarDataCount", None, None, ""), + ("LOffset", "VarData", "VarDataCount", 0, ""), + ], + ), + # Variation helpers + ( + "VarIdxMap", + [ + ("uint16", "EntryFormat", None, None, ""), # Automatically computed + ("uint16", "MappingCount", None, None, ""), # Automatically computed + ("VarIdxMapValue", "mapping", "", 0, "Array of compressed data"), + ], + ), + ( + "DeltaSetIndexMapFormat0", + [ + ("uint8", "Format", None, None, "Format of the DeltaSetIndexMap = 0"), + ("uint8", "EntryFormat", None, None, ""), # Automatically computed + ("uint16", "MappingCount", None, None, ""), # Automatically computed + ("VarIdxMapValue", "mapping", "", 0, "Array of compressed data"), + ], + ), + ( + "DeltaSetIndexMapFormat1", + [ + ("uint8", "Format", None, None, "Format of the DeltaSetIndexMap = 1"), + ("uint8", "EntryFormat", None, None, ""), # Automatically computed + ("uint32", "MappingCount", None, None, ""), # Automatically computed + ("VarIdxMapValue", "mapping", "", 0, "Array of compressed data"), + ], + ), + # MultiVariationStore + ( + "SparseVarRegionAxis", + [ + ("uint16", "AxisIndex", None, None, ""), + ("F2Dot14", "StartCoord", None, None, ""), + ("F2Dot14", "PeakCoord", None, None, ""), + ("F2Dot14", "EndCoord", None, None, ""), + ], + ), + ( + "SparseVarRegion", + [ + ("uint16", "SparseRegionCount", None, None, ""), + ("struct", "SparseVarRegionAxis", "SparseRegionCount", 0, ""), + ], + ), + ( + "SparseVarRegionList", + [ + ("uint16", "RegionCount", None, None, ""), + ("LOffsetTo(SparseVarRegion)", "Region", "RegionCount", 0, ""), + ], + ), + ( + "MultiVarData", + [ + ("uint8", "Format", None, None, "Set to 1."), + ("uint16", "VarRegionCount", None, None, ""), + ("uint16", "VarRegionIndex", "VarRegionCount", 0, ""), + ("TupleList", "Item", "", 0, ""), + ], + ), + ( + "MultiVarStore", + [ + ("uint16", "Format", None, None, "Set to 1."), + ("LOffset", "SparseVarRegionList", None, None, ""), + ("uint16", "MultiVarDataCount", None, None, ""), + ("LOffset", "MultiVarData", "MultiVarDataCount", 0, ""), + ], + ), + # VariableComposites + ( + "VARC", + [ + ( + "Version", + "Version", + None, + None, + "Version of the HVAR table-initially = 0x00010000", + ), + ("LOffset", "Coverage", None, None, ""), + ("LOffset", "MultiVarStore", None, None, "(may be NULL)"), + ("LOffset", "ConditionList", None, None, "(may be NULL)"), + ("LOffset", "AxisIndicesList", None, None, "(may be NULL)"), + ("LOffset", "VarCompositeGlyphs", None, None, ""), + ], + ), + ( + "AxisIndicesList", + [ + ("TupleList", "Item", "", 0, ""), + ], + ), + ( + "VarCompositeGlyphs", + [ + ("VarCompositeGlyphList", "VarCompositeGlyph", "", None, ""), + ], + ), + # Glyph advance variations + ( + "HVAR", + [ + ( + "Version", + "Version", + None, + None, + "Version of the HVAR table-initially = 0x00010000", + ), + ("LOffset", "VarStore", None, None, ""), + ("LOffsetTo(VarIdxMap)", "AdvWidthMap", None, None, ""), + ("LOffsetTo(VarIdxMap)", "LsbMap", None, None, ""), + ("LOffsetTo(VarIdxMap)", "RsbMap", None, None, ""), + ], + ), + ( + "VVAR", + [ + ( + "Version", + "Version", + None, + None, + "Version of the VVAR table-initially = 0x00010000", + ), + ("LOffset", "VarStore", None, None, ""), + ("LOffsetTo(VarIdxMap)", "AdvHeightMap", None, None, ""), + ("LOffsetTo(VarIdxMap)", "TsbMap", None, None, ""), + ("LOffsetTo(VarIdxMap)", "BsbMap", None, None, ""), + ("LOffsetTo(VarIdxMap)", "VOrgMap", None, None, "Vertical origin mapping."), + ], + ), + # Font-wide metrics variations + ( + "MetricsValueRecord", + [ + ("Tag", "ValueTag", None, None, "4-byte font-wide measure identifier"), + ("uint32", "VarIdx", None, None, "Combined outer-inner variation index"), + ( + "uint8", + "MoreBytes", + "ValueRecordSize", + -8, + "Extra bytes. Set to empty array.", + ), + ], + ), + ( + "MVAR", + [ + ( + "Version", + "Version", + None, + None, + "Version of the MVAR table-initially = 0x00010000", + ), + ("uint16", "Reserved", None, None, "Set to 0"), + ("uint16", "ValueRecordSize", None, None, ""), + ("uint16", "ValueRecordCount", None, None, ""), + ("Offset", "VarStore", None, None, ""), + ("MetricsValueRecord", "ValueRecord", "ValueRecordCount", 0, ""), + ], + ), + # + # math + # + ( + "MATH", + [ + ( + "Version", + "Version", + None, + None, + "Version of the MATH table-initially set to 0x00010000.", + ), + ( + "Offset", + "MathConstants", + None, + None, + "Offset to MathConstants table - from the beginning of MATH table.", + ), + ( + "Offset", + "MathGlyphInfo", + None, + None, + "Offset to MathGlyphInfo table - from the beginning of MATH table.", + ), + ( + "Offset", + "MathVariants", + None, + None, + "Offset to MathVariants table - from the beginning of MATH table.", + ), + ], + ), + ( + "MathValueRecord", + [ + ("int16", "Value", None, None, "The X or Y value in design units."), + ( + "Offset", + "DeviceTable", + None, + None, + "Offset to the device table - from the beginning of parent table. May be NULL. Suggested format for device table is 1.", + ), + ], + ), + ( + "MathConstants", + [ + ( + "int16", + "ScriptPercentScaleDown", + None, + None, + "Percentage of scaling down for script level 1. Suggested value: 80%.", + ), + ( + "int16", + "ScriptScriptPercentScaleDown", + None, + None, + "Percentage of scaling down for script level 2 (ScriptScript). Suggested value: 60%.", + ), + ( + "uint16", + "DelimitedSubFormulaMinHeight", + None, + None, + "Minimum height required for a delimited expression to be treated as a subformula. Suggested value: normal line height x1.5.", + ), + ( + "uint16", + "DisplayOperatorMinHeight", + None, + None, + "Minimum height of n-ary operators (such as integral and summation) for formulas in display mode.", + ), + ( + "MathValueRecord", + "MathLeading", + None, + None, + "White space to be left between math formulas to ensure proper line spacing. For example, for applications that treat line gap as a part of line ascender, formulas with ink going above (os2.sTypoAscender + os2.sTypoLineGap - MathLeading) or with ink going below os2.sTypoDescender will result in increasing line height.", + ), + ("MathValueRecord", "AxisHeight", None, None, "Axis height of the font."), + ( + "MathValueRecord", + "AccentBaseHeight", + None, + None, + "Maximum (ink) height of accent base that does not require raising the accents. Suggested: x-height of the font (os2.sxHeight) plus any possible overshots.", + ), + ( + "MathValueRecord", + "FlattenedAccentBaseHeight", + None, + None, + "Maximum (ink) height of accent base that does not require flattening the accents. Suggested: cap height of the font (os2.sCapHeight).", + ), + ( + "MathValueRecord", + "SubscriptShiftDown", + None, + None, + "The standard shift down applied to subscript elements. Positive for moving in the downward direction. Suggested: os2.ySubscriptYOffset.", + ), + ( + "MathValueRecord", + "SubscriptTopMax", + None, + None, + "Maximum allowed height of the (ink) top of subscripts that does not require moving subscripts further down. Suggested: 4/5 x-height.", + ), + ( + "MathValueRecord", + "SubscriptBaselineDropMin", + None, + None, + "Minimum allowed drop of the baseline of subscripts relative to the (ink) bottom of the base. Checked for bases that are treated as a box or extended shape. Positive for subscript baseline dropped below the base bottom.", + ), + ( + "MathValueRecord", + "SuperscriptShiftUp", + None, + None, + "Standard shift up applied to superscript elements. Suggested: os2.ySuperscriptYOffset.", + ), + ( + "MathValueRecord", + "SuperscriptShiftUpCramped", + None, + None, + "Standard shift of superscripts relative to the base, in cramped style.", + ), + ( + "MathValueRecord", + "SuperscriptBottomMin", + None, + None, + "Minimum allowed height of the (ink) bottom of superscripts that does not require moving subscripts further up. Suggested: 1/4 x-height.", + ), + ( + "MathValueRecord", + "SuperscriptBaselineDropMax", + None, + None, + "Maximum allowed drop of the baseline of superscripts relative to the (ink) top of the base. Checked for bases that are treated as a box or extended shape. Positive for superscript baseline below the base top.", + ), + ( + "MathValueRecord", + "SubSuperscriptGapMin", + None, + None, + "Minimum gap between the superscript and subscript ink. Suggested: 4x default rule thickness.", + ), + ( + "MathValueRecord", + "SuperscriptBottomMaxWithSubscript", + None, + None, + "The maximum level to which the (ink) bottom of superscript can be pushed to increase the gap between superscript and subscript, before subscript starts being moved down. Suggested: 4/5 x-height.", + ), + ( + "MathValueRecord", + "SpaceAfterScript", + None, + None, + "Extra white space to be added after each subscript and superscript. Suggested: 0.5pt for a 12 pt font.", + ), + ( + "MathValueRecord", + "UpperLimitGapMin", + None, + None, + "Minimum gap between the (ink) bottom of the upper limit, and the (ink) top of the base operator.", + ), + ( + "MathValueRecord", + "UpperLimitBaselineRiseMin", + None, + None, + "Minimum distance between baseline of upper limit and (ink) top of the base operator.", + ), + ( + "MathValueRecord", + "LowerLimitGapMin", + None, + None, + "Minimum gap between (ink) top of the lower limit, and (ink) bottom of the base operator.", + ), + ( + "MathValueRecord", + "LowerLimitBaselineDropMin", + None, + None, + "Minimum distance between baseline of the lower limit and (ink) bottom of the base operator.", + ), + ( + "MathValueRecord", + "StackTopShiftUp", + None, + None, + "Standard shift up applied to the top element of a stack.", + ), + ( + "MathValueRecord", + "StackTopDisplayStyleShiftUp", + None, + None, + "Standard shift up applied to the top element of a stack in display style.", + ), + ( + "MathValueRecord", + "StackBottomShiftDown", + None, + None, + "Standard shift down applied to the bottom element of a stack. Positive for moving in the downward direction.", + ), + ( + "MathValueRecord", + "StackBottomDisplayStyleShiftDown", + None, + None, + "Standard shift down applied to the bottom element of a stack in display style. Positive for moving in the downward direction.", + ), + ( + "MathValueRecord", + "StackGapMin", + None, + None, + "Minimum gap between (ink) bottom of the top element of a stack, and the (ink) top of the bottom element. Suggested: 3x default rule thickness.", + ), + ( + "MathValueRecord", + "StackDisplayStyleGapMin", + None, + None, + "Minimum gap between (ink) bottom of the top element of a stack, and the (ink) top of the bottom element in display style. Suggested: 7x default rule thickness.", + ), + ( + "MathValueRecord", + "StretchStackTopShiftUp", + None, + None, + "Standard shift up applied to the top element of the stretch stack.", + ), + ( + "MathValueRecord", + "StretchStackBottomShiftDown", + None, + None, + "Standard shift down applied to the bottom element of the stretch stack. Positive for moving in the downward direction.", + ), + ( + "MathValueRecord", + "StretchStackGapAboveMin", + None, + None, + "Minimum gap between the ink of the stretched element, and the (ink) bottom of the element above. Suggested: UpperLimitGapMin", + ), + ( + "MathValueRecord", + "StretchStackGapBelowMin", + None, + None, + "Minimum gap between the ink of the stretched element, and the (ink) top of the element below. Suggested: LowerLimitGapMin.", + ), + ( + "MathValueRecord", + "FractionNumeratorShiftUp", + None, + None, + "Standard shift up applied to the numerator.", + ), + ( + "MathValueRecord", + "FractionNumeratorDisplayStyleShiftUp", + None, + None, + "Standard shift up applied to the numerator in display style. Suggested: StackTopDisplayStyleShiftUp.", + ), + ( + "MathValueRecord", + "FractionDenominatorShiftDown", + None, + None, + "Standard shift down applied to the denominator. Positive for moving in the downward direction.", + ), + ( + "MathValueRecord", + "FractionDenominatorDisplayStyleShiftDown", + None, + None, + "Standard shift down applied to the denominator in display style. Positive for moving in the downward direction. Suggested: StackBottomDisplayStyleShiftDown.", + ), + ( + "MathValueRecord", + "FractionNumeratorGapMin", + None, + None, + "Minimum tolerated gap between the (ink) bottom of the numerator and the ink of the fraction bar. Suggested: default rule thickness", + ), + ( + "MathValueRecord", + "FractionNumDisplayStyleGapMin", + None, + None, + "Minimum tolerated gap between the (ink) bottom of the numerator and the ink of the fraction bar in display style. Suggested: 3x default rule thickness.", + ), + ( + "MathValueRecord", + "FractionRuleThickness", + None, + None, + "Thickness of the fraction bar. Suggested: default rule thickness.", + ), + ( + "MathValueRecord", + "FractionDenominatorGapMin", + None, + None, + "Minimum tolerated gap between the (ink) top of the denominator and the ink of the fraction bar. Suggested: default rule thickness", + ), + ( + "MathValueRecord", + "FractionDenomDisplayStyleGapMin", + None, + None, + "Minimum tolerated gap between the (ink) top of the denominator and the ink of the fraction bar in display style. Suggested: 3x default rule thickness.", + ), + ( + "MathValueRecord", + "SkewedFractionHorizontalGap", + None, + None, + "Horizontal distance between the top and bottom elements of a skewed fraction.", + ), + ( + "MathValueRecord", + "SkewedFractionVerticalGap", + None, + None, + "Vertical distance between the ink of the top and bottom elements of a skewed fraction.", + ), + ( + "MathValueRecord", + "OverbarVerticalGap", + None, + None, + "Distance between the overbar and the (ink) top of he base. Suggested: 3x default rule thickness.", + ), + ( + "MathValueRecord", + "OverbarRuleThickness", + None, + None, + "Thickness of overbar. Suggested: default rule thickness.", + ), + ( + "MathValueRecord", + "OverbarExtraAscender", + None, + None, + "Extra white space reserved above the overbar. Suggested: default rule thickness.", + ), + ( + "MathValueRecord", + "UnderbarVerticalGap", + None, + None, + "Distance between underbar and (ink) bottom of the base. Suggested: 3x default rule thickness.", + ), + ( + "MathValueRecord", + "UnderbarRuleThickness", + None, + None, + "Thickness of underbar. Suggested: default rule thickness.", + ), + ( + "MathValueRecord", + "UnderbarExtraDescender", + None, + None, + "Extra white space reserved below the underbar. Always positive. Suggested: default rule thickness.", + ), + ( + "MathValueRecord", + "RadicalVerticalGap", + None, + None, + "Space between the (ink) top of the expression and the bar over it. Suggested: 1 1/4 default rule thickness.", + ), + ( + "MathValueRecord", + "RadicalDisplayStyleVerticalGap", + None, + None, + "Space between the (ink) top of the expression and the bar over it. Suggested: default rule thickness + 1/4 x-height.", + ), + ( + "MathValueRecord", + "RadicalRuleThickness", + None, + None, + "Thickness of the radical rule. This is the thickness of the rule in designed or constructed radical signs. Suggested: default rule thickness.", + ), + ( + "MathValueRecord", + "RadicalExtraAscender", + None, + None, + "Extra white space reserved above the radical. Suggested: RadicalRuleThickness.", + ), + ( + "MathValueRecord", + "RadicalKernBeforeDegree", + None, + None, + "Extra horizontal kern before the degree of a radical, if such is present. Suggested: 5/18 of em.", + ), + ( + "MathValueRecord", + "RadicalKernAfterDegree", + None, + None, + "Negative kern after the degree of a radical, if such is present. Suggested: 10/18 of em.", + ), + ( + "uint16", + "RadicalDegreeBottomRaisePercent", + None, + None, + "Height of the bottom of the radical degree, if such is present, in proportion to the ascender of the radical sign. Suggested: 60%.", + ), + ], + ), + ( + "MathGlyphInfo", + [ + ( + "Offset", + "MathItalicsCorrectionInfo", + None, + None, + "Offset to MathItalicsCorrectionInfo table - from the beginning of MathGlyphInfo table.", + ), + ( + "Offset", + "MathTopAccentAttachment", + None, + None, + "Offset to MathTopAccentAttachment table - from the beginning of MathGlyphInfo table.", + ), + ( + "Offset", + "ExtendedShapeCoverage", + None, + None, + "Offset to coverage table for Extended Shape glyphs - from the beginning of MathGlyphInfo table. When the left or right glyph of a box is an extended shape variant, the (ink) box (and not the default position defined by values in MathConstants table) should be used for vertical positioning purposes. May be NULL.", + ), + ( + "Offset", + "MathKernInfo", + None, + None, + "Offset to MathKernInfo table - from the beginning of MathGlyphInfo table.", + ), + ], + ), + ( + "MathItalicsCorrectionInfo", + [ + ( + "Offset", + "Coverage", + None, + None, + "Offset to Coverage table - from the beginning of MathItalicsCorrectionInfo table.", + ), + ( + "uint16", + "ItalicsCorrectionCount", + None, + None, + "Number of italics correction values. Should coincide with the number of covered glyphs.", + ), + ( + "MathValueRecord", + "ItalicsCorrection", + "ItalicsCorrectionCount", + 0, + "Array of MathValueRecords defining italics correction values for each covered glyph.", + ), + ], + ), + ( + "MathTopAccentAttachment", + [ + ( + "Offset", + "TopAccentCoverage", + None, + None, + "Offset to Coverage table - from the beginning of MathTopAccentAttachment table.", + ), + ( + "uint16", + "TopAccentAttachmentCount", + None, + None, + "Number of top accent attachment point values. Should coincide with the number of covered glyphs", + ), + ( + "MathValueRecord", + "TopAccentAttachment", + "TopAccentAttachmentCount", + 0, + "Array of MathValueRecords defining top accent attachment points for each covered glyph", + ), + ], + ), + ( + "MathKernInfo", + [ + ( + "Offset", + "MathKernCoverage", + None, + None, + "Offset to Coverage table - from the beginning of the MathKernInfo table.", + ), + ("uint16", "MathKernCount", None, None, "Number of MathKernInfoRecords."), + ( + "MathKernInfoRecord", + "MathKernInfoRecords", + "MathKernCount", + 0, + "Array of MathKernInfoRecords, per-glyph information for mathematical positioning of subscripts and superscripts.", + ), + ], + ), + ( + "MathKernInfoRecord", + [ + ( + "Offset", + "TopRightMathKern", + None, + None, + "Offset to MathKern table for top right corner - from the beginning of MathKernInfo table. May be NULL.", + ), + ( + "Offset", + "TopLeftMathKern", + None, + None, + "Offset to MathKern table for the top left corner - from the beginning of MathKernInfo table. May be NULL.", + ), + ( + "Offset", + "BottomRightMathKern", + None, + None, + "Offset to MathKern table for bottom right corner - from the beginning of MathKernInfo table. May be NULL.", + ), + ( + "Offset", + "BottomLeftMathKern", + None, + None, + "Offset to MathKern table for bottom left corner - from the beginning of MathKernInfo table. May be NULL.", + ), + ], + ), + ( + "MathKern", + [ + ( + "uint16", + "HeightCount", + None, + None, + "Number of heights on which the kern value changes.", + ), + ( + "MathValueRecord", + "CorrectionHeight", + "HeightCount", + 0, + "Array of correction heights at which the kern value changes. Sorted by the height value in design units.", + ), + ( + "MathValueRecord", + "KernValue", + "HeightCount", + 1, + "Array of kern values corresponding to heights. First value is the kern value for all heights less or equal than the first height in this table.Last value is the value to be applied for all heights greater than the last height in this table. Negative values are interpreted as move glyphs closer to each other.", + ), + ], + ), + ( + "MathVariants", + [ + ( + "uint16", + "MinConnectorOverlap", + None, + None, + "Minimum overlap of connecting glyphs during glyph construction, in design units.", + ), + ( + "Offset", + "VertGlyphCoverage", + None, + None, + "Offset to Coverage table - from the beginning of MathVariants table.", + ), + ( + "Offset", + "HorizGlyphCoverage", + None, + None, + "Offset to Coverage table - from the beginning of MathVariants table.", + ), + ( + "uint16", + "VertGlyphCount", + None, + None, + "Number of glyphs for which information is provided for vertically growing variants.", + ), + ( + "uint16", + "HorizGlyphCount", + None, + None, + "Number of glyphs for which information is provided for horizontally growing variants.", + ), + ( + "Offset", + "VertGlyphConstruction", + "VertGlyphCount", + 0, + "Array of offsets to MathGlyphConstruction tables - from the beginning of the MathVariants table, for shapes growing in vertical direction.", + ), + ( + "Offset", + "HorizGlyphConstruction", + "HorizGlyphCount", + 0, + "Array of offsets to MathGlyphConstruction tables - from the beginning of the MathVariants table, for shapes growing in horizontal direction.", + ), + ], + ), + ( + "MathGlyphConstruction", + [ + ( + "Offset", + "GlyphAssembly", + None, + None, + "Offset to GlyphAssembly table for this shape - from the beginning of MathGlyphConstruction table. May be NULL", + ), + ( + "uint16", + "VariantCount", + None, + None, + "Count of glyph growing variants for this glyph.", + ), + ( + "MathGlyphVariantRecord", + "MathGlyphVariantRecord", + "VariantCount", + 0, + "MathGlyphVariantRecords for alternative variants of the glyphs.", + ), + ], + ), + ( + "MathGlyphVariantRecord", + [ + ("GlyphID", "VariantGlyph", None, None, "Glyph ID for the variant."), + ( + "uint16", + "AdvanceMeasurement", + None, + None, + "Advance width/height, in design units, of the variant, in the direction of requested glyph extension.", + ), + ], + ), + ( + "GlyphAssembly", + [ + ( + "MathValueRecord", + "ItalicsCorrection", + None, + None, + "Italics correction of this GlyphAssembly. Should not depend on the assembly size.", + ), + ("uint16", "PartCount", None, None, "Number of parts in this assembly."), + ( + "GlyphPartRecord", + "PartRecords", + "PartCount", + 0, + "Array of part records, from left to right and bottom to top.", + ), + ], + ), + ( + "GlyphPartRecord", + [ + ("GlyphID", "glyph", None, None, "Glyph ID for the part."), + ( + "uint16", + "StartConnectorLength", + None, + None, + "Advance width/ height of the straight bar connector material, in design units, is at the beginning of the glyph, in the direction of the extension.", + ), + ( + "uint16", + "EndConnectorLength", + None, + None, + "Advance width/ height of the straight bar connector material, in design units, is at the end of the glyph, in the direction of the extension.", + ), + ( + "uint16", + "FullAdvance", + None, + None, + "Full advance width/height for this part, in the direction of the extension. In design units.", + ), + ( + "uint16", + "PartFlags", + None, + None, + "Part qualifiers. PartFlags enumeration currently uses only one bit: 0x0001 fExtender: If set, the part can be skipped or repeated. 0xFFFE Reserved", + ), + ], + ), + ## + ## Apple Advanced Typography (AAT) tables + ## + ( + "AATLookupSegment", + [ + ("uint16", "lastGlyph", None, None, "Last glyph index in this segment."), + ("uint16", "firstGlyph", None, None, "First glyph index in this segment."), + ( + "uint16", + "value", + None, + None, + "A 16-bit offset from the start of the table to the data.", + ), + ], + ), + # + # ankr + # + ( + "ankr", + [ + ("struct", "AnchorPoints", None, None, "Anchor points table."), + ], + ), + ( + "AnchorPointsFormat0", + [ + ("uint16", "Format", None, None, "Format of the anchor points table, = 0."), + ("uint16", "Flags", None, None, "Flags. Currenty unused, set to zero."), + ( + "AATLookupWithDataOffset(AnchorGlyphData)", + "Anchors", + None, + None, + "Table of with anchor overrides for each glyph.", + ), + ], + ), + ( + "AnchorGlyphData", + [ + ( + "uint32", + "AnchorPointCount", + None, + None, + "Number of anchor points for this glyph.", + ), + ( + "struct", + "AnchorPoint", + "AnchorPointCount", + 0, + "Individual anchor points.", + ), + ], + ), + ( + "AnchorPoint", + [ + ("int16", "XCoordinate", None, None, "X coordinate of this anchor point."), + ("int16", "YCoordinate", None, None, "Y coordinate of this anchor point."), + ], + ), + # + # bsln + # + ( + "bsln", + [ + ( + "Version", + "Version", + None, + None, + "Version number of the AAT baseline table (0x00010000 for the initial version).", + ), + ("struct", "Baseline", None, None, "Baseline table."), + ], + ), + ( + "BaselineFormat0", + [ + ("uint16", "Format", None, None, "Format of the baseline table, = 0."), + ( + "uint16", + "DefaultBaseline", + None, + None, + "Default baseline value for all glyphs. This value can be from 0 through 31.", + ), + ( + "uint16", + "Delta", + 32, + 0, + "These are the FUnit distance deltas from the font’s natural baseline to the other baselines used in the font. A total of 32 deltas must be assigned.", + ), + ], + ), + ( + "BaselineFormat1", + [ + ("uint16", "Format", None, None, "Format of the baseline table, = 1."), + ( + "uint16", + "DefaultBaseline", + None, + None, + "Default baseline value for all glyphs. This value can be from 0 through 31.", + ), + ( + "uint16", + "Delta", + 32, + 0, + "These are the FUnit distance deltas from the font’s natural baseline to the other baselines used in the font. A total of 32 deltas must be assigned.", + ), + ( + "AATLookup(uint16)", + "BaselineValues", + None, + None, + "Lookup table that maps glyphs to their baseline values.", + ), + ], + ), + ( + "BaselineFormat2", + [ + ("uint16", "Format", None, None, "Format of the baseline table, = 1."), + ( + "uint16", + "DefaultBaseline", + None, + None, + "Default baseline value for all glyphs. This value can be from 0 through 31.", + ), + ( + "GlyphID", + "StandardGlyph", + None, + None, + "Glyph index of the glyph in this font to be used to set the baseline values. This glyph must contain a set of control points (whose numbers are contained in the following field) that determines baseline distances.", + ), + ( + "uint16", + "ControlPoint", + 32, + 0, + "Array of 32 control point numbers, associated with the standard glyph. A value of 0xFFFF means there is no corresponding control point in the standard glyph.", + ), + ], + ), + ( + "BaselineFormat3", + [ + ("uint16", "Format", None, None, "Format of the baseline table, = 1."), + ( + "uint16", + "DefaultBaseline", + None, + None, + "Default baseline value for all glyphs. This value can be from 0 through 31.", + ), + ( + "GlyphID", + "StandardGlyph", + None, + None, + "Glyph index of the glyph in this font to be used to set the baseline values. This glyph must contain a set of control points (whose numbers are contained in the following field) that determines baseline distances.", + ), + ( + "uint16", + "ControlPoint", + 32, + 0, + "Array of 32 control point numbers, associated with the standard glyph. A value of 0xFFFF means there is no corresponding control point in the standard glyph.", + ), + ( + "AATLookup(uint16)", + "BaselineValues", + None, + None, + "Lookup table that maps glyphs to their baseline values.", + ), + ], + ), + # + # cidg + # + ( + "cidg", + [ + ("struct", "CIDGlyphMapping", None, None, "CID-to-glyph mapping table."), + ], + ), + ( + "CIDGlyphMappingFormat0", + [ + ( + "uint16", + "Format", + None, + None, + "Format of the CID-to-glyph mapping table, = 0.", + ), + ("uint16", "DataFormat", None, None, "Currenty unused, set to zero."), + ("uint32", "StructLength", None, None, "Size of the table in bytes."), + ("uint16", "Registry", None, None, "The registry ID."), + ( + "char64", + "RegistryName", + None, + None, + "The registry name in ASCII; unused bytes should be set to 0.", + ), + ("uint16", "Order", None, None, "The order ID."), + ( + "char64", + "OrderName", + None, + None, + "The order name in ASCII; unused bytes should be set to 0.", + ), + ("uint16", "SupplementVersion", None, None, "The supplement version."), + ( + "CIDGlyphMap", + "Mapping", + None, + None, + "A mapping from CIDs to the glyphs in the font, starting with CID 0. If a CID from the identified collection has no glyph in the font, 0xFFFF is used", + ), + ], + ), + # + # feat + # + ( + "feat", + [ + ( + "Version", + "Version", + None, + None, + "Version of the feat table-initially set to 0x00010000.", + ), + ("FeatureNames", "FeatureNames", None, None, "The feature names."), + ], + ), + ( + "FeatureNames", + [ + ( + "uint16", + "FeatureNameCount", + None, + None, + "Number of entries in the feature name array.", + ), + ("uint16", "Reserved1", None, None, "Reserved (set to zero)."), + ("uint32", "Reserved2", None, None, "Reserved (set to zero)."), + ( + "FeatureName", + "FeatureName", + "FeatureNameCount", + 0, + "The feature name array.", + ), + ], + ), + ( + "FeatureName", + [ + ("uint16", "FeatureType", None, None, "Feature type."), + ( + "uint16", + "SettingsCount", + None, + None, + "The number of records in the setting name array.", + ), + ( + "LOffset", + "Settings", + None, + None, + "Offset to setting table for this feature.", + ), + ( + "uint16", + "FeatureFlags", + None, + None, + "Single-bit flags associated with the feature type.", + ), + ( + "NameID", + "FeatureNameID", + None, + None, + "The name table index for the feature name.", + ), + ], + ), + ( + "Settings", + [ + ("Setting", "Setting", "SettingsCount", 0, "The setting array."), + ], + ), + ( + "Setting", + [ + ("uint16", "SettingValue", None, None, "The setting."), + ( + "NameID", + "SettingNameID", + None, + None, + "The name table index for the setting name.", + ), + ], + ), + # + # gcid + # + ( + "gcid", + [ + ("struct", "GlyphCIDMapping", None, None, "Glyph to CID mapping table."), + ], + ), + ( + "GlyphCIDMappingFormat0", + [ + ( + "uint16", + "Format", + None, + None, + "Format of the glyph-to-CID mapping table, = 0.", + ), + ("uint16", "DataFormat", None, None, "Currenty unused, set to zero."), + ("uint32", "StructLength", None, None, "Size of the table in bytes."), + ("uint16", "Registry", None, None, "The registry ID."), + ( + "char64", + "RegistryName", + None, + None, + "The registry name in ASCII; unused bytes should be set to 0.", + ), + ("uint16", "Order", None, None, "The order ID."), + ( + "char64", + "OrderName", + None, + None, + "The order name in ASCII; unused bytes should be set to 0.", + ), + ("uint16", "SupplementVersion", None, None, "The supplement version."), + ( + "GlyphCIDMap", + "Mapping", + None, + None, + "The CIDs for the glyphs in the font, starting with glyph 0. If a glyph does not correspond to a CID in the identified collection, 0xFFFF is used", + ), + ], + ), + # + # lcar + # + ( + "lcar", + [ + ( + "Version", + "Version", + None, + None, + "Version number of the ligature caret table (0x00010000 for the initial version).", + ), + ("struct", "LigatureCarets", None, None, "Ligature carets table."), + ], + ), + ( + "LigatureCaretsFormat0", + [ + ( + "uint16", + "Format", + None, + None, + "Format of the ligature caret table. Format 0 indicates division points are distances in font units, Format 1 indicates division points are indexes of control points.", + ), + ( + "AATLookup(LigCaretDistances)", + "Carets", + None, + None, + "Lookup table associating ligature glyphs with their caret positions, in font unit distances.", + ), + ], + ), + ( + "LigatureCaretsFormat1", + [ + ( + "uint16", + "Format", + None, + None, + "Format of the ligature caret table. Format 0 indicates division points are distances in font units, Format 1 indicates division points are indexes of control points.", + ), + ( + "AATLookup(LigCaretPoints)", + "Carets", + None, + None, + "Lookup table associating ligature glyphs with their caret positions, as control points.", + ), + ], + ), + ( + "LigCaretDistances", + [ + ("uint16", "DivsionPointCount", None, None, "Number of division points."), + ( + "int16", + "DivisionPoint", + "DivsionPointCount", + 0, + "Distance in font units through which a subdivision is made orthogonally to the baseline.", + ), + ], + ), + ( + "LigCaretPoints", + [ + ("uint16", "DivsionPointCount", None, None, "Number of division points."), + ( + "int16", + "DivisionPoint", + "DivsionPointCount", + 0, + "The number of the control point through which a subdivision is made orthogonally to the baseline.", + ), + ], + ), + # + # mort + # + ( + "mort", + [ + ("Version", "Version", None, None, "Version of the mort table."), + ( + "uint32", + "MorphChainCount", + None, + None, + "Number of metamorphosis chains.", + ), + ( + "MortChain", + "MorphChain", + "MorphChainCount", + 0, + "Array of metamorphosis chains.", + ), + ], + ), + ( + "MortChain", + [ + ( + "Flags32", + "DefaultFlags", + None, + None, + "The default specification for subtables.", + ), + ( + "uint32", + "StructLength", + None, + None, + "Total byte count, including this header; must be a multiple of 4.", + ), + ( + "uint16", + "MorphFeatureCount", + None, + None, + "Number of metamorphosis feature entries.", + ), + ( + "uint16", + "MorphSubtableCount", + None, + None, + "The number of subtables in the chain.", + ), + ( + "struct", + "MorphFeature", + "MorphFeatureCount", + 0, + "Array of metamorphosis features.", + ), + ( + "MortSubtable", + "MorphSubtable", + "MorphSubtableCount", + 0, + "Array of metamorphosis subtables.", + ), + ], + ), + ( + "MortSubtable", + [ + ( + "uint16", + "StructLength", + None, + None, + "Total subtable length, including this header.", + ), + ( + "uint8", + "CoverageFlags", + None, + None, + "Most significant byte of coverage flags.", + ), + ("uint8", "MorphType", None, None, "Subtable type."), + ( + "Flags32", + "SubFeatureFlags", + None, + None, + "The 32-bit mask identifying which subtable this is (the subtable being executed if the AND of this value and the processed defaultFlags is nonzero).", + ), + ("SubStruct", "SubStruct", None, None, "SubTable."), + ], + ), + # + # morx + # + ( + "morx", + [ + ("uint16", "Version", None, None, "Version of the morx table."), + ("uint16", "Reserved", None, None, "Reserved (set to zero)."), + ( + "uint32", + "MorphChainCount", + None, + None, + "Number of extended metamorphosis chains.", + ), + ( + "MorxChain", + "MorphChain", + "MorphChainCount", + 0, + "Array of extended metamorphosis chains.", + ), + ], + ), + ( + "MorxChain", + [ + ( + "Flags32", + "DefaultFlags", + None, + None, + "The default specification for subtables.", + ), + ( + "uint32", + "StructLength", + None, + None, + "Total byte count, including this header; must be a multiple of 4.", + ), + ( + "uint32", + "MorphFeatureCount", + None, + None, + "Number of feature subtable entries.", + ), + ( + "uint32", + "MorphSubtableCount", + None, + None, + "The number of subtables in the chain.", + ), + ( + "MorphFeature", + "MorphFeature", + "MorphFeatureCount", + 0, + "Array of metamorphosis features.", + ), + ( + "MorxSubtable", + "MorphSubtable", + "MorphSubtableCount", + 0, + "Array of extended metamorphosis subtables.", + ), + ], + ), + ( + "MorphFeature", + [ + ("uint16", "FeatureType", None, None, "The type of feature."), + ( + "uint16", + "FeatureSetting", + None, + None, + "The feature's setting (aka selector).", + ), + ( + "Flags32", + "EnableFlags", + None, + None, + "Flags for the settings that this feature and setting enables.", + ), + ( + "Flags32", + "DisableFlags", + None, + None, + "Complement of flags for the settings that this feature and setting disable.", + ), + ], + ), + # Apple TrueType Reference Manual, chapter “The ‘morx’ table”, + # section “Metamorphosis Subtables”. + # https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6morx.html + ( + "MorxSubtable", + [ + ( + "uint32", + "StructLength", + None, + None, + "Total subtable length, including this header.", + ), + ( + "uint8", + "CoverageFlags", + None, + None, + "Most significant byte of coverage flags.", + ), + ("uint16", "Reserved", None, None, "Unused."), + ("uint8", "MorphType", None, None, "Subtable type."), + ( + "Flags32", + "SubFeatureFlags", + None, + None, + "The 32-bit mask identifying which subtable this is (the subtable being executed if the AND of this value and the processed defaultFlags is nonzero).", + ), + ("SubStruct", "SubStruct", None, None, "SubTable."), + ], + ), + ( + "StateHeader", + [ + ( + "uint32", + "ClassCount", + None, + None, + "Number of classes, which is the number of 16-bit entry indices in a single line in the state array.", + ), + ( + "uint32", + "MorphClass", + None, + None, + "Offset from the start of this state table header to the start of the class table.", + ), + ( + "uint32", + "StateArrayOffset", + None, + None, + "Offset from the start of this state table header to the start of the state array.", + ), + ( + "uint32", + "EntryTableOffset", + None, + None, + "Offset from the start of this state table header to the start of the entry table.", + ), + ], + ), + ( + "RearrangementMorph", + [ + ( + "STXHeader(RearrangementMorphAction)", + "StateTable", + None, + None, + "Finite-state transducer table for indic rearrangement.", + ), + ], + ), + ( + "ContextualMorph", + [ + ( + "STXHeader(ContextualMorphAction)", + "StateTable", + None, + None, + "Finite-state transducer for contextual glyph substitution.", + ), + ], + ), + ( + "LigatureMorph", + [ + ( + "STXHeader(LigatureMorphAction)", + "StateTable", + None, + None, + "Finite-state transducer for ligature substitution.", + ), + ], + ), + ( + "NoncontextualMorph", + [ + ( + "AATLookup(GlyphID)", + "Substitution", + None, + None, + "The noncontextual glyph substitution table.", + ), + ], + ), + ( + "InsertionMorph", + [ + ( + "STXHeader(InsertionMorphAction)", + "StateTable", + None, + None, + "Finite-state transducer for glyph insertion.", + ), + ], + ), + ( + "MorphClass", + [ + ( + "uint16", + "FirstGlyph", + None, + None, + "Glyph index of the first glyph in the class table.", + ), + # ('uint16', 'GlyphCount', None, None, 'Number of glyphs in class table.'), + # ('uint8', 'GlyphClass', 'GlyphCount', 0, 'The class codes (indexed by glyph index minus firstGlyph). Class codes range from 0 to the value of stateSize minus 1.'), + ], + ), + # If the 'morx' table version is 3 or greater, then the last subtable in the chain is followed by a subtableGlyphCoverageArray, as described below. + # ('Offset', 'MarkGlyphSetsDef', None, 'round(Version*0x10000) >= 0x00010002', 'Offset to the table of mark set definitions-from beginning of GDEF header (may be NULL)'), + # + # prop + # + ( + "prop", + [ + ( + "Fixed", + "Version", + None, + None, + "Version number of the AAT glyphs property table. Version 1.0 is the initial table version. Version 2.0, which is recognized by macOS 8.5 and later, adds support for the “attaches on right” bit. Version 3.0, which gets recognized by macOS X and iOS, adds support for the additional directional properties defined in Unicode 3.0.", + ), + ("struct", "GlyphProperties", None, None, "Glyph properties."), + ], + ), + ( + "GlyphPropertiesFormat0", + [ + ("uint16", "Format", None, None, "Format, = 0."), + ( + "uint16", + "DefaultProperties", + None, + None, + "Default properties applied to a glyph. Since there is no lookup table in prop format 0, the default properties get applied to every glyph in the font.", + ), + ], + ), + ( + "GlyphPropertiesFormat1", + [ + ("uint16", "Format", None, None, "Format, = 1."), + ( + "uint16", + "DefaultProperties", + None, + None, + "Default properties applied to a glyph if that glyph is not present in the Properties lookup table.", + ), + ( + "AATLookup(uint16)", + "Properties", + None, + None, + "Lookup data associating glyphs with their properties.", + ), + ], + ), + # + # opbd + # + ( + "opbd", + [ + ( + "Version", + "Version", + None, + None, + "Version number of the optical bounds table (0x00010000 for the initial version).", + ), + ("struct", "OpticalBounds", None, None, "Optical bounds table."), + ], + ), + ( + "OpticalBoundsFormat0", + [ + ( + "uint16", + "Format", + None, + None, + "Format of the optical bounds table, = 0.", + ), + ( + "AATLookup(OpticalBoundsDeltas)", + "OpticalBoundsDeltas", + None, + None, + "Lookup table associating glyphs with their optical bounds, given as deltas in font units.", + ), + ], + ), + ( + "OpticalBoundsFormat1", + [ + ( + "uint16", + "Format", + None, + None, + "Format of the optical bounds table, = 1.", + ), + ( + "AATLookup(OpticalBoundsPoints)", + "OpticalBoundsPoints", + None, + None, + "Lookup table associating glyphs with their optical bounds, given as references to control points.", + ), + ], + ), + ( + "OpticalBoundsDeltas", + [ + ( + "int16", + "Left", + None, + None, + "Delta value for the left-side optical edge.", + ), + ("int16", "Top", None, None, "Delta value for the top-side optical edge."), + ( + "int16", + "Right", + None, + None, + "Delta value for the right-side optical edge.", + ), + ( + "int16", + "Bottom", + None, + None, + "Delta value for the bottom-side optical edge.", + ), + ], + ), + ( + "OpticalBoundsPoints", + [ + ( + "int16", + "Left", + None, + None, + "Control point index for the left-side optical edge, or -1 if this glyph has none.", + ), + ( + "int16", + "Top", + None, + None, + "Control point index for the top-side optical edge, or -1 if this glyph has none.", + ), + ( + "int16", + "Right", + None, + None, + "Control point index for the right-side optical edge, or -1 if this glyph has none.", + ), + ( + "int16", + "Bottom", + None, + None, + "Control point index for the bottom-side optical edge, or -1 if this glyph has none.", + ), + ], + ), + # + # TSIC + # + ( + "TSIC", + [ + ( + "Version", + "Version", + None, + None, + "Version of table initially set to 0x00010000.", + ), + ("uint16", "Flags", None, None, "TSIC flags - set to 0"), + ("uint16", "AxisCount", None, None, "Axis count from fvar"), + ("uint16", "RecordCount", None, None, "TSIC record count"), + ("uint16", "Reserved", None, None, "Set to 0"), + ("Tag", "AxisArray", "AxisCount", 0, "Array of axis tags in fvar order"), + ( + "LocationRecord", + "RecordLocations", + "RecordCount", + 0, + "Location in variation space of TSIC record", + ), + ("TSICRecord", "Record", "RecordCount", 0, "Array of TSIC records"), + ], + ), + ( + "LocationRecord", + [ + ("F2Dot14", "Axis", "AxisCount", 0, "Axis record"), + ], + ), + ( + "TSICRecord", + [ + ("uint16", "Flags", None, None, "Record flags - set to 0"), + ("uint16", "NumCVTEntries", None, None, "Number of CVT number value pairs"), + ("uint16", "NameLength", None, None, "Length of optional user record name"), + ("uint16", "NameArray", "NameLength", 0, "Unicode 16 name"), + ("uint16", "CVTArray", "NumCVTEntries", 0, "CVT number array"), + ("int16", "CVTValueArray", "NumCVTEntries", 0, "CVT value"), + ], + ), + # + # COLR + # + ( + "COLR", + [ + ("uint16", "Version", None, None, "Table version number (starts at 0)."), + ( + "uint16", + "BaseGlyphRecordCount", + None, + None, + "Number of Base Glyph Records.", + ), + ( + "LOffset", + "BaseGlyphRecordArray", + None, + None, + "Offset (from beginning of COLR table) to Base Glyph records.", + ), + ( + "LOffset", + "LayerRecordArray", + None, + None, + "Offset (from beginning of COLR table) to Layer Records.", + ), + ("uint16", "LayerRecordCount", None, None, "Number of Layer Records."), + ( + "LOffset", + "BaseGlyphList", + None, + "Version >= 1", + "Offset (from beginning of COLR table) to array of Version-1 Base Glyph records.", + ), + ( + "LOffset", + "LayerList", + None, + "Version >= 1", + "Offset (from beginning of COLR table) to LayerList.", + ), + ( + "LOffset", + "ClipList", + None, + "Version >= 1", + "Offset to ClipList table (may be NULL)", + ), + ( + "LOffsetTo(DeltaSetIndexMap)", + "VarIndexMap", + None, + "Version >= 1", + "Offset to DeltaSetIndexMap table (may be NULL)", + ), + ( + "LOffset", + "VarStore", + None, + "Version >= 1", + "Offset to variation store (may be NULL)", + ), + ], + ), + ( + "BaseGlyphRecordArray", + [ + ( + "BaseGlyphRecord", + "BaseGlyphRecord", + "BaseGlyphRecordCount", + 0, + "Base Glyph records.", + ), + ], + ), + ( + "BaseGlyphRecord", + [ + ( + "GlyphID", + "BaseGlyph", + None, + None, + "Glyph ID of reference glyph. This glyph is for reference only and is not rendered for color.", + ), + ( + "uint16", + "FirstLayerIndex", + None, + None, + "Index (from beginning of the Layer Records) to the layer record. There will be numLayers consecutive entries for this base glyph.", + ), + ( + "uint16", + "NumLayers", + None, + None, + "Number of color layers associated with this glyph.", + ), + ], + ), + ( + "LayerRecordArray", + [ + ("LayerRecord", "LayerRecord", "LayerRecordCount", 0, "Layer records."), + ], + ), + ( + "LayerRecord", + [ + ( + "GlyphID", + "LayerGlyph", + None, + None, + "Glyph ID of layer glyph (must be in z-order from bottom to top).", + ), + ( + "uint16", + "PaletteIndex", + None, + None, + "Index value to use with a selected color palette.", + ), + ], + ), + ( + "BaseGlyphList", + [ + ( + "uint32", + "BaseGlyphCount", + None, + None, + "Number of Version-1 Base Glyph records", + ), + ( + "struct", + "BaseGlyphPaintRecord", + "BaseGlyphCount", + 0, + "Array of Version-1 Base Glyph records", + ), + ], + ), + ( + "BaseGlyphPaintRecord", + [ + ("GlyphID", "BaseGlyph", None, None, "Glyph ID of reference glyph."), + ( + "LOffset", + "Paint", + None, + None, + "Offset (from beginning of BaseGlyphPaintRecord) to Paint, typically a PaintColrLayers.", + ), + ], + ), + ( + "LayerList", + [ + ("uint32", "LayerCount", None, None, "Number of Version-1 Layers"), + ( + "LOffset", + "Paint", + "LayerCount", + 0, + "Array of offsets to Paint tables, from the start of the LayerList table.", + ), + ], + ), + ( + "ClipListFormat1", + [ + ( + "uint8", + "Format", + None, + None, + "Format for ClipList with 16bit glyph IDs: 1", + ), + ("uint32", "ClipCount", None, None, "Number of Clip records."), + ( + "struct", + "ClipRecord", + "ClipCount", + 0, + "Array of Clip records sorted by glyph ID.", + ), + ], + ), + ( + "ClipRecord", + [ + ("uint16", "StartGlyphID", None, None, "First glyph ID in the range."), + ("uint16", "EndGlyphID", None, None, "Last glyph ID in the range."), + ("Offset24", "ClipBox", None, None, "Offset to a ClipBox table."), + ], + ), + ( + "ClipBoxFormat1", + [ + ( + "uint8", + "Format", + None, + None, + "Format for ClipBox without variation: set to 1.", + ), + ("int16", "xMin", None, None, "Minimum x of clip box."), + ("int16", "yMin", None, None, "Minimum y of clip box."), + ("int16", "xMax", None, None, "Maximum x of clip box."), + ("int16", "yMax", None, None, "Maximum y of clip box."), + ], + ), + ( + "ClipBoxFormat2", + [ + ("uint8", "Format", None, None, "Format for variable ClipBox: set to 2."), + ("int16", "xMin", None, None, "Minimum x of clip box. VarIndexBase + 0."), + ("int16", "yMin", None, None, "Minimum y of clip box. VarIndexBase + 1."), + ("int16", "xMax", None, None, "Maximum x of clip box. VarIndexBase + 2."), + ("int16", "yMax", None, None, "Maximum y of clip box. VarIndexBase + 3."), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # COLRv1 Affine2x3 uses the same column-major order to serialize a 2D + # Affine Transformation as the one used by fontTools.misc.transform. + # However, for historical reasons, the labels 'xy' and 'yx' are swapped. + # Their fundamental meaning is the same though. + # COLRv1 Affine2x3 follows the names found in FreeType and Cairo. + # In all case, the second element in the 6-tuple correspond to the + # y-part of the x basis vector, and the third to the x-part of the y + # basis vector. + # See https://github.com/googlefonts/colr-gradients-spec/pull/85 + ( + "Affine2x3", + [ + ("Fixed", "xx", None, None, "x-part of x basis vector"), + ("Fixed", "yx", None, None, "y-part of x basis vector"), + ("Fixed", "xy", None, None, "x-part of y basis vector"), + ("Fixed", "yy", None, None, "y-part of y basis vector"), + ("Fixed", "dx", None, None, "Translation in x direction"), + ("Fixed", "dy", None, None, "Translation in y direction"), + ], + ), + ( + "VarAffine2x3", + [ + ("Fixed", "xx", None, None, "x-part of x basis vector. VarIndexBase + 0."), + ("Fixed", "yx", None, None, "y-part of x basis vector. VarIndexBase + 1."), + ("Fixed", "xy", None, None, "x-part of y basis vector. VarIndexBase + 2."), + ("Fixed", "yy", None, None, "y-part of y basis vector. VarIndexBase + 3."), + ( + "Fixed", + "dx", + None, + None, + "Translation in x direction. VarIndexBase + 4.", + ), + ( + "Fixed", + "dy", + None, + None, + "Translation in y direction. VarIndexBase + 5.", + ), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + ( + "ColorStop", + [ + ("F2Dot14", "StopOffset", None, None, ""), + ("uint16", "PaletteIndex", None, None, "Index for a CPAL palette entry."), + ("F2Dot14", "Alpha", None, None, "Values outsided [0.,1.] reserved"), + ], + ), + ( + "VarColorStop", + [ + ("F2Dot14", "StopOffset", None, None, "VarIndexBase + 0."), + ("uint16", "PaletteIndex", None, None, "Index for a CPAL palette entry."), + ( + "F2Dot14", + "Alpha", + None, + None, + "Values outsided [0.,1.] reserved. VarIndexBase + 1.", + ), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + ( + "ColorLine", + [ + ( + "ExtendMode", + "Extend", + None, + None, + "Enum {PAD = 0, REPEAT = 1, REFLECT = 2}", + ), + ("uint16", "StopCount", None, None, "Number of Color stops."), + ("ColorStop", "ColorStop", "StopCount", 0, "Array of Color stops."), + ], + ), + ( + "VarColorLine", + [ + ( + "ExtendMode", + "Extend", + None, + None, + "Enum {PAD = 0, REPEAT = 1, REFLECT = 2}", + ), + ("uint16", "StopCount", None, None, "Number of Color stops."), + ("VarColorStop", "ColorStop", "StopCount", 0, "Array of Color stops."), + ], + ), + # PaintColrLayers + ( + "PaintFormat1", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 1"), + ( + "uint8", + "NumLayers", + None, + None, + "Number of offsets to Paint to read from LayerList.", + ), + ("uint32", "FirstLayerIndex", None, None, "Index into LayerList."), + ], + ), + # PaintSolid + ( + "PaintFormat2", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 2"), + ("uint16", "PaletteIndex", None, None, "Index for a CPAL palette entry."), + ("F2Dot14", "Alpha", None, None, "Values outsided [0.,1.] reserved"), + ], + ), + # PaintVarSolid + ( + "PaintFormat3", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 3"), + ("uint16", "PaletteIndex", None, None, "Index for a CPAL palette entry."), + ( + "F2Dot14", + "Alpha", + None, + None, + "Values outsided [0.,1.] reserved. VarIndexBase + 0.", + ), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # PaintLinearGradient + ( + "PaintFormat4", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 4"), + ( + "Offset24", + "ColorLine", + None, + None, + "Offset (from beginning of PaintLinearGradient table) to ColorLine subtable.", + ), + ("int16", "x0", None, None, ""), + ("int16", "y0", None, None, ""), + ("int16", "x1", None, None, ""), + ("int16", "y1", None, None, ""), + ("int16", "x2", None, None, ""), + ("int16", "y2", None, None, ""), + ], + ), + # PaintVarLinearGradient + ( + "PaintFormat5", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 5"), + ( + "LOffset24To(VarColorLine)", + "ColorLine", + None, + None, + "Offset (from beginning of PaintVarLinearGradient table) to VarColorLine subtable.", + ), + ("int16", "x0", None, None, "VarIndexBase + 0."), + ("int16", "y0", None, None, "VarIndexBase + 1."), + ("int16", "x1", None, None, "VarIndexBase + 2."), + ("int16", "y1", None, None, "VarIndexBase + 3."), + ("int16", "x2", None, None, "VarIndexBase + 4."), + ("int16", "y2", None, None, "VarIndexBase + 5."), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # PaintRadialGradient + ( + "PaintFormat6", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 6"), + ( + "Offset24", + "ColorLine", + None, + None, + "Offset (from beginning of PaintRadialGradient table) to ColorLine subtable.", + ), + ("int16", "x0", None, None, ""), + ("int16", "y0", None, None, ""), + ("uint16", "r0", None, None, ""), + ("int16", "x1", None, None, ""), + ("int16", "y1", None, None, ""), + ("uint16", "r1", None, None, ""), + ], + ), + # PaintVarRadialGradient + ( + "PaintFormat7", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 7"), + ( + "LOffset24To(VarColorLine)", + "ColorLine", + None, + None, + "Offset (from beginning of PaintVarRadialGradient table) to VarColorLine subtable.", + ), + ("int16", "x0", None, None, "VarIndexBase + 0."), + ("int16", "y0", None, None, "VarIndexBase + 1."), + ("uint16", "r0", None, None, "VarIndexBase + 2."), + ("int16", "x1", None, None, "VarIndexBase + 3."), + ("int16", "y1", None, None, "VarIndexBase + 4."), + ("uint16", "r1", None, None, "VarIndexBase + 5."), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # PaintSweepGradient + ( + "PaintFormat8", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 8"), + ( + "Offset24", + "ColorLine", + None, + None, + "Offset (from beginning of PaintSweepGradient table) to ColorLine subtable.", + ), + ("int16", "centerX", None, None, "Center x coordinate."), + ("int16", "centerY", None, None, "Center y coordinate."), + ( + "BiasedAngle", + "startAngle", + None, + None, + "Start of the angular range of the gradient.", + ), + ( + "BiasedAngle", + "endAngle", + None, + None, + "End of the angular range of the gradient.", + ), + ], + ), + # PaintVarSweepGradient + ( + "PaintFormat9", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 9"), + ( + "LOffset24To(VarColorLine)", + "ColorLine", + None, + None, + "Offset (from beginning of PaintVarSweepGradient table) to VarColorLine subtable.", + ), + ("int16", "centerX", None, None, "Center x coordinate. VarIndexBase + 0."), + ("int16", "centerY", None, None, "Center y coordinate. VarIndexBase + 1."), + ( + "BiasedAngle", + "startAngle", + None, + None, + "Start of the angular range of the gradient. VarIndexBase + 2.", + ), + ( + "BiasedAngle", + "endAngle", + None, + None, + "End of the angular range of the gradient. VarIndexBase + 3.", + ), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # PaintGlyph + ( + "PaintFormat10", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 10"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintGlyph table) to Paint subtable.", + ), + ("GlyphID", "Glyph", None, None, "Glyph ID for the source outline."), + ], + ), + # PaintColrGlyph + ( + "PaintFormat11", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 11"), + ( + "GlyphID", + "Glyph", + None, + None, + "Virtual glyph ID for a BaseGlyphList base glyph.", + ), + ], + ), + # PaintTransform + ( + "PaintFormat12", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 12"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintTransform table) to Paint subtable.", + ), + ( + "LOffset24To(Affine2x3)", + "Transform", + None, + None, + "2x3 matrix for 2D affine transformations.", + ), + ], + ), + # PaintVarTransform + ( + "PaintFormat13", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 13"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintVarTransform table) to Paint subtable.", + ), + ( + "LOffset24To(VarAffine2x3)", + "Transform", + None, + None, + "2x3 matrix for 2D affine transformations.", + ), + ], + ), + # PaintTranslate + ( + "PaintFormat14", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 14"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintTranslate table) to Paint subtable.", + ), + ("int16", "dx", None, None, "Translation in x direction."), + ("int16", "dy", None, None, "Translation in y direction."), + ], + ), + # PaintVarTranslate + ( + "PaintFormat15", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 15"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintVarTranslate table) to Paint subtable.", + ), + ( + "int16", + "dx", + None, + None, + "Translation in x direction. VarIndexBase + 0.", + ), + ( + "int16", + "dy", + None, + None, + "Translation in y direction. VarIndexBase + 1.", + ), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # PaintScale + ( + "PaintFormat16", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 16"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintScale table) to Paint subtable.", + ), + ("F2Dot14", "scaleX", None, None, ""), + ("F2Dot14", "scaleY", None, None, ""), + ], + ), + # PaintVarScale + ( + "PaintFormat17", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 17"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintVarScale table) to Paint subtable.", + ), + ("F2Dot14", "scaleX", None, None, "VarIndexBase + 0."), + ("F2Dot14", "scaleY", None, None, "VarIndexBase + 1."), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # PaintScaleAroundCenter + ( + "PaintFormat18", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 18"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintScaleAroundCenter table) to Paint subtable.", + ), + ("F2Dot14", "scaleX", None, None, ""), + ("F2Dot14", "scaleY", None, None, ""), + ("int16", "centerX", None, None, ""), + ("int16", "centerY", None, None, ""), + ], + ), + # PaintVarScaleAroundCenter + ( + "PaintFormat19", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 19"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintVarScaleAroundCenter table) to Paint subtable.", + ), + ("F2Dot14", "scaleX", None, None, "VarIndexBase + 0."), + ("F2Dot14", "scaleY", None, None, "VarIndexBase + 1."), + ("int16", "centerX", None, None, "VarIndexBase + 2."), + ("int16", "centerY", None, None, "VarIndexBase + 3."), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # PaintScaleUniform + ( + "PaintFormat20", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 20"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintScaleUniform table) to Paint subtable.", + ), + ("F2Dot14", "scale", None, None, ""), + ], + ), + # PaintVarScaleUniform + ( + "PaintFormat21", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 21"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintVarScaleUniform table) to Paint subtable.", + ), + ("F2Dot14", "scale", None, None, "VarIndexBase + 0."), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # PaintScaleUniformAroundCenter + ( + "PaintFormat22", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 22"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintScaleUniformAroundCenter table) to Paint subtable.", + ), + ("F2Dot14", "scale", None, None, ""), + ("int16", "centerX", None, None, ""), + ("int16", "centerY", None, None, ""), + ], + ), + # PaintVarScaleUniformAroundCenter + ( + "PaintFormat23", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 23"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintVarScaleUniformAroundCenter table) to Paint subtable.", + ), + ("F2Dot14", "scale", None, None, "VarIndexBase + 0"), + ("int16", "centerX", None, None, "VarIndexBase + 1"), + ("int16", "centerY", None, None, "VarIndexBase + 2"), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # PaintRotate + ( + "PaintFormat24", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 24"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintRotate table) to Paint subtable.", + ), + ("Angle", "angle", None, None, ""), + ], + ), + # PaintVarRotate + ( + "PaintFormat25", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 25"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintVarRotate table) to Paint subtable.", + ), + ("Angle", "angle", None, None, "VarIndexBase + 0."), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # PaintRotateAroundCenter + ( + "PaintFormat26", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 26"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintRotateAroundCenter table) to Paint subtable.", + ), + ("Angle", "angle", None, None, ""), + ("int16", "centerX", None, None, ""), + ("int16", "centerY", None, None, ""), + ], + ), + # PaintVarRotateAroundCenter + ( + "PaintFormat27", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 27"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintVarRotateAroundCenter table) to Paint subtable.", + ), + ("Angle", "angle", None, None, "VarIndexBase + 0."), + ("int16", "centerX", None, None, "VarIndexBase + 1."), + ("int16", "centerY", None, None, "VarIndexBase + 2."), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # PaintSkew + ( + "PaintFormat28", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 28"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintSkew table) to Paint subtable.", + ), + ("Angle", "xSkewAngle", None, None, ""), + ("Angle", "ySkewAngle", None, None, ""), + ], + ), + # PaintVarSkew + ( + "PaintFormat29", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 29"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintVarSkew table) to Paint subtable.", + ), + ("Angle", "xSkewAngle", None, None, "VarIndexBase + 0."), + ("Angle", "ySkewAngle", None, None, "VarIndexBase + 1."), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # PaintSkewAroundCenter + ( + "PaintFormat30", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 30"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintSkewAroundCenter table) to Paint subtable.", + ), + ("Angle", "xSkewAngle", None, None, ""), + ("Angle", "ySkewAngle", None, None, ""), + ("int16", "centerX", None, None, ""), + ("int16", "centerY", None, None, ""), + ], + ), + # PaintVarSkewAroundCenter + ( + "PaintFormat31", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 31"), + ( + "Offset24", + "Paint", + None, + None, + "Offset (from beginning of PaintVarSkewAroundCenter table) to Paint subtable.", + ), + ("Angle", "xSkewAngle", None, None, "VarIndexBase + 0."), + ("Angle", "ySkewAngle", None, None, "VarIndexBase + 1."), + ("int16", "centerX", None, None, "VarIndexBase + 2."), + ("int16", "centerY", None, None, "VarIndexBase + 3."), + ( + "VarIndex", + "VarIndexBase", + None, + None, + "Base index into DeltaSetIndexMap.", + ), + ], + ), + # PaintComposite + ( + "PaintFormat32", + [ + ("uint8", "PaintFormat", None, None, "Format identifier-format = 32"), + ( + "LOffset24To(Paint)", + "SourcePaint", + None, + None, + "Offset (from beginning of PaintComposite table) to source Paint subtable.", + ), + ( + "CompositeMode", + "CompositeMode", + None, + None, + "A CompositeMode enumeration value.", + ), + ( + "LOffset24To(Paint)", + "BackdropPaint", + None, + None, + "Offset (from beginning of PaintComposite table) to backdrop Paint subtable.", + ), + ], + ), + # + # avar + # + ( + "AxisValueMap", + [ + ( + "F2Dot14", + "FromCoordinate", + None, + None, + "A normalized coordinate value obtained using default normalization", + ), + ( + "F2Dot14", + "ToCoordinate", + None, + None, + "The modified, normalized coordinate value", + ), + ], + ), + ( + "AxisSegmentMap", + [ + ( + "uint16", + "PositionMapCount", + None, + None, + "The number of correspondence pairs for this axis", + ), + ( + "AxisValueMap", + "AxisValueMap", + "PositionMapCount", + 0, + "The array of axis value map records for this axis", + ), + ], + ), + ( + "avar", + [ + ( + "Version", + "Version", + None, + None, + "Version of the avar table- 0x00010000 or 0x00020000", + ), + ("uint16", "Reserved", None, None, "Permanently reserved; set to zero"), + ( + "uint16", + "AxisCount", + None, + None, + 'The number of variation axes for this font. This must be the same number as axisCount in the "fvar" table', + ), + ( + "AxisSegmentMap", + "AxisSegmentMap", + "AxisCount", + 0, + 'The segment maps array — one segment map for each axis, in the order of axes specified in the "fvar" table', + ), + ( + "LOffsetTo(DeltaSetIndexMap)", + "VarIdxMap", + None, + "Version >= 0x00020000", + "", + ), + ("LOffset", "VarStore", None, "Version >= 0x00020000", ""), + ], + ), +] diff --git a/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/otTables.py b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/otTables.py new file mode 100644 index 0000000000000000000000000000000000000000..ab5dace7265826cbf4f8aa12a940b26da50b9623 --- /dev/null +++ b/data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/otTables.py @@ -0,0 +1,2703 @@ +# coding: utf-8 +"""fontTools.ttLib.tables.otTables -- A collection of classes representing the various +OpenType subtables. + +Most are constructed upon import from data in otData.py, all are populated with +converter objects from otConverters.py. +""" +import copy +from enum import IntEnum +from functools import reduce +from math import radians +import itertools +from collections import defaultdict, namedtuple +from fontTools.ttLib import OPTIMIZE_FONT_SPEED +from fontTools.ttLib.tables.TupleVariation import TupleVariation +from fontTools.ttLib.tables.otTraverse import dfs_base_table +from fontTools.misc.arrayTools import quantizeRect +from fontTools.misc.roundTools import otRound +from fontTools.misc.transform import Transform, Identity, DecomposedTransform +from fontTools.misc.textTools import bytesjoin, pad, safeEval +from fontTools.misc.vector import Vector +from fontTools.pens.boundsPen import ControlBoundsPen +from fontTools.pens.transformPen import TransformPen +from .otBase import ( + BaseTable, + FormatSwitchingBaseTable, + ValueRecord, + CountReference, + getFormatSwitchingBaseTableClass, +) +from fontTools.misc.fixedTools import ( + fixedToFloat as fi2fl, + floatToFixed as fl2fi, + floatToFixedToStr as fl2str, + strToFixedToFloat as str2fl, +) +from fontTools.feaLib.lookupDebugInfo import LookupDebugInfo, LOOKUP_DEBUG_INFO_KEY +import logging +import struct +import array +import sys +from enum import IntFlag +from typing import TYPE_CHECKING, Iterator, List, Optional, Set + +if TYPE_CHECKING: + from fontTools.ttLib.ttGlyphSet import _TTGlyphSet + + +log = logging.getLogger(__name__) + + +class VarComponentFlags(IntFlag): + RESET_UNSPECIFIED_AXES = 1 << 0 + + HAVE_AXES = 1 << 1 + + AXIS_VALUES_HAVE_VARIATION = 1 << 2 + TRANSFORM_HAS_VARIATION = 1 << 3 + + HAVE_TRANSLATE_X = 1 << 4 + HAVE_TRANSLATE_Y = 1 << 5 + HAVE_ROTATION = 1 << 6 + + HAVE_CONDITION = 1 << 7 + + HAVE_SCALE_X = 1 << 8 + HAVE_SCALE_Y = 1 << 9 + HAVE_TCENTER_X = 1 << 10 + HAVE_TCENTER_Y = 1 << 11 + + GID_IS_24BIT = 1 << 12 + + HAVE_SKEW_X = 1 << 13 + HAVE_SKEW_Y = 1 << 14 + + RESERVED_MASK = (1 << 32) - (1 << 15) + + +VarTransformMappingValues = namedtuple( + "VarTransformMappingValues", + ["flag", "fractionalBits", "scale", "defaultValue"], +) + +VAR_TRANSFORM_MAPPING = { + "translateX": VarTransformMappingValues( + VarComponentFlags.HAVE_TRANSLATE_X, 0, 1, 0 + ), + "translateY": VarTransformMappingValues( + VarComponentFlags.HAVE_TRANSLATE_Y, 0, 1, 0 + ), + "rotation": VarTransformMappingValues(VarComponentFlags.HAVE_ROTATION, 12, 180, 0), + "scaleX": VarTransformMappingValues(VarComponentFlags.HAVE_SCALE_X, 10, 1, 1), + "scaleY": VarTransformMappingValues(VarComponentFlags.HAVE_SCALE_Y, 10, 1, 1), + "skewX": VarTransformMappingValues(VarComponentFlags.HAVE_SKEW_X, 12, -180, 0), + "skewY": VarTransformMappingValues(VarComponentFlags.HAVE_SKEW_Y, 12, 180, 0), + "tCenterX": VarTransformMappingValues(VarComponentFlags.HAVE_TCENTER_X, 0, 1, 0), + "tCenterY": VarTransformMappingValues(VarComponentFlags.HAVE_TCENTER_Y, 0, 1, 0), +} + +# Probably should be somewhere in fontTools.misc +_packer = { + 1: lambda v: struct.pack(">B", v), + 2: lambda v: struct.pack(">H", v), + 3: lambda v: struct.pack(">L", v)[1:], + 4: lambda v: struct.pack(">L", v), +} +_unpacker = { + 1: lambda v: struct.unpack(">B", v)[0], + 2: lambda v: struct.unpack(">H", v)[0], + 3: lambda v: struct.unpack(">L", b"\0" + v)[0], + 4: lambda v: struct.unpack(">L", v)[0], +} + + +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 (b0 - 0xC0) << 16 | data[i + 1] << 8 | data[i + 2], i + 3 + elif b0 < 0xF0: + return (b0 - 0xE0) << 24 | data[i + 1] << 16 | data[i + 2] << 8 | data[ + i + 3 + ], i + 4 + else: + return (b0 - 0xF0) << 32 | data[i + 1] << 24 | data[i + 2] << 16 | data[ + i + 3 + ] << 8 | data[i + 4], i + 5 + + +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: + return struct.pack(">L", (v | 0xE0000000)) + else: + return struct.pack(">B", 0xF0) + struct.pack(">L", v) + + +class VarComponent: + def __init__(self): + self.populateDefaults() + + def populateDefaults(self, propagator=None): + self.flags = 0 + self.glyphName = None + self.conditionIndex = None + self.axisIndicesIndex = None + self.axisValues = () + self.axisValuesVarIndex = NO_VARIATION_INDEX + self.transformVarIndex = NO_VARIATION_INDEX + self.transform = DecomposedTransform() + + def decompile(self, data, font, localState): + i = 0 + self.flags, i = _read_uint32var(data, i) + flags = self.flags + + gidSize = 3 if flags & VarComponentFlags.GID_IS_24BIT else 2 + glyphID = _unpacker[gidSize](data[i : i + gidSize]) + i += gidSize + self.glyphName = font.glyphOrder[glyphID] + + if flags & VarComponentFlags.HAVE_CONDITION: + self.conditionIndex, i = _read_uint32var(data, i) + + if flags & VarComponentFlags.HAVE_AXES: + self.axisIndicesIndex, i = _read_uint32var(data, i) + else: + self.axisIndicesIndex = None + + if self.axisIndicesIndex is None: + numAxes = 0 + else: + axisIndices = localState["AxisIndicesList"].Item[self.axisIndicesIndex] + numAxes = len(axisIndices) + + if flags & VarComponentFlags.HAVE_AXES: + axisValues, i = TupleVariation.decompileDeltas_(numAxes, data, i) + self.axisValues = tuple(fi2fl(v, 14) for v in axisValues) + else: + self.axisValues = () + assert len(self.axisValues) == numAxes + + if flags & VarComponentFlags.AXIS_VALUES_HAVE_VARIATION: + self.axisValuesVarIndex, i = _read_uint32var(data, i) + else: + self.axisValuesVarIndex = NO_VARIATION_INDEX + if flags & VarComponentFlags.TRANSFORM_HAS_VARIATION: + self.transformVarIndex, i = _read_uint32var(data, i) + else: + self.transformVarIndex = NO_VARIATION_INDEX + + self.transform = DecomposedTransform() + + def read_transform_component(values): + nonlocal i + if flags & values.flag: + v = ( + fi2fl( + struct.unpack(">h", data[i : i + 2])[0], values.fractionalBits + ) + * values.scale + ) + i += 2 + return v + else: + return values.defaultValue + + for attr_name, mapping_values in VAR_TRANSFORM_MAPPING.items(): + value = read_transform_component(mapping_values) + setattr(self.transform, attr_name, value) + + if not (flags & VarComponentFlags.HAVE_SCALE_Y): + self.transform.scaleY = self.transform.scaleX + + n = flags & VarComponentFlags.RESERVED_MASK + while n: + _, i = _read_uint32var(data, i) + n &= n - 1 + + return data[i:] + + def compile(self, font): + optimizeSpeed = font.cfg[OPTIMIZE_FONT_SPEED] + + data = [] + + flags = self.flags + + glyphID = font.getGlyphID(self.glyphName) + if glyphID > 65535: + flags |= VarComponentFlags.GID_IS_24BIT + data.append(_packer[3](glyphID)) + else: + flags &= ~VarComponentFlags.GID_IS_24BIT + data.append(_packer[2](glyphID)) + + if self.conditionIndex is not None: + flags |= VarComponentFlags.HAVE_CONDITION + data.append(_write_uint32var(self.conditionIndex)) + + numAxes = len(self.axisValues) + + if numAxes: + flags |= VarComponentFlags.HAVE_AXES + data.append(_write_uint32var(self.axisIndicesIndex)) + data.append( + TupleVariation.compileDeltaValues_( + [fl2fi(v, 14) for v in self.axisValues], + optimizeSize=not optimizeSpeed, + ) + ) + else: + flags &= ~VarComponentFlags.HAVE_AXES + + if self.axisValuesVarIndex != NO_VARIATION_INDEX: + flags |= VarComponentFlags.AXIS_VALUES_HAVE_VARIATION + data.append(_write_uint32var(self.axisValuesVarIndex)) + else: + flags &= ~VarComponentFlags.AXIS_VALUES_HAVE_VARIATION + if self.transformVarIndex != NO_VARIATION_INDEX: + flags |= VarComponentFlags.TRANSFORM_HAS_VARIATION + data.append(_write_uint32var(self.transformVarIndex)) + else: + flags &= ~VarComponentFlags.TRANSFORM_HAS_VARIATION + + def write_transform_component(value, values): + if flags & values.flag: + return struct.pack( + ">h", fl2fi(value / values.scale, values.fractionalBits) + ) + else: + return b"" + + for attr_name, mapping_values in VAR_TRANSFORM_MAPPING.items(): + value = getattr(self.transform, attr_name) + data.append(write_transform_component(value, mapping_values)) + + return _write_uint32var(flags) + bytesjoin(data) + + def toXML(self, writer, ttFont, attrs): + writer.begintag("VarComponent", attrs) + writer.newline() + + def write(name, value, attrs=()): + if value is not None: + writer.simpletag(name, (("value", value),) + attrs) + writer.newline() + + write("glyphName", self.glyphName) + + if self.conditionIndex is not None: + write("conditionIndex", self.conditionIndex) + if self.axisIndicesIndex is not None: + write("axisIndicesIndex", self.axisIndicesIndex) + if ( + self.axisIndicesIndex is not None + or self.flags & VarComponentFlags.RESET_UNSPECIFIED_AXES + ): + if self.flags & VarComponentFlags.RESET_UNSPECIFIED_AXES: + attrs = (("resetUnspecifiedAxes", 1),) + else: + attrs = () + write("axisValues", [float(fl2str(v, 14)) for v in self.axisValues], attrs) + + if self.axisValuesVarIndex != NO_VARIATION_INDEX: + write("axisValuesVarIndex", self.axisValuesVarIndex) + if self.transformVarIndex != NO_VARIATION_INDEX: + write("transformVarIndex", self.transformVarIndex) + + # Only write transform components that are specified in the + # flags, even if they are the default value. + for attr_name, mapping in VAR_TRANSFORM_MAPPING.items(): + if not (self.flags & mapping.flag): + continue + v = getattr(self.transform, attr_name) + write(attr_name, fl2str(v, mapping.fractionalBits)) + + writer.endtag("VarComponent") + writer.newline() + + def fromXML(self, name, attrs, content, ttFont): + content = [c for c in content if isinstance(c, tuple)] + + self.populateDefaults() + + for name, attrs, content in content: + assert not content + v = attrs["value"] + + if name == "glyphName": + self.glyphName = v + elif name == "conditionIndex": + self.conditionIndex = safeEval(v) + elif name == "axisIndicesIndex": + self.axisIndicesIndex = safeEval(v) + elif name == "axisValues": + self.axisValues = tuple(str2fl(v, 14) for v in safeEval(v)) + if safeEval(attrs.get("resetUnspecifiedAxes", "0")): + self.flags |= VarComponentFlags.RESET_UNSPECIFIED_AXES + elif name == "axisValuesVarIndex": + self.axisValuesVarIndex = safeEval(v) + elif name == "transformVarIndex": + self.transformVarIndex = safeEval(v) + elif name in VAR_TRANSFORM_MAPPING: + setattr( + self.transform, + name, + safeEval(v), + ) + self.flags |= VAR_TRANSFORM_MAPPING[name].flag + else: + assert False, name + + def applyTransformDeltas(self, deltas): + i = 0 + + def read_transform_component_delta(values): + nonlocal i + if self.flags & values.flag: + v = fi2fl(deltas[i], values.fractionalBits) * values.scale + i += 1 + return v + else: + return 0 + + for attr_name, mapping_values in VAR_TRANSFORM_MAPPING.items(): + value = read_transform_component_delta(mapping_values) + setattr( + self.transform, attr_name, getattr(self.transform, attr_name) + value + ) + + if not (self.flags & VarComponentFlags.HAVE_SCALE_Y): + self.transform.scaleY = self.transform.scaleX + + assert i == len(deltas), (i, len(deltas)) + + def __eq__(self, other): + if type(self) != type(other): + return NotImplemented + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + result = self.__eq__(other) + return result if result is NotImplemented else not result + + +class VarCompositeGlyph: + def __init__(self, components=None): + self.components = components if components is not None else [] + + def decompile(self, data, font, localState): + self.components = [] + while data: + component = VarComponent() + data = component.decompile(data, font, localState) + self.components.append(component) + + def compile(self, font): + data = [] + for component in self.components: + data.append(component.compile(font)) + return bytesjoin(data) + + def toXML(self, xmlWriter, font, attrs, name): + xmlWriter.begintag("VarCompositeGlyph", attrs) + xmlWriter.newline() + for i, component in enumerate(self.components): + component.toXML(xmlWriter, font, [("index", i)]) + xmlWriter.endtag("VarCompositeGlyph") + xmlWriter.newline() + + def fromXML(self, name, attrs, content, font): + content = [c for c in content if isinstance(c, tuple)] + for name, attrs, content in content: + assert name == "VarComponent" + component = VarComponent() + component.fromXML(name, attrs, content, font) + self.components.append(component) + + +class AATStateTable(object): + def __init__(self): + self.GlyphClasses = {} # GlyphID --> GlyphClass + self.States = [] # List of AATState, indexed by state number + self.PerGlyphLookups = [] # [{GlyphID:GlyphID}, ...] + + +class AATState(object): + def __init__(self): + self.Transitions = {} # GlyphClass --> AATAction + + +class AATAction(object): + _FLAGS = None + + @staticmethod + def compileActions(font, states): + return (None, None) + + def _writeFlagsToXML(self, xmlWriter): + flags = [f for f in self._FLAGS if self.__dict__[f]] + if flags: + xmlWriter.simpletag("Flags", value=",".join(flags)) + xmlWriter.newline() + if self.ReservedFlags != 0: + xmlWriter.simpletag("ReservedFlags", value="0x%04X" % self.ReservedFlags) + xmlWriter.newline() + + def _setFlag(self, flag): + assert flag in self._FLAGS, "unsupported flag %s" % flag + self.__dict__[flag] = True + + +class RearrangementMorphAction(AATAction): + staticSize = 4 + actionHeaderSize = 0 + _FLAGS = ["MarkFirst", "DontAdvance", "MarkLast"] + + _VERBS = { + 0: "no change", + 1: "Ax ⇒ xA", + 2: "xD ⇒ Dx", + 3: "AxD ⇒ DxA", + 4: "ABx ⇒ xAB", + 5: "ABx ⇒ xBA", + 6: "xCD ⇒ CDx", + 7: "xCD ⇒ DCx", + 8: "AxCD ⇒ CDxA", + 9: "AxCD ⇒ DCxA", + 10: "ABxD ⇒ DxAB", + 11: "ABxD ⇒ DxBA", + 12: "ABxCD ⇒ CDxAB", + 13: "ABxCD ⇒ CDxBA", + 14: "ABxCD ⇒ DCxAB", + 15: "ABxCD ⇒ DCxBA", + } + + def __init__(self): + self.NewState = 0 + self.Verb = 0 + self.MarkFirst = False + self.DontAdvance = False + self.MarkLast = False + self.ReservedFlags = 0 + + def compile(self, writer, font, actionIndex): + assert actionIndex is None + writer.writeUShort(self.NewState) + assert self.Verb >= 0 and self.Verb <= 15, self.Verb + flags = self.Verb | self.ReservedFlags + if self.MarkFirst: + flags |= 0x8000 + if self.DontAdvance: + flags |= 0x4000 + if self.MarkLast: + flags |= 0x2000 + writer.writeUShort(flags) + + def decompile(self, reader, font, actionReader): + assert actionReader is None + self.NewState = reader.readUShort() + flags = reader.readUShort() + self.Verb = flags & 0xF + self.MarkFirst = bool(flags & 0x8000) + self.DontAdvance = bool(flags & 0x4000) + self.MarkLast = bool(flags & 0x2000) + self.ReservedFlags = flags & 0x1FF0 + + def toXML(self, xmlWriter, font, attrs, name): + xmlWriter.begintag(name, **attrs) + xmlWriter.newline() + xmlWriter.simpletag("NewState", value=self.NewState) + xmlWriter.newline() + self._writeFlagsToXML(xmlWriter) + xmlWriter.simpletag("Verb", value=self.Verb) + verbComment = self._VERBS.get(self.Verb) + if verbComment is not None: + xmlWriter.comment(verbComment) + xmlWriter.newline() + xmlWriter.endtag(name) + xmlWriter.newline() + + def fromXML(self, name, attrs, content, font): + self.NewState = self.Verb = self.ReservedFlags = 0 + self.MarkFirst = self.DontAdvance = self.MarkLast = False + content = [t for t in content if isinstance(t, tuple)] + for eltName, eltAttrs, eltContent in content: + if eltName == "NewState": + self.NewState = safeEval(eltAttrs["value"]) + elif eltName == "Verb": + self.Verb = safeEval(eltAttrs["value"]) + elif eltName == "ReservedFlags": + self.ReservedFlags = safeEval(eltAttrs["value"]) + elif eltName == "Flags": + for flag in eltAttrs["value"].split(","): + self._setFlag(flag.strip()) + + +class ContextualMorphAction(AATAction): + staticSize = 8 + actionHeaderSize = 0 + _FLAGS = ["SetMark", "DontAdvance"] + + def __init__(self): + self.NewState = 0 + self.SetMark, self.DontAdvance = False, False + self.ReservedFlags = 0 + self.MarkIndex, self.CurrentIndex = 0xFFFF, 0xFFFF + + def compile(self, writer, font, actionIndex): + assert actionIndex is None + writer.writeUShort(self.NewState) + flags = self.ReservedFlags + if self.SetMark: + flags |= 0x8000 + if self.DontAdvance: + flags |= 0x4000 + writer.writeUShort(flags) + writer.writeUShort(self.MarkIndex) + writer.writeUShort(self.CurrentIndex) + + def decompile(self, reader, font, actionReader): + assert actionReader is None + self.NewState = reader.readUShort() + flags = reader.readUShort() + self.SetMark = bool(flags & 0x8000) + self.DontAdvance = bool(flags & 0x4000) + self.ReservedFlags = flags & 0x3FFF + self.MarkIndex = reader.readUShort() + self.CurrentIndex = reader.readUShort() + + def toXML(self, xmlWriter, font, attrs, name): + xmlWriter.begintag(name, **attrs) + xmlWriter.newline() + xmlWriter.simpletag("NewState", value=self.NewState) + xmlWriter.newline() + self._writeFlagsToXML(xmlWriter) + xmlWriter.simpletag("MarkIndex", value=self.MarkIndex) + xmlWriter.newline() + xmlWriter.simpletag("CurrentIndex", value=self.CurrentIndex) + xmlWriter.newline() + xmlWriter.endtag(name) + xmlWriter.newline() + + def fromXML(self, name, attrs, content, font): + self.NewState = self.ReservedFlags = 0 + self.SetMark = self.DontAdvance = False + self.MarkIndex, self.CurrentIndex = 0xFFFF, 0xFFFF + content = [t for t in content if isinstance(t, tuple)] + for eltName, eltAttrs, eltContent in content: + if eltName == "NewState": + self.NewState = safeEval(eltAttrs["value"]) + elif eltName == "Flags": + for flag in eltAttrs["value"].split(","): + self._setFlag(flag.strip()) + elif eltName == "ReservedFlags": + self.ReservedFlags = safeEval(eltAttrs["value"]) + elif eltName == "MarkIndex": + self.MarkIndex = safeEval(eltAttrs["value"]) + elif eltName == "CurrentIndex": + self.CurrentIndex = safeEval(eltAttrs["value"]) + + +class LigAction(object): + def __init__(self): + self.Store = False + # GlyphIndexDelta is a (possibly negative) delta that gets + # added to the glyph ID at the top of the AAT runtime + # execution stack. It is *not* a byte offset into the + # morx table. The result of the addition, which is performed + # at run time by the shaping engine, is an index into + # the ligature components table. See 'morx' specification. + # In the AAT specification, this field is called Offset; + # but its meaning is quite different from other offsets + # in either AAT or OpenType, so we use a different name. + self.GlyphIndexDelta = 0 + + +class LigatureMorphAction(AATAction): + staticSize = 6 + + # 4 bytes for each of {action,ligComponents,ligatures}Offset + actionHeaderSize = 12 + + _FLAGS = ["SetComponent", "DontAdvance"] + + def __init__(self): + self.NewState = 0 + self.SetComponent, self.DontAdvance = False, False + self.ReservedFlags = 0 + self.Actions = [] + + def compile(self, writer, font, actionIndex): + assert actionIndex is not None + writer.writeUShort(self.NewState) + flags = self.ReservedFlags + if self.SetComponent: + flags |= 0x8000 + if self.DontAdvance: + flags |= 0x4000 + if len(self.Actions) > 0: + flags |= 0x2000 + writer.writeUShort(flags) + if len(self.Actions) > 0: + actions = self.compileLigActions() + writer.writeUShort(actionIndex[actions]) + else: + writer.writeUShort(0) + + def decompile(self, reader, font, actionReader): + assert actionReader is not None + self.NewState = reader.readUShort() + flags = reader.readUShort() + self.SetComponent = bool(flags & 0x8000) + self.DontAdvance = bool(flags & 0x4000) + performAction = bool(flags & 0x2000) + # As of 2017-09-12, the 'morx' specification says that + # the reserved bitmask in ligature subtables is 0x3FFF. + # However, the specification also defines a flag 0x2000, + # so the reserved value should actually be 0x1FFF. + # TODO: Report this specification bug to Apple. + self.ReservedFlags = flags & 0x1FFF + actionIndex = reader.readUShort() + if performAction: + self.Actions = self._decompileLigActions(actionReader, actionIndex) + else: + self.Actions = [] + + @staticmethod + def compileActions(font, states): + result, actions, actionIndex = b"", set(), {} + for state in states: + for _glyphClass, trans in state.Transitions.items(): + actions.add(trans.compileLigActions()) + # Sort the compiled actions in decreasing order of + # length, so that the longer sequence come before the + # shorter ones. For each compiled action ABCD, its + # suffixes BCD, CD, and D do not be encoded separately + # (in case they occur); instead, we can just store an + # index that points into the middle of the longer + # sequence. Every compiled AAT ligature sequence is + # terminated with an end-of-sequence flag, which can + # only be set on the last element of the sequence. + # Therefore, it is sufficient to consider just the + # suffixes. + for a in sorted(actions, key=lambda x: (-len(x), x)): + if a not in actionIndex: + for i in range(0, len(a), 4): + suffix = a[i:] + suffixIndex = (len(result) + i) // 4 + actionIndex.setdefault(suffix, suffixIndex) + result += a + result = pad(result, 4) + return (result, actionIndex) + + def compileLigActions(self): + result = [] + for i, action in enumerate(self.Actions): + last = i == len(self.Actions) - 1 + value = action.GlyphIndexDelta & 0x3FFFFFFF + value |= 0x80000000 if last else 0 + value |= 0x40000000 if action.Store else 0 + result.append(struct.pack(">L", value)) + return bytesjoin(result) + + def _decompileLigActions(self, actionReader, actionIndex): + actions = [] + last = False + reader = actionReader.getSubReader(actionReader.pos + actionIndex * 4) + while not last: + value = reader.readULong() + last = bool(value & 0x80000000) + action = LigAction() + actions.append(action) + action.Store = bool(value & 0x40000000) + delta = value & 0x3FFFFFFF + if delta >= 0x20000000: # sign-extend 30-bit value + delta = -0x40000000 + delta + action.GlyphIndexDelta = delta + return actions + + def fromXML(self, name, attrs, content, font): + self.NewState = self.ReservedFlags = 0 + self.SetComponent = self.DontAdvance = False + self.ReservedFlags = 0 + self.Actions = [] + content = [t for t in content if isinstance(t, tuple)] + for eltName, eltAttrs, eltContent in content: + if eltName == "NewState": + self.NewState = safeEval(eltAttrs["value"]) + elif eltName == "Flags": + for flag in eltAttrs["value"].split(","): + self._setFlag(flag.strip()) + elif eltName == "ReservedFlags": + self.ReservedFlags = safeEval(eltAttrs["value"]) + elif eltName == "Action": + action = LigAction() + flags = eltAttrs.get("Flags", "").split(",") + flags = [f.strip() for f in flags] + action.Store = "Store" in flags + action.GlyphIndexDelta = safeEval(eltAttrs["GlyphIndexDelta"]) + self.Actions.append(action) + + def toXML(self, xmlWriter, font, attrs, name): + xmlWriter.begintag(name, **attrs) + xmlWriter.newline() + xmlWriter.simpletag("NewState", value=self.NewState) + xmlWriter.newline() + self._writeFlagsToXML(xmlWriter) + for action in self.Actions: + attribs = [("GlyphIndexDelta", action.GlyphIndexDelta)] + if action.Store: + attribs.append(("Flags", "Store")) + xmlWriter.simpletag("Action", attribs) + xmlWriter.newline() + xmlWriter.endtag(name) + xmlWriter.newline() + + +class InsertionMorphAction(AATAction): + staticSize = 8 + actionHeaderSize = 4 # 4 bytes for actionOffset + _FLAGS = [ + "SetMark", + "DontAdvance", + "CurrentIsKashidaLike", + "MarkedIsKashidaLike", + "CurrentInsertBefore", + "MarkedInsertBefore", + ] + + def __init__(self): + self.NewState = 0 + for flag in self._FLAGS: + setattr(self, flag, False) + self.ReservedFlags = 0 + self.CurrentInsertionAction, self.MarkedInsertionAction = [], [] + + def compile(self, writer, font, actionIndex): + assert actionIndex is not None + writer.writeUShort(self.NewState) + flags = self.ReservedFlags + if self.SetMark: + flags |= 0x8000 + if self.DontAdvance: + flags |= 0x4000 + if self.CurrentIsKashidaLike: + flags |= 0x2000 + if self.MarkedIsKashidaLike: + flags |= 0x1000 + if self.CurrentInsertBefore: + flags |= 0x0800 + if self.MarkedInsertBefore: + flags |= 0x0400 + flags |= len(self.CurrentInsertionAction) << 5 + flags |= len(self.MarkedInsertionAction) + writer.writeUShort(flags) + if len(self.CurrentInsertionAction) > 0: + currentIndex = actionIndex[tuple(self.CurrentInsertionAction)] + else: + currentIndex = 0xFFFF + writer.writeUShort(currentIndex) + if len(self.MarkedInsertionAction) > 0: + markedIndex = actionIndex[tuple(self.MarkedInsertionAction)] + else: + markedIndex = 0xFFFF + writer.writeUShort(markedIndex) + + def decompile(self, reader, font, actionReader): + assert actionReader is not None + self.NewState = reader.readUShort() + flags = reader.readUShort() + self.SetMark = bool(flags & 0x8000) + self.DontAdvance = bool(flags & 0x4000) + self.CurrentIsKashidaLike = bool(flags & 0x2000) + self.MarkedIsKashidaLike = bool(flags & 0x1000) + self.CurrentInsertBefore = bool(flags & 0x0800) + self.MarkedInsertBefore = bool(flags & 0x0400) + self.CurrentInsertionAction = self._decompileInsertionAction( + actionReader, font, index=reader.readUShort(), count=((flags & 0x03E0) >> 5) + ) + self.MarkedInsertionAction = self._decompileInsertionAction( + actionReader, font, index=reader.readUShort(), count=(flags & 0x001F) + ) + + def _decompileInsertionAction(self, actionReader, font, index, count): + if index == 0xFFFF or count == 0: + return [] + reader = actionReader.getSubReader(actionReader.pos + index * 2) + return font.getGlyphNameMany(reader.readUShortArray(count)) + + def toXML(self, xmlWriter, font, attrs, name): + xmlWriter.begintag(name, **attrs) + xmlWriter.newline() + xmlWriter.simpletag("NewState", value=self.NewState) + xmlWriter.newline() + self._writeFlagsToXML(xmlWriter) + for g in self.CurrentInsertionAction: + xmlWriter.simpletag("CurrentInsertionAction", glyph=g) + xmlWriter.newline() + for g in self.MarkedInsertionAction: + xmlWriter.simpletag("MarkedInsertionAction", glyph=g) + xmlWriter.newline() + xmlWriter.endtag(name) + xmlWriter.newline() + + def fromXML(self, name, attrs, content, font): + self.__init__() + content = [t for t in content if isinstance(t, tuple)] + for eltName, eltAttrs, eltContent in content: + if eltName == "NewState": + self.NewState = safeEval(eltAttrs["value"]) + elif eltName == "Flags": + for flag in eltAttrs["value"].split(","): + self._setFlag(flag.strip()) + elif eltName == "CurrentInsertionAction": + self.CurrentInsertionAction.append(eltAttrs["glyph"]) + elif eltName == "MarkedInsertionAction": + self.MarkedInsertionAction.append(eltAttrs["glyph"]) + else: + assert False, eltName + + @staticmethod + def compileActions(font, states): + actions, actionIndex, result = set(), {}, b"" + for state in states: + for _glyphClass, trans in state.Transitions.items(): + if trans.CurrentInsertionAction is not None: + actions.add(tuple(trans.CurrentInsertionAction)) + if trans.MarkedInsertionAction is not None: + actions.add(tuple(trans.MarkedInsertionAction)) + # Sort the compiled actions in decreasing order of + # length, so that the longer sequence come before the + # shorter ones. + for action in sorted(actions, key=lambda x: (-len(x), x)): + # We insert all sub-sequences of the action glyph sequence + # into actionIndex. For example, if one action triggers on + # glyph sequence [A, B, C, D, E] and another action triggers + # on [C, D], we return result=[A, B, C, D, E] (as list of + # encoded glyph IDs), and actionIndex={('A','B','C','D','E'): 0, + # ('C','D'): 2}. + if action in actionIndex: + continue + for start in range(0, len(action)): + startIndex = (len(result) // 2) + start + for limit in range(start, len(action)): + glyphs = action[start : limit + 1] + actionIndex.setdefault(glyphs, startIndex) + for glyph in action: + glyphID = font.getGlyphID(glyph) + result += struct.pack(">H", glyphID) + return result, actionIndex + + +class FeatureParams(BaseTable): + def compile(self, writer, font): + assert ( + featureParamTypes.get(writer["FeatureTag"]) == self.__class__ + ), "Wrong FeatureParams type for feature '%s': %s" % ( + writer["FeatureTag"], + self.__class__.__name__, + ) + BaseTable.compile(self, writer, font) + + def toXML(self, xmlWriter, font, attrs=None, name=None): + BaseTable.toXML(self, xmlWriter, font, attrs, name=self.__class__.__name__) + + +class FeatureParamsSize(FeatureParams): + pass + + +class FeatureParamsStylisticSet(FeatureParams): + pass + + +class FeatureParamsCharacterVariants(FeatureParams): + pass + + +class Coverage(FormatSwitchingBaseTable): + # manual implementation to get rid of glyphID dependencies + + def populateDefaults(self, propagator=None): + if not hasattr(self, "glyphs"): + self.glyphs = [] + + def postRead(self, rawTable, font): + if self.Format == 1: + self.glyphs = rawTable["GlyphArray"] + elif self.Format == 2: + glyphs = self.glyphs = [] + ranges = rawTable["RangeRecord"] + # Some SIL fonts have coverage entries that don't have sorted + # StartCoverageIndex. If it is so, fixup and warn. We undo + # this when writing font out. + sorted_ranges = sorted(ranges, key=lambda a: a.StartCoverageIndex) + if ranges != sorted_ranges: + log.warning("GSUB/GPOS Coverage is not sorted by glyph ids.") + ranges = sorted_ranges + del sorted_ranges + for r in ranges: + start = r.Start + end = r.End + startID = font.getGlyphID(start) + endID = font.getGlyphID(end) + 1 + glyphs.extend(font.getGlyphNameMany(range(startID, endID))) + else: + self.glyphs = [] + log.warning("Unknown Coverage format: %s", self.Format) + del self.Format # Don't need this anymore + + def preWrite(self, font): + glyphs = getattr(self, "glyphs", None) + if glyphs is None: + glyphs = self.glyphs = [] + format = 1 + rawTable = {"GlyphArray": glyphs} + if glyphs: + # find out whether Format 2 is more compact or not + glyphIDs = font.getGlyphIDMany(glyphs) + brokenOrder = sorted(glyphIDs) != glyphIDs + + last = glyphIDs[0] + ranges = [[last]] + for glyphID in glyphIDs[1:]: + if glyphID != last + 1: + ranges[-1].append(last) + ranges.append([glyphID]) + last = glyphID + ranges[-1].append(last) + + if brokenOrder or len(ranges) * 3 < len(glyphs): # 3 words vs. 1 word + # Format 2 is more compact + index = 0 + for i, (start, end) in enumerate(ranges): + r = RangeRecord() + r.StartID = start + r.Start = font.getGlyphName(start) + r.End = font.getGlyphName(end) + r.StartCoverageIndex = index + ranges[i] = r + index = index + end - start + 1 + if brokenOrder: + log.warning("GSUB/GPOS Coverage is not sorted by glyph ids.") + ranges.sort(key=lambda a: a.StartID) + for r in ranges: + del r.StartID + format = 2 + rawTable = {"RangeRecord": ranges} + # else: + # fallthrough; Format 1 is more compact + self.Format = format + return rawTable + + def toXML2(self, xmlWriter, font): + for glyphName in getattr(self, "glyphs", []): + xmlWriter.simpletag("Glyph", value=glyphName) + xmlWriter.newline() + + def fromXML(self, name, attrs, content, font): + glyphs = getattr(self, "glyphs", None) + if glyphs is None: + glyphs = [] + self.glyphs = glyphs + glyphs.append(attrs["value"]) + + +# The special 0xFFFFFFFF delta-set index is used to indicate that there +# is no variation data in the ItemVariationStore for a given variable field +NO_VARIATION_INDEX = 0xFFFFFFFF + + +class DeltaSetIndexMap(getFormatSwitchingBaseTableClass("uint8")): + def populateDefaults(self, propagator=None): + if not hasattr(self, "mapping"): + self.mapping = [] + + def postRead(self, rawTable, font): + assert (rawTable["EntryFormat"] & 0xFFC0) == 0 + self.mapping = rawTable["mapping"] + + @staticmethod + def getEntryFormat(mapping): + ored = 0 + for idx in mapping: + ored |= idx + + inner = ored & 0xFFFF + innerBits = 0 + while inner: + innerBits += 1 + inner >>= 1 + innerBits = max(innerBits, 1) + assert innerBits <= 16 + + ored = (ored >> (16 - innerBits)) | (ored & ((1 << innerBits) - 1)) + if ored <= 0x000000FF: + entrySize = 1 + elif ored <= 0x0000FFFF: + entrySize = 2 + elif ored <= 0x00FFFFFF: + entrySize = 3 + else: + entrySize = 4 + + return ((entrySize - 1) << 4) | (innerBits - 1) + + def preWrite(self, font): + mapping = getattr(self, "mapping", None) + if mapping is None: + mapping = self.mapping = [] + self.Format = 1 if len(mapping) > 0xFFFF else 0 + rawTable = self.__dict__.copy() + rawTable["MappingCount"] = len(mapping) + rawTable["EntryFormat"] = self.getEntryFormat(mapping) + return rawTable + + def toXML2(self, xmlWriter, font): + # Make xml dump less verbose, by omitting no-op entries like: + # + xmlWriter.comment("Omitted values default to 0xFFFF/0xFFFF (no variations)") + xmlWriter.newline() + for i, value in enumerate(getattr(self, "mapping", [])): + attrs = [("index", i)] + if value != NO_VARIATION_INDEX: + attrs.extend( + [ + ("outer", value >> 16), + ("inner", value & 0xFFFF), + ] + ) + xmlWriter.simpletag("Map", attrs) + xmlWriter.newline() + + def fromXML(self, name, attrs, content, font): + mapping = getattr(self, "mapping", None) + if mapping is None: + self.mapping = mapping = [] + index = safeEval(attrs["index"]) + outer = safeEval(attrs.get("outer", "0xFFFF")) + inner = safeEval(attrs.get("inner", "0xFFFF")) + assert inner <= 0xFFFF + mapping.insert(index, (outer << 16) | inner) + + def __getitem__(self, i): + return self.mapping[i] if i < len(self.mapping) else NO_VARIATION_INDEX + + +class VarIdxMap(BaseTable): + def populateDefaults(self, propagator=None): + if not hasattr(self, "mapping"): + self.mapping = {} + + def postRead(self, rawTable, font): + assert (rawTable["EntryFormat"] & 0xFFC0) == 0 + glyphOrder = font.getGlyphOrder() + mapList = rawTable["mapping"] + mapList.extend([mapList[-1]] * (len(glyphOrder) - len(mapList))) + self.mapping = dict(zip(glyphOrder, mapList)) + + def preWrite(self, font): + mapping = getattr(self, "mapping", None) + if mapping is None: + mapping = self.mapping = {} + + glyphOrder = font.getGlyphOrder() + mapping = [mapping[g] for g in glyphOrder] + while len(mapping) > 1 and mapping[-2] == mapping[-1]: + del mapping[-1] + + rawTable = {"mapping": mapping} + rawTable["MappingCount"] = len(mapping) + rawTable["EntryFormat"] = DeltaSetIndexMap.getEntryFormat(mapping) + return rawTable + + def toXML2(self, xmlWriter, font): + for glyph, value in sorted(getattr(self, "mapping", {}).items()): + attrs = ( + ("glyph", glyph), + ("outer", value >> 16), + ("inner", value & 0xFFFF), + ) + xmlWriter.simpletag("Map", attrs) + xmlWriter.newline() + + def fromXML(self, name, attrs, content, font): + mapping = getattr(self, "mapping", None) + if mapping is None: + mapping = {} + self.mapping = mapping + try: + glyph = attrs["glyph"] + except: # https://github.com/fonttools/fonttools/commit/21cbab8ce9ded3356fef3745122da64dcaf314e9#commitcomment-27649836 + glyph = font.getGlyphOrder()[attrs["index"]] + outer = safeEval(attrs["outer"]) + inner = safeEval(attrs["inner"]) + assert inner <= 0xFFFF + mapping[glyph] = (outer << 16) | inner + + def __getitem__(self, glyphName): + return self.mapping.get(glyphName, NO_VARIATION_INDEX) + + +class VarRegionList(BaseTable): + def preWrite(self, font): + # The OT spec says VarStore.VarRegionList.RegionAxisCount should always + # be equal to the fvar.axisCount, and OTS < v8.0.0 enforces this rule + # even when the VarRegionList is empty. We can't treat RegionAxisCount + # like a normal propagated count (== len(Region[i].VarRegionAxis)), + # otherwise it would default to 0 if VarRegionList is empty. + # Thus, we force it to always be equal to fvar.axisCount. + # https://github.com/khaledhosny/ots/pull/192 + fvarTable = font.get("fvar") + if fvarTable: + self.RegionAxisCount = len(fvarTable.axes) + return { + **self.__dict__, + "RegionAxisCount": CountReference(self.__dict__, "RegionAxisCount"), + } + + +class SingleSubst(FormatSwitchingBaseTable): + def populateDefaults(self, propagator=None): + if not hasattr(self, "mapping"): + self.mapping = {} + + def postRead(self, rawTable, font): + mapping = {} + input = _getGlyphsFromCoverageTable(rawTable["Coverage"]) + if self.Format == 1: + delta = rawTable["DeltaGlyphID"] + inputGIDS = font.getGlyphIDMany(input) + outGIDS = [(glyphID + delta) % 65536 for glyphID in inputGIDS] + outNames = font.getGlyphNameMany(outGIDS) + for inp, out in zip(input, outNames): + mapping[inp] = out + elif self.Format == 2: + assert ( + len(input) == rawTable["GlyphCount"] + ), "invalid SingleSubstFormat2 table" + subst = rawTable["Substitute"] + for inp, sub in zip(input, subst): + mapping[inp] = sub + else: + assert 0, "unknown format: %s" % self.Format + self.mapping = mapping + del self.Format # Don't need this anymore + + def preWrite(self, font): + mapping = getattr(self, "mapping", None) + if mapping is None: + mapping = self.mapping = {} + items = list(mapping.items()) + getGlyphID = font.getGlyphID + gidItems = [(getGlyphID(a), getGlyphID(b)) for a, b in items] + sortableItems = sorted(zip(gidItems, items)) + + # figure out format + format = 2 + delta = None + for inID, outID in gidItems: + if delta is None: + delta = (outID - inID) % 65536 + + if (inID + delta) % 65536 != outID: + break + else: + if delta is None: + # the mapping is empty, better use format 2 + format = 2 + else: + format = 1 + + rawTable = {} + self.Format = format + cov = Coverage() + input = [item[1][0] for item in sortableItems] + subst = [item[1][1] for item in sortableItems] + cov.glyphs = input + rawTable["Coverage"] = cov + if format == 1: + assert delta is not None + rawTable["DeltaGlyphID"] = delta + else: + rawTable["Substitute"] = subst + return rawTable + + def toXML2(self, xmlWriter, font): + items = sorted(self.mapping.items()) + for inGlyph, outGlyph in items: + xmlWriter.simpletag("Substitution", [("in", inGlyph), ("out", outGlyph)]) + xmlWriter.newline() + + def fromXML(self, name, attrs, content, font): + mapping = getattr(self, "mapping", None) + if mapping is None: + mapping = {} + self.mapping = mapping + mapping[attrs["in"]] = attrs["out"] + + +class MultipleSubst(FormatSwitchingBaseTable): + def populateDefaults(self, propagator=None): + if not hasattr(self, "mapping"): + self.mapping = {} + + def postRead(self, rawTable, font): + mapping = {} + if self.Format == 1: + glyphs = _getGlyphsFromCoverageTable(rawTable["Coverage"]) + subst = [s.Substitute for s in rawTable["Sequence"]] + mapping = dict(zip(glyphs, subst)) + else: + assert 0, "unknown format: %s" % self.Format + self.mapping = mapping + del self.Format # Don't need this anymore + + def preWrite(self, font): + mapping = getattr(self, "mapping", None) + if mapping is None: + mapping = self.mapping = {} + cov = Coverage() + cov.glyphs = sorted(list(mapping.keys()), key=font.getGlyphID) + self.Format = 1 + rawTable = { + "Coverage": cov, + "Sequence": [self.makeSequence_(mapping[glyph]) for glyph in cov.glyphs], + } + return rawTable + + def toXML2(self, xmlWriter, font): + items = sorted(self.mapping.items()) + for inGlyph, outGlyphs in items: + out = ",".join(outGlyphs) + xmlWriter.simpletag("Substitution", [("in", inGlyph), ("out", out)]) + xmlWriter.newline() + + def fromXML(self, name, attrs, content, font): + mapping = getattr(self, "mapping", None) + if mapping is None: + mapping = {} + self.mapping = mapping + + # TTX v3.0 and earlier. + if name == "Coverage": + self.old_coverage_ = [] + for element in content: + if not isinstance(element, tuple): + continue + element_name, element_attrs, _ = element + if element_name == "Glyph": + self.old_coverage_.append(element_attrs["value"]) + return + if name == "Sequence": + index = int(attrs.get("index", len(mapping))) + glyph = self.old_coverage_[index] + glyph_mapping = mapping[glyph] = [] + for element in content: + if not isinstance(element, tuple): + continue + element_name, element_attrs, _ = element + if element_name == "Substitute": + glyph_mapping.append(element_attrs["value"]) + return + + # TTX v3.1 and later. + outGlyphs = attrs["out"].split(",") if attrs["out"] else [] + mapping[attrs["in"]] = [g.strip() for g in outGlyphs] + + @staticmethod + def makeSequence_(g): + seq = Sequence() + seq.Substitute = g + return seq + + +class ClassDef(FormatSwitchingBaseTable): + def populateDefaults(self, propagator=None): + if not hasattr(self, "classDefs"): + self.classDefs = {} + + def postRead(self, rawTable, font): + classDefs = {} + + if self.Format == 1: + start = rawTable["StartGlyph"] + classList = rawTable["ClassValueArray"] + startID = font.getGlyphID(start) + endID = startID + len(classList) + glyphNames = font.getGlyphNameMany(range(startID, endID)) + for glyphName, cls in zip(glyphNames, classList): + if cls: + classDefs[glyphName] = cls + + elif self.Format == 2: + records = rawTable["ClassRangeRecord"] + for rec in records: + cls = rec.Class + if not cls: + continue + start = rec.Start + end = rec.End + startID = font.getGlyphID(start) + endID = font.getGlyphID(end) + 1 + glyphNames = font.getGlyphNameMany(range(startID, endID)) + for glyphName in glyphNames: + classDefs[glyphName] = cls + else: + log.warning("Unknown ClassDef format: %s", self.Format) + self.classDefs = classDefs + del self.Format # Don't need this anymore + + def _getClassRanges(self, font): + classDefs = getattr(self, "classDefs", None) + if classDefs is None: + self.classDefs = {} + return + getGlyphID = font.getGlyphID + items = [] + for glyphName, cls in classDefs.items(): + if not cls: + continue + items.append((getGlyphID(glyphName), glyphName, cls)) + if items: + items.sort() + last, lastName, lastCls = items[0] + ranges = [[lastCls, last, lastName]] + for glyphID, glyphName, cls in items[1:]: + if glyphID != last + 1 or cls != lastCls: + ranges[-1].extend([last, lastName]) + ranges.append([cls, glyphID, glyphName]) + last = glyphID + lastName = glyphName + lastCls = cls + ranges[-1].extend([last, lastName]) + return ranges + + def preWrite(self, font): + format = 2 + rawTable = {"ClassRangeRecord": []} + ranges = self._getClassRanges(font) + if ranges: + startGlyph = ranges[0][1] + endGlyph = ranges[-1][3] + glyphCount = endGlyph - startGlyph + 1 + if len(ranges) * 3 < glyphCount + 1: + # Format 2 is more compact + for i, (cls, start, startName, end, endName) in enumerate(ranges): + rec = ClassRangeRecord() + rec.Start = startName + rec.End = endName + rec.Class = cls + ranges[i] = rec + format = 2 + rawTable = {"ClassRangeRecord": ranges} + else: + # Format 1 is more compact + startGlyphName = ranges[0][2] + classes = [0] * glyphCount + for cls, start, startName, end, endName in ranges: + for g in range(start - startGlyph, end - startGlyph + 1): + classes[g] = cls + format = 1 + rawTable = {"StartGlyph": startGlyphName, "ClassValueArray": classes} + self.Format = format + return rawTable + + def toXML2(self, xmlWriter, font): + items = sorted(self.classDefs.items()) + for glyphName, cls in items: + xmlWriter.simpletag("ClassDef", [("glyph", glyphName), ("class", cls)]) + xmlWriter.newline() + + def fromXML(self, name, attrs, content, font): + classDefs = getattr(self, "classDefs", None) + if classDefs is None: + classDefs = {} + self.classDefs = classDefs + classDefs[attrs["glyph"]] = int(attrs["class"]) + + +class AlternateSubst(FormatSwitchingBaseTable): + def populateDefaults(self, propagator=None): + if not hasattr(self, "alternates"): + self.alternates = {} + + def postRead(self, rawTable, font): + alternates = {} + if self.Format == 1: + input = _getGlyphsFromCoverageTable(rawTable["Coverage"]) + alts = rawTable["AlternateSet"] + assert len(input) == len(alts) + for inp, alt in zip(input, alts): + alternates[inp] = alt.Alternate + else: + assert 0, "unknown format: %s" % self.Format + self.alternates = alternates + del self.Format # Don't need this anymore + + def preWrite(self, font): + self.Format = 1 + alternates = getattr(self, "alternates", None) + if alternates is None: + alternates = self.alternates = {} + items = list(alternates.items()) + for i, (glyphName, set) in enumerate(items): + items[i] = font.getGlyphID(glyphName), glyphName, set + items.sort() + cov = Coverage() + cov.glyphs = [item[1] for item in items] + alternates = [] + setList = [item[-1] for item in items] + for set in setList: + alts = AlternateSet() + alts.Alternate = set + alternates.append(alts) + # a special case to deal with the fact that several hundred Adobe Japan1-5 + # CJK fonts will overflow an offset if the coverage table isn't pushed to the end. + # Also useful in that when splitting a sub-table because of an offset overflow + # I don't need to calculate the change in the subtable offset due to the change in the coverage table size. + # Allows packing more rules in subtable. + self.sortCoverageLast = 1 + return {"Coverage": cov, "AlternateSet": alternates} + + def toXML2(self, xmlWriter, font): + items = sorted(self.alternates.items()) + for glyphName, alternates in items: + xmlWriter.begintag("AlternateSet", glyph=glyphName) + xmlWriter.newline() + for alt in alternates: + xmlWriter.simpletag("Alternate", glyph=alt) + xmlWriter.newline() + xmlWriter.endtag("AlternateSet") + xmlWriter.newline() + + def fromXML(self, name, attrs, content, font): + alternates = getattr(self, "alternates", None) + if alternates is None: + alternates = {} + self.alternates = alternates + glyphName = attrs["glyph"] + set = [] + alternates[glyphName] = set + for element in content: + if not isinstance(element, tuple): + continue + name, attrs, content = element + set.append(attrs["glyph"]) + + +class LigatureSubst(FormatSwitchingBaseTable): + def populateDefaults(self, propagator=None): + if not hasattr(self, "ligatures"): + self.ligatures = {} + + def postRead(self, rawTable, font): + ligatures = {} + if self.Format == 1: + input = _getGlyphsFromCoverageTable(rawTable["Coverage"]) + ligSets = rawTable["LigatureSet"] + assert len(input) == len(ligSets) + for i, inp in enumerate(input): + ligatures[inp] = ligSets[i].Ligature + else: + assert 0, "unknown format: %s" % self.Format + self.ligatures = ligatures + del self.Format # Don't need this anymore + + @staticmethod + def _getLigatureSortKey(components): + # Computes a key for ordering ligatures in a GSUB Type-4 lookup. + + # When building the OpenType lookup, we need to make sure that + # the longest sequence of components is listed first, so we + # use the negative length as the key for sorting. + # Note, we no longer need to worry about deterministic order because the + # ligature mapping `dict` remembers the insertion order, and this in + # turn depends on the order in which the ligatures are written in the FEA. + # Since python sort algorithm is stable, the ligatures of equal length + # will keep the relative order in which they appear in the feature file. + # For example, given the following ligatures (all starting with 'f' and + # thus belonging to the same LigatureSet): + # + # feature liga { + # sub f i by f_i; + # sub f f f by f_f_f; + # sub f f by f_f; + # sub f f i by f_f_i; + # } liga; + # + # this should sort to: f_f_f, f_f_i, f_i, f_f + # This is also what fea-rs does, see: + # https://github.com/adobe-type-tools/afdko/issues/1727 + # https://github.com/fonttools/fonttools/issues/3428 + # https://github.com/googlefonts/fontc/pull/680 + return -len(components) + + def preWrite(self, font): + self.Format = 1 + ligatures = getattr(self, "ligatures", None) + if ligatures is None: + ligatures = self.ligatures = {} + + if ligatures and isinstance(next(iter(ligatures)), tuple): + # New high-level API in v3.1 and later. Note that we just support compiling this + # for now. We don't load to this API, and don't do XML with it. + + # ligatures is map from components-sequence to lig-glyph + newLigatures = dict() + for comps in sorted(ligatures.keys(), key=self._getLigatureSortKey): + ligature = Ligature() + ligature.Component = comps[1:] + ligature.CompCount = len(comps) + ligature.LigGlyph = ligatures[comps] + newLigatures.setdefault(comps[0], []).append(ligature) + ligatures = newLigatures + + items = list(ligatures.items()) + for i, (glyphName, set) in enumerate(items): + items[i] = font.getGlyphID(glyphName), glyphName, set + items.sort() + cov = Coverage() + cov.glyphs = [item[1] for item in items] + + ligSets = [] + setList = [item[-1] for item in items] + for set in setList: + ligSet = LigatureSet() + ligs = ligSet.Ligature = [] + for lig in set: + ligs.append(lig) + ligSets.append(ligSet) + # Useful in that when splitting a sub-table because of an offset overflow + # I don't need to calculate the change in subtabl offset due to the coverage table size. + # Allows packing more rules in subtable. + self.sortCoverageLast = 1 + return {"Coverage": cov, "LigatureSet": ligSets} + + def toXML2(self, xmlWriter, font): + items = sorted(self.ligatures.items()) + for glyphName, ligSets in items: + xmlWriter.begintag("LigatureSet", glyph=glyphName) + xmlWriter.newline() + for lig in ligSets: + xmlWriter.simpletag( + "Ligature", glyph=lig.LigGlyph, components=",".join(lig.Component) + ) + xmlWriter.newline() + xmlWriter.endtag("LigatureSet") + xmlWriter.newline() + + def fromXML(self, name, attrs, content, font): + ligatures = getattr(self, "ligatures", None) + if ligatures is None: + ligatures = {} + self.ligatures = ligatures + glyphName = attrs["glyph"] + ligs = [] + ligatures[glyphName] = ligs + for element in content: + if not isinstance(element, tuple): + continue + name, attrs, content = element + lig = Ligature() + lig.LigGlyph = attrs["glyph"] + components = attrs["components"] + lig.Component = components.split(",") if components else [] + lig.CompCount = len(lig.Component) + ligs.append(lig) + + +class COLR(BaseTable): + def decompile(self, reader, font): + # COLRv0 is exceptional in that LayerRecordCount appears *after* the + # LayerRecordArray it counts, but the parser logic expects Count fields + # to always precede the arrays. Here we work around this by parsing the + # LayerRecordCount before the rest of the table, and storing it in + # the reader's local state. + subReader = reader.getSubReader(offset=0) + for conv in self.getConverters(): + if conv.name != "LayerRecordCount": + subReader.advance(conv.staticSize) + continue + reader[conv.name] = conv.read(subReader, font, tableDict={}) + break + else: + raise AssertionError("LayerRecordCount converter not found") + return BaseTable.decompile(self, reader, font) + + def preWrite(self, font): + # The writer similarly assumes Count values precede the things counted, + # thus here we pre-initialize a CountReference; the actual count value + # will be set to the lenght of the array by the time this is assembled. + self.LayerRecordCount = None + return { + **self.__dict__, + "LayerRecordCount": CountReference(self.__dict__, "LayerRecordCount"), + } + + def computeClipBoxes(self, glyphSet: "_TTGlyphSet", quantization: int = 1): + if self.Version == 0: + return + + clips = {} + for rec in self.BaseGlyphList.BaseGlyphPaintRecord: + try: + clipBox = rec.Paint.computeClipBox(self, glyphSet, quantization) + except Exception as e: + from fontTools.ttLib import TTLibError + + raise TTLibError( + f"Failed to compute COLR ClipBox for {rec.BaseGlyph!r}" + ) from e + + if clipBox is not None: + clips[rec.BaseGlyph] = clipBox + + hasClipList = hasattr(self, "ClipList") and self.ClipList is not None + if not clips: + if hasClipList: + self.ClipList = None + else: + if not hasClipList: + self.ClipList = ClipList() + self.ClipList.Format = 1 + self.ClipList.clips = clips + + +class LookupList(BaseTable): + @property + def table(self): + for l in self.Lookup: + for st in l.SubTable: + if type(st).__name__.endswith("Subst"): + return "GSUB" + if type(st).__name__.endswith("Pos"): + return "GPOS" + raise ValueError + + def toXML2(self, xmlWriter, font): + if ( + not font + or "Debg" not in font + or LOOKUP_DEBUG_INFO_KEY not in font["Debg"].data + ): + return super().toXML2(xmlWriter, font) + debugData = font["Debg"].data[LOOKUP_DEBUG_INFO_KEY][self.table] + for conv in self.getConverters(): + if conv.repeat: + value = getattr(self, conv.name, []) + for lookupIndex, item in enumerate(value): + if str(lookupIndex) in debugData: + info = LookupDebugInfo(*debugData[str(lookupIndex)]) + tag = info.location + if info.name: + tag = f"{info.name}: {tag}" + if info.feature: + script, language, feature = info.feature + tag = f"{tag} in {feature} ({script}/{language})" + xmlWriter.comment(tag) + xmlWriter.newline() + + conv.xmlWrite( + xmlWriter, font, item, conv.name, [("index", lookupIndex)] + ) + else: + if conv.aux and not eval(conv.aux, None, vars(self)): + continue + value = getattr( + self, conv.name, None + ) # TODO Handle defaults instead of defaulting to None! + conv.xmlWrite(xmlWriter, font, value, conv.name, []) + + +class BaseGlyphRecordArray(BaseTable): + def preWrite(self, font): + self.BaseGlyphRecord = sorted( + self.BaseGlyphRecord, key=lambda rec: font.getGlyphID(rec.BaseGlyph) + ) + return self.__dict__.copy() + + +class BaseGlyphList(BaseTable): + def preWrite(self, font): + self.BaseGlyphPaintRecord = sorted( + self.BaseGlyphPaintRecord, key=lambda rec: font.getGlyphID(rec.BaseGlyph) + ) + return self.__dict__.copy() + + +class ClipBoxFormat(IntEnum): + Static = 1 + Variable = 2 + + def is_variable(self): + return self is self.Variable + + def as_variable(self): + return self.Variable + + +class ClipBox(getFormatSwitchingBaseTableClass("uint8")): + formatEnum = ClipBoxFormat + + def as_tuple(self): + return tuple(getattr(self, conv.name) for conv in self.getConverters()) + + def __repr__(self): + return f"{self.__class__.__name__}{self.as_tuple()}" + + +class ClipList(getFormatSwitchingBaseTableClass("uint8")): + def populateDefaults(self, propagator=None): + if not hasattr(self, "clips"): + self.clips = {} + + def postRead(self, rawTable, font): + clips = {} + glyphOrder = font.getGlyphOrder() + for i, rec in enumerate(rawTable["ClipRecord"]): + if rec.StartGlyphID > rec.EndGlyphID: + log.warning( + "invalid ClipRecord[%i].StartGlyphID (%i) > " + "EndGlyphID (%i); skipped", + i, + rec.StartGlyphID, + rec.EndGlyphID, + ) + continue + redefinedGlyphs = [] + missingGlyphs = [] + for glyphID in range(rec.StartGlyphID, rec.EndGlyphID + 1): + try: + glyph = glyphOrder[glyphID] + except IndexError: + missingGlyphs.append(glyphID) + continue + if glyph not in clips: + clips[glyph] = copy.copy(rec.ClipBox) + else: + redefinedGlyphs.append(glyphID) + if redefinedGlyphs: + log.warning( + "ClipRecord[%i] overlaps previous records; " + "ignoring redefined clip boxes for the " + "following glyph ID range: [%i-%i]", + i, + min(redefinedGlyphs), + max(redefinedGlyphs), + ) + if missingGlyphs: + log.warning( + "ClipRecord[%i] range references missing " "glyph IDs: [%i-%i]", + i, + min(missingGlyphs), + max(missingGlyphs), + ) + self.clips = clips + + def groups(self): + glyphsByClip = defaultdict(list) + uniqueClips = {} + for glyphName, clipBox in self.clips.items(): + key = clipBox.as_tuple() + glyphsByClip[key].append(glyphName) + if key not in uniqueClips: + uniqueClips[key] = clipBox + return { + frozenset(glyphs): uniqueClips[key] for key, glyphs in glyphsByClip.items() + } + + def preWrite(self, font): + if not hasattr(self, "clips"): + self.clips = {} + clipBoxRanges = {} + glyphMap = font.getReverseGlyphMap() + for glyphs, clipBox in self.groups().items(): + glyphIDs = sorted( + glyphMap[glyphName] for glyphName in glyphs if glyphName in glyphMap + ) + if not glyphIDs: + continue + last = glyphIDs[0] + ranges = [[last]] + for glyphID in glyphIDs[1:]: + if glyphID != last + 1: + ranges[-1].append(last) + ranges.append([glyphID]) + last = glyphID + ranges[-1].append(last) + for start, end in ranges: + assert (start, end) not in clipBoxRanges + clipBoxRanges[(start, end)] = clipBox + + clipRecords = [] + for (start, end), clipBox in sorted(clipBoxRanges.items()): + record = ClipRecord() + record.StartGlyphID = start + record.EndGlyphID = end + record.ClipBox = clipBox + clipRecords.append(record) + rawTable = { + "ClipCount": len(clipRecords), + "ClipRecord": clipRecords, + } + return rawTable + + def toXML(self, xmlWriter, font, attrs=None, name=None): + tableName = name if name else self.__class__.__name__ + if attrs is None: + attrs = [] + if hasattr(self, "Format"): + attrs.append(("Format", self.Format)) + xmlWriter.begintag(tableName, attrs) + xmlWriter.newline() + # sort clips alphabetically to ensure deterministic XML dump + for glyphs, clipBox in sorted( + self.groups().items(), key=lambda item: min(item[0]) + ): + xmlWriter.begintag("Clip") + xmlWriter.newline() + for glyphName in sorted(glyphs): + xmlWriter.simpletag("Glyph", value=glyphName) + xmlWriter.newline() + xmlWriter.begintag("ClipBox", [("Format", clipBox.Format)]) + xmlWriter.newline() + clipBox.toXML2(xmlWriter, font) + xmlWriter.endtag("ClipBox") + xmlWriter.newline() + xmlWriter.endtag("Clip") + xmlWriter.newline() + xmlWriter.endtag(tableName) + xmlWriter.newline() + + def fromXML(self, name, attrs, content, font): + clips = getattr(self, "clips", None) + if clips is None: + self.clips = clips = {} + assert name == "Clip" + glyphs = [] + clipBox = None + for elem in content: + if not isinstance(elem, tuple): + continue + name, attrs, content = elem + if name == "Glyph": + glyphs.append(attrs["value"]) + elif name == "ClipBox": + clipBox = ClipBox() + clipBox.Format = safeEval(attrs["Format"]) + for elem in content: + if not isinstance(elem, tuple): + continue + name, attrs, content = elem + clipBox.fromXML(name, attrs, content, font) + if clipBox: + for glyphName in glyphs: + clips[glyphName] = clipBox + + +class ExtendMode(IntEnum): + PAD = 0 + REPEAT = 1 + REFLECT = 2 + + +# Porter-Duff modes for COLRv1 PaintComposite: +# https://github.com/googlefonts/colr-gradients-spec/tree/off_sub_1#compositemode-enumeration +class CompositeMode(IntEnum): + CLEAR = 0 + SRC = 1 + DEST = 2 + SRC_OVER = 3 + DEST_OVER = 4 + SRC_IN = 5 + DEST_IN = 6 + SRC_OUT = 7 + DEST_OUT = 8 + SRC_ATOP = 9 + DEST_ATOP = 10 + XOR = 11 + PLUS = 12 + SCREEN = 13 + OVERLAY = 14 + DARKEN = 15 + LIGHTEN = 16 + COLOR_DODGE = 17 + COLOR_BURN = 18 + HARD_LIGHT = 19 + SOFT_LIGHT = 20 + DIFFERENCE = 21 + EXCLUSION = 22 + MULTIPLY = 23 + HSL_HUE = 24 + HSL_SATURATION = 25 + HSL_COLOR = 26 + HSL_LUMINOSITY = 27 + + +class PaintFormat(IntEnum): + PaintColrLayers = 1 + PaintSolid = 2 + PaintVarSolid = 3 + PaintLinearGradient = 4 + PaintVarLinearGradient = 5 + PaintRadialGradient = 6 + PaintVarRadialGradient = 7 + PaintSweepGradient = 8 + PaintVarSweepGradient = 9 + PaintGlyph = 10 + PaintColrGlyph = 11 + PaintTransform = 12 + PaintVarTransform = 13 + PaintTranslate = 14 + PaintVarTranslate = 15 + PaintScale = 16 + PaintVarScale = 17 + PaintScaleAroundCenter = 18 + PaintVarScaleAroundCenter = 19 + PaintScaleUniform = 20 + PaintVarScaleUniform = 21 + PaintScaleUniformAroundCenter = 22 + PaintVarScaleUniformAroundCenter = 23 + PaintRotate = 24 + PaintVarRotate = 25 + PaintRotateAroundCenter = 26 + PaintVarRotateAroundCenter = 27 + PaintSkew = 28 + PaintVarSkew = 29 + PaintSkewAroundCenter = 30 + PaintVarSkewAroundCenter = 31 + PaintComposite = 32 + + def is_variable(self): + return self.name.startswith("PaintVar") + + def as_variable(self): + if self.is_variable(): + return self + try: + return PaintFormat.__members__[f"PaintVar{self.name[5:]}"] + except KeyError: + return None + + +class Paint(getFormatSwitchingBaseTableClass("uint8")): + formatEnum = PaintFormat + + def getFormatName(self): + try: + return self.formatEnum(self.Format).name + except ValueError: + raise NotImplementedError(f"Unknown Paint format: {self.Format}") + + def toXML(self, xmlWriter, font, attrs=None, name=None): + tableName = name if name else self.__class__.__name__ + if attrs is None: + attrs = [] + attrs.append(("Format", self.Format)) + xmlWriter.begintag(tableName, attrs) + xmlWriter.comment(self.getFormatName()) + xmlWriter.newline() + self.toXML2(xmlWriter, font) + xmlWriter.endtag(tableName) + xmlWriter.newline() + + def iterPaintSubTables(self, colr: COLR) -> Iterator[BaseTable.SubTableEntry]: + if self.Format == PaintFormat.PaintColrLayers: + # https://github.com/fonttools/fonttools/issues/2438: don't die when no LayerList exists + layers = [] + if colr.LayerList is not None: + layers = colr.LayerList.Paint + yield from ( + BaseTable.SubTableEntry(name="Layers", value=v, index=i) + for i, v in enumerate( + layers[self.FirstLayerIndex : self.FirstLayerIndex + self.NumLayers] + ) + ) + return + + if self.Format == PaintFormat.PaintColrGlyph: + for record in colr.BaseGlyphList.BaseGlyphPaintRecord: + if record.BaseGlyph == self.Glyph: + yield BaseTable.SubTableEntry(name="BaseGlyph", value=record.Paint) + return + else: + raise KeyError(f"{self.Glyph!r} not in colr.BaseGlyphList") + + for conv in self.getConverters(): + if conv.tableClass is not None and issubclass(conv.tableClass, type(self)): + value = getattr(self, conv.name) + yield BaseTable.SubTableEntry(name=conv.name, value=value) + + def getChildren(self, colr) -> List["Paint"]: + # this is kept for backward compatibility (e.g. it's used by the subsetter) + return [p.value for p in self.iterPaintSubTables(colr)] + + 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.iterPaintSubTables(colr) + ): + paint = path[-1].value + callback(paint) + + def getTransform(self) -> Transform: + if self.Format == PaintFormat.PaintTransform: + t = self.Transform + return Transform(t.xx, t.yx, t.xy, t.yy, t.dx, t.dy) + elif self.Format == PaintFormat.PaintTranslate: + return Identity.translate(self.dx, self.dy) + elif self.Format == PaintFormat.PaintScale: + return Identity.scale(self.scaleX, self.scaleY) + elif self.Format == PaintFormat.PaintScaleAroundCenter: + return ( + Identity.translate(self.centerX, self.centerY) + .scale(self.scaleX, self.scaleY) + .translate(-self.centerX, -self.centerY) + ) + elif self.Format == PaintFormat.PaintScaleUniform: + return Identity.scale(self.scale) + elif self.Format == PaintFormat.PaintScaleUniformAroundCenter: + return ( + Identity.translate(self.centerX, self.centerY) + .scale(self.scale) + .translate(-self.centerX, -self.centerY) + ) + elif self.Format == PaintFormat.PaintRotate: + return Identity.rotate(radians(self.angle)) + elif self.Format == PaintFormat.PaintRotateAroundCenter: + return ( + Identity.translate(self.centerX, self.centerY) + .rotate(radians(self.angle)) + .translate(-self.centerX, -self.centerY) + ) + elif self.Format == PaintFormat.PaintSkew: + return Identity.skew(radians(-self.xSkewAngle), radians(self.ySkewAngle)) + elif self.Format == PaintFormat.PaintSkewAroundCenter: + return ( + Identity.translate(self.centerX, self.centerY) + .skew(radians(-self.xSkewAngle), radians(self.ySkewAngle)) + .translate(-self.centerX, -self.centerY) + ) + if PaintFormat(self.Format).is_variable(): + raise NotImplementedError(f"Variable Paints not supported: {self.Format}") + + return Identity + + def computeClipBox( + self, colr: COLR, glyphSet: "_TTGlyphSet", quantization: int = 1 + ) -> Optional[ClipBox]: + pen = ControlBoundsPen(glyphSet) + for path in dfs_base_table( + self, iter_subtables_fn=lambda paint: paint.iterPaintSubTables(colr) + ): + paint = path[-1].value + if paint.Format == PaintFormat.PaintGlyph: + transformation = reduce( + Transform.transform, + (st.value.getTransform() for st in path), + Identity, + ) + glyphSet[paint.Glyph].draw(TransformPen(pen, transformation)) + + if pen.bounds is None: + return None + + cb = ClipBox() + cb.Format = int(ClipBoxFormat.Static) + cb.xMin, cb.yMin, cb.xMax, cb.yMax = quantizeRect(pen.bounds, quantization) + return cb + + +# For each subtable format there is a class. However, we don't really distinguish +# between "field name" and "format name": often these are the same. Yet there's +# a whole bunch of fields with different names. The following dict is a mapping +# from "format name" to "field name". _buildClasses() uses this to create a +# subclass for each alternate field name. +# +_equivalents = { + "MarkArray": ("Mark1Array",), + "LangSys": ("DefaultLangSys",), + "Coverage": ( + "MarkCoverage", + "BaseCoverage", + "LigatureCoverage", + "Mark1Coverage", + "Mark2Coverage", + "BacktrackCoverage", + "InputCoverage", + "LookAheadCoverage", + "VertGlyphCoverage", + "HorizGlyphCoverage", + "TopAccentCoverage", + "ExtendedShapeCoverage", + "MathKernCoverage", + ), + "ClassDef": ( + "ClassDef1", + "ClassDef2", + "BacktrackClassDef", + "InputClassDef", + "LookAheadClassDef", + "GlyphClassDef", + "MarkAttachClassDef", + ), + "Anchor": ( + "EntryAnchor", + "ExitAnchor", + "BaseAnchor", + "LigatureAnchor", + "Mark2Anchor", + "MarkAnchor", + ), + "Device": ( + "XPlaDevice", + "YPlaDevice", + "XAdvDevice", + "YAdvDevice", + "XDeviceTable", + "YDeviceTable", + "DeviceTable", + ), + "Axis": ( + "HorizAxis", + "VertAxis", + ), + "MinMax": ("DefaultMinMax",), + "BaseCoord": ( + "MinCoord", + "MaxCoord", + ), + "JstfLangSys": ("DefJstfLangSys",), + "JstfGSUBModList": ( + "ShrinkageEnableGSUB", + "ShrinkageDisableGSUB", + "ExtensionEnableGSUB", + "ExtensionDisableGSUB", + ), + "JstfGPOSModList": ( + "ShrinkageEnableGPOS", + "ShrinkageDisableGPOS", + "ExtensionEnableGPOS", + "ExtensionDisableGPOS", + ), + "JstfMax": ( + "ShrinkageJstfMax", + "ExtensionJstfMax", + ), + "MathKern": ( + "TopRightMathKern", + "TopLeftMathKern", + "BottomRightMathKern", + "BottomLeftMathKern", + ), + "MathGlyphConstruction": ("VertGlyphConstruction", "HorizGlyphConstruction"), +} + +# +# OverFlow logic, to automatically create ExtensionLookups +# XXX This should probably move to otBase.py +# + + +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 + Lookup[0] and contents + SubTable offset list + SubTable[0] and contents + ... + SubTable[n] and contents + ... + Lookup[n] and contents + SubTable offset list + SubTable[0] and contents + ... + SubTable[n] and contents + + If the offset to a lookup overflowed (SubTableIndex is None) + we must promote the *previous* lookup to an Extension type. + + If the offset from a lookup to subtable overflowed, then we must promote it + to an Extension Lookup type. + """ + ok = 0 + lookupIndex = overflowRecord.LookupListIndex + if overflowRecord.SubTableIndex is None: + lookupIndex = lookupIndex - 1 + if lookupIndex < 0: + return ok + if overflowRecord.tableType == "GSUB": + extType = 7 + elif overflowRecord.tableType == "GPOS": + extType = 9 + + lookups = ttf[overflowRecord.tableType].table.LookupList.Lookup + lookup = lookups[lookupIndex] + # If the previous lookup is an extType, look further back. Very unlikely, but possible. + while lookup.SubTable[0].__class__.LookupType == extType: + lookupIndex = lookupIndex - 1 + if lookupIndex < 0: + return ok + lookup = lookups[lookupIndex] + + for lookupIndex in range(lookupIndex, len(lookups)): + lookup = lookups[lookupIndex] + if lookup.LookupType != extType: + lookup.LookupType = extType + for si, subTable in enumerate(lookup.SubTable): + extSubTableClass = lookupTypes[overflowRecord.tableType][extType] + extSubTable = extSubTableClass() + extSubTable.Format = 1 + extSubTable.ExtSubTable = subTable + lookup.SubTable[si] = extSubTable + ok = 1 + return ok + + +def splitMultipleSubst(oldSubTable, newSubTable, overflowRecord): + ok = 1 + oldMapping = sorted(oldSubTable.mapping.items()) + oldLen = len(oldMapping) + + if overflowRecord.itemName in ["Coverage", "RangeRecord"]: + # Coverage table is written last. Overflow is to or within the + # the coverage table. We will just cut the subtable in half. + newLen = oldLen // 2 + + elif overflowRecord.itemName == "Sequence": + # We just need to back up by two items from the overflowed + # Sequence index to make sure the offset to the Coverage table + # doesn't overflow. + newLen = overflowRecord.itemIndex - 1 + + newSubTable.mapping = {} + for i in range(newLen, oldLen): + item = oldMapping[i] + key = item[0] + newSubTable.mapping[key] = item[1] + del oldSubTable.mapping[key] + + return ok + + +def splitAlternateSubst(oldSubTable, newSubTable, overflowRecord): + ok = 1 + if hasattr(oldSubTable, "sortCoverageLast"): + newSubTable.sortCoverageLast = oldSubTable.sortCoverageLast + + oldAlts = sorted(oldSubTable.alternates.items()) + oldLen = len(oldAlts) + + if overflowRecord.itemName in ["Coverage", "RangeRecord"]: + # Coverage table is written last. overflow is to or within the + # the coverage table. We will just cut the subtable in half. + newLen = oldLen // 2 + + elif overflowRecord.itemName == "AlternateSet": + # We just need to back up by two items + # from the overflowed AlternateSet index to make sure the offset + # to the Coverage table doesn't overflow. + newLen = overflowRecord.itemIndex - 1 + + newSubTable.alternates = {} + for i in range(newLen, oldLen): + item = oldAlts[i] + key = item[0] + newSubTable.alternates[key] = item[1] + del oldSubTable.alternates[key] + + return ok + + +def splitLigatureSubst(oldSubTable, newSubTable, overflowRecord): + ok = 1 + oldLigs = sorted(oldSubTable.ligatures.items()) + oldLen = len(oldLigs) + + if overflowRecord.itemName in ["Coverage", "RangeRecord"]: + # Coverage table is written last. overflow is to or within the + # the coverage table. We will just cut the subtable in half. + newLen = oldLen // 2 + + elif overflowRecord.itemName == "LigatureSet": + # We just need to back up by two items + # from the overflowed AlternateSet index to make sure the offset + # to the Coverage table doesn't overflow. + newLen = overflowRecord.itemIndex - 1 + + newSubTable.ligatures = {} + for i in range(newLen, oldLen): + item = oldLigs[i] + key = item[0] + newSubTable.ligatures[key] = item[1] + del oldSubTable.ligatures[key] + + return ok + + +def splitPairPos(oldSubTable, newSubTable, overflowRecord): + st = oldSubTable + ok = False + newSubTable.Format = oldSubTable.Format + if oldSubTable.Format == 1 and len(oldSubTable.PairSet) > 1: + for name in "ValueFormat1", "ValueFormat2": + setattr(newSubTable, name, getattr(oldSubTable, name)) + + # Move top half of coverage to new subtable + + newSubTable.Coverage = oldSubTable.Coverage.__class__() + + coverage = oldSubTable.Coverage.glyphs + records = oldSubTable.PairSet + + oldCount = len(oldSubTable.PairSet) // 2 + + oldSubTable.Coverage.glyphs = coverage[:oldCount] + oldSubTable.PairSet = records[:oldCount] + + newSubTable.Coverage.glyphs = coverage[oldCount:] + newSubTable.PairSet = records[oldCount:] + + oldSubTable.PairSetCount = len(oldSubTable.PairSet) + newSubTable.PairSetCount = len(newSubTable.PairSet) + + ok = True + + elif oldSubTable.Format == 2 and len(oldSubTable.Class1Record) > 1: + if not hasattr(oldSubTable, "Class2Count"): + oldSubTable.Class2Count = len(oldSubTable.Class1Record[0].Class2Record) + for name in "Class2Count", "ClassDef2", "ValueFormat1", "ValueFormat2": + setattr(newSubTable, name, getattr(oldSubTable, name)) + + # The two subtables will still have the same ClassDef2 and the table + # sharing will still cause the sharing to overflow. As such, disable + # sharing on the one that is serialized second (that's oldSubTable). + oldSubTable.DontShare = True + + # Move top half of class numbers to new subtable + + newSubTable.Coverage = oldSubTable.Coverage.__class__() + newSubTable.ClassDef1 = oldSubTable.ClassDef1.__class__() + + coverage = oldSubTable.Coverage.glyphs + classDefs = oldSubTable.ClassDef1.classDefs + records = oldSubTable.Class1Record + + oldCount = len(oldSubTable.Class1Record) // 2 + newGlyphs = set(k for k, v in classDefs.items() if v >= oldCount) + + oldSubTable.Coverage.glyphs = [g for g in coverage if g not in newGlyphs] + oldSubTable.ClassDef1.classDefs = { + k: v for k, v in classDefs.items() if v < oldCount + } + oldSubTable.Class1Record = records[:oldCount] + + newSubTable.Coverage.glyphs = [g for g in coverage if g in newGlyphs] + newSubTable.ClassDef1.classDefs = { + k: (v - oldCount) for k, v in classDefs.items() if v > oldCount + } + newSubTable.Class1Record = records[oldCount:] + + oldSubTable.Class1Count = len(oldSubTable.Class1Record) + newSubTable.Class1Count = len(newSubTable.Class1Record) + + ok = True + + return ok + + +def splitMarkBasePos(oldSubTable, newSubTable, overflowRecord): + # split half of the mark classes to the new subtable + classCount = oldSubTable.ClassCount + if classCount < 2: + # oh well, not much left to split... + return False + + oldClassCount = classCount // 2 + newClassCount = classCount - oldClassCount + + oldMarkCoverage, oldMarkRecords = [], [] + newMarkCoverage, newMarkRecords = [], [] + for glyphName, markRecord in zip( + oldSubTable.MarkCoverage.glyphs, oldSubTable.MarkArray.MarkRecord + ): + if markRecord.Class < oldClassCount: + oldMarkCoverage.append(glyphName) + oldMarkRecords.append(markRecord) + else: + markRecord.Class -= oldClassCount + newMarkCoverage.append(glyphName) + newMarkRecords.append(markRecord) + + oldBaseRecords, newBaseRecords = [], [] + for rec in oldSubTable.BaseArray.BaseRecord: + oldBaseRecord, newBaseRecord = rec.__class__(), rec.__class__() + oldBaseRecord.BaseAnchor = rec.BaseAnchor[:oldClassCount] + newBaseRecord.BaseAnchor = rec.BaseAnchor[oldClassCount:] + oldBaseRecords.append(oldBaseRecord) + newBaseRecords.append(newBaseRecord) + + newSubTable.Format = oldSubTable.Format + + oldSubTable.MarkCoverage.glyphs = oldMarkCoverage + newSubTable.MarkCoverage = oldSubTable.MarkCoverage.__class__() + newSubTable.MarkCoverage.glyphs = newMarkCoverage + + # share the same BaseCoverage in both halves + newSubTable.BaseCoverage = oldSubTable.BaseCoverage + + oldSubTable.ClassCount = oldClassCount + newSubTable.ClassCount = newClassCount + + oldSubTable.MarkArray.MarkRecord = oldMarkRecords + newSubTable.MarkArray = oldSubTable.MarkArray.__class__() + newSubTable.MarkArray.MarkRecord = newMarkRecords + + oldSubTable.MarkArray.MarkCount = len(oldMarkRecords) + newSubTable.MarkArray.MarkCount = len(newMarkRecords) + + oldSubTable.BaseArray.BaseRecord = oldBaseRecords + newSubTable.BaseArray = oldSubTable.BaseArray.__class__() + newSubTable.BaseArray.BaseRecord = newBaseRecords + + oldSubTable.BaseArray.BaseCount = len(oldBaseRecords) + newSubTable.BaseArray.BaseCount = len(newBaseRecords) + + return True + + +splitTable = { + "GSUB": { + # 1: splitSingleSubst, + 2: splitMultipleSubst, + 3: splitAlternateSubst, + 4: splitLigatureSubst, + # 5: splitContextSubst, + # 6: splitChainContextSubst, + # 7: splitExtensionSubst, + # 8: splitReverseChainSingleSubst, + }, + "GPOS": { + # 1: splitSinglePos, + 2: splitPairPos, + # 3: splitCursivePos, + 4: splitMarkBasePos, + # 5: splitMarkLigPos, + # 6: splitMarkMarkPos, + # 7: splitContextPos, + # 8: splitChainContextPos, + # 9: splitExtensionPos, + }, +} + + +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.SubTableIndex + subtable = lookup.SubTable[subIndex] + + # First, try not sharing anything for this subtable... + if not hasattr(subtable, "DontShare"): + subtable.DontShare = True + return True + + if hasattr(subtable, "ExtSubTable"): + # We split the subtable of the Extension table, and add a new Extension table + # to contain the new subtable. + + subTableType = subtable.ExtSubTable.__class__.LookupType + extSubTable = subtable + subtable = extSubTable.ExtSubTable + newExtSubTableClass = lookupTypes[overflowRecord.tableType][ + extSubTable.__class__.LookupType + ] + newExtSubTable = newExtSubTableClass() + newExtSubTable.Format = extSubTable.Format + toInsert = newExtSubTable + + newSubTableClass = lookupTypes[overflowRecord.tableType][subTableType] + newSubTable = newSubTableClass() + newExtSubTable.ExtSubTable = newSubTable + else: + subTableType = subtable.__class__.LookupType + newSubTableClass = lookupTypes[overflowRecord.tableType][subTableType] + newSubTable = newSubTableClass() + toInsert = newSubTable + + if hasattr(lookup, "SubTableCount"): # may not be defined yet. + lookup.SubTableCount = lookup.SubTableCount + 1 + + try: + splitFunc = splitTable[overflowRecord.tableType][subTableType] + except KeyError: + log.error( + "Don't know how to split %s lookup type %s", + overflowRecord.tableType, + subTableType, + ) + return False + + ok = splitFunc(subtable, newSubTable, overflowRecord) + if ok: + lookup.SubTable.insert(subIndex + 1, toInsert) + return ok + + +# End of OverFlow logic + + +def _buildClasses(): + import re + from .otData import otData + + formatPat = re.compile(r"([A-Za-z0-9]+)Format(\d+)$") + namespace = globals() + + # populate module with classes + for name, table in otData: + baseClass = BaseTable + m = formatPat.match(name) + if m: + # XxxFormatN subtable, we only add the "base" table + name = m.group(1) + # the first row of a format-switching otData table describes the Format; + # the first column defines the type of the Format field. + # Currently this can be either 'uint16' or 'uint8'. + formatType = table[0][0] + baseClass = getFormatSwitchingBaseTableClass(formatType) + if name not in namespace: + # the class doesn't exist yet, so the base implementation is used. + cls = type(name, (baseClass,), {}) + if name in ("GSUB", "GPOS"): + cls.DontShare = True + namespace[name] = cls + + # link Var{Table} <-> {Table} (e.g. ColorStop <-> VarColorStop, etc.) + for name, _ in otData: + if name.startswith("Var") and len(name) > 3 and name[3:] in namespace: + varType = namespace[name] + noVarType = namespace[name[3:]] + varType.NoVarType = noVarType + noVarType.VarType = varType + + for base, alts in _equivalents.items(): + base = namespace[base] + for alt in alts: + namespace[alt] = base + + global lookupTypes + lookupTypes = { + "GSUB": { + 1: SingleSubst, + 2: MultipleSubst, + 3: AlternateSubst, + 4: LigatureSubst, + 5: ContextSubst, + 6: ChainContextSubst, + 7: ExtensionSubst, + 8: ReverseChainSingleSubst, + }, + "GPOS": { + 1: SinglePos, + 2: PairPos, + 3: CursivePos, + 4: MarkBasePos, + 5: MarkLigPos, + 6: MarkMarkPos, + 7: ContextPos, + 8: ChainContextPos, + 9: ExtensionPos, + }, + "mort": { + 4: NoncontextualMorph, + }, + "morx": { + 0: RearrangementMorph, + 1: ContextualMorph, + 2: LigatureMorph, + # 3: Reserved, + 4: NoncontextualMorph, + 5: InsertionMorph, + }, + } + lookupTypes["JSTF"] = lookupTypes["GPOS"] # JSTF contains GPOS + for lookupEnum in lookupTypes.values(): + for enum, cls in lookupEnum.items(): + cls.LookupType = enum + + global featureParamTypes + featureParamTypes = { + "size": FeatureParamsSize, + } + for i in range(1, 20 + 1): + featureParamTypes["ss%02d" % i] = FeatureParamsStylisticSet + for i in range(1, 99 + 1): + featureParamTypes["cv%02d" % i] = FeatureParamsCharacterVariants + + # add converters to classes + from .otConverters import buildConverters + + for name, table in otData: + m = formatPat.match(name) + if m: + # XxxFormatN subtable, add converter to "base" table + name, format = m.groups() + format = int(format) + cls = namespace[name] + if not hasattr(cls, "converters"): + cls.converters = {} + cls.convertersByName = {} + converters, convertersByName = buildConverters(table[1:], namespace) + cls.converters[format] = converters + cls.convertersByName[format] = convertersByName + # XXX Add staticSize? + else: + cls = namespace[name] + cls.converters, cls.convertersByName = buildConverters(table, namespace) + # XXX Add staticSize? + + +_buildClasses() + + +def _getGlyphsFromCoverageTable(coverage): + if coverage is None: + # empty coverage table + return [] + else: + return coverage.glyphs