Example #1
0
    def draw_image(self, gc, x, y, im):
        bbox = gc.get_clip_rectangle()

        if bbox != None:
            l,b,w,h = bbox.bounds
            #rectangle = (int(l), self.height-int(b+h),
            #             int(w), int(h))
            # set clip rect?

        rows, cols = im.shape[:2]

        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[:, :, :] = im[::-1]

        gc = self.new_gc()


        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)
Example #2
0
 def _draw_mathtext(self, gc, x, y, s, prop, angle):
     ox, oy, width, height, descent, font_image, used_characters = \
         self.mathtext_parser.parse(s, self.dpi, prop)
     if angle==90:
         width, height = height, width
         x -= width
     y -= height
     imw = font_image.get_width()
     imh = font_image.get_height()
     N = imw * imh
     Xall = npy.zeros((N,1), npy.uint8)
     image_str = font_image.as_str()
     Xall[:,0] = npy.fromstring(image_str, npy.uint8)
     Xs = npy.amax(Xall,axis=1)
     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
         self.gdkDrawable.draw_pixbuf (gc.gdkGC, pixbuf, 0, 0,
                                       int(x), int(y), imw, imh,
                                       gdk.RGB_DITHER_NONE, 0, 0)
     except AttributeError:
         pixbuf.render_to_drawable(self.gdkDrawable, gc.gdkGC, 0, 0,
                               int(x), int(y), imw, imh,
                               gdk.RGB_DITHER_NONE, 0, 0)
Example #3
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        ox, oy, width, height, descent, font_image, used_characters = \
            self.mathtext_parser.parse(s, self.dpi, prop)

        if angle == 90:
            width, height = height, width
            x -= width
        y -= height

        imw = font_image.get_width()
        imh = font_image.get_height()

        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] = (
            np.fromstring(font_image.as_str(), np.uint8).reshape((imh, imw)))

        # 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)
Example #4
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        ox, oy, width, height, descent, font_image, used_characters = \
            self.mathtext_parser.parse(s, self.dpi, prop)

        if angle == 90:
            width, height = height, width
            x -= width
        y -= height

        imw = font_image.get_width()
        imh = font_image.get_height()

        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] = (np.fromstring(font_image.as_str(), np.uint8).reshape(
            (imh, imw)))

        # 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)
Example #5
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        if not HAVE_MATHTEX:
            return

        m = Mathtex(s, matplotlib.rcParams['mathtext.fontset'],
                    prop.get_size_in_points(), self.dpi, rcParams['mathtext.default'],
                    cache=True)
        b = MathtexBackendImage()
        m.render_to_backend(b)

        width, height = m.width, m.height + m.depth
        font_image = b.image

        if angle==90:
            width, height = height, width
            x -= width
        y -= height

        imw = font_image.get_width()
        imh = font_image.get_height()
        N = imw * imh

        # a numpixels by num fonts array
        Xall = npy.zeros((N,1), npy.uint8)

        image_str = font_image.as_str()
        Xall[:,0] = npy.fromstring(image_str, npy.uint8)

        # get the max alpha at each pixel
        Xs = npy.amax(Xall,axis=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)
Example #6
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        ox, oy, width, height, descent, font_image, used_characters = \
            self.mathtext_parser.parse(s, self.dpi, prop)

        if angle == 90:
            width, height = height, width
            x -= width
        y -= height

        imw = font_image.get_width()
        imh = font_image.get_height()
        N = imw * imh

        # a numpixels by num fonts array
        Xall = np.zeros((N, 1), np.uint8)

        image_str = font_image.as_str()
        Xall[:, 0] = np.fromstring(image_str, np.uint8)

        # get the max alpha at each pixel
        Xs = np.amax(Xall, axis=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)
Example #7
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        ox, oy, width, height, descent, font_image, used_characters = \
            self.mathtext_parser.parse(s, self.dpi, prop)

        if angle==90:
            width, height = height, width
            x -= width
        y -= height

        imw = font_image.get_width()
        imh = font_image.get_height()
        N = imw * imh

        # a numpixels by num fonts array
        Xall = np.zeros((N,1), np.uint8)

        image_str = font_image.as_str()
        Xall[:,0] = np.fromstring(image_str, np.uint8)

        # get the max alpha at each pixel
        Xs = np.amax(Xall,axis=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)
Example #8
0
    def draw_image(self, x, y, im, 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?

        im.flipud_out()
        rows, cols, image_str = im.as_rgba_str()

        image_array = npy.fromstring(image_str, npy.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()

        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)

        # unflip
        im.flipud_out()
Example #9
0
    def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None):
        if bbox != None:
            l,b,w,h = bbox.bounds
            #rectangle = (int(l), self.height-int(b+h),
            #             int(w), int(h))
            # set clip rect?

        im.flipud_out()
        rows, cols, image_str = im.as_rgba_str()

        image_array = npy.fromstring(image_str, npy.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()


        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)

        # unflip
        im.flipud_out()
Example #10
0
 def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None):
     if bbox != None:
         l,b,w,h = bbox.bounds
     im.flipud_out()
     rows, cols, image_str = im.as_rgba_str()
     image_array = npy.fromstring(image_str, npy.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()
     y = self.height-y-rows
     try: # new in 2.2
         self.gdkDrawable.draw_pixbuf (gc.gdkGC, pixbuf, 0, 0,
                                       int(x), int(y), cols, rows,
                                       gdk.RGB_DITHER_NONE, 0, 0)
     except AttributeError:
         pixbuf.render_to_drawable(self.gdkDrawable, gc.gdkGC, 0, 0,
                               int(x), int(y), cols, rows,
                               gdk.RGB_DITHER_NONE, 0, 0)
     im.flipud_out()