• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Since bitmap glyph metrics are shared between EBLC and EBDT
2# this class gets its own python file.
3from __future__ import print_function, division, absolute_import
4from fontTools.misc.py23 import *
5from fontTools.misc import sstruct
6from fontTools.misc.textTools import safeEval
7import logging
8
9
10log = logging.getLogger(__name__)
11
12bigGlyphMetricsFormat = """
13  > # big endian
14  height:       B
15  width:        B
16  horiBearingX: b
17  horiBearingY: b
18  horiAdvance:  B
19  vertBearingX: b
20  vertBearingY: b
21  vertAdvance:  B
22"""
23
24smallGlyphMetricsFormat = """
25  > # big endian
26  height:   B
27  width:    B
28  BearingX: b
29  BearingY: b
30  Advance:  B
31"""
32
33class BitmapGlyphMetrics(object):
34
35	def toXML(self, writer, ttFont):
36		writer.begintag(self.__class__.__name__)
37		writer.newline()
38		for metricName in sstruct.getformat(self.__class__.binaryFormat)[1]:
39			writer.simpletag(metricName, value=getattr(self, metricName))
40			writer.newline()
41		writer.endtag(self.__class__.__name__)
42		writer.newline()
43
44	def fromXML(self, name, attrs, content, ttFont):
45		metricNames = set(sstruct.getformat(self.__class__.binaryFormat)[1])
46		for element in content:
47			if not isinstance(element, tuple):
48				continue
49			name, attrs, content = element
50			# Make sure this is a metric that is needed by GlyphMetrics.
51			if name in metricNames:
52				vars(self)[name] = safeEval(attrs['value'])
53			else:
54				log.warning("unknown name '%s' being ignored in %s.", name, self.__class__.__name__)
55
56
57class BigGlyphMetrics(BitmapGlyphMetrics):
58	binaryFormat = bigGlyphMetricsFormat
59
60class SmallGlyphMetrics(BitmapGlyphMetrics):
61	binaryFormat = smallGlyphMetricsFormat
62