7
7
import glob , math , md5 , os , shutil , sys , time
8
8
def _fn_name (): return sys ._getframe (1 ).f_code .co_name
9
9
10
- from subprocess import Popen , STDOUT , PIPE
10
+ ## from subprocess import Popen, STDOUT, PIPE
11
11
from tempfile import gettempdir
12
12
from cStringIO import StringIO
13
13
from matplotlib import verbose , __version__ , rcParams , get_data_path
@@ -1196,20 +1196,21 @@ def _print_figure_tex(self, outfile, dpi, facecolor, edgecolor, orientation,
1196
1196
isLandscape = True
1197
1197
width , height = height , width
1198
1198
bbox = (lly , llx , ury , urx )
1199
- temp_papertype = _get_papertype (width + 1 , height + 1 )
1199
+ temp_papertype = _get_papertype (width , height )
1200
1200
if papertype == 'auto' :
1201
1201
papertype = temp_papertype
1202
1202
paperWidth , paperHeight = papersize [papertype ]
1203
1203
convert_psfrags (tmpfile , renderer .psfrag ,
1204
- renderer .texmanager .get_font_preamble (), width + 1 , height + 1 ,
1204
+ renderer .texmanager .get_font_preamble (), width + 2 , height + 2 ,
1205
1205
orientation )
1206
1206
1207
1207
if rcParams ['ps.usedistiller' ] == 'ghostscript' :
1208
1208
gs_distill (tmpfile , ext == '.eps' , ptype = papertype , bbox = bbox )
1209
1209
elif rcParams ['ps.usedistiller' ] == 'xpdf' :
1210
1210
xpdf_distill (tmpfile , ext == '.eps' , ptype = papertype , bbox = bbox )
1211
1211
elif rcParams ['text.usetex' ]:
1212
- gs_distill (tmpfile , ext == '.eps' , ptype = papertype , bbox = bbox )
1212
+ if False : pass # for debugging
1213
+ else : gs_distill (tmpfile , ext == '.eps' , ptype = papertype , bbox = bbox )
1213
1214
1214
1215
if isinstance (outfile , file ):
1215
1216
fh = file (tmpfile )
@@ -1235,7 +1236,7 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, paperWidth, paperHeight,
1235
1236
else : angle = 0
1236
1237
print >> latexh , r"""\documentclass{article}
1237
1238
%s
1238
- \usepackage[dvips, papersize={%sin,%sin}, body={%sin,%sin}, margin={0.5in,0.5in }]{geometry}
1239
+ \usepackage[dvips, papersize={%sin,%sin}, body={%sin,%sin}, margin={0in,0in }]{geometry}
1239
1240
\usepackage{psfrag}
1240
1241
\usepackage[dvips]{graphicx}
1241
1242
\usepackage{color}
@@ -1247,7 +1248,7 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, paperWidth, paperHeight,
1247
1248
\includegraphics[angle=%s]{%s}
1248
1249
\end{figure}
1249
1250
\end{document}
1250
- """ % (font_preamble , paperWidth , paperHeight , paperWidth - 1 , paperHeight - 1 , '\n ' .join (psfrags ), angle ,
1251
+ """ % (font_preamble , paperWidth , paperHeight , paperWidth , paperHeight , '\n ' .join (psfrags ), angle ,
1251
1252
os .path .split (epsfile )[- 1 ])
1252
1253
latexh .close ()
1253
1254
@@ -1256,23 +1257,27 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, paperWidth, paperHeight,
1256
1257
1257
1258
command = 'latex -interaction=nonstopmode "%s"' % latexfile
1258
1259
verbose .report (command , 'debug-annoying' )
1259
- process = Popen (command , shell = True , stderr = STDOUT ,
1260
- stdout = PIPE , close_fds = True )
1261
- exit_status = process .wait ()
1262
- if exit_status : raise RuntimeError ('LaTeX was not able to process \
1263
- your image.\n Here is the full report generated by LaTeX: \
1264
- \n \n ' + process .stdout .read ())
1265
- else : verbose .report (process .stdout .read (), 'debug-annoying' )
1260
+ ## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
1261
+ ## exit_status = process.wait()
1262
+ ## if exit_status: raise RuntimeError('LaTeX was not able to process \
1263
+ ##your image.\nHere is the full report generated by LaTeX: \
1264
+ ##\n\n' + process.stdout.read())
1265
+ ## else: verbose.report(process.stdout.read(), 'debug-annoying')
1266
+ stdin , stdout , stderr = os .popen3 (command )
1267
+ verbose .report (stdout .read (), 'debug-annoying' )
1268
+ verbose .report (stderr .read (), 'helpful' )
1266
1269
1267
1270
command = 'dvips -o "%s" "%s"' % (psfile , dvifile )
1268
1271
verbose .report (command , 'debug-annoying' )
1269
- process = Popen (command , shell = True , stderr = STDOUT ,
1270
- stdout = PIPE , close_fds = True )
1271
- exit_status = process .wait ()
1272
- if exit_status : raise RuntimeError ('dvips was not able to process \
1273
- your image.\n Here is the full report generated by dvips: \
1274
- \n \n ' + process .stdout .read ())
1275
- else : verbose .report (process .stdout .read (), 'debug-annoying' )
1272
+ ## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
1273
+ ## exit_status = process.wait()
1274
+ ## if exit_status: raise RuntimeError('dvips was not able to process \
1275
+ ##your image.\nHere is the full report generated by dvips: \
1276
+ ##\n\n' + process.stdout.read())
1277
+ ## else: verbose.report(process.stdout.read(), 'debug-annoying')
1278
+ stdin , stdout , stderr = os .popen3 (command )
1279
+ verbose .report (stdout .read (), 'debug-annoying' )
1280
+ verbose .report (stderr .read (), 'helpful' )
1276
1281
1277
1282
shutil .move (psfile , tmpfile )
1278
1283
for fname in glob .glob (tmpfile + '.*' ):
@@ -1295,13 +1300,15 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None):
1295
1300
command = '%s -dBATCH -dNOPAUSE -r%d -sDEVICE=pswrite %s -sOutputFile="%s" \
1296
1301
"%s"'% (gs_exe , dpi , paper , outputfile , tmpfile )
1297
1302
verbose .report (command , 'debug-annoying' )
1298
- process = Popen (command , shell = True , stderr = STDOUT ,
1299
- stdout = PIPE , close_fds = True )
1300
- exit_status = process .wait ()
1301
- if exit_status : raise RuntimeError ('ghostscript was not able to process \
1302
- your image.\n Here is the full report generated by ghostscript: \
1303
- \n \n ' + process .stdout .read ())
1304
- else : verbose .report (process .stdout .read (), 'debug-annoying' )
1303
+ ## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
1304
+ ## exit_status = process.wait()
1305
+ ## if exit_status: raise RuntimeError('ghostscript was not able to process \
1306
+ ##your image.\nHere is the full report generated by ghostscript: \
1307
+ ##\n\n' + process.stdout.read())
1308
+ ## else: verbose.report(process.stdout.read(), 'debug-annoying')
1309
+ stdin , stdout , stderr = os .popen3 (command )
1310
+ verbose .report (stdout .read (), 'debug-annoying' )
1311
+ verbose .report (stderr .read (), 'helpful' )
1305
1312
os .remove (tmpfile )
1306
1313
shutil .move (outputfile , tmpfile )
1307
1314
if eps :
@@ -1319,22 +1326,24 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None):
1319
1326
psfile = tmpfile + '.ps'
1320
1327
command = 'ps2pdf -sPAPERSIZE=%s "%s" "%s"' % (ptype , tmpfile , pdffile )
1321
1328
verbose .report (command , 'debug-annoying' )
1322
- process = Popen (command , shell = True , stderr = STDOUT ,
1323
- stdout = PIPE , close_fds = True )
1324
- exit_status = process .wait ()
1325
- if exit_status :
1326
- raise RuntimeError ('ps2pdf was not able to process your image.\n \
1327
- Here is the report generated by ghostscript:\n \n ' + process .stdout .read ())
1328
- else : verbose .report (process .stdout .read (), 'debug-annoying' )
1329
+ ## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
1330
+ ## exit_status = process.wait()
1331
+ ## if exit_status:
1332
+ ## raise RuntimeError('ps2pdf was not able to process your image.\n\
1333
+ ##Here is the report generated by ghostscript:\n\n' + process.stdout.read())
1334
+ ## else: verbose.report(process.stdout.read(), 'debug-annoying')
1335
+ stdin , stderr = os .popen4 (command )
1336
+ verbose .report (stderr .read (), 'helpful' )
1329
1337
command = 'pdftops -paper match -level2 "%s" "%s"' % (pdffile , psfile )
1330
1338
verbose .report (command , 'debug-annoying' )
1331
- process = Popen (command , shell = True , stderr = STDOUT ,
1332
- stdout = PIPE , close_fds = True )
1333
- exit_status = process .wait ()
1334
- if exit_status : raise RuntimeError ('pdftops was not able to process \
1335
- your image.\n Here is the full report generated by pdftops: \
1336
- \n \n ' + process .stdout .read ())
1337
- else : verbose .report (process .stdout .read (), 'debug-annoying' )
1339
+ ## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
1340
+ ## exit_status = process.wait()
1341
+ ## if exit_status: raise RuntimeError('pdftops was not able to process \
1342
+ ##your image.\nHere is the full report generated by pdftops: \
1343
+ ##\n\n' + process.stdout.read())
1344
+ ## else: verbose.report(process.stdout.read(), 'debug-annoying')
1345
+ stdin , stderr = os .popen4 (command )
1346
+ verbose .report (stderr .read (), 'helpful' )
1338
1347
os .remove (tmpfile )
1339
1348
shutil .move (psfile , tmpfile )
1340
1349
if eps :
@@ -1352,15 +1361,18 @@ def get_bbox(tmpfile, bbox):
1352
1361
else : gs_exe = 'gs'
1353
1362
command = '%s -dBATCH -dNOPAUSE -sDEVICE=bbox "%s"' % (gs_exe , tmpfile )
1354
1363
verbose .report (command , 'debug-annoying' )
1355
- process = Popen (command , shell = True , stderr = STDOUT ,
1356
- stdout = PIPE , close_fds = True )
1357
- exit_status = process .wait ()
1358
- if exit_status : raise RuntimeError ('ghostscript was not able to determine \
1359
- the bounding box for your image.\n Here is the full report generated by \
1360
- ghostscript: \n \n ' + process .stdout .read ())
1361
- else :
1362
- bbox_info = process .stdout .read ()
1363
- verbose .report (bbox_info , 'debug' )
1364
+ ## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
1365
+ ## exit_status = process.wait()
1366
+ ## if exit_status: raise RuntimeError('ghostscript was not able to determine \
1367
+ ##the bounding box for your image.\nHere is the full report generated by \
1368
+ ##ghostscript: \n\n' + process.stdout.read())
1369
+ ## else:
1370
+ ## bbox_info = process.stdout.read()
1371
+ ## verbose.report(bbox_info, 'debug')
1372
+ stdin , stdout , stderr = os .popen3 (command )
1373
+ verbose .report (stdout .read (), 'debug-annoying' )
1374
+ bbox_info = stderr .read ()
1375
+ verbose .report (bbox_info , 'helpful' )
1364
1376
l , b , r , t = [float (i ) for i in bbox_info .split ()[- 4 :]]
1365
1377
1366
1378
# this is a hack to deal with the fact that ghostscript does not return the
0 commit comments