Example #1
0
 def test_concat_ctm(self):
     gc = basecore2d.GraphicsContextBase()
     ident = affine.affine_identity()
     trans = affine.affine_from_rotation(2.0)
     desired = affine.concat(ident, trans)
     gc.concat_ctm(trans)
     actual = gc.get_ctm()
     self.assertTrue(alltrue(ravel(actual == desired)))
 def test_concat_ctm(self):
     gc = basecore2d.GraphicsContextBase()
     ident = affine.affine_identity()
     trans = affine.affine_from_rotation(2.)
     x, y = 2., 3.
     desired = affine.concat(ident, trans)
     gc.concat_ctm(trans)
     actual = gc.get_ctm()
     self.assert_(alltrue(ravel(actual == desired)))
 def test_concat(self):
     a, b, c, d, tx, ty = 1, 2, 3, 4, 5, 6
     transform1 = affine.affine_from_values(a, b, c, d, tx, ty)
     a, b, c, d, tx, ty = 2, 3, 4, 5, 6, 7
     transform2 = affine.affine_from_values(a, b, c, d, tx, ty)
     tot_transform = affine.concat(transform1, transform2)
     pt1 = array([1., -1., 1.])
     actual = dot(pt1, tot_transform)
     # this does the first transform and the scaling separately
     desired = dot(dot(pt1, transform2), transform1)
     assert (alltrue((actual - desired) < 1e-6))
Example #4
0
 def test_concat(self):
     a,b,c,d,tx,ty = 1,2,3,4,5,6
     transform1 = affine.affine_from_values(a,b,c,d,tx,ty)
     a,b,c,d,tx,ty = 2,3,4,5,6,7
     transform2 = affine.affine_from_values(a,b,c,d,tx,ty)
     tot_transform = affine.concat(transform1,transform2)
     pt1 = array([1.,-1.,1.])
     actual = dot(pt1,tot_transform)
     # this does the first transform and the scaling separately
     desired = dot(dot(pt1,transform2),transform1)
     assert(alltrue( (actual - desired) < 1e-6 ))
Example #5
0
    def concat_ctm(self, transform):
        """ Concatenates the transform to current coordinate transform matrix.

            Parameters
            ----------
            transform : affine_matrix
                the transform matrix to concatenate with
                the current coordinate matrix.
        """
        self.state.ctm = affine.concat(self.state.ctm, transform)
        self.active_subpath.append((CONCAT_CTM, (transform,)))
        self.path_transform_indices.append(len(self.active_subpath)-1)
Example #6
0
    def concat_ctm(self, transform):
        """ Concatenates the transform to current coordinate transform matrix.

            Parameters
            ----------
            transform : affine_matrix
                the transform matrix to concatenate with
                the current coordinate matrix.
        """
        self.state.ctm = affine.concat(self.state.ctm, transform)
        self.active_subpath.append((CONCAT_CTM, (transform,)))
        self.path_transform_indices.append(len(self.active_subpath) - 1)
Example #7
0
 def device_show_text(self, text):
     ttm = self.get_text_matrix()
     ctm = self.get_ctm()  # not device_ctm!!
     m = affine.concat(ctm,ttm)
     tx,ty,sx,sy,angle = affine.trs_factor(m)
     angle = angle * 180. / pi
     gc = self._backend.new_gc()
     text = unicode_to_mathtext(text)
     if self._backend.flipy():
         ty = self.height() - ty
     self._backend.draw_text(gc, tx, ty - 1, text,
                             self._font_prop, angle, ismath=True)
     gc.restore()
Example #8
0
 def device_show_text(self, text):
     text = text.encode('ascii', 'xmlcharrefreplace')
     ttm = self.get_text_matrix()
     ctm = self.get_ctm()  # not device_ctm!!
     m = affine.concat(ctm,ttm)
     #height = self.get_full_text_extent(text)[1]
     a,b,c,d,tx,ty = affine.affine_params(m)
     transform = 'matrix(%(a)f,%(b)f,%(c)f,%(d)f,%(tx)f,%(ty)f) scale(1,-1)' % locals()
     self._emit('text', contents=text,
                kw={'font-family': self.font.fontName,
                    'font-size': str(self.font_size),
                    'xml:space': 'preserve',
                    'transform': transform})
Example #9
0
 def device_show_text(self, text):
     ttm = self.get_text_matrix()
     ctm = self.get_ctm()  # not device_ctm!!
     m = affine.concat(ctm,ttm)
     if self.state.clipping_path:
         self.contents.write('clipsave\n')
         self.contents.write('%3.3f %3.3f %3.3f %3.3f rectclip\n' % self.state.clipping_path)
     self.contents.write('gsave\n')
     self.device_transform_device_ctm(LOAD_CTM, [m])
     self.contents.write('%3.3f %3.3f moveto\n' % (0,0))
     r,g,b,a = self.state.line_color
     self.contents.write('%1.3f %1.3f %1.3f setrgbcolor\n' % (r,g,b) )
     text = text.encode('ascii', 'replace')
     self.contents.write('(%s) show\n' % text)
     self.contents.write('grestore\n')
     if self.state.clipping_path:
         self.contents.write('cliprestore\n')
Example #10
0
    def device_transform_device_ctm(self, func, args):
        """ Default implementation for handling scaling matrices.

            Many implementations will just use this function.  Others, like
            OpenGL, can benefit from overriding the method and using
            hardware acceleration.
        """
        if func == SCALE_CTM:
            self.device_ctm = affine.scale(self.device_ctm, args[0], args[1])
        elif func == ROTATE_CTM:
            self.device_ctm = affine.rotate(self.device_ctm, args[0])
        elif func == TRANSLATE_CTM:
            self.device_ctm = affine.translate(self.device_ctm, args[0],
                                               args[1])
        elif func == CONCAT_CTM:
            self.device_ctm = affine.concat(self.device_ctm, args[0])
        elif func == LOAD_CTM:
            self.device_ctm = args[0].copy()
Example #11
0
 def device_show_text(self, text):
     ttm = self.get_text_matrix()
     ctm = self.get_ctm()  # not device_ctm!!
     m = affine.concat(ctm, ttm)
     tx, ty, sx, sy, angle = affine.trs_factor(m)
     angle = angle * 180. / pi
     gc = self._backend.new_gc()
     text = unicode_to_mathtext(text)
     if self._backend.flipy():
         ty = self.height() - ty
     self._backend.draw_text(gc,
                             tx,
                             ty - 1,
                             text,
                             self._font_prop,
                             angle,
                             ismath=True)
     gc.restore()
Example #12
0
    def device_transform_device_ctm(self, func, args):
        """ Default implementation for handling scaling matrices.

            Many implementations will just use this function.  Others, like
            OpenGL, can benefit from overriding the method and using
            hardware acceleration.
        """
        if func == SCALE_CTM:
            self.device_ctm = affine.scale(self.device_ctm, args[0], args[1])
        elif func == ROTATE_CTM:
            self.device_ctm = affine.rotate(self.device_ctm, args[0])
        elif func == TRANSLATE_CTM:
            self.device_ctm = affine.translate(self.device_ctm, args[0],
                                               args[1])
        elif func == CONCAT_CTM:
            self.device_ctm = affine.concat(self.device_ctm, args[0])
        elif func == LOAD_CTM:
            self.device_ctm = args[0].copy()