2004-09-08 12:41:14 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
|
2004-09-23 21:33:53 +00:00
|
|
|
|
* Copyright (C) 2004 by Albert Astals Cid <tsdgeos@terra.es> *
|
2004-09-08 12:41:14 +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. *
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
2004-10-06 00:05:49 +00:00
|
|
|
|
// qt/kde/system includes
|
2004-12-05 22:47:32 +00:00
|
|
|
|
#include <qdatetime.h>
|
2004-10-06 00:05:49 +00:00
|
|
|
|
#include <qdir.h>
|
2004-09-08 12:41:14 +00:00
|
|
|
|
#include <qfile.h>
|
2004-10-06 00:05:49 +00:00
|
|
|
|
#include <qfileinfo.h>
|
2004-09-08 12:41:14 +00:00
|
|
|
|
#include <qmutex.h>
|
|
|
|
|
#include <qvaluevector.h>
|
2004-09-15 20:45:00 +00:00
|
|
|
|
#include <qmap.h>
|
2004-09-12 23:19:18 +00:00
|
|
|
|
#include <kdebug.h>
|
2004-09-16 21:04:49 +00:00
|
|
|
|
#include <klocale.h>
|
|
|
|
|
#include <kfinddialog.h>
|
|
|
|
|
#include <kmessagebox.h>
|
2004-10-17 18:40:02 +00:00
|
|
|
|
#include <kmimetype.h>
|
2004-09-23 22:11:44 +00:00
|
|
|
|
#include <kpassdlg.h>
|
2004-11-03 21:37:21 +00:00
|
|
|
|
#include <kprinter.h>
|
2004-09-17 17:58:42 +00:00
|
|
|
|
#include <kstandarddirs.h>
|
2004-11-03 21:37:21 +00:00
|
|
|
|
#include <ktempfile.h>
|
2004-10-06 00:05:49 +00:00
|
|
|
|
#include <kapplication.h>
|
|
|
|
|
#include <krun.h>
|
|
|
|
|
#include <kurl.h>
|
|
|
|
|
#include <kuserprofile.h>
|
|
|
|
|
#include <string.h>
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
|
|
|
|
// local includes
|
2004-09-23 22:11:44 +00:00
|
|
|
|
#include "ErrorCodes.h"
|
2004-09-08 12:41:14 +00:00
|
|
|
|
#include "PDFDoc.h"
|
2004-11-03 21:37:21 +00:00
|
|
|
|
#include "PSOutputDev.h"
|
2004-09-10 17:44:05 +00:00
|
|
|
|
#include "QOutputDev.h"
|
2004-12-05 22:47:32 +00:00
|
|
|
|
#include "UnicodeMap.h"
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
|
|
|
|
#include "document.h"
|
|
|
|
|
#include "page.h"
|
2004-10-27 14:07:24 +00:00
|
|
|
|
#include "settings.h"
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
2004-09-09 13:25:40 +00:00
|
|
|
|
/* Notes:
|
2004-11-25 19:42:04 +00:00
|
|
|
|
- FIXME event queuing to avoid flow loops (!!?) maybe avoided by the
|
2004-09-09 13:25:40 +00:00
|
|
|
|
warning to not call something 'active' inside an observer method.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-09-26 23:39:39 +00:00
|
|
|
|
// structure used internally by KPDFDocument for local variables storage
|
2004-09-09 13:25:40 +00:00
|
|
|
|
class KPDFDocumentPrivate
|
2004-09-08 12:41:14 +00:00
|
|
|
|
{
|
2004-09-09 13:25:40 +00:00
|
|
|
|
public:
|
2004-12-05 22:47:32 +00:00
|
|
|
|
// Albert says: I've put that two functions here but they could go
|
|
|
|
|
// elsewhere, i leave it up to you if you want to change them Enrico
|
|
|
|
|
QString getDocumentInfo(const QString &data) const
|
|
|
|
|
{
|
|
|
|
|
// Code adapted from pdfinfo.cc on xpdf
|
|
|
|
|
Object info;
|
|
|
|
|
if (pdfdoc)
|
|
|
|
|
{
|
|
|
|
|
pdfdoc->getDocInfo(&info);
|
|
|
|
|
if (info.isDict())
|
|
|
|
|
{
|
|
|
|
|
QCString result;
|
|
|
|
|
Object obj;
|
|
|
|
|
GString *s1;
|
|
|
|
|
GBool isUnicode;
|
|
|
|
|
Unicode u;
|
|
|
|
|
char buf[8];
|
|
|
|
|
int i, n;
|
|
|
|
|
Dict *infoDict = info.getDict();
|
|
|
|
|
UnicodeMap *uMap = globalParams->getTextEncoding();
|
|
|
|
|
|
|
|
|
|
if (!uMap) return i18n("Unknown");
|
|
|
|
|
|
|
|
|
|
if (infoDict->lookup(data.latin1(), &obj)->isString())
|
|
|
|
|
{
|
|
|
|
|
s1 = obj.getString();
|
|
|
|
|
if ((s1->getChar(0) & 0xff) == 0xfe && (s1->getChar(1) & 0xff) == 0xff)
|
|
|
|
|
{
|
|
|
|
|
isUnicode = gTrue;
|
|
|
|
|
i = 2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
isUnicode = gFalse;
|
|
|
|
|
i = 0;
|
|
|
|
|
}
|
|
|
|
|
while (i < obj.getString()->getLength())
|
|
|
|
|
{
|
|
|
|
|
if (isUnicode)
|
|
|
|
|
{
|
|
|
|
|
u = ((s1->getChar(i) & 0xff) << 8) | (s1->getChar(i+1) & 0xff);
|
|
|
|
|
i += 2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
u = s1->getChar(i) & 0xff;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
n = uMap->mapUnicode(u, buf, sizeof(buf));
|
|
|
|
|
result += QCString(buf, n + 1);
|
|
|
|
|
}
|
|
|
|
|
obj.free();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
obj.free();
|
|
|
|
|
return i18n("Unknown");
|
|
|
|
|
}
|
|
|
|
|
else return i18n("Unknown");
|
|
|
|
|
}
|
|
|
|
|
else return i18n("Unknown");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString getDocumentDate(const QString &data) const
|
|
|
|
|
{
|
|
|
|
|
// Code adapted from pdfinfo.cc on xpdf
|
|
|
|
|
Object info;
|
|
|
|
|
if (pdfdoc)
|
|
|
|
|
{
|
|
|
|
|
pdfdoc->getDocInfo(&info);
|
|
|
|
|
if (info.isDict())
|
|
|
|
|
{
|
|
|
|
|
Object obj;
|
|
|
|
|
char *s;
|
|
|
|
|
int year, mon, day, hour, min, sec;
|
|
|
|
|
Dict *infoDict = info.getDict();
|
|
|
|
|
UnicodeMap *uMap = globalParams->getTextEncoding();
|
|
|
|
|
|
|
|
|
|
if (!uMap) return i18n("Unknown");
|
|
|
|
|
|
|
|
|
|
if (infoDict->lookup(data.latin1(), &obj)->isString())
|
|
|
|
|
{
|
|
|
|
|
s = obj.getString()->getCString();
|
|
|
|
|
if (s[0] == 'D' && s[1] == ':') s += 2;
|
|
|
|
|
if (sscanf(s, "%4d%2d%2d%2d%2d%2d", &year, &mon, &day, &hour, &min, &sec) == 6)
|
|
|
|
|
{
|
|
|
|
|
QDate d(year, mon - 1, day);
|
|
|
|
|
QTime t(hour, min, sec);
|
|
|
|
|
if (d.isValid() && t.isValid()) return KGlobal::locale()->formatDateTime(QDateTime(d, t), false, true);
|
|
|
|
|
else return s;
|
|
|
|
|
}
|
|
|
|
|
else return s;
|
|
|
|
|
fputc('\n', stdout);
|
|
|
|
|
obj.free();
|
|
|
|
|
//return result;
|
|
|
|
|
}
|
|
|
|
|
obj.free();
|
|
|
|
|
return i18n("Unknown");
|
|
|
|
|
}
|
|
|
|
|
else return i18n("Unknown");
|
|
|
|
|
}
|
|
|
|
|
else return i18n("Unknown");
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
|
// document related
|
|
|
|
|
QMutex docLock;
|
|
|
|
|
PDFDoc * pdfdoc;
|
2004-09-15 20:45:00 +00:00
|
|
|
|
KPDFOutputDev * kpdfOutputDev;
|
2004-09-08 12:41:14 +00:00
|
|
|
|
int currentPage;
|
2004-10-10 13:21:30 +00:00
|
|
|
|
QRect currentViewport;
|
2004-09-08 12:41:14 +00:00
|
|
|
|
QValueVector< KPDFPage* > pages;
|
2004-11-09 17:20:19 +00:00
|
|
|
|
QColor paperColor;
|
2004-09-12 23:19:18 +00:00
|
|
|
|
|
2004-09-16 21:04:49 +00:00
|
|
|
|
// find related
|
2004-09-17 17:58:42 +00:00
|
|
|
|
QString searchText;
|
|
|
|
|
bool searchCase;
|
|
|
|
|
int searchPage;
|
2004-09-16 21:04:49 +00:00
|
|
|
|
// filtering related
|
2004-09-17 17:58:42 +00:00
|
|
|
|
QString filterText;
|
|
|
|
|
bool filterCase;
|
2004-09-16 21:04:49 +00:00
|
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
|
// observers related (note: won't delete oservers)
|
2004-09-15 20:45:00 +00:00
|
|
|
|
QMap< int, KPDFDocumentObserver* > observers;
|
2004-09-08 12:41:14 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define foreachObserver( cmd ) {\
|
2004-09-15 20:45:00 +00:00
|
|
|
|
QMap<int,KPDFDocumentObserver*>::iterator it = d->observers.begin();\
|
|
|
|
|
QMap<int,KPDFDocumentObserver*>::iterator end = d->observers.end();\
|
2004-09-08 12:41:14 +00:00
|
|
|
|
for ( ; it != end ; ++ it ) { (*it)-> cmd ; } }
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* KPDFDocument class
|
|
|
|
|
*/
|
|
|
|
|
KPDFDocument::KPDFDocument()
|
|
|
|
|
{
|
|
|
|
|
d = new KPDFDocumentPrivate;
|
|
|
|
|
d->pdfdoc = 0;
|
2004-09-09 13:25:40 +00:00
|
|
|
|
d->currentPage = -1;
|
2004-09-17 17:58:42 +00:00
|
|
|
|
d->searchPage = -1;
|
2004-11-09 17:20:19 +00:00
|
|
|
|
d->kpdfOutputDev = 0;
|
|
|
|
|
// create the outputdev
|
|
|
|
|
reparseConfig();
|
2004-09-08 12:41:14 +00:00
|
|
|
|
}
|
2004-09-12 23:19:18 +00:00
|
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
|
KPDFDocument::~KPDFDocument()
|
|
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
|
closeDocument();
|
2004-09-15 20:45:00 +00:00
|
|
|
|
delete d->kpdfOutputDev;
|
2004-09-08 12:41:14 +00:00
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-27 14:07:24 +00:00
|
|
|
|
|
2004-09-17 17:58:42 +00:00
|
|
|
|
bool KPDFDocument::openDocument( const QString & docFile )
|
2004-09-08 12:41:14 +00:00
|
|
|
|
{
|
|
|
|
|
// docFile is always local so we can use QFile on it
|
|
|
|
|
QFile fileReadTest( docFile );
|
|
|
|
|
if ( !fileReadTest.open( IO_ReadOnly ) )
|
|
|
|
|
return false;
|
2004-09-17 17:58:42 +00:00
|
|
|
|
long fileSize = fileReadTest.size();
|
2004-09-08 12:41:14 +00:00
|
|
|
|
fileReadTest.close();
|
|
|
|
|
|
2004-09-17 17:58:42 +00:00
|
|
|
|
// free internal data
|
|
|
|
|
closeDocument();
|
|
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
|
GString *filename = new GString( QFile::encodeName( docFile ) );
|
|
|
|
|
delete d->pdfdoc;
|
2004-09-10 17:44:05 +00:00
|
|
|
|
d->pdfdoc = new PDFDoc( filename, 0, 0 );
|
2004-09-11 15:59:32 +00:00
|
|
|
|
|
|
|
|
|
if ( !d->pdfdoc->isOk() )
|
2004-09-08 12:41:14 +00:00
|
|
|
|
{
|
2004-09-23 22:11:44 +00:00
|
|
|
|
if (d->pdfdoc->getErrorCode() == errEncrypted)
|
|
|
|
|
{
|
|
|
|
|
bool first, correct;
|
|
|
|
|
QString prompt;
|
|
|
|
|
QCString pwd;
|
|
|
|
|
|
|
|
|
|
first = true;
|
|
|
|
|
correct = false;
|
|
|
|
|
while(!correct)
|
|
|
|
|
{
|
|
|
|
|
if (first)
|
|
|
|
|
{
|
|
|
|
|
prompt = i18n("Please insert the password to read the document:");
|
|
|
|
|
first = false;
|
|
|
|
|
}
|
|
|
|
|
else prompt = i18n("Incorrect password. Try again:");
|
|
|
|
|
if (KPasswordDialog::getPassword(pwd, prompt) == KPasswordDialog::Accepted)
|
|
|
|
|
{
|
|
|
|
|
GString *pwd2;
|
|
|
|
|
pwd2 = new GString(pwd.data());
|
|
|
|
|
d->pdfdoc = new PDFDoc(filename, pwd2, pwd2);
|
|
|
|
|
delete pwd2;
|
|
|
|
|
correct = d->pdfdoc->isOk();
|
|
|
|
|
if (!correct && d->pdfdoc->getErrorCode() != errEncrypted)
|
|
|
|
|
{
|
|
|
|
|
delete d->pdfdoc;
|
|
|
|
|
d->pdfdoc = 0;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
delete d->pdfdoc;
|
|
|
|
|
d->pdfdoc = 0;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
delete d->pdfdoc;
|
|
|
|
|
d->pdfdoc = 0;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2004-09-08 12:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-11 15:59:32 +00:00
|
|
|
|
// initialize output device for rendering current pdf
|
2004-09-15 20:45:00 +00:00
|
|
|
|
d->kpdfOutputDev->startDoc( d->pdfdoc->getXRef() );
|
2004-09-11 15:59:32 +00:00
|
|
|
|
|
|
|
|
|
// build Pages (currentPage was set -1 by deletePages)
|
2004-09-08 12:41:14 +00:00
|
|
|
|
uint pageCount = d->pdfdoc->getNumPages();
|
|
|
|
|
d->pages.resize( pageCount );
|
2004-09-11 15:59:32 +00:00
|
|
|
|
if ( pageCount > 0 )
|
|
|
|
|
{
|
|
|
|
|
for ( uint i = 0; i < pageCount ; i++ )
|
|
|
|
|
d->pages[i] = new KPDFPage( i, d->pdfdoc->getPageWidth(i+1), d->pdfdoc->getPageHeight(i+1), d->pdfdoc->getPageRotate(i+1) );
|
|
|
|
|
// filter pages, setup observers and set the first page as current
|
2004-09-17 17:58:42 +00:00
|
|
|
|
processPageList( true );
|
2004-11-09 17:20:19 +00:00
|
|
|
|
setCurrentPage( 0 );
|
2004-09-11 15:59:32 +00:00
|
|
|
|
}
|
2004-09-12 23:19:18 +00:00
|
|
|
|
|
2004-09-17 17:58:42 +00:00
|
|
|
|
// check local directory for an overlay xml
|
2004-10-24 09:10:24 +00:00
|
|
|
|
// TODO import overlay layers from XML
|
2004-09-17 17:58:42 +00:00
|
|
|
|
QString fileName = docFile.contains('/') ? docFile.section('/', -1, -1) : docFile;
|
|
|
|
|
fileName = "kpdf/" + QString::number(fileSize) + "." + fileName + ".xml";
|
|
|
|
|
QString localFN = locateLocal( "data", fileName );
|
2004-10-24 09:10:24 +00:00
|
|
|
|
//kdWarning() << localFN << endl;
|
2004-09-17 17:58:42 +00:00
|
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-17 17:58:42 +00:00
|
|
|
|
void KPDFDocument::closeDocument()
|
2004-09-08 12:41:14 +00:00
|
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
|
// delete pages and clear container
|
|
|
|
|
for ( uint i = 0; i < d->pages.count() ; i++ )
|
|
|
|
|
delete d->pages[i];
|
|
|
|
|
d->pages.clear();
|
|
|
|
|
|
|
|
|
|
// broadcast zero pages
|
|
|
|
|
processPageList( true );
|
|
|
|
|
|
|
|
|
|
// reset internal variables
|
|
|
|
|
d->currentPage = -1;
|
|
|
|
|
d->searchPage = -1;
|
|
|
|
|
|
|
|
|
|
// delete xpds's PDFDoc contents generator
|
2004-09-08 12:41:14 +00:00
|
|
|
|
delete d->pdfdoc;
|
|
|
|
|
d->pdfdoc = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-09 13:25:40 +00:00
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
|
void KPDFDocument::addObserver( KPDFDocumentObserver * pObserver )
|
2004-09-08 12:41:14 +00:00
|
|
|
|
{
|
2004-11-09 17:20:19 +00:00
|
|
|
|
d->observers[ pObserver->observerId() ] = pObserver;
|
2004-09-08 12:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
|
void KPDFDocument::reparseConfig()
|
2004-09-08 12:41:14 +00:00
|
|
|
|
{
|
2004-11-09 17:20:19 +00:00
|
|
|
|
// load paper color from Settings or use the white default color
|
|
|
|
|
QColor color = ( (Settings::renderMode() == Settings::EnumRenderMode::Paper ) &&
|
|
|
|
|
Settings::changeColors() ) ? Settings::paperColor() : Qt::white;
|
2004-11-12 10:58:33 +00:00
|
|
|
|
// if paper color changed we have to rebuild every visible pixmap in addition to
|
|
|
|
|
// the outputDevice. it's the 'heaviest' case, other effect are just recoloring
|
|
|
|
|
// over the page rendered on 'standard' white background.
|
2004-11-09 17:20:19 +00:00
|
|
|
|
if ( color != d->paperColor || !d->kpdfOutputDev )
|
|
|
|
|
{
|
|
|
|
|
d->paperColor = color;
|
|
|
|
|
SplashColor paperColor;
|
|
|
|
|
paperColor.rgb8 = splashMakeRGB8( d->paperColor.red(), d->paperColor.green(), d->paperColor.blue() );
|
|
|
|
|
// rebuild the output device using the new paper color
|
|
|
|
|
d->docLock.lock();
|
|
|
|
|
delete d->kpdfOutputDev;
|
|
|
|
|
d->kpdfOutputDev = new KPDFOutputDev( paperColor );
|
|
|
|
|
if ( d->pdfdoc )
|
|
|
|
|
d->kpdfOutputDev->startDoc( d->pdfdoc->getXRef() );
|
|
|
|
|
d->docLock.unlock();
|
2004-11-12 10:58:33 +00:00
|
|
|
|
// invalidate pixmaps and send reload signals to observers
|
|
|
|
|
QValueVector<KPDFPage*>::iterator it = d->pages.begin(), end = d->pages.end();
|
|
|
|
|
for ( ; it != end; ++it )
|
|
|
|
|
(*it)->deletePixmapsAndLinks();
|
|
|
|
|
foreachObserver( notifyPixmapsCleared() );
|
2004-11-09 17:20:19 +00:00
|
|
|
|
}
|
2004-09-08 12:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
|
|
|
|
|
|
uint KPDFDocument::currentPage() const
|
2004-09-09 13:25:40 +00:00
|
|
|
|
{
|
2004-11-09 17:20:19 +00:00
|
|
|
|
return d->currentPage;
|
2004-09-09 13:25:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
|
uint KPDFDocument::pages() const
|
2004-09-09 13:25:40 +00:00
|
|
|
|
{
|
2004-11-09 17:20:19 +00:00
|
|
|
|
return d->pdfdoc ? d->pdfdoc->getNumPages() : 0;
|
2004-09-09 13:25:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-12-05 22:47:32 +00:00
|
|
|
|
QString KPDFDocument::author() const
|
|
|
|
|
{
|
|
|
|
|
return d->getDocumentInfo("Author");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString KPDFDocument::creationDate() const
|
|
|
|
|
{
|
|
|
|
|
return d->getDocumentDate("CreationDate");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString KPDFDocument::creator() const
|
|
|
|
|
{
|
|
|
|
|
return d->getDocumentInfo("Creator");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool KPDFDocument::encrypted() const
|
|
|
|
|
{
|
|
|
|
|
if (d->pdfdoc) return d->pdfdoc->isEncrypted();
|
|
|
|
|
else return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString KPDFDocument::keywords() const
|
|
|
|
|
{
|
|
|
|
|
return d->getDocumentInfo("Keywords");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString KPDFDocument::modificationDate() const
|
|
|
|
|
{
|
|
|
|
|
return d->getDocumentDate("ModDate");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool KPDFDocument::optimized() const
|
|
|
|
|
{
|
|
|
|
|
if (d->pdfdoc) return d->pdfdoc->isLinearized();
|
|
|
|
|
else return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float KPDFDocument::PDFversion() const
|
|
|
|
|
{
|
|
|
|
|
if (d->pdfdoc) return d->pdfdoc->getPDFVersion();
|
|
|
|
|
else return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString KPDFDocument::producer() const
|
|
|
|
|
{
|
|
|
|
|
return d->getDocumentInfo("Producer");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString KPDFDocument::subject() const
|
|
|
|
|
{
|
|
|
|
|
return d->getDocumentInfo("Subject");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString KPDFDocument::title() const
|
|
|
|
|
{
|
|
|
|
|
return d->getDocumentInfo("Title");
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
|
bool KPDFDocument::okToPrint() const
|
2004-09-09 13:25:40 +00:00
|
|
|
|
{
|
2004-11-09 17:20:19 +00:00
|
|
|
|
return d->pdfdoc->okToPrint();
|
2004-09-09 13:25:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-23 21:33:53 +00:00
|
|
|
|
Outline * KPDFDocument::outline() const
|
|
|
|
|
{
|
|
|
|
|
return d->pdfdoc ? d->pdfdoc->getOutline() : 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
|
const KPDFPage * KPDFDocument::page( uint n ) const
|
2004-09-15 20:45:00 +00:00
|
|
|
|
{
|
2004-11-09 17:20:19 +00:00
|
|
|
|
return ( n < d->pages.count() ) ? d->pages[n] : 0;
|
2004-09-15 20:45:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
|
|
2004-09-15 20:45:00 +00:00
|
|
|
|
void KPDFDocument::requestPixmap( int id, uint page, int width, int height, bool syn )
|
|
|
|
|
{
|
|
|
|
|
KPDFPage * kp = d->pages[page];
|
|
|
|
|
if ( !d->pdfdoc || !kp || kp->width() < 1 || kp->height() < 1 )
|
|
|
|
|
return;
|
|
|
|
|
|
2004-11-06 00:56:55 +00:00
|
|
|
|
//kdDebug() << "id: " << id << " is requesting pixmap for page " << page << " [" << width << " x " << height << "]." << endl;
|
2004-09-15 20:45:00 +00:00
|
|
|
|
if ( syn )
|
|
|
|
|
{
|
|
|
|
|
// in-place Pixmap generation for syncronous requests
|
|
|
|
|
if ( !kp->hasPixmap( id, width, height ) )
|
|
|
|
|
{
|
|
|
|
|
// compute dpi used to get an image with desired width and height
|
|
|
|
|
double fakeDpiX = width * 72.0 / kp->width(),
|
|
|
|
|
fakeDpiY = height * 72.0 / kp->height();
|
2004-09-16 21:04:49 +00:00
|
|
|
|
|
|
|
|
|
// setup kpdf 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 = !kp->hasSearchPage() && (width == kp->width()) && (height == kp->height());
|
2004-11-07 14:15:33 +00:00
|
|
|
|
// generate links and activeRects if rendering pages on pageview
|
2004-10-02 14:30:30 +00:00
|
|
|
|
bool genLinks = id == PAGEVIEW_ID;
|
2004-11-07 14:15:33 +00:00
|
|
|
|
d->kpdfOutputDev->setParams( width, height, genTextPage, genLinks, genLinks );
|
2004-09-16 21:04:49 +00:00
|
|
|
|
|
2004-09-15 20:45:00 +00:00
|
|
|
|
d->docLock.lock();
|
2004-10-02 14:30:30 +00:00
|
|
|
|
d->pdfdoc->displayPage( d->kpdfOutputDev, page + 1, fakeDpiX, fakeDpiY, 0, true, genLinks );
|
2004-09-15 20:45:00 +00:00
|
|
|
|
d->docLock.unlock();
|
|
|
|
|
|
|
|
|
|
kp->setPixmap( id, d->kpdfOutputDev->takePixmap() );
|
2004-09-16 21:04:49 +00:00
|
|
|
|
if ( genTextPage )
|
|
|
|
|
kp->setSearchPage( d->kpdfOutputDev->takeTextPage() );
|
2004-10-02 14:30:30 +00:00
|
|
|
|
if ( genLinks )
|
2004-11-07 14:15:33 +00:00
|
|
|
|
{
|
2004-10-02 14:30:30 +00:00
|
|
|
|
kp->setLinks( d->kpdfOutputDev->takeLinks() );
|
2004-11-07 14:15:33 +00:00
|
|
|
|
kp->setActiveRects( d->kpdfOutputDev->takeActiveRects() );
|
|
|
|
|
}
|
2004-09-15 20:45:00 +00:00
|
|
|
|
|
|
|
|
|
d->observers[id]->notifyPixmapChanged( page );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//TODO asyncronous events queuing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-09 08:10:56 +00:00
|
|
|
|
void KPDFDocument::requestTextPage( uint n )
|
|
|
|
|
{
|
|
|
|
|
KPDFPage * page = d->pages[ n ];
|
|
|
|
|
// build a TextPage using the lightweight KPDFTextDev generator..
|
|
|
|
|
KPDFTextDev td;
|
|
|
|
|
d->docLock.lock();
|
|
|
|
|
d->pdfdoc->displayPage( &td, page->number()+1, 72, 72, 0, true, false );
|
|
|
|
|
d->docLock.unlock();
|
|
|
|
|
// ..and attach it to the page
|
|
|
|
|
page->setSearchPage( td.takeTextPage() );
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
|
void KPDFDocument::setCurrentPage( int page, const QRect & viewport )
|
2004-09-09 13:25:40 +00:00
|
|
|
|
{
|
2004-10-10 13:21:30 +00:00
|
|
|
|
if ( page < 0 )
|
2004-10-09 08:10:56 +00:00
|
|
|
|
page = 0;
|
2004-10-10 13:21:30 +00:00
|
|
|
|
else if ( page > (int)d->pages.count() )
|
|
|
|
|
page = d->pages.count() - 1;
|
|
|
|
|
if ( page == d->currentPage && viewport == d->currentViewport )
|
2004-09-08 12:41:14 +00:00
|
|
|
|
return;
|
|
|
|
|
d->currentPage = page;
|
2004-10-10 13:21:30 +00:00
|
|
|
|
d->currentViewport = viewport;
|
|
|
|
|
foreachObserver( pageSetCurrent( page, viewport ) );
|
2004-09-08 12:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
|
void KPDFDocument::findText( const QString & string, bool keepCase )
|
2004-09-16 21:04:49 +00:00
|
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
|
// turn selection drawing off on filtered pages
|
|
|
|
|
if ( !d->filterText.isEmpty() )
|
|
|
|
|
unHilightPages();
|
|
|
|
|
|
|
|
|
|
// save params for the 'find next' case
|
|
|
|
|
if ( !string.isEmpty() )
|
2004-09-08 12:41:14 +00:00
|
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
|
d->searchText = string;
|
|
|
|
|
d->searchCase = keepCase;
|
2004-09-08 12:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-16 21:04:49 +00:00
|
|
|
|
// continue checking last SearchPage first (if it is the current page)
|
|
|
|
|
int currentPage = d->currentPage;
|
|
|
|
|
int pageCount = d->pages.count();
|
2004-09-17 17:58:42 +00:00
|
|
|
|
KPDFPage * foundPage = 0,
|
|
|
|
|
* lastPage = (d->searchPage > -1) ? d->pages[ d->searchPage ] : 0;
|
|
|
|
|
if ( lastPage && d->searchPage == currentPage )
|
|
|
|
|
if ( lastPage->hasText( d->searchText, d->searchCase, false ) )
|
|
|
|
|
foundPage = lastPage;
|
2004-09-16 21:04:49 +00:00
|
|
|
|
else
|
2004-09-08 12:41:14 +00:00
|
|
|
|
{
|
2004-11-06 00:56:55 +00:00
|
|
|
|
lastPage->clearAttribute( KPDFPage::Highlight );
|
2004-09-16 21:04:49 +00:00
|
|
|
|
currentPage++;
|
|
|
|
|
pageCount--;
|
2004-09-08 12:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-16 21:04:49 +00:00
|
|
|
|
if ( !foundPage )
|
|
|
|
|
// loop through the whole document
|
|
|
|
|
for ( int i = 0; i < pageCount; i++ )
|
2004-09-13 08:51:36 +00:00
|
|
|
|
{
|
2004-09-16 21:04:49 +00:00
|
|
|
|
if ( currentPage >= pageCount )
|
|
|
|
|
{
|
|
|
|
|
if ( KMessageBox::questionYesNo(0, i18n("End of document reached.\nContinue from the beginning?")) == KMessageBox::Yes )
|
|
|
|
|
currentPage = 0;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
KPDFPage * page = d->pages[ currentPage ];
|
|
|
|
|
if ( !page->hasSearchPage() )
|
2004-10-09 08:10:56 +00:00
|
|
|
|
requestTextPage( page->number() );
|
2004-09-17 17:58:42 +00:00
|
|
|
|
if ( page->hasText( d->searchText, d->searchCase, true ) )
|
2004-09-16 21:04:49 +00:00
|
|
|
|
{
|
|
|
|
|
foundPage = page;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
currentPage++;
|
2004-09-13 08:51:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-16 21:04:49 +00:00
|
|
|
|
if ( foundPage )
|
2004-09-08 12:41:14 +00:00
|
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
|
int pageNumber = foundPage->number();
|
|
|
|
|
d->searchPage = pageNumber;
|
2004-11-06 00:56:55 +00:00
|
|
|
|
foundPage->setAttribute( KPDFPage::Highlight );
|
2004-11-09 17:20:19 +00:00
|
|
|
|
setCurrentPage( pageNumber );
|
2004-09-17 17:58:42 +00:00
|
|
|
|
foreachObserver( notifyPixmapChanged( pageNumber ) );
|
2004-09-08 12:41:14 +00:00
|
|
|
|
}
|
2004-09-16 21:04:49 +00:00
|
|
|
|
else
|
2004-09-17 17:58:42 +00:00
|
|
|
|
KMessageBox::information( 0, i18n("No matches found for '%1'.").arg(d->searchText) );
|
2004-09-08 12:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-11-09 17:20:19 +00:00
|
|
|
|
void KPDFDocument::findTextAll( const QString & pattern, bool keepCase )
|
|
|
|
|
{
|
|
|
|
|
d->filterText = pattern;
|
|
|
|
|
d->filterCase = keepCase;
|
|
|
|
|
processPageList( false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KPDFDocument::toggleBookmark( int n )
|
|
|
|
|
{
|
|
|
|
|
KPDFPage * page = ( n < (int)d->pages.count() ) ? d->pages[ n ] : 0;
|
|
|
|
|
if ( page )
|
|
|
|
|
{
|
|
|
|
|
page->toggleAttribute( KPDFPage::Bookmark );
|
|
|
|
|
foreachObserver( notifyPixmapChanged( n ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KPDFDocument::processLink( const KPDFLink * link )
|
2004-09-08 12:41:14 +00:00
|
|
|
|
{
|
2004-10-06 00:05:49 +00:00
|
|
|
|
if ( !link )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch( link->type() )
|
|
|
|
|
{
|
|
|
|
|
case KPDFLink::Goto: {
|
|
|
|
|
// make copies of the 'nameDest' (string) and the 'dest' (class)
|
|
|
|
|
char * namedDest = 0;
|
|
|
|
|
link->copyString( namedDest, link->getNamedDest() );
|
|
|
|
|
LinkDest * dest = link->getDest() ? ((LinkDest*)link->getDest())->copy() : 0;
|
|
|
|
|
|
|
|
|
|
// first open filename if link is pointing outside this document
|
|
|
|
|
QString fileName( link->getFileName() );
|
|
|
|
|
if ( !fileName.isNull() )
|
|
|
|
|
if ( !openRelativeFile( fileName ) )
|
|
|
|
|
{
|
|
|
|
|
kdWarning() << "Link: Error opening '" << fileName << "'." << endl;
|
|
|
|
|
delete dest;
|
|
|
|
|
delete namedDest;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now previous KPDFLink and KPDFPage don't exist anymore!
|
|
|
|
|
if ( namedDest && !dest )
|
|
|
|
|
{
|
|
|
|
|
GString temp( namedDest );
|
2004-10-09 08:10:56 +00:00
|
|
|
|
d->docLock.lock();
|
2004-10-06 00:05:49 +00:00
|
|
|
|
dest = d->pdfdoc->findDest( &temp );
|
|
|
|
|
d->docLock.unlock();
|
|
|
|
|
}
|
2004-10-09 08:10:56 +00:00
|
|
|
|
if ( dest && dest->isOk() )
|
2004-10-06 00:05:49 +00:00
|
|
|
|
{
|
2004-10-10 13:21:30 +00:00
|
|
|
|
// get destination page number
|
|
|
|
|
int pageNum = dest->getPageNum() - 1;
|
2004-10-09 08:10:56 +00:00
|
|
|
|
if ( dest->isPageRef() )
|
|
|
|
|
{
|
|
|
|
|
Ref ref = dest->getPageRef();
|
|
|
|
|
d->docLock.lock();
|
2004-10-10 13:21:30 +00:00
|
|
|
|
pageNum = d->pdfdoc->findPage( ref.num, ref.gen ) - 1;
|
2004-10-09 08:10:56 +00:00
|
|
|
|
d->docLock.unlock();
|
|
|
|
|
}
|
|
|
|
|
// get destination position
|
2004-10-10 13:21:30 +00:00
|
|
|
|
QRect r;
|
2004-10-27 14:07:24 +00:00
|
|
|
|
//KPDFPage * page = (pageNum >= 0 && pageNum < (int)d->pages.count()) ? d->pages[ pageNum ] : 0;
|
2004-10-10 13:21:30 +00:00
|
|
|
|
//if ( page )
|
2004-10-09 08:10:56 +00:00
|
|
|
|
/* TODO
|
|
|
|
|
switch ( dest->getKind() )
|
|
|
|
|
{
|
|
|
|
|
case destXYZ
|
2004-10-10 13:21:30 +00:00
|
|
|
|
OD -> cvtUserToDev( dest->getLeft(), dest->getTop(), &X, &Y );<EFBFBD>
|
2004-10-09 08:10:56 +00:00
|
|
|
|
if ( dest->getChangeLeft() )
|
|
|
|
|
make hor change
|
|
|
|
|
if ( dest->getChangeTop() )
|
|
|
|
|
make ver change
|
|
|
|
|
if ( dest->getChangeZoom() )
|
|
|
|
|
make zoom change
|
|
|
|
|
case destFit
|
|
|
|
|
case destFitB
|
|
|
|
|
fit page
|
|
|
|
|
case destFitH
|
|
|
|
|
case destFitBH
|
|
|
|
|
read top, fit Width
|
|
|
|
|
case destFitV
|
|
|
|
|
case destFitBV
|
|
|
|
|
read left, fit Height
|
|
|
|
|
destFitR
|
|
|
|
|
read and fit left,bottom,right,top
|
|
|
|
|
}*/
|
2004-11-09 17:20:19 +00:00
|
|
|
|
setCurrentPage( pageNum, r );
|
2004-10-06 00:05:49 +00:00
|
|
|
|
}
|
|
|
|
|
delete namedDest;
|
|
|
|
|
delete dest;
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case KPDFLink::Execute: {
|
|
|
|
|
QString fileName( link->getFileName() );
|
|
|
|
|
if ( fileName.endsWith( ".pdf" ) || fileName.endsWith( ".PDF" ) )
|
|
|
|
|
openRelativeFile( fileName );
|
|
|
|
|
else
|
2004-10-17 18:40:02 +00:00
|
|
|
|
{
|
|
|
|
|
KMimeType::Ptr mime;
|
|
|
|
|
KService::Ptr ptr;
|
2004-10-24 07:53:00 +00:00
|
|
|
|
|
2004-10-17 18:40:02 +00:00
|
|
|
|
// the only pdf i have that has that kind of link don't define an application
|
|
|
|
|
// and use the fileName as the file to open
|
2004-10-24 07:53:00 +00:00
|
|
|
|
|
2004-10-17 18:40:02 +00:00
|
|
|
|
fileName = giveAbsolutePath( fileName );
|
|
|
|
|
mime = KMimeType::findByPath( fileName );
|
|
|
|
|
// Check executables
|
|
|
|
|
if ( KRun::isExecutableFile( fileName, mime->name() ) )
|
|
|
|
|
{
|
|
|
|
|
// Don't have any pdf that uses this code path, just a guess on how it should work
|
|
|
|
|
if ( link->getParameters() )
|
|
|
|
|
{
|
|
|
|
|
fileName = giveAbsolutePath( link->getParameters() );
|
|
|
|
|
mime = KMimeType::findByPath( fileName );
|
|
|
|
|
if ( KRun::isExecutableFile( fileName, mime->name() ) )
|
|
|
|
|
{
|
|
|
|
|
// this case is a link pointing to an executable with a parameter
|
|
|
|
|
// that also is an executable, possibly a hand-crafted pdf
|
|
|
|
|
KMessageBox::information( 0, i18n("The pdf file is trying to execute an external application and for your safety kpdf does not allow that.") );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// this case is a link pointing to an executable with no parameters
|
|
|
|
|
// core developers find unacceptable executing it even after asking the user
|
|
|
|
|
KMessageBox::information( 0, i18n("The pdf file is trying to execute an external application and for your safety kpdf does not allow that.") );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-10-24 07:53:00 +00:00
|
|
|
|
|
2004-10-17 18:40:02 +00:00
|
|
|
|
ptr = KServiceTypeProfile::preferredService(mime->name(), "Application");
|
|
|
|
|
if (ptr)
|
|
|
|
|
{
|
|
|
|
|
KURL::List lst;
|
|
|
|
|
lst.append( fileName );
|
|
|
|
|
KRun::run( *ptr, lst );
|
|
|
|
|
}
|
|
|
|
|
else KMessageBox::information( 0, i18n("No application found for opening file of mimetype %1.").arg(mime->name()) );
|
|
|
|
|
}
|
2004-10-06 00:05:49 +00:00
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case KPDFLink::Named: {
|
|
|
|
|
const char * name = link->getName();
|
|
|
|
|
if ( !strcmp( name, "NextPage" ) && (d->currentPage < (int)d->pages.count() - 1) )
|
2004-11-09 17:20:19 +00:00
|
|
|
|
setCurrentPage( d->currentPage + 1 );
|
2004-10-06 00:05:49 +00:00
|
|
|
|
else if ( !strcmp( name, "PrevPage" ) && d->currentPage > 0 )
|
2004-11-09 17:20:19 +00:00
|
|
|
|
setCurrentPage( d->currentPage - 1 );
|
2004-10-06 00:05:49 +00:00
|
|
|
|
else if ( !strcmp( name, "FirstPage" ) )
|
2004-11-09 17:20:19 +00:00
|
|
|
|
setCurrentPage( 0 );
|
2004-10-06 00:05:49 +00:00
|
|
|
|
else if ( !strcmp( name, "LastPage" ) )
|
2004-11-09 17:20:19 +00:00
|
|
|
|
setCurrentPage( d->pages.count() - 1 );
|
2004-10-06 00:05:49 +00:00
|
|
|
|
else if ( !strcmp( name, "GoBack" ) )
|
|
|
|
|
{} //TODO
|
|
|
|
|
else if ( !strcmp( name, "GoForward" ) )
|
|
|
|
|
{} //TODO
|
|
|
|
|
else if ( !strcmp( name, "Quit" ) )
|
|
|
|
|
kapp->quit();
|
|
|
|
|
else
|
|
|
|
|
{}//FIXME error(-1, "Unknown named action: '%s'", name);
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case KPDFLink::URI: {
|
|
|
|
|
KService::Ptr ptr = KServiceTypeProfile::preferredService("text/html", "Application");
|
|
|
|
|
KURL::List lst;
|
|
|
|
|
lst.append( link->getURI() );
|
|
|
|
|
KRun::run( *ptr, lst );
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case KPDFLink::Movie:
|
|
|
|
|
case KPDFLink::Unknown:
|
|
|
|
|
// unimplemented cases
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-09-09 13:25:40 +00:00
|
|
|
|
}
|
2004-11-09 17:20:19 +00:00
|
|
|
|
|
|
|
|
|
bool KPDFDocument::print(KPrinter &printer)
|
|
|
|
|
{
|
|
|
|
|
KTempFile tf( QString::null, ".ps" );
|
|
|
|
|
PSOutputDev *psOut = new PSOutputDev(tf.name().latin1(), d->pdfdoc->getXRef(), d->pdfdoc->getCatalog(), 1, d->pdfdoc->getNumPages(), psModePS);
|
|
|
|
|
|
|
|
|
|
if (psOut->isOk())
|
|
|
|
|
{
|
|
|
|
|
std::list<int> pages;
|
|
|
|
|
|
|
|
|
|
if (!printer.previewOnly())
|
|
|
|
|
{
|
|
|
|
|
QValueList<int> pageList = printer.pageList();
|
|
|
|
|
QValueList<int>::const_iterator it;
|
|
|
|
|
|
|
|
|
|
for(it = pageList.begin(); it != pageList.end(); ++it) pages.push_back(*it);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for(int i = 1; i <= d->pdfdoc->getNumPages(); i++) pages.push_back(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d->docLock.lock();
|
|
|
|
|
d->pdfdoc->displayPages(psOut, pages, 72, 72, 0, globalParams->getPSCrop(), gFalse);
|
|
|
|
|
d->docLock.unlock();
|
|
|
|
|
|
|
|
|
|
// needs to be here so that the file is flushed, do not merge with the one
|
|
|
|
|
// in the else
|
|
|
|
|
delete psOut;
|
|
|
|
|
printer.printFiles(tf.name(), true);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
delete psOut;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-09-23 21:33:53 +00:00
|
|
|
|
//END slots
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
2004-10-17 18:40:02 +00:00
|
|
|
|
QString KPDFDocument::giveAbsolutePath( const QString & fileName )
|
|
|
|
|
{
|
|
|
|
|
const char * currentName = d->pdfdoc->getFileName()->getCString();
|
|
|
|
|
if ( !currentName || currentName[0] == 0 )
|
|
|
|
|
return QString::null;
|
|
|
|
|
|
|
|
|
|
// convert the pdf fileName to absolute using current pdf path
|
|
|
|
|
QFileInfo currentInfo( currentName );
|
|
|
|
|
return currentInfo.dir().absFilePath( fileName );
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-06 00:05:49 +00:00
|
|
|
|
bool KPDFDocument::openRelativeFile( const QString & fileName )
|
|
|
|
|
{
|
2004-10-17 18:40:02 +00:00
|
|
|
|
QString absFileName = giveAbsolutePath( fileName );
|
|
|
|
|
if ( absFileName.isNull() )
|
2004-10-06 00:05:49 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
kdDebug() << "openDocument: '" << absFileName << "'" << endl;
|
|
|
|
|
|
|
|
|
|
// open the absolute filename
|
|
|
|
|
return openDocument( absFileName );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-17 17:58:42 +00:00
|
|
|
|
void KPDFDocument::processPageList( bool documentChanged )
|
2004-09-09 13:25:40 +00:00
|
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
|
if ( d->filterText.length() < 3 )
|
|
|
|
|
unHilightPages();
|
|
|
|
|
else
|
2004-09-16 21:27:34 +00:00
|
|
|
|
{
|
2004-09-17 17:58:42 +00:00
|
|
|
|
uint pageCount = d->pages.count();
|
2004-09-15 20:45:00 +00:00
|
|
|
|
for ( uint i = 0; i < pageCount ; i++ )
|
2004-09-16 21:27:34 +00:00
|
|
|
|
{
|
|
|
|
|
KPDFPage * page = d->pages[ i ];
|
2004-11-06 00:56:55 +00:00
|
|
|
|
page->clearAttribute( KPDFPage::Highlight );
|
|
|
|
|
if ( d->filterText.length() > 2 )
|
2004-09-16 21:27:34 +00:00
|
|
|
|
{
|
|
|
|
|
if ( !page->hasSearchPage() )
|
|
|
|
|
{
|
|
|
|
|
// build a TextPage using the lightweight KPDFTextDev generator..
|
|
|
|
|
KPDFTextDev td;
|
|
|
|
|
d->docLock.lock();
|
|
|
|
|
d->pdfdoc->displayPage( &td, page->number()+1, 72, 72, 0, true, false );
|
|
|
|
|
d->docLock.unlock();
|
|
|
|
|
// ..and attach it to the page
|
|
|
|
|
page->setSearchPage( td.takeTextPage() );
|
|
|
|
|
}
|
2004-11-06 00:56:55 +00:00
|
|
|
|
if ( page->hasText( d->filterText, d->filterCase, true ) )
|
|
|
|
|
page->setAttribute( KPDFPage::Highlight );
|
2004-09-16 21:27:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
|
|
|
|
// send the list to observers
|
2004-09-17 17:58:42 +00:00
|
|
|
|
foreachObserver( pageSetup( d->pages, documentChanged ) );
|
2004-09-08 12:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-17 17:58:42 +00:00
|
|
|
|
void KPDFDocument::unHilightPages()
|
2004-09-08 12:41:14 +00:00
|
|
|
|
{
|
2004-10-24 07:53:00 +00:00
|
|
|
|
if ( d->filterText.isEmpty() )
|
2004-09-08 12:41:14 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2004-11-06 00:56:55 +00:00
|
|
|
|
d->filterText = QString::null;
|
2004-09-17 17:58:42 +00:00
|
|
|
|
QValueVector<KPDFPage*>::iterator it = d->pages.begin(), end = d->pages.end();
|
|
|
|
|
for ( ; it != end; ++it )
|
|
|
|
|
{
|
|
|
|
|
KPDFPage * page = *it;
|
2004-11-06 00:56:55 +00:00
|
|
|
|
if ( page->attributes() & KPDFPage::Highlight )
|
2004-09-17 17:58:42 +00:00
|
|
|
|
{
|
2004-11-06 00:56:55 +00:00
|
|
|
|
page->clearAttribute( KPDFPage::Highlight );
|
2004-09-17 17:58:42 +00:00
|
|
|
|
foreachObserver( notifyPixmapChanged( page->number() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-09-08 12:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-10 00:35:26 +00:00
|
|
|
|
/** TO BE IMPORTED:
|
|
|
|
|
void generateThumbnails(PDFDoc *doc);
|
|
|
|
|
void stopThumbnailGeneration();
|
|
|
|
|
protected slots:
|
|
|
|
|
void customEvent(QCustomEvent *e);
|
|
|
|
|
private slots:
|
|
|
|
|
void changeSelected(int i);
|
|
|
|
|
void emitClicked(int i);
|
|
|
|
|
signals:
|
|
|
|
|
void clicked(int);
|
|
|
|
|
private:
|
|
|
|
|
void generateNextThumbnail();
|
|
|
|
|
ThumbnailGenerator *m_tg;
|
|
|
|
|
|
|
|
|
|
void resizeThumbnails();
|
|
|
|
|
int m_nextThumbnail;
|
|
|
|
|
bool m_ignoreNext;
|
|
|
|
|
|
|
|
|
|
DELETE:
|
|
|
|
|
if (m_tg)
|
|
|
|
|
{
|
|
|
|
|
m_tg->wait();
|
|
|
|
|
delete m_tg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThumbnailList::generateThumbnails(PDFDoc *doc)
|
|
|
|
|
{
|
|
|
|
|
m_nextThumbnail = 1;
|
|
|
|
|
m_doc = doc;
|
|
|
|
|
generateNextThumbnail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThumbnailList::generateNextThumbnail()
|
|
|
|
|
{
|
|
|
|
|
if (m_tg)
|
|
|
|
|
{
|
|
|
|
|
m_tg->wait();
|
|
|
|
|
delete m_tg;
|
|
|
|
|
}
|
|
|
|
|
m_tg = new ThumbnailGenerator(m_doc, m_docMutex, m_nextThumbnail, QPaintDevice::x11AppDpiX(), this);
|
|
|
|
|
m_tg->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ThumbnailList::stopThumbnailGeneration()
|
|
|
|
|
{
|
|
|
|
|
if (m_tg)
|
|
|
|
|
{
|
|
|
|
|
m_ignoreNext = true;
|
|
|
|
|
m_tg->wait();
|
|
|
|
|
delete m_tg;
|
|
|
|
|
m_tg = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ThumbnailList::customEvent(QCustomEvent *e)
|
|
|
|
|
{
|
|
|
|
|
if (e->type() == 65432 && !m_ignoreNext)
|
|
|
|
|
{
|
|
|
|
|
QImage *i = (QImage*)(e -> data());
|
2004-09-23 21:33:53 +00:00
|
|
|
|
|
2004-09-10 00:35:26 +00:00
|
|
|
|
setThumbnail(m_nextThumbnail, i);
|
|
|
|
|
m_nextThumbnail++;
|
|
|
|
|
if (m_nextThumbnail <= m_doc->getNumPages()) generateNextThumbnail();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_tg->wait();
|
|
|
|
|
delete m_tg;
|
|
|
|
|
m_tg = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_ignoreNext = false;
|
|
|
|
|
}
|
|
|
|
|
*/
|