From: <lee...@us...> - 2010-01-29 16:22:58
|
Revision: 8102 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8102&view=rev Author: leejjoon Date: 2010-01-29 16:22:51 +0000 (Fri, 29 Jan 2010) Log Message: ----------- fix some issues in the bbox after the postscript distiller is run Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py trunk/matplotlib/lib/matplotlib/font_manager.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2010-01-29 15:27:54 UTC (rev 8101) +++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2010-01-29 16:22:51 UTC (rev 8102) @@ -1383,14 +1383,17 @@ This yields smaller files without illegal encapsulated postscript operators. The output is low-level, converting text to outlines. """ - paper = '-sPAPERSIZE=%s'% ptype + + paper_option = "-sPAPERSIZE=%s" % ptype + psfile = tmpfile + '.ps' outfile = tmpfile + '.output' dpi = rcParams['ps.distiller.res'] if sys.platform == 'win32': gs_exe = 'gswin32c' else: gs_exe = 'gs' + command = '%s -dBATCH -dNOPAUSE -r%d -sDEVICE=pswrite %s -sOutputFile="%s" \ - "%s" > "%s"'% (gs_exe, dpi, paper, psfile, tmpfile, outfile) + "%s" > "%s"'% (gs_exe, dpi, paper_option, psfile, tmpfile, outfile) verbose.report(command, 'debug') exit_status = os.system(command) fh = file(outfile) @@ -1403,14 +1406,14 @@ shutil.move(psfile, tmpfile) + # While it is best if above steps preserve the original bounding + # box, it does not seems to be the case. pstoeps not only convert + # the input to eps format, but also restores the original bbox. - # Since the the paper size is set to the figure size for eps - # output (in '_print_figure_tex'), pstoeps call is not required. + if eps: + pstoeps(tmpfile, bbox) - #if eps: - # pstoeps(tmpfile, bbox) - def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None): """ Use ghostscript's ps2pdf and xpdf's/poppler's pdftops to distill a file. @@ -1421,9 +1424,13 @@ pdffile = tmpfile + '.pdf' psfile = tmpfile + '.ps' outfile = tmpfile + '.output' + + if eps: paper_option = "-dEPSCrop" + else: paper_option = "-sPAPERSIZE=%s" % ptype + command = 'ps2pdf -dAutoFilterColorImages=false \ --sColorImageFilter=FlateEncode -sPAPERSIZE=%s "%s" "%s" > "%s"'% \ -(ptype, tmpfile, pdffile, outfile) +-sColorImageFilter=FlateEncode %s "%s" "%s" > "%s"'% \ +(paper_option, tmpfile, pdffile, outfile) if sys.platform == 'win32': command = command.replace('=', '#') verbose.report(command, 'debug') exit_status = os.system(command) @@ -1445,17 +1452,37 @@ os.remove(outfile) os.remove(tmpfile) shutil.move(psfile, tmpfile) + + + # Similar to the gs_distillier case, ps2pdf does not seem to + # preserve the bbox of the original file (at least w/ gs + # 8.61). Thus, the original bbox need to be resotred. + if eps: pstoeps(tmpfile, bbox) for fname in glob.glob(tmpfile+'.*'): os.remove(fname) +def get_bbox_header(l, b, r, t): + """ + return a postscript header stringfor the given bbox (l, b, r, t) + """ + + bbox_info = '%%%%BoundingBox: %d %d %d %d' % (l, b, npy.ceil(r), npy.ceil(t)) + hires_bbox_info = '%%%%HiResBoundingBox: %.6f %.6f %.6f %.6f' % (l, b, r, t) + + return '\n'.join([bbox_info, hires_bbox_info]) + + +# get_bbox is deprecated. I don't see any reason to use ghostscript to +# find the bounding box, as the required bounding box is alread known. def get_bbox(tmpfile, bbox): """ Use ghostscript's bbox device to find the center of the bounding box. Return an appropriately sized bbox centered around that point. A bit of a hack. """ + outfile = tmpfile + '.output' if sys.platform == 'win32': gs_exe = 'gswin32c' else: gs_exe = 'gs' @@ -1497,7 +1524,7 @@ """ Convert the postscript to encapsulated postscript. """ - bbox_info = get_bbox(tmpfile, bbox) + bbox_info = get_bbox_header(*bbox) epsfile = tmpfile + '.eps' epsh = file(epsfile, 'w') @@ -1552,6 +1579,7 @@ shutil.move(epsfile, tmpfile) + class FigureManagerPS(FigureManagerBase): pass Modified: trunk/matplotlib/lib/matplotlib/font_manager.py =================================================================== --- trunk/matplotlib/lib/matplotlib/font_manager.py 2010-01-29 15:27:54 UTC (rev 8101) +++ trunk/matplotlib/lib/matplotlib/font_manager.py 2010-01-29 16:22:51 UTC (rev 8102) @@ -1204,7 +1204,6 @@ for font in fontlist: if (directory is not None and os.path.commonprefix([font.fname, directory]) != directory): - print directory, font.fname, os.path.commonprefix([font.fname, directory]) continue # Matching family should have highest priority, so it is multiplied # by 10.0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |