Ejemplo n.º 1
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
Ejemplo n.º 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
Ejemplo n.º 3
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)