def toXML(self, writer, ttFont): writer.simpletag('version', version=self.version, compressionScheme=self.scheme) writer.newline() for n, a in sorted(self.attributes.items(), key=lambda x: ttFont.getGlyphID(x[0])): writer.begintag('glyph', name=n) writer.newline() if hasattr(a, 'octabox'): o = a.octabox formatstring, names, fixes = sstruct.getformat( Glat_format_3_octabox_metrics) vals = {} for k in names: if k == 'subboxBitmap': continue vals[k] = "{:.3f}%".format(getattr(o, k) * 100. / 255) vals['bitmap'] = "{:0X}".format(o.subboxBitmap) writer.begintag('octaboxes', **vals) writer.newline() formatstring, names, fixes = sstruct.getformat( Glat_format_3_subbox_entry) for s in o.subboxes: vals = {} for k in names: vals[k] = "{:.3f}%".format(getattr(s, k) * 100. / 255) writer.simpletag('octabox', **vals) writer.newline() writer.endtag('octaboxes') writer.newline() for k, v in sorted(a.items()): writer.simpletag('attribute', index=k, value=v) writer.newline() writer.endtag('glyph') writer.newline()
def toXML(self, writer, ttFont): if self.tableVersion != 0x00005000: writer.comment( "Most of this table will be recalculated by the compiler") writer.newline() formatstring, names, fixes = sstruct.getformat(maxpFormat_0_5) if self.tableVersion != 0x00005000: formatstring, names_1_0, fixes = sstruct.getformat( maxpFormat_1_0_add) names = names + names_1_0 for name in names: value = getattr(self, name) if name == "tableVersion": value = hex(value) writer.simpletag(name, value=value) writer.newline()
def toXML(self, writer, ttFont): writer.comment( "Most of this table will be recalculated by the compiler") writer.newline() formatstring, names, fixes = sstruct.getformat(GPKGFormat) for name in names: value = getattr(self, name) writer.simpletag(name, value=value) writer.newline() writer.begintag("GMAPs") writer.newline() for gmapData in self.GMAPs: writer.begintag("hexdata") writer.newline() writer.dumphex(gmapData) writer.endtag("hexdata") writer.newline() writer.endtag("GMAPs") writer.newline() writer.begintag("glyphlets") writer.newline() for glyphletData in self.glyphlets: writer.begintag("hexdata") writer.newline() writer.dumphex(glyphletData) writer.endtag("hexdata") writer.newline() writer.endtag("glyphlets") writer.newline()
def toXML(self, writer, ttFont): writer.comment( "The fields 'usFirstCharIndex' and 'usLastCharIndex'\n" "will be recalculated by the compiler") writer.newline() if self.version == 1: format = OS2_format_1 elif self.version in (2, 3, 4): format = OS2_format_2 elif self.version == 5: format = OS2_format_5 else: format = OS2_format_0 formatstring, names, fixes = sstruct.getformat(format) for name in names: value = getattr(self, name) if name=="panose": writer.begintag("panose") writer.newline() value.toXML(writer, ttFont) writer.endtag("panose") elif name in ("ulUnicodeRange1", "ulUnicodeRange2", "ulUnicodeRange3", "ulUnicodeRange4", "ulCodePageRange1", "ulCodePageRange2"): writer.simpletag(name, value=num2binary(value)) elif name in ("fsType", "fsSelection"): writer.simpletag(name, value=num2binary(value, 16)) elif name == "achVendID": writer.simpletag(name, value=repr(value)[1:-1]) else: writer.simpletag(name, value=value) writer.newline()
def toXML(self, writer, ttFont): writer.begintag('ebdtComponent', [('name', self.name)]) writer.newline() for componentName in sstruct.getformat(ebdtComponentFormat)[1][1:]: writer.simpletag(componentName, value=getattr(self, componentName)) writer.newline() writer.endtag('ebdtComponent') writer.newline()
def fromXML(self, name, attrs, content, ttFont): metricNames = set(sstruct.getformat(sbitLineMetricsFormat)[1]) for element in content: if not isinstance(element, tuple): continue name, attrs, content = element if name in metricNames: vars(self)[name] = safeEval(attrs['value'])
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()
def toXML(self, name, writer, ttFont): writer.begintag('sbitLineMetrics', [('direction', name)]) writer.newline() for metricName in sstruct.getformat(sbitLineMetricsFormat)[1]: writer.simpletag(metricName, value=getattr(self, metricName)) writer.newline() writer.endtag('sbitLineMetrics') writer.newline()
def toXML(self, writer, ttFont): formatstring, names, fixes = sstruct.getformat(hheaFormat) for name in names: value = getattr(self, name) if name == "tableVersion": value = fi2ve(value) value = "0x%08x" % value writer.simpletag(name, value=value) writer.newline()
def toXML(self, writer, ttFont): writer.comment( "Most of this table will be recalculated by the compiler") writer.newline() formatstring, names, fixes = sstruct.getformat(SINGFormat) for name in names: value = getattr(self, name) writer.simpletag(name, value=value) writer.newline() writer.simpletag("baseGlyphName", value=self.baseGlyphName) writer.newline()
def toXML(self, writer, ttFont): writer.comment("Most of this table will be recalculated by the compiler") writer.newline() formatstring, names, fixes = sstruct.getformat(GMAPFormat) for name in names: value = getattr(self, name) writer.simpletag(name, value=value) writer.newline() writer.simpletag("PSFontName", value=self.psFontName) writer.newline() for gmapRecord in self.gmapRecords: gmapRecord.toXML(writer, ttFont)
def toXML(self, writer, ttFont): writer.comment( "FontForge's timestamp, font source creation and modification dates" ) writer.newline() formatstring, names, fixes = sstruct.getformat(FFTMFormat) for name in names: value = getattr(self, name) if name in ("FFTimeStamp", "sourceCreated", "sourceModified"): value = timestampToString(value) writer.simpletag(name, value=value) writer.newline()
def fromXML(self, name, attrs, content, ttFont): value = attrs["value"] fixes = sstruct.getformat(headFormat)[2] if name in fixes: value = strToFixedToFloat(value, precisionBits=fixes[name]) elif name in ("created", "modified"): value = timestampFromString(value) elif name in ("macStyle", "flags"): value = binary2num(value) else: value = safeEval(value) setattr(self, name, value)
def fromXML(self, name, attrs, content, ttFont): metricNames = set(sstruct.getformat(self.__class__.binaryFormat)[1]) for element in content: if not isinstance(element, tuple): 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: log.warning("unknown name '%s' being ignored in %s.", name, self.__class__.__name__)
def fromXML(self, name, attrs, content, ttFont): self.name = attrs['name'] componentNames = set(sstruct.getformat(ebdtComponentFormat)[1][1:]) for element in content: if not isinstance(element, tuple): continue name, attrs, content = element if name in componentNames: vars(self)[name] = safeEval(attrs['value']) else: log.warning( "unknown name '%s' being ignored by EbdtComponent.", name)
def toXML(self, writer, ttFont, version=2.0): if version >= 3.0: writer.simpletag('version', ruleVersion=self.ruleVersion) writer.newline() writesimple('info', self, writer, *attrs_info) writesimple('passindexes', self, writer, *attrs_passindexes) writesimple('contexts', self, writer, *attrs_contexts) writesimple('attributes', self, writer, *attrs_attributes) if len(self.jLevels): writer.begintag('justifications') writer.newline() jformat, jnames, jfixes = sstruct.getformat(Silf_justify_format) for i, j in enumerate(self.jLevels): attrs = dict([(k, getattr(j, k)) for k in jnames]) writer.simpletag('justify', **attrs) writer.newline() writer.endtag('justifications') writer.newline() if len(self.critFeatures): writer.begintag('critFeatures') writer.newline() writer.write(" ".join(map(str, self.critFeatures))) writer.newline() writer.endtag('critFeatures') writer.newline() if len(self.scriptTags): writer.begintag('scriptTags') writer.newline() writer.write(" ".join(self.scriptTags)) writer.newline() writer.endtag('scriptTags') writer.newline() if self.pMap: writer.begintag('pseudoMap') writer.newline() for k, v in sorted(self.pMap.items()): writer.simpletag('pseudo', unicode=hex(k), pseudo=v) writer.newline() writer.endtag('pseudoMap') writer.newline() self.classes.toXML(writer, ttFont, version) if len(self.passes): writer.begintag('passes') writer.newline() for i, p in enumerate(self.passes): writer.begintag('pass', _index=i) writer.newline() p.toXML(writer, ttFont, version) writer.endtag('pass') writer.newline() writer.endtag('passes') writer.newline()
def toXML(self, writer, ttFont): formatstring, names, fixes = sstruct.getformat(postFormat) for name in names: value = getattr(self, name) writer.simpletag(name, value=value) writer.newline() if hasattr(self, "mapping"): writer.begintag("psNames") writer.newline() writer.comment( "This file uses unique glyph names based on the information\n" "found in the 'post' table. Since these names might not be unique,\n" "we have to invent artificial names in case of clashes. In order to\n" "be able to retain the original information, we need a name to\n" "ps name mapping for those cases where they differ. That's what\n" "you see below.\n") writer.newline() items = sorted(self.mapping.items()) for name, psName in items: writer.simpletag("psName", name=name, psName=psName) writer.newline() writer.endtag("psNames") writer.newline() if hasattr(self, "extraNames"): writer.begintag("extraNames") writer.newline() writer.comment( "following are the name that are not taken from the standard Mac glyph order" ) writer.newline() for name in self.extraNames: writer.simpletag("psName", name=name) writer.newline() writer.endtag("extraNames") writer.newline() if hasattr(self, "data"): writer.begintag("hexdata") writer.newline() writer.dumphex(self.data) writer.endtag("hexdata") writer.newline()
def toXML(self, writer, ttFont): writer.comment( "Most of this table will be recalculated by the compiler") writer.newline() _, names, fixes = sstruct.getformat(headFormat) for name in names: value = getattr(self, name) if name in fixes: value = floatToFixedToStr(value, precisionBits=fixes[name]) elif name in ("created", "modified"): value = timestampToString(value) elif name in ("magicNumber", "checkSumAdjustment"): if value < 0: value = value + 0x100000000 value = hex(value) if value[-1:] == "L": value = value[:-1] elif name in ("macStyle", "flags"): value = num2binary(value, 16) writer.simpletag(name, value=value) writer.newline()
def _getXMLMetricNames(self): dataNames = sstruct.getformat(bitmapSizeTableFormatPart1)[1] dataNames = dataNames + sstruct.getformat( bitmapSizeTableFormatPart2)[1] # Skip the first 3 data names because they are byte offsets and counts. return dataNames[3:]
def toXML(self, writer, ttFont): formatstring, names, fixes = sstruct.getformat(panoseFormat) for name in names: writer.simpletag(name, value=getattr(self, name)) writer.newline()