]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/lyxpreview2bitmap.py
Pass parameters by reference (performance)
[lyx.git] / lib / scripts / lyxpreview2bitmap.py
index c4c1844b669e9b6031936e84095d6bd242b23a30..ace46d21c69599ebafab87313b9854dc5d44d3ae 100755 (executable)
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
 # file lyxpreview2bitmap.py
@@ -155,42 +154,6 @@ def extract_metrics_info(dvipng_stdout):
     return results
 
 
-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():
-            match = use_preview_pdf_re.match(line)
-            if match == None:
-                tmp.write(line)
-                continue
-            success = 1
-            tmp.write("  \\usepackage{color}\n" \
-                  "  \\pagecolor[rgb]{%s}\n" \
-                  "%s" \
-                  "%s\n" \
-                  % (bg_color, fg, match.group()))
-            continue
-
-    except:
-        # Unable to open the file, but do nothing here because
-        # the calling function will act on the value of 'success'.
-        warning('Warning in color_pdf! Unable to open "%s"' % latex_file)
-        warning(`sys.exc_type` + ',' + `sys.exc_value`)
-
-    if success:
-        copyfileobj(tmp, open(latex_file,"wb"), 1)
-
-    return success
-
-
 def fix_latex_file(latex_file):
     documentclass_re = re.compile("(\\\\documentclass\[)(1[012]pt,?)(.+)")
 
@@ -385,9 +348,6 @@ def main(argv):
     fg_color_dvipng = make_texcolor(fg_color, False)
     bg_color_dvipng = make_texcolor(bg_color, False)
 
-    fg_color_gr = make_texcolor(fg_color, True)
-    bg_color_gr = make_texcolor(bg_color, True)
-
     # External programs used by the script.
     latex = find_exe_or_terminate(latex or latex_commands)
     bibtex = find_exe(bibtex or bibtex_commands)
@@ -406,8 +366,7 @@ def main(argv):
     progress("Altering the latex file for font size and colors")
 
     # Omit font size specification in latex file.
-    if not fix_latex_file(latex_file):
-        warning("Unable to remove font size from the latex file")
+    fix_latex_file(latex_file)
 
     if lilypond:
         progress("Preprocess the latex file through %s" % lilypond_book)
@@ -448,12 +407,10 @@ def main(argv):
             return legacy_conversion_step1(latex_file, dpi, output_format,
                 fg_color, bg_color, latex, pdf_output)
 
-    # Move color information for PDF into the latex file.
-    if not color_pdf(latex_file, bg_color_gr, fg_color_gr):
-        warning("Unable to move color info into the latex file")
-
     # Compile the latex file.
     latex_status, latex_stdout = run_latex(latex, latex_file, bibtex)
+    if latex_status:
+      return (latex_status, [])
 
     # The dvi output file name
     dvi_file = latex_file_re.sub(".dvi", latex_file)