QImage SvgPatternHelper::generateImage( const QRectF &objectBound, const QList<KoShape*> content )
{
    KoZoomHandler zoomHandler;
    
    QSizeF patternSize = size( objectBound );
    QSizeF tileSize = zoomHandler.documentToView( patternSize );

    QMatrix viewMatrix;

    if( ! m_patternContentViewbox.isNull() )
    {
        viewMatrix.translate( -m_patternContentViewbox.x(), -m_patternContentViewbox.y() );
        const qreal xScale = patternSize.width() / m_patternContentViewbox.width();
        const qreal yScale = patternSize.height() / m_patternContentViewbox.height();
        viewMatrix.scale( xScale, yScale );
    }

    // setup the tile image
    QImage tile( tileSize.toSize(), QImage::Format_ARGB32 );
    tile.fill( QColor( Qt::transparent ).rgba() );
    
    // setup the painter to paint the tile content
    QPainter tilePainter( &tile );
    tilePainter.setClipRect( tile.rect() );
    tilePainter.setWorldMatrix( viewMatrix );
    //tilePainter.setRenderHint(QPainter::Antialiasing);

    // paint the content into the tile image
    KoShapePainter shapePainter;
    shapePainter.setShapes( content );
    shapePainter.paintShapes( tilePainter, zoomHandler );

    return tile;
}
void KoPAMasterPage::paintPage( QPainter & painter, KoZoomHandler & zoomHandler )
{
    paintBackground( painter, zoomHandler );

    KoShapePainter shapePainter;
    shapePainter.setShapes( shapes() );
    shapePainter.paint(painter, zoomHandler);
}
Beispiel #3
0
KoFilter::ConversionStatus
PngExport::convert( const QByteArray& from, const QByteArray& to )
{
    if ( to != "image/png" || from != "application/vnd.oasis.opendocument.graphics" )
    {
        return KoFilter::NotImplemented;
    }

    KoDocument * document = m_chain->inputDocument();
    if( ! document )
        return KoFilter::ParsingError;

    KarbonPart * karbonPart = dynamic_cast<KarbonPart*>( document );
    if( ! karbonPart )
        return KoFilter::WrongFormat;

    KoShapePainter painter;
    painter.setShapes( karbonPart->document().shapes() );

    // get the bounding rect of the content
    QRectF shapesRect = painter.contentRect();
    // get the size on point
    QSizeF pointSize = shapesRect.size();
    // get the size in pixel (100% zoom)
    KoZoomHandler zoomHandler;
    QSize pixelSize = zoomHandler.documentToView( pointSize ).toSize();
    QColor backgroundColor( Qt::white );

    if( ! m_chain->manager()->getBatchMode() )
    {
        PngExportOptionsWidget * widget = new PngExportOptionsWidget( pointSize );
        widget->setUnit( karbonPart->unit() );
        widget->setBackgroundColor( backgroundColor );

        KDialog dlg;
        dlg.setCaption( i18n("PNG Export Options") );
        dlg.setButtons( KDialog::Ok | KDialog::Cancel );
        dlg.setMainWidget( widget );
        if( dlg.exec() != QDialog::Accepted )
            return KoFilter::UserCancelled;

        pixelSize = widget->pixelSize();
        backgroundColor = widget->backgroundColor();
    }
    QImage image( pixelSize, QImage::Format_ARGB32 );

    // draw the background of the image
    image.fill( backgroundColor.rgba() );

    // paint the shapes
    if( ! painter.paintShapes( image ) )
        return KoFilter::CreationError;

    image.save( m_chain->outputFile(), "PNG" );

    return KoFilter::OK;
}