[Zhihao Yuan & I] use convert is dvipng doesn't work. Fixes #5935

This commit is contained in:
Yann Leboulanger 2010-09-24 23:15:21 +02:00
parent 97ec4df020
commit 8d218ab0d0
3 changed files with 32 additions and 10 deletions

View File

@ -115,11 +115,16 @@ def latex_to_image(str_):
result = None
exitcode = 0
try:
bg_str, fg_str = gajim.interface.get_bg_fg_colors()
except:
# interface may not be available when we test latext at startup
bg_str, fg_str = 'rgb 1.0 1.0 1.0', 'rgb 0.0 0.0 0.0'
def fg_str(fmt):
try:
return [{'hex' : '+level-colors', 'tex' : '-fg'}[fmt],
gajim.interface.get_fg_color(fmt)]
except KeyError:
# interface may not be available when we test latex at startup
return []
except AttributeError:
# interface may not be available when we test latext at startup
return ['-fg', 'rgb 0.0 0.0 0.0']
# filter latex code with bad commands
if check_blacklist(str_):
@ -138,9 +143,13 @@ def latex_to_image(str_):
if exitcode == 0:
# convert dvi to png
latex_png_dpi = gajim.config.get('latex_png_dpi')
exitcode = try_run(['dvipng', '-bg', bg_str, '-fg', fg_str, '-T',
'tight', '-D', latex_png_dpi, tmpfile + '.dvi', '-o',
tmpfile + '.png'])
exitcode = try_run(['dvipng'] + fg_str('tex') + ['-T', 'tight', '-D',
latex_png_dpi, tmpfile + '.dvi', '-o', tmpfile + '.png'])
if exitcode:
# dvipng failed, try convert
exitcode = try_run(['convert'] + fg_str('hex') + ['-trim',
'-density', latex_png_dpi, tmpfile + '.dvi', tmpfile + '.png'])
# remove temp files created by us and TeX
extensions = ['.tex', '.log', '.aux', '.dvi']

View File

@ -92,8 +92,8 @@ class FeaturesWindow:
_('Requires python2.5.')),
_('LaTeX'): (self.latex_available,
_('Transform LaTeX expressions between $$ $$.'),
_('Requires texlive-latex-base and dvipng. You have to set \'use_latex\' to True in the Advanced Configuration Editor.'),
_('Requires texlive-latex-base and dvipng (All is in MikTeX). You have to set \'use_latex\' to True in the Advanced Configuration Editor.')),
_('Requires texlive-latex-base and (dvipng or ImageMagick). You have to set \'use_latex\' to True in the Advanced Configuration Editor.'),
_('Requires texlive-latex-base and (dvipng or ImageMagick) (All is in MikTeX). You have to set \'use_latex\' to True in the Advanced Configuration Editor.')),
_('End to End message encryption'): (self.pycrypto_available,
_('Encrypting chat messages.'),
_('Requires python-crypto.'),

View File

@ -2704,6 +2704,19 @@ class Interface:
fg_str = format_gdkcolor(style.text[gtk.STATE_NORMAL])
return (bg_str, fg_str)
def get_fg_color(self, fmt='hex'):
def format_gdkcolor (c):
if fmt == 'tex':
return ' '.join([str(s) for s in
('rgb', c.red_float, c.green_float, c.blue_float)])
elif fmt == 'hex':
return str(c)
# get foreground style color and create string
dummy = gtk.Invisible()
dummy.ensure_style()
return format_gdkcolor(dummy.get_style().text[gtk.STATE_NORMAL])
def read_sleepy(self):
"""
Check idle status and change that status if needed