2006-06-27 22:17:35 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2006 by Luigi Toscano <luigi.toscano@tiscali.it> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-04-20 11:26:05 +00:00
|
|
|
#include <okular/core/action.h>
|
2007-01-03 14:30:48 +00:00
|
|
|
#include <okular/core/document.h>
|
2007-12-30 16:41:10 +00:00
|
|
|
#include <okular/core/fileprinter.h>
|
2007-01-03 14:30:48 +00:00
|
|
|
#include <okular/core/page.h>
|
|
|
|
#include <okular/core/sourcereference.h>
|
|
|
|
#include <okular/core/textpage.h>
|
|
|
|
#include <okular/core/utils.h>
|
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
#include "generator_dvi.h"
|
|
|
|
#include "dviFile.h"
|
|
|
|
#include "dviPageInfo.h"
|
|
|
|
#include "dviRenderer.h"
|
|
|
|
#include "pageSize.h"
|
2007-12-30 16:41:10 +00:00
|
|
|
#include "dviexport.h"
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qstring.h>
|
|
|
|
#include <qurl.h>
|
2006-07-01 21:17:42 +00:00
|
|
|
#include <qvector.h>
|
2006-06-30 22:35:48 +00:00
|
|
|
#include <qstack.h>
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2007-11-24 18:08:30 +00:00
|
|
|
#include <kaboutdata.h>
|
2006-06-27 22:17:35 +00:00
|
|
|
#include <kdebug.h>
|
|
|
|
#include <klocale.h>
|
2007-12-30 16:41:10 +00:00
|
|
|
#include <ktemporaryfile.h>
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2007-12-31 18:44:18 +00:00
|
|
|
static const int DviDebug = 4713;
|
|
|
|
|
2007-12-02 20:57:24 +00:00
|
|
|
static KAboutData createAboutData()
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
2007-12-02 20:57:24 +00:00
|
|
|
KAboutData aboutData(
|
2007-11-24 18:08:30 +00:00
|
|
|
"okular_dvi",
|
|
|
|
"okular_dvi",
|
2009-03-30 17:50:44 +00:00
|
|
|
ki18n( "DVI Backend" ),
|
2007-11-24 18:08:30 +00:00
|
|
|
"0.1",
|
2009-03-30 17:50:44 +00:00
|
|
|
ki18n( "A DVI file renderer" ),
|
2007-11-24 18:08:30 +00:00
|
|
|
KAboutData::License_GPL,
|
2009-03-30 17:50:44 +00:00
|
|
|
ki18n( "© 2006 Luigi Toscano" )
|
2007-11-24 18:08:30 +00:00
|
|
|
);
|
2007-12-02 20:57:24 +00:00
|
|
|
return aboutData;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2007-01-26 16:35:30 +00:00
|
|
|
setFeature( TextExtraction );
|
2007-12-30 16:41:10 +00:00
|
|
|
setFeature( PrintPostscript );
|
2008-12-14 23:18:52 +00:00
|
|
|
if ( Okular::FilePrinter::ps2pdfAvailable() )
|
|
|
|
setFeature( PrintToFile );
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
bool DviGenerator::loadDocument( const QString & fileName, QVector< Okular::Page * > &pagesVector )
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
2007-12-31 18:44:18 +00:00
|
|
|
//kDebug(DviDebug) << "file:" << fileName;
|
2006-06-27 22:17:35 +00:00
|
|
|
KUrl base( fileName );
|
|
|
|
|
|
|
|
m_dviRenderer = new dviRenderer();
|
|
|
|
if ( ! m_dviRenderer->setFile( fileName, base ) )
|
2009-05-07 21:43:13 +00:00
|
|
|
{
|
|
|
|
delete m_dviRenderer;
|
|
|
|
m_dviRenderer = 0;
|
2006-06-27 22:17:35 +00:00
|
|
|
return false;
|
2009-05-07 21:43:13 +00:00
|
|
|
}
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2007-12-30 16:41:10 +00:00
|
|
|
m_dviRenderer->setParentWidget( document()->widget() );
|
|
|
|
|
2007-12-31 18:44:18 +00:00
|
|
|
kDebug(DviDebug) << "# of pages:" << m_dviRenderer->dviFile->total_pages;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2006-11-27 08:13:47 +00:00
|
|
|
m_resolution = Okular::Utils::dpiY();
|
2007-12-27 15:38:29 +00:00
|
|
|
loadPages( pagesVector );
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
ready = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-10-08 16:46:51 +00:00
|
|
|
bool DviGenerator::doCloseDocument()
|
2006-07-14 10:54:29 +00:00
|
|
|
{
|
|
|
|
delete m_docInfo;
|
|
|
|
m_docInfo = 0;
|
|
|
|
delete m_docSynopsis;
|
|
|
|
m_docSynopsis = 0;
|
|
|
|
delete m_dviRenderer;
|
|
|
|
m_dviRenderer = 0;
|
|
|
|
|
|
|
|
ready = false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-01-24 15:06:45 +00:00
|
|
|
bool DviGenerator::canGeneratePixmap () const
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
|
|
|
return ready;
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
void DviGenerator::fillViewportFromAnchor( Okular::DocumentViewport &vp,
|
2007-12-27 15:38:29 +00:00
|
|
|
const Anchor &anch, int pW, int pH )
|
2006-06-30 22:35:48 +00:00
|
|
|
{
|
|
|
|
vp.pageNumber = anch.page - 1;
|
|
|
|
|
|
|
|
|
|
|
|
SimplePageSize ps = m_dviRenderer->sizeOfPage( vp.pageNumber );
|
|
|
|
double resolution = 0;
|
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
resolution = (double)(pW)/ps.width().getLength_in_inch();
|
2006-06-30 22:35:48 +00:00
|
|
|
|
|
|
|
double py = (double)anch.distance_from_top.getLength_in_inch()*resolution + 0.5;
|
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
vp.rePos.normalizedX = 0.5;
|
|
|
|
vp.rePos.normalizedY = py/(double)pH;
|
2006-06-30 22:35:48 +00:00
|
|
|
vp.rePos.enabled = true;
|
2006-09-21 08:45:36 +00:00
|
|
|
vp.rePos.pos = Okular::DocumentViewport::Center;
|
2006-06-30 22:35:48 +00:00
|
|
|
}
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
QLinkedList<Okular::ObjectRect*> DviGenerator::generateDviLinks( const dviPageInfo *pageInfo )
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
QLinkedList<Okular::ObjectRect*> dviLinks;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
int pageWidth = pageInfo->width, pageHeight = pageInfo->height;
|
|
|
|
|
2008-02-09 15:34:37 +00:00
|
|
|
foreach( const Hyperlink &dviLink, pageInfo->hyperLinkList )
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
2007-12-27 15:38:29 +00:00
|
|
|
QRect boxArea = dviLink.box;
|
2006-06-27 22:17:35 +00:00
|
|
|
double nl = (double)boxArea.left() / pageWidth,
|
|
|
|
nt = (double)boxArea.top() / pageHeight,
|
|
|
|
nr = (double)boxArea.right() / pageWidth,
|
|
|
|
nb = (double)boxArea.bottom() / pageHeight;
|
2007-12-27 15:38:29 +00:00
|
|
|
|
|
|
|
QString linkText = dviLink.linkText;
|
|
|
|
if ( linkText.startsWith("#") )
|
|
|
|
linkText = linkText.mid( 1 );
|
|
|
|
Anchor anch = m_dviRenderer->findAnchor( linkText );
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2007-04-20 12:37:12 +00:00
|
|
|
Okular::Action *okuLink = 0;
|
2006-06-28 20:40:47 +00:00
|
|
|
|
2006-06-30 22:35:48 +00:00
|
|
|
/* distinguish between local (-> anchor) and remote links */
|
|
|
|
if (anch.isValid())
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
2006-06-30 22:35:48 +00:00
|
|
|
/* internal link */
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::DocumentViewport vp;
|
2007-12-27 15:38:29 +00:00
|
|
|
fillViewportFromAnchor( vp, anch, pageWidth, pageHeight );
|
|
|
|
|
2007-05-02 22:50:27 +00:00
|
|
|
okuLink = new Okular::GotoAction( "", vp );
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-05-02 22:50:27 +00:00
|
|
|
okuLink = new Okular::BrowseAction( dviLink.linkText );
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
2006-06-28 20:40:47 +00:00
|
|
|
if ( okuLink )
|
|
|
|
{
|
2007-12-27 15:38:29 +00:00
|
|
|
Okular::ObjectRect *orlink = new Okular::ObjectRect( nl, nt, nr, nb,
|
|
|
|
false, Okular::ObjectRect::Action, okuLink );
|
2006-06-28 20:40:47 +00:00
|
|
|
dviLinks.push_front( orlink );
|
|
|
|
}
|
2007-12-27 15:38:29 +00:00
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
return dviLinks;
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
void DviGenerator::generatePixmap( Okular::PixmapRequest *request )
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
dviPageInfo *pageInfo = new dviPageInfo();
|
|
|
|
pageSize ps;
|
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
pageInfo->width = request->width();
|
|
|
|
pageInfo->height = request->height();
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2006-10-25 15:35:53 +00:00
|
|
|
pageInfo->pageNumber = request->pageNumber() + 1;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
// pageInfo->resolution = m_resolution;
|
|
|
|
|
|
|
|
SimplePageSize s = m_dviRenderer->sizeOfPage( pageInfo->pageNumber );
|
|
|
|
|
|
|
|
/* if ( s.width() != pageInfo->width) */
|
|
|
|
// if (!useDocumentSpecifiedSize)
|
|
|
|
// s = userPreferredSize;
|
|
|
|
|
|
|
|
if (s.isValid())
|
|
|
|
{
|
|
|
|
ps = s; /* it should be the user specified size, if any, instead */
|
|
|
|
}
|
|
|
|
|
|
|
|
pageInfo->resolution = (double)(pageInfo->width)/ps.width().getLength_in_inch();
|
|
|
|
|
|
|
|
#if 0
|
2007-12-31 18:44:18 +00:00
|
|
|
kDebug(DviDebug) << *request
|
2006-06-27 22:17:35 +00:00
|
|
|
<< ", res:" << pageInfo->resolution << " - (" << pageInfo->width << ","
|
|
|
|
<< ps.width().getLength_in_inch() << ")," << ps.width().getLength_in_mm()
|
|
|
|
<< endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( m_dviRenderer )
|
|
|
|
{
|
|
|
|
m_dviRenderer->drawPage( pageInfo );
|
|
|
|
|
|
|
|
if ( ! pageInfo->img.isNull() )
|
|
|
|
{
|
2007-12-31 18:44:18 +00:00
|
|
|
kDebug(DviDebug) << "Image OK";
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2008-05-19 07:05:20 +00:00
|
|
|
if ( !request->page()->isBoundingBoxKnown() )
|
|
|
|
updatePageBoundingBox( request->page()->number(), Okular::Utils::imageBoundingBox( &(pageInfo->img) ) );
|
|
|
|
|
2006-11-20 07:53:32 +00:00
|
|
|
request->page()->setPixmap( request->id(), new QPixmap( QPixmap::fromImage( pageInfo->img ) ) );
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
request->page()->setObjectRects( generateDviLinks( pageInfo ) );
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ready = true;
|
|
|
|
|
|
|
|
delete pageInfo;
|
|
|
|
|
2007-01-29 08:17:45 +00:00
|
|
|
signalPixmapRequestDone( request );
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
|
2007-01-31 18:31:19 +00:00
|
|
|
Okular::TextPage* DviGenerator::textPage( Okular::Page *page )
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
2007-12-31 18:44:18 +00:00
|
|
|
kDebug(DviDebug);
|
2006-06-27 22:17:35 +00:00
|
|
|
dviPageInfo *pageInfo = new dviPageInfo();
|
|
|
|
pageSize ps;
|
2007-12-27 15:38:29 +00:00
|
|
|
|
|
|
|
pageInfo->width=page->width();
|
|
|
|
pageInfo->height=page->height();
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
pageInfo->pageNumber = page->number() + 1;
|
|
|
|
|
|
|
|
pageInfo->resolution = m_resolution;
|
|
|
|
SimplePageSize s = m_dviRenderer->sizeOfPage( pageInfo->pageNumber );
|
|
|
|
pageInfo->resolution = (double)(pageInfo->width)/ps.width().getLength_in_inch();
|
|
|
|
|
|
|
|
// get page text from m_dviRenderer
|
2007-01-31 18:31:19 +00:00
|
|
|
Okular::TextPage *ktp = 0;
|
2006-06-27 22:17:35 +00:00
|
|
|
if ( m_dviRenderer )
|
|
|
|
{
|
|
|
|
m_dviRenderer->getText( pageInfo );
|
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
ktp = extractTextFromPage( pageInfo );
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
delete pageInfo;
|
2007-01-31 18:31:19 +00:00
|
|
|
return ktp;
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
Okular::TextPage *DviGenerator::extractTextFromPage( dviPageInfo *pageInfo )
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
QList<Okular::TextEntity*> textOfThePage;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2006-07-01 21:17:42 +00:00
|
|
|
QVector<TextBox>::ConstIterator it = pageInfo->textBoxList.constBegin();
|
|
|
|
QVector<TextBox>::ConstIterator itEnd = pageInfo->textBoxList.constEnd();
|
2006-06-27 22:17:35 +00:00
|
|
|
QRect tmpRect;
|
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
int pageWidth = pageInfo->width, pageHeight = pageInfo->height;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
for ( ; it != itEnd ; ++it )
|
|
|
|
{
|
|
|
|
TextBox curTB = *it;
|
2006-06-30 22:35:48 +00:00
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
#if 0
|
2007-12-31 18:44:18 +00:00
|
|
|
kDebug(DviDebug) << "orientation: " << orientation
|
2006-06-27 22:17:35 +00:00
|
|
|
<< ", curTB.box: " << curTB.box
|
|
|
|
<< ", tmpRect: " << tmpRect
|
|
|
|
<< ", ( " << pageWidth << "," << pageHeight << " )"
|
|
|
|
<<endl;
|
|
|
|
#endif
|
2006-09-21 08:45:36 +00:00
|
|
|
textOfThePage.push_back( new Okular::TextEntity( curTB.text,
|
2007-12-27 15:38:29 +00:00
|
|
|
new Okular::NormalizedRect( curTB.box, pageWidth, pageHeight ) ) );
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::TextPage* ktp = new Okular::TextPage( textOfThePage );
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
return ktp;
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
const Okular::DocumentInfo *DviGenerator::generateDocumentInfo()
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
|
|
|
if ( m_docInfo )
|
|
|
|
return m_docInfo;
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
m_docInfo = new Okular::DocumentInfo();
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2007-05-13 12:54:46 +00:00
|
|
|
m_docInfo->set( Okular::DocumentInfo::MimeType, "application/x-dvi" );
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
if ( m_dviRenderer && m_dviRenderer->dviFile )
|
|
|
|
{
|
|
|
|
dvifile *dvif = m_dviRenderer->dviFile;
|
|
|
|
|
|
|
|
// read properties from dvif
|
|
|
|
//m_docInfo->set( "filename", dvif->filename, i18n("Filename") );
|
|
|
|
m_docInfo->set( "generatorDate", dvif->generatorString,
|
|
|
|
i18n("Generator/Date") );
|
2007-05-13 12:54:46 +00:00
|
|
|
m_docInfo->set( Okular::DocumentInfo::Pages, QString::number( dvif->total_pages ) );
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
return m_docInfo;
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
const Okular::DocumentSynopsis *DviGenerator::generateDocumentSynopsis()
|
2006-06-30 22:35:48 +00:00
|
|
|
{
|
|
|
|
if ( m_docSynopsis )
|
|
|
|
return m_docSynopsis;
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
m_docSynopsis = new Okular::DocumentSynopsis();
|
2006-06-30 22:35:48 +00:00
|
|
|
|
2006-07-01 21:17:42 +00:00
|
|
|
QVector<PreBookmark> prebookmarks = m_dviRenderer->getPrebookmarks();
|
2006-06-30 22:35:48 +00:00
|
|
|
|
|
|
|
if ( prebookmarks.isEmpty() )
|
|
|
|
return m_docSynopsis;
|
|
|
|
|
2007-12-26 20:08:29 +00:00
|
|
|
QStack<QDomElement> stack;
|
|
|
|
|
2008-11-11 18:48:40 +00:00
|
|
|
QVector<PreBookmark>::ConstIterator it = prebookmarks.constBegin();
|
|
|
|
QVector<PreBookmark>::ConstIterator itEnd = prebookmarks.constEnd();
|
2006-06-30 22:35:48 +00:00
|
|
|
for( ; it != itEnd; ++it )
|
|
|
|
{
|
2007-12-26 20:08:29 +00:00
|
|
|
QDomElement domel = m_docSynopsis->createElement( (*it).title );
|
2006-06-30 22:35:48 +00:00
|
|
|
Anchor a = m_dviRenderer->findAnchor((*it).anchorName);
|
|
|
|
if ( a.isValid() )
|
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::DocumentViewport vp;
|
2006-06-30 22:35:48 +00:00
|
|
|
|
2006-10-22 11:25:08 +00:00
|
|
|
const Okular::Page *p = document()->page( a.page - 1 );
|
2007-12-27 15:38:29 +00:00
|
|
|
|
|
|
|
fillViewportFromAnchor( vp, a, (int)p->width(), (int)p->height() );
|
2007-12-26 20:08:29 +00:00
|
|
|
domel.setAttribute( "Viewport", vp.toString() );
|
2006-06-30 22:35:48 +00:00
|
|
|
}
|
|
|
|
if ( stack.isEmpty() )
|
2007-12-26 20:08:29 +00:00
|
|
|
m_docSynopsis->appendChild( domel );
|
2006-06-30 22:35:48 +00:00
|
|
|
else
|
|
|
|
{
|
2007-12-26 20:08:29 +00:00
|
|
|
stack.top().appendChild( domel );
|
2006-06-30 22:35:48 +00:00
|
|
|
stack.pop();
|
|
|
|
}
|
|
|
|
for ( int i = 0; i < (*it).noOfChildren; ++i )
|
|
|
|
stack.push( domel );
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_docSynopsis;
|
|
|
|
}
|
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
void DviGenerator::loadPages( QVector< Okular::Page * > &pagesVector )
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
|
|
|
QSize pageRequiredSize;
|
|
|
|
|
|
|
|
int numofpages = m_dviRenderer->dviFile->total_pages;
|
|
|
|
pagesVector.resize( numofpages );
|
|
|
|
|
2007-12-31 18:44:18 +00:00
|
|
|
//kDebug(DviDebug) << "resolution:" << m_resolution << ", dviFile->preferred?";
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
/* get the suggested size */
|
|
|
|
if ( m_dviRenderer->dviFile->suggestedPageSize )
|
|
|
|
{
|
|
|
|
pageRequiredSize = m_dviRenderer->dviFile->suggestedPageSize->sizeInPixel(
|
|
|
|
m_resolution );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pageSize ps;
|
|
|
|
pageRequiredSize = ps.sizeInPixel( m_resolution );
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( int i = 0; i < numofpages; ++i )
|
|
|
|
{
|
2007-12-31 18:44:18 +00:00
|
|
|
//kDebug(DviDebug) << "getting status of page" << i << ":";
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
if ( pagesVector[i] )
|
|
|
|
{
|
|
|
|
delete pagesVector[i];
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::Page * page = new Okular::Page( i,
|
2006-06-27 22:17:35 +00:00
|
|
|
pageRequiredSize.width(),
|
|
|
|
pageRequiredSize.height(),
|
2007-12-27 15:38:29 +00:00
|
|
|
Okular::Rotation0 );
|
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
pagesVector[i] = page;
|
|
|
|
}
|
2007-12-31 18:44:18 +00:00
|
|
|
kDebug(DviDebug) << "pagesVector successfully inizialized!";
|
2006-11-17 22:15:15 +00:00
|
|
|
|
|
|
|
// filling the pages with the source references rects
|
|
|
|
const QVector<DVI_SourceFileAnchor>& sourceAnchors = m_dviRenderer->sourceAnchors();
|
|
|
|
QVector< QLinkedList< Okular::SourceRefObjectRect * > > refRects( numofpages );
|
|
|
|
foreach ( const DVI_SourceFileAnchor& sfa, sourceAnchors )
|
|
|
|
{
|
|
|
|
if ( sfa.page < 1 || (int)sfa.page > numofpages )
|
|
|
|
continue;
|
|
|
|
|
2009-03-23 12:11:25 +00:00
|
|
|
Okular::NormalizedPoint p( -1.0, (double)sfa.distance_from_top.getLength_in_pixel( Okular::Utils::dpiY() ) / (double)pageRequiredSize.height() );
|
2006-11-17 22:15:15 +00:00
|
|
|
Okular::SourceReference * sourceRef = new Okular::SourceReference( sfa.fileName, sfa.line );
|
|
|
|
refRects[ sfa.page - 1 ].append( new Okular::SourceRefObjectRect( p, sourceRef ) );
|
|
|
|
}
|
|
|
|
for ( int i = 0; i < refRects.size(); ++i )
|
|
|
|
if ( !refRects.at(i).isEmpty() )
|
|
|
|
pagesVector[i]->setSourceReferences( refRects.at(i) );
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
|
2007-12-30 16:41:10 +00:00
|
|
|
bool DviGenerator::print( QPrinter& printer )
|
|
|
|
{
|
|
|
|
// Create tempfile to write to
|
|
|
|
KTemporaryFile tf;
|
|
|
|
tf.setSuffix( ".ps" );
|
|
|
|
if ( !tf.open() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QList<int> pageList = Okular::FilePrinter::pageList( printer,
|
|
|
|
m_dviRenderer->totalPages(),
|
|
|
|
document()->bookmarkedPageList() );
|
|
|
|
QString pages;
|
|
|
|
QStringList printOptions;
|
|
|
|
// List of pages to print.
|
|
|
|
foreach ( int p, pageList )
|
|
|
|
{
|
|
|
|
pages += QString(",%1").arg(p);
|
|
|
|
}
|
|
|
|
if ( !pages.isEmpty() )
|
|
|
|
printOptions << "-pp" << pages.mid(1);
|
|
|
|
|
|
|
|
QEventLoop el;
|
|
|
|
m_dviRenderer->setEventLoop( &el );
|
|
|
|
m_dviRenderer->exportPS( tf.fileName(), printOptions, &printer );
|
|
|
|
|
|
|
|
tf.close();
|
|
|
|
|
|
|
|
// Error messages are handled by the generator - ugly, but it works.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
#include "generator_dvi.moc"
|