a whole bunch of renames, purely stylistic

git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@226 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
jvr 2002-05-13 16:21:51 +00:00
parent dbc2c173b3
commit 8307fa42cd
3 changed files with 41 additions and 42 deletions

View File

@ -42,7 +42,7 @@ Dumping 'prep' table...
""" """
# #
# $Id: __init__.py,v 1.26 2002-05-13 11:26:38 jvr Exp $ # $Id: __init__.py,v 1.27 2002-05-13 16:21:50 jvr Exp $
# #
import os import os
@ -203,14 +203,14 @@ class TTFont:
for i in range(numTables): for i in range(numTables):
tag = tables[i] tag = tables[i]
xmltag = tag2xmltag(tag) xmlTag = tagToXML(tag)
if splitTables: if splitTables:
tablePath = fileNameTemplate % tag2identifier(tag) tablePath = fileNameTemplate % tagToIdentifier(tag)
writer = xmlWriter.XMLWriter(tablePath) writer = xmlWriter.XMLWriter(tablePath)
writer.begintag("ttFont", ttLibVersion=version) writer.begintag("ttFont", ttLibVersion=version)
writer.newline() writer.newline()
writer.newline() writer.newline()
collection.simpletag(xmltag, src=os.path.basename(tablePath)) collection.simpletag(xmlTag, src=os.path.basename(tablePath))
collection.newline() collection.newline()
table = self[tag] table = self[tag]
report = "Dumping '%s' table..." % tag report = "Dumping '%s' table..." % tag
@ -221,15 +221,15 @@ class TTFont:
else: else:
print report print report
if hasattr(table, "ERROR"): if hasattr(table, "ERROR"):
writer.begintag(xmltag, ERROR="decompilation error") writer.begintag(xmlTag, ERROR="decompilation error")
else: else:
writer.begintag(xmltag) writer.begintag(xmlTag)
writer.newline() writer.newline()
if tag in ("glyf", "CFF "): if tag in ("glyf", "CFF "):
table.toXML(writer, self, progress) table.toXML(writer, self, progress)
else: else:
table.toXML(writer, self) table.toXML(writer, self)
writer.endtag(xmltag) writer.endtag(xmlTag)
writer.newline() writer.newline()
writer.newline() writer.newline()
if splitTables: if splitTables:
@ -290,8 +290,8 @@ class TTFont:
if self.verbose: if self.verbose:
debugmsg("reading '%s' table from disk" % tag) debugmsg("reading '%s' table from disk" % tag)
data = self.reader[tag] data = self.reader[tag]
tableclass = getTableClass(tag) tableClass = getTableClass(tag)
table = tableclass(tag) table = tableClass(tag)
self.tables[tag] = table self.tables[tag] = table
if self.verbose: if self.verbose:
debugmsg("decompiling '%s' table" % tag) debugmsg("decompiling '%s' table" % tag)
@ -483,8 +483,8 @@ class TTFont:
""" """
if tag in done: if tag in done:
return return
tableclass = getTableClass(tag) tableClass = getTableClass(tag)
for masterTable in tableclass.dependencies: for masterTable in tableClass.dependencies:
if masterTable not in done: if masterTable not in done:
if self.has_key(masterTable): if self.has_key(masterTable):
self._writeTable(masterTable, writer, done) self._writeTable(masterTable, writer, done)
@ -535,16 +535,16 @@ def getTableModule(tag):
""" """
import imp import imp
import tables import tables
py_tag = tag2identifier(tag) pyTag = tagToIdentifier(tag)
try: try:
f, path, kind = imp.find_module(py_tag, tables.__path__) f, path, kind = imp.find_module(pyTag, tables.__path__)
if f: if f:
f.close() f.close()
except ImportError: except ImportError:
return None return None
else: else:
module = __import__("fontTools.ttLib.tables." + py_tag) module = __import__("fontTools.ttLib.tables." + pyTag)
return getattr(tables, py_tag) return getattr(tables, pyTag)
def getTableClass(tag): def getTableClass(tag):
@ -555,19 +555,19 @@ def getTableClass(tag):
if module is None: if module is None:
from tables.DefaultTable import DefaultTable from tables.DefaultTable import DefaultTable
return DefaultTable return DefaultTable
py_tag = tag2identifier(tag) pyTag = tagToIdentifier(tag)
tableclass = getattr(module, "table_" + py_tag) tableClass = getattr(module, "table_" + pyTag)
return tableclass return tableClass
def getNewTable(tag): def newTable(tag):
"""Return a new instance of a table.""" """Return a new instance of a table."""
tableclass = getTableClass(tag) tableClass = getTableClass(tag)
return tableclass(tag) return tableClass(tag)
def _escapechar(c): def _escapechar(c):
"""Helper function for tag2identifier()""" """Helper function for tagToIdentifier()"""
import re import re
if re.match("[a-z0-9]", c): if re.match("[a-z0-9]", c):
return "_" + c return "_" + c
@ -577,7 +577,7 @@ def _escapechar(c):
return hex(ord(c))[2:] return hex(ord(c))[2:]
def tag2identifier(tag): def tagToIdentifier(tag):
"""Convert a table tag to a valid (but UGLY) python identifier, """Convert a table tag to a valid (but UGLY) python identifier,
as well as a filename that's guaranteed to be unique even on a as well as a filename that's guaranteed to be unique even on a
caseless file system. Each character is mapped to two characters. caseless file system. Each character is mapped to two characters.
@ -602,8 +602,8 @@ def tag2identifier(tag):
return ident return ident
def identifier2tag(ident): def identifierToTag(ident):
"""the opposite of tag2identifier()""" """the opposite of tagToIdentifier()"""
if len(ident) % 2 and ident[0] == "_": if len(ident) % 2 and ident[0] == "_":
ident = ident[1:] ident = ident[1:]
assert not (len(ident) % 2) assert not (len(ident) % 2)
@ -621,8 +621,8 @@ def identifier2tag(ident):
return tag return tag
def tag2xmltag(tag): def tagToXML(tag):
"""Similarly to tag2identifier(), this converts a TT tag """Similarly to tagToIdentifier(), this converts a TT tag
to a valid XML element name. Since XML element names are to a valid XML element name. Since XML element names are
case sensitive, this is a fairly simple/readable translation. case sensitive, this is a fairly simple/readable translation.
""" """
@ -632,15 +632,15 @@ def tag2xmltag(tag):
if re.match("[A-Za-z_][A-Za-z_0-9]* *$", tag): if re.match("[A-Za-z_][A-Za-z_0-9]* *$", tag):
return string.strip(tag) return string.strip(tag)
else: else:
return tag2identifier(tag) return tagToIdentifier(tag)
def xmltag2tag(tag): def xmlToTag(tag):
"""The opposite of tag2xmltag()""" """The opposite of tagToXML()"""
if tag == "OS_2": if tag == "OS_2":
return "OS/2" return "OS/2"
if len(tag) == 8: if len(tag) == 8:
return identifier2tag(tag) return identifierToTag(tag)
else: else:
return tag + " " * (4 - len(tag)) return tag + " " * (4 - len(tag))
return tag return tag
@ -650,4 +650,3 @@ def debugmsg(msg):
import time import time
print msg + time.strftime(" (%H:%M:%S)", time.localtime(time.time())) print msg + time.strftime(" (%H:%M:%S)", time.localtime(time.time()))

