Commit 2677200e authored by Wilfried Huss's avatar Wilfried Huss

port of commit 553824:

Further refractoring.

We now only put JobId's into the RenderQueue.
DocumentRenderer::drawPage() now also takes a JobId as
argument, and returns the resulting RenderedDocumentPagePixmap.

svn path=/trunk/KDE/kdegraphics/kviewshell/plugins/dvi/; revision=553987
parent 012297a4
......@@ -16,6 +16,7 @@
#include "dvisourcesplitter.h"
#include "hyperlink.h"
#include "infodialog.h"
#include "kmultipage.h"
#include "kvs_debug.h"
#include "prebookmark.h"
#include "psgs.h"
......@@ -47,8 +48,9 @@ QPainter *foreGroundPainter; // QPainter used for text
//------ now comes the dviRenderer class implementation ----------
dviRenderer::dviRenderer()
: dviFile(0),
dviRenderer::dviRenderer(KMultiPage* _multiPage)
: DocumentRenderer(_multiPage),
dviFile(0),
info(new infoDialog(0)),
resolutionInDPI(0),
embedPS_progress(0),
......@@ -112,46 +114,42 @@ void dviRenderer::showInfo()
//------ this function calls the dvi interpreter ----------
void dviRenderer::drawPage(RenderedDocumentPagePixmap* page)
RenderedDocumentPagePixmap* dviRenderer::drawPage(const JobId& id)
{
#ifdef DEBUG_DVIRENDERER
kDebug(kvs::dvi) << "dviRenderer::drawPage(documentPage *) called, page number " << page->getPageNumber() << endl;
kDebug(kvs::djvu) << "dviRenderer::drawPage(JobId) called, page number " << id.pageNumber << endl;
#endif
// Paranoid safety checks
if (page == 0) {
kError(kvs::dvi) << "dviRenderer::drawPage(documentPage *) called with argument == 0" << endl;
return;
}
if (page->getPageNumber() == 0) {
kError(kvs::dvi) << "dviRenderer::drawPage(documentPage *) called for a documentPage with page number 0" << endl;
return;
if (!id.pageNumber.isValid())
{
kDebug(kvs::djvu) << "dviRenderer::drawPage(JobId) called with an invalid pageNumber" << endl;
return 0;
}
QMutexLocker locker(&mutex);
if ( dviFile == 0 ) {
kError(kvs::dvi) << "dviRenderer::drawPage(documentPage *) called, but no dviFile class allocated." << endl;
page->clear();
return;
kError(kvs::dvi) << "dviRenderer::drawPage(JobId) called, but no dviFile class allocated." << endl;
return 0;
}
if (page->getPageNumber() > dviFile->total_pages) {
kError(kvs::dvi) << "dviRenderer::drawPage(documentPage *) called for a documentPage with page number " << page->getPageNumber()
if (id.pageNumber > dviFile->total_pages) {
kError(kvs::dvi) << "dviRenderer::drawPage(JobId) called for a documentPage with page number " << id.pageNumber
<< " but the current dviFile has only " << dviFile->total_pages << " pages." << endl;
return;
return 0;
}
if ( dviFile->dvi_Data() == 0 ) {
kError(kvs::dvi) << "dviRenderer::drawPage(documentPage *) called, but no dviFile is loaded yet." << endl;
page->clear();
return;
kError(kvs::dvi) << "dviRenderer::drawPage(JobId) called, but no dviFile is loaded yet." << endl;
return 0;
}
double resolution = page->getId().resolution;
double resolution = id.resolution;
if (resolution != resolutionInDPI)
setResolution(resolution);
RenderedDocumentPagePixmap* page = multiPage->createDocumentPagePixmap(id);
currentlyDrawnPage = page;
shrinkfactor = 1200/resolutionInDPI;
current_page = page->getPageNumber()-1;
......@@ -161,8 +159,10 @@ void dviRenderer::drawPage(RenderedDocumentPagePixmap* page)
colorStack.clear();
globalColor = Qt::black;
int pageWidth = page->width();
int pageHeight = page->height();
SimplePageSize ps = sizeOfPage(page->getPageNumber());
int pageHeight = ps.sizeInPixel(resolution).height();
int pageWidth = ps.sizeInPixel(resolution).width();
page->resize(pageWidth, pageHeight);
QImage img(pageWidth, pageHeight, QImage::Format_RGB32);
foreGroundPainter = new QPainter(&img);
......@@ -186,7 +186,7 @@ void dviRenderer::drawPage(RenderedDocumentPagePixmap* page)
errorMsg, i18n("DVI File Error"));
errorMsg = QString::null;
currentlyDrawnPage = 0;
return;
return 0;
}
// Tell the user (once) if the DVI file contains source specials
......@@ -204,18 +204,22 @@ void dviRenderer::drawPage(RenderedDocumentPagePixmap* page)
}
currentlyDrawnPage = 0;
return page;
}
void dviRenderer::getText(RenderedDocumentPagePixmap* page)
RenderedDocumentPagePixmap* dviRenderer::getText(const JobId& id)
{
bool postscriptBackup = _postscript;
// Disable postscript-specials temporarely to speed up text extraction.
_postscript = false;
drawPage(page);
RenderedDocumentPagePixmap* page = drawPage(id);
_postscript = postscriptBackup;
return page;
}
......
......@@ -87,7 +87,7 @@ class dviRenderer : public DocumentRenderer, bigEndianByteReader
Q_OBJECT
public:
dviRenderer();
dviRenderer(KMultiPage*);
~dviRenderer();
virtual bool setFile(const QString &fname, const KUrl &base);
......@@ -148,8 +148,8 @@ public slots:
in dviRenderer::mouseMoveEvent(), see the explanation there. */
void clearStatusBar();
virtual void drawPage(RenderedDocumentPagePixmap* page);
virtual void getText(RenderedDocumentPagePixmap* page);
virtual RenderedDocumentPagePixmap* drawPage(const JobId& id);
virtual RenderedDocumentPagePixmap* getText(const JobId& id);
private slots:
/** This method shows a dialog that tells the user that source
......
......@@ -40,9 +40,9 @@ int performanceFlag = 0;
K_EXPORT_COMPONENT_FACTORY( kdvipart, KGenericFactory<KDVIMultiPage>( "kdvipart" ) )
KDVIMultiPage::KDVIMultiPage(QObject *parent, const QStringList& args)
: KMultiPage(parent)
: KMultiPage(parent),
DVIRenderer(this)
{
Q_UNUSED(args);
#ifdef PERFORMANCE_MEASUREMENT
......
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