def render(self, text, antialias, forecolor, backcolor=(0,0,0,255)):
size = self.size(text)
img = NSImage.alloc().initWithSize_(size)
img.lockFocus()
NSString.drawAtPoint_withAttributes_(text, (0.0, 0.0), {
NSFontAttributeName: self._font,
NSUnderlineStyleAttributeName: self._isUnderline and 1.0 or None,
NSBackgroundColorAttributeName: backcolor and _getColor(backcolor) or None,
NSForegroundColorAttributeName: _getColor(forecolor),
})
rep = NSBitmapImageRep.alloc().initWithFocusedViewRect_(((0.0, 0.0), size))
img.unlockFocus()
if rep.samplesPerPixel() == 4:
s = Surface(size, SRCALPHA|SWSURFACE, 32, [-1<<24,0xff<<16,0xff<<8,0xff])
a = Numeric.reshape(Numeric.fromstring(rep.bitmapData(), typecode=Numeric.Int32), (size[1], size[0]))
blit_array(s, Numeric.swapaxes(a,0,1))
return s.convert_alpha()
评论列表
文章目录