Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
1.9 KiB
Python
Raw Normal View History

from io import BytesIO
from fontTools import cffLib
from . import DefaultTable
class table_C_F_F_(DefaultTable.DefaultTable):
"""Compact Font Format table (version 1)
The ``CFF`` table embeds a CFF-formatted font. The CFF font format
predates OpenType and could be used as a standalone font file, but the
``CFF`` table is also used to package CFF fonts into an OpenType
container.
.. note::
``CFF`` has been succeeded by ``CFF2``, which eliminates much of
the redundancy incurred by embedding CFF version 1 in an OpenType
font.
See also https://learn.microsoft.com/en-us/typography/opentype/spec/cff
"""
def __init__(self, tag=None):
DefaultTable.DefaultTable.__init__(self, tag)
self.cff = cffLib.CFFFontSet()
2013-12-04 21:28:50 -05:00
self._gaveGlyphOrder = False
2022-12-13 11:26:36 +00:00
def decompile(self, data, otFont):
self.cff.decompile(BytesIO(data), otFont, isCFF2=False)
assert len(self.cff) == 1, "can't deal with multi-font CFF tables."
2022-12-13 11:26:36 +00:00
def compile(self, otFont):
2015-08-07 16:16:49 +01:00
f = BytesIO()
self.cff.compile(f, otFont, isCFF2=False)
return f.getvalue()
2022-12-13 11:26:36 +00:00
def haveGlyphNames(self):
if hasattr(self.cff[self.cff.fontNames[0]], "ROS"):
2013-12-04 21:28:50 -05:00
return False # CID-keyed font
else:
2013-12-04 21:28:50 -05:00
return True
2022-12-13 11:26:36 +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
return self.cff[self.cff.fontNames[0]].getGlyphOrder()
2022-12-13 11:26:36 +00:00
def setGlyphOrder(self, glyphOrder):
pass
# XXX
# self.cff[self.cff.fontNames[0]].setGlyphOrder(glyphOrder)
2022-12-13 11:26:36 +00:00
def toXML(self, writer, otFont):
self.cff.toXML(writer)
2022-12-13 11:26:36 +00:00
def fromXML(self, name, attrs, content, otFont):
if not hasattr(self, "cff"):
self.cff = cffLib.CFFFontSet()
self.cff.fromXML(name, attrs, content, otFont)