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

Skip to content

Commit 3937462

Browse files
author
Steve Chaplin
committed
SC 15/01/2004
svn path=/trunk/matplotlib/; revision=865
1 parent 19df3fa commit 3937462

4 files changed

Lines changed: 40 additions & 20 deletions

File tree

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
New entries should be added at the top
22

3+
2005-01-15 backend_cairo: added PDF support which requires pycairo 0.1.4.
4+
Its not usable yet, but is ready for when the Cairo PDF backend
5+
matures - SC
6+
37
2005-01-15 Added Nadia's x,y contour fix
48

59
2005-01-12 Fixed set clip_on bug in artist - JDH

lib/matplotlib/backends/backend_cairo.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* save image files:
1111
- PNG
1212
- PostScript (50% complete)
13-
- PDF (proposed, 0% complete)
13+
- PDF (in development)
1414
1515
http://cairographics.org
1616
Requires (in order, all available from Cairo website):
@@ -40,14 +40,13 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
4040

4141
import cairo
4242

43-
# uncomment when 0.1.4 is available
44-
#version_required = (0,1,3)
45-
#if cairo.version_info < version_required:
46-
# raise SystemExit ("PyCairo %d.%d.%d is installed\n"
47-
# "PyCairo %d.%d.%d or later is required"
48-
# % (cairo.version_info + version_required))
49-
#backend_version = cairo.version
50-
#del version_required
43+
version_required = (0,1,4)
44+
if cairo.version_info < version_required:
45+
raise SystemExit ("PyCairo %d.%d.%d is installed\n"
46+
"PyCairo %d.%d.%d or later is required"
47+
% (cairo.version_info + version_required))
48+
backend_version = cairo.version
49+
del version_required
5150

5251

5352
DEBUG = False
@@ -57,6 +56,7 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
5756

5857
# Image formats that this backend supports - for print_figure()
5958
IMAGE_FORMAT = ['eps', 'png', 'ps', 'svg']
59+
#IMAGE_FORMAT = ['eps', 'pdf', 'png', 'ps', 'svg'] # pdf not ready yet
6060
IMAGE_FORMAT_DEFAULT = 'png'
6161

6262

@@ -462,14 +462,14 @@ def print_figure_fn(figure, filename, dpi=150, facecolor='w', edgecolor='w',
462462
filename = filename + '.' + ext
463463

464464
ext = ext.lower()
465-
if ext in ('png', 'ps'): # native formats
465+
if ext in ('pdf', 'png', 'ps'): # native formats
466466
try:
467467
fileObject = file(filename,'wb')
468468
except IOError, exc:
469469
verbose.report_error("%s: %s" % (exc.filename, exc.strerror))
470470
else:
471471
if ext == 'png': _save_png (figure, fileObject)
472-
else: _save_ps (figure, fileObject, orientation)
472+
else: _save_ps_pdf (figure, fileObject, ext, orientation)
473473

474474
elif ext in ('eps', 'svg'): # backend_svg/ps
475475
if ext == 'svg':
@@ -498,7 +498,7 @@ def _save_png (figure, fileObject):
498498
ctx.show_page()
499499

500500

501-
def _save_ps (figure, fileObject, orientation):
501+
def _save_ps_pdf (figure, fileObject, ext, orientation):
502502
# Cairo produces PostScript Level 3
503503
# 'ggv' can't read cairo ps files, but 'gv' can
504504

@@ -511,11 +511,15 @@ def _save_ps (figure, fileObject, orientation):
511511

512512
ctx = cairo.Context()
513513

514-
if orientation == 'portrait':
514+
if orientation == 'landscape':
515+
w_in, h_in = h_in, w_in
516+
517+
if ext == 'ps':
515518
ctx.set_target_ps (fileObject, w_in, h_in, ppi, ppi)
519+
else: # pdf
520+
ctx.set_target_pdf (fileObject, w_in, h_in, ppi, ppi)
516521

517-
elif orientation == 'landscape':
518-
ctx.set_target_ps (fileObject, h_in, w_in, ppi, ppi)
522+
if orientation == 'landscape':
519523
ctx.rotate(pi/2)
520524
ctx.translate(0, -height)
521525
# cairo/src/cairo_ps_surface.c
@@ -524,7 +528,7 @@ def _save_ps (figure, fileObject, orientation):
524528
# since some printers would rotate again ?
525529
# TODO:
526530
# add portrait/landscape checkbox to FileChooser
527-
531+
528532
renderer = RendererCairo (ctx.matrix, figure.dpi)
529533
renderer._set_width_height(width, height)
530534
renderer.surface = ctx.target_surface

lib/matplotlib/backends/backend_gtk.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def fn_name(): return sys._getframe(1).f_code.co_name
4848
PIXELS_PER_INCH = 96
4949

5050
# Image formats that this backend supports - for FileChooser and print_figure()
51-
IMAGE_FORMAT = ['eps', 'jpg', 'png', 'ps', 'svg'] + ['bmp'] # , 'raw', 'rgb']
51+
IMAGE_FORMAT = ['bmp', 'eps', 'jpg', 'png', 'ps', 'svg']
52+
#IMAGE_FORMAT = ['bmp', 'eps', 'jpg', 'png', 'pdf', 'ps', 'svg'] # pdf not ready yet
5253
IMAGE_FORMAT.sort()
5354
IMAGE_FORMAT_DEFAULT = 'png'
5455

@@ -320,7 +321,18 @@ def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
320321
from backend_agg import FigureCanvasAgg as FigureCanvas
321322
except:
322323
error_msg('Save figure failure:\n'
323-
'Agg must be loaded to save as bmp, raw and rgb',
324+
'Agg must be installed to save as bmp, raw and rgb',
325+
parent=self)
326+
else:
327+
fc = self.switch_backends(FigureCanvas)
328+
fc.print_figure(filename, dpi, facecolor, edgecolor, orientation)
329+
330+
elif ext in ('pdf',):
331+
try:
332+
from backend_cairo import FigureCanvasCairo as FigureCanvas
333+
except:
334+
error_msg('Save figure failure:\n'
335+
'Cairo must be installed to save as pdf',
324336
parent=self)
325337
else:
326338
fc = self.switch_backends(FigureCanvas)

lib/matplotlib/backends/backend_gtkcairo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import cairo
99
import cairo.gtk
1010

11-
#backend_version = 'PyGTK(%d.%d.%d),PyCairo(%d.%d.%d)' % (gtk.pygtk_version + cairo.version_info)
12-
backend_version = 'PyGTK(%d.%d.%d)' % gtk.pygtk_version
11+
backend_version = 'PyGTK(%d.%d.%d),PyCairo(%d.%d.%d)' % (gtk.pygtk_version + cairo.version_info)
12+
#backend_version = 'PyGTK(%d.%d.%d)' % gtk.pygtk_version
1313

1414
DEBUG = False
1515

0 commit comments

Comments
 (0)