diff --git a/Lib/fontTools/ttLib/tables/_s_b_i_x.py b/Lib/fontTools/ttLib/tables/_s_b_i_x.py index d24db023c..35c7e5022 100644 --- a/Lib/fontTools/ttLib/tables/_s_b_i_x.py +++ b/Lib/fontTools/ttLib/tables/_s_b_i_x.py @@ -88,7 +88,7 @@ class table__s_b_i_x(DefaultTable.DefaultTable): #print "Number of Bitmaps:", myBitmapSet.numBitmaps if myBitmapSet.size in self.bitmapSets: from fontTools import ttLib - raise(ttLib.TTLibError, "Pixel 'size' must be unique for each BitmapSet") + raise ttLib.TTLibError("Pixel 'size' must be unique for each BitmapSet") self.bitmapSets[myBitmapSet.size] = myBitmapSet # after the bitmaps have been extracted, we don't need the offsets anymore @@ -121,18 +121,19 @@ class table__s_b_i_x(DefaultTable.DefaultTable): for i in sorted(self.bitmapSets.keys()): self.bitmapSets[i].toXML(xmlWriter, ttFont) - def fromXML(self, (name, attrs, content), ttFont): + def fromXML(self, name, attrs, content, ttFont): if name in ["usVal1", "usVal2"]: setattr(self, name, int(attrs["value"])) elif name == "bitmapSet": myBitmapSet = BitmapSet() for element in content: - if type(element) == TupleType: - myBitmapSet.fromXML(element, ttFont) + if isinstance(element, tuple): + name, attrs, content = element + myBitmapSet.fromXML(name, attrs, content, ttFont) self.bitmapSets[myBitmapSet.size] = myBitmapSet else: from fontTools import ttLib - raise ttLib.TTLibError, "can't handle '%s' element" % name + raise ttLib.TTLibError("can't handle '%s' element" % name) # Helper classes diff --git a/Lib/fontTools/ttLib/tables/sbixBitmap.py b/Lib/fontTools/ttLib/tables/sbixBitmap.py index 10bb2f216..991b54759 100644 --- a/Lib/fontTools/ttLib/tables/sbixBitmap.py +++ b/Lib/fontTools/ttLib/tables/sbixBitmap.py @@ -30,12 +30,12 @@ class Bitmap(object): self.glyphName = ttFont.getGlyphName(self.gid) if self.rawdata is None: from fontTools import ttLib - raise(ttLib.TTLibError, "No table data to decompile.") + raise ttLib.TTLibError("No table data to decompile") if len(self.rawdata) > 0: if len(self.rawdata) < sbixBitmapHeaderFormatSize: from fontTools import ttLib #print "Bitmap %i header too short: Expected %x, got %x." % (self.gid, sbixBitmapHeaderFormatSize, len(self.rawdata)) - raise(ttLib.TTLibError, "Bitmap header too short.") + raise ttLib.TTLibError("Bitmap header too short.") sstruct.unpack(sbixBitmapHeaderFormat, self.rawdata[:sbixBitmapHeaderFormatSize], self) @@ -53,7 +53,7 @@ class Bitmap(object): def compile(self, ttFont): if self.glyphName is None: from fontTools import ttLib - raise ttLib.TTLibError, "Can't compile bitmap without glyph name" + raise ttLib.TTLibError("Can't compile bitmap without glyph name") # TODO: if ttFont has no maxp, cmap etc., ignore glyph names and compile by index? # (needed if you just want to compile the sbix table on its own) self.gid = struct.pack(">H", ttFont.getGlyphID(self.glyphName)) @@ -88,7 +88,7 @@ class Bitmap(object): xmlWriter.endtag("bitmap") xmlWriter.newline() - def fromXML(self, (name, attrs, content), ttFont): + def fromXML(self, name, attrs, content, ttFont): #if name in ["usReserved1", "usReserved2"]: # setattr(self, name, int(attrs["value"])) #elif @@ -101,4 +101,4 @@ class Bitmap(object): self.imageData = readHex(content) else: from fontTools import ttLib - raise ttLib.TTLibError, "can't handle '%s' element" % name + raise ttLib.TTLibError("can't handle '%s' element" % name) diff --git a/Lib/fontTools/ttLib/tables/sbixBitmapSet.py b/Lib/fontTools/ttLib/tables/sbixBitmapSet.py index b27d86857..9798666d1 100644 --- a/Lib/fontTools/ttLib/tables/sbixBitmapSet.py +++ b/Lib/fontTools/ttLib/tables/sbixBitmapSet.py @@ -30,7 +30,7 @@ class BitmapSet(object): def decompile(self, ttFont): if self.data is None: from fontTools import ttLib - raise(ttLib.TTLibError, "No table data to decompile.") + raise ttLib.TTLibError if len(self.data) < sbixBitmapSetHeaderFormatSize: from fontTools import ttLib raise(ttLib.TTLibError, "BitmapSet header too short: Expected %x, got %x.") \ @@ -42,7 +42,7 @@ class BitmapSet(object): # calculate number of bitmaps firstBitmapOffset, = struct.unpack(">L", \ self.data[sbixBitmapSetHeaderFormatSize : sbixBitmapSetHeaderFormatSize + sbixBitmapOffsetEntryFormatSize]) - self.numBitmaps = (firstBitmapOffset - sbixBitmapSetHeaderFormatSize) / sbixBitmapOffsetEntryFormatSize - 1 + self.numBitmaps = (firstBitmapOffset - sbixBitmapSetHeaderFormatSize) // sbixBitmapOffsetEntryFormatSize - 1 # ^ -1 because there's one more offset than bitmaps # build offset list for single bitmap offsets @@ -113,25 +113,26 @@ class BitmapSet(object): xmlWriter.endtag("bitmapSet") xmlWriter.newline() - def fromXML(self, (name, attrs, content), ttFont): + def fromXML(self, name, attrs, content, ttFont): if name in ["size", "resolution"]: setattr(self, name, int(attrs["value"])) elif name == "bitmap": - if attrs.has_key("format"): + if "format" in attrs: myFormat = attrs["format"] else: myFormat = None - if attrs.has_key("glyphname"): + if "glyphname" in attrs: myGlyphName = attrs["glyphname"] else: from fontTools import ttLib - raise ttLib.TTLibError, "Bitmap must have a glyph name." + raise ttLib.TTLibError("Bitmap must have a glyph name.") myBitmap = Bitmap(glyphName=myGlyphName, imageFormatTag=myFormat) for element in content: - if type(element) == TupleType: - myBitmap.fromXML(element, ttFont) + if isinstance(element, tuple): + name, attrs, content = element + myBitmap.fromXML(name, attrs, content, ttFont) myBitmap.compile(ttFont) self.bitmaps[myBitmap.glyphName] = myBitmap else: from fontTools import ttLib - raise ttLib.TTLibError, "can't handle '%s' element" % name + raise ttLib.TTLibError("can't handle '%s' element" % name)