2006-06-27 22:17:35 +00:00
|
|
|
/***************************************************************************
|
2009-11-21 00:57:56 +00:00
|
|
|
* Copyright (C) 2006-2009 by Luigi Toscano <luigi.toscano@tiscali.it> *
|
2006-06-27 22:17:35 +00:00
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2011-06-01 08:49:49 +00:00
|
|
|
#include <core/action.h>
|
|
|
|
#include <core/document.h>
|
|
|
|
#include <core/fileprinter.h>
|
|
|
|
#include <core/page.h>
|
|
|
|
#include <core/sourcereference.h>
|
|
|
|
#include <core/textpage.h>
|
|
|
|
#include <core/utils.h>
|
2007-01-03 14:30:48 +00:00
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
#include "generator_dvi.h"
|
2014-09-11 19:12:27 +00:00
|
|
|
#include "debug_dvi.h"
|
2006-06-27 22:17:35 +00:00
|
|
|
#include "dviFile.h"
|
|
|
|
#include "dviPageInfo.h"
|
|
|
|
#include "dviRenderer.h"
|
|
|
|
#include "pageSize.h"
|
2007-12-30 16:41:10 +00:00
|
|
|
#include "dviexport.h"
|
2009-11-21 00:57:56 +00:00
|
|
|
#include "TeXFont.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>
|
2009-05-11 15:14:17 +00:00
|
|
|
#include <qmutex.h>
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2007-11-24 18:08:30 +00:00
|
|
|
#include <kaboutdata.h>
|
2014-09-11 19:12:27 +00:00
|
|
|
#include <QtCore/QDebug>
|
2006-06-27 22:17:35 +00:00
|
|
|
#include <klocale.h>
|
2007-12-30 16:41:10 +00:00
|
|
|
#include <ktemporaryfile.h>
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-05-26 22:53:40 +00:00
|
|
|
#ifdef DVI_OPEN_BUSYLOOP
|
2009-05-25 16:04:36 +00:00
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
#include <ctime>
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#include <windows.h> // for Sleep
|
|
|
|
#endif
|
2009-05-26 22:53:40 +00:00
|
|
|
#endif
|
2009-05-25 16:04:36 +00:00
|
|
|
|
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(
|
2014-08-09 18:21:20 +00:00
|
|
|
QStringLiteral("okular_dvi"),
|
|
|
|
i18n( "DVI Backend" ),
|
2014-08-14 11:35:43 +00:00
|
|
|
QStringLiteral("0.3.7"),
|
2014-08-09 18:21:20 +00:00
|
|
|
i18n( "A DVI file renderer" ),
|
|
|
|
KAboutLicense::GPL,
|
|
|
|
i18n( "© 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 ),
|
2014-05-11 09:17:49 +00:00
|
|
|
m_fontExtracted( false ), m_docSynopsis( 0 ), m_dviRenderer( 0 )
|
2007-12-02 20:57:24 +00:00
|
|
|
{
|
2009-05-11 15:14:17 +00:00
|
|
|
setFeature( Threaded );
|
2007-01-26 16:35:30 +00:00
|
|
|
setFeature( TextExtraction );
|
2009-11-21 00:57:56 +00:00
|
|
|
setFeature( FontInfo );
|
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
|
|
|
{
|
2014-09-11 19:12:27 +00:00
|
|
|
//qCDebug(OkularDviDebug) << "file:" << fileName;
|
2006-06-27 22:17:35 +00:00
|
|
|
KUrl base( fileName );
|
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
(void)userMutex();
|
|
|
|
|
2009-10-08 21:55:51 +00:00
|
|
|
m_dviRenderer = new dviRenderer(documentMetaData("TextHinting", QVariant()).toBool());
|
2014-02-21 00:04:13 +00:00
|
|
|
connect( m_dviRenderer, SIGNAL( error(QString,int) ), this, SIGNAL( error(QString,int) ) );
|
|
|
|
connect( m_dviRenderer, SIGNAL( warning(QString,int) ), this, SIGNAL( warning(QString,int) ) );
|
|
|
|
connect( m_dviRenderer, SIGNAL( notice(QString,int) ), this, SIGNAL( notice(QString,int) ) );
|
2009-05-26 22:53:40 +00:00
|
|
|
#ifdef DVI_OPEN_BUSYLOOP
|
2009-05-25 16:04:36 +00:00
|
|
|
static const ushort s_waitTime = 800; // milliseconds
|
|
|
|
static const int s_maxIterations = 10;
|
|
|
|
int iter = 0;
|
|
|
|
for ( ; !m_dviRenderer->isValidFile( fileName ) && iter < s_maxIterations; ++iter )
|
|
|
|
{
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug).nospace() << "file not valid after iteration #" << iter << "/" << s_maxIterations << ", waiting for " << s_waitTime;
|
2009-05-25 16:04:36 +00:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
Sleep( uint( s_waitTime ) );
|
|
|
|
#else
|
|
|
|
struct timespec ts = { 0, s_waitTime * 1000 * 1000 };
|
|
|
|
nanosleep( &ts, NULL );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if ( iter >= s_maxIterations && !m_dviRenderer->isValidFile( fileName ) )
|
|
|
|
{
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug) << "file still not valid after" << s_maxIterations;
|
2009-05-25 16:04:36 +00:00
|
|
|
delete m_dviRenderer;
|
|
|
|
m_dviRenderer = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-26 22:53:40 +00:00
|
|
|
#else
|
|
|
|
if ( !m_dviRenderer->isValidFile( fileName ) )
|
|
|
|
{
|
|
|
|
delete m_dviRenderer;
|
|
|
|
m_dviRenderer = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2006-06-27 22:17:35 +00:00
|
|
|
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
|
|
|
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug) << "# 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
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-10-08 16:46:51 +00:00
|
|
|
bool DviGenerator::doCloseDocument()
|
2006-07-14 10:54:29 +00:00
|
|
|
{
|
|
|
|
delete m_docSynopsis;
|
|
|
|
m_docSynopsis = 0;
|
|
|
|
delete m_dviRenderer;
|
|
|
|
m_dviRenderer = 0;
|
|
|
|
|
2009-05-11 11:41:20 +00:00
|
|
|
m_linkGenerated.clear();
|
2009-11-21 00:57:56 +00:00
|
|
|
m_fontExtracted = false;
|
2006-07-14 10:54:29 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-05-16 19:38:00 +00:00
|
|
|
void DviGenerator::fillViewportFromAnchor( Okular::DocumentViewport &vp,
|
2010-01-08 00:01:28 +00:00
|
|
|
const Anchor &anch, const Okular::Page *page ) const
|
2009-05-16 19:38:00 +00:00
|
|
|
{
|
|
|
|
fillViewportFromAnchor( vp, anch, page->width(), page->height() );
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
void DviGenerator::fillViewportFromAnchor( Okular::DocumentViewport &vp,
|
2010-01-08 00:01:28 +00:00
|
|
|
const Anchor &anch, int pW, int pH ) const
|
2006-06-30 22:35:48 +00:00
|
|
|
{
|
|
|
|
vp.pageNumber = anch.page - 1;
|
|
|
|
|
|
|
|
|
|
|
|
SimplePageSize ps = m_dviRenderer->sizeOfPage( vp.pageNumber );
|
|
|
|
double resolution = 0;
|
2010-01-09 15:08:53 +00:00
|
|
|
if (ps.isValid()) resolution = (double)(pW)/ps.width().getLength_in_inch();
|
|
|
|
else resolution = m_resolution;
|
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
|
|
|
|
{
|
2014-08-24 20:52:23 +00:00
|
|
|
okuLink = new Okular::BrowseAction( QUrl::fromUserInput( 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;
|
|
|
|
}
|
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
QImage DviGenerator::image( Okular::PixmapRequest *request )
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
dviPageInfo *pageInfo = new dviPageInfo();
|
|
|
|
pageSize ps;
|
2009-05-11 15:14:17 +00:00
|
|
|
QImage ret;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
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;
|
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
QMutexLocker lock( userMutex() );
|
|
|
|
|
2009-09-13 21:53:24 +00:00
|
|
|
if ( m_dviRenderer )
|
|
|
|
{
|
|
|
|
SimplePageSize s = m_dviRenderer->sizeOfPage( pageInfo->pageNumber );
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-09-13 21:53:24 +00:00
|
|
|
/* if ( s.width() != pageInfo->width) */
|
|
|
|
// if (!useDocumentSpecifiedSize)
|
|
|
|
// s = userPreferredSize;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-09-13 21:53:24 +00:00
|
|
|
if (s.isValid())
|
|
|
|
{
|
|
|
|
ps = s; /* it should be the user specified size, if any, instead */
|
|
|
|
}
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-09-13 21:53:24 +00:00
|
|
|
pageInfo->resolution = (double)(pageInfo->width)/ps.width().getLength_in_inch();
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
#if 0
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug) << *request
|
2009-09-13 21:53:24 +00:00
|
|
|
<< ", res:" << pageInfo->resolution << " - (" << pageInfo->width << ","
|
|
|
|
<< ps.width().getLength_in_inch() << ")," << ps.width().getLength_in_mm()
|
|
|
|
<< endl;
|
2006-06-27 22:17:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
m_dviRenderer->drawPage( pageInfo );
|
|
|
|
|
|
|
|
if ( ! pageInfo->img.isNull() )
|
|
|
|
{
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug) << "Image OK";
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
ret = pageInfo->img;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-05-11 11:41:20 +00:00
|
|
|
if ( !m_linkGenerated[ request->pageNumber() ] )
|
|
|
|
{
|
|
|
|
request->page()->setObjectRects( generateDviLinks( pageInfo ) );
|
|
|
|
m_linkGenerated[ request->pageNumber() ] = true;
|
|
|
|
}
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
lock.unlock();
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
delete pageInfo;
|
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
return ret;
|
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
|
|
|
{
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug);
|
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;
|
2009-05-11 15:14:17 +00:00
|
|
|
|
|
|
|
QMutexLocker lock( userMutex() );
|
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
// 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 )
|
|
|
|
{
|
2009-09-13 21:53:24 +00:00
|
|
|
SimplePageSize s = m_dviRenderer->sizeOfPage( pageInfo->pageNumber );
|
|
|
|
pageInfo->resolution = (double)(pageInfo->width)/ps.width().getLength_in_inch();
|
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
m_dviRenderer->getText( pageInfo );
|
2009-05-11 15:14:17 +00:00
|
|
|
lock.unlock();
|
2006-06-27 22:17:35 +00:00
|
|
|
|
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
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug) << "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;
|
|
|
|
}
|
|
|
|
|
2014-05-11 09:17:49 +00:00
|
|
|
Okular::DocumentInfo DviGenerator::generateDocumentInfo( const QSet<Okular::DocumentInfo::Key> &keys ) const
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
2014-05-11 09:17:49 +00:00
|
|
|
Okular::DocumentInfo docInfo;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2014-05-11 09:17:49 +00:00
|
|
|
if ( keys.contains( Okular::DocumentInfo::MimeType ) )
|
|
|
|
docInfo.set( Okular::DocumentInfo::MimeType, "application/x-dvi" );
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
QMutexLocker lock( userMutex() );
|
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
if ( m_dviRenderer && m_dviRenderer->dviFile )
|
|
|
|
{
|
|
|
|
dvifile *dvif = m_dviRenderer->dviFile;
|
|
|
|
|
|
|
|
// read properties from dvif
|
2014-05-11 09:17:49 +00:00
|
|
|
//docInfo.set( "filename", dvif->filename, i18n("Filename") );
|
|
|
|
if ( keys.contains( Okular::DocumentInfo::CustomKeys ) )
|
|
|
|
docInfo.set( "generatorDate", dvif->generatorString, i18n("Generator/Date") );
|
|
|
|
if ( keys.contains( Okular::DocumentInfo::Pages ) )
|
|
|
|
docInfo.set( Okular::DocumentInfo::Pages, QString::number( dvif->total_pages ) );
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
2014-05-11 09:17:49 +00:00
|
|
|
return docInfo;
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
userMutex()->lock();
|
|
|
|
|
2006-07-01 21:17:42 +00:00
|
|
|
QVector<PreBookmark> prebookmarks = m_dviRenderer->getPrebookmarks();
|
2006-06-30 22:35:48 +00:00
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
userMutex()->unlock();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-11-21 00:57:56 +00:00
|
|
|
Okular::FontInfo::List DviGenerator::fontsForPage( int page )
|
|
|
|
{
|
|
|
|
Q_UNUSED( page );
|
|
|
|
|
|
|
|
Okular::FontInfo::List list;
|
|
|
|
|
|
|
|
// the list of the fonts is extracted once
|
|
|
|
if ( m_fontExtracted )
|
|
|
|
return list;
|
|
|
|
|
|
|
|
if ( m_dviRenderer && m_dviRenderer->dviFile &&
|
|
|
|
m_dviRenderer->dviFile->font_pool )
|
|
|
|
{
|
|
|
|
QList<TeXFontDefinition*> fonts = m_dviRenderer->dviFile->font_pool->fontList;
|
|
|
|
|
|
|
|
foreach (const TeXFontDefinition* font, fonts)
|
|
|
|
{
|
|
|
|
Okular::FontInfo of;
|
|
|
|
QString name;
|
|
|
|
int zoom = (int)(font->enlargement*100 + 0.5);
|
2011-11-15 09:14:43 +00:00
|
|
|
#ifdef HAVE_FREETYPE
|
2009-11-21 00:57:56 +00:00
|
|
|
if ( font->getFullFontName().isEmpty() )
|
|
|
|
{
|
|
|
|
name = QString( "%1, %2%" )
|
|
|
|
.arg( font->fontname )
|
|
|
|
.arg( zoom );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name = QString( "%1 (%2), %3%" )
|
|
|
|
.arg( font->fontname )
|
|
|
|
.arg( font->getFullFontName() )
|
|
|
|
.arg( zoom );
|
|
|
|
}
|
2011-11-15 09:14:43 +00:00
|
|
|
#else
|
|
|
|
name = QString( "%1, %2%" )
|
|
|
|
.arg( font->fontname )
|
|
|
|
.arg( zoom );
|
|
|
|
#endif
|
2009-11-21 00:57:56 +00:00
|
|
|
of.setName( name );
|
|
|
|
|
|
|
|
QString fontFileName;
|
|
|
|
if (!(font->flags & TeXFontDefinition::FONT_VIRTUAL)) {
|
|
|
|
if ( font->font != 0 )
|
|
|
|
fontFileName = font->font->errorMessage;
|
|
|
|
else
|
|
|
|
fontFileName = i18n("Font file not found");
|
|
|
|
|
|
|
|
if ( fontFileName.isEmpty() )
|
|
|
|
fontFileName = font->filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
of.setFile( fontFileName );
|
|
|
|
|
|
|
|
Okular::FontInfo::FontType ft;
|
|
|
|
switch ( font->getFontType() )
|
|
|
|
{
|
|
|
|
case TeXFontDefinition::TEX_PK:
|
|
|
|
ft = Okular::FontInfo::TeXPK;
|
|
|
|
break;
|
|
|
|
case TeXFontDefinition::TEX_VIRTUAL:
|
|
|
|
ft = Okular::FontInfo::TeXVirtual;
|
|
|
|
break;
|
|
|
|
case TeXFontDefinition::TEX_FONTMETRIC:
|
|
|
|
ft = Okular::FontInfo::TeXFontMetric;
|
|
|
|
break;
|
|
|
|
case TeXFontDefinition::FREETYPE:
|
|
|
|
ft = Okular::FontInfo::TeXFreeTypeHandled;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
of.setType( ft );
|
|
|
|
|
|
|
|
// DVI has not the concept of "font embedding"
|
|
|
|
of.setEmbedType( Okular::FontInfo::NotEmbedded );
|
|
|
|
of.setCanBeExtracted( false );
|
|
|
|
|
|
|
|
list.append( of );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_fontExtracted = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
|
2009-05-11 11:41:20 +00:00
|
|
|
m_linkGenerated.fill( false, numofpages );
|
|
|
|
|
2014-09-11 19:12:27 +00:00
|
|
|
//qCDebug(OkularDviDebug) << "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 )
|
|
|
|
{
|
2014-09-11 19:12:27 +00:00
|
|
|
//qCDebug(OkularDviDebug) << "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;
|
|
|
|
}
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug) << "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(),
|
2010-06-04 08:25:25 +00:00
|
|
|
document()->currentPage() + 1,
|
2007-12-30 16:41:10 +00:00
|
|
|
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 );
|
2011-06-05 22:40:22 +00:00
|
|
|
m_dviRenderer->exportPS( tf.fileName(), printOptions, &printer, document()->orientation() );
|
2007-12-30 16:41:10 +00:00
|
|
|
|
|
|
|
tf.close();
|
|
|
|
|
|
|
|
// Error messages are handled by the generator - ugly, but it works.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-05-16 19:38:00 +00:00
|
|
|
QVariant DviGenerator::metaData( const QString & key, const QVariant & option ) const
|
|
|
|
{
|
|
|
|
if ( key == "NamedViewport" && !option.toString().isEmpty() )
|
|
|
|
{
|
|
|
|
const Anchor anchor = m_dviRenderer->parseReference( option.toString() );
|
|
|
|
if ( anchor.isValid() )
|
|
|
|
{
|
|
|
|
const Okular::Page *page = document()->page( anchor.page - 1 );
|
|
|
|
Q_ASSERT_X( page, "DviGenerator::metaData()", "NULL page as result of valid Anchor" );
|
|
|
|
Okular::DocumentViewport viewport;
|
2010-01-08 00:01:28 +00:00
|
|
|
fillViewportFromAnchor( viewport, anchor, page );
|
2009-05-16 19:38:00 +00:00
|
|
|
if ( viewport.isValid() )
|
|
|
|
{
|
|
|
|
return viewport.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
2007-12-30 16:41:10 +00:00
|
|
|
|
2014-09-11 19:12:27 +00:00
|
|
|
Q_LOGGING_CATEGORY(OkularDviDebug, "org.kde.okular.generators.dvi.core")
|
|
|
|
Q_LOGGING_CATEGORY(OkularDviShellDebug, "org.kde.okular.generators.dvi.shell")
|
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
#include "generator_dvi.moc"
|