Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
2ea30bf9
Commit
2ea30bf9
authored
Jan 31, 2012
by
Anatoly Mihalchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved PDF export. Now it exports in proper size.
parent
3aaedfa7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
76 deletions
+29
-76
UBExportFullPDF.cpp
src/adaptors/UBExportFullPDF.cpp
+26
-71
UBExportFullPDF.h
src/adaptors/UBExportFullPDF.h
+3
-4
UBExportPDF.cpp
src/adaptors/UBExportPDF.cpp
+0
-1
No files found.
src/adaptors/UBExportFullPDF.cpp
View file @
2ea30bf9
...
@@ -46,7 +46,10 @@ using namespace merge_lib;
...
@@ -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.0
f
/
dpiCommon
;
}
}
...
@@ -56,7 +59,7 @@ UBExportFullPDF::~UBExportFullPDF()
...
@@ -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
...
@@ -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
...
@@ -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
)
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
();
UBGraphicsPDFItem
*
pdfItem
=
qgraphicsitem_cast
<
UBGraphicsPDFItem
*>
(
scene
->
backgroundObject
());
if
(
docSize
.
width
()
>
docSize
.
height
())
{
pdfPrinter
.
setOrientation
(
QPrinter
::
Landscape
);
}
if
(
pageIndex
!=
0
)
if
(
pdfItem
)
mHasPDFBackgrounds
=
true
;
pdfPrinter
.
newPage
();
pdfPrinter
.
setPaperSize
(
QSizeF
(
pageSize
.
width
()
*
mScaleFactor
,
pageSize
.
height
()
*
mScaleFactor
),
QPrinter
::
Point
);
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
...
@@ -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)
...
@@ -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,31 +172,27 @@ void UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, QString
...
@@ -209,31 +172,27 @@ 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
());
if
(
pdfItem
)
QSize
pageSize
=
scene
->
nominalSize
();
if
(
pdfItem
)
{
{
QString
pdfName
=
UBPersistenceManager
::
objectDirectory
+
"/"
+
pdfItem
->
fileUuid
().
toString
()
+
".pdf"
;
QString
pdfName
=
UBPersistenceManager
::
objectDirectory
+
"/"
+
pdfItem
->
fileUuid
().
toString
()
+
".pdf"
;
QString
backgroundPath
=
pDocumentProxy
->
persistencePath
()
+
"/"
+
pdfName
;
QString
backgroundPath
=
pDocumentProxy
->
persistencePath
()
+
"/"
+
pdfName
;
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
...
@@ -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
(),
...
...
src/adaptors/UBExportFullPDF.h
View file @
2ea30bf9
...
@@ -33,14 +33,13 @@ class UBExportFullPDF : public UBExportAdaptor
...
@@ -33,14 +33,13 @@ class UBExportFullPDF : public UBExportAdaptor
virtual
QString
exportExtention
();
virtual
QString
exportExtention
();
virtual
void
persist
(
UBDocumentProxy
*
pDocument
);
virtual
void
persist
(
UBDocumentProxy
*
pDocument
);
virtual
void
persistsDocument
(
UBDocumentProxy
*
pDocument
,
QString
filename
);
virtual
void
persistsDocument
(
UBDocumentProxy
*
pDocument
,
const
QString
&
filename
);
protected
:
protected
:
void
saveOverlayPdf
(
UBDocumentProxy
*
pDocumentProxy
,
QString
filename
);
void
saveOverlayPdf
(
UBDocumentProxy
*
pDocumentProxy
,
const
QString
&
filename
);
private
:
private
:
QRect
mDefaultPageRect
;
float
mScaleFactor
;
int
mMargin
;
bool
mHasPDFBackgrounds
;
bool
mHasPDFBackgrounds
;
};
};
...
...
src/adaptors/UBExportPDF.cpp
View file @
2ea30bf9
...
@@ -101,7 +101,6 @@ void UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QStrin
...
@@ -101,7 +101,6 @@ void UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QStrin
//setting page size to appropriate value
//setting page size to appropriate value
pdfPrinter
.
setPaperSize
(
QSizeF
(
pageSize
.
width
()
*
scaleFactor
,
pageSize
.
height
()
*
scaleFactor
),
QPrinter
::
Point
);
pdfPrinter
.
setPaperSize
(
QSizeF
(
pageSize
.
width
()
*
scaleFactor
,
pageSize
.
height
()
*
scaleFactor
),
QPrinter
::
Point
);
pdfPrinter
.
setOrientation
((
pageSize
.
width
()
>
pageSize
.
height
())
?
QPrinter
::
Landscape
:
QPrinter
::
Portrait
);
if
(
painterNeedsBegin
)
painterNeedsBegin
=
!
pdfPainter
.
begin
(
&
pdfPrinter
);
if
(
painterNeedsBegin
)
painterNeedsBegin
=
!
pdfPainter
.
begin
(
&
pdfPrinter
);
//render to PDF
//render to PDF
scene
->
render
(
&
pdfPainter
);
scene
->
render
(
&
pdfPainter
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment