py23 Use new-style classes

Such that we get the same semantics in both Python 2 and 3.
This commit is contained in:
Behdad Esfahbod 2013-11-28 14:26:58 -05:00
parent b475c03b4d
commit e388db566b
34 changed files with 81 additions and 81 deletions

View File

@ -83,7 +83,7 @@ preferredAttributeOrder = [
class error(Exception): pass
class AFM:
class AFM(object):
_attrs = None

View File

@ -21,7 +21,7 @@ cffHeaderFormat = """
offSize: B
"""
class CFFFontSet:
class CFFFontSet(object):
def __init__(self):
pass
@ -126,7 +126,7 @@ class CFFFontSet:
self.GlobalSubrs.append(subr)
class CFFWriter:
class CFFWriter(object):
def __init__(self):
self.data = []
@ -180,7 +180,7 @@ def calcOffSize(largestOffset):
return offSize
class IndexCompiler:
class IndexCompiler(object):
def __init__(self, items, strings, parent):
self.items = self.getItems(items, strings)
@ -303,7 +303,7 @@ class CharStringsCompiler(GlobalSubrsCompiler):
self.parent.rawDict["CharStrings"] = pos
class Index:
class Index(object):
"""This class represents what the CFF spec calls an INDEX."""
@ -500,7 +500,7 @@ class FDSelect:
self.gidArray.append(fdSelectValue)
class CharStrings:
class CharStrings(object):
def __init__(self, file, charset, globalSubrs, private, fdSelect, fdArray):
if file is not None:
@ -662,7 +662,7 @@ def buildConverters(table):
return d
class SimpleConverter:
class SimpleConverter(object):
def read(self, parent, value):
return value
def write(self, parent, value):
@ -783,7 +783,7 @@ class CharStringsConverter(TableConverter):
charStrings.fromXML(name, attrs, content)
return charStrings
class CharsetConverter:
class CharsetConverter(object):
def read(self, parent, value):
isCID = hasattr(parent, "ROS")
if value > 2:
@ -827,7 +827,7 @@ class CharsetConverter:
return safeEval(attrs["value"])
class CharsetCompiler:
class CharsetCompiler(object):
def __init__(self, strings, charset, parent):
assert charset[0] == '.notdef'
@ -936,7 +936,7 @@ def parseCharset(numGlyphs, file, strings, isCID, format):
return charset
class EncodingCompiler:
class EncodingCompiler(object):
def __init__(self, strings, encoding, parent):
assert not isinstance(encoding, basestring)
@ -1121,7 +1121,7 @@ class FDArrayConverter(TableConverter):
return fdArray
class FDSelectConverter:
class FDSelectConverter(object):
def read(self, parent, value):
file = parent.file
@ -1177,7 +1177,7 @@ def packFDSelect3(fdSelectArray):
return bytesjoin(data)
class FDSelectCompiler:
class FDSelectCompiler(object):
def __init__(self, fdSelect, parent):
format = fdSelect.format
@ -1315,7 +1315,7 @@ class PrivateDictDecompiler(psCharStrings.DictDecompiler):
operators = buildOperatorDict(privateDictOperators)
class DictCompiler:
class DictCompiler(object):
def __init__(self, dictObj, strings, parent):
assert isinstance(strings, IndexedStrings)
@ -1471,7 +1471,7 @@ class PrivateDictCompiler(DictCompiler):
return children
class BaseDict:
class BaseDict(object):
def __init__(self, strings=None, file=None, offset=None):
self.rawDict = {}
@ -1603,7 +1603,7 @@ class PrivateDict(BaseDict):
compilerClass = PrivateDictCompiler
class IndexedStrings:
class IndexedStrings(object):
"""SID -> string mapping."""

View File

@ -29,7 +29,7 @@ headerformat = """
FONDheadersize = 52
class FontFamily:
class FontFamily(object):
def __init__(self, theRes, mode = 'r'):
self.ID, type, self.name = theRes.GetResInfo()
@ -464,7 +464,7 @@ def makeLWFNfilename(name):
lwfnname = lwfnname + part[:3]
return lwfnname
class BitmapFontFile:
class BitmapFontFile(object):
def __init__(self, path, mode='r'):
if mode == 'r':
@ -507,7 +507,7 @@ class BitmapFontFile:
self.resref = None
class FondSelector:
class FondSelector(object):
def __init__(self, fondlist):
import W

View File

@ -51,7 +51,7 @@ _FCBPBFormat = """
ioFCBParID: l
"""
class ParamBlock:
class ParamBlock(object):
"""Wrapper for the very low level FCBPB record."""

View File

@ -35,7 +35,7 @@ for _i in range(len(realNibbles)):
realNibblesDict[realNibbles[_i]] = _i
class ByteCodeBase:
class ByteCodeBase(object):
def read_byte(self, b0, data, index):
return b0 - 139, index
@ -482,7 +482,7 @@ class T1CharString(T2CharString):
self.width = extractor.width
class SimpleT2Decompiler:
class SimpleT2Decompiler(object):
def __init__(self, localSubrs, globalSubrs):
self.localSubrs = localSubrs

View File

@ -185,7 +185,7 @@ def _test():
print('size:', calcsize(format))
class foo:
class foo(object):
pass
i = foo()

View File

@ -66,7 +66,7 @@ def _normSinCos(v):
return v
class Transform:
class Transform(object):
"""2x2 transformation matrix plus offset, a.k.a. Affine transform.
Transform instances are immutable: all transforming methods, eg.

View File

@ -11,7 +11,7 @@ class TTXParseError(Exception): pass
BUFSIZE = 0x4000
class XMLReader:
class XMLReader(object):
def __init__(self, fileName, ttFont, progress=None, quiet=False):
self.ttFont = ttFont
@ -116,7 +116,7 @@ class XMLReader:
self.root = None
class ProgressPrinter:
class ProgressPrinter(object):
def __init__(self, title, maxval=100):
print(title)

View File

@ -9,7 +9,7 @@ import struct
INDENT = " "
class XMLWriter:
class XMLWriter(object):
def __init__(self, fileOrPath, indentwhite=INDENT, idlefunc=None):
if not hasattr(fileOrPath, "write"):

View File

@ -25,7 +25,7 @@ headerSize = sstruct.calcsize(nfntHeaderFormat)
assert headerSize == 26
class NFNT:
class NFNT(object):
def __init__(self, data=None):
if data is not None:
@ -259,7 +259,7 @@ class NFNT:
return width, srcbounds, destbounds
class Glyph:
class Glyph(object):
def __init__(self, width, offset, pixels=None, pixelDepth=1):
self.width = width

View File

@ -43,7 +43,7 @@ else:
class T1Error(Exception): pass
class T1Font:
class T1Font(object):
"""Type 1 font class.

View File

@ -61,7 +61,7 @@ elif sys.platform == "darwin" and sys.version_info[:3] != (2, 2, 0):
class TTLibError(Exception): pass
class TTFont:
class TTFont(object):
"""The main font object. It manages file input and output, and offers
a convenient way of accessing tables.
@ -650,7 +650,7 @@ class TTFont:
raise TTLibError("Font contains no outlines")
class _TTGlyphSet:
class _TTGlyphSet(object):
"""Generic dict-like GlyphSet class, meant as a TrueType counterpart
to CFF's CharString dict. See TTFont.getGlyphSet().
@ -681,7 +681,7 @@ class _TTGlyphSet:
return default
class _TTGlyph:
class _TTGlyph(object):
"""Wrapper for a TrueType glyph that supports the Pen protocol, meaning
that it has a .draw() method that takes a pen object as its only
@ -742,7 +742,7 @@ class _TTGlyph:
pen.closePath()
class GlyphOrder:
class GlyphOrder(object):
"""A pseudo table. The glyph order isn't in the font as a separate
table, but it's nice to present it as such in the TTX format.

View File

@ -54,7 +54,7 @@ def openTTFonts(path):
return fonts
class SFNTResourceReader:
class SFNTResourceReader(object):
"""Simple (Mac-only) read-only file wrapper for 'sfnt' resources."""
@ -74,7 +74,7 @@ class SFNTResourceReader:
return getattr(self.file, attr)
class SFNTResourceWriter:
class SFNTResourceWriter(object):
"""Simple (Mac-only) file wrapper for 'sfnt' resources."""

View File

@ -18,7 +18,7 @@ from fontTools.misc import sstruct
import struct
class SFNTReader:
class SFNTReader(object):
def __init__(self, file, checkChecksums=1, fontNumber=-1):
self.file = file
@ -101,7 +101,7 @@ class SFNTReader:
self.file.close()
class SFNTWriter:
class SFNTWriter(object):
def __init__(self, file, numTables, sfntVersion="\000\001\000\000",
flavor=None, flavorData=None):
@ -340,7 +340,7 @@ woffDirectoryEntryFormat = """
woffDirectoryEntrySize = sstruct.calcsize(woffDirectoryEntryFormat)
class DirectoryEntry:
class DirectoryEntry(object):
def __init__(self):
self.uncompressed = False # if True, always embed entry raw

View File

@ -27,7 +27,7 @@ smallGlyphMetricsFormat = """
Advance: B
"""
class BitmapGlyphMetrics:
class BitmapGlyphMetrics(object):
def toXML(self, writer, ttFont):
writer.begintag(self.__class__.__name__)

View File

@ -138,7 +138,7 @@ class table_C_O_L_R_(DefaultTable.DefaultTable):
elif glyphSelector in self.ColorLayers:
del self.ColorLayers[glyphSelector]
class LayerRecord:
class LayerRecord(object):
def __init__(self, name = None, colorID = None):
self.name = name

View File

@ -72,7 +72,7 @@ class table_C_P_A_L_(DefaultTable.DefaultTable):
value = safeEval(attrs["value"])
setattr(self, name, value)
class Color:
class Color(object):
def __init__(self, blue=None, green=None, red=None, alpha=None):
self.blue = blue

View File

@ -112,7 +112,7 @@ def b64encode(b):
s = s[76:]
return strjoin(items)
class SignatureRecord:
class SignatureRecord(object):
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self.__dict__)

View File

@ -1,7 +1,7 @@
from __future__ import print_function, division
from fontTools.misc.py23 import *
class DefaultTable:
class DefaultTable(object):
dependencies = []

View File

@ -175,7 +175,7 @@ class table_E_B_D_T_(DefaultTable.DefaultTable):
assert self.strikeData[strikeIndex] == None, "Duplicate strike EBDT indices."
self.strikeData[strikeIndex] = bitmapGlyphDict
class EbdtComponent:
class EbdtComponent(object):
def toXML(self, writer, ttFont):
writer.begintag('ebdtComponent', [('name', self.name)])
@ -364,7 +364,7 @@ def _readExtFileImageData(bitmapObject, name, attrs, content, ttFont):
# in XML.
_bitmapGlyphSubclassPrefix = 'ebdt_bitmap_format_'
class BitmapGlyph:
class BitmapGlyph(object):
# For the external file format. This can be changed in subclasses. This way
# when the extfile option is turned on files have the form: glyphName.ext
@ -459,7 +459,7 @@ def _createBitmapPlusMetricsMixin(metricsClass):
metricsId = metricStrings.index(curMetricsName)
oppositeMetricsName = metricStrings[1-metricsId]
class BitmapPlusMetricsMixin:
class BitmapPlusMetricsMixin(object):
def writeMetrics(self, writer, ttFont):
self.metrics.toXML(writer, ttFont)
@ -484,7 +484,7 @@ BitmapPlusSmallMetricsMixin = _createBitmapPlusMetricsMixin(SmallGlyphMetrics)
# Data that is bit aligned can be tricky to deal with. These classes implement
# helper functionality for dealing with the data and getting a particular row
# of bitwise data. Also helps implement fancy data export/import in XML.
class BitAlignedBitmapMixin:
class BitAlignedBitmapMixin(object):
def _getBitRange(self, row, bitDepth, metrics):
rowBits = (bitDepth * metrics.width)
@ -572,7 +572,7 @@ class BitAlignedBitmapMixin:
# Save the image data with the bits going the correct way.
self.imageData = _reverseBytes(bytesjoin(map(bytechr, ordDataList)))
class ByteAlignedBitmapMixin:
class ByteAlignedBitmapMixin(object):
def _getByteRange(self, row, bitDepth, metrics):
rowBytes = (bitDepth * metrics.width + 7) // 8

