A rather big change:

* Hide as much private API as possible in Generator, PixmapRequest and ExportEntry/Format
 * Renamed ExportEntry to ExportFormat and made it value based
 * Removed canExportToText() and exportToText() from Generator API and implemented this
   functionality in exportFormats()/exportTo() in the generators
 * Removed the orientation parameter from PixmapRequest and let the Document handle the rotation
   of the page (pixmap) instead

CCMAIL:okular-devel@kde.org

svn path=/trunk/playground/graphics/okular/; revision=599058
This commit is contained in:
Tobias Koenig 2006-10-25 15:35:53 +00:00
parent 46a1ddc08e
commit d22b2f1892
18 changed files with 589 additions and 285 deletions

View file

@ -595,22 +595,40 @@ QStringList Document::paperSizes() const
bool Document::canExportToText() const
{
return generator ? generator->canExportToText() : false;
if ( !generator )
return false;
const ExportFormat::List formats = generator->exportFormats();
for ( int i = 0; i < formats.count(); ++i ) {
if ( formats[ i ].mimeType()->name() == QLatin1String( "text/plain" ) )
return true;
}
return false;
}
bool Document::exportToText( const QString& fileName ) const
{
return generator ? generator->exportToText( fileName ) : false;
if ( !generator )
return false;
const ExportFormat::List formats = generator->exportFormats();
for ( int i = 0; i < formats.count(); ++i ) {
if ( formats[ i ].mimeType()->name() == QLatin1String( "text/plain" ) )
return generator->exportTo( fileName, formats[ i ] );
}
return false;
}
QList<ExportEntry*> Document::exportFormats() const
ExportFormat::List Document::exportFormats() const
{
return generator ? generator->exportFormats() : QList<ExportEntry*>();
return generator ? generator->exportFormats() : ExportFormat::List();
}
bool Document::exportTo( const QString& fileName, const KMimeType::Ptr& mime ) const
bool Document::exportTo( const QString& fileName, const ExportFormat& format ) const
{
return generator ? generator->exportTo( fileName, mime ) : false;
return generator ? generator->exportTo( fileName, format ) : false;
}
bool Document::historyAtBegin() const
@ -676,11 +694,11 @@ void Document::requestPixmaps( const QLinkedList< PixmapRequest * > & requests )
}
// 1. [CLEAN STACK] remove previous requests of requesterID
int requesterID = requests.first()->id;
int requesterID = requests.first()->id();
QLinkedList< PixmapRequest * >::iterator sIt = d->pixmapRequestsStack.begin(), sEnd = d->pixmapRequestsStack.end();
while ( sIt != sEnd )
{
if ( (*sIt)->id == requesterID )
if ( (*sIt)->id() == requesterID )
{
// delete request and remove it from stack
delete *sIt;
@ -697,24 +715,24 @@ void Document::requestPixmaps( const QLinkedList< PixmapRequest * > & requests )
{
// set the 'page field' (see PixmapRequest) and check if it is valid
PixmapRequest * request = *rIt;
kWarning() << "request id=" << request->id << " " <<request->width << "x" << request->height << "@" << request->pageNumber << endl;
if ( !(request->page = pages_vector[ request->pageNumber ]) )
kWarning() << "request id=" << request->id() << " " <<request->width() << "x" << request->height() << "@" << request->pageNumber() << endl;
if ( pages_vector.value( request->pageNumber() ) == 0 )
{
// skip requests referencing an invalid page (must not happen)
delete request;
continue;
}
};
request->documentRotation = d->rotation;
request->setPage( pages_vector.value( request->pageNumber() ) );
if ( !request->async )
request->priority = 0;
if ( !request->asynchronous() )
request->setPriority( 0 );
if ( request->async && threadingDisabled )
request->async = false;
if ( request->asynchronous() && threadingDisabled )
request->setAsynchronous( false );
// add request to the 'stack' at the right place
if ( !request->priority )
if ( !request->priority() )
// add priority zero requests to the top of the stack
d->pixmapRequestsStack.append( request );
else
@ -722,7 +740,7 @@ void Document::requestPixmaps( const QLinkedList< PixmapRequest * > & requests )
// insert in stack sorted by priority
sIt = d->pixmapRequestsStack.begin();
sEnd = d->pixmapRequestsStack.end();
while ( sIt != sEnd && (*sIt)->priority >= request->priority )
while ( sIt != sEnd && (*sIt)->priority() >= request->priority() )
++sIt;
d->pixmapRequestsStack.insert( sIt, request );
}
@ -1398,7 +1416,7 @@ bool Document::print( KPrinter &printer )
void Document::requestDone( PixmapRequest * req )
{
#ifndef NDEBUG
if ( !generator->canGeneratePixmap( req->async ) )
if ( !generator->canGeneratePixmap( req->asynchronous() ) )
kDebug() << "requestDone with generator not in READY state." << endl;
#endif
@ -1406,7 +1424,7 @@ void Document::requestDone( PixmapRequest * req )
QLinkedList< AllocatedPixmap * >::iterator aIt = d->allocatedPixmapsFifo.begin();
QLinkedList< AllocatedPixmap * >::iterator aEnd = d->allocatedPixmapsFifo.end();
for ( ; aIt != aEnd; ++aIt )
if ( (*aIt)->page == req->pageNumber && (*aIt)->id == req->id )
if ( (*aIt)->page == req->pageNumber() && (*aIt)->id == req->id() )
{
AllocatedPixmap * p = *aIt;
d->allocatedPixmapsFifo.erase( aIt );
@ -1416,14 +1434,14 @@ void Document::requestDone( PixmapRequest * req )
}
// [MEM] 1.2 append memory allocation descriptor to the FIFO
int memoryBytes = 4 * req->width * req->height;
AllocatedPixmap * memoryPage = new AllocatedPixmap( req->id, req->pageNumber, memoryBytes );
int memoryBytes = 4 * req->width() * req->height();
AllocatedPixmap * memoryPage = new AllocatedPixmap( req->id(), req->pageNumber(), memoryBytes );
d->allocatedPixmapsFifo.append( memoryPage );
d->allocatedPixmapsTotalMemory += memoryBytes;
// 2. notify an observer that its pixmap changed
if ( d->observers.contains( req->id ) )
d->observers[ req->id ]->notifyPageChanged( req->pageNumber, DocumentObserver::Pixmap );
if ( d->observers.contains( req->id() ) )
d->observers[ req->id() ]->notifyPageChanged( req->pageNumber(), DocumentObserver::Pixmap );
// 3. delete request
delete req;
@ -1445,22 +1463,22 @@ void Document::sendGeneratorRequest()
d->pixmapRequestsStack.pop_back();
}
// request only if page isn't already present or request has invalid id
else if ( r->page->hasPixmap( r->id, r->width, r->height ) || r->id <= 0 || r->id >= MAX_OBSERVER_ID)
else if ( r->page()->hasPixmap( r->id(), r->width(), r->height() ) || r->id() <= 0 || r->id() >= MAX_OBSERVER_ID)
{
d->pixmapRequestsStack.pop_back();
delete r;
}
else if ( (long)r->width * (long)r->height > 20000000L )
else if ( (long)r->width() * (long)r->height() > 20000000L )
{
d->pixmapRequestsStack.pop_back();
if ( !d->warnedOutOfMemory )
{
kWarning() << "Running out of memory on page " << r->pageNumber
<< " (" << r->width << "x" << r->height << " px);" << endl;
kWarning() << "Running out of memory on page " << r->pageNumber()
<< " (" << r->width() << "x" << r->height() << " px);" << endl;
kWarning() << "this message will be reported only once." << endl;
d->warnedOutOfMemory = true;
}
delete r;
delete r;
}
else
request = r;
@ -1471,14 +1489,14 @@ void Document::sendGeneratorRequest()
return;
// [MEM] preventive memory freeing
int pixmapBytes = 4 * request->width * request->height;
int pixmapBytes = 4 * request->width() * request->height();
if ( pixmapBytes > (1024 * 1024) )
cleanupPixmapMemory( pixmapBytes );
// submit the request to the generator
if ( generator->canGeneratePixmap( request->async ) )
if ( generator->canGeneratePixmap( request->asynchronous() ) )
{
kWarning() << "sending request id=" << request->id << " " <<request->width << "x" << request->height << "@" << request->pageNumber << " async == " << request->async << endl;
kWarning() << "sending request id=" << request->id() << " " <<request->width() << "x" << request->height() << "@" << request->pageNumber() << " async == " << request->asynchronous() << endl;
d->pixmapRequestsStack.removeAll ( request );
generator->generatePixmap ( request );
}
@ -1817,6 +1835,28 @@ void Document::slotTimedMemoryCheck()
void Document::slotRotation( int rotation )
{
// tell the pages to rotate
QVector< Okular::Page * >::iterator pIt = pages_vector.begin();
QVector< Okular::Page * >::iterator pEnd = pages_vector.end();
for ( ; pIt != pEnd; ++pIt )
(*pIt)->rotateAt( rotation );
// clear 'memory allocation' descriptors
QLinkedList< AllocatedPixmap * >::iterator aIt = d->allocatedPixmapsFifo.begin();
QLinkedList< AllocatedPixmap * >::iterator aEnd = d->allocatedPixmapsFifo.end();
for ( ; aIt != aEnd; ++aIt )
delete *aIt;
d->allocatedPixmapsFifo.clear();
d->allocatedPixmapsTotalMemory = 0;
// notify the generator that the current rotation has changed
generator->rotationChanged( rotation, d->rotation );
// set the new rotation
d->rotation = rotation;
foreachObserver( notifySetup( pages_vector, true ) );
foreachObserver( notifyContentsCleared (DocumentObserver::Pixmap | DocumentObserver::Highlights | DocumentObserver::Annotations));
kDebug() << "Rotated: " << rotation << endl;
/*
if ( generator->supportsRotation() )
{
// tell the pages to rotate
@ -1838,10 +1878,11 @@ void Document::slotRotation( int rotation )
foreachObserver( notifySetup( pages_vector, true ) );
foreachObserver( notifyContentsCleared (DocumentObserver::Pixmap | DocumentObserver::Highlights | DocumentObserver::Annotations));
// foreachObserver( notifyViewportChanged( false /*disables smoothMove*/ ));
// foreachObserver( notifyViewportChanged( false ));
// foreachObserver( notifyPageChanged( ) );
kDebug() << "Rotated: " << rotation << endl;
}
*/
}
void Document::slotPaperSizes( int newsize )

