Commit 455b535a authored by Pino Toscano's avatar Pino Toscano

Switch from the sync API to the async one.

Protected the potentially concurred methods using the user mutex.
Removed the manual 'ready' flag and the calculation of the bounding box, as both are done in the core.

This should avoid the block when rendering pages and extracting text from them, and reduce the "slow" feeling esp when invoking external Ghostscript.
BUG: 192284
CCBUG: 162643

svn path=/trunk/KDE/kdegraphics/okular/; revision=966599
parent e75b7654
......@@ -27,6 +27,7 @@
#include <qurl.h>
#include <qvector.h>
#include <qstack.h>
#include <qmutex.h>
#include <kaboutdata.h>
#include <kdebug.h>
......@@ -52,8 +53,9 @@ static KAboutData createAboutData()
OKULAR_EXPORT_PLUGIN( DviGenerator, createAboutData() )
DviGenerator::DviGenerator( QObject *parent, const QVariantList &args ) : Okular::Generator( parent, args ),
m_docInfo( 0 ), m_docSynopsis( 0 ), ready( false ), m_dviRenderer( 0 )
m_docInfo( 0 ), m_docSynopsis( 0 ), m_dviRenderer( 0 )
{
setFeature( Threaded );
setFeature( TextExtraction );
setFeature( PrintPostscript );
if ( Okular::FilePrinter::ps2pdfAvailable() )
......@@ -65,6 +67,8 @@ bool DviGenerator::loadDocument( const QString & fileName, QVector< Okular::Page
//kDebug(DviDebug) << "file:" << fileName;
KUrl base( fileName );
(void)userMutex();
m_dviRenderer = new dviRenderer();
if ( ! m_dviRenderer->setFile( fileName, base ) )
{
......@@ -80,7 +84,6 @@ bool DviGenerator::loadDocument( const QString & fileName, QVector< Okular::Page
m_resolution = Okular::Utils::dpiY();
loadPages( pagesVector );
ready = true;
return true;
}
......@@ -93,17 +96,11 @@ bool DviGenerator::doCloseDocument()
delete m_dviRenderer;
m_dviRenderer = 0;
ready = false;
m_linkGenerated.clear();
return true;
}
bool DviGenerator::canGeneratePixmap () const
{
return ready;
}
void DviGenerator::fillViewportFromAnchor( Okular::DocumentViewport &vp,
const Anchor &anch, int pW, int pH )
{
......@@ -168,11 +165,12 @@ QLinkedList<Okular::ObjectRect*> DviGenerator::generateDviLinks( const dviPageIn
return dviLinks;
}
void DviGenerator::generatePixmap( Okular::PixmapRequest *request )
QImage DviGenerator::image( Okular::PixmapRequest *request )
{
dviPageInfo *pageInfo = new dviPageInfo();
pageSize ps;
QImage ret;
pageInfo->width = request->width();
pageInfo->height = request->height();
......@@ -181,6 +179,8 @@ void DviGenerator::generatePixmap( Okular::PixmapRequest *request )
// pageInfo->resolution = m_resolution;
QMutexLocker lock( userMutex() );
SimplePageSize s = m_dviRenderer->sizeOfPage( pageInfo->pageNumber );
/* if ( s.width() != pageInfo->width) */
......@@ -209,10 +209,7 @@ void DviGenerator::generatePixmap( Okular::PixmapRequest *request )
{
kDebug(DviDebug) << "Image OK";
if ( !request->page()->isBoundingBoxKnown() )
updatePageBoundingBox( request->page()->number(), Okular::Utils::imageBoundingBox( &(pageInfo->img) ) );
request->page()->setPixmap( request->id(), new QPixmap( QPixmap::fromImage( pageInfo->img ) ) );
ret = pageInfo->img;
if ( !m_linkGenerated[ request->pageNumber() ] )
{
......@@ -222,11 +219,11 @@ void DviGenerator::generatePixmap( Okular::PixmapRequest *request )
}
}
ready = true;
lock.unlock();
delete pageInfo;
signalPixmapRequestDone( request );
return ret;
}
Okular::TextPage* DviGenerator::textPage( Okular::Page *page )
......@@ -241,6 +238,9 @@ Okular::TextPage* DviGenerator::textPage( Okular::Page *page )
pageInfo->pageNumber = page->number() + 1;
pageInfo->resolution = m_resolution;
QMutexLocker lock( userMutex() );
SimplePageSize s = m_dviRenderer->sizeOfPage( pageInfo->pageNumber );
pageInfo->resolution = (double)(pageInfo->width)/ps.width().getLength_in_inch();
......@@ -249,6 +249,7 @@ Okular::TextPage* DviGenerator::textPage( Okular::Page *page )
if ( m_dviRenderer )
{
m_dviRenderer->getText( pageInfo );
lock.unlock();
ktp = extractTextFromPage( pageInfo );
}
......@@ -295,6 +296,8 @@ const Okular::DocumentInfo *DviGenerator::generateDocumentInfo()
m_docInfo->set( Okular::DocumentInfo::MimeType, "application/x-dvi" );
QMutexLocker lock( userMutex() );
if ( m_dviRenderer && m_dviRenderer->dviFile )
{
dvifile *dvif = m_dviRenderer->dviFile;
......@@ -315,8 +318,12 @@ const Okular::DocumentSynopsis *DviGenerator::generateDocumentSynopsis()
m_docSynopsis = new Okular::DocumentSynopsis();
userMutex()->lock();
QVector<PreBookmark> prebookmarks = m_dviRenderer->getPrebookmarks();
userMutex()->unlock();
if ( prebookmarks.isEmpty() )
return m_docSynopsis;
......
......@@ -30,9 +30,6 @@ class DviGenerator : public Okular::Generator
DviGenerator( QObject *parent, const QVariantList &args );
bool loadDocument( const QString & fileName, QVector< Okular::Page * > & pagesVector );
bool canGeneratePixmap() const;
void generatePixmap( Okular::PixmapRequest * request );
// document information
const Okular::DocumentInfo *generateDocumentInfo();
......@@ -43,6 +40,7 @@ class DviGenerator : public Okular::Generator
protected:
bool doCloseDocument();
QImage image( Okular::PixmapRequest * request );
Okular::TextPage* textPage( Okular::Page *page );
private:
......@@ -51,7 +49,6 @@ class DviGenerator : public Okular::Generator
Okular::DocumentInfo *m_docInfo;
Okular::DocumentSynopsis *m_docSynopsis;
bool ready;
dviRenderer *m_dviRenderer;
QBitArray m_linkGenerated;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment