--- ./build/mac/createfont_osx.py (original) +++ ./build/mac/createfont_osx.py (refactored) @@ -36,7 +36,7 @@ def _getBitmapImageRep(size, hasAlpha=True): - width, height = map(int, size) + width, height = list(map(int, size)) return NSBitmapImageRep.alloc().initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_(None, width, height, 8, 4, hasAlpha, False, NSDeviceRGBColorSpace, width*4, 32) @@ -55,7 +55,7 @@ def filter_range(n): offset = 1 # - int(n/5) - return range(-n/2 + offset, n/2 + offset) + return list(range(-n/2 + offset, n/2 + offset)) class SysFont(object): @@ -79,7 +79,7 @@ self._isBold and 'Bold' or '', self._isOblique and 'Oblique' or '') self._font = NSFont.fontWithName_size_(name, self._size) - print name, self._font + print(name, self._font) if self._font is None: if self._isBold: self._font = NSFont.boldSystemFontOfSize(self._size) @@ -121,10 +121,10 @@ self._isUnderline = isUnderline def size(self, text): - return tuple(map(int,map(math.ceil, NSString.sizeWithAttributes_(text, { + return tuple(map(int,list(map(math.ceil, NSString.sizeWithAttributes_(text, { NSFontAttributeName: self._font, NSUnderlineStyleAttributeName: self._isUnderline and 1.0 or 0, - })))) + }))))) def advancement(self, glyph): return tuple(self._font.advancementForGlyph_(ord(glyph))) @@ -196,7 +196,7 @@ [6, 36, 90, 120, 90, 36, 6], [1, 6, 15, 20, 15, 6, 1]] else: - print "factors for filter size", filter_size, "not defined!" + print("factors for filter size", filter_size, "not defined!") factors = 0 # Filter a shadow. @@ -269,7 +269,7 @@ if __name__=='__main__': if len(sys.argv) < 5: - print "usage: " + sys.argv[0] + " (font-name) (font-size) (texture-width) (output-file)" + print("usage: " + sys.argv[0] + " (font-name) (font-size) (texture-width) (output-file)") sys.exit(0) out_filename = sys.argv[4] @@ -286,17 +286,17 @@ texture_width = int(sys.argv[3]) font_point_height = s.get_height() - print "Font texture width =", texture_width - print "Line height =", font_point_height, "pt" - print "Font size =", point_size, "pt" + print("Font texture width =", texture_width) + print("Line height =", font_point_height, "pt") + print("Font size =", point_size, "pt") ascent = s.get_ascent() descent = s.get_descent() - print "Ascent =", ascent, "pt Descent =", descent, "pt" - - print "Shadow filter is sized %i for this font." % s.shadow_filter_size() + print("Ascent =", ascent, "pt Descent =", descent, "pt") + + print("Shadow filter is sized %i for this font." % s.shadow_filter_size()) border_size = s.border_size() - print "Glyph borders are %i pixels wide." % border_size + print("Glyph borders are %i pixels wide." % border_size) rover = (0, 0) line_height = 0 @@ -304,7 +304,7 @@ used_pixels = 0 # Only the basic ASCII set, and some specific characters. - char_range = range(0x20, 0x7F) + [0x96, 0x97, 0xA3, 0xA4, 0xA9, 0xB0, 0xB1] + char_range = list(range(0x20, 0x7F)) + [0x96, 0x97, 0xA3, 0xA4, 0xA9, 0xB0, 0xB1] for code in char_range: glyph = Glyph(code) try: @@ -320,7 +320,7 @@ # No, move to the new row. rover = (0, rover[1] + line_height) texture_height += line_height - print "Finished a %i pixels tall line." % line_height + print("Finished a %i pixels tall line." % line_height) line_height = 0 glyph.pos = rover @@ -332,20 +332,20 @@ glyphs.append(glyph) #except Exception, x: except KeyboardInterrupt: - print "Code %i: Failed to render." % code - print x - - print "Finished rendering %i glyphs." % len(glyphs) + print("Code %i: Failed to render." % code) + print(x) + + print("Finished rendering %i glyphs." % len(glyphs)) actual_line_height = glyphs[0].dims[1] - border_size*2 - print "Actual line height is %i pixels." % actual_line_height - - print "Size of the finished texture is %i x %i." % (texture_width, texture_height) + print("Actual line height is %i pixels." % actual_line_height) + + print("Size of the finished texture is %i x %i." % (texture_width, texture_height)) actual_height = pow2(texture_height) total_pixels = texture_width * actual_height - print "Unused texture area: %.2f %%" % (100*(1.0 - used_pixels/float(total_pixels))) - print "Writing output to file: %s" % out_filename + print("Unused texture area: %.2f %%" % (100*(1.0 - used_pixels/float(total_pixels)))) + print("Writing output to file: %s" % out_filename) out = file(out_filename, 'wb') @@ -365,10 +365,10 @@ scale = float(actual_line_height) / font_point_height pixel_ascent = int(math.ceil(scale * ascent)) pixel_descent = int(math.ceil(scale * descent)) - print " Pixel ascent/descent:", pixel_ascent, '/', pixel_descent + print(" Pixel ascent/descent:", pixel_ascent, '/', pixel_descent) pixel_line_height = int(scale * font_point_height) - print " Pixel line height:", pixel_line_height + print(" Pixel line height:", pixel_line_height) # Ascent and descent. out.write(struct.pack('