Esempio n. 1
0
class TeX1():
  """
  Render TeX code with matplotlib mathtext. Doesn't need a LaTeX installation.
  @enocde ........ Enocde base64
  @init_render ... Render the PNG image when creating an instance.
  """
  def __init__(self, src, encode = False, cfg = fs()):

    self.cfg = copy(cfg)
    self.src = src
    self.encode = encode
    self.png = None

    if self.cfg.initrender:
      self.render(self.cfg)

  def render(self, cfg):
    self.mtp = MathTextParser('bitmap')
    f = StringIO()
    self.mtp.to_png(f, self.src, cfg.forecolor, cfg.resolution, cfg.fontsize)
    bin_data = f.getvalue()
    if self.encode:
      bin_data = encodestring(bin_data)
    self.png = bin_data
    f.close()

  def _repr_png_(self):
    return self.png
Esempio n. 2
0
class TeX1():
  """
  Render TeX code with matplotlib mathtext. Doesn't need a LaTeX installation.
  @texstr ........ TeX code as string
  @color ......... Font color
  @dpi ........... Resolution (dots per inch)
  @fontsize ...... Font size
  @enocde ........ Enocde base64
  @init_render ... Render the PNG image when creating an instance.
                   If 'False' one has to call the render method explicitly.
  """
  def __init__(self, texstr, color = 'black', dpi = 120, fontsize = 12,
    encode=False, init_render = True):

    self.texstr = texstr
    self.color = color
    self.dpi = dpi
    self.fontsize = fontsize
    self.encode = encode
    self.init_render = init_render
    self.png = None

    if self.init_render:
      self.render()

  def render(self):
    self.mtp = MathTextParser('bitmap')
    f = StringIO()
    self.mtp.to_png(f, self.texstr, self.color, self.dpi, self.fontsize)
    bin_data = f.getvalue()
    if self.encode:
      bin_data = encodestring(bin_data)
    self.png = bin_data
    f.close()

  def set_texstr(self, texstr):
    self.texstr = texstr
    self.render()

  def set_color(self, color):
    self.color = color
    self.render()

  def set_dpi(self, dpi):
    self.dpi = dpi
    self.render()

  def set_fontsize(self, fontsize):
    self.fontsize = fontsize
    self.render()

  def set_encode(self, encode):
    self.encode = encode
    self.render()

  def _repr_png_(self):
    return self.png
Esempio n. 3
0
class TeX1():
  """
  Render TeX code with matplotlib mathtext. Doesn't need a LaTeX installation.
  @texstr ........ TeX code as string
  @color ......... Font color
  @dpi ........... Resolution (dots per inch)
  @fontsize ...... Font size
  @enocde ........ Enocde base64
  @init_render ... Render the PNG image when creating an instance.
                   If 'False' one has to call the render method explicitly.
  """
  def __init__(self, texstr, color = 'black', dpi = 120, fontsize = 12,
    encode=False, init_render = True):
    self.texstr = texstr
    self.color = color
    self.dpi = dpi
    self.fontsize = fontsize
    self.encode = encode
    self.init_render = init_render
    self.png = None
 
    if self.init_render:
      self.render()
 
  def render(self):
    self.mtp = MathTextParser('bitmap')
    f = StringIO()
    self.mtp.to_png(f, self.texstr, self.color, self.dpi, self.fontsize)
    bin_data = f.getvalue()
    if self.encode:
      bin_data = encodestring(bin_data)
    self.png = bin_data
    f.close()
 
  def set_texstr(self, texstr):
    self.texstr = texstr
    self.render()
 
  def set_color(self, color):
    self.color = color
    self.render()
 
  def set_dpi(self, dpi):
    self.dpi = dpi
    self.render()
 
  def set_fontsize(self, fontsize):
    self.fontsize = fontsize
    self.render()
 
  def set_encode(self, encode):
    self.encode = encode
    self.render()
 
  def _repr_png_(self):
    return self.png
Esempio n. 4
0
    def updateShape(self):
        try:
            self.bitmapName = './tmp/tex_bmp_' + str(self.uid) + '.png'
            q = MathTextParser('Bitmap')
            q.to_png(self.bitmapName, self.parameter['LaTex'].value)

            self.png = QPixmap(self.bitmapName)

        except:
            print ('>>> ERROR ImageLaTex.updateShape')
            print ('    Syntax Error - chyba pri update/parsovani LaTex retazca alebo renedrovani')
            print ('    obrazku ' + self.bitmapName)
            self.png = QPixmap(self.path + '/img/error_tex_format.png')