@ -46,7 +46,10 @@ using namespace merge_lib;
UBExportFullPDF : : UBExportFullPDF ( QObject * parent )
UBExportFullPDF : : UBExportFullPDF ( QObject * parent )
: UBExportAdaptor ( parent )
: UBExportAdaptor ( parent )
{
{
// NOOP
//need to calculate screen resolution
QDesktopWidget * desktop = UBApplication : : desktop ( ) ;
int dpiCommon = ( desktop - > physicalDpiX ( ) + desktop - > physicalDpiY ( ) ) / 2 ;
mScaleFactor = 72.0f / dpiCommon ;
}
}
@ -56,7 +59,7 @@ UBExportFullPDF::~UBExportFullPDF()
}
}
void UBExportFullPDF : : saveOverlayPdf ( UBDocumentProxy * pDocumentProxy , QString filename )
void UBExportFullPDF : : saveOverlayPdf ( UBDocumentProxy * pDocumentProxy , const QString & filename )
{
{
if ( ! pDocumentProxy | | filename . length ( ) = = 0 | | pDocumentProxy - > pageCount ( ) = = 0 )
if ( ! pDocumentProxy | | filename . length ( ) = = 0 | | pDocumentProxy - > pageCount ( ) = = 0 )
return ;
return ;
@ -70,9 +73,6 @@ void UBExportFullPDF::saveOverlayPdf(UBDocumentProxy* pDocumentProxy, QString fi
pdfPrinter . setOutputFileName ( filename ) ;
pdfPrinter . setOutputFileName ( filename ) ;
pdfPrinter . setFullPage ( true ) ;
pdfPrinter . setFullPage ( true ) ;
const qreal margin = UBSettings : : settings ( ) - > pdfMargin - > get ( ) . toDouble ( ) * pdfPrinter . resolution ( ) / 25.4 ;
mMargin = margin ;
QPainter * pdfPainter = 0 ;
QPainter * pdfPainter = 0 ;
for ( int pageIndex = 0 ; pageIndex < pDocumentProxy - > pageCount ( ) ; pageIndex + + )
for ( int pageIndex = 0 ; pageIndex < pDocumentProxy - > pageCount ( ) ; pageIndex + + )
@ -87,54 +87,20 @@ void UBExportFullPDF::saveOverlayPdf(UBDocumentProxy* pDocumentProxy, QString fi
scene - > setRenderingQuality ( UBItem : : RenderingQualityHigh ) ;
scene - > setRenderingQuality ( UBItem : : RenderingQualityHigh ) ;
scene - > setRenderingContext ( UBGraphicsScene : : PdfExport ) ;
scene - > setRenderingContext ( UBGraphicsScene : : PdfExport ) ;
UBGraphicsPDFItem * pdfItem = qgraphicsitem_cast < UBGraphicsPDFItem * > ( scene - > backgroundObject ( ) ) ;
QSize pageSize = scene - > nominalSize ( ) ;
if ( pdfItem )
{
QSizeF sceneItemsBound = scene - > itemsBoundingRect ( ) . size ( ) ;
qreal ratio = ( qreal ) pdfPrinter . resolution ( ) / 72.0 ;
QSizeF scaled = sceneItemsBound * ratio ;
pdfPrinter . setPaperSize ( scaled , QPrinter : : DevicePixel ) ;
if ( pageIndex ! = 0 )
UBGraphicsPDFItem * pdfItem = qgraphicsitem_cast < UBGraphicsPDFItem * > ( scene - > backgroundObject ( ) ) ;
pdfPrinter . newPage ( ) ;
if ( ! pdfPainter )
pdfPainter = new QPainter ( & pdfPrinter ) ;
//render to PDF
scene - > render ( pdfPainter , QRectF ( 0 , 0 , sceneItemsBound . width ( ) * ratio
, sceneItemsBound . height ( ) * ratio ) , scene - > itemsBoundingRect ( ) ) ;
mHasPDFBackgrounds = true ;
}
else
{
if ( UBSettings : : settings ( ) - > pdfPageFormat - > get ( ) . toString ( ) = = " Letter " )
pdfPrinter . setPageSize ( QPrinter : : Letter ) ;
else
pdfPrinter . setPageSize ( QPrinter : : A4 ) ;
QSize docSize = pDocumentProxy - > defaultDocumentSize ( ) ;
if ( pdfItem ) mHasPDFBackgrounds = true ;
if ( docSize . width ( ) > docSize . height ( ) )
{
pdfPrinter . setOrientation ( QPrinter : : Landscape ) ;
}
if ( pageIndex ! = 0 )
pdfPrinter . setPaperSize ( QSizeF ( pageSize . width ( ) * mScaleFactor , pageSize . height ( ) * mScaleFactor ) , QPrinter : : Point ) ;
pdfPrinter . newPage ( ) ;
mDefaultPageRect = pdfPrinter . paperRect ( ) ;
if ( ! pdfPainter ) pdfPainter = new QPainter ( & pdfPrinter ) ;
QRectF paperRect = mDefaultPageRect . adjusted ( margin , margin , - margin , - margin ) ;
QRectF normalized = scene - > normalizedSceneRect ( paperRect . width ( ) / paperRect . height ( ) ) ;
if ( ! pdfPainter )
if ( pageIndex ! = 0 ) pdfPrinter . newPage ( ) ;
pdfPainter = new QPainter ( & pdfPrinter ) ;
//render to PDF
//render to PDF
scene - > render ( pdfPainter , paperRect , normalized ) ;
scene - > render ( pdfPainter ) ;
}
//restore screen rendering quality
//restore screen rendering quality
scene - > setRenderingContext ( UBGraphicsScene : : Screen ) ;
scene - > setRenderingContext ( UBGraphicsScene : : Screen ) ;
@ -144,8 +110,7 @@ void UBExportFullPDF::saveOverlayPdf(UBDocumentProxy* pDocumentProxy, QString fi
scene - > setBackground ( isDark , isCrossed ) ;
scene - > setBackground ( isDark , isCrossed ) ;
}
}
if ( pdfPainter )
if ( pdfPainter ) delete pdfPainter ;
delete pdfPainter ;
}
}
@ -171,12 +136,10 @@ void UBExportFullPDF::persist(UBDocumentProxy* pDocumentProxy)
}
}
void UBExportFullPDF : : persistsDocument ( UBDocumentProxy * pDocumentProxy , QString filename )
void UBExportFullPDF : : persistsDocument ( UBDocumentProxy * pDocumentProxy , const QString & filename )
{
{
QFile file ( filename ) ;
QFile file ( filename ) ;
if ( file . exists ( ) )
if ( file . exists ( ) ) file . remove ( ) ;
file . remove ( ) ;
QString overlayName = filename ;
QString overlayName = filename ;
overlayName . replace ( " .pdf " , " _overlay.pdf " ) ;
overlayName . replace ( " .pdf " , " _overlay.pdf " ) ;
@ -209,6 +172,8 @@ void UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, QString
UBGraphicsScene * scene = UBPersistenceManager : : persistenceManager ( ) - > loadDocumentScene ( pDocumentProxy , pageIndex ) ;
UBGraphicsScene * scene = UBPersistenceManager : : persistenceManager ( ) - > loadDocumentScene ( pDocumentProxy , pageIndex ) ;
UBGraphicsPDFItem * pdfItem = qgraphicsitem_cast < UBGraphicsPDFItem * > ( scene - > backgroundObject ( ) ) ;
UBGraphicsPDFItem * pdfItem = qgraphicsitem_cast < UBGraphicsPDFItem * > ( scene - > backgroundObject ( ) ) ;
QSize pageSize = scene - > nominalSize ( ) ;
if ( pdfItem )
if ( pdfItem )
{
{
QString pdfName = UBPersistenceManager : : objectDirectory + " / " + pdfItem - > fileUuid ( ) . toString ( ) + " .pdf " ;
QString pdfName = UBPersistenceManager : : objectDirectory + " / " + pdfItem - > fileUuid ( ) . toString ( ) + " .pdf " ;
@ -216,24 +181,18 @@ void UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, QString
QPointF boudingRectBottomLeft = scene - > itemsBoundingRect ( ) . bottomLeft ( ) ;
QPointF boudingRectBottomLeft = scene - > itemsBoundingRect ( ) . bottomLeft ( ) ;
QPointF pdfItemBottomLeft = pdfItem - > sceneBoundingRect ( ) . bottomLeft ( ) ;
QPointF pdfItemBottomLeft = pdfItem - > sceneBoundingRect ( ) . bottomLeft ( ) ;
QPointF offset = pdfItemBottomLeft - boudingRectBottomLeft ;
qDebug ( ) < < " scene->itemsBoundingRect() " < < scene - > itemsBoundingRect ( ) ;
qDebug ( ) < < " scene->itemsBoundingRect() " < < scene - > itemsBoundingRect ( ) ;
qDebug ( ) < < " pdfItem->boundingRect() " < < pdfItem - > boundingRect ( ) ;
qDebug ( ) < < " pdfItem->boundingRect() " < < pdfItem - > boundingRect ( ) ;
qDebug ( ) < < " pdfItem->sceneBoundingRect() " < < pdfItem - > sceneBoundingRect ( ) ;
qDebug ( ) < < " pdfItem->sceneBoundingRect() " < < pdfItem - > sceneBoundingRect ( ) ;
qDebug ( ) < < offset ;
TransformationDescription baseTrans ( offset . x ( ) , offset . y ( ) * - 1 , 1 , 0 ) ;
//TransformationDescription baseTrans(0, 0, 1, 0);
TransformationDescription overlayTrans ( 0 , 0 , 1 , 0 ) ;
MergePageDescription pageDescription ( scene - > itemsBoundingRect ( ) . width ( ) ,
MergePageDescription pageDescription ( pageSize . width ( ) * mScaleFactor ,
scene - > itemsBoundingRect ( ) . height ( ) ,
pageSize . height ( ) * mScaleFactor ,
pdfItem - > pageNumber ( ) ,
pdfItem - > pageNumber ( ) ,
QFile : : encodeName ( backgroundPath ) . constData ( ) ,
QFile : : encodeName ( backgroundPath ) . constData ( ) ,
baseTrans ,
TransformationDescription ( ) ,
pageIndex + 1 ,
pageIndex + 1 ,
overlayTrans ,
TransformationDescription ( ) ,
false , false ) ;
false , false ) ;
mergeInfo . push_back ( pageDescription ) ;
mergeInfo . push_back ( pageDescription ) ;
@ -242,12 +201,8 @@ void UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, QString
}
}
else
else
{
{
QRectF paperRect = mDefaultPageRect . adjusted ( mMargin , mMargin , - mMargin , - mMargin ) ;
MergePageDescription pageDescription ( pageSize . width ( ) * mScaleFactor ,
QRectF normalized = scene - > normalizedSceneRect ( paperRect . width ( ) / paperRect . height ( ) ) ;
pageSize . height ( ) * mScaleFactor ,
MergePageDescription pageDescription ( normalized . width ( ) ,
normalized . height ( ) ,
0 ,
0 ,
" " ,
" " ,
TransformationDescription ( ) ,
TransformationDescription ( ) ,