View File

@ -222,7 +222,7 @@ class table_E_B_L_C_(DefaultTable.DefaultTable):
assert self.strikes[strikeIndex] == None, "Duplicate strike EBLC indices."
self.strikes[strikeIndex] = curStrike
class Strike:
class Strike(object):
def __init__(self):
self.bitmapSizeTable = BitmapSizeTable()
@ -255,7 +255,7 @@ class Strike:
self.indexSubTables.append(indexSubTable)
class BitmapSizeTable:
class BitmapSizeTable(object):
# Returns all the simple metric names that bitmap size table
# cares about in terms of XML creation.
@ -296,7 +296,7 @@ class BitmapSizeTable:
print("Warning: unknown name '%s' being ignored in BitmapSizeTable." % name)
class SbitLineMetrics:
class SbitLineMetrics(object):
def toXML(self, name, writer, ttFont):
writer.begintag('sbitLineMetrics', [('direction', name)])
@ -319,7 +319,7 @@ class SbitLineMetrics:
# Important information about the naming scheme. Used for identifying subtables.
_indexSubTableSubclassPrefix = 'eblc_index_sub_table_'
class EblcIndexSubTable:
class EblcIndexSubTable(object):
def __init__(self, data, ttFont):
self.data = data
@ -424,7 +424,7 @@ def _createOffsetArrayIndexSubTableMixin(formatStringForDataType):
dataFormat = '>'+formatStringForDataType
offsetDataSize = struct.calcsize(dataFormat)
class OffsetArrayIndexSubTableMixin:
class OffsetArrayIndexSubTableMixin(object):
def decompile(self):
@ -485,7 +485,7 @@ def _createOffsetArrayIndexSubTableMixin(formatStringForDataType):
# A Mixin for functionality shared between the different kinds
# of fixed sized data handling. Both kinds have big metrics so
# that kind of special processing is also handled in this mixin.
class FixedSizeIndexSubTableMixin:
class FixedSizeIndexSubTableMixin(object):
def writeMetrics(self, writer, ttFont):
writer.simpletag('imageSize', value=self.imageSize)

View File

@ -27,7 +27,7 @@ GMAPRecordFormat1 = """
class GMAPRecord:
class GMAPRecord(object):
def __init__(self, uv = 0, cid = 0, gid = 0, ggid = 0, name = ""):
self.UV = uv
self.cid = cid

View File

@ -184,7 +184,7 @@ class table_M_E_T_A_(DefaultTable.DefaultTable):
setattr(self, name, safeEval(attrs["value"]))
class GlyphRecord:
class GlyphRecord(object):
def __init__(self):
self.glyphID = -1
self.nMetaEntry = -1
@ -267,7 +267,7 @@ def mapUTF8toXML(string):
return string
class StringRecord:
class StringRecord(object):
def __init__(self):
self.labelID = -1
self.string = ""

View File

@ -21,7 +21,7 @@ panoseFormat = """
bXHeight: B
"""
class Panose:
class Panose(object):
def toXML(self, writer, ttFont):
formatstring, names, fixes = sstruct.getformat(panoseFormat)

View File

@ -307,7 +307,7 @@ class table_S_V_G_(DefaultTable.DefaultTable):
else:
print("Unknown", name, content)
class DocumentIndexEntry:
class DocumentIndexEntry(object):
def __init__(self):
self.startGlyphID = None # USHORT
self.endGlyphID = None # USHORT
@ -317,7 +317,7 @@ class DocumentIndexEntry:
def __repr__(self):
return "startGlyphID: %s, endGlyphID: %s, svgDocOffset: %s, svgDocLength: %s" % (self.startGlyphID, self.endGlyphID, self.svgDocOffset, self.svgDocLength)
class ColorPalettes:
class ColorPalettes(object):
def __init__(self):
self.numColorParams = None # USHORT
self.colorParamUINameIDs = [] # list of name table name ID values that provide UI description of each color palette.
@ -343,7 +343,7 @@ class ColorPalettes:
if len(colorPalette.paletteColors) != self.numColorParams:
raise ValueError("Number of color records in a colorPalette ('%s') does not match the number of colorParamUINameIDs elements ('%s')." % (len(colorPalette.paletteColors), self.numColorParams))
class ColorPalette:
class ColorPalette(object):
def __init__(self):
self.uiNameID = None # USHORT. name table ID that describes user interface strings associated with this color palette.
self.paletteColors = [] # list of ColorRecords
@ -362,7 +362,7 @@ class ColorPalette:
colorRecord.blue = eval(attrib["blue"])
colorRecord.alpha = eval(attrib["alpha"])
class ColorRecord:
class ColorRecord(object):
def __init__(self):
self.red = 255 # all are one byte values.
self.green = 255

View File

@ -115,7 +115,7 @@ class table_V_O_R_G_(DefaultTable.DefaultTable):
elif glyphSelector in self.VOriginRecords:
del self.VOriginRecords[glyphSelector]
class VOriginRecord:
class VOriginRecord(object):
def __init__(self, name = None, vOrigin = None):
self.glyphName = name

View File

@ -97,7 +97,7 @@ class table__c_m_a_p(DefaultTable.DefaultTable):
self.tables.append(table)
class CmapSubtable:
class CmapSubtable(object):
def __init__(self, format):
self.format = format
@ -217,7 +217,7 @@ class cmap_format_0(CmapSubtable):
subHeaderFormat = ">HHhH"
class SubHeader:
class SubHeader(object):
def __init__(self):
self.firstCode = None
self.entryCount = None

View File

@ -203,7 +203,7 @@ SCALED_COMPONENT_OFFSET = 0x0800 # composite designed to have the component
UNSCALED_COMPONENT_OFFSET = 0x1000 # composite designed not to have the component offset scaled (designed for MS)
class Glyph:
class Glyph(object):
def __init__(self, data=""):
if not data:
@ -730,7 +730,7 @@ class Glyph:
return self.__dict__ == other.__dict__
class GlyphComponent:
class GlyphComponent(object):
def __init__(self):
pass
@ -890,7 +890,7 @@ class GlyphComponent:
raise TypeError("unordered types %s() < %s()", type(self), type(other))
return self.__dict__ == other.__dict__
class GlyphCoordinates:
class GlyphCoordinates(object):
def __init__(self, iterable=[]):
self._a = array.array("h")

View File

@ -84,7 +84,7 @@ class table__k_e_r_n(DefaultTable.DefaultTable):
subtable.fromXML(name, attrs, content, ttFont)
class KernTable_format_0:
class KernTable_format_0(object):
def decompile(self, data, ttFont):
version, length, coverage = (0,0,0)
@ -162,7 +162,7 @@ class KernTable_format_0:
del self.kernTable[pair]
class KernTable_format_2:
class KernTable_format_2(object):
def decompile(self, data, ttFont):
self.data = data
@ -181,7 +181,7 @@ class KernTable_format_2:
self.decompile(readHex(content), ttFont)
class KernTable_format_unkown:
class KernTable_format_unkown(object):
def __init__(self, format):
self.format = format

View File

@ -88,7 +88,7 @@ class table__n_a_m_e(DefaultTable.DefaultTable):
return None # not found
class NameRecord:
class NameRecord(object):
def toXML(self, writer, ttFont):
writer.begintag("namerecord", [

View File

@ -3,7 +3,7 @@ from fontTools.misc.py23 import *
from .DefaultTable import DefaultTable
import struct
class OverflowErrorRecord:
class OverflowErrorRecord(object):
def __init__(self, overflowTuple):
self.tableType = overflowTuple[0]
self.LookupListIndex = overflowTuple[1]
@ -32,7 +32,7 @@ class BaseTTXConverter(DefaultTable):
def decompile(self, data, font):
from . import otTables
cachingStats = None if True else {}
class GlobalState:
class GlobalState(object):
def __init__(self, tableType, cachingStats):
self.tableType = tableType
self.cachingStats = cachingStats
@ -73,7 +73,7 @@ class BaseTTXConverter(DefaultTable):
If a lookup subtable overflows an offset, we have to start all over.
"""
class GlobalState:
class GlobalState(object):
def __init__(self, tableType):
self.tableType = tableType
globalState = GlobalState(tableType=self.tableTag)
@ -468,7 +468,7 @@ class OTTableWriter(object):
return OverflowErrorRecord( (self.globalState.tableType, LookupListIndex, SubTableIndex, itemName, itemIndex) )
class CountReference:
class CountReference(object):
"""A reference to a Count value, not a count of references."""
def __init__(self, table, name):
self.table = table
@ -740,7 +740,7 @@ def _buildDict():
valueRecordFormatDict = _buildDict()
class ValueRecordFactory:
class ValueRecordFactory(object):
"""Given a format code, this object convert ValueRecords."""
@ -788,7 +788,7 @@ class ValueRecordFactory:
writer.writeUShort(value)
class ValueRecord:
class ValueRecord(object):
# see ValueRecordFactory

View File

@ -200,7 +200,7 @@ def _skipWhite(data, pos, _whiteRE=_whiteRE):
return newPos
class Program:
class Program(object):
def __init__(self):
pass

View File

@ -100,7 +100,7 @@ def makeOutputFileName(input, outputDir, extension):
return output
class Options:
class Options(object):
listTables = False
outputDir = None

View File

@ -24471,7 +24471,7 @@ def _makeunicodes():
return unicodes
class _Unicode:
class _Unicode(object):
def __init__(self):
self.codes = _makeunicodes()