View file

@ -38,7 +38,7 @@ class DocumentObserver;
class DocumentSynopsis;
class DocumentViewport;
class EmbeddedFile;
class ExportEntry;
class ExportFormat;
class Generator;
class Link;
class NotifyRequest;
@ -111,8 +111,8 @@ class OKULAR_EXPORT Document : public QObject
QStringList paperSizes() const;
bool canExportToText() const;
bool exportToText( const QString& fileName ) const;
QList<ExportEntry*> exportFormats() const;
bool exportTo( const QString& fileName, const KMimeType::Ptr& mime ) const;
QList<ExportFormat> exportFormats() const;
bool exportTo( const QString& fileName, const ExportFormat& format ) const;
bool historyAtBegin() const;
bool historyAtEnd() const;
QString getMetaData( const QString & key, const QString & option = QString() ) const;

View file

@ -8,18 +8,31 @@
***************************************************************************/
#include <kdebug.h>
#include <kicon.h>
#include "generator.h"
using namespace Okular;
class Generator::Private
{
public:
Private()
: m_document( 0 )
{
}
Document * m_document;
};
Generator::Generator()
: m_document( 0 )
: d( new Private )
{
}
Generator::~Generator()
{
delete d;
}
bool Generator::canGenerateTextPage() const
@ -126,22 +139,12 @@ void Generator::addPages( KConfigDialog* )
{
}
bool Generator::canExportToText() const
ExportFormat::List Generator::exportFormats() const
{
return false;
return ExportFormat::List();
}
bool Generator::exportToText( const QString& )
{
return false;
}
QList<ExportEntry*> Generator::exportFormats() const
{
return QList<ExportEntry*>();
}
bool Generator::exportTo( const QString&, const KMimeType::Ptr& )
bool Generator::exportTo( const QString&, const ExportFormat& )
{
return false;
}
@ -153,29 +156,174 @@ bool Generator::handleEvent( QEvent* )
void Generator::setDocument( Document *document )
{
m_document = document;
d->m_document = document;
}
void Generator::signalRequestDone( PixmapRequest * request )
{
m_document->requestDone( request );
if ( d->m_document )
d->m_document->requestDone( request );
else
Q_ASSERT( !"No document set for generator in signalRequestDone!" );
}
Document * Generator::document() const
{
return m_document;
return d->m_document;
}
class PixmapRequest::Private
{
public:
int mId;
int mPageNumber;
int mWidth;
int mHeight;
int mPriority;
bool mAsynchronous;
Page *mPage;
};
PixmapRequest::PixmapRequest( int id, int pageNumber, int width, int height, int priority, bool asynchronous )
: d( new Private )
{
d->mId = id;
d->mPageNumber = pageNumber;
d->mWidth = width;
d->mHeight = height;
d->mPriority = priority;
d->mAsynchronous = asynchronous;
}
PixmapRequest::~PixmapRequest()
{
delete d;
}
int PixmapRequest::id() const
{
return d->mId;
}
int PixmapRequest::pageNumber() const
{
return d->mPageNumber;
}
int PixmapRequest::width() const
{
return d->mWidth;
}
int PixmapRequest::height() const
{
return d->mHeight;
}
int PixmapRequest::priority() const
{
return d->mPriority;
}
bool PixmapRequest::asynchronous() const
{
return d->mAsynchronous;
}
Page* PixmapRequest::page() const
{
return d->mPage;
}
void PixmapRequest::setPriority( int priority )
{
d->mPriority = priority;
}
void PixmapRequest::setAsynchronous( bool asynchronous )
{
d->mAsynchronous = asynchronous;
}
void PixmapRequest::setPage( Page *page )
{
d->mPage = page;
}
class ExportFormat::Private
{
public:
Private( const QString &description, const KMimeType::Ptr &mimeType, const KIcon &icon = KIcon() )
: mDescription( description ), mMimeType( mimeType ), mIcon( icon )
{
}
QString mDescription;
KMimeType::Ptr mMimeType;
KIcon mIcon;
};
ExportFormat::ExportFormat()
: d( new Private( QString(), KMimeType::Ptr() ) )
{
}
ExportFormat::ExportFormat( const QString &description, const KMimeType::Ptr &mimeType )
: d( new Private( description, mimeType ) )
{
}
ExportFormat::ExportFormat( const KIcon &icon, const QString &description, const KMimeType::Ptr &mimeType )
: d( new Private( description, mimeType, icon ) )
{
}
ExportFormat::~ExportFormat()
{
delete d;
}
ExportFormat::ExportFormat( const ExportFormat &other )
: d( new Private( QString(), KMimeType::Ptr() ) )
{
*d = *other.d;
}
ExportFormat& ExportFormat::operator=( const ExportFormat &other )
{
if ( this == &other )
return *this;
*d = *other.d;
return *this;
}
QString ExportFormat::description() const
{
return d->mDescription;
}
KMimeType::Ptr ExportFormat::mimeType() const
{
return d->mMimeType;
}
KIcon ExportFormat::icon() const
{
return d->mIcon;
}
kdbgstream& operator<<( kdbgstream &str, const Okular::PixmapRequest &req )
{
QString s = QString( "%1 PixmapRequest (id: %2) (%3x%4), prio %5, pageNo %6" )
.arg( QString( req.async ? "Async" : "Sync" ) )
.arg( req.id )
.arg( req.width )
.arg( req.height )
.arg( req.priority )
.arg( req.pageNumber );
.arg( QString( req.asynchronous() ? "Async" : "Sync" ) )
.arg( req.id() )
.arg( req.width() )
.arg( req.height() )
.arg( req.priority() )
.arg( req.pageNumber() );
str << s;
return str;
}

