On Wed, Jan 12, 2011 at 01:01:43PM +0100, [email protected] wrote:
>
> Tomorrow I'll try to write down this "splitter".
In order to avoid wasting time, I suggest to check whether the approach
can lead somewhere. For example, by using the quite simple attached
patch, whenever the legacy route is taken I get all previews except
the failing ones. However, the problem is that ghostscript is still
called for each snippet, so, when one has a large number of snippets
the conversion time becomes unacceptable.
I am afraid, something more clever is needed.
--
Enrico
Index: lib/scripts/legacy_lyxpreview2ppm.py
===================================================================
--- lib/scripts/legacy_lyxpreview2ppm.py (revisione 37182)
+++ lib/scripts/legacy_lyxpreview2ppm.py (copia locale)
@@ -256,7 +256,7 @@ def legacy_conversion(argv):
latex_status, latex_stdout = run_command(latex_call)
if latex_status != None:
- error("%s failed to compile %s" \
+ warning("%s had problems compiling %s" \
% (os.path.basename(latex), latex_file))
return legacy_conversion_step2(latex_file, dpi, output_format)
@@ -274,7 +274,7 @@ def legacy_conversion_step2(latex_file,
ps_file = latex_file_re.sub(".ps", latex_file)
pdf_file = latex_file_re.sub(".pdf", latex_file)
- dvips_call = '%s -o "%s" "%s"' % (dvips, ps_file, dvi_file)
+ dvips_call = '%s -i -o "%s" "%s"' % (dvips, ps_file, dvi_file)
dvips_failed = False
dvips_status, dvips_stdout = run_command(dvips_call)
@@ -300,13 +300,6 @@ def legacy_conversion_step2(latex_file,
gs_ext = "ppm"
# Generate the bitmap images
- gs_call = '%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=%s ' \
- '-sOutputFile="%s%%d.%s" ' \
- '-dGraphicsAlphaBit=%d -dTextAlphaBits=%d ' \
- '-r%f "%s"' \
- % (gs, gs_device, latex_file_re.sub("", latex_file), \
- gs_ext, alpha, alpha, resolution, ps_file)
-
if dvips_failed:
gs_call = '%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=%s ' \
'-sOutputFile="%s%%d.%s" ' \
@@ -314,10 +307,22 @@ def legacy_conversion_step2(latex_file,
'-r%f "%s"' \
% (gs, gs_device, latex_file_re.sub("", latex_file), \
gs_ext, alpha, alpha, resolution, pdf_file)
-
- gs_status, gs_stdout = run_command(gs_call)
- if gs_status != None:
- error("Failed: %s %s" % (os.path.basename(gs), ps_file))
+ gs_status, gs_stdout = run_command(gs_call)
+ if gs_status != None:
+ error("Failed: %s %s" % (os.path.basename(gs), ps_file))
+ else:
+ gs_call = '%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=%s ' \
+ '-sOutputFile="%s%%d.%s" ' \
+ '-dGraphicsAlphaBit=%d -dTextAlphaBits=%d ' \
+ '-r%f "%%s"' \
+ % (gs, gs_device, latex_file_re.sub("", latex_file), \
+ gs_ext, alpha, alpha, resolution)
+ i = 0
+ for file in glob.glob("%s.[0-9][0-9][0-9]" % latex_file_re.sub("",
latex_file)):
+ i = i + 1
+ gs_status, gs_stdout = run_command(gs_call % (i, file))
+ if gs_status != None:
+ warning("Failed: %s %s" % (os.path.basename(gs), file))
# Crop the images
if pnmcrop != None: