From b6481d54eae73cd31f56b437d38da2fd1f6373c5 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Thu, 17 Sep 2009 13:54:20 +0200
Subject: [PATCH] [Jonathan Michalon] Make latex images theme aware.

---
 src/common/latex.py |  8 +++++++-
 src/gajim.py        | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/common/latex.py b/src/common/latex.py
index 2d783726d7..777577d1cf 100644
--- a/src/common/latex.py
+++ b/src/common/latex.py
@@ -114,6 +114,12 @@ 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'
+
 	# filter latex code with bad commands
 	if check_blacklist(str_):
 		# we triggered the blacklist, immediately return None
@@ -131,7 +137,7 @@ 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', 'rgb 1.0 1.0 1.0', '-T',
+		exitcode = try_run(['dvipng', '-bg', bg_str, '-fg', fg_str, '-T',
 				'tight', '-D', latex_png_dpi, tmpfile + '.dvi', '-o',
 				tmpfile + '.png'])
 
diff --git a/src/gajim.py b/src/gajim.py
index b8512ac43d..46357eb4b9 100644
--- a/src/gajim.py
+++ b/src/gajim.py
@@ -3036,6 +3036,25 @@ class Interface:
 			pep.user_send_tune(acct, artist, title, source)
 			gajim.connections[acct].music_track_info = music_track_info
 
+	def get_bg_fg_colors(self):
+		def gdkcolor_to_rgb (gdkcolor):
+			return [c / 65535. for c in (gdkcolor.red, gdkcolor.green,
+				gdkcolor.blue)]
+
+		def format_rgb (r, g, b):
+			return ' '.join([str(c) for c in ('rgb', r, g, b)])
+
+		def format_gdkcolor (gdkcolor):
+			return format_rgb (*gdkcolor_to_rgb (gdkcolor))
+		
+		# get style colors and create string for dvipng
+		dummy = gtk.Invisible()
+		dummy.ensure_style()
+		style = dummy.get_style()
+		bg_str = format_gdkcolor(style.base[gtk.STATE_NORMAL])
+		fg_str = format_gdkcolor(style.text[gtk.STATE_NORMAL])
+		return (bg_str, fg_str)
+
 	def read_sleepy(self):
 		'''Check idle status and change that status if needed'''
 		if not self.sleeper.poll():
-- 
GitLab