示例#1
0
文件: pdf.py 项目: wilsaj/enable
 def get_text_matrix(self):
     """
         temporarily not implemented.  can perhaps get the _textmatrix object off
         of the canvas if we need to.
     """
     a, b, c, d, tx, ty = self.gc._textMatrix
     #print "get text matrix", a,b,c,d,tx,ty
     return affine.affine_from_values(a, b, c, d, tx, ty)
示例#2
0
文件: gl.py 项目: GaZ3ll3/enable
    def draw_image(self, img, rect=None, force_copy=False):
        """ Renders a GraphicsContextArray into this GC """
        xform = self.get_ctm()
        x0 = xform[4]
        y0 = xform[5]

        image = image_as_array(img)
        shape = image.shape
        if shape[2] == 4:
            fmt = "RGBA"
        else:
            fmt = "RGB"
        aii = ArrayImage(image, format=fmt)
        texture = aii.texture

        # The texture coords consists of (u,v,r) for each corner of the
        # texture rectangle.  The coordinates are stored in the order
        # bottom left, bottom right, top right, top left.
        x, y, w, h = rect
        texture.width = w
        texture.height = h
        t = texture.tex_coords
        points = array([
            [x,   y+h],
            [x+w, y+h],
            [x+w, y],
            [x,   y],
        ])
        p = transform_points(affine_from_values(*xform), points)
        a = (gl.GLfloat*32)(
            t[0],   t[1],   t[2],  1.,
            p[0,0], p[0,1], 0,     1.,
            t[3],   t[4],   t[5],  1.,
            p[1,0], p[1,1], 0,     1.,
            t[6],   t[7],   t[8],  1.,
            p[2,0], p[2,1], 0,     1.,
            t[9],   t[10],  t[11], 1.,
            p[3,0], p[3,1], 0,     1.,
        )
        gl.glPushAttrib(gl.GL_ENABLE_BIT)
        gl.glEnable(texture.target)
        gl.glBindTexture(texture.target, texture.id)
        gl.glPushClientAttrib(gl.GL_CLIENT_VERTEX_ARRAY_BIT)
        gl.glInterleavedArrays(gl.GL_T4F_V4F, 0, a)
        gl.glDrawArrays(gl.GL_QUADS, 0, 4)
        gl.glPopClientAttrib()
        gl.glPopAttrib()