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
47f69a82
Commit
47f69a82
authored
Aug 12, 2011
by
Claudio Valerio
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed pdf bug. When loading a already imported pdf the application crashes.
parent
dbaaa27a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
94 deletions
+28
-94
XPDFRenderer.cpp
src/pdf/XPDFRenderer.cpp
+28
-94
No files found.
src/pdf/XPDFRenderer.cpp
View file @
47f69a82
...
@@ -19,6 +19,13 @@
...
@@ -19,6 +19,13 @@
#include <frameworks/UBPlatformUtils.h>
#include <frameworks/UBPlatformUtils.h>
#include <splash/SplashBitmap.h>
#include <xpdf/Object.h>
#include <xpdf/GlobalParams.h>
#include <xpdf/SplashOutputDev.h>
#include <xpdf/PDFDoc.h>
#include "core/memcheck.h"
#include "core/memcheck.h"
QAtomicInt
XPDFRenderer
::
sInstancesCount
=
0
;
QAtomicInt
XPDFRenderer
::
sInstancesCount
=
0
;
...
@@ -37,13 +44,7 @@ XPDFRenderer::XPDFRenderer(const QString &filename)
...
@@ -37,13 +44,7 @@ XPDFRenderer::XPDFRenderer(const QString &filename)
mDocument
=
new
PDFDoc
(
new
GString
(
filename
.
toUtf8
().
data
()),
0
,
0
,
0
);
// the filename GString is deleted on PDFDoc desctruction
mDocument
=
new
PDFDoc
(
new
GString
(
filename
.
toUtf8
().
data
()),
0
,
0
,
0
);
// the filename GString is deleted on PDFDoc desctruction
sInstancesCount
.
ref
();
sInstancesCount
.
ref
();
bThumbGenerated
=
false
;
bPagesGenerated
=
false
;
mPagesMap
.
clear
();
mThumbs
.
clear
();
mThumbMap
.
clear
();
mScaleX
=
0.0
;
mScaleY
=
0.0
;
}
}
XPDFRenderer
::~
XPDFRenderer
()
XPDFRenderer
::~
XPDFRenderer
()
...
@@ -134,114 +135,47 @@ int XPDFRenderer::pageRotation(int pageNumber) const
...
@@ -134,114 +135,47 @@ int XPDFRenderer::pageRotation(int pageNumber) const
return
0
;
return
0
;
}
}
void
XPDFRenderer
::
render
(
QPainter
*
p
,
int
pageNumber
,
const
QRectF
&
bounds
)
{
if
(
isValid
())
{
qreal
xscale
=
p
->
worldTransform
().
m11
();
qreal
yscale
=
p
->
worldTransform
().
m22
();
bool
bZoomChanged
=
false
;
bool
bFirstThumbnail
=
false
;
if
(
fabs
(
mScaleX
-
xscale
)
>
0.1
||
fabs
(
mScaleY
-
yscale
)
>
0.1
)
{
mScaleX
=
xscale
;
mScaleY
=
yscale
;
bZoomChanged
=
true
;
}
// First verify if the thumbnails and the pages are generated
if
(
!
bThumbGenerated
)
{
if
(
pageNumber
==
1
)
{
bFirstThumbnail
=
true
;
}
if
(
!
mThumbMap
[
pageNumber
-
1
])
{
// Generate the thumbnail
mThumbs
<<
*
createPDFImage
(
pageNumber
,
xscale
,
yscale
,
bounds
);
mThumbMap
[
pageNumber
-
1
]
=
true
;
if
(
pageNumber
==
mDocument
->
getNumPages
())
{
bThumbGenerated
=
true
;
}
}
}
else
if
(
!
bPagesGenerated
||
bZoomChanged
)
{
if
(
!
mPagesMap
[
pageNumber
-
1
]
||
bZoomChanged
)
{
// Generate the page
mNumPageToPageMap
[
pageNumber
]
=
*
createPDFImage
(
pageNumber
,
xscale
,
yscale
,
bounds
);
mPagesMap
[
pageNumber
-
1
]
=
true
;
if
(
mPagesMap
.
size
()
==
mDocument
->
getNumPages
())
{
bPagesGenerated
=
true
;
}
}
}
QImage
pdfImage
;
if
(
!
bThumbGenerated
||
bFirstThumbnail
)
void
XPDFRenderer
::
render
(
QPainter
*
p
,
int
pageNumber
,
const
QRectF
&
bounds
)
{
pdfImage
=
mThumbs
.
at
(
pageNumber
-
1
);
}
else
{
pdfImage
=
mNumPageToPageMap
[
pageNumber
];
}
QTransform
savedTransform
=
p
->
worldTransform
();
p
->
resetTransform
();
QTime
t
;
t
.
start
();
p
->
drawImage
(
QPointF
(
savedTransform
.
dx
()
+
mSliceX
,
savedTransform
.
dy
()
+
mSliceY
),
pdfImage
);
//qDebug() << "XPDFRenderer::render(...) execution time: " << t.elapsed() << "ms";
p
->
setWorldTransform
(
savedTransform
);
}
}
QImage
*
XPDFRenderer
::
createPDFImage
(
int
pageNumber
,
const
qreal
xscale
,
const
qreal
yscale
,
const
QRectF
&
bounds
)
{
{
QImage
*
img
=
new
QImage
();
if
(
isValid
())
if
(
isValid
())
{
{
SplashColor
paperColor
=
{
0xFF
,
0xFF
,
0xFF
};
// white
SplashColor
paperColor
=
{
0xFF
,
0xFF
,
0xFF
};
// white
mSplash
=
new
SplashOutputDev
(
splashModeRGB8
,
1
,
gFalse
,
paperColor
);
SplashOutputDev
splash
(
splashModeRGB8
,
1
,
gFalse
,
paperColor
);
mSplash
->
startDoc
(
mDocument
->
getXRef
());
splash
.
startDoc
(
mDocument
->
getXRef
());
int
hResolution
=
72
;
int
hResolution
=
72
;
int
vResolution
=
72
;
int
vResolution
=
72
;
int
rotation
=
0
;
// in degrees (get it from the worldTransform if we want to support rotation)
int
rotation
=
0
;
// in degrees (get it from the worldTransform if we want to support rotation)
GBool
useMediaBox
=
gFalse
;
GBool
useMediaBox
=
gFalse
;
GBool
crop
=
gTrue
;
GBool
crop
=
gTrue
;
GBool
printing
=
gFalse
;
GBool
printing
=
gFalse
;
const
qreal
xScale
=
xscale
;
const
qreal
xScale
=
p
->
worldTransform
().
m11
()
;
const
qreal
yScale
=
yscale
;
const
qreal
yScale
=
p
->
worldTransform
().
m22
()
;
mS
liceX
=
0.
;
qreal
s
liceX
=
0.
;
mS
liceY
=
0.
;
qreal
s
liceY
=
0.
;
if
(
bounds
.
isNull
())
if
(
bounds
.
isNull
())
{
{
mDocument
->
displayPage
(
mS
plash
,
pageNumber
,
hResolution
*
xScale
,
vResolution
*
yScale
,
mDocument
->
displayPage
(
&
s
plash
,
pageNumber
,
hResolution
*
xScale
,
vResolution
*
yScale
,
rotation
,
useMediaBox
,
crop
,
printing
);
rotation
,
useMediaBox
,
crop
,
printing
);
}
}
else
else
{
{
mS
liceX
=
bounds
.
x
()
*
xScale
;
s
liceX
=
bounds
.
x
()
*
xScale
;
mS
liceY
=
bounds
.
y
()
*
yScale
;
s
liceY
=
bounds
.
y
()
*
yScale
;
qreal
sliceW
=
bounds
.
width
()
*
xScale
;
qreal
sliceW
=
bounds
.
width
()
*
xScale
;
qreal
sliceH
=
bounds
.
height
()
*
yScale
;
qreal
sliceH
=
bounds
.
height
()
*
yScale
;
mDocument
->
displayPageSlice
(
mS
plash
,
pageNumber
,
hResolution
*
xScale
,
vResolution
*
yScale
,
mDocument
->
displayPageSlice
(
&
s
plash
,
pageNumber
,
hResolution
*
xScale
,
vResolution
*
yScale
,
rotation
,
useMediaBox
,
crop
,
printing
,
mSliceX
,
mS
liceY
,
sliceW
,
sliceH
);
rotation
,
useMediaBox
,
crop
,
printing
,
sliceX
,
s
liceY
,
sliceW
,
sliceH
);
}
}
mpSplashBitmap
=
mSplash
->
getBitmap
();
SplashBitmap
*
bitmap
=
splash
.
getBitmap
();
img
=
new
QImage
(
mpSplashBitmap
->
getDataPtr
(),
mpSplashBitmap
->
getWidth
(),
mpSplashBitmap
->
getHeight
(),
mpSplashBitmap
->
getWidth
()
*
3
,
QImage
::
Format_RGB888
);
QImage
pdfImage
(
bitmap
->
getDataPtr
(),
bitmap
->
getWidth
(),
bitmap
->
getHeight
(),
bitmap
->
getWidth
()
*
3
,
QImage
::
Format_RGB888
);
QTransform
savedTransform
=
p
->
worldTransform
();
p
->
resetTransform
();
p
->
drawImage
(
QPointF
(
savedTransform
.
dx
()
+
sliceX
,
savedTransform
.
dy
()
+
sliceY
),
pdfImage
);
p
->
setWorldTransform
(
savedTransform
);
}
}
return
img
;
}
}
\ No newline at end of file
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