Skip to content

Commit

Permalink
Bounds polygon must be in PDF units
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 20, 2019
1 parent 3bb93fc commit 9116907
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/core/qgsabstractgeopdfexporter.cpp
Expand Up @@ -338,10 +338,12 @@ QString QgsAbstractGeoPdfExporter::createCompositionXml( const QList<ComponentLa
page.appendChild( dpi );
// assumes DPI of 72, which is an assumption on GDALs/PDF side. It's only related to the PDF coordinate space and doesn't affect the actual output DPI!
QDomElement width = doc.createElement( QStringLiteral( "Width" ) );
width.appendChild( doc.createTextNode( QString::number( std::ceil( details.pageSizeMm.width() / 25.4 * 72 ) ) ) );
const double pageWidthPdfUnits = std::ceil( details.pageSizeMm.width() / 25.4 * 72 );
width.appendChild( doc.createTextNode( QString::number( pageWidthPdfUnits ) ) );
page.appendChild( width );
QDomElement height = doc.createElement( QStringLiteral( "Height" ) );
height.appendChild( doc.createTextNode( QString::number( std::ceil( details.pageSizeMm.height() / 25.4 * 72 ) ) ) );
const double pageHeightPdfUnits = std::ceil( details.pageSizeMm.height() / 25.4 * 72 );
height.appendChild( doc.createTextNode( QString::number( pageHeightPdfUnits ) ) );
page.appendChild( height );


Expand Down Expand Up @@ -380,7 +382,15 @@ QString QgsAbstractGeoPdfExporter::createCompositionXml( const QList<ComponentLa
the whole PDF page will be assumed to be georeferenced.
*/
QDomElement boundingPolygon = doc.createElement( QStringLiteral( "BoundingPolygon" ) );
boundingPolygon.appendChild( doc.createTextNode( section.pageBoundsPolygon.asWkt() ) );

// transform to PDF coordinate space
QTransform t = QTransform::fromTranslate( 0, pageHeightPdfUnits ).scale( pageWidthPdfUnits / details.pageSizeMm.width(),
-pageHeightPdfUnits / details.pageSizeMm.height() );

QgsPolygon p = section.pageBoundsPolygon;
p.transform( t );
boundingPolygon.appendChild( doc.createTextNode( p.asWkt() ) );

georeferencing.appendChild( boundingPolygon );
}
else
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgsgeopdfexport.cpp
Expand Up @@ -379,7 +379,7 @@ void TestQgsGeoPdfExport::testGeorefPolygon()
QDomDocument doc;
doc.setContent( composition );
QCOMPARE( doc.elementsByTagName( QStringLiteral( "SRS" ) ).at( 0 ).toElement().text(), QStringLiteral( "EPSG:4283" ) );
QCOMPARE( doc.elementsByTagName( QStringLiteral( "BoundingPolygon" ) ).at( 0 ).toElement().text(), QStringLiteral( "Polygon ((30 5, 250 15, 240 200, 50 190, 30 5))" ) );
QCOMPARE( doc.elementsByTagName( QStringLiteral( "BoundingPolygon" ) ).at( 0 ).toElement().text(), QStringLiteral( "Polygon ((60 -12, 500 -32, 480 -402, 100 -382, 60 -12))" ) );

QDomNodeList cps = doc.elementsByTagName( QStringLiteral( "ControlPoint" ) );
QCOMPARE( cps.count(), 4 );
Expand Down

0 comments on commit 9116907

Please sign in to comment.