View file

@ -29,12 +29,12 @@
#include "document.h"
class KConfigDialog;
class KIcon;
class KPrinter;
class kdbgstream;
namespace Okular {
class ExportEntry;
class Link;
class Page;
class PixmapRequest;
@ -50,6 +50,68 @@ class TextPage;
* (even for sync or async queries) has been done.
*/
/**
* @short Defines an entry for the export menu
*
* This class encapsulates information about an export format.
* Every Generator can support 0 ore more export formats which can be
* queried with @see Generator::exportFormats().
*/
class OKULAR_EXPORT ExportFormat
{
public:
typedef QList<ExportFormat> List;
/**
* Creates an empty export format.
*/
ExportFormat();
/**
* Creates a new export format.
*
* @param description The i18n'ed description of the format.
* @param mimeType The supported mime type of the format.
*/
ExportFormat( const QString &description, const KMimeType::Ptr &mimeType );
/**
* Creates a new export format.
*
* @param icon The icon used in the GUI for this format.
* @param description The i18n'ed description of the format.
* @param mimeType The supported mime type of the format.
*/
ExportFormat( const KIcon &icon, const QString &description, const KMimeType::Ptr &mimeType );
/**
* Destroys the export format.
*/
~ExportFormat();
ExportFormat( const ExportFormat &other );
ExportFormat& operator=( const ExportFormat &other );
/**
* Returns the description of the format.
*/
QString description() const;
/**
* Returns the mime type of the format.
*/
KMimeType::Ptr mimeType() const;
/**
* Returns the icon for GUI representations of the format.
*/
KIcon icon() const;
private:
class Private;
Private* const d;
};
/**
* @short [Abstract Class] The information generator.
*
@ -70,7 +132,6 @@ class OKULAR_EXPORT Generator : public QObject
*/
Generator();
/**
* Destroys the generator.
*/
@ -237,27 +298,16 @@ class OKULAR_EXPORT Generator : public QObject
*/
virtual void addPages( KConfigDialog *dialog );
/**
* Returns whether the generator can export the document to text format.
*/
virtual bool canExportToText() const;
/**
* This method is called to export the document as text format and save it
* under the given @p fileName.
*/
virtual bool exportToText( const QString &fileName );
/**
* Returns the list of additional supported export formats.
*/
virtual QList<ExportEntry*> exportFormats() const;
virtual ExportFormat::List exportFormats() const;
/**
* This method is called to export the document in the given @p mimeType and save it
* under the given @p fileName. The mime type must be one of the supported export formats.
* This method is called to export the document in the given @p format and save it
* under the given @p fileName. The format must be one of the supported export formats.
*/
virtual bool exportTo( const QString &fileName, const KMimeType::Ptr &mimeType );
virtual bool exportTo( const QString &fileName, const ExportFormat &format );
// TODO: remove
virtual bool handleEvent (QEvent * /*event*/ );
@ -300,58 +350,96 @@ class OKULAR_EXPORT Generator : public QObject
Document * document() const;
private:
/**
* The internal pointer to the document.
*/
Document * m_document;
class Private;
Private* const d;
};
/**
* @short Describes a pixmap type request.
*/
struct OKULAR_EXPORT PixmapRequest
class OKULAR_EXPORT PixmapRequest
{
PixmapRequest( int rId, int n, int w, int h, /*double z,*/ int p, bool a )
: id( rId ), pageNumber( n ), width( w ), height( h ), /*zoom(z),*/
priority( p ), async( a ), page( 0 ) {};
friend class Document;
PixmapRequest() {;};
// observer id
int id;
// page number and size
int pageNumber;
int width;
int height;
// double zoom;
// asyncronous request priority (less is better, 0 is max)
int priority;
// generate the pixmap in a thread and notify observer when done
bool async;
public:
/**
* Creates a new pixmap request.
*
* @param id The observer id.
* @param pageNumber The page number.
* @param width The width of the page.
* @param height The height of the page.
* @param priority The priority of the request.
* @param asynchronous The mode of generation.
*/
PixmapRequest( int id, int pageNumber, int width, int height, int priority, bool asynchronous );
// these fields are set by the Document prior passing the
// request to the generator
int documentRotation;
Page * page;
/**
* Destroys the pixmap request.
*/
~PixmapRequest();
};
/**
* Returns the observer id of the request.
*/
int id() const;
/**
* @short Defines an entry for the export menu
*/
struct OKULAR_EXPORT ExportEntry
{
ExportEntry( const QString & desc, const KMimeType::Ptr & _mime )
: description( desc ), mime( _mime ) {};
/**
* Returns the page number of the request.
*/
int pageNumber() const;
ExportEntry( const QString & _icon, const QString & desc, const KMimeType::Ptr & _mime )
: description( desc ), mime( _mime ), icon( _icon ) {};
/**
* Returns the page width of the requested pixmap.
*/
int width() const;
// the description to be shown in the Export menu
QString description;
// the mime associated
KMimeType::Ptr mime;
// the icon to be shown in the menu item
QString icon;
/**
* Returns the page height of the requested pixmap.
*/
int height() const;
/**
* Returns the priority (less it better, 0 is maximum) of the
* request.
*/
int priority() const;
/**
* Returns whether the generation should be done synchronous or
* asynchronous.
*
* If asynchronous, the pixmap is created in a thread and the observer
* is notified when the job is done.
*/
bool asynchronous() const;
/**
* Returns a pointer to the page where the pixmap shall be generated for.
*/
Page *page() const;
protected:
/**
* Internal usage.
*/
void setPriority( int priority );
/**
* Internal usage.
*/
void setAsynchronous( bool asynchronous );
/**
* Internal usage.
*/
void setPage( Page *page );
private:
Q_DISABLE_COPY( PixmapRequest )
class Private;
Private* const d;
};
}

View file

