Ignore:
Timestamp:
10/12/12 15:32:11 (18 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Fixed 'grab_svg' function.

Need to properly set the SVG's viewBox.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/canvas/scene.py

    r11113 r11115  
    672672    gen = QSvgGenerator() 
    673673    gen.setOutputDevice(svg_buffer) 
    674     aspect_ratio = 1.618 
    675     items_rect = scene.itemsBoundingRect() 
     674 
     675    items_rect = scene.itemsBoundingRect().adjusted(-10, -10, 10, 10) 
    676676 
    677677    if items_rect.isNull(): 
     
    680680    width, height = items_rect.width(), items_rect.height() 
    681681    rect_ratio = float(width) / height 
     682 
     683    # Keep a fixed aspect ratio. 
     684    aspect_ratio = 1.618 
    682685    if rect_ratio > aspect_ratio: 
    683686        height = int(height * rect_ratio / aspect_ratio) 
     
    685688        width = int(width * aspect_ratio / rect_ratio) 
    686689 
    687     scene_rect = QRectF(0, 0, width + 20, height + 20) 
    688     scene_rect.moveCenter(items_rect.center()) 
    689     scene.setSceneRect(scene_rect) 
    690  
    691     gen.setSize(scene_rect.size().toSize()) 
     690    target_rect = QRectF(0, 0, width, height) 
     691    source_rect = QRectF(0, 0, width, height) 
     692    source_rect.moveCenter(items_rect.center()) 
     693 
     694    gen.setSize(target_rect.size().toSize()) 
     695    gen.setViewBox(target_rect) 
     696 
    692697    painter = QPainter(gen) 
     698 
     699    # Draw background. 
    693700    painter.setBrush(QBrush(Qt.white)) 
    694     painter.drawRect(QRectF(0, 0, scene_rect.width(), scene_rect.height())) 
    695 #    print scene_rect, scene_rect.topLeft() - items_rect.topLeft() 
    696 #    painter.translate(items_rect.topLeft() - scene_rect.topLeft()) 
    697     scene.render(painter) 
     701    painter.drawRect(target_rect) 
     702 
     703    # Render the scene 
     704    scene.render(painter, target_rect, source_rect) 
    698705    painter.end() 
     706 
    699707    return unicode(svg_buffer.buffer()) 
Note: See TracChangeset for help on using the changeset viewer.