]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/fig2pdftex.py
Revert "DocBook: add new layout parameter DocBookWrapperMergeWithPrevious."
[lyx.git] / lib / scripts / fig2pdftex.py
index 6f711bffbce6f2e26595b8e3ca840ef46000a718..b458ccd8f3b7f368469162202ec500be2b87ed86 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
 # file fig2pdf.py
@@ -27,7 +26,7 @@
 #   the real pdf file will be overwritten by a tex file named file.pdf.
 #
 
-
+from __future__ import print_function
 import os, sys, re
 
 
@@ -36,7 +35,7 @@ def runCommand(cmd):
         run a command, quit if fails
     '''
     if os.system(cmd) != 0:
-        print "Command '%s' fails." % cmd
+        print("Command '%s' fails." % cmd)
         sys.exit(1)
 
 
@@ -78,16 +77,16 @@ else:
     # The generated PostScript commands are extracted from epstopdf, distributed
     # with tetex.
     epsfile = outbase + '.pstex'
-    tmp = open(epsfile + '.??', 'w')
-    boundingboxline = re.compile('%%BoundingBox:\s+(\d*)\s+(\d*)\s+(\d*)\s+(\d*)')
-    for line in open(epsfile).xreadlines():
-        if line[:13] == '%%BoundingBox':
-            (llx, lly, urx, ury) = map(int, boundingboxline.search(line).groups())
+    tmp = mkstemp()
+    boundingboxline = re.compile(b'%%BoundingBox:\s+(\d*)\s+(\d*)\s+(\d*)\s+(\d*)')
+    for line in open(epsfile, 'rb'):
+        if line[:13] == b'%%BoundingBox':
+            (llx, lly, urx, ury) = list(map(int, boundingboxline.search(line).groups()))
             width = urx - llx
             height = ury - lly
             xoffset = - llx
             yoffset = - lly
-            tmp.write('''%%%%BoundingBox: 0 0 %d %d
+            tmp.write(b'''%%%%BoundingBox: 0 0 %d %d
 << /PageSize  [%d %d] >> setpagedevice
 gsave %d %d translate
 ''' % (width, height, width, height, xoffset, yoffset))