]> git.lyx.org Git - features.git/commitdiff
Allow previewing images generated through postscript specials which are
authorEnrico Forestieri <forenr@lyx.org>
Fri, 3 Dec 2010 17:37:38 +0000 (17:37 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Fri, 3 Dec 2010 17:37:38 +0000 (17:37 +0000)
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

lib/scripts/lyxpreview-lytex2bitmap.py
lib/scripts/lyxpreview2bitmap.py

index 9759822a306d62ed84519a32d486d960ed098bc4..384c0da43551ce99a81646cc2d875a57a2d06e7a 100755 (executable)
@@ -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)
 
index ac425f14d272a6aea3df419f8917769224d3da7a..517d710f950c4bd717c855995fe3660156563606 100755 (executable)
@@ -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)