2013-08-19 14:13:05 -04:00
|
|
|
# Since bitmap glyph metrics are shared between EBLC and EBDT
|
|
|
|
# this class gets its own python file.
|
2013-09-17 16:59:39 -04:00
|
|
|
from fontTools.misc import sstruct
|
2013-08-19 14:13:05 -04:00
|
|
|
from fontTools.misc.textTools import safeEval
|
2016-01-24 14:30:09 +00:00
|
|
|
import logging
|
2013-08-19 14:13:05 -04:00
|
|
|
|
|
|
|
|
2016-01-24 14:30:09 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-08-19 14:13:05 -04:00
|
|
|
bigGlyphMetricsFormat = """
|
|
|
|
> # big endian
|
|
|
|
height: B
|
|
|
|
width: B
|
|
|
|
horiBearingX: b
|
|
|
|
horiBearingY: b
|
|
|
|
horiAdvance: B
|
|
|
|
vertBearingX: b
|
|
|
|
vertBearingY: b
|
|
|
|
vertAdvance: B
|
|
|
|
"""
|
|
|
|
|
|
|
|
smallGlyphMetricsFormat = """
|
|
|
|
> # big endian
|
|
|
|
height: B
|
|
|
|
width: B
|
|
|
|
BearingX: b
|
|
|
|
BearingY: b
|
|
|
|
Advance: B
|
|
|
|
"""
|
|
|
|
|
2022-12-13 11:26:36 +00:00
|
|
|
|
2013-11-28 14:26:58 -05:00
|
|
|
class BitmapGlyphMetrics(object):
|
2013-08-19 14:13:05 -04:00
|
|
|
def toXML(self, writer, ttFont):
|
|
|
|
writer.begintag(self.__class__.__name__)
|
|
|
|
writer.newline()
|
|
|
|
for metricName in sstruct.getformat(self.__class__.binaryFormat)[1]:
|
|
|
|
writer.simpletag(metricName, value=getattr(self, metricName))
|
|
|
|
writer.newline()
|
|
|
|
writer.endtag(self.__class__.__name__)
|
|
|
|
writer.newline()
|
|
|
|
|
2013-11-27 03:19:32 -05:00
|
|
|
def fromXML(self, name, attrs, content, ttFont):
|
2013-08-19 14:13:05 -04:00
|
|
|
metricNames = set(sstruct.getformat(self.__class__.binaryFormat)[1])
|
|
|
|
for element in content:
|
2013-11-27 05:17:37 -05:00
|
|
|
if not isinstance(element, tuple):
|
2013-08-19 14:13:05 -04:00
|
|
|
continue
|
|
|
|
name, attrs, content = element
|
|
|
|
# Make sure this is a metric that is needed by GlyphMetrics.
|
|
|
|
if name in metricNames:
|
|
|
|
vars(self)[name] = safeEval(attrs["value"])
|
|
|
|
else:
|
2016-01-24 14:30:09 +00:00
|
|
|
log.warning(
|
|
|
|
"unknown name '%s' being ignored in %s.",
|
|
|
|
name,
|
|
|
|
self.__class__.__name__,
|
|
|
|
)
|
2013-08-19 14:13:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
class BigGlyphMetrics(BitmapGlyphMetrics):
|
|
|
|
binaryFormat = bigGlyphMetricsFormat
|
2022-12-13 11:26:36 +00:00
|
|
|
|
2015-04-26 02:01:01 -04:00
|
|
|
|
2013-08-19 14:13:05 -04:00
|
|
|
class SmallGlyphMetrics(BitmapGlyphMetrics):
|
|
|
|
binaryFormat = smallGlyphMetricsFormat
|