@@ -553,34 +553,24 @@ QByteArray* QgsWMSServer::getPrint( const QString& formatString )
553
553
generator.setResolution ( c->printResolution () ); // because the rendering is done in mm, convert the dpi
554
554
555
555
QPainter p ( &generator );
556
- QRectF sourceArea ( 0 , 0 , c->paperWidth (), c->paperHeight () );
557
- QRectF targetArea ( 0 , 0 , width, height );
558
556
if ( c->printAsRaster () ) // embed one raster into the svg
559
557
{
560
- QImage* img = printCompositionToImage ( c );
561
- if ( img )
562
- {
563
- p.drawImage ( targetArea, *img, QRectF ( 0 , 0 , img->width (), img->height () ) );
564
- }
565
- delete img;
558
+ QImage img = c->printPageAsRaster ( 0 );
559
+ p.drawImage ( QRect ( 0 , 0 , width, height ), img, QRectF ( 0 , 0 , img.width (), img.height () ) );
566
560
}
567
561
else
568
562
{
569
- c->render ( &p, targetArea, sourceArea );
563
+ c->renderPage ( &p, 0 );
570
564
}
571
565
p.end ();
572
566
}
573
567
else if ( formatString.compare ( " png" , Qt::CaseInsensitive ) == 0 || formatString.compare ( " jpg" , Qt::CaseInsensitive ) == 0 )
574
568
{
575
- QImage* image = printCompositionToImage ( c );
576
- if ( image )
577
- {
578
- ba = new QByteArray ();
579
- QBuffer buffer ( ba );
580
- buffer.open ( QIODevice::WriteOnly );
581
- image->save ( &buffer, formatString.toLocal8Bit ().data (), -1 );
582
- }
583
- delete image;
569
+ QImage image = c->printPageAsRaster ( 0 ); // can only return the first page if pixmap is requested
570
+ ba = new QByteArray ();
571
+ QBuffer buffer ( ba );
572
+ buffer.open ( QIODevice::WriteOnly );
573
+ image.save ( &buffer, formatString.toLocal8Bit ().data (), -1 );
584
574
}
585
575
else if ( formatString.compare ( " pdf" , Qt::CaseInsensitive ) == 0 )
586
576
{
@@ -593,33 +583,7 @@ QByteArray* QgsWMSServer::getPrint( const QString& formatString )
593
583
return 0 ;
594
584
}
595
585
596
- QPrinter printer;
597
- printer.setResolution ( c->printResolution () );
598
- printer.setFullPage ( true );
599
- printer.setOutputFormat ( QPrinter::PdfFormat );
600
- printer.setOutputFileName ( tempFile.fileName () );
601
- printer.setPaperSize ( QSizeF ( c->paperWidth (), c->paperHeight () ), QPrinter::Millimeter );
602
- QRectF paperRectMM = printer.pageRect ( QPrinter::Millimeter );
603
- QRectF paperRectPixel = printer.pageRect ( QPrinter::DevicePixel );
604
-
605
- QgsPaintEngineHack::fixEngineFlags ( printer.paintEngine () );
606
-
607
- QPainter p ( &printer );
608
- if ( c->printAsRaster () ) // embed one raster into the pdf
609
- {
610
- QImage* img = printCompositionToImage ( c );
611
- if ( img )
612
- {
613
- p.drawImage ( paperRectPixel, *img, QRectF ( 0 , 0 , img->width (), img->height () ) );
614
- }
615
- delete img;
616
- }
617
- else // vector pdf
618
- {
619
- c->render ( &p, paperRectPixel, paperRectMM );
620
- }
621
- p.end ();
622
-
586
+ c->exportAsPDF ( tempFile.fileName () );
623
587
ba = new QByteArray ();
624
588
*ba = tempFile.readAll ();
625
589
}
0 commit comments