示例#1
0
    def __init__(self):
        gtk.DrawingArea.__init__(self)
        self.parser = MathtexParser()
        self.bakoma = BakomaFonts()
        self.stix = StixFonts()
# #          self.parser.parse(r"$R_{\mu\nu\rho}{}^{\sigma} = \nabla_\mu F_{\nu\rho}^\sigma$", 
        self.box =  \
            self.parser.parse(r"$x_{1,2}=\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$",
                            self.bakoma, 18, 99.0)
        self.rects, self.glyphs, self.bbox =  ship(0, 0, self.box)
示例#2
0
    def __init__(self,
                 expr,
                 fontset='bakoma',
                 fontsize=12,
                 dpi=100,
                 default_style='it',
                 cache=False):
        # Hash the arguments
        h = hash((expr, fontset, fontsize, dpi, default_style))

        if is_string_like(fontset):
            fontset = self.fontset_mapping[fontset](default_style)

        # Check the cache first
        if cache and h in self._cache:
            self.boxmodel = self._cache[h]
        # Parse the expression
        else:
            self.boxmodel = MathtexParser().parse(expr, fontset, fontsize, dpi)
            if cache:
                self._cache[h] = self.boxmodel

        # Use ship to get a stream of glyphs and rectangles
        bbox = ship(0, 0, self.boxmodel)[2]
        self.rects, self.glyphs, bbox = ship(-bbox[0], 0, self.boxmodel)

        # Calculate the exact width, height and depth
        self.width = bbox[2] - bbox[0]
        self.height = self.boxmodel.height
        self.depth = self.boxmodel.depth

        self.fontset = fontset
        self.fontsize = fontsize
        self.dpi = dpi
示例#3
0
class MathCell(gtk.DrawingArea):
    """Cell for display of maths."""

    __gsignals__ = { "expose-event": "override" }
  
    def __init__(self):
        gtk.DrawingArea.__init__(self)
        self.parser = MathtexParser()
        self.bakoma = BakomaFonts()
        self.stix = StixFonts()
# #          self.parser.parse(r"$R_{\mu\nu\rho}{}^{\sigma} = \nabla_\mu F_{\nu\rho}^\sigma$", 
        self.box =  \
            self.parser.parse(r"$x_{1,2}=\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$",
                            self.bakoma, 18, 99.0)
        self.rects, self.glyphs, self.bbox =  ship(0, 0, self.box)
      
    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)

 #       self.draw(cr, *self.window.get_size())

    def draw(self, cr, width, height):
        cr.set_source_rgb(0.5, 0.5, 0.7)
        cr.rectangle(0.5, 0.5, .5*width, .5*height)
        cr.fill()