@ -43,6 +43,14 @@ static void deleteObjectRects( QLinkedList< ObjectRect * >& rects, const QSet<Ob
++it;
}
static QPixmap rotatedPixmap( const QImage &image, int rotation )
{
QMatrix matrix;
matrix.rotate( rotation * 90 );
return QPixmap::fromImage( image.transformed( matrix ) );
}
/** class Page **/
Page::Page( uint page, double w, double h, int o )
@ -179,6 +187,16 @@ void Page::rotateAt( int orientation )
qSwap( m_width, m_height );
m_rotation = neworientation;
QMapIterator< int, QImage> it( m_images );
while ( it.hasNext() ) {
it.next();
if ( m_pixmaps.contains( it.key() ) )
delete m_pixmaps[ it.key() ];
m_pixmaps[ it.key() ] = new QPixmap( rotatedPixmap( it.value(), m_rotation ) );
}
}
const ObjectRect * Page::getObjectRect( ObjectRect::ObjectType type, double x, double y, double xScale, double yScale ) const
@ -212,9 +230,25 @@ const Link * Page::getPageAction( PageAction act ) const
void Page::setPixmap( int id, QPixmap * pixmap )
{
const QImage image = pixmap->toImage();
delete pixmap;
setImage( id, image );
/*
if ( m_pixmaps.contains( id ) )
delete m_pixmaps[id];
m_pixmaps[id] = pixmap;
*/
}
void Page::setImage( int id, const QImage &image )
{
m_images[ id ] = image;
if ( m_pixmaps.contains( id ) )
delete m_pixmaps[ id ];
m_pixmaps[ id ] = new QPixmap( rotatedPixmap( image, m_rotation ) );
}
void Page::setSearchPage( TextPage * tp )

View file

@ -12,6 +12,8 @@
#include <QtCore/QLinkedList>
#include <QtCore/QMap>
#include <QtGui/QImage>
#include <QtGui/QPixmap>
#include "area.h"
#include "okular_export.h"
@ -19,7 +21,6 @@
class QDomDocument;
class QDomNode;
class QPixmap;
class QRect;
class PagePainter;
@ -88,6 +89,7 @@ class OKULAR_EXPORT Page
// operations: set contents (by Document)
void setPixmap( int p_id, QPixmap * pixmap );
void setImage( int p_id, const QImage &image );
void setSearchPage( TextPage * text );
void setBookmark( bool state );
void setObjectRects( const QLinkedList< ObjectRect * > rects );
@ -118,6 +120,7 @@ class OKULAR_EXPORT Page
bool m_bookmarked;
int m_maxuniqueNum;
QMap< int, QImage > m_images;
QMap< int, QPixmap * > m_pixmaps;
TextPage * m_text;
QLinkedList< ObjectRect * > m_rects;

View file

@ -102,10 +102,10 @@ void CHMGenerator::slotCompleted()
else if (m_state==1)
{
// kDebug() << "completed(1) " << m_request->id << endl;
QPixmap* pix=new QPixmap (m_request->width,m_request->height);
QPixmap* pix=new QPixmap (m_request->width(),m_request->height());
pix->fill();
QPainter p (pix);
QRect r(0,0,m_request->width,m_request->height);
QRect r(0,0,m_request->width(),m_request->height());
bool moreToPaint;
// m_syncGen->view()->layout();
m_syncGen->paint(&p, r,0,&moreToPaint);
@ -113,14 +113,14 @@ void CHMGenerator::slotCompleted()
if (m_pixmapRequestZoom>1)
{
QPixmap* newpix=new QPixmap();
*newpix=pix->scaled(m_request->width/m_pixmapRequestZoom, m_request->height/m_pixmapRequestZoom);
*newpix=pix->scaled(m_request->width()/m_pixmapRequestZoom, m_request->height()/m_pixmapRequestZoom);
delete pix;
pix=newpix;
m_pixmapRequestZoom=1;
}
additionalRequestData();
syncLock.unlock();
m_request->page->setPixmap( m_request->id, pix );
m_request->page()->setPixmap( m_request->id(), pix );
signalRequestDone( m_request );
}
}
@ -162,30 +162,32 @@ bool CHMGenerator::canGeneratePixmap ( bool /*async*/ ) const
void CHMGenerator::generatePixmap( Okular::PixmapRequest * request )
{
QString a="S";
if (request->async) a="As";
if (request->asynchronous()) a="As";
kDebug() << a << "ync PixmapRequest of " << request->width << "x"
<< request->height << " size, pageNo " << request->pageNumber
<< ", priority: " << request->priority << " id: " << request->id
kDebug() << a << "ync PixmapRequest of " << request->width() << "x"
<< request->height() << " size, pageNo " << request->pageNumber()
<< ", priority: " << request->priority() << " id: " << request->id()
<< endl;
if (request->width<300)
int requestWidth = request->width();
int requestHeight = request->height();
if (requestWidth<300)
{
m_pixmapRequestZoom=900/request->width;
request->width*=m_pixmapRequestZoom;
request->height*=m_pixmapRequestZoom;
m_pixmapRequestZoom=900/requestWidth;
requestWidth*=m_pixmapRequestZoom;
requestHeight*=m_pixmapRequestZoom;
}
syncLock.lock();
QString url= m_file->getUrlForPage ( request->pageNumber + 1 );
int zoom = qMax( static_cast<double>(request->width)/static_cast<double>(request->page->width())
, static_cast<double>(request->height)/static_cast<double>(request->page->height())
) * 100;
QString url= m_file->getUrlForPage ( request->pageNumber() + 1 );
int zoom = qRound( qMax( static_cast<double>(requestWidth)/static_cast<double>(request->page()->width())
, static_cast<double>(requestHeight)/static_cast<double>(request->page()->height())
) ) * 100;
KUrl pAddress= "ms-its:" + m_fileName + "::" + url;
kDebug() << "Page asked is: " << pAddress << " zoom is " << zoom << endl;
m_syncGen->setZoomFactor(zoom);
m_syncGen->view()->resize(request->width,request->height);
m_syncGen->view()->resize(requestWidth,requestHeight);
m_request=request;
m_state=1;
// will emit openURL without problems
@ -265,9 +267,9 @@ void CHMGenerator::recursiveExploreNodes(DOM::Node node,Okular::TextPage *tp)
void CHMGenerator::additionalRequestData()
{
Okular::Page * page=m_request->page;
bool genObjectRects = m_request->id & (PAGEVIEW_ID | PRESENTATION_ID);
bool genTextPage = !m_request->page->hasSearchPage() && genObjectRects;
Okular::Page * page=m_request->page();
bool genObjectRects = m_request->id() & (PAGEVIEW_ID | PRESENTATION_ID);
bool genTextPage = !m_request->page()->hasSearchPage() && genObjectRects;
if (genObjectRects || genTextPage )
{
@ -277,8 +279,8 @@ void CHMGenerator::additionalRequestData()
{
kDebug() << "Generating ObjRects - start" << endl;
QLinkedList< Okular::ObjectRect * > objRects;
int xScale=m_request->width;
int yScale=m_request->height;
int xScale=m_request->width();
int yScale=m_request->height();
// getting links
DOM::HTMLCollection coll=domDoc.links();
DOM::Node n;
@ -336,7 +338,7 @@ void CHMGenerator::additionalRequestData()
}
}
}
m_request->page->setObjectRects( objRects );
m_request->page()->setObjectRects( objRects );
}
if ( genTextPage )
@ -358,8 +360,8 @@ void CHMGenerator::generateSyncTextPage( Okular::Page * page )
{
syncLock.lock();
double zoomP=Okular::Settings::zoomFactor();
int zoom = zoomP * 100;
m_syncGen->view()->resize(page->width() * zoomP , page->height() * zoomP);
int zoom = qRound( zoomP * 100 );
m_syncGen->view()->resize(qRound( page->width() * zoomP ) , qRound( page->height() * zoomP ));
preparePageForSyncOperation(zoom, m_file->getUrlForPage ( page->number() + 1 ));
Okular::TextPage *tp=new Okular::TextPage();
recursiveExploreNodes( m_syncGen->htmlDocument(), tp);

View file

@ -95,15 +95,15 @@ void DjVuGenerator::generatePixmap( Okular::PixmapRequest * request )
m_request = request;
QPixmap pix = m_djvu->pixmap( request->pageNumber, request->width, request->height, request->documentRotation );
QPixmap pix = m_djvu->pixmap( request->pageNumber(), request->width(), request->height(), 0 );
if ( pix.isNull() )
{
m_djvu->requestPixmap( request->pageNumber, request->width, request->height, request->documentRotation );
m_djvu->requestPixmap( request->pageNumber(), request->width(), request->height(), 0 );
}
else
{
djvuPixmapGenerated( request->pageNumber, pix );
djvuPixmapGenerated( request->pageNumber(), pix );
}
}
@ -150,7 +150,7 @@ const Okular::DocumentSynopsis * DjVuGenerator::generateDocumentSynopsis()
void DjVuGenerator::djvuPixmapGenerated( int page, const QPixmap & pix )
{
m_request->page->setPixmap( m_request->id, new QPixmap( pix ) );
m_request->page()->setPixmap( m_request->id(), new QPixmap( pix ) );
QList<KDjVu::Link*> links = m_djvu->linksForPage( page );
if ( links.count() > 0 )
@ -198,7 +198,7 @@ void DjVuGenerator::djvuPixmapGenerated( int page, const QPixmap & pix )
const KDjVu::Page* p = m_djvu->pages().at( newpage == -1 ? page : newpage );
int width = p->width();
int height = p->height();
bool scape_orientation = ( m_request->documentRotation % 2 == 1 );
bool scape_orientation = false; // hack by tokoe, should always create default page
if ( scape_orientation )
qSwap( width, height );
Okular::ObjectRect *newrect = 0;
@ -209,7 +209,7 @@ void DjVuGenerator::djvuPixmapGenerated( int page, const QPixmap & pix )
{
QRect r( QPoint( curlink->point().x(), p->height() - curlink->point().y() - curlink->size().height() ), curlink->size() );
bool ellipse = ( curlink->areaType() == KDjVu::Link::EllipseArea );
newrect = new Okular::ObjectRect( Okular::NormalizedRect( Okular::Utils::rotateRect( r, width, height, m_request->documentRotation ), width, height ), ellipse, Okular::ObjectRect::Link, newlink );
newrect = new Okular::ObjectRect( Okular::NormalizedRect( Okular::Utils::rotateRect( r, width, height, 0 ), width, height ), ellipse, Okular::ObjectRect::Link, newlink );
break;
}
case KDjVu::Link::PolygonArea:
@ -246,7 +246,7 @@ void DjVuGenerator::djvuPixmapGenerated( int page, const QPixmap & pix )
delete curlink;
}
if ( rects.count() > 0 )
m_request->page->setObjectRects( rects );
m_request->page()->setObjectRects( rects );
}
ready = true;

View file

@ -186,10 +186,10 @@ void DviGenerator::generatePixmap( Okular::PixmapRequest *request )
dviPageInfo *pageInfo = new dviPageInfo();
pageSize ps;
rotateCoordinates( request->width, request->height,
pageInfo->width, pageInfo->height, request->documentRotation );
rotateCoordinates( request->width(), request->height(),
pageInfo->width, pageInfo->height, 0 );
pageInfo->pageNumber = request->pageNumber + 1;
pageInfo->pageNumber = request->pageNumber() + 1;
// pageInfo->resolution = m_resolution;
@ -221,16 +221,12 @@ void DviGenerator::generatePixmap( Okular::PixmapRequest *request )
{
kDebug() << "Image OK" << endl;
if ( request->documentRotation > 0 )
pageInfo->img = KImageEffect::rotate( pageInfo->img,
(KImageEffect::RotateDirection)( request->documentRotation - 1 ) );
QPixmap *tmpPx = new QPixmap();
*tmpPx = QPixmap::fromImage( pageInfo->img );
request->page->setPixmap( request->id, tmpPx );
request->page()->setPixmap( request->id(), tmpPx );
request->page->setObjectRects(
generateDviLinks( pageInfo, request->documentRotation ) );
request->page()->setObjectRects(
generateDviLinks( pageInfo, 0 ) );
}
}

View file

@ -228,20 +228,20 @@ bool GSGenerator::closeDocument()
void GSGenerator::slotPixmapGenerated(const QImage* img)
{
kWarning() << "SlotSyncGenerated! - finished m_sRequest id=" << m_sRequest->id << " " <<m_sRequest->width << "x" << m_sRequest->height << "@" << m_sRequest->pageNumber << " async == " << m_sRequest->async << endl;
kWarning() << "SlotSyncGenerated! - finished m_sRequest id=" << m_sRequest->id() << " " <<m_sRequest->width() << "x" << m_sRequest->height() << "@" << m_sRequest->pageNumber() << " async == " << m_sRequest->asynchronous() << endl;
// kWarning() << "sync gen is ready:" << pixGenerator->ready() << endl;
QPixmap * rPix = new QPixmap();
*rPix = QPixmap::fromImage( *img );
kWarning() << "unlocking \n";
syncLock.unlock();
m_sRequest->page->setPixmap( m_sRequest->id, rPix );
m_sRequest->page()->setPixmap( m_sRequest->id(), rPix );
signalRequestDone( m_sRequest );
}
void GSGenerator::slotAsyncPixmapGenerated(QPixmap * pix)
{
kWarning() << "SlotASyncGenerated!\n";
m_asRequest->page->setPixmap( m_asRequest->id, pix );
m_asRequest->page()->setPixmap( m_asRequest->id(), pix );
signalRequestDone( m_asRequest );
docLock.unlock();
}
@ -363,9 +363,9 @@ bool GSGenerator::loadDocumentWithDSC( const QString & name, QVector< Okular::Pa
void GSGenerator::generatePixmap( Okular::PixmapRequest * req )
{
kWarning() << "receiving req id=" << req->id << " " <<req->width << "x" << req->height << "@" << req->pageNumber << " async == " << req->async << endl;
int pgNo=req->pageNumber;
if ( req->async )
kWarning() << "receiving req id=" << req->id() << " " <<req->width() << "x" << req->height() << "@" << req->pageNumber() << " async == " << req->asynchronous() << endl;
int pgNo=req->pageNumber();
if ( req->asynchronous() )
{
docLock.lock();
m_asRequest=req;
@ -373,12 +373,12 @@ void GSGenerator::generatePixmap( Okular::PixmapRequest * req )
asyncGenerator->setOrientation(rotation (internalDoc->orientation(pgNo)));
// asyncGenerator->setBoundingBox( internalDoc->boundingBox(i));
kWarning() << "setSize\n";
asyncGenerator->setSize(req->width ,req->height);
asyncGenerator->setSize(req->width() ,req->height());
kWarning() << "setMedia\n";
asyncGenerator->setMedia( internalDoc -> getPaperSize ( internalDoc -> pageMedia( pgNo )) );
kWarning() << "setMagnify\n";
asyncGenerator->setMagnify(qMax(static_cast<double>(req->width)/req->page->width() ,
static_cast<double>(req->height)/req->page->height()));
asyncGenerator->setMagnify(qMax(static_cast<double>(req->width())/req->page()->width() ,
static_cast<double>(req->height())/req->page()->height()));
GSInterpreterLib::Position u=internalDoc->pagePos(pgNo);
// kWarning () << "Page pos is " << pgNo << ":"<< u.first << "/" << u.second << endl;
if (!asyncGenerator->interpreterRunning())
@ -405,10 +405,10 @@ void GSGenerator::generatePixmap( Okular::PixmapRequest * req )
// this, SLOT(slotPixmapGenerated (const QImage*)));
pixGenerator->setMedia( internalDoc -> getPaperSize ( internalDoc -> pageMedia( pgNo )) );
pixGenerator->setMagnify(qMax(static_cast<double>(req->width)/req->page->width() ,
static_cast<double>(req->height)/req->page->height()));
pixGenerator->setMagnify(qMax(static_cast<double>(req->width())/req->page()->width() ,
static_cast<double>(req->height())/req->page()->height()));
pixGenerator->setOrientation(rotation (internalDoc->orientation(pgNo)));
pixGenerator->setSize(req->width ,req->height);
pixGenerator->setSize(req->width() ,req->height());
// pixGenerator->setBoundingBox( internalDoc->boundingBox(i));
@ -420,7 +420,7 @@ void GSGenerator::generatePixmap( Okular::PixmapRequest * req )
/* connect (pixGenerator, SIGNAL (Finished(const QImage*)),
this, SLOT(slotPixmapGenerated (const QImage*)));*/
this->m_sRequest=req;
kWarning() << "checking req id=" << req->id << " " <<req->width << "x" << req->height << "@" << req->pageNumber << " async == " << req->async << endl;
kWarning() << "checking req id=" << req->id() << " " <<req->width() << "x" << req->height() << "@" << req->pageNumber() << " async == " << req->asynchronous() << endl;
kWarning() << "generator running : " << pixGenerator->running() << endl;
pixGenerator->run ( internalDoc->file() , internalDoc->pagePos(pgNo),true);

View file

@ -54,15 +54,15 @@ bool KIMGIOGenerator::canGeneratePixmap( bool /* async */ ) const
void KIMGIOGenerator::generatePixmap( Okular::PixmapRequest * request )
{
// perform a smooth scaled generation
QImage smoothImage = m_pix->toImage().scaled( request->width, request->height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
QImage smoothImage = m_pix->toImage().scaled( request->width(), request->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
// rotate, if necessary
int rotation = request->page->rotation();
int rotation = request->page()->rotation();
QImage finalImage = rotation > 0
? KImageEffect::rotate( smoothImage, (KImageEffect::RotateDirection)( rotation - 1 ) )
: smoothImage;
QPixmap * p = new QPixmap();
*p = QPixmap::fromImage( finalImage );
request->page->setPixmap(request->id, p);
request->page()->setPixmap(request->id(), p);
// signal that the request has been accomplished
signalRequestDone(request);

View file

@ -86,64 +86,42 @@ void KOOOGenerator::generatePixmap( Okular::PixmapRequest * request )
{
const QSize size = mDocument->pageSize().toSize();
QPixmap *pm = new QPixmap( request->width, request->height );
QPixmap *pm = new QPixmap( request->width(), request->height() );
pm->fill( Qt::white );
QPainter p;
p.begin( pm );
qreal width = request->width;
qreal height = request->height;
if ( request->documentRotation % 2 == 1 )
qSwap( width, height );
switch ( request->documentRotation ) {
case 0:
default:
break;
case 1:
p.rotate( 90 );
p.translate( QPoint( 0, qRound(-size.height() * (height / (qreal)size.height())) ) );
break;
case 2:
p.rotate( 180 );
p.translate( QPoint( qRound(-size.width() * (width / (qreal)size.width())),
qRound(-size.height() * (height / (qreal)size.height())) ) );
break;
case 3:
p.rotate( 270 );
p.translate( QPoint( qRound(-size.width() * (width / (qreal)size.width())), 0 ) );
break;
}
qreal width = request->width();
qreal height = request->height();
p.scale( width / (qreal)size.width(), height / (qreal)size.height() );
QRect rect;
rect = QRect( 0, request->pageNumber * size.height(), size.width(), size.height() );
p.translate( QPoint( 0, request->pageNumber * size.height() * -1 ) );
rect = QRect( 0, request->pageNumber() * size.height(), size.width(), size.height() );
p.translate( QPoint( 0, request->pageNumber() * size.height() * -1 ) );
mDocument->drawContents( &p, rect );
p.end();
request->page->setPixmap( request->id, pm );
request->page()->setPixmap( request->id(), pm );
/**
* Add link information
*/
QLinkedList<Okular::ObjectRect*> objects;
for ( int i = 0; i < mLinks.count(); ++i ) {
if ( mLinks[ i ].page == request->pageNumber ) {
if ( mLinks[ i ].page == request->pageNumber() ) {
const QRectF rect = mLinks[ i ].boundingRect;
double x = rect.x() / request->width;
double y = rect.y() / request->height;
double w = rect.width() / request->width;
double h = rect.height() / request->height;
double x = rect.x() / request->width();
double y = rect.y() / request->height();
double w = rect.width() / request->width();
double h = rect.height() / request->height();
objects.append( new Okular::ObjectRect( x, y, w, h, false,
Okular::ObjectRect::Link, new Okular::LinkBrowse( mLinks[ i ].url ) ) );
}
}
request->page->setObjectRects( objects );
request->page()->setObjectRects( objects );
signalRequestDone( request );
}

View file

@ -563,7 +563,7 @@ void PDFGenerator::generatePixmap( Okular::PixmapRequest * request )
//kDebug() << "id: " << request->id << " is requesting " << (request->async ? "ASYNC" : "sync") << " pixmap for page " << request->page->number() << " [" << request->width << " x " << request->height << "]." << endl;
/** asynchronous requests (generation in PDFPixmapGeneratorThread::run() **/
if ( request->async )
if ( request->asynchronous() )
{
// start the generation into the thread
generatorThread->startGeneration( request );
@ -572,16 +572,16 @@ void PDFGenerator::generatePixmap( Okular::PixmapRequest * request )
/** synchronous request: in-place generation **/
// compute dpi used to get an image with desired width and height
Okular::Page * page = request->page;
double fakeDpiX = request->width * 72.0 / page->width(),
fakeDpiY = request->height * 72.0 / page->height();
Okular::Page * page = request->page();
double fakeDpiX = request->width() * 72.0 / page->width(),
fakeDpiY = request->height() * 72.0 / page->height();
// setup Okular:: output device: text page is generated only if we are at 72dpi.
// since we can pre-generate the TextPage at the right res.. why not?
bool genTextPage = !page->hasSearchPage() && (request->width == page->width()) &&
(request->height == page->height());
bool genTextPage = !page->hasSearchPage() && (request->width() == page->width()) &&
(request->height() == page->height());
// generate links and image rects if rendering pages on pageview
bool genObjectRects = request->id & (PAGEVIEW_ID | PRESENTATION_ID);
bool genObjectRects = request->id() & (PAGEVIEW_ID | PRESENTATION_ID);
// 0. LOCK [waits for the thread end]
docLock.lock();
@ -591,22 +591,22 @@ void PDFGenerator::generatePixmap( Okular::PixmapRequest * request )
Poppler::Page *p = pdfdoc->page(page->number());
// 2. Take data from outputdev and attach it to the Page
page->setPixmap( request->id, p->splashRenderToPixmap(fakeDpiX, fakeDpiY, -1, -1, -1, -1, genObjectRects, (Poppler::Page::Rotation)document()->rotation()) );
page->setPixmap( request->id(), p->splashRenderToPixmap(fakeDpiX, fakeDpiY, -1, -1, -1, -1, genObjectRects, (Poppler::Page::Rotation)document()->rotation()) );
if ( genObjectRects )
{
// TODO previously we extracted Image type rects too, but that needed porting to poppler
// and as we are not doing anything with Image type rects i did not port it, have a look at
// dead gp_outputdev.cpp on image extraction
page->setObjectRects( generateLinks(p->links(), request->width, request->height, pdfdoc) );
page->setObjectRects( generateLinks(p->links(), request->width(), request->height(), pdfdoc) );
}
// 3. UNLOCK [re-enables shared access]
docLock.unlock();
if ( genTextPage )
{
QList<Poppler::TextBox*> textList = p->textList((Poppler::Page::Rotation)request->page->rotation());
page->setSearchPage( abstractTextPage(textList, page->height(), page->width(), request->page->totalOrientation()) );
QList<Poppler::TextBox*> textList = p->textList((Poppler::Page::Rotation)request->page()->rotation());
page->setSearchPage( abstractTextPage(textList, page->height(), page->width(), request->page()->totalOrientation()) );
qDeleteAll(textList);
}
delete p;
@ -738,26 +738,40 @@ bool PDFGenerator::reparseConfig()
return false;
}
bool PDFGenerator::exportToText( const QString & fileName )
Okular::ExportFormat::List PDFGenerator::exportFormats() const
{
QFile f( fileName );
if ( !f.open( QIODevice::WriteOnly ) )
return false;
QTextStream ts( &f );
int num = document()->pages();
for ( int i = 0; i < num; ++i )
{
docLock.lock();
Poppler::Page *pp = pdfdoc->page(i);
QString text = pp->text(QRect());
docLock.unlock();
ts << text;
delete pp;
static Okular::ExportFormat::List formats;
if ( formats.isEmpty() ) {
formats.append( Okular::ExportFormat( i18n( "Plain Text" ), KMimeType::mimeType( "text/plain" ) ) );
}
f.close();
return true;
return formats;
}
bool PDFGenerator::exportTo( const QString &fileName, const Okular::ExportFormat &format )
{
if ( format.mimeType()->name() == QLatin1String( "text/plain" ) ) {
QFile f( fileName );
if ( !f.open( QIODevice::WriteOnly ) )
return false;
QTextStream ts( &f );
int num = document()->pages();
for ( int i = 0; i < num; ++i )
{
docLock.lock();
Poppler::Page *pp = pdfdoc->page(i);
QString text = pp->text(QRect());
docLock.unlock();
ts << text;
delete pp;
}
f.close();
return true;
}
return false;
}
//END Generator inherited functions
@ -1093,16 +1107,16 @@ void PDFGenerator::threadFinished()
QPixmap * newpix = new QPixmap();
*newpix = QPixmap::fromImage( *outImage );
request->page->setPixmap( request->id, newpix );
request->page()->setPixmap( request->id(), newpix );
delete outImage;
if ( !outText.isEmpty() )
{
request->page->setSearchPage( abstractTextPage( outText ,
request->page->height(), request->page->width(),request->page->totalOrientation()));
request->page()->setSearchPage( abstractTextPage( outText ,
request->page()->height(), request->page()->width(),request->page()->totalOrientation()));
qDeleteAll(outText);
}
bool genObjectRects = request->id & (PAGEVIEW_ID | PRESENTATION_ID);
if (genObjectRects) request->page->setObjectRects( outRects );
bool genObjectRects = request->id() & (PAGEVIEW_ID | PRESENTATION_ID);
if (genObjectRects) request->page()->setObjectRects( outRects );
// 3. tell generator that data has been taken
generatorThread->endGeneration();
@ -1230,9 +1244,9 @@ void PDFPixmapGeneratorThread::run()
// @see PDFGenerator::generatePixmap( .. ) (and be aware to sync the code)
{
// compute dpi used to get an image with desired width and height
Okular::Page * page = d->currentRequest->page;
int width = d->currentRequest->width,
height = d->currentRequest->height;
Okular::Page * page = d->currentRequest->page();
int width = d->currentRequest->width(),
height = d->currentRequest->height();
double fakeDpiX = width * 72.0 / page->width(),
fakeDpiY = height * 72.0 / page->height();
@ -1243,7 +1257,7 @@ void PDFPixmapGeneratorThread::run()
( height == page->height() );
// generate links and image rects if rendering pages on pageview
bool genObjectRects = d->currentRequest->id & (PAGEVIEW_ID | PRESENTATION_ID);
bool genObjectRects = d->currentRequest->id() & (PAGEVIEW_ID | PRESENTATION_ID);
// 0. LOCK s[tart locking XPDF thread unsafe classes]
d->generator->docLock.lock();
@ -1258,7 +1272,7 @@ void PDFPixmapGeneratorThread::run()
if ( !d->m_textList.isEmpty() )
kDebug() << "PDFPixmapGeneratorThread: previous text not taken" << endl;
#endif
d->m_image = new QImage( pp->splashRenderToImage( fakeDpiX, fakeDpiY, -1, -1, -1, -1, genObjectRects, (Poppler::Page::Rotation)d->currentRequest->documentRotation ) );
d->m_image = new QImage( pp->splashRenderToImage( fakeDpiX, fakeDpiY, -1, -1, -1, -1, genObjectRects, (Poppler::Page::Rotation)0 ) );
if ( genObjectRects )
{
@ -1268,7 +1282,7 @@ void PDFPixmapGeneratorThread::run()
if ( genTextPage )
{
d->m_textList = pp->textList((Poppler::Page::Rotation)d->currentRequest->page->rotation());
d->m_textList = pp->textList((Poppler::Page::Rotation)d->currentRequest->page()->rotation());
}
delete pp;

View file

@ -84,8 +84,8 @@ class PDFGenerator : public Okular::Generator
bool reparseConfig();
// [INHERITED] text exporting
bool canExportToText() const { return true; };
bool exportToText( const QString & fileName );
Okular::ExportFormat::List exportFormats() const;
bool exportTo( const QString &fileName, const Okular::ExportFormat &format );
private slots:
// (async related) receive data from the generator thread
@ -94,16 +94,16 @@ class PDFGenerator : public Okular::Generator
private:
// friend class to access private document related variables
friend class PDFPixmapGeneratorThread;
// create the document synopsis hieracy
void addSynopsisChildren( QDomNode * parentSource, QDomNode * parentDestination );
// fetch annotations from the pdf file and add they to the page
void addAnnotations( Poppler::Page * popplerPage, Okular::Page * page );
// fetch the transition information and add it to the page
void addTransition( Poppler::Page * popplerPage, Okular::Page * page );
Okular::TextPage * abstractTextPage(const QList<Poppler::TextBox*> &text, double height, double width, int rot);
// poppler dependant stuff
mutable QMutex docLock;
Poppler::Document *pdfdoc;

View file

@ -85,13 +85,13 @@ QPixmap* TIFFGeneratorThread::takePixmap()
void TIFFGeneratorThread::run()
{
bool generated = false;
m_pix = new QPixmap( m_request->width, m_request->height );
m_pix = new QPixmap( m_request->width(), m_request->height() );
if ( TIFFSetDirectory( m_tiff, m_request->page->number() ) )
if ( TIFFSetDirectory( m_tiff, m_request->page()->number() ) )
{
int rotation = m_request->documentRotation;
uint32 width = (uint32)m_request->page->width();
uint32 height = (uint32)m_request->page->height();
int rotation = 0;
uint32 width = (uint32)m_request->page()->width();
uint32 height = (uint32)m_request->page()->height();
if ( rotation % 2 == 1 )
qSwap( width, height );
@ -110,8 +110,8 @@ void TIFFGeneratorThread::run()
data[i] = ( data[i] & 0xFF00FF00 ) + red + blue;
}
int reqwidth = m_request->width;
int reqheight = m_request->height;
int reqwidth = m_request->width();
int reqheight = m_request->height();
if ( rotation % 2 == 1 )
qSwap( reqwidth, reqheight );
QImage smoothImage = image.scaled( reqwidth, reqheight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
@ -202,20 +202,20 @@ void TIFFGenerator::generatePixmap( Okular::PixmapRequest * request )
{
ready = false;
if ( request->async )
if ( request->asynchronous() )
{
thread->startGeneration( request, d->tiff );
return;
}
bool generated = false;
QPixmap * p = new QPixmap( request->width, request->height );
QPixmap * p = new QPixmap( request->width(), request->height() );
if ( TIFFSetDirectory( d->tiff, request->page->number() ) )
if ( TIFFSetDirectory( d->tiff, request->page()->number() ) )
{
int rotation = request->documentRotation;
uint32 width = (uint32)request->page->width();
uint32 height = (uint32)request->page->height();
int rotation = 0;
uint32 width = (uint32)request->page()->width();
uint32 height = (uint32)request->page()->height();
if ( rotation % 2 == 1 )
qSwap( width, height );
@ -234,8 +234,8 @@ void TIFFGenerator::generatePixmap( Okular::PixmapRequest * request )
data[i] = ( data[i] & 0xFF00FF00 ) + red + blue;
}
int reqwidth = request->width;
int reqheight = request->height;
int reqwidth = request->width();
int reqheight = request->height();
if ( rotation % 2 == 1 )
qSwap( reqwidth, reqheight );
QImage smoothImage = image.scaled( reqwidth, reqheight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
@ -253,7 +253,7 @@ void TIFFGenerator::generatePixmap( Okular::PixmapRequest * request )
p->fill();
}
request->page->setPixmap( request->id, p );
request->page()->setPixmap( request->id(), p );
ready = true;
@ -302,7 +302,7 @@ void TIFFGenerator::slotThreadFinished()
Okular::PixmapRequest * request = thread->request();
thread->endGeneration();
request->page->setPixmap( request->id, thread->takePixmap() );
request->page()->setPixmap( request->id(), thread->takePixmap() );
ready = true;

View file

@ -653,13 +653,13 @@ bool XpsGenerator::canGeneratePixmap( bool /*async*/ ) const
void XpsGenerator::generatePixmap( Okular::PixmapRequest * request )
{
QSize size( (int)request->page->width(), (int)request->page->height() );
QSize size( (int)request->page()->width(), (int)request->page()->height() );
QPixmap * p = new QPixmap( size );
QImage image( size, QImage::Format_RGB32 );
XpsPage *pageToRender = m_xpsFile->page( request->page->number() );
XpsPage *pageToRender = m_xpsFile->page( request->page()->number() );
pageToRender->renderToImage( &image );
*p = QPixmap::fromImage( image );
request->page->setPixmap( request->id, p );
request->page()->setPixmap( request->id(), p );
#if 0
if ( TIFFSetDirectory( d->tiff, request->page->number() ) )
{

View file

@ -588,20 +588,20 @@ bool Part::openFile()
m_showPresentation->setEnabled( ok );
if ( ok )
{
m_exportItems = m_document->exportFormats();
QList<Okular::ExportEntry*>::ConstIterator it = m_exportItems.constBegin();
QList<Okular::ExportEntry*>::ConstIterator itEnd = m_exportItems.constEnd();
m_exportFormats = m_document->exportFormats();
QList<Okular::ExportFormat>::ConstIterator it = m_exportFormats.constBegin();
QList<Okular::ExportFormat>::ConstIterator itEnd = m_exportFormats.constEnd();
QMenu *menu = m_exportAs->menu();
for ( ; it != itEnd; ++it )
{
Okular::ExportEntry* cur = *it;
if ( !cur->icon.isEmpty() )
const Okular::ExportFormat &format = *it;
if ( !format.icon().isNull() )
{
menu->addAction( KIcon( cur->icon ), cur->description );
menu->addAction( format.icon(), format.description() );
}
else
{
menu->addAction( cur->description );
menu->addAction( format.description() );
}
}
}
@ -680,7 +680,7 @@ bool Part::closeUrl()
m_showProperties->setEnabled( false );
m_showEmbeddedFiles->setEnabled( false );
m_exportAsText->setEnabled( false );
m_exportItems.clear();
m_exportFormats.clear();
QMenu *menu = m_exportAs->menu();
QList<QAction*> acts = menu->actions();
int num = acts.count();
@ -1175,11 +1175,11 @@ void Part::slotExportAs(QAction * act)
if ( ( id < 0 ) || ( id >= acts.count() ) )
return;
QString filter = id == 0 ? "text/plain" : m_exportItems.at( id - 1 )->mime->name();
QString filter = id == 0 ? "text/plain" : m_exportFormats.at( id - 1 ).mimeType()->name();
QString fileName = KFileDialog::getSaveFileName( url().isLocalFile() ? url().fileName() : QString::null, filter, widget() );
if ( !fileName.isEmpty() )
{
bool saved = id == 0 ? m_document->exportToText( fileName ) : m_document->exportTo( fileName, m_exportItems.at( id - 1 )->mime );
bool saved = id == 0 ? m_document->exportToText( fileName ) : m_document->exportTo( fileName, m_exportFormats.at( id - 1 ) );
if ( !saved )
KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) );
}

4
part.h
View file

@ -53,7 +53,7 @@ class MiniBar;
namespace Okular {
class Document;
class ExportEntry;
class ExportFormat;
}
class BrowserExtension;
@ -210,7 +210,7 @@ private:
QStringList m_generatorsWithSettings;
QStringList m_supportedMimeTypes;
KSelectAction * m_confGens;
QList<Okular::ExportEntry*> m_exportItems;
QList<Okular::ExportFormat> m_exportFormats;
private slots:
void slotGeneratorPreferences();