Hi all!

For some reason the dvipng distributed with miktex (at least the one I have
installed) fails to generate the instant preview images:

$ python /path/to/lyxpreview2bitmap.py png 0lyxpreview.tex 128 000000 f0f0f0
makepk: METAFONT failed on "cmmi12".
C:\texmf\miktex\bin\dvipng.exe warning: font cmmi12 at 512 dpi not found, 
characters will be left blank
makepk: METAFONT failed on "cmti8".
C:\texmf\miktex\bin\dvipng.exe warning: font cmti8 at 512 dpi not found, 
characters will be left blank
makepk: METAFONT failed on "cmr12".
C:\texmf\miktex\bin\dvipng.exe warning: font cmr12 at 512 dpi not found, 
characters will be left blank
C:\texmf\miktex\bin\dvipng.exe warning: at (1,-15) ignored header 
\special{!/[EMAIL PROTECTED](11.81)def} Failed to extract metrics info from 
dvipng

$ dvipng --version
This is C:\texmf\miktex\bin\dvipng.exe (dvipng) 1.6 Copyright 2002-2005 Jan-Ake 
Larsson
dvipng.exe (dvipng) 1.6
kpathsea version 3.3.2
Copyright (C) 2002-2005 Jan-Ake Larsson.
There is NO warranty.  You may redistribute this software
under the terms of the GNU General Public License.
For more information about these matters, see the files
named COPYING and dvipng.c.


So, I tried to force using the legacy_lyxpreview2ppm.py script only to
discover that it can only generate ppm images (as its name implies ;-)).

I propose the patch at the bottom to also allow png generation in the
legacy script. The patch also addresses the problem that when "ascent" or
"descent" are zero, then the generated image is not correctly aligned on
its baseline with the surrounding text.

Another problem I faced is the following. When not specifying a
\preview_scale_factor in preferences, the instant-preview inlined equations
are perfectly aligned on the baseline, but specifying, for example,
"\preview_scale_factor 1.02" causes the inlined images to be shifted down
by a noticeable amount.

I obviated to this by hardcoding in the conversion script "frac = 1.02*frac",
after frac is evaluated in extract_metrics_info(), where 1.02 matches my
\preview_scale_factor. I think that this should be done in the LyX sources
but I didn't had a look at it.

--
Enrico


--- ./lib/scripts/lyxpreview2bitmap.py  2005-09-21 11:22:18.000000000 +0200
+++ /c/Programmi/LyX-1.4.0/Resources/LyX-1.4.0pre3/scripts/lyxpreview2bitmap.py 
2006-01-03 10:55:48.000000000 +0100
@@ -93,7 +93,7 @@
         ascent  = string.atof(match.group(3))
 
         frac = 0.5
-        if ascent > 0 and descent > 0:
+        if ascent >= 0 and descent >= 0:
             if abs(ascent + descent) > 0.1:
                 frac = ascent / (ascent + descent)
 
@@ -145,15 +145,11 @@
     # This can go once dvipng becomes widespread.
     dvipng = find_exe(["dvipng"], path)
     if dvipng == None:
-        if output_format == "ppm":
-            # The data is input to legacy_conversion in as similar
-            # as possible a manner to that input to the code used in
-            # LyX 1.3.x.
-            vec = [ argv[0], argv[2], argv[3], argv[1], argv[4], argv[5] ]
-            return legacy_conversion(vec)
-        else:
-            error("The old 'dvi->ps->ppm' conversion requires "
-                  "ppm as the output format")
+   # The data is input to legacy_conversion in as similar
+   # as possible a manner to that input to the code used in
+   # LyX 1.3.x.
+   vec = [ argv[0], argv[2], argv[3], argv[1], argv[4], argv[5] ]
+   return legacy_conversion(vec)
 
     pngtopnm = ""
     if output_format == "ppm":


--- ./lib/scripts/legacy_lyxpreview2ppm.py  2005-09-21 11:22:18.000000000 +0200
+++ 
/c/Programmi/LyX-1.4.0/Resources/LyX-1.4.0pre3/scripts/legacy_lyxpreview2ppm.py 
2006-01-03 11:43:58.000000000 +0100
@@ -95,7 +95,7 @@
                 descent = string.atoi(match.group(3))
 
                 frac = 0.5
-                if ascent > 0 and descent > 0:
+                if ascent >= 0 and descent >= 0:
                     ascent = float(ascent) + tp_ascent
                     descent = float(descent) - tp_descent
 
@@ -226,8 +226,14 @@
     dpi = string.atoi(argv[2])
 
     output_format = argv[3]
-    if output_format != "ppm":
-        error("This script will generate ppm format images only.")
+    if output_format == "ppm":
+   gsdevice = "pnmraw"
+   gssuffix = "ppm"
+    elif output_format == "png":
+   gsdevice = "png16m"
+   gssuffix = "png"
+    else:
+        error("This script will generate png or ppm format images only.")
 
     fg_color = argv[4]
     bg_color = argv[5]
@@ -272,12 +278,12 @@
         alpha = 2
 
     # Generate the bitmap images
-    gs_call = '%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pnmraw ' \
-              '-sOutputFile="%s%%d.ppm" ' \
+    gs_call = '%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=%s ' \
+              '-sOutputFile="%s%%d.%s" ' \
               '-dGraphicsAlphaBit=%d -dTextAlphaBits=%d ' \
               '-r%f "%s"' \
-              % (gs, latex_file_re.sub("", latex_file), \
-                 alpha, alpha, resolution, ps_file)
+              % (gs, gsdevice, latex_file_re.sub("", latex_file), \
+                 gssuffix, alpha, alpha, resolution, ps_file)
 
     gs_status, gs_stdout = run_command(gs_call)
     if gs_status != None:



Reply via email to