Skip to content

Commit

Permalink
[composer] Make sure entire page symbol border is included when expor…
Browse files Browse the repository at this point in the history
…ting compositions. Previously half the page border would be cropped out. Also fix nIRV's infamous 1px bad row at bottom of composer exports bug.
  • Loading branch information
nyalldawson committed Jan 4, 2014
1 parent b5502b6 commit 6d918a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/core/composer/qgspaperitem.cpp
Expand Up @@ -128,13 +128,13 @@ QgsPaperItem::QgsPaperItem( QgsComposition* c ): QgsComposerItem( c, false ),
}

QgsPaperItem::QgsPaperItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition ): QgsComposerItem( x, y, width, height, composition, false ),
mPageGrid( 0 )
mPageGrid( 0 ), mPageMargin( 0 )
{
initialize();
}

QgsPaperItem::QgsPaperItem(): QgsComposerItem( 0, false ),
mPageGrid( 0 )
mPageGrid( 0 ), mPageMargin( 0 )
{
initialize();
}
Expand Down Expand Up @@ -167,15 +167,28 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite

painter->save();
painter->setRenderHint( QPainter::Antialiasing );
QPolygonF pagePolygon = QPolygonF( QRectF( 0, 0, rect().width(), rect().height() ) );
mComposition->pageStyleSymbol()->startRender( context );

calculatePageMargin();
QPolygonF pagePolygon = QPolygonF( QRectF( mPageMargin, mPageMargin, rect().width() - 2 * mPageMargin, rect().height() - 2 * mPageMargin ) );
QList<QPolygonF> rings; //empty list
mComposition->pageStyleSymbol()->renderPolygon( pagePolygon, &rings, 0, context );
mComposition->pageStyleSymbol()->stopRender( context );
painter->restore();

}

void QgsPaperItem::calculatePageMargin()
{
//get max bleed from symbol
double maxBleed = QgsSymbolLayerV2Utils::estimateMaxSymbolBleed( mComposition->pageStyleSymbol() );

//Now subtract 1 pixel to prevent semi-transparent borders at edge of solid page caused by
//anti-aliased painting. This may cause a pixel to be cropped from certain edge lines/symbols,
//but that can be counteracted by adding a dummy transparent line symbol layer with a wider line width
mPageMargin = maxBleed - ( 25.4 / mComposition->printResolution() );
}

bool QgsPaperItem::writeXML( QDomElement& elem, QDomDocument & doc ) const
{
Q_UNUSED( elem );
Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgspaperitem.h
Expand Up @@ -69,7 +69,10 @@ class CORE_EXPORT QgsPaperItem: public QgsComposerItem
/**Set flags and z-value*/
void initialize();

void calculatePageMargin();

QgsPaperGrid* mPageGrid;
double mPageMargin;
};

#endif

0 comments on commit 6d918a1

Please sign in to comment.