From 8d218ab0d06c870849f944c6a4b99fe521aff6fb Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Fri, 24 Sep 2010 23:15:21 +0200 Subject: [PATCH] [Zhihao Yuan & I] use convert is dvipng doesn't work. Fixes #5935 --- src/common/latex.py | 25 +++++++++++++++++-------- src/features_window.py | 4 ++-- src/gui_interface.py | 13 +++++++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/common/latex.py b/src/common/latex.py index 95e0b09de..75a1a699e 100644 --- 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'] diff --git a/src/features_window.py b/src/features_window.py index e9a823c16..4e0aeeade 100644 --- 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.'), diff --git a/src/gui_interface.py b/src/gui_interface.py index 61f86c641..a60ce0b22 100644 --- a/src/gui_interface.py +++ b/src/gui_interface.py @@ -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