예제 #1
0
 def create_graphics_context(self, width, height):
     return PSGC((width, height))
예제 #2
0
def font_metrics_provider():
    from kiva.fonttools import Font
    gc = GraphicsContext((1, 1))
    gc.set_font(Font())
    return gc
예제 #3
0
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)
예제 #4
0
파일: ps.py 프로젝트: GaZ3ll3/enable
def font_metrics_provider():
    from kiva.fonttools import Font
    gc = GraphicsContext((1, 1))
    gc.set_font(Font())
    return gc