2021-03-29 11:45:58 +02:00
|
|
|
from io import BytesIO
|
2013-11-27 17:27:45 -05:00
|
|
|
from fontTools import cffLib
|
|
|
|
from . import DefaultTable
|
1999-12-16 21:34:53 +00:00
|
|
|
|
|
|
|
|
2002-05-03 14:33:41 +00:00
|
|
|
class table_C_F_F_(DefaultTable.DefaultTable):
|
2024-12-04 15:58:46 +00:00
|
|
|
"""Compact Font Format table (version 1)
|
|
|
|
|
|
|
|
The ``CFF`` table embeds a CFF-formatted font. The CFF font format
|
|
|
|
predates OpenType and could be used as a standalone font file, but the
|
|
|
|
``CFF`` table is also used to package CFF fonts into an OpenType
|
|
|
|
container.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
``CFF`` has been succeeded by ``CFF2``, which eliminates much of
|
|
|
|
the redundancy incurred by embedding CFF version 1 in an OpenType
|
|
|
|
font.
|
|
|
|
|
|
|
|
See also https://learn.microsoft.com/en-us/typography/opentype/spec/cff
|
|
|
|
"""
|
|
|
|
|
2016-04-21 23:42:13 -07:00
|
|
|
def __init__(self, tag=None):
|
1999-12-16 21:34:53 +00:00
|
|
|
DefaultTable.DefaultTable.__init__(self, tag)
|
2002-05-03 14:33:41 +00:00
|
|
|
self.cff = cffLib.CFFFontSet()
|
2013-12-04 21:28:50 -05:00
|
|
|
self._gaveGlyphOrder = False
|
2022-12-13 11:26:36 +00:00
|
|
|
|
1999-12-16 21:34:53 +00:00
|
|
|
def decompile(self, data, otFont):
|
2017-07-19 18:18:58 +01:00
|
|
|
self.cff.decompile(BytesIO(data), otFont, isCFF2=False)
|
2002-05-16 18:15:57 +00:00
|
|
|
assert len(self.cff) == 1, "can't deal with multi-font CFF tables."
|
2022-12-13 11:26:36 +00:00
|
|
|
|
2002-05-24 09:58:04 +00:00
|
|
|
def compile(self, otFont):
|
2015-08-07 16:16:49 +01:00
|
|
|
f = BytesIO()
|
2017-07-19 18:18:58 +01:00
|
|
|
self.cff.compile(f, otFont, isCFF2=False)
|
2002-05-24 09:58:04 +00:00
|
|
|
return f.getvalue()
|
2022-12-13 11:26:36 +00:00
|
|
|
|
2002-05-13 11:25:17 +00:00
|
|
|
def haveGlyphNames(self):
|
2002-05-16 18:15:57 +00:00
|
|
|
if hasattr(self.cff[self.cff.fontNames[0]], "ROS"):
|
2013-12-04 21:28:50 -05:00
|
|
|
return False # CID-keyed font
|
2002-05-13 11:25:17 +00:00
|
|
|
else:
|
2013-12-04 21:28:50 -05:00
|
|
|
return True
|
2022-12-13 11:26:36 +00:00
|
|
|
|
1999-12-16 21:34:53 +00:00
|
|
|
def getGlyphOrder(self):
|
|
|
|
if self._gaveGlyphOrder:
|
|
|
|
from fontTools import ttLib
|
2022-12-13 11:26:36 +00:00
|
|
|
|
2013-11-27 02:42:28 -05:00
|
|
|
raise ttLib.TTLibError("illegal use of getGlyphOrder()")
|
2013-12-04 21:28:50 -05:00
|
|
|
self._gaveGlyphOrder = True
|
2002-05-16 18:15:57 +00:00
|
|
|
return self.cff[self.cff.fontNames[0]].getGlyphOrder()
|
2022-12-13 11:26:36 +00:00
|
|
|
|
1999-12-16 21:34:53 +00:00
|
|
|
def setGlyphOrder(self, glyphOrder):
|
2002-05-16 18:15:57 +00:00
|
|
|
pass
|
|
|
|
# XXX
|
|
|
|
# self.cff[self.cff.fontNames[0]].setGlyphOrder(glyphOrder)
|
2022-12-13 11:26:36 +00:00
|
|
|
|
2018-01-25 17:30:23 -08:00
|
|
|
def toXML(self, writer, otFont):
|
|
|
|
self.cff.toXML(writer)
|
2022-12-13 11:26:36 +00:00
|
|
|
|
2013-11-27 03:19:32 -05:00
|
|
|
def fromXML(self, name, attrs, content, otFont):
|
2002-05-24 09:58:04 +00:00
|
|
|
if not hasattr(self, "cff"):
|
|
|
|
self.cff = cffLib.CFFFontSet()
|
2017-05-09 11:20:07 -07:00
|
|
|
self.cff.fromXML(name, attrs, content, otFont)
|