Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fed9755

Browse files
committed
fix some issues in the bbox after the postscript distiller is run
svn path=/trunk/matplotlib/; revision=8102
1 parent fc40214 commit fed9755

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

lib/matplotlib/backends/backend_ps.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,14 +1383,17 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None):
13831383
This yields smaller files without illegal encapsulated postscript
13841384
operators. The output is low-level, converting text to outlines.
13851385
"""
1386-
paper = '-sPAPERSIZE=%s'% ptype
1386+
1387+
paper_option = "-sPAPERSIZE=%s" % ptype
1388+
13871389
psfile = tmpfile + '.ps'
13881390
outfile = tmpfile + '.output'
13891391
dpi = rcParams['ps.distiller.res']
13901392
if sys.platform == 'win32': gs_exe = 'gswin32c'
13911393
else: gs_exe = 'gs'
1394+
13921395
command = '%s -dBATCH -dNOPAUSE -r%d -sDEVICE=pswrite %s -sOutputFile="%s" \
1393-
"%s" > "%s"'% (gs_exe, dpi, paper, psfile, tmpfile, outfile)
1396+
"%s" > "%s"'% (gs_exe, dpi, paper_option, psfile, tmpfile, outfile)
13941397
verbose.report(command, 'debug')
13951398
exit_status = os.system(command)
13961399
fh = file(outfile)
@@ -1403,12 +1406,12 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None):
14031406
shutil.move(psfile, tmpfile)
14041407

14051408

1409+
# While it is best if above steps preserve the original bounding
1410+
# box, it does not seems to be the case. pstoeps not only convert
1411+
# the input to eps format, but also restores the original bbox.
14061412

1407-
# Since the the paper size is set to the figure size for eps
1408-
# output (in '_print_figure_tex'), pstoeps call is not required.
1409-
1410-
#if eps:
1411-
# pstoeps(tmpfile, bbox)
1413+
if eps:
1414+
pstoeps(tmpfile, bbox)
14121415

14131416

14141417
def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None):
@@ -1421,9 +1424,13 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None):
14211424
pdffile = tmpfile + '.pdf'
14221425
psfile = tmpfile + '.ps'
14231426
outfile = tmpfile + '.output'
1427+
1428+
if eps: paper_option = "-dEPSCrop"
1429+
else: paper_option = "-sPAPERSIZE=%s" % ptype
1430+
14241431
command = 'ps2pdf -dAutoFilterColorImages=false \
1425-
-sColorImageFilter=FlateEncode -sPAPERSIZE=%s "%s" "%s" > "%s"'% \
1426-
(ptype, tmpfile, pdffile, outfile)
1432+
-sColorImageFilter=FlateEncode %s "%s" "%s" > "%s"'% \
1433+
(paper_option, tmpfile, pdffile, outfile)
14271434
if sys.platform == 'win32': command = command.replace('=', '#')
14281435
verbose.report(command, 'debug')
14291436
exit_status = os.system(command)
@@ -1445,17 +1452,37 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None):
14451452
os.remove(outfile)
14461453
os.remove(tmpfile)
14471454
shutil.move(psfile, tmpfile)
1455+
1456+
1457+
# Similar to the gs_distillier case, ps2pdf does not seem to
1458+
# preserve the bbox of the original file (at least w/ gs
1459+
# 8.61). Thus, the original bbox need to be resotred.
1460+
14481461
if eps:
14491462
pstoeps(tmpfile, bbox)
14501463
for fname in glob.glob(tmpfile+'.*'):
14511464
os.remove(fname)
14521465

14531466

1467+
def get_bbox_header(l, b, r, t):
1468+
"""
1469+
return a postscript header stringfor the given bbox (l, b, r, t)
1470+
"""
1471+
1472+
bbox_info = '%%%%BoundingBox: %d %d %d %d' % (l, b, npy.ceil(r), npy.ceil(t))
1473+
hires_bbox_info = '%%%%HiResBoundingBox: %.6f %.6f %.6f %.6f' % (l, b, r, t)
1474+
1475+
return '\n'.join([bbox_info, hires_bbox_info])
1476+
1477+
1478+
# get_bbox is deprecated. I don't see any reason to use ghostscript to
1479+
# find the bounding box, as the required bounding box is alread known.
14541480
def get_bbox(tmpfile, bbox):
14551481
"""
14561482
Use ghostscript's bbox device to find the center of the bounding box. Return
14571483
an appropriately sized bbox centered around that point. A bit of a hack.
14581484
"""
1485+
14591486
outfile = tmpfile + '.output'
14601487
if sys.platform == 'win32': gs_exe = 'gswin32c'
14611488
else: gs_exe = 'gs'
@@ -1497,7 +1524,7 @@ def pstoeps(tmpfile, bbox):
14971524
"""
14981525
Convert the postscript to encapsulated postscript.
14991526
"""
1500-
bbox_info = get_bbox(tmpfile, bbox)
1527+
bbox_info = get_bbox_header(*bbox)
15011528

15021529
epsfile = tmpfile + '.eps'
15031530
epsh = file(epsfile, 'w')
@@ -1552,6 +1579,7 @@ def pstoeps(tmpfile, bbox):
15521579
shutil.move(epsfile, tmpfile)
15531580

15541581

1582+
15551583
class FigureManagerPS(FigureManagerBase):
15561584
pass
15571585

lib/matplotlib/font_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,6 @@ def findfont(self, prop, fontext='ttf', directory=None):
12041204
for font in fontlist:
12051205
if (directory is not None and
12061206
os.path.commonprefix([font.fname, directory]) != directory):
1207-
print directory, font.fname, os.path.commonprefix([font.fname, directory])
12081207
continue
12091208
# Matching family should have highest priority, so it is multiplied
12101209
# by 10.0

0 commit comments

Comments
 (0)