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
7138cb9c
Commit
7138cb9c
authored
Jun 24, 2011
by
shibakaneki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolved bad performance when drawing on top of a PDF
parent
086c4954
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
28 deletions
+96
-28
UBGraphicsScene.cpp
src/domain/UBGraphicsScene.cpp
+1
-0
XPDFRenderer.cpp
src/pdf/XPDFRenderer.cpp
+77
-26
XPDFRenderer.h
src/pdf/XPDFRenderer.h
+18
-2
No files found.
src/domain/UBGraphicsScene.cpp
View file @
7138cb9c
...
...
@@ -10,6 +10,7 @@
#include <QtGui>
#include <QtWebKit>
#include <QtSvg>
#include <QGraphicsView>
#include "frameworks/UBGeometryUtils.h"
#include "frameworks/UBPlatformUtils.h"
...
...
src/pdf/XPDFRenderer.cpp
View file @
7138cb9c
...
...
@@ -5,12 +5,6 @@
#include <frameworks/UBPlatformUtils.h>
#include <splash/SplashBitmap.h>
#include <xpdf/Object.h>
#include <xpdf/GlobalParams.h>
#include <xpdf/SplashOutputDev.h>
#include <xpdf/PDFDoc.h>
QAtomicInt
XPDFRenderer
::
sInstancesCount
=
0
;
XPDFRenderer
::
XPDFRenderer
(
const
QString
&
filename
)
...
...
@@ -27,7 +21,11 @@ XPDFRenderer::XPDFRenderer(const QString &filename)
mDocument
=
new
PDFDoc
(
new
GString
(
filename
.
toUtf8
().
data
()),
0
,
0
,
0
);
// the filename GString is deleted on PDFDoc desctruction
sInstancesCount
.
ref
();
bThumbGenerated
=
false
;
bPagesGenerated
=
false
;
mPagesMap
.
clear
();
mThumbs
.
clear
();
mThumbMap
.
clear
();
}
XPDFRenderer
::~
XPDFRenderer
()
...
...
@@ -118,47 +116,100 @@ int XPDFRenderer::pageRotation(int pageNumber) const
return
0
;
}
void
XPDFRenderer
::
render
(
QPainter
*
p
,
int
pageNumber
,
const
QRectF
&
bounds
)
{
if
(
isValid
())
{
// First verify if the thumbnails and the pages are generated
if
(
!
bThumbGenerated
)
{
qreal
xscale
=
p
->
worldTransform
().
m11
();
qreal
yscale
=
p
->
worldTransform
().
m22
();
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
)
{
qreal
xscale
=
p
->
worldTransform
().
m11
();
qreal
yscale
=
p
->
worldTransform
().
m22
();
if
(
!
mPagesMap
[
pageNumber
-
1
])
{
// Generate the page
mNumPageToPageMap
[
pageNumber
]
=
*
createPDFImage
(
pageNumber
,
xscale
,
yscale
,
bounds
);
mPagesMap
[
pageNumber
-
1
]
=
true
;
if
(
mPagesMap
.
size
()
==
mDocument
->
getNumPages
())
{
bPagesGenerated
=
true
;
}
}
}
// Warning: verify pagenumber
QImage
pdfImage
;
if
(
!
bThumbGenerated
)
{
pdfImage
=
mThumbs
.
at
(
pageNumber
-
1
);
}
else
{
pdfImage
=
mNumPageToPageMap
[
pageNumber
];
}
pdfImage
.
rect
();
QTransform
savedTransform
=
p
->
worldTransform
();
p
->
resetTransform
();
p
->
drawImage
(
QPointF
(
savedTransform
.
dx
()
+
mSliceX
,
savedTransform
.
dy
()
+
mSliceY
),
pdfImage
);
p
->
setWorldTransform
(
savedTransform
);
}
}
QImage
*
XPDFRenderer
::
createPDFImage
(
int
pageNumber
,
const
qreal
xscale
,
const
qreal
yscale
,
const
QRectF
&
bounds
)
{
QImage
*
img
=
new
QImage
();
if
(
isValid
())
{
SplashColor
paperColor
=
{
0xFF
,
0xFF
,
0xFF
};
// white
SplashOutputDev
splash
(
splashModeRGB8
,
1
,
gFalse
,
paperColor
);
splash
.
startDoc
(
mDocument
->
getXRef
());
mSplash
=
new
SplashOutputDev
(
splashModeRGB8
,
1
,
gFalse
,
paperColor
);
mSplash
->
startDoc
(
mDocument
->
getXRef
());
int
hResolution
=
72
;
int
vResolution
=
72
;
int
rotation
=
0
;
// in degrees (get it from the worldTransform if we want to support rotation)
GBool
useMediaBox
=
gFalse
;
GBool
crop
=
gTrue
;
GBool
printing
=
gFalse
;
const
qreal
xScale
=
p
->
worldTransform
().
m11
()
;
const
qreal
yScale
=
p
->
worldTransform
().
m22
()
;
qreal
s
liceX
=
0.
;
qreal
s
liceY
=
0.
;
const
qreal
xScale
=
xscale
;
const
qreal
yScale
=
yscale
;
mS
liceX
=
0.
;
mS
liceY
=
0.
;
if
(
bounds
.
isNull
())
{
mDocument
->
displayPage
(
&
s
plash
,
pageNumber
,
hResolution
*
xScale
,
vResolution
*
yScale
,
mDocument
->
displayPage
(
mS
plash
,
pageNumber
,
hResolution
*
xScale
,
vResolution
*
yScale
,
rotation
,
useMediaBox
,
crop
,
printing
);
}
else
{
s
liceX
=
bounds
.
x
()
*
xScale
;
s
liceY
=
bounds
.
y
()
*
yScale
;
mS
liceX
=
bounds
.
x
()
*
xScale
;
mS
liceY
=
bounds
.
y
()
*
yScale
;
qreal
sliceW
=
bounds
.
width
()
*
xScale
;
qreal
sliceH
=
bounds
.
height
()
*
yScale
;
mDocument
->
displayPageSlice
(
&
s
plash
,
pageNumber
,
hResolution
*
xScale
,
vResolution
*
yScale
,
rotation
,
useMediaBox
,
crop
,
printing
,
sliceX
,
s
liceY
,
sliceW
,
sliceH
);
mDocument
->
displayPageSlice
(
mS
plash
,
pageNumber
,
hResolution
*
xScale
,
vResolution
*
yScale
,
rotation
,
useMediaBox
,
crop
,
printing
,
mSliceX
,
mS
liceY
,
sliceW
,
sliceH
);
}
SplashBitmap
*
bitmap
=
splash
.
getBitmap
();
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
);
mpSplashBitmap
=
mSplash
->
getBitmap
();
img
=
new
QImage
(
mpSplashBitmap
->
getDataPtr
(),
mpSplashBitmap
->
getWidth
(),
mpSplashBitmap
->
getHeight
(),
mpSplashBitmap
->
getWidth
()
*
3
,
QImage
::
Format_RGB888
);
}
return
img
;
}
src/pdf/XPDFRenderer.h
View file @
7138cb9c
#ifndef XPDFRENDERER_H
#define XPDFRENDERER_H
#include <QImage>
#include "PDFRenderer.h"
#include <splash/SplashBitmap.h>
#include <xpdf/Object.h>
#include <xpdf/GlobalParams.h>
#include <xpdf/SplashOutputDev.h>
#include <xpdf/PDFDoc.h>
class
PDFDoc
;
...
...
@@ -29,10 +34,21 @@ class XPDFRenderer : public PDFRenderer
private
:
void
init
();
QImage
*
createPDFImage
(
int
pageNumber
,
const
qreal
xscale
=
0
.
5
,
const
qreal
yscale
=
0
.
5
,
const
QRectF
&
bounds
=
QRectF
());
PDFDoc
*
mDocument
;
QList
<
QImage
>
mThumbs
;
QMap
<
int
,
bool
>
mPagesMap
;
QMap
<
int
,
bool
>
mThumbMap
;
QMap
<
int
,
QImage
>
mNumPageToPageMap
;
static
QAtomicInt
sInstancesCount
;
qreal
mSliceX
;
qreal
mSliceY
;
int
bPD
;
bool
bThumbGenerated
;
bool
bPagesGenerated
;
SplashBitmap
*
mpSplashBitmap
;
SplashOutputDev
*
mSplash
;
};
#endif // XPDFRENDERER_H
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