def draw_image(self, x, y, im, origin, bbox): if bbox != None: l,b,w,h = bbox.get_bounds() #rectangle = (int(l), self.height-int(b+h), # int(w), int(h)) # set clip rect? flipud = origin=='lower' rows, cols, image_str = im.as_str(flipud) image_array = fromstring(image_str, UInt8) image_array.shape = rows, cols, 4 pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, has_alpha=True, bits_per_sample=8, width=cols, height=rows) array = pixbuf_get_pixels_array(pixbuf) array[:,:,:] = image_array gc = self.new_gc() if flipud: y = self.height-y-rows try: # new in 2.2 # can use None instead of gc.gdkGC, if don't need clipping self.gdkDrawable.draw_pixbuf (gc.gdkGC, pixbuf, 0, 0, int(x), int(y), cols, rows, gdk.RGB_DITHER_NONE, 0, 0) except AttributeError: # deprecated in 2.2 pixbuf.render_to_drawable(self.gdkDrawable, gc.gdkGC, 0, 0, int(x), int(y), cols, rows, gdk.RGB_DITHER_NONE, 0, 0)
def _draw_mathtext(self, gc, x, y, s, prop, angle): size = prop.get_size_in_points() width, height, fonts = math_parse_s_ft2font(s, self.dpi.get(), size) if angle == 90: width, height = height, width x -= width y -= height imw, imh, image_str = fonts[0].image_as_str() N = imw * imh # a numpixels by num fonts array Xall = zeros((N, len(fonts)), typecode=UInt8) for i, font in enumerate(fonts): if angle == 90: font.horiz_image_to_vert_image() # <-- Rotate imw, imh, image_str = font.image_as_str() Xall[:, i] = fromstring(image_str, UInt8) # get the max alpha at each pixel Xs = numerix.mlab.max(Xall, 1) # convert it to it's proper shape Xs.shape = imh, imw pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, has_alpha=True, bits_per_sample=8, width=imw, height=imh) array = pixbuf_get_pixels_array(pixbuf) rgb = gc.get_rgb() array[:, :, 0] = int(rgb[0] * 255) array[:, :, 1] = int(rgb[1] * 255) array[:, :, 2] = int(rgb[2] * 255) array[:, :, 3] = Xs try: # new in 2.2 # can use None instead of gc.gdkGC, if don't need clipping self.gdkDrawable.draw_pixbuf(gc.gdkGC, pixbuf, 0, 0, int(x), int(y), imw, imh, gdk.RGB_DITHER_NONE, 0, 0) except AttributeError: # deprecated in 2.2 pixbuf.render_to_drawable(self.gdkDrawable, gc.gdkGC, 0, 0, int(x), int(y), imw, imh, gdk.RGB_DITHER_NONE, 0, 0)
def _draw_mathtext(self, gc, x, y, s, prop, angle): size = prop.get_size_in_points() width, height, fonts = math_parse_s_ft2font( s, self.dpi.get(), size) if angle==90: width, height = height, width x -= width y -= height imw, imh, image_str = fonts[0].image_as_str() N = imw*imh # a numpixels by num fonts array Xall = zeros((N,len(fonts)), typecode=UInt8) for i, font in enumerate(fonts): if angle == 90: font.horiz_image_to_vert_image() # <-- Rotate imw, imh, image_str = font.image_as_str() Xall[:,i] = fromstring(image_str, UInt8) # get the max alpha at each pixel Xs = numerix.mlab.max(Xall,1) # convert it to it's proper shape Xs.shape = imh, imw pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, has_alpha=True, bits_per_sample=8, width=imw, height=imh) array = pixbuf_get_pixels_array(pixbuf) rgb = gc.get_rgb() array[:,:,0]=int(rgb[0]*255) array[:,:,1]=int(rgb[1]*255) array[:,:,2]=int(rgb[2]*255) array[:,:,3]=Xs try: # new in 2.2 # can use None instead of gc.gdkGC, if don't need clipping self.gdkDrawable.draw_pixbuf (gc.gdkGC, pixbuf, 0, 0, int(x), int(y), imw, imh, gdk.RGB_DITHER_NONE, 0, 0) except AttributeError: # deprecated in 2.2 pixbuf.render_to_drawable(self.gdkDrawable, gc.gdkGC, 0, 0, int(x), int(y), imw, imh, gdk.RGB_DITHER_NONE, 0, 0)
def draw_image(self, x, y, im, origin, bbox): if bbox != None: l, b, w, h = bbox.get_bounds() #rectangle = (int(l), self.height-int(b+h), # int(w), int(h)) # set clip rect? flipud = origin == 'lower' rows, cols, image_str = im.as_str(flipud) image_array = fromstring(image_str, UInt8) image_array.shape = rows, cols, 4 pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, has_alpha=True, bits_per_sample=8, width=cols, height=rows) array = pixbuf_get_pixels_array(pixbuf) array[:, :, :] = image_array gc = self.new_gc() if flipud: y = self.height - y - rows try: # new in 2.2 # can use None instead of gc.gdkGC, if don't need clipping self.gdkDrawable.draw_pixbuf(gc.gdkGC, pixbuf, 0, 0, int(x), int(y), cols, rows, gdk.RGB_DITHER_NONE, 0, 0) except AttributeError: # deprecated in 2.2 pixbuf.render_to_drawable(self.gdkDrawable, gc.gdkGC, 0, 0, int(x), int(y), cols, rows, gdk.RGB_DITHER_NONE, 0, 0)