]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/legacy_lyxpreview2ppm.py
* lib/scripts/TeXFiles.py:
[lyx.git] / lib / scripts / legacy_lyxpreview2ppm.py
index 3bf1de27c12894a455121c0dd67cd96f9b6e8fe0..f4f13a92233f01e3374c66b3c86e16c484a055a3 100644 (file)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# -*- coding: iso-8859-1 -*-
+# -*- coding: utf-8 -*-
 
 # file legacy_lyxpreview2ppm.py
 # This file is part of LyX, the document processor.
@@ -10,7 +10,7 @@
 
 # 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.
 # and with much help testing the code under Windows from
 #   Paul A. Rubin, rubin@msu.edu.
 
@@ -91,14 +91,22 @@ def extract_metrics_info(log_file, metrics_file):
                 error("Unexpected data in %s\n%s" % (log_file, line))
 
             if snippet:
-                ascent  = string.atof(match.group(2)) + tp_ascent
-                descent = string.atof(match.group(3)) - tp_descent
+                ascent  = string.atoi(match.group(2))
+                descent = string.atoi(match.group(3))
 
                 frac = 0.5
-                if abs(ascent + descent) > 0.1:
-                    frac = ascent / (ascent + descent)
+                if ascent >= 0 and descent >= 0:
+                    ascent = float(ascent) + tp_ascent
+                    descent = float(descent) - tp_descent
 
-                    metrics.write("Snippet %s %f\n" % (match.group(1), frac))
+                    if abs(ascent + descent) > 0.1:
+                        frac = ascent / (ascent + descent)
+
+                    # Sanity check
+                    if frac < 0 or frac > 1:
+                            frac = 0.5
+
+                metrics.write("Snippet %s %f\n" % (match.group(1), frac))
 
             else:
                 tp_descent = string.atof(match.group(2))
@@ -226,7 +234,7 @@ def legacy_conversion(argv):
 
     # External programs used by the script.
     path = string.split(os.environ["PATH"], os.pathsep)
-    latex   = find_exe_or_terminate(["pplatex", "latex2e", "latex"], path)
+    latex   = find_exe_or_terminate(["pplatex", "platex", "latex2e", "latex"], path)
     dvips   = find_exe_or_terminate(["dvips"], path)
     gs      = find_exe_or_terminate(["gswin32c", "gs"], path)
     pnmcrop = find_exe(["pnmcrop"], path)