1# This file is part of pybootchartgui. 2 3# pybootchartgui is free software: you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation, either version 3 of the License, or 6# (at your option) any later version. 7 8# pybootchartgui is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12 13# You should have received a copy of the GNU General Public License 14# along with pybootchartgui. If not, see <http://www.gnu.org/licenses/>. 15 16import cairo 17from . import draw 18from .draw import RenderOptions 19 20def render(writer, trace, app_options, filename): 21 handlers = { 22 "png": (lambda w, h: cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h), \ 23 lambda sfc: sfc.write_to_png(filename)), 24 "pdf": (lambda w, h: cairo.PDFSurface(filename, w, h), lambda sfc: 0), 25 "svg": (lambda w, h: cairo.SVGSurface(filename, w, h), lambda sfc: 0) 26 } 27 28 if app_options.format is None: 29 fmt = filename.rsplit('.', 1)[1] 30 else: 31 fmt = app_options.format 32 33 if not (fmt in handlers): 34 writer.error ("Unknown format '%s'." % fmt) 35 return 10 36 37 make_surface, write_surface = handlers[fmt] 38 options = RenderOptions (app_options) 39 (w, h) = draw.extents (options, 1.0, trace) 40 w = max (w, draw.MIN_IMG_W) 41 surface = make_surface (w, h) 42 ctx = cairo.Context (surface) 43 draw.render (ctx, options, 1.0, trace) 44 write_surface (surface) 45 writer.status ("bootchart written to '%s'" % filename) 46 47