]> git.lyx.org Git - lyx.git/commitdiff
From Enrico Forestieri: fix script to work with recent versions of preview-latex...
authorJürgen Spitzmüller <spitz@lyx.org>
Mon, 20 Feb 2006 19:29:58 +0000 (19:29 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Mon, 20 Feb 2006 19:29:58 +0000 (19:29 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13263 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ChangeLog
lib/scripts/lyxpreview2bitmap.py

index 372489f571fcd3977e8e16b94f8f6a1e04cf274b..0ad1f7b6b5feebb5f9751245d73e6b5e096f9a6f 100644 (file)
@@ -1,3 +1,8 @@
+2006-02-19  Enrico Forestieri  <forenr@tlc.unipr.it>
+
+       * scripts/lyxpreview2bitmap.py: fix script to work with recent versions
+       of preview-latex and dvipng (bug 2243).
+
 2006-02-19  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * bind/de_menus.bind: comment out obsolete bindings (bug 1161).
index f0af3babf8b89f84ac2805a74c03a3ce31b83974..3d3569e59b499bbc15b6d36869e08783863a8753 100755 (executable)
@@ -78,19 +78,29 @@ 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]+)")
+# "\[[0-9]+" can match two kinds of numbers: page numbers from dvipng
+# and glyph numbers from mktexpk. The glyph numbers always match
+# "\[[0-9]+\]" while the page number never is followed by "\]". Thus:
+    page_re = re.compile("\[([0-9]+)[^]]");
+    metrics_re = re.compile("depth=(-?[0-9]+) height=(-?[0-9]+)")
 
     success = 0
+    page = ""
     pos = 0
     while 1:
+        match = page_re.search(dvipng_stdout, pos)
+        if match == None:
+            break
+        page = match.group(1)
+        pos = match.end()
         match = metrics_re.search(dvipng_stdout, pos)
         if match == None:
             break
         success = 1
 
         # Calculate the 'ascent fraction'.
-        descent = string.atof(match.group(2))
-        ascent  = string.atof(match.group(3))
+        descent = string.atof(match.group(1))
+        ascent  = string.atof(match.group(2))
 
         frac = 0.5
         if ascent > 0 and descent > 0:
@@ -101,8 +111,8 @@ def extract_metrics_info(dvipng_stdout, metrics_file):
             if frac < 0 or frac > 1:
                 frac = 0.5
 
-        metrics.write("Snippet %s %f\n" % (match.group(1), frac))
-        pos = match.end(3) + 2
+        metrics.write("Snippet %s %f\n" % (page, frac))
+        pos = match.end() + 2
 
     return success