From 18e268b04bca55e8d21ce6dc627f7a30ba2e43de Mon Sep 17 00:00:00 2001 From: John Hunter Date: Sun, 27 Apr 2008 02:27:01 +0000 Subject: [PATCH] removed backend_agg2 svn path=/trunk/matplotlib/; revision=5078 --- lib/matplotlib/backends/backend_agg2.py | 206 -------------------- lib/matplotlib/backends/backend_template.py | 11 +- 2 files changed, 7 insertions(+), 210 deletions(-) delete mode 100644 lib/matplotlib/backends/backend_agg2.py diff --git a/lib/matplotlib/backends/backend_agg2.py b/lib/matplotlib/backends/backend_agg2.py deleted file mode 100644 index c71c3a8da567..000000000000 --- a/lib/matplotlib/backends/backend_agg2.py +++ /dev/null @@ -1,206 +0,0 @@ -""" -An agg http://antigrain.com/ backend - -""" -from __future__ import division - -import os, sys -import matplotlib.agg as agg - -from matplotlib import verbose - -from matplotlib._pylab_helpers import Gcf -from matplotlib.backend_bases import RendererBase,\ - GraphicsContextBase, FigureManagerBase, FigureCanvasBase - -from matplotlib.cbook import enumerate, is_string_like, exception_to_str -from matplotlib.figure import Figure -from matplotlib.ft2font import FT2Font -from matplotlib.mathtext import MathTextParser - - -from _backend_agg import RendererAgg as _RendererAgg - -backend_version = 'v2.2' -_fontd = {} # a map from fname to font instances - - -class RendererAgg(RendererBase): - """ - The renderer handles all the drawing primitives using a graphics - context instance that controls the colors/styles - """ - - debug=1 - def __init__(self, width, height, dpi): - if __debug__: verbose.report('RendererAgg.__init__', 'debug-annoying') - self.dpi = dpi - self.width = int(width) - self.height = int(height) - - stride = self.width*4 - self.buffer = agg.buffer(self.width, self.height, stride) - - self.rbuf = agg.rendering_buffer() - self.rbuf.attachb(self.buffer) - - self.pf = agg.pixel_format(self.rbuf) - self.rbase = agg.renderer_base(self.pf) - - self.rasterizer = agg.rasterizer_scanline_aa() - self.scanline = agg.scanline_p8() - self.renderer = agg.renderer_scanline_aa_solid(self.rbase); - - - def draw_lines(self, gc, x, y, trans): - """ - x and y are equal length arrays, draw lines connecting each - point in x, y - """ - - x, y = trans.numerix_x_y(x,y) - if len(x)<2: return - path = agg.path_storage() - path.move_to(x[0],self.height-y[0]) - for i in xrange(1, len(x)): - path.line_to(x[i],self.height-y[i]) - - stroke = agg.conv_stroke(path) - stroke.width(1.0) - r,g,b = [int(255*val) for val in gc.get_rgb()] - a = int(255*gc.get_alpha()) - - color = agg.rgba8(r,g,b,a) - self.renderer.color( color ) - self.rasterizer.add_path(stroke) - agg.render_scanlines(self.rasterizer, self.scanline, self.renderer); - - def draw_markers(self, gc, path, rgbFace, xt, yt, trans): - pass - - def draw_arc(self, gcEdge, rgbFace, x, y, width, height, angle1, angle2, rotation): - pass - - def draw_image(self, x, y, im, origin, bbox): - pass - - def draw_line(self, gc, x1, y1, x2, y2): - pass - - def draw_point(self, gc, x, y): - pass - - def draw_polygon(self, gcEdge, rgbFace, points): - pass - - def draw_rectangle(self, gcEdge, rgbFace, x, y, width, height): - pass - - def draw_text(self, gc, x, y, s, prop, angle, ismath=False): - pass - - def flipy(self): - return True - - def get_canvas_width_height(self): - return 100, 100 - - def get_text_width_height(self, s, prop, ismath): - return 1, 1 - - def new_gc(self): - return GraphicsContextBase() - - - def points_to_pixels(self, points): - """ - convert point measures to pixes using dpi and the pixels per - inch of the display - """ - if __debug__: verbose.report('RendererAgg.points_to_pixels', 'debug-annoying') - return points*self.dpi.get()/72.0 - - - - - -def new_figure_manager(num, *args, **kwargs): - """ - Create a new figure manager instance - """ - if __debug__: verbose.report('backend_agg.new_figure_manager', 'debug-annoying') - FigureClass = kwargs.pop('FigureClass', Figure) - thisFig = FigureClass(*args, **kwargs) - canvas = FigureCanvasAgg(thisFig) - manager = FigureManagerBase(canvas, num) - return manager - - -class FigureCanvasAgg(FigureCanvasBase): - """ - The canvas the figure renders into. Calls the draw and print fig - methods, creates the renderers, etc... - - Public attribute - - figure - A Figure instance - """ - - - - def draw(self): - """ - Draw the figure using the renderer - """ - if __debug__: verbose.report('FigureCanvasAgg.draw', 'debug-annoying') - - renderer = self.get_renderer() - self.figure.draw(renderer) - return renderer - - def get_renderer(self): - l,b,w,h = self.figure.bbox.get_bounds() - key = w, h, self.figure.dpi.get() - try: self._lastKey, self.renderer - except AttributeError: need_new_renderer = True - else: need_new_renderer = (self._lastKey != key) - - if need_new_renderer: - self.renderer = RendererAgg(w, h, self.figure.dpi) - self._lastKey = key - return self.renderer - - def tostring_rgb(self): - if __debug__: verbose.report('FigureCanvasAgg.tostring_rgb', 'debug-annoying') - return self.renderer.tostring_rgb() - - def tostring_argb(self): - if __debug__: verbose.report('FigureCanvasAgg.tostring_argb', 'debug-annoying') - return self.renderer.tostring_argb() - - def buffer_rgba(self,x,y): - if __debug__: verbose.report('FigureCanvasAgg.buffer_rgba', 'debug-annoying') - return self.renderer.buffer_rgba(x,y) - - - def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w', - orientation='portrait', **kwargs): - """ - Render the figure to hardcopy. Set the figure patch face and - edge colors. This is useful because some of the GUIs have a - gray figure face color background and you'll probably want to - override this on hardcopy - - If the extension matches PNG, write a PNG file - - If the extension matches BMP or RAW, write an RGBA bitmap file - - If filename is a fileobject, write png to file object (thus - you can, for example, write the png to stdout - """ - - r = self.draw() - s = r.buffer.to_string() - import Image - im = Image.fromstring( "RGBA", (r.width, r.height), s) - im.show() diff --git a/lib/matplotlib/backends/backend_template.py b/lib/matplotlib/backends/backend_template.py index 70ef468006c7..965a25c5b937 100644 --- a/lib/matplotlib/backends/backend_template.py +++ b/lib/matplotlib/backends/backend_template.py @@ -68,13 +68,15 @@ def __init__(self, dpi): def draw_path(self, gc, path, transform, rgbFace=None): pass - # draw_markers is optional, and we get more correct - # relative timings by leaving it out. + # draw_markers is optional, and we get more correct relative + # timings by leaving it out. backend implementers concerned with + # performance will probably want to implement it # def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None): # pass # draw_path_collection is optional, and we get more correct - # relative timings by leaving it out. + # relative timings by leaving it out. backend implementers concerned with + # performance will probably want to implement it # def draw_path_collection(self, master_transform, cliprect, clippath, # clippath_trans, paths, all_transforms, offsets, # offsetTrans, facecolors, edgecolors, linewidths, @@ -82,7 +84,8 @@ def draw_path(self, gc, path, transform, rgbFace=None): # pass # draw_quad_mesh is optional, and we get more correct - # relative timings by leaving it out. + # relative timings by leaving it out. backend implementers concerned with + # performance will probably want to implement it # def draw_quad_mesh(self, master_transform, cliprect, clippath, # clippath_trans, meshWidth, meshHeight, coordinates, # offsets, offsetTrans, facecolors, antialiased,