]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/lyxpreview2bitmap.py
make sure docs are disted
[lyx.git] / lib / scripts / lyxpreview2bitmap.py
index 0a1f77c85fd3a6887e7c06ca61246be67531a1ef..bb7438bf066c31ea32cb345bd3d04bab6333f376 100755 (executable)
@@ -1,4 +1,5 @@
 #! /usr/bin/env python
+# -*- coding: iso-8859-1 -*-
 
 # file lyxpreview2bitmap.py
 # This file is part of LyX, the document processor.
@@ -7,7 +8,7 @@
 # author Angus Leeming
 # with much advice from members of the preview-latex project:
 # David Kastrup, dak@gnu.org and
-# Jan-Åke Larsson, jalar@mai.liu.se.
+# Jan-Åke Larsson, jalar@mai.liu.se.
 
 # Full author contact details are available in file CREDITS
 
@@ -44,6 +45,7 @@
 #   the images correctly on the screen.
 
 import glob, os, re, string, sys
+from legacy_lyxpreview2ppm import legacy_conversion
 
 
 # Pre-compiled regular expressions.
@@ -65,7 +67,11 @@ def error(message):
 def find_exe(candidates, path):
     for prog in candidates:
         for directory in path:
-            full_path = os.path.join(directory, prog)
+            if os.name == "nt":
+                full_path = os.path.join(directory, prog + ".exe")
+            else:
+                full_path = os.path.join(directory, prog)
+
             if os.access(full_path, os.X_OK):
                 return full_path
 
@@ -102,7 +108,7 @@ def make_texcolor(hexcolor):
 
 def extract_metrics_info(dvipng_stdout, metrics_file):
     metrics = open(metrics_file, 'w')
-    metrics_re = re.compile("\[([0-9]+) depth=([0-9]+) height=([0-9]+)\]")
+    metrics_re = re.compile("\[([0-9]+) depth=(-?[0-9]+) height=(-?[0-9]+)")
 
     success = 0
     pos = 0
@@ -159,7 +165,16 @@ def main(argv):
     # External programs used by the script.
     path = string.split(os.getenv("PATH"), os.pathsep)
     latex = find_exe_or_terminate(["pplatex", "latex2e", "latex"], path)
-    dvipng = find_exe_or_terminate(["dvipng"], path)
+
+    # This can go once dvipng becomes widespread.
+    dvipng = find_exe(["dvipng"], path)
+    if dvipng == None:
+        if output_format == "ppm":
+            return legacy_conversion(argv)
+        else:
+            error("The old 'dvi->ps->ppm' conversion requires "
+                  "ppm as the output format")
+
     pngtopnm = ""
     if output_format == "ppm":
         pngtopnm = find_exe_or_terminate(["pngtopnm"], path)
@@ -191,6 +206,7 @@ def main(argv):
     if output_format == "ppm":
         convert_to_ppm_format(pngtopnm, latex_file_re.sub("", latex_file))
 
+    return 0
 
 if __name__ == "__main__":
     main(sys.argv)