From: Enrico Forestieri Date: Fri, 3 Dec 2010 17:37:38 +0000 (+0000) Subject: Allow previewing images generated through postscript specials which are X-Git-Tag: 2.0.0~1541 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=32ea5966c5aa9c21405c0cefe5dd6a4c2eb3ee86;p=features.git Allow previewing images generated through postscript specials which are not correctly handled by dvipng. When a ps special is detected in the dvi file, the old good legacy method is used. Patch from Ale. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36685 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/scripts/lyxpreview-lytex2bitmap.py b/lib/scripts/lyxpreview-lytex2bitmap.py index 9759822a30..384c0da435 100755 --- a/lib/scripts/lyxpreview-lytex2bitmap.py +++ b/lib/scripts/lyxpreview-lytex2bitmap.py @@ -222,8 +222,25 @@ def main(argv): # FIXME: skip unnecessary dvips trial in legacy_conversion_step2 return legacy_conversion_step2(latex_file, dpi, output_format) - # Run the dvi file through dvipng. + # The dvi output file name dvi_file = latex_file_re.sub(".dvi", latex_file) + + # Check for PostScript specials in the dvi, badly supported by dvipng + # This is required for correct rendering of PSTricks and TikZ + dv2dt = find_exe_or_terminate(["dv2dt"], path) + dv2dt_call = '%s %s' % (dv2dt, dvi_file) + + # The output from dv2dt goes to stdout + dv2dt_status, dv2dt_output = run_command(dv2dt_call) + psliteral_re = re.compile("^special[1-4] [0-9]+ '(\"|ps:)") + for dtl_line in dv2dt_output.split("\n"): + if psliteral_re.match(dtl_line) != None: + # Literal PostScript special detected! + # Fallback to legacy conversion + vec = [argv[0], argv[2], argv[3], argv[1], argv[4], argv[5], latex] + return legacy_conversion(vec) + + # Run the dvi file through dvipng. dvipng_call = '%s -Ttight -depth -height -D %d -fg "%s" -bg "%s" "%s"' \ % (dvipng, dpi, fg_color, bg_color, dvi_file) diff --git a/lib/scripts/lyxpreview2bitmap.py b/lib/scripts/lyxpreview2bitmap.py index ac425f14d2..517d710f95 100755 --- a/lib/scripts/lyxpreview2bitmap.py +++ b/lib/scripts/lyxpreview2bitmap.py @@ -207,8 +207,25 @@ def main(argv): # FIXME: skip unnecessary dvips trial in legacy_conversion_step2 return legacy_conversion_step2(latex_file, dpi, output_format) - # Run the dvi file through dvipng. + # The dvi output file name dvi_file = latex_file_re.sub(".dvi", latex_file) + + # Check for PostScript specials in the dvi, badly supported by dvipng + # This is required for correct rendering of PSTricks and TikZ + dv2dt = find_exe_or_terminate(["dv2dt"], path) + dv2dt_call = '%s %s' % (dv2dt, dvi_file) + + # The output from dv2dt goes to stdout + dv2dt_status, dv2dt_output = run_command(dv2dt_call) + psliteral_re = re.compile("^special[1-4] [0-9]+ '(\"|ps:)") + for dtl_line in dv2dt_output.split("\n"): + if psliteral_re.match(dtl_line) != None: + # Literal PostScript special detected! + # Fallback to legacy conversion + vec = [argv[0], argv[2], argv[3], argv[1], argv[4], argv[5], latex] + return legacy_conversion(vec) + + # Run the dvi file through dvipng. dvipng_call = '%s -Ttight -depth -height -D %d -fg "%s" -bg "%s" "%s"' \ % (dvipng, dpi, fg_color, bg_color, dvi_file)