right = x + w bottom = top + h if right >= iw or bottom >= ih: print "glyph", glyph.unicode print "RECT", (left, top, right, bottom) raise FontException("The texture size is too small: (%d, %d) Increase the 'texturesize' property in the font info" % (info.texturesize[0], info.texturesize[1]) ) glyph.bitmapbox = (left, top, w, h) try: image[ left : right, top : bottom ] = glyph.bitmap except Exception, e: print "glyph", glyph.unicode print "ERROR", e print "RECT", (left, top, right, bottom) print "image.shape", image.shape print "char.bitmap.shape", glyph.bitmap.shape raise #x += max(w, w2) + info.padding + info.internalpadding[0]*2 x += info.padding + w if info.usepremultipliedalpha: image = pre_multiply_alpha(image) return image
ones = np.ones( (top.shape[0], top.shape[1]) ) from random import random r = random() * 0.4 + 0.6 g = random() * 0.4 + 0.6 b = random() * 0.4 + 0.6 a = 1.0 bottom = np.dstack( (ones * r, ones * g, ones * b, ones * a) ) result = fontutils.alpha_blend(bottom, top) image[ rect.x : rect.x + rect.width, rect.y : rect.y + rect.height ] = result except Exception, e: print "ERROR", e print "RECT", rect #print "bmshape", (bx,by,w,h) print "image.shape", image.shape print "char.bitmap.shape", glyph.bitmap.shape raise #x += max(w, w2) + info.padding + info.internalpadding[0]*2 logging.debug('Used %f %% of the texture', (binpack.get_occupancy(packer) * 100)) binpack.destroy_packer(packer) if info.usepremultipliedalpha: image = fontutils.pre_multiply_alpha(image) return image