Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/__init__.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/__main__.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/macUtils.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/removeOverlaps.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/reorderGlyphs.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/scaleUpem.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/sfnt.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/standardGlyphOrder.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttCollection.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttFont.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttGlyphSet.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttVisitor.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/woff2.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/BitmapGlyphMetrics.py +64 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_F_F_.py +61 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_F_F__2.py +26 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_O_L_R_.py +165 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_P_A_L_.py +305 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/D__e_b_g.py +35 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/DefaultTable.py +63 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G_D_E_F_.py +13 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G_V_A_R_.py +5 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G__l_o_c.py +85 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/H_V_A_R_.py +13 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/J_S_T_F_.py +13 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/L_T_S_H_.py +58 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/M_V_A_R_.py +13 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/O_S_2f_2.py +752 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/S_T_A_T_.py +15 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/S__i_l_l.py +92 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I_C_.py +14 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I_S_.py +13 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__0.py +70 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__1.py +163 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__2.py +17 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__3.py +22 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__5.py +60 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/V_A_R_C_.py +12 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/V_O_R_G_.py +165 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__init__.py +94 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/B_A_S_E_.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_F_F_.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_F_F__2.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_P_A_L_.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/E_B_D_T_.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/E_B_L_C_.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/F_F_T_M_.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/F__e_a_t.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/G__l_a_t.cpython-311.pyc +0 -0
- data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/H_V_A_R_.cpython-311.pyc +0 -0
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (1.71 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/__main__.cpython-311.pyc
ADDED
|
Binary file (5.86 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/macUtils.cpython-311.pyc
ADDED
|
Binary file (3.16 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/removeOverlaps.cpython-311.pyc
ADDED
|
Binary file (17.2 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/reorderGlyphs.cpython-311.pyc
ADDED
|
Binary file (14.9 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/scaleUpem.cpython-311.pyc
ADDED
|
Binary file (19.5 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/sfnt.cpython-311.pyc
ADDED
|
Binary file (31.8 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/standardGlyphOrder.cpython-311.pyc
ADDED
|
Binary file (2.37 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttCollection.cpython-311.pyc
ADDED
|
Binary file (6.51 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttFont.cpython-311.pyc
ADDED
|
Binary file (91.7 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttGlyphSet.cpython-311.pyc
ADDED
|
Binary file (27.6 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/ttVisitor.cpython-311.pyc
ADDED
|
Binary file (2.04 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/__pycache__/woff2.cpython-311.pyc
ADDED
|
Binary file (79.9 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/BitmapGlyphMetrics.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Since bitmap glyph metrics are shared between EBLC and EBDT
|
| 2 |
+
# this class gets its own python file.
|
| 3 |
+
from fontTools.misc import sstruct
|
| 4 |
+
from fontTools.misc.textTools import safeEval
|
| 5 |
+
import logging
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
log = logging.getLogger(__name__)
|
| 9 |
+
|
| 10 |
+
bigGlyphMetricsFormat = """
|
| 11 |
+
> # big endian
|
| 12 |
+
height: B
|
| 13 |
+
width: B
|
| 14 |
+
horiBearingX: b
|
| 15 |
+
horiBearingY: b
|
| 16 |
+
horiAdvance: B
|
| 17 |
+
vertBearingX: b
|
| 18 |
+
vertBearingY: b
|
| 19 |
+
vertAdvance: B
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
smallGlyphMetricsFormat = """
|
| 23 |
+
> # big endian
|
| 24 |
+
height: B
|
| 25 |
+
width: B
|
| 26 |
+
BearingX: b
|
| 27 |
+
BearingY: b
|
| 28 |
+
Advance: B
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class BitmapGlyphMetrics(object):
|
| 33 |
+
def toXML(self, writer, ttFont):
|
| 34 |
+
writer.begintag(self.__class__.__name__)
|
| 35 |
+
writer.newline()
|
| 36 |
+
for metricName in sstruct.getformat(self.__class__.binaryFormat)[1]:
|
| 37 |
+
writer.simpletag(metricName, value=getattr(self, metricName))
|
| 38 |
+
writer.newline()
|
| 39 |
+
writer.endtag(self.__class__.__name__)
|
| 40 |
+
writer.newline()
|
| 41 |
+
|
| 42 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 43 |
+
metricNames = set(sstruct.getformat(self.__class__.binaryFormat)[1])
|
| 44 |
+
for element in content:
|
| 45 |
+
if not isinstance(element, tuple):
|
| 46 |
+
continue
|
| 47 |
+
name, attrs, content = element
|
| 48 |
+
# Make sure this is a metric that is needed by GlyphMetrics.
|
| 49 |
+
if name in metricNames:
|
| 50 |
+
vars(self)[name] = safeEval(attrs["value"])
|
| 51 |
+
else:
|
| 52 |
+
log.warning(
|
| 53 |
+
"unknown name '%s' being ignored in %s.",
|
| 54 |
+
name,
|
| 55 |
+
self.__class__.__name__,
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class BigGlyphMetrics(BitmapGlyphMetrics):
|
| 60 |
+
binaryFormat = bigGlyphMetricsFormat
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
class SmallGlyphMetrics(BitmapGlyphMetrics):
|
| 64 |
+
binaryFormat = smallGlyphMetricsFormat
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_F_F_.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from io import BytesIO
|
| 2 |
+
from fontTools import cffLib
|
| 3 |
+
from . import DefaultTable
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class table_C_F_F_(DefaultTable.DefaultTable):
|
| 7 |
+
"""Compact Font Format table (version 1)
|
| 8 |
+
|
| 9 |
+
The ``CFF`` table embeds a CFF-formatted font. The CFF font format
|
| 10 |
+
predates OpenType and could be used as a standalone font file, but the
|
| 11 |
+
``CFF`` table is also used to package CFF fonts into an OpenType
|
| 12 |
+
container.
|
| 13 |
+
|
| 14 |
+
.. note::
|
| 15 |
+
``CFF`` has been succeeded by ``CFF2``, which eliminates much of
|
| 16 |
+
the redundancy incurred by embedding CFF version 1 in an OpenType
|
| 17 |
+
font.
|
| 18 |
+
|
| 19 |
+
See also https://learn.microsoft.com/en-us/typography/opentype/spec/cff
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
def __init__(self, tag=None):
|
| 23 |
+
DefaultTable.DefaultTable.__init__(self, tag)
|
| 24 |
+
self.cff = cffLib.CFFFontSet()
|
| 25 |
+
self._gaveGlyphOrder = False
|
| 26 |
+
|
| 27 |
+
def decompile(self, data, otFont):
|
| 28 |
+
self.cff.decompile(BytesIO(data), otFont, isCFF2=False)
|
| 29 |
+
assert len(self.cff) == 1, "can't deal with multi-font CFF tables."
|
| 30 |
+
|
| 31 |
+
def compile(self, otFont):
|
| 32 |
+
f = BytesIO()
|
| 33 |
+
self.cff.compile(f, otFont, isCFF2=False)
|
| 34 |
+
return f.getvalue()
|
| 35 |
+
|
| 36 |
+
def haveGlyphNames(self):
|
| 37 |
+
if hasattr(self.cff[self.cff.fontNames[0]], "ROS"):
|
| 38 |
+
return False # CID-keyed font
|
| 39 |
+
else:
|
| 40 |
+
return True
|
| 41 |
+
|
| 42 |
+
def getGlyphOrder(self):
|
| 43 |
+
if self._gaveGlyphOrder:
|
| 44 |
+
from fontTools import ttLib
|
| 45 |
+
|
| 46 |
+
raise ttLib.TTLibError("illegal use of getGlyphOrder()")
|
| 47 |
+
self._gaveGlyphOrder = True
|
| 48 |
+
return self.cff[self.cff.fontNames[0]].getGlyphOrder()
|
| 49 |
+
|
| 50 |
+
def setGlyphOrder(self, glyphOrder):
|
| 51 |
+
pass
|
| 52 |
+
# XXX
|
| 53 |
+
# self.cff[self.cff.fontNames[0]].setGlyphOrder(glyphOrder)
|
| 54 |
+
|
| 55 |
+
def toXML(self, writer, otFont):
|
| 56 |
+
self.cff.toXML(writer)
|
| 57 |
+
|
| 58 |
+
def fromXML(self, name, attrs, content, otFont):
|
| 59 |
+
if not hasattr(self, "cff"):
|
| 60 |
+
self.cff = cffLib.CFFFontSet()
|
| 61 |
+
self.cff.fromXML(name, attrs, content, otFont)
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_F_F__2.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from io import BytesIO
|
| 2 |
+
from fontTools.ttLib.tables.C_F_F_ import table_C_F_F_
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class table_C_F_F__2(table_C_F_F_):
|
| 6 |
+
"""Compact Font Format version 2 table
|
| 7 |
+
|
| 8 |
+
The ``CFF2`` table contains glyph data for a CFF2-flavored OpenType
|
| 9 |
+
font.
|
| 10 |
+
|
| 11 |
+
.. note::
|
| 12 |
+
``CFF2`` is the successor to ``CFF``, and eliminates much of
|
| 13 |
+
the redundancy incurred by embedding CFF version 1 in an OpenType
|
| 14 |
+
font.
|
| 15 |
+
|
| 16 |
+
See also https://learn.microsoft.com/en-us/typography/opentype/spec/cff2
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
def decompile(self, data, otFont):
|
| 20 |
+
self.cff.decompile(BytesIO(data), otFont, isCFF2=True)
|
| 21 |
+
assert len(self.cff) == 1, "can't deal with multi-font CFF tables."
|
| 22 |
+
|
| 23 |
+
def compile(self, otFont):
|
| 24 |
+
f = BytesIO()
|
| 25 |
+
self.cff.compile(f, otFont, isCFF2=True)
|
| 26 |
+
return f.getvalue()
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_O_L_R_.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2013 Google, Inc. All Rights Reserved.
|
| 2 |
+
#
|
| 3 |
+
# Google Author(s): Behdad Esfahbod
|
| 4 |
+
|
| 5 |
+
from fontTools.misc.textTools import safeEval
|
| 6 |
+
from . import DefaultTable
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class table_C_O_L_R_(DefaultTable.DefaultTable):
|
| 10 |
+
"""Color table
|
| 11 |
+
|
| 12 |
+
The ``COLR`` table defines color presentation of outline glyphs. It must
|
| 13 |
+
be used in concert with the ``CPAL`` table, which contains the color
|
| 14 |
+
descriptors used.
|
| 15 |
+
|
| 16 |
+
This table is structured so that you can treat it like a dictionary keyed by glyph name.
|
| 17 |
+
|
| 18 |
+
``ttFont['COLR'][<glyphName>]`` will return the color layers for any glyph.
|
| 19 |
+
|
| 20 |
+
``ttFont['COLR'][<glyphName>] = <value>`` will set the color layers for any glyph.
|
| 21 |
+
|
| 22 |
+
See also https://learn.microsoft.com/en-us/typography/opentype/spec/colr
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
@staticmethod
|
| 26 |
+
def _decompileColorLayersV0(table):
|
| 27 |
+
if not table.LayerRecordArray:
|
| 28 |
+
return {}
|
| 29 |
+
colorLayerLists = {}
|
| 30 |
+
layerRecords = table.LayerRecordArray.LayerRecord
|
| 31 |
+
numLayerRecords = len(layerRecords)
|
| 32 |
+
for baseRec in table.BaseGlyphRecordArray.BaseGlyphRecord:
|
| 33 |
+
baseGlyph = baseRec.BaseGlyph
|
| 34 |
+
firstLayerIndex = baseRec.FirstLayerIndex
|
| 35 |
+
numLayers = baseRec.NumLayers
|
| 36 |
+
assert firstLayerIndex + numLayers <= numLayerRecords
|
| 37 |
+
layers = []
|
| 38 |
+
for i in range(firstLayerIndex, firstLayerIndex + numLayers):
|
| 39 |
+
layerRec = layerRecords[i]
|
| 40 |
+
layers.append(LayerRecord(layerRec.LayerGlyph, layerRec.PaletteIndex))
|
| 41 |
+
colorLayerLists[baseGlyph] = layers
|
| 42 |
+
return colorLayerLists
|
| 43 |
+
|
| 44 |
+
def _toOTTable(self, ttFont):
|
| 45 |
+
from . import otTables
|
| 46 |
+
from fontTools.colorLib.builder import populateCOLRv0
|
| 47 |
+
|
| 48 |
+
tableClass = getattr(otTables, self.tableTag)
|
| 49 |
+
table = tableClass()
|
| 50 |
+
table.Version = self.version
|
| 51 |
+
|
| 52 |
+
populateCOLRv0(
|
| 53 |
+
table,
|
| 54 |
+
{
|
| 55 |
+
baseGlyph: [(layer.name, layer.colorID) for layer in layers]
|
| 56 |
+
for baseGlyph, layers in self.ColorLayers.items()
|
| 57 |
+
},
|
| 58 |
+
glyphMap=ttFont.getReverseGlyphMap(rebuild=True),
|
| 59 |
+
)
|
| 60 |
+
return table
|
| 61 |
+
|
| 62 |
+
def decompile(self, data, ttFont):
|
| 63 |
+
from .otBase import OTTableReader
|
| 64 |
+
from . import otTables
|
| 65 |
+
|
| 66 |
+
# We use otData to decompile, but we adapt the decompiled otTables to the
|
| 67 |
+
# existing COLR v0 API for backward compatibility.
|
| 68 |
+
reader = OTTableReader(data, tableTag=self.tableTag)
|
| 69 |
+
tableClass = getattr(otTables, self.tableTag)
|
| 70 |
+
table = tableClass()
|
| 71 |
+
table.decompile(reader, ttFont)
|
| 72 |
+
|
| 73 |
+
self.version = table.Version
|
| 74 |
+
if self.version == 0:
|
| 75 |
+
self.ColorLayers = self._decompileColorLayersV0(table)
|
| 76 |
+
else:
|
| 77 |
+
# for new versions, keep the raw otTables around
|
| 78 |
+
self.table = table
|
| 79 |
+
|
| 80 |
+
def compile(self, ttFont):
|
| 81 |
+
from .otBase import OTTableWriter
|
| 82 |
+
|
| 83 |
+
if hasattr(self, "table"):
|
| 84 |
+
table = self.table
|
| 85 |
+
else:
|
| 86 |
+
table = self._toOTTable(ttFont)
|
| 87 |
+
|
| 88 |
+
writer = OTTableWriter(tableTag=self.tableTag)
|
| 89 |
+
table.compile(writer, ttFont)
|
| 90 |
+
return writer.getAllData()
|
| 91 |
+
|
| 92 |
+
def toXML(self, writer, ttFont):
|
| 93 |
+
if hasattr(self, "table"):
|
| 94 |
+
self.table.toXML2(writer, ttFont)
|
| 95 |
+
else:
|
| 96 |
+
writer.simpletag("version", value=self.version)
|
| 97 |
+
writer.newline()
|
| 98 |
+
for baseGlyph in sorted(self.ColorLayers.keys(), key=ttFont.getGlyphID):
|
| 99 |
+
writer.begintag("ColorGlyph", name=baseGlyph)
|
| 100 |
+
writer.newline()
|
| 101 |
+
for layer in self.ColorLayers[baseGlyph]:
|
| 102 |
+
layer.toXML(writer, ttFont)
|
| 103 |
+
writer.endtag("ColorGlyph")
|
| 104 |
+
writer.newline()
|
| 105 |
+
|
| 106 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 107 |
+
if name == "version": # old COLR v0 API
|
| 108 |
+
setattr(self, name, safeEval(attrs["value"]))
|
| 109 |
+
elif name == "ColorGlyph":
|
| 110 |
+
if not hasattr(self, "ColorLayers"):
|
| 111 |
+
self.ColorLayers = {}
|
| 112 |
+
glyphName = attrs["name"]
|
| 113 |
+
for element in content:
|
| 114 |
+
if isinstance(element, str):
|
| 115 |
+
continue
|
| 116 |
+
layers = []
|
| 117 |
+
for element in content:
|
| 118 |
+
if isinstance(element, str):
|
| 119 |
+
continue
|
| 120 |
+
layer = LayerRecord()
|
| 121 |
+
layer.fromXML(element[0], element[1], element[2], ttFont)
|
| 122 |
+
layers.append(layer)
|
| 123 |
+
self.ColorLayers[glyphName] = layers
|
| 124 |
+
else: # new COLR v1 API
|
| 125 |
+
from . import otTables
|
| 126 |
+
|
| 127 |
+
if not hasattr(self, "table"):
|
| 128 |
+
tableClass = getattr(otTables, self.tableTag)
|
| 129 |
+
self.table = tableClass()
|
| 130 |
+
self.table.fromXML(name, attrs, content, ttFont)
|
| 131 |
+
self.table.populateDefaults()
|
| 132 |
+
self.version = self.table.Version
|
| 133 |
+
|
| 134 |
+
def __getitem__(self, glyphName):
|
| 135 |
+
if not isinstance(glyphName, str):
|
| 136 |
+
raise TypeError(f"expected str, found {type(glyphName).__name__}")
|
| 137 |
+
return self.ColorLayers[glyphName]
|
| 138 |
+
|
| 139 |
+
def __setitem__(self, glyphName, value):
|
| 140 |
+
if not isinstance(glyphName, str):
|
| 141 |
+
raise TypeError(f"expected str, found {type(glyphName).__name__}")
|
| 142 |
+
if value is not None:
|
| 143 |
+
self.ColorLayers[glyphName] = value
|
| 144 |
+
elif glyphName in self.ColorLayers:
|
| 145 |
+
del self.ColorLayers[glyphName]
|
| 146 |
+
|
| 147 |
+
def __delitem__(self, glyphName):
|
| 148 |
+
del self.ColorLayers[glyphName]
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
class LayerRecord(object):
|
| 152 |
+
def __init__(self, name=None, colorID=None):
|
| 153 |
+
self.name = name
|
| 154 |
+
self.colorID = colorID
|
| 155 |
+
|
| 156 |
+
def toXML(self, writer, ttFont):
|
| 157 |
+
writer.simpletag("layer", name=self.name, colorID=self.colorID)
|
| 158 |
+
writer.newline()
|
| 159 |
+
|
| 160 |
+
def fromXML(self, eltname, attrs, content, ttFont):
|
| 161 |
+
for name, value in attrs.items():
|
| 162 |
+
if name == "name":
|
| 163 |
+
setattr(self, name, value)
|
| 164 |
+
else:
|
| 165 |
+
setattr(self, name, safeEval(value))
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/C_P_A_L_.py
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2013 Google, Inc. All Rights Reserved.
|
| 2 |
+
#
|
| 3 |
+
# Google Author(s): Behdad Esfahbod
|
| 4 |
+
|
| 5 |
+
from fontTools.misc.textTools import bytesjoin, safeEval
|
| 6 |
+
from . import DefaultTable
|
| 7 |
+
import array
|
| 8 |
+
from collections import namedtuple
|
| 9 |
+
import struct
|
| 10 |
+
import sys
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class table_C_P_A_L_(DefaultTable.DefaultTable):
|
| 14 |
+
"""Color Palette table
|
| 15 |
+
|
| 16 |
+
The ``CPAL`` table contains a set of one or more color palettes. The color
|
| 17 |
+
records in each palette can be referenced by the ``COLR`` table to specify
|
| 18 |
+
the colors used in a color glyph.
|
| 19 |
+
|
| 20 |
+
See also https://learn.microsoft.com/en-us/typography/opentype/spec/cpal
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
NO_NAME_ID = 0xFFFF
|
| 24 |
+
DEFAULT_PALETTE_TYPE = 0
|
| 25 |
+
|
| 26 |
+
def __init__(self, tag=None):
|
| 27 |
+
DefaultTable.DefaultTable.__init__(self, tag)
|
| 28 |
+
self.palettes = []
|
| 29 |
+
self.paletteTypes = []
|
| 30 |
+
self.paletteLabels = []
|
| 31 |
+
self.paletteEntryLabels = []
|
| 32 |
+
|
| 33 |
+
def decompile(self, data, ttFont):
|
| 34 |
+
(
|
| 35 |
+
self.version,
|
| 36 |
+
self.numPaletteEntries,
|
| 37 |
+
numPalettes,
|
| 38 |
+
numColorRecords,
|
| 39 |
+
goffsetFirstColorRecord,
|
| 40 |
+
) = struct.unpack(">HHHHL", data[:12])
|
| 41 |
+
assert (
|
| 42 |
+
self.version <= 1
|
| 43 |
+
), "Version of CPAL table is higher than I know how to handle"
|
| 44 |
+
self.palettes = []
|
| 45 |
+
pos = 12
|
| 46 |
+
for i in range(numPalettes):
|
| 47 |
+
startIndex = struct.unpack(">H", data[pos : pos + 2])[0]
|
| 48 |
+
assert startIndex + self.numPaletteEntries <= numColorRecords
|
| 49 |
+
pos += 2
|
| 50 |
+
palette = []
|
| 51 |
+
ppos = goffsetFirstColorRecord + startIndex * 4
|
| 52 |
+
for j in range(self.numPaletteEntries):
|
| 53 |
+
palette.append(Color(*struct.unpack(">BBBB", data[ppos : ppos + 4])))
|
| 54 |
+
ppos += 4
|
| 55 |
+
self.palettes.append(palette)
|
| 56 |
+
if self.version == 0:
|
| 57 |
+
offsetToPaletteTypeArray = 0
|
| 58 |
+
offsetToPaletteLabelArray = 0
|
| 59 |
+
offsetToPaletteEntryLabelArray = 0
|
| 60 |
+
else:
|
| 61 |
+
pos = 12 + numPalettes * 2
|
| 62 |
+
(
|
| 63 |
+
offsetToPaletteTypeArray,
|
| 64 |
+
offsetToPaletteLabelArray,
|
| 65 |
+
offsetToPaletteEntryLabelArray,
|
| 66 |
+
) = struct.unpack(">LLL", data[pos : pos + 12])
|
| 67 |
+
self.paletteTypes = self._decompileUInt32Array(
|
| 68 |
+
data,
|
| 69 |
+
offsetToPaletteTypeArray,
|
| 70 |
+
numPalettes,
|
| 71 |
+
default=self.DEFAULT_PALETTE_TYPE,
|
| 72 |
+
)
|
| 73 |
+
self.paletteLabels = self._decompileUInt16Array(
|
| 74 |
+
data, offsetToPaletteLabelArray, numPalettes, default=self.NO_NAME_ID
|
| 75 |
+
)
|
| 76 |
+
self.paletteEntryLabels = self._decompileUInt16Array(
|
| 77 |
+
data,
|
| 78 |
+
offsetToPaletteEntryLabelArray,
|
| 79 |
+
self.numPaletteEntries,
|
| 80 |
+
default=self.NO_NAME_ID,
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
def _decompileUInt16Array(self, data, offset, numElements, default=0):
|
| 84 |
+
if offset == 0:
|
| 85 |
+
return [default] * numElements
|
| 86 |
+
result = array.array("H", data[offset : offset + 2 * numElements])
|
| 87 |
+
if sys.byteorder != "big":
|
| 88 |
+
result.byteswap()
|
| 89 |
+
assert len(result) == numElements, result
|
| 90 |
+
return result.tolist()
|
| 91 |
+
|
| 92 |
+
def _decompileUInt32Array(self, data, offset, numElements, default=0):
|
| 93 |
+
if offset == 0:
|
| 94 |
+
return [default] * numElements
|
| 95 |
+
result = array.array("I", data[offset : offset + 4 * numElements])
|
| 96 |
+
if sys.byteorder != "big":
|
| 97 |
+
result.byteswap()
|
| 98 |
+
assert len(result) == numElements, result
|
| 99 |
+
return result.tolist()
|
| 100 |
+
|
| 101 |
+
def compile(self, ttFont):
|
| 102 |
+
colorRecordIndices, colorRecords = self._compileColorRecords()
|
| 103 |
+
paletteTypes = self._compilePaletteTypes()
|
| 104 |
+
paletteLabels = self._compilePaletteLabels()
|
| 105 |
+
paletteEntryLabels = self._compilePaletteEntryLabels()
|
| 106 |
+
numColorRecords = len(colorRecords) // 4
|
| 107 |
+
offsetToFirstColorRecord = 12 + len(colorRecordIndices)
|
| 108 |
+
if self.version >= 1:
|
| 109 |
+
offsetToFirstColorRecord += 12
|
| 110 |
+
header = struct.pack(
|
| 111 |
+
">HHHHL",
|
| 112 |
+
self.version,
|
| 113 |
+
self.numPaletteEntries,
|
| 114 |
+
len(self.palettes),
|
| 115 |
+
numColorRecords,
|
| 116 |
+
offsetToFirstColorRecord,
|
| 117 |
+
)
|
| 118 |
+
if self.version == 0:
|
| 119 |
+
dataList = [header, colorRecordIndices, colorRecords]
|
| 120 |
+
else:
|
| 121 |
+
pos = offsetToFirstColorRecord + len(colorRecords)
|
| 122 |
+
if len(paletteTypes) == 0:
|
| 123 |
+
offsetToPaletteTypeArray = 0
|
| 124 |
+
else:
|
| 125 |
+
offsetToPaletteTypeArray = pos
|
| 126 |
+
pos += len(paletteTypes)
|
| 127 |
+
if len(paletteLabels) == 0:
|
| 128 |
+
offsetToPaletteLabelArray = 0
|
| 129 |
+
else:
|
| 130 |
+
offsetToPaletteLabelArray = pos
|
| 131 |
+
pos += len(paletteLabels)
|
| 132 |
+
if len(paletteEntryLabels) == 0:
|
| 133 |
+
offsetToPaletteEntryLabelArray = 0
|
| 134 |
+
else:
|
| 135 |
+
offsetToPaletteEntryLabelArray = pos
|
| 136 |
+
pos += len(paletteLabels)
|
| 137 |
+
header1 = struct.pack(
|
| 138 |
+
">LLL",
|
| 139 |
+
offsetToPaletteTypeArray,
|
| 140 |
+
offsetToPaletteLabelArray,
|
| 141 |
+
offsetToPaletteEntryLabelArray,
|
| 142 |
+
)
|
| 143 |
+
dataList = [
|
| 144 |
+
header,
|
| 145 |
+
colorRecordIndices,
|
| 146 |
+
header1,
|
| 147 |
+
colorRecords,
|
| 148 |
+
paletteTypes,
|
| 149 |
+
paletteLabels,
|
| 150 |
+
paletteEntryLabels,
|
| 151 |
+
]
|
| 152 |
+
return bytesjoin(dataList)
|
| 153 |
+
|
| 154 |
+
def _compilePalette(self, palette):
|
| 155 |
+
assert len(palette) == self.numPaletteEntries
|
| 156 |
+
pack = lambda c: struct.pack(">BBBB", c.blue, c.green, c.red, c.alpha)
|
| 157 |
+
return bytesjoin([pack(color) for color in palette])
|
| 158 |
+
|
| 159 |
+
def _compileColorRecords(self):
|
| 160 |
+
colorRecords, colorRecordIndices, pool = [], [], {}
|
| 161 |
+
for palette in self.palettes:
|
| 162 |
+
packedPalette = self._compilePalette(palette)
|
| 163 |
+
if packedPalette in pool:
|
| 164 |
+
index = pool[packedPalette]
|
| 165 |
+
else:
|
| 166 |
+
index = len(colorRecords)
|
| 167 |
+
colorRecords.append(packedPalette)
|
| 168 |
+
pool[packedPalette] = index
|
| 169 |
+
colorRecordIndices.append(struct.pack(">H", index * self.numPaletteEntries))
|
| 170 |
+
return bytesjoin(colorRecordIndices), bytesjoin(colorRecords)
|
| 171 |
+
|
| 172 |
+
def _compilePaletteTypes(self):
|
| 173 |
+
if self.version == 0 or not any(self.paletteTypes):
|
| 174 |
+
return b""
|
| 175 |
+
assert len(self.paletteTypes) == len(self.palettes)
|
| 176 |
+
result = bytesjoin([struct.pack(">I", ptype) for ptype in self.paletteTypes])
|
| 177 |
+
assert len(result) == 4 * len(self.palettes)
|
| 178 |
+
return result
|
| 179 |
+
|
| 180 |
+
def _compilePaletteLabels(self):
|
| 181 |
+
if self.version == 0 or all(l == self.NO_NAME_ID for l in self.paletteLabels):
|
| 182 |
+
return b""
|
| 183 |
+
assert len(self.paletteLabels) == len(self.palettes)
|
| 184 |
+
result = bytesjoin([struct.pack(">H", label) for label in self.paletteLabels])
|
| 185 |
+
assert len(result) == 2 * len(self.palettes)
|
| 186 |
+
return result
|
| 187 |
+
|
| 188 |
+
def _compilePaletteEntryLabels(self):
|
| 189 |
+
if self.version == 0 or all(
|
| 190 |
+
l == self.NO_NAME_ID for l in self.paletteEntryLabels
|
| 191 |
+
):
|
| 192 |
+
return b""
|
| 193 |
+
assert len(self.paletteEntryLabels) == self.numPaletteEntries
|
| 194 |
+
result = bytesjoin(
|
| 195 |
+
[struct.pack(">H", label) for label in self.paletteEntryLabels]
|
| 196 |
+
)
|
| 197 |
+
assert len(result) == 2 * self.numPaletteEntries
|
| 198 |
+
return result
|
| 199 |
+
|
| 200 |
+
def toXML(self, writer, ttFont):
|
| 201 |
+
numPalettes = len(self.palettes)
|
| 202 |
+
paletteLabels = {i: nameID for (i, nameID) in enumerate(self.paletteLabels)}
|
| 203 |
+
paletteTypes = {i: typ for (i, typ) in enumerate(self.paletteTypes)}
|
| 204 |
+
writer.simpletag("version", value=self.version)
|
| 205 |
+
writer.newline()
|
| 206 |
+
writer.simpletag("numPaletteEntries", value=self.numPaletteEntries)
|
| 207 |
+
writer.newline()
|
| 208 |
+
for index, palette in enumerate(self.palettes):
|
| 209 |
+
attrs = {"index": index}
|
| 210 |
+
paletteType = paletteTypes.get(index, self.DEFAULT_PALETTE_TYPE)
|
| 211 |
+
paletteLabel = paletteLabels.get(index, self.NO_NAME_ID)
|
| 212 |
+
if self.version > 0 and paletteLabel != self.NO_NAME_ID:
|
| 213 |
+
attrs["label"] = paletteLabel
|
| 214 |
+
if self.version > 0 and paletteType != self.DEFAULT_PALETTE_TYPE:
|
| 215 |
+
attrs["type"] = paletteType
|
| 216 |
+
writer.begintag("palette", **attrs)
|
| 217 |
+
writer.newline()
|
| 218 |
+
if (
|
| 219 |
+
self.version > 0
|
| 220 |
+
and paletteLabel != self.NO_NAME_ID
|
| 221 |
+
and ttFont
|
| 222 |
+
and "name" in ttFont
|
| 223 |
+
):
|
| 224 |
+
name = ttFont["name"].getDebugName(paletteLabel)
|
| 225 |
+
if name is not None:
|
| 226 |
+
writer.comment(name)
|
| 227 |
+
writer.newline()
|
| 228 |
+
assert len(palette) == self.numPaletteEntries
|
| 229 |
+
for cindex, color in enumerate(palette):
|
| 230 |
+
color.toXML(writer, ttFont, cindex)
|
| 231 |
+
writer.endtag("palette")
|
| 232 |
+
writer.newline()
|
| 233 |
+
if self.version > 0 and not all(
|
| 234 |
+
l == self.NO_NAME_ID for l in self.paletteEntryLabels
|
| 235 |
+
):
|
| 236 |
+
writer.begintag("paletteEntryLabels")
|
| 237 |
+
writer.newline()
|
| 238 |
+
for index, label in enumerate(self.paletteEntryLabels):
|
| 239 |
+
if label != self.NO_NAME_ID:
|
| 240 |
+
writer.simpletag("label", index=index, value=label)
|
| 241 |
+
if self.version > 0 and label and ttFont and "name" in ttFont:
|
| 242 |
+
name = ttFont["name"].getDebugName(label)
|
| 243 |
+
if name is not None:
|
| 244 |
+
writer.comment(name)
|
| 245 |
+
writer.newline()
|
| 246 |
+
writer.endtag("paletteEntryLabels")
|
| 247 |
+
writer.newline()
|
| 248 |
+
|
| 249 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 250 |
+
if name == "palette":
|
| 251 |
+
self.paletteLabels.append(int(attrs.get("label", self.NO_NAME_ID)))
|
| 252 |
+
self.paletteTypes.append(int(attrs.get("type", self.DEFAULT_PALETTE_TYPE)))
|
| 253 |
+
palette = []
|
| 254 |
+
for element in content:
|
| 255 |
+
if isinstance(element, str):
|
| 256 |
+
continue
|
| 257 |
+
attrs = element[1]
|
| 258 |
+
color = Color.fromHex(attrs["value"])
|
| 259 |
+
palette.append(color)
|
| 260 |
+
self.palettes.append(palette)
|
| 261 |
+
elif name == "paletteEntryLabels":
|
| 262 |
+
colorLabels = {}
|
| 263 |
+
for element in content:
|
| 264 |
+
if isinstance(element, str):
|
| 265 |
+
continue
|
| 266 |
+
elementName, elementAttr, _ = element
|
| 267 |
+
if elementName == "label":
|
| 268 |
+
labelIndex = safeEval(elementAttr["index"])
|
| 269 |
+
nameID = safeEval(elementAttr["value"])
|
| 270 |
+
colorLabels[labelIndex] = nameID
|
| 271 |
+
self.paletteEntryLabels = [
|
| 272 |
+
colorLabels.get(i, self.NO_NAME_ID)
|
| 273 |
+
for i in range(self.numPaletteEntries)
|
| 274 |
+
]
|
| 275 |
+
elif "value" in attrs:
|
| 276 |
+
value = safeEval(attrs["value"])
|
| 277 |
+
setattr(self, name, value)
|
| 278 |
+
if name == "numPaletteEntries":
|
| 279 |
+
self.paletteEntryLabels = [self.NO_NAME_ID] * self.numPaletteEntries
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
class Color(namedtuple("Color", "blue green red alpha")):
|
| 283 |
+
def hex(self):
|
| 284 |
+
return "#%02X%02X%02X%02X" % (self.red, self.green, self.blue, self.alpha)
|
| 285 |
+
|
| 286 |
+
def __repr__(self):
|
| 287 |
+
return self.hex()
|
| 288 |
+
|
| 289 |
+
def toXML(self, writer, ttFont, index=None):
|
| 290 |
+
writer.simpletag("color", value=self.hex(), index=index)
|
| 291 |
+
writer.newline()
|
| 292 |
+
|
| 293 |
+
@classmethod
|
| 294 |
+
def fromHex(cls, value):
|
| 295 |
+
if value[0] == "#":
|
| 296 |
+
value = value[1:]
|
| 297 |
+
red = int(value[0:2], 16)
|
| 298 |
+
green = int(value[2:4], 16)
|
| 299 |
+
blue = int(value[4:6], 16)
|
| 300 |
+
alpha = int(value[6:8], 16) if len(value) >= 8 else 0xFF
|
| 301 |
+
return cls(red=red, green=green, blue=blue, alpha=alpha)
|
| 302 |
+
|
| 303 |
+
@classmethod
|
| 304 |
+
def fromRGBA(cls, red, green, blue, alpha):
|
| 305 |
+
return cls(red=red, green=green, blue=blue, alpha=alpha)
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/D__e_b_g.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from textwrap import indent
|
| 3 |
+
|
| 4 |
+
from . import DefaultTable
|
| 5 |
+
from fontTools.misc.textTools import tostr
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class table_D__e_b_g(DefaultTable.DefaultTable):
|
| 9 |
+
def __init__(self, tag=None):
|
| 10 |
+
DefaultTable.DefaultTable.__init__(self, tag)
|
| 11 |
+
self.data = {}
|
| 12 |
+
|
| 13 |
+
def decompile(self, data, ttFont):
|
| 14 |
+
self.data = json.loads(data)
|
| 15 |
+
|
| 16 |
+
def compile(self, ttFont):
|
| 17 |
+
return json.dumps(self.data).encode("utf-8")
|
| 18 |
+
|
| 19 |
+
def toXML(self, writer, ttFont):
|
| 20 |
+
# make sure json indentation inside CDATA block matches XMLWriter's
|
| 21 |
+
data = json.dumps(self.data, indent=len(writer.indentwhite))
|
| 22 |
+
prefix = tostr(writer.indentwhite) * (writer.indentlevel + 1)
|
| 23 |
+
# but don't indent the first json line so it's adjacent to `<![CDATA[{`
|
| 24 |
+
cdata = indent(data, prefix, lambda ln: ln != "{\n")
|
| 25 |
+
|
| 26 |
+
writer.begintag("json")
|
| 27 |
+
writer.newline()
|
| 28 |
+
writer.writecdata(cdata)
|
| 29 |
+
writer.newline()
|
| 30 |
+
writer.endtag("json")
|
| 31 |
+
writer.newline()
|
| 32 |
+
|
| 33 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 34 |
+
if name == "json":
|
| 35 |
+
self.data = json.loads("".join(content))
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/DefaultTable.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import TYPE_CHECKING
|
| 4 |
+
|
| 5 |
+
from fontTools.misc.textTools import Tag
|
| 6 |
+
from fontTools.ttLib import getClassTag
|
| 7 |
+
|
| 8 |
+
if TYPE_CHECKING:
|
| 9 |
+
from typing import Any
|
| 10 |
+
|
| 11 |
+
from fontTools.misc.xmlWriter import XMLWriter
|
| 12 |
+
from fontTools.ttLib import TTFont
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class DefaultTable:
|
| 16 |
+
dependencies: list[str] = []
|
| 17 |
+
|
| 18 |
+
def __init__(self, tag: str | bytes | None = None) -> None:
|
| 19 |
+
if tag is None:
|
| 20 |
+
tag = getClassTag(self.__class__)
|
| 21 |
+
self.tableTag = Tag(tag)
|
| 22 |
+
|
| 23 |
+
def decompile(self, data: bytes, ttFont: TTFont) -> None:
|
| 24 |
+
self.data = data
|
| 25 |
+
|
| 26 |
+
def compile(self, ttFont: TTFont) -> bytes:
|
| 27 |
+
return self.data
|
| 28 |
+
|
| 29 |
+
def toXML(
|
| 30 |
+
self, writer: XMLWriter, ttFont: TTFont, **kwargs: dict[str, Any]
|
| 31 |
+
) -> None:
|
| 32 |
+
if hasattr(self, "ERROR"):
|
| 33 |
+
writer.comment("An error occurred during the decompilation of this table")
|
| 34 |
+
writer.newline()
|
| 35 |
+
writer.comment(self.ERROR)
|
| 36 |
+
writer.newline()
|
| 37 |
+
writer.begintag("hexdata")
|
| 38 |
+
writer.newline()
|
| 39 |
+
writer.dumphex(self.compile(ttFont))
|
| 40 |
+
writer.endtag("hexdata")
|
| 41 |
+
writer.newline()
|
| 42 |
+
|
| 43 |
+
def fromXML(
|
| 44 |
+
self, name: str, attrs: dict[str, str], content: str, ttFont: TTFont
|
| 45 |
+
) -> None:
|
| 46 |
+
from fontTools import ttLib
|
| 47 |
+
from fontTools.misc.textTools import readHex
|
| 48 |
+
|
| 49 |
+
if name != "hexdata":
|
| 50 |
+
raise ttLib.TTLibError("can't handle '%s' element" % name)
|
| 51 |
+
self.decompile(readHex(content), ttFont)
|
| 52 |
+
|
| 53 |
+
def __repr__(self) -> str:
|
| 54 |
+
return "<'%s' table at %x>" % (self.tableTag, id(self))
|
| 55 |
+
|
| 56 |
+
def __eq__(self, other: Any) -> bool:
|
| 57 |
+
if type(self) != type(other):
|
| 58 |
+
return NotImplemented
|
| 59 |
+
return self.__dict__ == other.__dict__
|
| 60 |
+
|
| 61 |
+
def __ne__(self, other: Any) -> bool:
|
| 62 |
+
result = self.__eq__(other)
|
| 63 |
+
return result if result is NotImplemented else not result
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G_D_E_F_.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .otBase import BaseTTXConverter
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class table_G_D_E_F_(BaseTTXConverter):
|
| 5 |
+
"""Glyph Definition table
|
| 6 |
+
|
| 7 |
+
The ``GDEF`` table stores various glyph properties that are used
|
| 8 |
+
by OpenType Layout.
|
| 9 |
+
|
| 10 |
+
See also https://learn.microsoft.com/en-us/typography/opentype/spec/gdef
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
pass
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G_V_A_R_.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ._g_v_a_r import table__g_v_a_r
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class table_G_V_A_R_(table__g_v_a_r):
|
| 5 |
+
gid_size = 3
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/G__l_o_c.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.misc import sstruct
|
| 2 |
+
from fontTools.misc.textTools import safeEval
|
| 3 |
+
from . import DefaultTable
|
| 4 |
+
import array
|
| 5 |
+
import sys
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
Gloc_header = """
|
| 9 |
+
> # big endian
|
| 10 |
+
version: 16.16F # Table version
|
| 11 |
+
flags: H # bit 0: 1=long format, 0=short format
|
| 12 |
+
# bit 1: 1=attribute names, 0=no names
|
| 13 |
+
numAttribs: H # NUmber of attributes
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class table_G__l_o_c(DefaultTable.DefaultTable):
|
| 18 |
+
"""Graphite Index to Glyph Atttributes table
|
| 19 |
+
|
| 20 |
+
See also https://graphite.sil.org/graphite_techAbout#graphite-font-tables
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
dependencies = ["Glat"]
|
| 24 |
+
|
| 25 |
+
def __init__(self, tag=None):
|
| 26 |
+
DefaultTable.DefaultTable.__init__(self, tag)
|
| 27 |
+
self.attribIds = None
|
| 28 |
+
self.numAttribs = 0
|
| 29 |
+
|
| 30 |
+
def decompile(self, data, ttFont):
|
| 31 |
+
_, data = sstruct.unpack2(Gloc_header, data, self)
|
| 32 |
+
flags = self.flags
|
| 33 |
+
del self.flags
|
| 34 |
+
self.locations = array.array("I" if flags & 1 else "H")
|
| 35 |
+
self.locations.frombytes(data[: len(data) - self.numAttribs * (flags & 2)])
|
| 36 |
+
if sys.byteorder != "big":
|
| 37 |
+
self.locations.byteswap()
|
| 38 |
+
self.attribIds = array.array("H")
|
| 39 |
+
if flags & 2:
|
| 40 |
+
self.attribIds.frombytes(data[-self.numAttribs * 2 :])
|
| 41 |
+
if sys.byteorder != "big":
|
| 42 |
+
self.attribIds.byteswap()
|
| 43 |
+
|
| 44 |
+
def compile(self, ttFont):
|
| 45 |
+
data = sstruct.pack(
|
| 46 |
+
Gloc_header,
|
| 47 |
+
dict(
|
| 48 |
+
version=1.0,
|
| 49 |
+
flags=(bool(self.attribIds) << 1) + (self.locations.typecode == "I"),
|
| 50 |
+
numAttribs=self.numAttribs,
|
| 51 |
+
),
|
| 52 |
+
)
|
| 53 |
+
if sys.byteorder != "big":
|
| 54 |
+
self.locations.byteswap()
|
| 55 |
+
data += self.locations.tobytes()
|
| 56 |
+
if sys.byteorder != "big":
|
| 57 |
+
self.locations.byteswap()
|
| 58 |
+
if self.attribIds:
|
| 59 |
+
if sys.byteorder != "big":
|
| 60 |
+
self.attribIds.byteswap()
|
| 61 |
+
data += self.attribIds.tobytes()
|
| 62 |
+
if sys.byteorder != "big":
|
| 63 |
+
self.attribIds.byteswap()
|
| 64 |
+
return data
|
| 65 |
+
|
| 66 |
+
def set(self, locations):
|
| 67 |
+
long_format = max(locations) >= 65536
|
| 68 |
+
self.locations = array.array("I" if long_format else "H", locations)
|
| 69 |
+
|
| 70 |
+
def toXML(self, writer, ttFont):
|
| 71 |
+
writer.simpletag("attributes", number=self.numAttribs)
|
| 72 |
+
writer.newline()
|
| 73 |
+
|
| 74 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 75 |
+
if name == "attributes":
|
| 76 |
+
self.numAttribs = int(safeEval(attrs["number"]))
|
| 77 |
+
|
| 78 |
+
def __getitem__(self, index):
|
| 79 |
+
return self.locations[index]
|
| 80 |
+
|
| 81 |
+
def __len__(self):
|
| 82 |
+
return len(self.locations)
|
| 83 |
+
|
| 84 |
+
def __iter__(self):
|
| 85 |
+
return iter(self.locations)
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/H_V_A_R_.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .otBase import BaseTTXConverter
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class table_H_V_A_R_(BaseTTXConverter):
|
| 5 |
+
"""Horizontal Metrics Variations table
|
| 6 |
+
|
| 7 |
+
The ``HVAR`` table contains variations in horizontal glyph metrics
|
| 8 |
+
in variable fonts.
|
| 9 |
+
|
| 10 |
+
See also https://learn.microsoft.com/en-us/typography/opentype/spec/hvar
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
pass
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/J_S_T_F_.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .otBase import BaseTTXConverter
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class table_J_S_T_F_(BaseTTXConverter):
|
| 5 |
+
"""Justification table
|
| 6 |
+
|
| 7 |
+
The ``JSTF`` table contains glyph substitution and positioning
|
| 8 |
+
data used to perform text justification.
|
| 9 |
+
|
| 10 |
+
See also https://learn.microsoft.com/en-us/typography/opentype/spec/jstf
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
pass
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/L_T_S_H_.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.misc.textTools import safeEval
|
| 2 |
+
from . import DefaultTable
|
| 3 |
+
import struct
|
| 4 |
+
import array
|
| 5 |
+
|
| 6 |
+
# XXX I've lowered the strictness, to make sure Apple's own Chicago
|
| 7 |
+
# XXX gets through. They're looking into it, I hope to raise the standards
|
| 8 |
+
# XXX back to normal eventually.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class table_L_T_S_H_(DefaultTable.DefaultTable):
|
| 12 |
+
"""Linear Threshold table
|
| 13 |
+
|
| 14 |
+
The ``LTSH`` table contains per-glyph settings indicating the ppem sizes
|
| 15 |
+
at which the advance width metric should be scaled linearly, despite the
|
| 16 |
+
effects of any TrueType instructions that might otherwise alter the
|
| 17 |
+
advance width.
|
| 18 |
+
|
| 19 |
+
See also https://learn.microsoft.com/en-us/typography/opentype/spec/ltsh
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
def decompile(self, data, ttFont):
|
| 23 |
+
version, numGlyphs = struct.unpack(">HH", data[:4])
|
| 24 |
+
data = data[4:]
|
| 25 |
+
assert version == 0, "unknown version: %s" % version
|
| 26 |
+
assert (len(data) % numGlyphs) < 4, "numGlyphs doesn't match data length"
|
| 27 |
+
# ouch: the assertion is not true in Chicago!
|
| 28 |
+
# assert numGlyphs == ttFont['maxp'].numGlyphs
|
| 29 |
+
yPels = array.array("B")
|
| 30 |
+
yPels.frombytes(data)
|
| 31 |
+
self.yPels = {}
|
| 32 |
+
for i in range(numGlyphs):
|
| 33 |
+
self.yPels[ttFont.getGlyphName(i)] = yPels[i]
|
| 34 |
+
|
| 35 |
+
def compile(self, ttFont):
|
| 36 |
+
version = 0
|
| 37 |
+
names = list(self.yPels.keys())
|
| 38 |
+
numGlyphs = len(names)
|
| 39 |
+
yPels = [0] * numGlyphs
|
| 40 |
+
# ouch: the assertion is not true in Chicago!
|
| 41 |
+
# assert len(self.yPels) == ttFont['maxp'].numGlyphs == numGlyphs
|
| 42 |
+
for name in names:
|
| 43 |
+
yPels[ttFont.getGlyphID(name)] = self.yPels[name]
|
| 44 |
+
yPels = array.array("B", yPels)
|
| 45 |
+
return struct.pack(">HH", version, numGlyphs) + yPels.tobytes()
|
| 46 |
+
|
| 47 |
+
def toXML(self, writer, ttFont):
|
| 48 |
+
names = sorted(self.yPels.keys())
|
| 49 |
+
for name in names:
|
| 50 |
+
writer.simpletag("yPel", name=name, value=self.yPels[name])
|
| 51 |
+
writer.newline()
|
| 52 |
+
|
| 53 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 54 |
+
if not hasattr(self, "yPels"):
|
| 55 |
+
self.yPels = {}
|
| 56 |
+
if name != "yPel":
|
| 57 |
+
return # ignore unknown tags
|
| 58 |
+
self.yPels[attrs["name"]] = safeEval(attrs["value"])
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/M_V_A_R_.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .otBase import BaseTTXConverter
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class table_M_V_A_R_(BaseTTXConverter):
|
| 5 |
+
"""Metrics Variations table
|
| 6 |
+
|
| 7 |
+
The ``MVAR`` table contains variation information for font-wide
|
| 8 |
+
metrics in a variable font.
|
| 9 |
+
|
| 10 |
+
See also https://learn.microsoft.com/en-us/typography/opentype/spec/mvar
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
pass
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/O_S_2f_2.py
ADDED
|
@@ -0,0 +1,752 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.misc import sstruct
|
| 2 |
+
from fontTools.misc.roundTools import otRound
|
| 3 |
+
from fontTools.misc.textTools import safeEval, num2binary, binary2num
|
| 4 |
+
from fontTools.ttLib.tables import DefaultTable
|
| 5 |
+
import bisect
|
| 6 |
+
import logging
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
log = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
# panose classification
|
| 12 |
+
|
| 13 |
+
panoseFormat = """
|
| 14 |
+
bFamilyType: B
|
| 15 |
+
bSerifStyle: B
|
| 16 |
+
bWeight: B
|
| 17 |
+
bProportion: B
|
| 18 |
+
bContrast: B
|
| 19 |
+
bStrokeVariation: B
|
| 20 |
+
bArmStyle: B
|
| 21 |
+
bLetterForm: B
|
| 22 |
+
bMidline: B
|
| 23 |
+
bXHeight: B
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class Panose(object):
|
| 28 |
+
def __init__(self, **kwargs):
|
| 29 |
+
_, names, _ = sstruct.getformat(panoseFormat)
|
| 30 |
+
for name in names:
|
| 31 |
+
setattr(self, name, kwargs.pop(name, 0))
|
| 32 |
+
for k in kwargs:
|
| 33 |
+
raise TypeError(f"Panose() got an unexpected keyword argument {k!r}")
|
| 34 |
+
|
| 35 |
+
def toXML(self, writer, ttFont):
|
| 36 |
+
formatstring, names, fixes = sstruct.getformat(panoseFormat)
|
| 37 |
+
for name in names:
|
| 38 |
+
writer.simpletag(name, value=getattr(self, name))
|
| 39 |
+
writer.newline()
|
| 40 |
+
|
| 41 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 42 |
+
setattr(self, name, safeEval(attrs["value"]))
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# 'sfnt' OS/2 and Windows Metrics table - 'OS/2'
|
| 46 |
+
|
| 47 |
+
OS2_format_0 = """
|
| 48 |
+
> # big endian
|
| 49 |
+
version: H # version
|
| 50 |
+
xAvgCharWidth: h # average character width
|
| 51 |
+
usWeightClass: H # degree of thickness of strokes
|
| 52 |
+
usWidthClass: H # aspect ratio
|
| 53 |
+
fsType: H # type flags
|
| 54 |
+
ySubscriptXSize: h # subscript horizontal font size
|
| 55 |
+
ySubscriptYSize: h # subscript vertical font size
|
| 56 |
+
ySubscriptXOffset: h # subscript x offset
|
| 57 |
+
ySubscriptYOffset: h # subscript y offset
|
| 58 |
+
ySuperscriptXSize: h # superscript horizontal font size
|
| 59 |
+
ySuperscriptYSize: h # superscript vertical font size
|
| 60 |
+
ySuperscriptXOffset: h # superscript x offset
|
| 61 |
+
ySuperscriptYOffset: h # superscript y offset
|
| 62 |
+
yStrikeoutSize: h # strikeout size
|
| 63 |
+
yStrikeoutPosition: h # strikeout position
|
| 64 |
+
sFamilyClass: h # font family class and subclass
|
| 65 |
+
panose: 10s # panose classification number
|
| 66 |
+
ulUnicodeRange1: L # character range
|
| 67 |
+
ulUnicodeRange2: L # character range
|
| 68 |
+
ulUnicodeRange3: L # character range
|
| 69 |
+
ulUnicodeRange4: L # character range
|
| 70 |
+
achVendID: 4s # font vendor identification
|
| 71 |
+
fsSelection: H # font selection flags
|
| 72 |
+
usFirstCharIndex: H # first unicode character index
|
| 73 |
+
usLastCharIndex: H # last unicode character index
|
| 74 |
+
sTypoAscender: h # typographic ascender
|
| 75 |
+
sTypoDescender: h # typographic descender
|
| 76 |
+
sTypoLineGap: h # typographic line gap
|
| 77 |
+
usWinAscent: H # Windows ascender
|
| 78 |
+
usWinDescent: H # Windows descender
|
| 79 |
+
"""
|
| 80 |
+
|
| 81 |
+
OS2_format_1_addition = """
|
| 82 |
+
ulCodePageRange1: L
|
| 83 |
+
ulCodePageRange2: L
|
| 84 |
+
"""
|
| 85 |
+
|
| 86 |
+
OS2_format_2_addition = (
|
| 87 |
+
OS2_format_1_addition
|
| 88 |
+
+ """
|
| 89 |
+
sxHeight: h
|
| 90 |
+
sCapHeight: h
|
| 91 |
+
usDefaultChar: H
|
| 92 |
+
usBreakChar: H
|
| 93 |
+
usMaxContext: H
|
| 94 |
+
"""
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
OS2_format_5_addition = (
|
| 98 |
+
OS2_format_2_addition
|
| 99 |
+
+ """
|
| 100 |
+
usLowerOpticalPointSize: H
|
| 101 |
+
usUpperOpticalPointSize: H
|
| 102 |
+
"""
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
bigendian = " > # big endian\n"
|
| 106 |
+
|
| 107 |
+
OS2_format_1 = OS2_format_0 + OS2_format_1_addition
|
| 108 |
+
OS2_format_2 = OS2_format_0 + OS2_format_2_addition
|
| 109 |
+
OS2_format_5 = OS2_format_0 + OS2_format_5_addition
|
| 110 |
+
OS2_format_1_addition = bigendian + OS2_format_1_addition
|
| 111 |
+
OS2_format_2_addition = bigendian + OS2_format_2_addition
|
| 112 |
+
OS2_format_5_addition = bigendian + OS2_format_5_addition
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
class table_O_S_2f_2(DefaultTable.DefaultTable):
|
| 116 |
+
"""OS/2 and Windows Metrics table
|
| 117 |
+
|
| 118 |
+
The ``OS/2`` table contains a variety of font-wide metrics and
|
| 119 |
+
parameters that may be useful to an operating system or other
|
| 120 |
+
software for system-integration purposes.
|
| 121 |
+
|
| 122 |
+
See also https://learn.microsoft.com/en-us/typography/opentype/spec/os2
|
| 123 |
+
"""
|
| 124 |
+
|
| 125 |
+
dependencies = ["head"]
|
| 126 |
+
|
| 127 |
+
def decompile(self, data, ttFont):
|
| 128 |
+
dummy, data = sstruct.unpack2(OS2_format_0, data, self)
|
| 129 |
+
|
| 130 |
+
if self.version == 1:
|
| 131 |
+
dummy, data = sstruct.unpack2(OS2_format_1_addition, data, self)
|
| 132 |
+
elif self.version in (2, 3, 4):
|
| 133 |
+
dummy, data = sstruct.unpack2(OS2_format_2_addition, data, self)
|
| 134 |
+
elif self.version == 5:
|
| 135 |
+
dummy, data = sstruct.unpack2(OS2_format_5_addition, data, self)
|
| 136 |
+
self.usLowerOpticalPointSize /= 20
|
| 137 |
+
self.usUpperOpticalPointSize /= 20
|
| 138 |
+
elif self.version != 0:
|
| 139 |
+
from fontTools import ttLib
|
| 140 |
+
|
| 141 |
+
raise ttLib.TTLibError(
|
| 142 |
+
"unknown format for OS/2 table: version %s" % self.version
|
| 143 |
+
)
|
| 144 |
+
if len(data):
|
| 145 |
+
log.warning("too much 'OS/2' table data")
|
| 146 |
+
|
| 147 |
+
self.panose = sstruct.unpack(panoseFormat, self.panose, Panose())
|
| 148 |
+
|
| 149 |
+
def compile(self, ttFont):
|
| 150 |
+
self.updateFirstAndLastCharIndex(ttFont)
|
| 151 |
+
panose = self.panose
|
| 152 |
+
head = ttFont["head"]
|
| 153 |
+
if (self.fsSelection & 1) and not (head.macStyle & 1 << 1):
|
| 154 |
+
log.warning(
|
| 155 |
+
"fsSelection bit 0 (italic) and "
|
| 156 |
+
"head table macStyle bit 1 (italic) should match"
|
| 157 |
+
)
|
| 158 |
+
if (self.fsSelection & 1 << 5) and not (head.macStyle & 1):
|
| 159 |
+
log.warning(
|
| 160 |
+
"fsSelection bit 5 (bold) and "
|
| 161 |
+
"head table macStyle bit 0 (bold) should match"
|
| 162 |
+
)
|
| 163 |
+
if (self.fsSelection & 1 << 6) and (self.fsSelection & 1 + (1 << 5)):
|
| 164 |
+
log.warning(
|
| 165 |
+
"fsSelection bit 6 (regular) is set, "
|
| 166 |
+
"bits 0 (italic) and 5 (bold) must be clear"
|
| 167 |
+
)
|
| 168 |
+
if self.version < 4 and self.fsSelection & 0b1110000000:
|
| 169 |
+
log.warning(
|
| 170 |
+
"fsSelection bits 7, 8 and 9 are only defined in "
|
| 171 |
+
"OS/2 table version 4 and up: version %s",
|
| 172 |
+
self.version,
|
| 173 |
+
)
|
| 174 |
+
self.panose = sstruct.pack(panoseFormat, self.panose)
|
| 175 |
+
if self.version == 0:
|
| 176 |
+
data = sstruct.pack(OS2_format_0, self)
|
| 177 |
+
elif self.version == 1:
|
| 178 |
+
data = sstruct.pack(OS2_format_1, self)
|
| 179 |
+
elif self.version in (2, 3, 4):
|
| 180 |
+
data = sstruct.pack(OS2_format_2, self)
|
| 181 |
+
elif self.version == 5:
|
| 182 |
+
d = self.__dict__.copy()
|
| 183 |
+
d["usLowerOpticalPointSize"] = round(self.usLowerOpticalPointSize * 20)
|
| 184 |
+
d["usUpperOpticalPointSize"] = round(self.usUpperOpticalPointSize * 20)
|
| 185 |
+
data = sstruct.pack(OS2_format_5, d)
|
| 186 |
+
else:
|
| 187 |
+
from fontTools import ttLib
|
| 188 |
+
|
| 189 |
+
raise ttLib.TTLibError(
|
| 190 |
+
"unknown format for OS/2 table: version %s" % self.version
|
| 191 |
+
)
|
| 192 |
+
self.panose = panose
|
| 193 |
+
return data
|
| 194 |
+
|
| 195 |
+
def toXML(self, writer, ttFont):
|
| 196 |
+
writer.comment(
|
| 197 |
+
"The fields 'usFirstCharIndex' and 'usLastCharIndex'\n"
|
| 198 |
+
"will be recalculated by the compiler"
|
| 199 |
+
)
|
| 200 |
+
writer.newline()
|
| 201 |
+
if self.version == 1:
|
| 202 |
+
format = OS2_format_1
|
| 203 |
+
elif self.version in (2, 3, 4):
|
| 204 |
+
format = OS2_format_2
|
| 205 |
+
elif self.version == 5:
|
| 206 |
+
format = OS2_format_5
|
| 207 |
+
else:
|
| 208 |
+
format = OS2_format_0
|
| 209 |
+
formatstring, names, fixes = sstruct.getformat(format)
|
| 210 |
+
for name in names:
|
| 211 |
+
value = getattr(self, name)
|
| 212 |
+
if name == "panose":
|
| 213 |
+
writer.begintag("panose")
|
| 214 |
+
writer.newline()
|
| 215 |
+
value.toXML(writer, ttFont)
|
| 216 |
+
writer.endtag("panose")
|
| 217 |
+
elif name in (
|
| 218 |
+
"ulUnicodeRange1",
|
| 219 |
+
"ulUnicodeRange2",
|
| 220 |
+
"ulUnicodeRange3",
|
| 221 |
+
"ulUnicodeRange4",
|
| 222 |
+
"ulCodePageRange1",
|
| 223 |
+
"ulCodePageRange2",
|
| 224 |
+
):
|
| 225 |
+
writer.simpletag(name, value=num2binary(value))
|
| 226 |
+
elif name in ("fsType", "fsSelection"):
|
| 227 |
+
writer.simpletag(name, value=num2binary(value, 16))
|
| 228 |
+
elif name == "achVendID":
|
| 229 |
+
writer.simpletag(name, value=repr(value)[1:-1])
|
| 230 |
+
else:
|
| 231 |
+
writer.simpletag(name, value=value)
|
| 232 |
+
writer.newline()
|
| 233 |
+
|
| 234 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 235 |
+
if name == "panose":
|
| 236 |
+
self.panose = panose = Panose()
|
| 237 |
+
for element in content:
|
| 238 |
+
if isinstance(element, tuple):
|
| 239 |
+
name, attrs, content = element
|
| 240 |
+
panose.fromXML(name, attrs, content, ttFont)
|
| 241 |
+
elif name in (
|
| 242 |
+
"ulUnicodeRange1",
|
| 243 |
+
"ulUnicodeRange2",
|
| 244 |
+
"ulUnicodeRange3",
|
| 245 |
+
"ulUnicodeRange4",
|
| 246 |
+
"ulCodePageRange1",
|
| 247 |
+
"ulCodePageRange2",
|
| 248 |
+
"fsType",
|
| 249 |
+
"fsSelection",
|
| 250 |
+
):
|
| 251 |
+
setattr(self, name, binary2num(attrs["value"]))
|
| 252 |
+
elif name == "achVendID":
|
| 253 |
+
setattr(self, name, safeEval("'''" + attrs["value"] + "'''"))
|
| 254 |
+
else:
|
| 255 |
+
setattr(self, name, safeEval(attrs["value"]))
|
| 256 |
+
|
| 257 |
+
def updateFirstAndLastCharIndex(self, ttFont):
|
| 258 |
+
if "cmap" not in ttFont:
|
| 259 |
+
return
|
| 260 |
+
codes = set()
|
| 261 |
+
for table in getattr(ttFont["cmap"], "tables", []):
|
| 262 |
+
if table.isUnicode():
|
| 263 |
+
codes.update(table.cmap.keys())
|
| 264 |
+
if codes:
|
| 265 |
+
minCode = min(codes)
|
| 266 |
+
maxCode = max(codes)
|
| 267 |
+
# USHORT cannot hold codepoints greater than 0xFFFF
|
| 268 |
+
self.usFirstCharIndex = min(0xFFFF, minCode)
|
| 269 |
+
self.usLastCharIndex = min(0xFFFF, maxCode)
|
| 270 |
+
|
| 271 |
+
# misspelled attributes kept for legacy reasons
|
| 272 |
+
|
| 273 |
+
@property
|
| 274 |
+
def usMaxContex(self):
|
| 275 |
+
return self.usMaxContext
|
| 276 |
+
|
| 277 |
+
@usMaxContex.setter
|
| 278 |
+
def usMaxContex(self, value):
|
| 279 |
+
self.usMaxContext = value
|
| 280 |
+
|
| 281 |
+
@property
|
| 282 |
+
def fsFirstCharIndex(self):
|
| 283 |
+
return self.usFirstCharIndex
|
| 284 |
+
|
| 285 |
+
@fsFirstCharIndex.setter
|
| 286 |
+
def fsFirstCharIndex(self, value):
|
| 287 |
+
self.usFirstCharIndex = value
|
| 288 |
+
|
| 289 |
+
@property
|
| 290 |
+
def fsLastCharIndex(self):
|
| 291 |
+
return self.usLastCharIndex
|
| 292 |
+
|
| 293 |
+
@fsLastCharIndex.setter
|
| 294 |
+
def fsLastCharIndex(self, value):
|
| 295 |
+
self.usLastCharIndex = value
|
| 296 |
+
|
| 297 |
+
def getUnicodeRanges(self):
|
| 298 |
+
"""Return the set of 'ulUnicodeRange*' bits currently enabled."""
|
| 299 |
+
bits = set()
|
| 300 |
+
ul1, ul2 = self.ulUnicodeRange1, self.ulUnicodeRange2
|
| 301 |
+
ul3, ul4 = self.ulUnicodeRange3, self.ulUnicodeRange4
|
| 302 |
+
for i in range(32):
|
| 303 |
+
if ul1 & (1 << i):
|
| 304 |
+
bits.add(i)
|
| 305 |
+
if ul2 & (1 << i):
|
| 306 |
+
bits.add(i + 32)
|
| 307 |
+
if ul3 & (1 << i):
|
| 308 |
+
bits.add(i + 64)
|
| 309 |
+
if ul4 & (1 << i):
|
| 310 |
+
bits.add(i + 96)
|
| 311 |
+
return bits
|
| 312 |
+
|
| 313 |
+
def setUnicodeRanges(self, bits):
|
| 314 |
+
"""Set the 'ulUnicodeRange*' fields to the specified 'bits'."""
|
| 315 |
+
ul1, ul2, ul3, ul4 = 0, 0, 0, 0
|
| 316 |
+
for bit in bits:
|
| 317 |
+
if 0 <= bit < 32:
|
| 318 |
+
ul1 |= 1 << bit
|
| 319 |
+
elif 32 <= bit < 64:
|
| 320 |
+
ul2 |= 1 << (bit - 32)
|
| 321 |
+
elif 64 <= bit < 96:
|
| 322 |
+
ul3 |= 1 << (bit - 64)
|
| 323 |
+
elif 96 <= bit < 123:
|
| 324 |
+
ul4 |= 1 << (bit - 96)
|
| 325 |
+
else:
|
| 326 |
+
raise ValueError("expected 0 <= int <= 122, found: %r" % bit)
|
| 327 |
+
self.ulUnicodeRange1, self.ulUnicodeRange2 = ul1, ul2
|
| 328 |
+
self.ulUnicodeRange3, self.ulUnicodeRange4 = ul3, ul4
|
| 329 |
+
|
| 330 |
+
def recalcUnicodeRanges(self, ttFont, pruneOnly=False):
|
| 331 |
+
"""Intersect the codepoints in the font's Unicode cmap subtables with
|
| 332 |
+
the Unicode block ranges defined in the OpenType specification (v1.7),
|
| 333 |
+
and set the respective 'ulUnicodeRange*' bits if there is at least ONE
|
| 334 |
+
intersection.
|
| 335 |
+
If 'pruneOnly' is True, only clear unused bits with NO intersection.
|
| 336 |
+
"""
|
| 337 |
+
unicodes = set()
|
| 338 |
+
for table in ttFont["cmap"].tables:
|
| 339 |
+
if table.isUnicode():
|
| 340 |
+
unicodes.update(table.cmap.keys())
|
| 341 |
+
if pruneOnly:
|
| 342 |
+
empty = intersectUnicodeRanges(unicodes, inverse=True)
|
| 343 |
+
bits = self.getUnicodeRanges() - empty
|
| 344 |
+
else:
|
| 345 |
+
bits = intersectUnicodeRanges(unicodes)
|
| 346 |
+
self.setUnicodeRanges(bits)
|
| 347 |
+
return bits
|
| 348 |
+
|
| 349 |
+
def getCodePageRanges(self):
|
| 350 |
+
"""Return the set of 'ulCodePageRange*' bits currently enabled."""
|
| 351 |
+
bits = set()
|
| 352 |
+
if self.version < 1:
|
| 353 |
+
return bits
|
| 354 |
+
ul1, ul2 = self.ulCodePageRange1, self.ulCodePageRange2
|
| 355 |
+
for i in range(32):
|
| 356 |
+
if ul1 & (1 << i):
|
| 357 |
+
bits.add(i)
|
| 358 |
+
if ul2 & (1 << i):
|
| 359 |
+
bits.add(i + 32)
|
| 360 |
+
return bits
|
| 361 |
+
|
| 362 |
+
def setCodePageRanges(self, bits):
|
| 363 |
+
"""Set the 'ulCodePageRange*' fields to the specified 'bits'."""
|
| 364 |
+
ul1, ul2 = 0, 0
|
| 365 |
+
for bit in bits:
|
| 366 |
+
if 0 <= bit < 32:
|
| 367 |
+
ul1 |= 1 << bit
|
| 368 |
+
elif 32 <= bit < 64:
|
| 369 |
+
ul2 |= 1 << (bit - 32)
|
| 370 |
+
else:
|
| 371 |
+
raise ValueError(f"expected 0 <= int <= 63, found: {bit:r}")
|
| 372 |
+
if self.version < 1:
|
| 373 |
+
self.version = 1
|
| 374 |
+
self.ulCodePageRange1, self.ulCodePageRange2 = ul1, ul2
|
| 375 |
+
|
| 376 |
+
def recalcCodePageRanges(self, ttFont, pruneOnly=False):
|
| 377 |
+
unicodes = set()
|
| 378 |
+
for table in ttFont["cmap"].tables:
|
| 379 |
+
if table.isUnicode():
|
| 380 |
+
unicodes.update(table.cmap.keys())
|
| 381 |
+
bits = calcCodePageRanges(unicodes)
|
| 382 |
+
if pruneOnly:
|
| 383 |
+
bits &= self.getCodePageRanges()
|
| 384 |
+
# when no codepage ranges can be enabled, fall back to enabling bit 0
|
| 385 |
+
# (Latin 1) so that the font works in MS Word:
|
| 386 |
+
# https://github.com/googlei18n/fontmake/issues/468
|
| 387 |
+
if not bits:
|
| 388 |
+
bits = {0}
|
| 389 |
+
self.setCodePageRanges(bits)
|
| 390 |
+
return bits
|
| 391 |
+
|
| 392 |
+
def recalcAvgCharWidth(self, ttFont):
|
| 393 |
+
"""Recalculate xAvgCharWidth using metrics from ttFont's 'hmtx' table.
|
| 394 |
+
|
| 395 |
+
Set it to 0 if the unlikely event 'hmtx' table is not found.
|
| 396 |
+
"""
|
| 397 |
+
avg_width = 0
|
| 398 |
+
hmtx = ttFont.get("hmtx")
|
| 399 |
+
if hmtx is not None:
|
| 400 |
+
widths = [width for width, _ in hmtx.metrics.values() if width > 0]
|
| 401 |
+
if widths:
|
| 402 |
+
avg_width = otRound(sum(widths) / len(widths))
|
| 403 |
+
self.xAvgCharWidth = avg_width
|
| 404 |
+
return avg_width
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
# Unicode ranges data from the OpenType OS/2 table specification v1.7
|
| 408 |
+
|
| 409 |
+
OS2_UNICODE_RANGES = (
|
| 410 |
+
(("Basic Latin", (0x0000, 0x007F)),),
|
| 411 |
+
(("Latin-1 Supplement", (0x0080, 0x00FF)),),
|
| 412 |
+
(("Latin Extended-A", (0x0100, 0x017F)),),
|
| 413 |
+
(("Latin Extended-B", (0x0180, 0x024F)),),
|
| 414 |
+
(
|
| 415 |
+
("IPA Extensions", (0x0250, 0x02AF)),
|
| 416 |
+
("Phonetic Extensions", (0x1D00, 0x1D7F)),
|
| 417 |
+
("Phonetic Extensions Supplement", (0x1D80, 0x1DBF)),
|
| 418 |
+
),
|
| 419 |
+
(
|
| 420 |
+
("Spacing Modifier Letters", (0x02B0, 0x02FF)),
|
| 421 |
+
("Modifier Tone Letters", (0xA700, 0xA71F)),
|
| 422 |
+
),
|
| 423 |
+
(
|
| 424 |
+
("Combining Diacritical Marks", (0x0300, 0x036F)),
|
| 425 |
+
("Combining Diacritical Marks Supplement", (0x1DC0, 0x1DFF)),
|
| 426 |
+
),
|
| 427 |
+
(("Greek and Coptic", (0x0370, 0x03FF)),),
|
| 428 |
+
(("Coptic", (0x2C80, 0x2CFF)),),
|
| 429 |
+
(
|
| 430 |
+
("Cyrillic", (0x0400, 0x04FF)),
|
| 431 |
+
("Cyrillic Supplement", (0x0500, 0x052F)),
|
| 432 |
+
("Cyrillic Extended-A", (0x2DE0, 0x2DFF)),
|
| 433 |
+
("Cyrillic Extended-B", (0xA640, 0xA69F)),
|
| 434 |
+
),
|
| 435 |
+
(("Armenian", (0x0530, 0x058F)),),
|
| 436 |
+
(("Hebrew", (0x0590, 0x05FF)),),
|
| 437 |
+
(("Vai", (0xA500, 0xA63F)),),
|
| 438 |
+
(("Arabic", (0x0600, 0x06FF)), ("Arabic Supplement", (0x0750, 0x077F))),
|
| 439 |
+
(("NKo", (0x07C0, 0x07FF)),),
|
| 440 |
+
(("Devanagari", (0x0900, 0x097F)),),
|
| 441 |
+
(("Bengali", (0x0980, 0x09FF)),),
|
| 442 |
+
(("Gurmukhi", (0x0A00, 0x0A7F)),),
|
| 443 |
+
(("Gujarati", (0x0A80, 0x0AFF)),),
|
| 444 |
+
(("Oriya", (0x0B00, 0x0B7F)),),
|
| 445 |
+
(("Tamil", (0x0B80, 0x0BFF)),),
|
| 446 |
+
(("Telugu", (0x0C00, 0x0C7F)),),
|
| 447 |
+
(("Kannada", (0x0C80, 0x0CFF)),),
|
| 448 |
+
(("Malayalam", (0x0D00, 0x0D7F)),),
|
| 449 |
+
(("Thai", (0x0E00, 0x0E7F)),),
|
| 450 |
+
(("Lao", (0x0E80, 0x0EFF)),),
|
| 451 |
+
(("Georgian", (0x10A0, 0x10FF)), ("Georgian Supplement", (0x2D00, 0x2D2F))),
|
| 452 |
+
(("Balinese", (0x1B00, 0x1B7F)),),
|
| 453 |
+
(("Hangul Jamo", (0x1100, 0x11FF)),),
|
| 454 |
+
(
|
| 455 |
+
("Latin Extended Additional", (0x1E00, 0x1EFF)),
|
| 456 |
+
("Latin Extended-C", (0x2C60, 0x2C7F)),
|
| 457 |
+
("Latin Extended-D", (0xA720, 0xA7FF)),
|
| 458 |
+
),
|
| 459 |
+
(("Greek Extended", (0x1F00, 0x1FFF)),),
|
| 460 |
+
(
|
| 461 |
+
("General Punctuation", (0x2000, 0x206F)),
|
| 462 |
+
("Supplemental Punctuation", (0x2E00, 0x2E7F)),
|
| 463 |
+
),
|
| 464 |
+
(("Superscripts And Subscripts", (0x2070, 0x209F)),),
|
| 465 |
+
(("Currency Symbols", (0x20A0, 0x20CF)),),
|
| 466 |
+
(("Combining Diacritical Marks For Symbols", (0x20D0, 0x20FF)),),
|
| 467 |
+
(("Letterlike Symbols", (0x2100, 0x214F)),),
|
| 468 |
+
(("Number Forms", (0x2150, 0x218F)),),
|
| 469 |
+
(
|
| 470 |
+
("Arrows", (0x2190, 0x21FF)),
|
| 471 |
+
("Supplemental Arrows-A", (0x27F0, 0x27FF)),
|
| 472 |
+
("Supplemental Arrows-B", (0x2900, 0x297F)),
|
| 473 |
+
("Miscellaneous Symbols and Arrows", (0x2B00, 0x2BFF)),
|
| 474 |
+
),
|
| 475 |
+
(
|
| 476 |
+
("Mathematical Operators", (0x2200, 0x22FF)),
|
| 477 |
+
("Supplemental Mathematical Operators", (0x2A00, 0x2AFF)),
|
| 478 |
+
("Miscellaneous Mathematical Symbols-A", (0x27C0, 0x27EF)),
|
| 479 |
+
("Miscellaneous Mathematical Symbols-B", (0x2980, 0x29FF)),
|
| 480 |
+
),
|
| 481 |
+
(("Miscellaneous Technical", (0x2300, 0x23FF)),),
|
| 482 |
+
(("Control Pictures", (0x2400, 0x243F)),),
|
| 483 |
+
(("Optical Character Recognition", (0x2440, 0x245F)),),
|
| 484 |
+
(("Enclosed Alphanumerics", (0x2460, 0x24FF)),),
|
| 485 |
+
(("Box Drawing", (0x2500, 0x257F)),),
|
| 486 |
+
(("Block Elements", (0x2580, 0x259F)),),
|
| 487 |
+
(("Geometric Shapes", (0x25A0, 0x25FF)),),
|
| 488 |
+
(("Miscellaneous Symbols", (0x2600, 0x26FF)),),
|
| 489 |
+
(("Dingbats", (0x2700, 0x27BF)),),
|
| 490 |
+
(("CJK Symbols And Punctuation", (0x3000, 0x303F)),),
|
| 491 |
+
(("Hiragana", (0x3040, 0x309F)),),
|
| 492 |
+
(
|
| 493 |
+
("Katakana", (0x30A0, 0x30FF)),
|
| 494 |
+
("Katakana Phonetic Extensions", (0x31F0, 0x31FF)),
|
| 495 |
+
),
|
| 496 |
+
(("Bopomofo", (0x3100, 0x312F)), ("Bopomofo Extended", (0x31A0, 0x31BF))),
|
| 497 |
+
(("Hangul Compatibility Jamo", (0x3130, 0x318F)),),
|
| 498 |
+
(("Phags-pa", (0xA840, 0xA87F)),),
|
| 499 |
+
(("Enclosed CJK Letters And Months", (0x3200, 0x32FF)),),
|
| 500 |
+
(("CJK Compatibility", (0x3300, 0x33FF)),),
|
| 501 |
+
(("Hangul Syllables", (0xAC00, 0xD7AF)),),
|
| 502 |
+
(("Non-Plane 0 *", (0xD800, 0xDFFF)),),
|
| 503 |
+
(("Phoenician", (0x10900, 0x1091F)),),
|
| 504 |
+
(
|
| 505 |
+
("CJK Unified Ideographs", (0x4E00, 0x9FFF)),
|
| 506 |
+
("CJK Radicals Supplement", (0x2E80, 0x2EFF)),
|
| 507 |
+
("Kangxi Radicals", (0x2F00, 0x2FDF)),
|
| 508 |
+
("Ideographic Description Characters", (0x2FF0, 0x2FFF)),
|
| 509 |
+
("CJK Unified Ideographs Extension A", (0x3400, 0x4DBF)),
|
| 510 |
+
("CJK Unified Ideographs Extension B", (0x20000, 0x2A6DF)),
|
| 511 |
+
("Kanbun", (0x3190, 0x319F)),
|
| 512 |
+
),
|
| 513 |
+
(("Private Use Area (plane 0)", (0xE000, 0xF8FF)),),
|
| 514 |
+
(
|
| 515 |
+
("CJK Strokes", (0x31C0, 0x31EF)),
|
| 516 |
+
("CJK Compatibility Ideographs", (0xF900, 0xFAFF)),
|
| 517 |
+
("CJK Compatibility Ideographs Supplement", (0x2F800, 0x2FA1F)),
|
| 518 |
+
),
|
| 519 |
+
(("Alphabetic Presentation Forms", (0xFB00, 0xFB4F)),),
|
| 520 |
+
(("Arabic Presentation Forms-A", (0xFB50, 0xFDFF)),),
|
| 521 |
+
(("Combining Half Marks", (0xFE20, 0xFE2F)),),
|
| 522 |
+
(
|
| 523 |
+
("Vertical Forms", (0xFE10, 0xFE1F)),
|
| 524 |
+
("CJK Compatibility Forms", (0xFE30, 0xFE4F)),
|
| 525 |
+
),
|
| 526 |
+
(("Small Form Variants", (0xFE50, 0xFE6F)),),
|
| 527 |
+
(("Arabic Presentation Forms-B", (0xFE70, 0xFEFF)),),
|
| 528 |
+
(("Halfwidth And Fullwidth Forms", (0xFF00, 0xFFEF)),),
|
| 529 |
+
(("Specials", (0xFFF0, 0xFFFF)),),
|
| 530 |
+
(("Tibetan", (0x0F00, 0x0FFF)),),
|
| 531 |
+
(("Syriac", (0x0700, 0x074F)),),
|
| 532 |
+
(("Thaana", (0x0780, 0x07BF)),),
|
| 533 |
+
(("Sinhala", (0x0D80, 0x0DFF)),),
|
| 534 |
+
(("Myanmar", (0x1000, 0x109F)),),
|
| 535 |
+
(
|
| 536 |
+
("Ethiopic", (0x1200, 0x137F)),
|
| 537 |
+
("Ethiopic Supplement", (0x1380, 0x139F)),
|
| 538 |
+
("Ethiopic Extended", (0x2D80, 0x2DDF)),
|
| 539 |
+
),
|
| 540 |
+
(("Cherokee", (0x13A0, 0x13FF)),),
|
| 541 |
+
(("Unified Canadian Aboriginal Syllabics", (0x1400, 0x167F)),),
|
| 542 |
+
(("Ogham", (0x1680, 0x169F)),),
|
| 543 |
+
(("Runic", (0x16A0, 0x16FF)),),
|
| 544 |
+
(("Khmer", (0x1780, 0x17FF)), ("Khmer Symbols", (0x19E0, 0x19FF))),
|
| 545 |
+
(("Mongolian", (0x1800, 0x18AF)),),
|
| 546 |
+
(("Braille Patterns", (0x2800, 0x28FF)),),
|
| 547 |
+
(("Yi Syllables", (0xA000, 0xA48F)), ("Yi Radicals", (0xA490, 0xA4CF))),
|
| 548 |
+
(
|
| 549 |
+
("Tagalog", (0x1700, 0x171F)),
|
| 550 |
+
("Hanunoo", (0x1720, 0x173F)),
|
| 551 |
+
("Buhid", (0x1740, 0x175F)),
|
| 552 |
+
("Tagbanwa", (0x1760, 0x177F)),
|
| 553 |
+
),
|
| 554 |
+
(("Old Italic", (0x10300, 0x1032F)),),
|
| 555 |
+
(("Gothic", (0x10330, 0x1034F)),),
|
| 556 |
+
(("Deseret", (0x10400, 0x1044F)),),
|
| 557 |
+
(
|
| 558 |
+
("Byzantine Musical Symbols", (0x1D000, 0x1D0FF)),
|
| 559 |
+
("Musical Symbols", (0x1D100, 0x1D1FF)),
|
| 560 |
+
("Ancient Greek Musical Notation", (0x1D200, 0x1D24F)),
|
| 561 |
+
),
|
| 562 |
+
(("Mathematical Alphanumeric Symbols", (0x1D400, 0x1D7FF)),),
|
| 563 |
+
(
|
| 564 |
+
("Private Use (plane 15)", (0xF0000, 0xFFFFD)),
|
| 565 |
+
("Private Use (plane 16)", (0x100000, 0x10FFFD)),
|
| 566 |
+
),
|
| 567 |
+
(
|
| 568 |
+
("Variation Selectors", (0xFE00, 0xFE0F)),
|
| 569 |
+
("Variation Selectors Supplement", (0xE0100, 0xE01EF)),
|
| 570 |
+
),
|
| 571 |
+
(("Tags", (0xE0000, 0xE007F)),),
|
| 572 |
+
(("Limbu", (0x1900, 0x194F)),),
|
| 573 |
+
(("Tai Le", (0x1950, 0x197F)),),
|
| 574 |
+
(("New Tai Lue", (0x1980, 0x19DF)),),
|
| 575 |
+
(("Buginese", (0x1A00, 0x1A1F)),),
|
| 576 |
+
(("Glagolitic", (0x2C00, 0x2C5F)),),
|
| 577 |
+
(("Tifinagh", (0x2D30, 0x2D7F)),),
|
| 578 |
+
(("Yijing Hexagram Symbols", (0x4DC0, 0x4DFF)),),
|
| 579 |
+
(("Syloti Nagri", (0xA800, 0xA82F)),),
|
| 580 |
+
(
|
| 581 |
+
("Linear B Syllabary", (0x10000, 0x1007F)),
|
| 582 |
+
("Linear B Ideograms", (0x10080, 0x100FF)),
|
| 583 |
+
("Aegean Numbers", (0x10100, 0x1013F)),
|
| 584 |
+
),
|
| 585 |
+
(("Ancient Greek Numbers", (0x10140, 0x1018F)),),
|
| 586 |
+
(("Ugaritic", (0x10380, 0x1039F)),),
|
| 587 |
+
(("Old Persian", (0x103A0, 0x103DF)),),
|
| 588 |
+
(("Shavian", (0x10450, 0x1047F)),),
|
| 589 |
+
(("Osmanya", (0x10480, 0x104AF)),),
|
| 590 |
+
(("Cypriot Syllabary", (0x10800, 0x1083F)),),
|
| 591 |
+
(("Kharoshthi", (0x10A00, 0x10A5F)),),
|
| 592 |
+
(("Tai Xuan Jing Symbols", (0x1D300, 0x1D35F)),),
|
| 593 |
+
(
|
| 594 |
+
("Cuneiform", (0x12000, 0x123FF)),
|
| 595 |
+
("Cuneiform Numbers and Punctuation", (0x12400, 0x1247F)),
|
| 596 |
+
),
|
| 597 |
+
(("Counting Rod Numerals", (0x1D360, 0x1D37F)),),
|
| 598 |
+
(("Sundanese", (0x1B80, 0x1BBF)),),
|
| 599 |
+
(("Lepcha", (0x1C00, 0x1C4F)),),
|
| 600 |
+
(("Ol Chiki", (0x1C50, 0x1C7F)),),
|
| 601 |
+
(("Saurashtra", (0xA880, 0xA8DF)),),
|
| 602 |
+
(("Kayah Li", (0xA900, 0xA92F)),),
|
| 603 |
+
(("Rejang", (0xA930, 0xA95F)),),
|
| 604 |
+
(("Cham", (0xAA00, 0xAA5F)),),
|
| 605 |
+
(("Ancient Symbols", (0x10190, 0x101CF)),),
|
| 606 |
+
(("Phaistos Disc", (0x101D0, 0x101FF)),),
|
| 607 |
+
(
|
| 608 |
+
("Carian", (0x102A0, 0x102DF)),
|
| 609 |
+
("Lycian", (0x10280, 0x1029F)),
|
| 610 |
+
("Lydian", (0x10920, 0x1093F)),
|
| 611 |
+
),
|
| 612 |
+
(("Domino Tiles", (0x1F030, 0x1F09F)), ("Mahjong Tiles", (0x1F000, 0x1F02F))),
|
| 613 |
+
)
|
| 614 |
+
|
| 615 |
+
|
| 616 |
+
_unicodeStarts = []
|
| 617 |
+
_unicodeValues = [None]
|
| 618 |
+
|
| 619 |
+
|
| 620 |
+
def _getUnicodeRanges():
|
| 621 |
+
# build the ranges of codepoints for each unicode range bit, and cache result
|
| 622 |
+
if not _unicodeStarts:
|
| 623 |
+
unicodeRanges = [
|
| 624 |
+
(start, (stop, bit))
|
| 625 |
+
for bit, blocks in enumerate(OS2_UNICODE_RANGES)
|
| 626 |
+
for _, (start, stop) in blocks
|
| 627 |
+
]
|
| 628 |
+
for start, (stop, bit) in sorted(unicodeRanges):
|
| 629 |
+
_unicodeStarts.append(start)
|
| 630 |
+
_unicodeValues.append((stop, bit))
|
| 631 |
+
return _unicodeStarts, _unicodeValues
|
| 632 |
+
|
| 633 |
+
|
| 634 |
+
def intersectUnicodeRanges(unicodes, inverse=False):
|
| 635 |
+
"""Intersect a sequence of (int) Unicode codepoints with the Unicode block
|
| 636 |
+
ranges defined in the OpenType specification v1.7, and return the set of
|
| 637 |
+
'ulUnicodeRanges' bits for which there is at least ONE intersection.
|
| 638 |
+
If 'inverse' is True, return the the bits for which there is NO intersection.
|
| 639 |
+
|
| 640 |
+
>>> intersectUnicodeRanges([0x0410]) == {9}
|
| 641 |
+
True
|
| 642 |
+
>>> intersectUnicodeRanges([0x0410, 0x1F000]) == {9, 57, 122}
|
| 643 |
+
True
|
| 644 |
+
>>> intersectUnicodeRanges([0x0410, 0x1F000], inverse=True) == (
|
| 645 |
+
... set(range(len(OS2_UNICODE_RANGES))) - {9, 57, 122})
|
| 646 |
+
True
|
| 647 |
+
"""
|
| 648 |
+
unicodes = set(unicodes)
|
| 649 |
+
unicodestarts, unicodevalues = _getUnicodeRanges()
|
| 650 |
+
bits = set()
|
| 651 |
+
for code in unicodes:
|
| 652 |
+
stop, bit = unicodevalues[bisect.bisect(unicodestarts, code)]
|
| 653 |
+
if code <= stop:
|
| 654 |
+
bits.add(bit)
|
| 655 |
+
# The spec says that bit 57 ("Non Plane 0") implies that there's
|
| 656 |
+
# at least one codepoint beyond the BMP; so I also include all
|
| 657 |
+
# the non-BMP codepoints here
|
| 658 |
+
if any(0x10000 <= code < 0x110000 for code in unicodes):
|
| 659 |
+
bits.add(57)
|
| 660 |
+
return set(range(len(OS2_UNICODE_RANGES))) - bits if inverse else bits
|
| 661 |
+
|
| 662 |
+
|
| 663 |
+
def calcCodePageRanges(unicodes):
|
| 664 |
+
"""Given a set of Unicode codepoints (integers), calculate the
|
| 665 |
+
corresponding OS/2 CodePage range bits.
|
| 666 |
+
This is a direct translation of FontForge implementation:
|
| 667 |
+
https://github.com/fontforge/fontforge/blob/7b2c074/fontforge/tottf.c#L3158
|
| 668 |
+
"""
|
| 669 |
+
bits = set()
|
| 670 |
+
hasAscii = set(range(0x20, 0x7E)).issubset(unicodes)
|
| 671 |
+
hasLineart = ord("┤") in unicodes
|
| 672 |
+
|
| 673 |
+
for uni in unicodes:
|
| 674 |
+
if uni == ord("Þ") and hasAscii:
|
| 675 |
+
bits.add(0) # Latin 1
|
| 676 |
+
elif uni == ord("Ľ") and hasAscii:
|
| 677 |
+
bits.add(1) # Latin 2: Eastern Europe
|
| 678 |
+
if hasLineart:
|
| 679 |
+
bits.add(58) # Latin 2
|
| 680 |
+
elif uni == ord("Б"):
|
| 681 |
+
bits.add(2) # Cyrillic
|
| 682 |
+
if ord("Ѕ") in unicodes and hasLineart:
|
| 683 |
+
bits.add(57) # IBM Cyrillic
|
| 684 |
+
if ord("╜") in unicodes and hasLineart:
|
| 685 |
+
bits.add(49) # MS-DOS Russian
|
| 686 |
+
elif uni == ord("Ά"):
|
| 687 |
+
bits.add(3) # Greek
|
| 688 |
+
if hasLineart and ord("½") in unicodes:
|
| 689 |
+
bits.add(48) # IBM Greek
|
| 690 |
+
if hasLineart and ord("√") in unicodes:
|
| 691 |
+
bits.add(60) # Greek, former 437 G
|
| 692 |
+
elif uni == ord("İ") and hasAscii:
|
| 693 |
+
bits.add(4) # Turkish
|
| 694 |
+
if hasLineart:
|
| 695 |
+
bits.add(56) # IBM turkish
|
| 696 |
+
elif uni == ord("א"):
|
| 697 |
+
bits.add(5) # Hebrew
|
| 698 |
+
if hasLineart and ord("√") in unicodes:
|
| 699 |
+
bits.add(53) # Hebrew
|
| 700 |
+
elif uni == ord("ر"):
|
| 701 |
+
bits.add(6) # Arabic
|
| 702 |
+
if ord("√") in unicodes:
|
| 703 |
+
bits.add(51) # Arabic
|
| 704 |
+
if hasLineart:
|
| 705 |
+
bits.add(61) # Arabic; ASMO 708
|
| 706 |
+
elif uni == ord("ŗ") and hasAscii:
|
| 707 |
+
bits.add(7) # Windows Baltic
|
| 708 |
+
if hasLineart:
|
| 709 |
+
bits.add(59) # MS-DOS Baltic
|
| 710 |
+
elif uni == ord("₫") and hasAscii:
|
| 711 |
+
bits.add(8) # Vietnamese
|
| 712 |
+
elif uni == ord("ๅ"):
|
| 713 |
+
bits.add(16) # Thai
|
| 714 |
+
elif uni == ord("エ"):
|
| 715 |
+
bits.add(17) # JIS/Japan
|
| 716 |
+
elif uni == ord("ㄅ"):
|
| 717 |
+
bits.add(18) # Chinese: Simplified
|
| 718 |
+
elif uni == ord("ㄱ"):
|
| 719 |
+
bits.add(19) # Korean wansung
|
| 720 |
+
elif uni == ord("央"):
|
| 721 |
+
bits.add(20) # Chinese: Traditional
|
| 722 |
+
elif uni == ord("곴"):
|
| 723 |
+
bits.add(21) # Korean Johab
|
| 724 |
+
elif uni == ord("♥") and hasAscii:
|
| 725 |
+
bits.add(30) # OEM Character Set
|
| 726 |
+
# TODO: Symbol bit has a special meaning (check the spec), we need
|
| 727 |
+
# to confirm if this is wanted by default.
|
| 728 |
+
# elif chr(0xF000) <= char <= chr(0xF0FF):
|
| 729 |
+
# codepageRanges.add(31) # Symbol Character Set
|
| 730 |
+
elif uni == ord("þ") and hasAscii and hasLineart:
|
| 731 |
+
bits.add(54) # MS-DOS Icelandic
|
| 732 |
+
elif uni == ord("╚") and hasAscii:
|
| 733 |
+
bits.add(62) # WE/Latin 1
|
| 734 |
+
bits.add(63) # US
|
| 735 |
+
elif hasAscii and hasLineart and ord("√") in unicodes:
|
| 736 |
+
if uni == ord("Å"):
|
| 737 |
+
bits.add(50) # MS-DOS Nordic
|
| 738 |
+
elif uni == ord("é"):
|
| 739 |
+
bits.add(52) # MS-DOS Canadian French
|
| 740 |
+
elif uni == ord("õ"):
|
| 741 |
+
bits.add(55) # MS-DOS Portuguese
|
| 742 |
+
|
| 743 |
+
if hasAscii and ord("‰") in unicodes and ord("∑") in unicodes:
|
| 744 |
+
bits.add(29) # Macintosh Character Set (US Roman)
|
| 745 |
+
|
| 746 |
+
return bits
|
| 747 |
+
|
| 748 |
+
|
| 749 |
+
if __name__ == "__main__":
|
| 750 |
+
import doctest, sys
|
| 751 |
+
|
| 752 |
+
sys.exit(doctest.testmod().failed)
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/S_T_A_T_.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .otBase import BaseTTXConverter
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class table_S_T_A_T_(BaseTTXConverter):
|
| 5 |
+
"""Style Attributes table
|
| 6 |
+
|
| 7 |
+
The ``STAT`` table records stylistic or typeface-design attributes that
|
| 8 |
+
differentiate the individual fonts within a font family from one another.
|
| 9 |
+
Those attributes can be used to assist users when navigating the style
|
| 10 |
+
variations of a variable font or a family of static fonts.
|
| 11 |
+
|
| 12 |
+
See also https://learn.microsoft.com/en-us/typography/opentype/spec/stat
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
pass
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/S__i_l_l.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.misc import sstruct
|
| 2 |
+
from fontTools.misc.fixedTools import floatToFixedToStr
|
| 3 |
+
from fontTools.misc.textTools import safeEval
|
| 4 |
+
from . import DefaultTable
|
| 5 |
+
from . import grUtils
|
| 6 |
+
import struct
|
| 7 |
+
|
| 8 |
+
Sill_hdr = """
|
| 9 |
+
>
|
| 10 |
+
version: 16.16F
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class table_S__i_l_l(DefaultTable.DefaultTable):
|
| 15 |
+
"""Graphite Languages table
|
| 16 |
+
|
| 17 |
+
See also https://graphite.sil.org/graphite_techAbout#graphite-font-tables
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
def __init__(self, tag=None):
|
| 21 |
+
DefaultTable.DefaultTable.__init__(self, tag)
|
| 22 |
+
self.langs = {}
|
| 23 |
+
|
| 24 |
+
def decompile(self, data, ttFont):
|
| 25 |
+
(_, data) = sstruct.unpack2(Sill_hdr, data, self)
|
| 26 |
+
self.version = float(floatToFixedToStr(self.version, precisionBits=16))
|
| 27 |
+
(numLangs,) = struct.unpack(">H", data[:2])
|
| 28 |
+
data = data[8:]
|
| 29 |
+
maxsetting = 0
|
| 30 |
+
langinfo = []
|
| 31 |
+
for i in range(numLangs):
|
| 32 |
+
(langcode, numsettings, offset) = struct.unpack(
|
| 33 |
+
">4sHH", data[i * 8 : (i + 1) * 8]
|
| 34 |
+
)
|
| 35 |
+
offset = int(offset / 8) - (numLangs + 1)
|
| 36 |
+
langcode = langcode.replace(b"\000", b"")
|
| 37 |
+
langinfo.append((langcode.decode("utf-8"), numsettings, offset))
|
| 38 |
+
maxsetting = max(maxsetting, offset + numsettings)
|
| 39 |
+
data = data[numLangs * 8 :]
|
| 40 |
+
finfo = []
|
| 41 |
+
for i in range(maxsetting):
|
| 42 |
+
(fid, val, _) = struct.unpack(">LHH", data[i * 8 : (i + 1) * 8])
|
| 43 |
+
finfo.append((fid, val))
|
| 44 |
+
self.langs = {}
|
| 45 |
+
for c, n, o in langinfo:
|
| 46 |
+
self.langs[c] = []
|
| 47 |
+
for i in range(o, o + n):
|
| 48 |
+
self.langs[c].append(finfo[i])
|
| 49 |
+
|
| 50 |
+
def compile(self, ttFont):
|
| 51 |
+
ldat = b""
|
| 52 |
+
fdat = b""
|
| 53 |
+
offset = len(self.langs)
|
| 54 |
+
for c, inf in sorted(self.langs.items()):
|
| 55 |
+
ldat += struct.pack(">4sHH", c.encode("utf8"), len(inf), 8 * offset + 20)
|
| 56 |
+
for fid, val in inf:
|
| 57 |
+
fdat += struct.pack(">LHH", fid, val, 0)
|
| 58 |
+
offset += len(inf)
|
| 59 |
+
ldat += struct.pack(">LHH", 0x80808080, 0, 8 * offset + 20)
|
| 60 |
+
return (
|
| 61 |
+
sstruct.pack(Sill_hdr, self)
|
| 62 |
+
+ grUtils.bininfo(len(self.langs))
|
| 63 |
+
+ ldat
|
| 64 |
+
+ fdat
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
def toXML(self, writer, ttFont):
|
| 68 |
+
writer.simpletag("version", version=self.version)
|
| 69 |
+
writer.newline()
|
| 70 |
+
for c, inf in sorted(self.langs.items()):
|
| 71 |
+
writer.begintag("lang", name=c)
|
| 72 |
+
writer.newline()
|
| 73 |
+
for fid, val in inf:
|
| 74 |
+
writer.simpletag("feature", fid=grUtils.num2tag(fid), val=val)
|
| 75 |
+
writer.newline()
|
| 76 |
+
writer.endtag("lang")
|
| 77 |
+
writer.newline()
|
| 78 |
+
|
| 79 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 80 |
+
if name == "version":
|
| 81 |
+
self.version = float(safeEval(attrs["version"]))
|
| 82 |
+
elif name == "lang":
|
| 83 |
+
c = attrs["name"]
|
| 84 |
+
self.langs[c] = []
|
| 85 |
+
for element in content:
|
| 86 |
+
if not isinstance(element, tuple):
|
| 87 |
+
continue
|
| 88 |
+
tag, a, subcontent = element
|
| 89 |
+
if tag == "feature":
|
| 90 |
+
self.langs[c].append(
|
| 91 |
+
(grUtils.tag2num(a["fid"]), int(safeEval(a["val"])))
|
| 92 |
+
)
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I_C_.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" TSI{B,C,D,J,P,S,V} are private tables used by Microsoft Visual TrueType (VTT)
|
| 2 |
+
tool to store its table source data.
|
| 3 |
+
|
| 4 |
+
TSIC contains the source text for the Variation CVT window and data for
|
| 5 |
+
the ``cvar`` table.
|
| 6 |
+
|
| 7 |
+
See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from .otBase import BaseTTXConverter
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class table_T_S_I_C_(BaseTTXConverter):
|
| 14 |
+
pass
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I_S_.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" TSI{B,C,D,J,P,S,V} are private tables used by Microsoft Visual TrueType (VTT)
|
| 2 |
+
tool to store its table source data.
|
| 3 |
+
|
| 4 |
+
TSIS contains the source text for the ``GSUB`` table.
|
| 5 |
+
|
| 6 |
+
See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from .T_S_I_V_ import table_T_S_I_V_
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class table_T_S_I_S_(table_T_S_I_V_):
|
| 13 |
+
pass
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__0.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT)
|
| 2 |
+
tool to store its hinting source data.
|
| 3 |
+
|
| 4 |
+
TSI0 is the index table containing the lengths and offsets for the glyph
|
| 5 |
+
programs and 'extra' programs ('fpgm', 'prep', and 'cvt') that are contained
|
| 6 |
+
in the TSI1 table.
|
| 7 |
+
|
| 8 |
+
See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import logging
|
| 12 |
+
import struct
|
| 13 |
+
|
| 14 |
+
from . import DefaultTable
|
| 15 |
+
|
| 16 |
+
log = logging.getLogger(__name__)
|
| 17 |
+
|
| 18 |
+
tsi0Format = ">HHL"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def fixlongs(glyphID, textLength, textOffset):
|
| 22 |
+
return int(glyphID), int(textLength), textOffset
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class table_T_S_I__0(DefaultTable.DefaultTable):
|
| 26 |
+
dependencies = ["TSI1"]
|
| 27 |
+
|
| 28 |
+
def decompile(self, data, ttFont):
|
| 29 |
+
numGlyphs = ttFont["maxp"].numGlyphs
|
| 30 |
+
indices = []
|
| 31 |
+
size = struct.calcsize(tsi0Format)
|
| 32 |
+
numEntries = len(data) // size
|
| 33 |
+
if numEntries != numGlyphs + 5:
|
| 34 |
+
diff = numEntries - numGlyphs - 5
|
| 35 |
+
log.warning(
|
| 36 |
+
"Number of glyphPrograms differs from the number of glyphs in the font "
|
| 37 |
+
f"by {abs(diff)} ({numEntries - 5} programs vs. {numGlyphs} glyphs)."
|
| 38 |
+
)
|
| 39 |
+
for _ in range(numEntries):
|
| 40 |
+
glyphID, textLength, textOffset = fixlongs(
|
| 41 |
+
*struct.unpack(tsi0Format, data[:size])
|
| 42 |
+
)
|
| 43 |
+
indices.append((glyphID, textLength, textOffset))
|
| 44 |
+
data = data[size:]
|
| 45 |
+
assert len(data) == 0
|
| 46 |
+
assert indices[-5] == (0xFFFE, 0, 0xABFC1F34), "bad magic number"
|
| 47 |
+
self.indices = indices[:-5]
|
| 48 |
+
self.extra_indices = indices[-4:]
|
| 49 |
+
|
| 50 |
+
def compile(self, ttFont):
|
| 51 |
+
if not hasattr(self, "indices"):
|
| 52 |
+
# We have no corresponding table (TSI1 or TSI3); let's return
|
| 53 |
+
# no data, which effectively means "ignore us".
|
| 54 |
+
return b""
|
| 55 |
+
data = b""
|
| 56 |
+
for index, textLength, textOffset in self.indices:
|
| 57 |
+
data = data + struct.pack(tsi0Format, index, textLength, textOffset)
|
| 58 |
+
data = data + struct.pack(tsi0Format, 0xFFFE, 0, 0xABFC1F34)
|
| 59 |
+
for index, textLength, textOffset in self.extra_indices:
|
| 60 |
+
data = data + struct.pack(tsi0Format, index, textLength, textOffset)
|
| 61 |
+
return data
|
| 62 |
+
|
| 63 |
+
def set(self, indices, extra_indices):
|
| 64 |
+
# gets called by 'TSI1' or 'TSI3'
|
| 65 |
+
self.indices = indices
|
| 66 |
+
self.extra_indices = extra_indices
|
| 67 |
+
|
| 68 |
+
def toXML(self, writer, ttFont):
|
| 69 |
+
writer.comment("This table will be calculated by the compiler")
|
| 70 |
+
writer.newline()
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__1.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT)
|
| 2 |
+
tool to store its hinting source data.
|
| 3 |
+
|
| 4 |
+
TSI1 contains the text of the glyph programs in the form of low-level assembly
|
| 5 |
+
code, as well as the 'extra' programs 'fpgm', 'ppgm' (i.e. 'prep'), and 'cvt'.
|
| 6 |
+
|
| 7 |
+
See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from . import DefaultTable
|
| 11 |
+
from fontTools.misc.loggingTools import LogMixin
|
| 12 |
+
from fontTools.misc.textTools import strjoin, tobytes, tostr
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class table_T_S_I__1(LogMixin, DefaultTable.DefaultTable):
|
| 16 |
+
extras = {0xFFFA: "ppgm", 0xFFFB: "cvt", 0xFFFC: "reserved", 0xFFFD: "fpgm"}
|
| 17 |
+
|
| 18 |
+
indextable = "TSI0"
|
| 19 |
+
|
| 20 |
+
def decompile(self, data, ttFont):
|
| 21 |
+
totalLength = len(data)
|
| 22 |
+
indextable = ttFont[self.indextable]
|
| 23 |
+
for indices, isExtra in zip(
|
| 24 |
+
(indextable.indices, indextable.extra_indices), (False, True)
|
| 25 |
+
):
|
| 26 |
+
programs = {}
|
| 27 |
+
for i, (glyphID, textLength, textOffset) in enumerate(indices):
|
| 28 |
+
if isExtra:
|
| 29 |
+
name = self.extras[glyphID]
|
| 30 |
+
else:
|
| 31 |
+
name = ttFont.getGlyphName(glyphID)
|
| 32 |
+
if textOffset > totalLength:
|
| 33 |
+
self.log.warning("textOffset > totalLength; %r skipped" % name)
|
| 34 |
+
continue
|
| 35 |
+
if textLength < 0x8000:
|
| 36 |
+
# If the length stored in the record is less than 32768, then use
|
| 37 |
+
# that as the length of the record.
|
| 38 |
+
pass
|
| 39 |
+
elif textLength == 0x8000:
|
| 40 |
+
# If the length is 32768, compute the actual length as follows:
|
| 41 |
+
isLast = i == (len(indices) - 1)
|
| 42 |
+
if isLast:
|
| 43 |
+
if isExtra:
|
| 44 |
+
# For the last "extra" record (the very last record of the
|
| 45 |
+
# table), the length is the difference between the total
|
| 46 |
+
# length of the TSI1 table and the textOffset of the final
|
| 47 |
+
# record.
|
| 48 |
+
nextTextOffset = totalLength
|
| 49 |
+
else:
|
| 50 |
+
# For the last "normal" record (the last record just prior
|
| 51 |
+
# to the record containing the "magic number"), the length
|
| 52 |
+
# is the difference between the textOffset of the record
|
| 53 |
+
# following the "magic number" (0xFFFE) record (i.e. the
|
| 54 |
+
# first "extra" record), and the textOffset of the last
|
| 55 |
+
# "normal" record.
|
| 56 |
+
nextTextOffset = indextable.extra_indices[0][2]
|
| 57 |
+
else:
|
| 58 |
+
# For all other records with a length of 0x8000, the length is
|
| 59 |
+
# the difference between the textOffset of the record in
|
| 60 |
+
# question and the textOffset of the next record.
|
| 61 |
+
nextTextOffset = indices[i + 1][2]
|
| 62 |
+
assert nextTextOffset >= textOffset, "entries not sorted by offset"
|
| 63 |
+
if nextTextOffset > totalLength:
|
| 64 |
+
self.log.warning(
|
| 65 |
+
"nextTextOffset > totalLength; %r truncated" % name
|
| 66 |
+
)
|
| 67 |
+
nextTextOffset = totalLength
|
| 68 |
+
textLength = nextTextOffset - textOffset
|
| 69 |
+
else:
|
| 70 |
+
from fontTools import ttLib
|
| 71 |
+
|
| 72 |
+
raise ttLib.TTLibError(
|
| 73 |
+
"%r textLength (%d) must not be > 32768" % (name, textLength)
|
| 74 |
+
)
|
| 75 |
+
text = data[textOffset : textOffset + textLength]
|
| 76 |
+
assert len(text) == textLength
|
| 77 |
+
text = tostr(text, encoding="utf-8")
|
| 78 |
+
if text:
|
| 79 |
+
programs[name] = text
|
| 80 |
+
if isExtra:
|
| 81 |
+
self.extraPrograms = programs
|
| 82 |
+
else:
|
| 83 |
+
self.glyphPrograms = programs
|
| 84 |
+
|
| 85 |
+
def compile(self, ttFont):
|
| 86 |
+
if not hasattr(self, "glyphPrograms"):
|
| 87 |
+
self.glyphPrograms = {}
|
| 88 |
+
self.extraPrograms = {}
|
| 89 |
+
data = b""
|
| 90 |
+
indextable = ttFont[self.indextable]
|
| 91 |
+
glyphNames = ttFont.getGlyphOrder()
|
| 92 |
+
|
| 93 |
+
indices = []
|
| 94 |
+
for i, name in enumerate(glyphNames):
|
| 95 |
+
if len(data) % 2:
|
| 96 |
+
data = (
|
| 97 |
+
data + b"\015"
|
| 98 |
+
) # align on 2-byte boundaries, fill with return chars. Yum.
|
| 99 |
+
if name in self.glyphPrograms:
|
| 100 |
+
text = tobytes(self.glyphPrograms[name], encoding="utf-8")
|
| 101 |
+
else:
|
| 102 |
+
text = b""
|
| 103 |
+
textLength = len(text)
|
| 104 |
+
if textLength >= 0x8000:
|
| 105 |
+
textLength = 0x8000
|
| 106 |
+
indices.append((i, textLength, len(data)))
|
| 107 |
+
data = data + text
|
| 108 |
+
|
| 109 |
+
extra_indices = []
|
| 110 |
+
for code, name in sorted(self.extras.items()):
|
| 111 |
+
if len(data) % 2:
|
| 112 |
+
data = (
|
| 113 |
+
data + b"\015"
|
| 114 |
+
) # align on 2-byte boundaries, fill with return chars.
|
| 115 |
+
if name in self.extraPrograms:
|
| 116 |
+
text = tobytes(self.extraPrograms[name], encoding="utf-8")
|
| 117 |
+
else:
|
| 118 |
+
text = b""
|
| 119 |
+
textLength = len(text)
|
| 120 |
+
if textLength >= 0x8000:
|
| 121 |
+
textLength = 0x8000
|
| 122 |
+
extra_indices.append((code, textLength, len(data)))
|
| 123 |
+
data = data + text
|
| 124 |
+
indextable.set(indices, extra_indices)
|
| 125 |
+
return data
|
| 126 |
+
|
| 127 |
+
def toXML(self, writer, ttFont):
|
| 128 |
+
names = sorted(self.glyphPrograms.keys())
|
| 129 |
+
writer.newline()
|
| 130 |
+
for name in names:
|
| 131 |
+
text = self.glyphPrograms[name]
|
| 132 |
+
if not text:
|
| 133 |
+
continue
|
| 134 |
+
writer.begintag("glyphProgram", name=name)
|
| 135 |
+
writer.newline()
|
| 136 |
+
writer.write_noindent(text.replace("\r", "\n"))
|
| 137 |
+
writer.newline()
|
| 138 |
+
writer.endtag("glyphProgram")
|
| 139 |
+
writer.newline()
|
| 140 |
+
writer.newline()
|
| 141 |
+
extra_names = sorted(self.extraPrograms.keys())
|
| 142 |
+
for name in extra_names:
|
| 143 |
+
text = self.extraPrograms[name]
|
| 144 |
+
if not text:
|
| 145 |
+
continue
|
| 146 |
+
writer.begintag("extraProgram", name=name)
|
| 147 |
+
writer.newline()
|
| 148 |
+
writer.write_noindent(text.replace("\r", "\n"))
|
| 149 |
+
writer.newline()
|
| 150 |
+
writer.endtag("extraProgram")
|
| 151 |
+
writer.newline()
|
| 152 |
+
writer.newline()
|
| 153 |
+
|
| 154 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 155 |
+
if not hasattr(self, "glyphPrograms"):
|
| 156 |
+
self.glyphPrograms = {}
|
| 157 |
+
self.extraPrograms = {}
|
| 158 |
+
lines = strjoin(content).replace("\r", "\n").split("\n")
|
| 159 |
+
text = "\r".join(lines[1:-1])
|
| 160 |
+
if name == "glyphProgram":
|
| 161 |
+
self.glyphPrograms[attrs["name"]] = text
|
| 162 |
+
elif name == "extraProgram":
|
| 163 |
+
self.extraPrograms[attrs["name"]] = text
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__2.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT)
|
| 2 |
+
tool to store its hinting source data.
|
| 3 |
+
|
| 4 |
+
TSI2 is the index table containing the lengths and offsets for the glyph
|
| 5 |
+
programs that are contained in the TSI3 table. It uses the same format as
|
| 6 |
+
the TSI0 table.
|
| 7 |
+
|
| 8 |
+
See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from fontTools import ttLib
|
| 12 |
+
|
| 13 |
+
superclass = ttLib.getTableClass("TSI0")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class table_T_S_I__2(superclass):
|
| 17 |
+
dependencies = ["TSI3"]
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__3.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT)
|
| 2 |
+
tool to store its hinting source data.
|
| 3 |
+
|
| 4 |
+
TSI3 contains the text of the glyph programs in the form of 'VTTTalk' code.
|
| 5 |
+
|
| 6 |
+
See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from fontTools import ttLib
|
| 10 |
+
|
| 11 |
+
superclass = ttLib.getTableClass("TSI1")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class table_T_S_I__3(superclass):
|
| 15 |
+
extras = {
|
| 16 |
+
0xFFFA: "reserved0",
|
| 17 |
+
0xFFFB: "reserved1",
|
| 18 |
+
0xFFFC: "reserved2",
|
| 19 |
+
0xFFFD: "reserved3",
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
indextable = "TSI2"
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/T_S_I__5.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT)
|
| 2 |
+
tool to store its hinting source data.
|
| 3 |
+
|
| 4 |
+
TSI5 contains the VTT character groups.
|
| 5 |
+
|
| 6 |
+
See also https://learn.microsoft.com/en-us/typography/tools/vtt/tsi-tables
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import array
|
| 10 |
+
import logging
|
| 11 |
+
import sys
|
| 12 |
+
|
| 13 |
+
from fontTools.misc.textTools import safeEval
|
| 14 |
+
|
| 15 |
+
from . import DefaultTable
|
| 16 |
+
|
| 17 |
+
log = logging.getLogger(__name__)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class table_T_S_I__5(DefaultTable.DefaultTable):
|
| 21 |
+
def decompile(self, data, ttFont):
|
| 22 |
+
numGlyphs = ttFont["maxp"].numGlyphs
|
| 23 |
+
a = array.array("H")
|
| 24 |
+
a.frombytes(data)
|
| 25 |
+
if sys.byteorder != "big":
|
| 26 |
+
a.byteswap()
|
| 27 |
+
self.glyphGrouping = {}
|
| 28 |
+
numEntries = len(data) // 2
|
| 29 |
+
if numEntries != numGlyphs:
|
| 30 |
+
diff = numEntries - numGlyphs
|
| 31 |
+
log.warning(
|
| 32 |
+
"Number of entries differs from the number of glyphs in the font "
|
| 33 |
+
f"by {abs(diff)} ({numEntries} entries vs. {numGlyphs} glyphs)."
|
| 34 |
+
)
|
| 35 |
+
for i in range(numEntries):
|
| 36 |
+
self.glyphGrouping[ttFont.getGlyphName(i)] = a[i]
|
| 37 |
+
|
| 38 |
+
def compile(self, ttFont):
|
| 39 |
+
glyphNames = ttFont.getGlyphOrder()
|
| 40 |
+
a = array.array("H")
|
| 41 |
+
for glyphName in glyphNames:
|
| 42 |
+
a.append(self.glyphGrouping.get(glyphName, 0))
|
| 43 |
+
if sys.byteorder != "big":
|
| 44 |
+
a.byteswap()
|
| 45 |
+
return a.tobytes()
|
| 46 |
+
|
| 47 |
+
def toXML(self, writer, ttFont):
|
| 48 |
+
names = sorted(self.glyphGrouping.keys())
|
| 49 |
+
for glyphName in names:
|
| 50 |
+
writer.simpletag(
|
| 51 |
+
"glyphgroup", name=glyphName, value=self.glyphGrouping[glyphName]
|
| 52 |
+
)
|
| 53 |
+
writer.newline()
|
| 54 |
+
|
| 55 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 56 |
+
if not hasattr(self, "glyphGrouping"):
|
| 57 |
+
self.glyphGrouping = {}
|
| 58 |
+
if name != "glyphgroup":
|
| 59 |
+
return
|
| 60 |
+
self.glyphGrouping[attrs["name"]] = safeEval(attrs["value"])
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/V_A_R_C_.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .otBase import BaseTTXConverter
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class table_V_A_R_C_(BaseTTXConverter):
|
| 5 |
+
"""Variable Components table
|
| 6 |
+
|
| 7 |
+
The ``VARC`` table contains variation information for composite glyphs.
|
| 8 |
+
|
| 9 |
+
See also https://github.com/harfbuzz/boring-expansion-spec/blob/main/VARC.md
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
pass
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/V_O_R_G_.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.misc.textTools import bytesjoin, safeEval
|
| 2 |
+
from . import DefaultTable
|
| 3 |
+
import struct
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class table_V_O_R_G_(DefaultTable.DefaultTable):
|
| 7 |
+
"""Vertical Origin table
|
| 8 |
+
|
| 9 |
+
The ``VORG`` table contains the vertical origin of each glyph
|
| 10 |
+
in a `CFF` or `CFF2` font.
|
| 11 |
+
|
| 12 |
+
This table is structured so that you can treat it like a dictionary keyed by glyph name.
|
| 13 |
+
|
| 14 |
+
``ttFont['VORG'][<glyphName>]`` will return the vertical origin for any glyph.
|
| 15 |
+
|
| 16 |
+
``ttFont['VORG'][<glyphName>] = <value>`` will set the vertical origin for any glyph.
|
| 17 |
+
|
| 18 |
+
See also https://learn.microsoft.com/en-us/typography/opentype/spec/vorg
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
def decompile(self, data, ttFont):
|
| 22 |
+
self.getGlyphName = (
|
| 23 |
+
ttFont.getGlyphName
|
| 24 |
+
) # for use in get/set item functions, for access by GID
|
| 25 |
+
(
|
| 26 |
+
self.majorVersion,
|
| 27 |
+
self.minorVersion,
|
| 28 |
+
self.defaultVertOriginY,
|
| 29 |
+
self.numVertOriginYMetrics,
|
| 30 |
+
) = struct.unpack(">HHhH", data[:8])
|
| 31 |
+
assert (
|
| 32 |
+
self.majorVersion <= 1
|
| 33 |
+
), "Major version of VORG table is higher than I know how to handle"
|
| 34 |
+
data = data[8:]
|
| 35 |
+
vids = []
|
| 36 |
+
gids = []
|
| 37 |
+
pos = 0
|
| 38 |
+
for i in range(self.numVertOriginYMetrics):
|
| 39 |
+
gid, vOrigin = struct.unpack(">Hh", data[pos : pos + 4])
|
| 40 |
+
pos += 4
|
| 41 |
+
gids.append(gid)
|
| 42 |
+
vids.append(vOrigin)
|
| 43 |
+
|
| 44 |
+
self.VOriginRecords = vOrig = {}
|
| 45 |
+
glyphOrder = ttFont.getGlyphOrder()
|
| 46 |
+
try:
|
| 47 |
+
names = [glyphOrder[gid] for gid in gids]
|
| 48 |
+
except IndexError:
|
| 49 |
+
getGlyphName = self.getGlyphName
|
| 50 |
+
names = map(getGlyphName, gids)
|
| 51 |
+
|
| 52 |
+
for name, vid in zip(names, vids):
|
| 53 |
+
vOrig[name] = vid
|
| 54 |
+
|
| 55 |
+
def compile(self, ttFont):
|
| 56 |
+
vorgs = list(self.VOriginRecords.values())
|
| 57 |
+
names = list(self.VOriginRecords.keys())
|
| 58 |
+
nameMap = ttFont.getReverseGlyphMap()
|
| 59 |
+
try:
|
| 60 |
+
gids = [nameMap[name] for name in names]
|
| 61 |
+
except KeyError:
|
| 62 |
+
nameMap = ttFont.getReverseGlyphMap(rebuild=True)
|
| 63 |
+
gids = [nameMap[name] for name in names]
|
| 64 |
+
vOriginTable = list(zip(gids, vorgs))
|
| 65 |
+
self.numVertOriginYMetrics = len(vorgs)
|
| 66 |
+
vOriginTable.sort() # must be in ascending GID order
|
| 67 |
+
dataList = [struct.pack(">Hh", rec[0], rec[1]) for rec in vOriginTable]
|
| 68 |
+
header = struct.pack(
|
| 69 |
+
">HHhH",
|
| 70 |
+
self.majorVersion,
|
| 71 |
+
self.minorVersion,
|
| 72 |
+
self.defaultVertOriginY,
|
| 73 |
+
self.numVertOriginYMetrics,
|
| 74 |
+
)
|
| 75 |
+
dataList.insert(0, header)
|
| 76 |
+
data = bytesjoin(dataList)
|
| 77 |
+
return data
|
| 78 |
+
|
| 79 |
+
def toXML(self, writer, ttFont):
|
| 80 |
+
writer.simpletag("majorVersion", value=self.majorVersion)
|
| 81 |
+
writer.newline()
|
| 82 |
+
writer.simpletag("minorVersion", value=self.minorVersion)
|
| 83 |
+
writer.newline()
|
| 84 |
+
writer.simpletag("defaultVertOriginY", value=self.defaultVertOriginY)
|
| 85 |
+
writer.newline()
|
| 86 |
+
writer.simpletag("numVertOriginYMetrics", value=self.numVertOriginYMetrics)
|
| 87 |
+
writer.newline()
|
| 88 |
+
vOriginTable = []
|
| 89 |
+
glyphNames = self.VOriginRecords.keys()
|
| 90 |
+
for glyphName in glyphNames:
|
| 91 |
+
try:
|
| 92 |
+
gid = ttFont.getGlyphID(glyphName)
|
| 93 |
+
except:
|
| 94 |
+
assert 0, (
|
| 95 |
+
"VORG table contains a glyph name not in ttFont.getGlyphNames(): "
|
| 96 |
+
+ str(glyphName)
|
| 97 |
+
)
|
| 98 |
+
vOriginTable.append([gid, glyphName, self.VOriginRecords[glyphName]])
|
| 99 |
+
vOriginTable.sort()
|
| 100 |
+
for entry in vOriginTable:
|
| 101 |
+
vOriginRec = VOriginRecord(entry[1], entry[2])
|
| 102 |
+
vOriginRec.toXML(writer, ttFont)
|
| 103 |
+
|
| 104 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 105 |
+
if not hasattr(self, "VOriginRecords"):
|
| 106 |
+
self.VOriginRecords = {}
|
| 107 |
+
self.getGlyphName = (
|
| 108 |
+
ttFont.getGlyphName
|
| 109 |
+
) # for use in get/set item functions, for access by GID
|
| 110 |
+
if name == "VOriginRecord":
|
| 111 |
+
vOriginRec = VOriginRecord()
|
| 112 |
+
for element in content:
|
| 113 |
+
if isinstance(element, str):
|
| 114 |
+
continue
|
| 115 |
+
name, attrs, content = element
|
| 116 |
+
vOriginRec.fromXML(name, attrs, content, ttFont)
|
| 117 |
+
self.VOriginRecords[vOriginRec.glyphName] = vOriginRec.vOrigin
|
| 118 |
+
elif "value" in attrs:
|
| 119 |
+
setattr(self, name, safeEval(attrs["value"]))
|
| 120 |
+
|
| 121 |
+
def __getitem__(self, glyphSelector):
|
| 122 |
+
if isinstance(glyphSelector, int):
|
| 123 |
+
# its a gid, convert to glyph name
|
| 124 |
+
glyphSelector = self.getGlyphName(glyphSelector)
|
| 125 |
+
|
| 126 |
+
if glyphSelector not in self.VOriginRecords:
|
| 127 |
+
return self.defaultVertOriginY
|
| 128 |
+
|
| 129 |
+
return self.VOriginRecords[glyphSelector]
|
| 130 |
+
|
| 131 |
+
def __setitem__(self, glyphSelector, value):
|
| 132 |
+
if isinstance(glyphSelector, int):
|
| 133 |
+
# its a gid, convert to glyph name
|
| 134 |
+
glyphSelector = self.getGlyphName(glyphSelector)
|
| 135 |
+
|
| 136 |
+
if value != self.defaultVertOriginY:
|
| 137 |
+
self.VOriginRecords[glyphSelector] = value
|
| 138 |
+
elif glyphSelector in self.VOriginRecords:
|
| 139 |
+
del self.VOriginRecords[glyphSelector]
|
| 140 |
+
|
| 141 |
+
def __delitem__(self, glyphSelector):
|
| 142 |
+
del self.VOriginRecords[glyphSelector]
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
class VOriginRecord(object):
|
| 146 |
+
def __init__(self, name=None, vOrigin=None):
|
| 147 |
+
self.glyphName = name
|
| 148 |
+
self.vOrigin = vOrigin
|
| 149 |
+
|
| 150 |
+
def toXML(self, writer, ttFont):
|
| 151 |
+
writer.begintag("VOriginRecord")
|
| 152 |
+
writer.newline()
|
| 153 |
+
writer.simpletag("glyphName", value=self.glyphName)
|
| 154 |
+
writer.newline()
|
| 155 |
+
writer.simpletag("vOrigin", value=self.vOrigin)
|
| 156 |
+
writer.newline()
|
| 157 |
+
writer.endtag("VOriginRecord")
|
| 158 |
+
writer.newline()
|
| 159 |
+
|
| 160 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 161 |
+
value = attrs["value"]
|
| 162 |
+
if name == "glyphName":
|
| 163 |
+
setattr(self, name, value)
|
| 164 |
+
else:
|
| 165 |
+
setattr(self, name, safeEval(value))
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__init__.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# DON'T EDIT! This file is generated by MetaTools/buildTableList.py.
|
| 2 |
+
def _moduleFinderHint():
|
| 3 |
+
"""Dummy function to let modulefinder know what tables may be
|
| 4 |
+
dynamically imported. Generated by MetaTools/buildTableList.py.
|
| 5 |
+
|
| 6 |
+
>>> _moduleFinderHint()
|
| 7 |
+
"""
|
| 8 |
+
from . import B_A_S_E_
|
| 9 |
+
from . import C_B_D_T_
|
| 10 |
+
from . import C_B_L_C_
|
| 11 |
+
from . import C_F_F_
|
| 12 |
+
from . import C_F_F__2
|
| 13 |
+
from . import C_O_L_R_
|
| 14 |
+
from . import C_P_A_L_
|
| 15 |
+
from . import D_S_I_G_
|
| 16 |
+
from . import D__e_b_g
|
| 17 |
+
from . import E_B_D_T_
|
| 18 |
+
from . import E_B_L_C_
|
| 19 |
+
from . import F_F_T_M_
|
| 20 |
+
from . import F__e_a_t
|
| 21 |
+
from . import G_D_E_F_
|
| 22 |
+
from . import G_P_O_S_
|
| 23 |
+
from . import G_S_U_B_
|
| 24 |
+
from . import G_V_A_R_
|
| 25 |
+
from . import G__l_a_t
|
| 26 |
+
from . import G__l_o_c
|
| 27 |
+
from . import H_V_A_R_
|
| 28 |
+
from . import J_S_T_F_
|
| 29 |
+
from . import L_T_S_H_
|
| 30 |
+
from . import M_A_T_H_
|
| 31 |
+
from . import M_V_A_R_
|
| 32 |
+
from . import O_S_2f_2
|
| 33 |
+
from . import S_T_A_T_
|
| 34 |
+
from . import S_V_G_
|
| 35 |
+
from . import S__i_l_f
|
| 36 |
+
from . import S__i_l_l
|
| 37 |
+
from . import T_S_I_B_
|
| 38 |
+
from . import T_S_I_C_
|
| 39 |
+
from . import T_S_I_D_
|
| 40 |
+
from . import T_S_I_J_
|
| 41 |
+
from . import T_S_I_P_
|
| 42 |
+
from . import T_S_I_S_
|
| 43 |
+
from . import T_S_I_V_
|
| 44 |
+
from . import T_S_I__0
|
| 45 |
+
from . import T_S_I__1
|
| 46 |
+
from . import T_S_I__2
|
| 47 |
+
from . import T_S_I__3
|
| 48 |
+
from . import T_S_I__5
|
| 49 |
+
from . import T_T_F_A_
|
| 50 |
+
from . import V_A_R_C_
|
| 51 |
+
from . import V_D_M_X_
|
| 52 |
+
from . import V_O_R_G_
|
| 53 |
+
from . import V_V_A_R_
|
| 54 |
+
from . import _a_n_k_r
|
| 55 |
+
from . import _a_v_a_r
|
| 56 |
+
from . import _b_s_l_n
|
| 57 |
+
from . import _c_i_d_g
|
| 58 |
+
from . import _c_m_a_p
|
| 59 |
+
from . import _c_v_a_r
|
| 60 |
+
from . import _c_v_t
|
| 61 |
+
from . import _f_e_a_t
|
| 62 |
+
from . import _f_p_g_m
|
| 63 |
+
from . import _f_v_a_r
|
| 64 |
+
from . import _g_a_s_p
|
| 65 |
+
from . import _g_c_i_d
|
| 66 |
+
from . import _g_l_y_f
|
| 67 |
+
from . import _g_v_a_r
|
| 68 |
+
from . import _h_d_m_x
|
| 69 |
+
from . import _h_e_a_d
|
| 70 |
+
from . import _h_h_e_a
|
| 71 |
+
from . import _h_m_t_x
|
| 72 |
+
from . import _k_e_r_n
|
| 73 |
+
from . import _l_c_a_r
|
| 74 |
+
from . import _l_o_c_a
|
| 75 |
+
from . import _l_t_a_g
|
| 76 |
+
from . import _m_a_x_p
|
| 77 |
+
from . import _m_e_t_a
|
| 78 |
+
from . import _m_o_r_t
|
| 79 |
+
from . import _m_o_r_x
|
| 80 |
+
from . import _n_a_m_e
|
| 81 |
+
from . import _o_p_b_d
|
| 82 |
+
from . import _p_o_s_t
|
| 83 |
+
from . import _p_r_e_p
|
| 84 |
+
from . import _p_r_o_p
|
| 85 |
+
from . import _s_b_i_x
|
| 86 |
+
from . import _t_r_a_k
|
| 87 |
+
from . import _v_h_e_a
|
| 88 |
+
from . import _v_m_t_x
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
if __name__ == "__main__":
|
| 92 |
+
import doctest, sys
|
| 93 |
+
|
| 94 |
+
sys.exit(doctest.testmod().failed)
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/B_A_S_E_.cpython-311.pyc
ADDED
|
Binary file (809 Bytes). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_F_F_.cpython-311.pyc
ADDED
|
Binary file (3.95 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_F_F__2.cpython-311.pyc
ADDED
|
Binary file (1.78 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/C_P_A_L_.cpython-311.pyc
ADDED
|
Binary file (18.8 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/E_B_D_T_.cpython-311.pyc
ADDED
|
Binary file (40.4 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/E_B_L_C_.cpython-311.pyc
ADDED
|
Binary file (40.4 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/F_F_T_M_.cpython-311.pyc
ADDED
|
Binary file (2.99 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/F__e_a_t.cpython-311.pyc
ADDED
|
Binary file (9.32 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/G__l_a_t.cpython-311.pyc
ADDED
|
Binary file (14 kB). View file
|
|
|
data/miniconda3/envs/catiagent/lib/python3.11/site-packages/fontTools/ttLib/tables/__pycache__/H_V_A_R_.cpython-311.pyc
ADDED
|
Binary file (750 Bytes). View file
|
|
|