]> git.lyx.org Git - features.git/commitdiff
* lyxpreview-lytex2bitmap.py: port color changes from lyxpreview2bitmap.py
authorJürgen Spitzmüller <spitz@lyx.org>
Tue, 29 Mar 2011 10:09:41 +0000 (10:09 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Tue, 29 Mar 2011 10:09:41 +0000 (10:09 +0000)
Why do we need two separate files actually? The difference of these two files is minimal.
Couldn't we introduce a further option for "lytex" mode in lyxpreview2bitmap.py instead?
This would significantly lower the maintenance burden.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38120 a592a061-630c-0410-9148-cb99ea01b6c8

lib/scripts/lyxpreview-lytex2bitmap.py

index 96c70ca15e990db010174b032a259f4ae1d535dc..197fd09d6a56f899b1f448fac72519b9c1e869c9 100755 (executable)
@@ -112,11 +112,15 @@ def extract_metrics_info(dvipng_stdout):
     return results
 
 
-def color_pdf(latex_file, bg_color):
-    use_preview_pdf_re = re.compile("(\s*\\\\usepackage\[[^]]+)(pdftex\]{preview})")
+def color_pdf(latex_file, bg_color, fg_color):
+    use_preview_pdf_re = re.compile("(\s*\\\\usepackage\[[^]]+)(pdftex|xetex\]{preview})")
 
     tmp = mkstemp()
-
+    
+    fg = ""
+    if fg_color != "0.000000,0.000000,0.000000":
+        fg = '  \\AtBeginDocument{\\let\\oldpreview\\preview\\renewcommand\\preview{\\oldpreview\\color[rgb]{%s}}}\n' % (fg_color)
+    
     success = 0
     try:
         for line in open(latex_file, 'r').readlines():
@@ -127,8 +131,9 @@ def color_pdf(latex_file, bg_color):
             success = 1
             tmp.write("  \\usepackage{color}\n" \
                   "  \\pagecolor[rgb]{%s}\n" \
+                  "%s" \
                   "%s\n" \
-                  % (bg_color, match.group()))
+                  % (bg_color, fg, match.group()))
             continue
 
     except:
@@ -174,6 +179,7 @@ def main(argv):
     fg_color = make_texcolor(argv[4], False)
     bg_color = make_texcolor(argv[5], False)
 
+    fg_color_gr = make_texcolor(argv[4], True)
     bg_color_gr = make_texcolor(argv[5], True)
 
     # External programs used by the script.
@@ -217,7 +223,7 @@ def main(argv):
         pngtopnm = find_exe_or_terminate(["pngtopnm"], path)
 
     # Move color information for PDF into the latex file.
-    if not color_pdf(latex_file, bg_color_gr):
+    if not color_pdf(latex_file, bg_color_gr, fg_color_gr):
         error("Unable to move color info into the latex file")
 
     # Compile the latex file.