]> 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 19207d107baefe5e64ef280b3d3042045022361a..b458ccd8f3b7f368469162202ec500be2b87ed86 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
 # file fig2pdf.py
@@ -27,8 +26,8 @@
 #   the real pdf file will be overwritten by a tex file named file.pdf.
 #
 
-
-import os, sys, re, locale
+from __future__ import print_function
+import os, sys, re
 
 
 def runCommand(cmd):
@@ -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)
 
 
@@ -44,12 +43,7 @@ def runCommand(cmd):
 if len(sys.argv) != 3:
     sys.exit(1)
 
-language, output_encoding = locale.getdefaultlocale()
-if output_encoding == None:
-    output_encoding = 'latin1'
-
-input = unicode(sys.argv[1], 'utf8').encode(output_encoding)
-output = unicode(sys.argv[2], 'utf8').encode(output_encoding)
+input, output = sys.argv[1:]
 
 # Fail silently if the file doesn't exist
 if not os.path.isfile(input):
@@ -83,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))