のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

TypeError: toXML() takes exactly 3 arguments (4 given) その2

その2

def _tableToXML(self, writer, tag, progress):
	if self.has_key(tag):
		table = self[tag]
		report = "Dumping '%s' table..." % tag
	else:
		report = "No '%s' table found." % tag
	if progress:
		progress.setLabel(report)
	elif self.verbose:
		debugmsg(report)
	else:
		print report
	if not self.has_key(tag):
		return
	xmlTag = tagToXML(tag)
	if hasattr(table, "ERROR"):
		writer.begintag(xmlTag, ERROR="decompilation error")
	else:
		writer.begintag(xmlTag)
	writer.newline()
	if tag in ("glyf", "CFF "):
		table.toXML(writer, self, progress) <==ここでtableのObjectがDefaultTableなため,TypeErrorになる。

	else:
		table.toXML(writer, self)
	writer.endtag(xmlTag)
	writer.newline()
	writer.newline()
table	GlyphOrder: <fontTools.ttLib.GlyphOrder instance at 0x0000000002B6D848>	
table	table__h_e_a_d: <'head' table at 2b6d7c8>	
table	table__h_h_e_a: <'hhea' table at 2bf34c8>	
table	table__m_a_x_p: <'maxp' table at 2b70c88>	
table	table_O_S_2f_2: <'OS/2' table at 2bf3d48>	
table	DefaultTable: <'hmtx' table at 2bf3a08>	
table	DefaultTable: <'VDMX' table at 2bf3d08>	
table	DefaultTable: <'cmap' table at 2bf3a88>	
table	DefaultTable: <'loca' table at 2bf3c48>	

table	DefaultTable: <'glyf' table at 2bf3d88>	<== glyfのときのオブジェクトがDefaultTableになっている
site-packages/FontTools/fontTools/ttLib/__init__.py

def getTableClass(tag):
	"""Fetch the packer/unpacker class for a table. 
	Return None when no class is found.
	"""
	module = getTableModule(tag)
	if module is None:
		from tables.DefaultTable import DefaultTable
		return DefaultTable     <=======================
	pyTag = tagToIdentifier(tag)
	tableClass = getattr(module, "table_" + pyTag)
	return tableClass
site-packages/FontTools/fontTools/ttLib/tables/DefaultTable.py

DefaultテーブルのtoXMLは引数が3つなので、4つだとエラーになる。

	def toXML(self, writer, ttFont): 
		if hasattr(self, "ERROR"):
			writer.comment("An error occurred during the decompilation of this table")
			writer.newline()
			writer.comment(self.ERROR)
			writer.newline()
		writer.begintag("hexdata")
		writer.newline()
		writer.dumphex(self.compile(ttFont))
		writer.endtag("hexdata")
		writer.newline()

修正方法その1 progressを追加する。

site-packages/FontTools/fontTools/ttLib/tables/DefaultTable.py

def toXML(self, writer, ttFont, progress=None):
	if hasattr(self, "ERROR"):
		writer.comment("An error occurred during the decompilation of this table")
		writer.newline()
		writer.comment(self.ERROR)
		writer.newline()
	writer.begintag("hexdata")
	writer.newline()
	writer.dumphex(self.compile(ttFont))
	writer.endtag("hexdata")
	writer.newline()