Esempio n. 1
0
    def save(self,
             filename,
             format='auto',
             backend='auto',
             backend_options={}):
        if format == 'auto':
            format = filename.split('.')[-1]
        if backend == 'auto':
            if format == 'png':
                backend = 'image'
            else:
                backend = 'cairo'

        # Create the backend instance
        if backend == 'image':
            backend = MathtexBackendImage()
        elif backend == 'cairo':
            if not HAVE_CAIRO_BACKEND:
                raise RuntimeError(
                    "Cairo backend requested when not available.")
            backend = MathtexBackendCairo()

        # Set the options for the backend
        backend.options = backend_options

        # Render!
        self.render_to_backend(backend)

        # Save
        backend.save(filename, format)
Esempio n. 2
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
        if not HAVE_MATHTEX: return

        ctx = gc.ctx

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

        ctx.save()
        ctx.translate(x, y - m.height - m.depth)
        if angle:
           ctx.rotate (-angle * npy.pi / 180)

        b.render_to_context(ctx)

        ctx.restore()
Esempio n. 3
0
    def do_expose_event(self, event):
        cr = self.window.cairo_create()
        cr.rectangle(event.area.x, event.area.y, 
                     event.area.width, event.area.height)
        cr.clip()

        width = self.bbox[2] - self.bbox[0]
        height = self.box.height
        depth = self.box.depth

        backend = MathtexBackendCairo()
        backend.set_canvas_size(self.box.width, self.box.height, 
                                self.box.depth, 100)
        backend.render(self.glyphs, self.rects)
        backend.render_to_context(cr)
Esempio n. 4
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
        if not HAVE_MATHTEX: return

        ctx = gc.ctx

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

        ctx.save()
        ctx.translate(x, y - m.height - m.depth)
        if angle:
            ctx.rotate(-angle * npy.pi / 180)

        b.render_to_context(ctx)

        ctx.restore()