View File

@ -16,25 +16,25 @@ as to Python identifiers. The latter means it can only contain
ttLib provides functions to expand a tag into the format used here: ttLib provides functions to expand a tag into the format used here:
>>> from fontTools import ttLib >>> from fontTools import ttLib
>>> ttLib.tag2identifier("FOO ") >>> ttLib.tagToIdentifier("FOO ")
'F_O_O_' 'F_O_O_'
>>> ttLib.tag2identifier("cvt ") >>> ttLib.tagToIdentifier("cvt ")
'_c_v_t' '_c_v_t'
>>> ttLib.tag2identifier("OS/2") >>> ttLib.tagToIdentifier("OS/2")
'O_S_2f_2' 'O_S_2f_2'
>>> ttLib.tag2identifier("glyf") >>> ttLib.tagToIdentifier("glyf")
'_g_l_y_f' '_g_l_y_f'
>>> >>>
And vice versa: And vice versa:
>>> ttLib.identifier2tag("F_O_O_") >>> ttLib.identifierToTag("F_O_O_")
'FOO ' 'FOO '
>>> ttLib.identifier2tag("_c_v_t") >>> ttLib.identifierToTag("_c_v_t")
'cvt ' 'cvt '
>>> ttLib.identifier2tag("O_S_2f_2") >>> ttLib.identifierToTag("O_S_2f_2")
'OS/2' 'OS/2'
>>> ttLib.identifier2tag("_g_l_y_f") >>> ttLib.identifierToTag("_g_l_y_f")
'glyf' 'glyf'
>>> >>>

View File

@ -62,14 +62,14 @@ class ExpatParser:
importXML(self.ttFont, subFile, self.progress) importXML(self.ttFont, subFile, self.progress)
self.contentStack.append([]) self.contentStack.append([])
return return
msg = "Parsing '%s' table..." % ttLib.xmltag2tag(name) msg = "Parsing '%s' table..." % ttLib.xmlToTag(name)
if self.progress: if self.progress:
self.progress.setlabel(msg) self.progress.setlabel(msg)
elif self.ttFont.verbose: elif self.ttFont.verbose:
ttLib.debugmsg(msg) ttLib.debugmsg(msg)
else: else:
print msg print msg
tag = ttLib.xmltag2tag(name) tag = ttLib.xmlToTag(name)
if attrs.has_key("ERROR"): if attrs.has_key("ERROR"):
tableClass = DefaultTable tableClass = DefaultTable
else: else: