def create_graphics_context(self, width, height): return PSGC((width, height))
def font_metrics_provider(): from kiva.fonttools import Font gc = GraphicsContext((1, 1)) gc.set_font(Font()) return gc
def save_pdf(component, path=None, default_directory=None, view=False, options=None): if default_directory is None: default_directory = os.path.join(os.path.expanduser('~'), 'Documents') ok = True if options is None: ok = False options = FigurePDFOptions() options.load() dlg = SavePDFDialog(model=options) info = dlg.edit_traits(kind='livemodal') # path = '/Users/ross/Documents/pdftest.pdf' if info.result: options.dump() ok = True if ok: if path is None: dlg = FileDialog(action='save as', default_directory=default_directory) if dlg.open() == OK: path = dlg.path if path: use_ps = False use_svg = False if use_ps: path = add_extension(path, '.ps') gc = PSGC(component.bounds) component.draw(gc) gc.save(path) elif use_svg: path = add_extension(path, '.svg') gc = SVGGraphicsContext(component.bounds) obackbuffer = component.use_backbuffer component.use_backbuffer = False gc.render_component(component) gc.save(path) component.use_backbuffer = obackbuffer else: path = add_extension(path, '.pdf') gc = myPdfPlotGraphicsContext(filename=path, dest_box=options.dest_box, pagesize=options.page_size) obounds = component.bounds # size = None if not obounds[0] and not obounds[1]: size = options.bounds component.do_layout(size=size, force=True) if options.fit_to_page: size = options.bounds component.do_layout(size=size, force=True) gc.render_component(component, valign='center') gc.save() if view: view_file(path) if options.fit_to_page: component.do_layout(size=obounds, force=True)