# HG changeset patch
# User Yann Leboulanger <asterix@lagaule.org>
# Date 1285362921 -7200
# Node ID c821dd3af25fdd8b534b2fa2e39dd9f6068517a3
# Parent e81ceeabe85a44ebb07fe493bd4482f2e32c4d7d
[Zhihao Yuan & I] use convert is dvipng doesn't work. Fixes #5935
--- a/src/common/latex.py
+++ b/src/common/latex.py
@@ -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']
--- a/src/features_window.py
+++ b/src/features_window.py
@@ -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.'),
--- a/src/gui_interface.py
+++ b/src/gui_interface.py
@@ -2972,6 +2972,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