Changeset 1308

Show
Ignore:
Timestamp:
05/23/07 04:33:52 (2 years ago)
Author:
arj..@yirdis.nl
Message:

Removed SVG, PNG and PDF export plugins.
All information is consolidated in diagramexportmanager.py

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/trunk/gaphor/services/diagramexportmanager.py

    r1307 r1308  
    1818    """ 
    1919 
    20     #interface.implements(IService) 
    2120    interface.implements(IService, IActionProvider) 
    2221 
     
    2928            <menu action="file-export"> 
    3029              <menuitem action="file-export-svg" /> 
     30              <menuitem action="file-export-png" /> 
     31              <menuitem action="file-export-pdf" /> 
    3132            </menu> 
    3233          </menu> 
     
    110111 
    111112 
     113    def save_png(self, filename, canvas): 
     114        log.debug('Exporting PNG image to: %s' % filename) 
     115        view = View(canvas) 
     116        view.painter = ItemPainter() 
     117 
     118        # Update bounding boxes with a temporaly CairoContext 
     119        # (used for stuff like calculating font metrics) 
     120        tmpsurface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 0, 0) 
     121        tmpcr = cairo.Context(tmpsurface) 
     122        view.update_bounding_box(tmpcr, items=canvas.get_root_items()) 
     123        tmpcr.show_page() 
     124        tmpsurface.flush() 
     125 
     126        w, h = view.bounding_box.width, view.bounding_box.height 
     127        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(w+1), int(h+1)) 
     128        cr = cairo.Context(surface) 
     129        view.matrix.translate(-view.bounding_box.x0, -view.bounding_box.y0) 
     130        view.paint(cr) 
     131        cr.show_page() 
     132        surface.write_to_png(filename) 
     133 
     134    def save_pdf(self, filename, canvas): 
     135        log.debug('Exporting PDF image to: %s' % filename) 
     136        view = View(canvas) 
     137        view.painter = ItemPainter() 
     138 
     139        # Update bounding boxes with a temporaly CairoContext 
     140        # (used for stuff like calculating font metrics) 
     141        tmpsurface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 0, 0) 
     142        tmpcr = cairo.Context(tmpsurface) 
     143        view.update_bounding_box(tmpcr) 
     144        tmpcr.show_page() 
     145        tmpsurface.flush() 
     146 
     147        w, h = view.bounding_box.width, view.bounding_box.height 
     148        surface = cairo.PDFSurface(filename, w, h) 
     149        cr = cairo.Context(surface) 
     150        view.matrix.translate(-view.bounding_box.x0, -view.bounding_box.y0) 
     151        view.paint(cr) 
     152        cr.show_page() 
     153        surface.flush() 
     154        surface.finish() 
     155 
    112156    @action(name='file-export-svg', label='Export to SVG', 
    113157            tooltip='Export the diagram to SVG') 
    114158    def save_svg_action(self): 
    115         title = 'Export diagram to SVG file
     159        title = 'Export diagram to SVG
    116160        ext = '.svg' 
    117161        diagram = self.gui_manager.main_window.get_current_diagram() 
     
    121165 
    122166 
     167    @action(name='file-export-png', label='Export to PNG', 
     168            tooltip='Export the diagram to PNG') 
     169    def save_png_action(self): 
     170        title = 'Export diagram to PNG' 
     171        ext = '.png' 
     172        diagram = self.gui_manager.main_window.get_current_diagram() 
     173        filename = self.save_dialog(diagram, title, ext) 
     174        if filename: 
     175            self.save_png(filename, diagram.canvas) 
     176 
     177 
     178    @action(name='file-export-pdf', label='Export to PDF', 
     179            tooltip='Export the diagram to PDF') 
     180    def save_pdf_action(self): 
     181        title = 'Export diagram to PDF' 
     182        ext = '.pdf' 
     183        diagram = self.gui_manager.main_window.get_current_diagram() 
     184        filename = self.save_dialog(diagram, title, ext) 
     185        if filename: 
     186            self.save_pdf(filename, diagram.canvas) 
     187 
     188 
    123189# vim:sw=4:et: 
    124190