mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-24 10:25:36 +00:00
Add a mapping system for pages to exclude the pages we are not able to load, avoid crashing when requesting "invalid" pages.
BUG: 156608 svn path=/trunk/KDE/kdegraphics/okular/; revision=765972
This commit is contained in:
parent
66c950fcbb
commit
e27bfaac73
|
@ -17,6 +17,7 @@
|
||||||
#include <QtGui/QPrinter>
|
#include <QtGui/QPrinter>
|
||||||
|
|
||||||
#include <kaboutdata.h>
|
#include <kaboutdata.h>
|
||||||
|
#include <kdebug.h>
|
||||||
#include <kglobal.h>
|
#include <kglobal.h>
|
||||||
#include <klocale.h>
|
#include <klocale.h>
|
||||||
|
|
||||||
|
@ -27,6 +28,8 @@
|
||||||
#include <tiff.h>
|
#include <tiff.h>
|
||||||
#include <tiffio.h>
|
#include <tiffio.h>
|
||||||
|
|
||||||
|
#define TiffDebug 4714
|
||||||
|
|
||||||
class TIFFGenerator::Private
|
class TIFFGenerator::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -102,6 +105,7 @@ bool TIFFGenerator::doCloseDocument()
|
||||||
d->tiff = 0;
|
d->tiff = 0;
|
||||||
delete m_docInfo;
|
delete m_docInfo;
|
||||||
m_docInfo = 0;
|
m_docInfo = 0;
|
||||||
|
m_pageMapping.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -112,7 +116,7 @@ QImage TIFFGenerator::image( Okular::PixmapRequest * request )
|
||||||
bool generated = false;
|
bool generated = false;
|
||||||
QImage img;
|
QImage img;
|
||||||
|
|
||||||
if ( TIFFSetDirectory( d->tiff, request->page()->number() ) )
|
if ( TIFFSetDirectory( d->tiff, mapPage( request->page()->number() ) ) )
|
||||||
{
|
{
|
||||||
int rotation = request->page()->rotation();
|
int rotation = request->page()->rotation();
|
||||||
uint32 width = (uint32)request->page()->width();
|
uint32 width = (uint32)request->page()->width();
|
||||||
|
@ -197,6 +201,7 @@ void TIFFGenerator::loadPages( QVector<Okular::Page*> & pagesVector )
|
||||||
|
|
||||||
tdir_t dirs = TIFFNumberOfDirectories( d->tiff );
|
tdir_t dirs = TIFFNumberOfDirectories( d->tiff );
|
||||||
pagesVector.resize( dirs );
|
pagesVector.resize( dirs );
|
||||||
|
tdir_t realdirs = 0;
|
||||||
|
|
||||||
uint32 width = 0;
|
uint32 width = 0;
|
||||||
uint32 height = 0;
|
uint32 height = 0;
|
||||||
|
@ -210,11 +215,15 @@ void TIFFGenerator::loadPages( QVector<Okular::Page*> & pagesVector )
|
||||||
TIFFGetField( d->tiff, TIFFTAG_IMAGELENGTH, &height ) != 1 )
|
TIFFGetField( d->tiff, TIFFTAG_IMAGELENGTH, &height ) != 1 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
delete pagesVector[i];
|
Okular::Page * page = new Okular::Page( realdirs, width, height, Okular::Rotation0 );
|
||||||
Okular::Page * page = new Okular::Page( i, width, height, Okular::Rotation0 );
|
pagesVector[ realdirs ] = page;
|
||||||
pagesVector[i] = page;
|
|
||||||
|
|
||||||
|
m_pageMapping[ realdirs ] = i;
|
||||||
|
|
||||||
|
++realdirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pagesVector.resize( realdirs );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TIFFGenerator::print( QPrinter& printer )
|
bool TIFFGenerator::print( QPrinter& printer )
|
||||||
|
@ -231,7 +240,7 @@ bool TIFFGenerator::print( QPrinter& printer )
|
||||||
|
|
||||||
for ( tdir_t i = 0; i < pageList.count(); ++i )
|
for ( tdir_t i = 0; i < pageList.count(); ++i )
|
||||||
{
|
{
|
||||||
if ( !TIFFSetDirectory( d->tiff, pageList[i] - 1 ) )
|
if ( !TIFFSetDirectory( d->tiff, mapPage( pageList[i] - 1 ) ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( TIFFGetField( d->tiff, TIFFTAG_IMAGEWIDTH, &width ) != 1 ||
|
if ( TIFFGetField( d->tiff, TIFFTAG_IMAGEWIDTH, &width ) != 1 ||
|
||||||
|
@ -263,5 +272,16 @@ bool TIFFGenerator::print( QPrinter& printer )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TIFFGenerator::mapPage( int page ) const
|
||||||
|
{
|
||||||
|
QHash< int, int >::const_iterator it = m_pageMapping.find( page );
|
||||||
|
if ( it == m_pageMapping.end() )
|
||||||
|
{
|
||||||
|
kWarning(TiffDebug) << "Requesting unmapped page" << page << ":" << m_pageMapping;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return it.value();
|
||||||
|
}
|
||||||
|
|
||||||
#include "generator_tiff.moc"
|
#include "generator_tiff.moc"
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
#include <core/generator.h>
|
#include <core/generator.h>
|
||||||
|
|
||||||
|
#include <qhash.h>
|
||||||
|
|
||||||
class TIFFGenerator : public Okular::Generator
|
class TIFFGenerator : public Okular::Generator
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -34,8 +36,10 @@ class TIFFGenerator : public Okular::Generator
|
||||||
Private * const d;
|
Private * const d;
|
||||||
|
|
||||||
void loadPages( QVector<Okular::Page*> & pagesVector );
|
void loadPages( QVector<Okular::Page*> & pagesVector );
|
||||||
|
int mapPage( int page ) const;
|
||||||
|
|
||||||
Okular::DocumentInfo * m_docInfo;
|
Okular::DocumentInfo * m_docInfo;
|
||||||
|
QHash< int, int > m_pageMapping;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue