2006-07-20 20:47:05 +00:00
/***************************************************************************
* Copyright ( C ) 2005 by Piotr Szymanski < niedakh @ gmail . com > *
2008-08-01 20:26:22 +00:00
* Copyright ( C ) 2008 by Albert Astals Cid < aacid @ kde . org > *
2017-10-03 07:29:18 +00:00
* Copyright ( C ) 2017 Klarälvdalens Datakonsult AB , a KDAB Group *
* company , info @ kdab . com . Work sponsored by the *
* LiMux project of the city of Munich *
2006-07-20 20:47:05 +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 . *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-04-19 18:30:20 +00:00
# include "generator.h"
# include "generator_p.h"
2012-07-02 06:22:51 +00:00
# include "observer.h"
2007-04-19 18:30:20 +00:00
2017-10-14 12:47:20 +00:00
# include <QApplication>
2020-07-08 11:54:37 +00:00
# include <QEventLoop>
2018-08-31 09:23:45 +00:00
# include <QPrinter>
2007-10-08 21:49:27 +00:00
2014-10-14 05:37:01 +00:00
# include <KLocalizedString>
2018-08-31 09:23:45 +00:00
# include <QDebug>
2014-10-06 06:31:17 +00:00
# include <QIcon>
2014-10-08 11:48:01 +00:00
# include <QMimeDatabase>
2018-02-01 18:42:37 +00:00
# include <QTimer>
2018-04-16 20:35:40 +00:00
2020-09-09 12:13:09 +00:00
# ifdef WITH_KWALLET
2020-07-08 11:54:37 +00:00
# include <KWallet>
2020-09-09 12:13:09 +00:00
# endif
2006-03-21 20:00:24 +00:00
2007-09-14 15:29:16 +00:00
# include "document_p.h"
2007-01-31 18:31:19 +00:00
# include "page.h"
2014-02-19 22:40:43 +00:00
# include "page_p.h"
2007-10-08 21:49:27 +00:00
# include "textpage.h"
2008-05-18 23:06:21 +00:00
# include "utils.h"
2005-11-20 15:30:15 +00:00
2006-09-21 08:45:36 +00:00
using namespace Okular ;
2007-09-14 13:31:55 +00:00
GeneratorPrivate : : GeneratorPrivate ( )
2017-09-05 21:27:18 +00:00
: m_document ( nullptr )
, mPixmapGenerationThread ( nullptr )
, mTextPageGenerationThread ( nullptr )
2020-01-30 08:28:17 +00:00
, mPixmapReady ( true )
, mTextPageReady ( true )
2017-09-05 21:27:18 +00:00
, m_closing ( false )
, m_closingLoop ( nullptr )
2014-01-13 00:15:55 +00:00
, m_dpi ( 72.0 , 72.0 )
2007-04-20 17:17:44 +00:00
{
2017-11-02 22:41:12 +00:00
qRegisterMetaType < Okular : : Page * > ( ) ;
2007-04-20 17:17:44 +00:00
}
GeneratorPrivate : : ~ GeneratorPrivate ( )
2006-10-25 15:35:53 +00:00
{
2007-04-20 17:17:44 +00:00
if ( mPixmapGenerationThread )
mPixmapGenerationThread - > wait ( ) ;
delete mPixmapGenerationThread ;
if ( mTextPageGenerationThread )
mTextPageGenerationThread - > wait ( ) ;
delete mTextPageGenerationThread ;
}
2007-04-20 17:59:12 +00:00
PixmapGenerationThread * GeneratorPrivate : : pixmapGenerationThread ( )
2007-01-31 18:50:31 +00:00
{
if ( mPixmapGenerationThread )
2007-04-20 17:59:12 +00:00
return mPixmapGenerationThread ;
2007-01-31 18:50:31 +00:00
2007-09-14 13:31:55 +00:00
Q_Q ( Generator ) ;
mPixmapGenerationThread = new PixmapGenerationThread ( q ) ;
2019-12-19 22:18:31 +00:00
QObject : : connect (
mPixmapGenerationThread , & PixmapGenerationThread : : finished , q , [ this ] { pixmapGenerationFinished ( ) ; } , Qt : : QueuedConnection ) ;
2007-04-20 17:59:12 +00:00
return mPixmapGenerationThread ;
2007-01-31 18:50:31 +00:00
}
2007-04-20 17:59:12 +00:00
TextPageGenerationThread * GeneratorPrivate : : textPageGenerationThread ( )
2007-01-31 18:50:31 +00:00
{
if ( mTextPageGenerationThread )
2007-04-20 17:59:12 +00:00
return mTextPageGenerationThread ;
2007-01-31 18:50:31 +00:00
2007-09-14 13:31:55 +00:00
Q_Q ( Generator ) ;
mTextPageGenerationThread = new TextPageGenerationThread ( q ) ;
2019-12-19 22:18:31 +00:00
QObject : : connect (
mTextPageGenerationThread , & TextPageGenerationThread : : finished , q , [ this ] { textpageGenerationFinished ( ) ; } , Qt : : QueuedConnection ) ;
2007-04-20 17:59:12 +00:00
return mTextPageGenerationThread ;
2007-01-31 18:50:31 +00:00
}
2007-04-20 17:17:44 +00:00
void GeneratorPrivate : : pixmapGenerationFinished ( )
2007-01-31 18:31:19 +00:00
{
2007-09-14 13:31:55 +00:00
Q_Q ( Generator ) ;
2007-01-31 18:31:19 +00:00
PixmapRequest * request = mPixmapGenerationThread - > request ( ) ;
2018-02-01 18:42:37 +00:00
const QImage & img = mPixmapGenerationThread - > image ( ) ;
2007-01-31 18:31:19 +00:00
mPixmapGenerationThread - > endGeneration ( ) ;
2007-10-08 21:49:27 +00:00
QMutexLocker locker ( threadsLock ( ) ) ;
2007-01-31 18:31:19 +00:00
2007-10-08 21:49:27 +00:00
if ( m_closing ) {
2018-02-01 18:42:37 +00:00
mPixmapReady = true ;
2007-10-08 21:49:27 +00:00
delete request ;
if ( mTextPageReady ) {
locker . unlock ( ) ;
m_closingLoop - > quit ( ) ;
}
return ;
}
2018-02-01 18:42:37 +00:00
if ( ! request - > shouldAbortRender ( ) ) {
request - > page ( ) - > setPixmap ( request - > observer ( ) , new QPixmap ( QPixmap : : fromImage ( img ) ) , request - > normalizedRect ( ) ) ;
const int pageNumber = request - > page ( ) - > number ( ) ;
if ( mPixmapGenerationThread - > calcBoundingBox ( ) )
q - > updatePageBoundingBox ( pageNumber , mPixmapGenerationThread - > boundingBox ( ) ) ;
} else {
// Cancel the text page generation too if it's still running
if ( mTextPageGenerationThread & & mTextPageGenerationThread - > isRunning ( ) ) {
mTextPageGenerationThread - > abortExtraction ( ) ;
mTextPageGenerationThread - > wait ( ) ;
}
}
mPixmapReady = true ;
2012-07-17 18:35:54 +00:00
q - > signalPixmapRequestDone ( request ) ;
2007-01-31 18:31:19 +00:00
}
2007-04-20 17:17:44 +00:00
void GeneratorPrivate : : textpageGenerationFinished ( )
2007-01-31 18:31:19 +00:00
{
2008-05-04 15:10:32 +00:00
Q_Q ( Generator ) ;
2007-01-31 18:31:19 +00:00
Page * page = mTextPageGenerationThread - > page ( ) ;
mTextPageGenerationThread - > endGeneration ( ) ;
2007-10-08 21:49:27 +00:00
QMutexLocker locker ( threadsLock ( ) ) ;
2007-01-31 18:31:19 +00:00
mTextPageReady = true ;
2007-10-08 21:49:27 +00:00
if ( m_closing ) {
delete mTextPageGenerationThread - > textPage ( ) ;
if ( mPixmapReady ) {
locker . unlock ( ) ;
m_closingLoop - > quit ( ) ;
}
return ;
}
2007-01-31 18:31:19 +00:00
if ( mTextPageGenerationThread - > textPage ( ) ) {
2008-05-04 15:10:32 +00:00
TextPage * tp = mTextPageGenerationThread - > textPage ( ) ;
page - > setTextPage ( tp ) ;
q - > signalTextGenerationDone ( page , tp ) ;
}
2007-01-31 18:31:19 +00:00
}
2007-10-08 21:49:27 +00:00
QMutex * GeneratorPrivate : : threadsLock ( )
{
2020-01-30 08:28:17 +00:00
return & m_threadsMutex ;
2007-10-08 21:49:27 +00:00
}
2008-03-15 02:15:16 +00:00
QVariant GeneratorPrivate : : metaData ( const QString & , const QVariant & ) const
{
return QVariant ( ) ;
}
2008-05-06 20:20:10 +00:00
QImage GeneratorPrivate : : image ( PixmapRequest * )
{
return QImage ( ) ;
}
2018-02-01 18:42:37 +00:00
Generator : : Generator ( QObject * parent , const QVariantList & args )
: Generator ( * new GeneratorPrivate ( ) , parent , args )
2006-10-20 16:51:46 +00:00
{
2018-02-01 18:42:37 +00:00
// the delegated constructor does it all
2007-09-14 13:31:55 +00:00
}
2014-09-17 21:52:14 +00:00
Generator : : Generator ( GeneratorPrivate & dd , QObject * parent , const QVariantList & args )
: QObject ( parent )
, d_ptr ( & dd )
2007-09-14 13:31:55 +00:00
{
d_ptr - > q_ptr = this ;
2014-09-17 21:52:14 +00:00
Q_UNUSED ( args )
2006-10-20 16:51:46 +00:00
}
Generator : : ~ Generator ( )
{
2007-09-14 13:31:55 +00:00
delete d_ptr ;
2006-10-20 16:51:46 +00:00
}
2014-05-09 17:56:16 +00:00
bool Generator : : loadDocument ( const QString & fileName , QVector < Page * > & pagesVector )
{
2016-07-11 20:57:11 +00:00
Q_UNUSED ( fileName ) ;
Q_UNUSED ( pagesVector ) ;
2014-05-09 17:56:16 +00:00
return false ;
}
2007-01-12 22:49:14 +00:00
bool Generator : : loadDocumentFromData ( const QByteArray & , QVector < Page * > & )
{
return false ;
}
2014-05-09 17:56:16 +00:00
Document : : OpenResult Generator : : loadDocumentWithPassword ( const QString & fileName , QVector < Page * > & pagesVector , const QString & )
{
return loadDocument ( fileName , pagesVector ) ? Document : : OpenSuccess : Document : : OpenError ;
}
Document : : OpenResult Generator : : loadDocumentFromDataWithPassword ( const QByteArray & fileData , QVector < Page * > & pagesVector , const QString & )
{
return loadDocumentFromData ( fileData , pagesVector ) ? Document : : OpenSuccess : Document : : OpenError ;
}
2017-10-26 07:47:18 +00:00
Generator : : SwapBackingFileResult Generator : : swapBackingFile ( QString const & /*newFileName */ , QVector < Okular : : Page * > & /*newPagesVector*/ )
2014-05-09 22:53:39 +00:00
{
2017-10-26 07:47:18 +00:00
return SwapBackingFileError ;
2014-05-09 22:53:39 +00:00
}
2007-10-08 16:46:51 +00:00
bool Generator : : closeDocument ( )
{
2007-10-08 21:49:27 +00:00
Q_D ( Generator ) ;
d - > m_closing = true ;
d - > threadsLock ( ) - > lock ( ) ;
if ( ! ( d - > mPixmapReady & & d - > mTextPageReady ) ) {
QEventLoop loop ;
d - > m_closingLoop = & loop ;
d - > threadsLock ( ) - > unlock ( ) ;
loop . exec ( ) ;
2017-09-05 21:27:18 +00:00
d - > m_closingLoop = nullptr ;
2007-10-08 21:49:27 +00:00
} else {
d - > threadsLock ( ) - > unlock ( ) ;
}
bool ret = doCloseDocument ( ) ;
d - > m_closing = false ;
return ret ;
2007-10-08 16:46:51 +00:00
}
2007-01-31 18:31:19 +00:00
bool Generator : : canGeneratePixmap ( ) const
2007-01-24 15:06:45 +00:00
{
2007-09-14 13:31:55 +00:00
Q_D ( const Generator ) ;
2007-01-31 18:31:19 +00:00
return d - > mPixmapReady ;
2007-01-24 15:06:45 +00:00
}
2020-10-29 16:14:05 +00:00
bool Generator : : canSign ( ) const
{
return false ;
}
bool Generator : : sign ( const NewSignatureData & , const QString & )
{
return false ;
}
CertificateStore * Generator : : getCertStore ( ) const
{
return nullptr ;
}
2007-01-31 18:31:19 +00:00
void Generator : : generatePixmap ( PixmapRequest * request )
2007-01-24 15:06:45 +00:00
{
2007-09-14 13:31:55 +00:00
Q_D ( Generator ) ;
2007-01-31 18:31:19 +00:00
d - > mPixmapReady = false ;
2012-12-01 16:12:40 +00:00
const bool calcBoundingBox = ! request - > isTile ( ) & & ! request - > page ( ) - > isBoundingBoxKnown ( ) ;
2009-01-20 12:52:01 +00:00
if ( request - > asynchronous ( ) & & hasFeature ( Threaded ) ) {
2018-02-01 18:42:37 +00:00
if ( d - > textPageGenerationThread ( ) - > isFinished ( ) & & ! canGenerateTextPage ( ) ) {
// It can happen that the text generation has already finished but
// mTextPageReady is still false because textpageGenerationFinished
// didn't have time to run, if so queue ourselves
QTimer : : singleShot ( 0 , this , [ this , request ] { generatePixmap ( request ) ; } ) ;
return ;
}
2007-01-31 21:10:00 +00:00
/**
* We create the text page for every page that is visible to the
* user , so he can use the text extraction tools without a delay .
*/
2014-03-01 16:01:14 +00:00
if ( hasFeature ( TextExtraction ) & & ! request - > page ( ) - > hasTextPage ( ) & & canGenerateTextPage ( ) & & ! d - > m_closing ) {
2007-01-31 21:10:00 +00:00
d - > mTextPageReady = false ;
2018-02-01 18:42:37 +00:00
d - > textPageGenerationThread ( ) - > setPage ( request - > page ( ) ) ;
// dummy is used as a way to make sure the lambda gets disconnected each time it is executed
// since not all the times the pixmap generation thread starts we want the text generation thread to also start
QObject * dummy = new QObject ( ) ;
connect ( d_ptr - > pixmapGenerationThread ( ) , & QThread : : started , dummy , [ this , dummy ] {
delete dummy ;
d_ptr - > textPageGenerationThread ( ) - > startGeneration ( ) ;
} ) ;
2007-01-31 21:10:00 +00:00
}
2020-01-29 22:19:52 +00:00
// pixmap generation thread must be started *after* connect(), else we may miss the start signal and get lock-ups (see bug 396137)
d - > pixmapGenerationThread ( ) - > startGeneration ( request , calcBoundingBox ) ;
2007-01-31 21:10:00 +00:00
2007-01-31 18:31:19 +00:00
return ;
}
2008-05-18 23:06:21 +00:00
const QImage & img = image ( request ) ;
2013-02-24 21:58:53 +00:00
request - > page ( ) - > setPixmap ( request - > observer ( ) , new QPixmap ( QPixmap : : fromImage ( img ) ) , request - > normalizedRect ( ) ) ;
2008-05-31 11:23:02 +00:00
const int pageNumber = request - > page ( ) - > number ( ) ;
2007-01-31 18:31:19 +00:00
d - > mPixmapReady = true ;
2007-09-14 13:31:55 +00:00
signalPixmapRequestDone ( request ) ;
2012-12-01 16:12:40 +00:00
if ( calcBoundingBox )
2008-05-31 11:23:02 +00:00
updatePageBoundingBox ( pageNumber , Utils : : imageBoundingBox ( & img ) ) ;
2007-01-24 15:06:45 +00:00
}
2007-01-31 18:31:19 +00:00
bool Generator : : canGenerateTextPage ( ) const
2007-01-24 18:27:54 +00:00
{
2007-09-14 13:31:55 +00:00
Q_D ( const Generator ) ;
2007-01-31 18:31:19 +00:00
return d - > mTextPageReady ;
2007-01-24 18:27:54 +00:00
}
2007-08-13 22:25:27 +00:00
void Generator : : generateTextPage ( Page * page )
2007-01-24 15:06:45 +00:00
{
2018-02-01 18:42:37 +00:00
TextRequest treq ( page ) ;
TextPage * tp = textPage ( & treq ) ;
2008-05-04 15:10:32 +00:00
page - > setTextPage ( tp ) ;
signalTextGenerationDone ( page , tp ) ;
2007-01-24 15:06:45 +00:00
}
2008-05-06 20:20:10 +00:00
QImage Generator : : image ( PixmapRequest * request )
2007-01-24 18:27:54 +00:00
{
2008-05-06 20:20:10 +00:00
Q_D ( Generator ) ;
return d - > image ( request ) ;
2007-01-24 18:27:54 +00:00
}
2018-02-01 18:42:37 +00:00
TextPage * Generator : : textPage ( TextRequest * )
2006-10-20 16:51:46 +00:00
{
2017-09-05 21:27:18 +00:00
return nullptr ;
2006-10-20 16:51:46 +00:00
}
2014-05-11 09:17:49 +00:00
DocumentInfo Generator : : generateDocumentInfo ( const QSet < DocumentInfo : : Key > & keys ) const
2006-10-20 16:51:46 +00:00
{
2016-07-11 20:57:11 +00:00
Q_UNUSED ( keys ) ;
2014-05-11 09:17:49 +00:00
return DocumentInfo ( ) ;
2006-10-20 16:51:46 +00:00
}
const DocumentSynopsis * Generator : : generateDocumentSynopsis ( )
{
2017-09-05 21:27:18 +00:00
return nullptr ;
2006-10-20 16:51:46 +00:00
}
2007-07-07 20:35:01 +00:00
FontInfo : : List Generator : : fontsForPage ( int )
2006-10-20 16:51:46 +00:00
{
2007-07-07 20:35:01 +00:00
return FontInfo : : List ( ) ;
2006-10-20 16:51:46 +00:00
}
const QList < EmbeddedFile * > * Generator : : embeddedFiles ( ) const
{
2017-09-05 21:27:18 +00:00
return nullptr ;
2006-10-20 16:51:46 +00:00
}
Generator : : PageSizeMetric Generator : : pagesSizeMetric ( ) const
{
2006-10-25 17:43:15 +00:00
return None ;
2006-10-20 16:51:46 +00:00
}
2007-03-10 23:59:11 +00:00
bool Generator : : isAllowed ( Permission ) const
2006-10-20 16:51:46 +00:00
{
2006-10-25 17:43:15 +00:00
return true ;
2006-10-20 16:51:46 +00:00
}
2007-01-05 17:09:47 +00:00
void Generator : : rotationChanged ( Rotation , Rotation )
2006-10-20 16:51:46 +00:00
{
}
2007-01-05 23:12:06 +00:00
PageSize : : List Generator : : pageSizes ( ) const
2006-10-20 16:51:46 +00:00
{
2007-01-05 23:12:06 +00:00
return PageSize : : List ( ) ;
2006-10-20 16:51:46 +00:00
}
2007-01-05 23:12:06 +00:00
void Generator : : pageSizeChanged ( const PageSize & , const PageSize & )
2006-10-20 16:51:46 +00:00
{
}
2007-10-15 23:01:27 +00:00
bool Generator : : print ( QPrinter & )
2006-10-20 16:51:46 +00:00
{
2006-10-25 17:43:15 +00:00
return false ;
2006-10-20 16:51:46 +00:00
}
2010-04-14 23:07:27 +00:00
Generator : : PrintError Generator : : printError ( ) const
{
return UnknownPrintError ;
}
2016-11-26 15:00:02 +00:00
void Generator : : opaqueAction ( const BackendOpaqueAction * /*action*/ )
{
}
2008-03-15 02:15:16 +00:00
QVariant Generator : : metaData ( const QString & key , const QVariant & option ) const
2006-10-20 16:51:46 +00:00
{
2008-03-15 02:15:16 +00:00
Q_D ( const Generator ) ;
return d - > metaData ( key , option ) ;
2006-10-20 16:51:46 +00:00
}
2006-10-25 15:35:53 +00:00
ExportFormat : : List Generator : : exportFormats ( ) const
2006-10-20 16:51:46 +00:00
{
2006-10-25 17:43:15 +00:00
return ExportFormat : : List ( ) ;
2006-10-20 16:51:46 +00:00
}
2006-10-25 15:35:53 +00:00
bool Generator : : exportTo ( const QString & , const ExportFormat & )
2006-10-20 16:51:46 +00:00
{
2006-10-25 17:43:15 +00:00
return false ;
2006-10-20 16:51:46 +00:00
}
2014-05-10 13:31:59 +00:00
void Generator : : walletDataForFile ( const QString & fileName , QString * walletName , QString * walletFolder , QString * walletKey ) const
{
2020-09-09 12:13:09 +00:00
# ifdef WITH_KWALLET
2016-07-11 20:07:57 +00:00
* walletKey = fileName . section ( QLatin1Char ( ' / ' ) , - 1 , - 1 ) ;
2014-05-10 13:31:59 +00:00
* walletName = KWallet : : Wallet : : NetworkWallet ( ) ;
2015-10-29 12:37:11 +00:00
* walletFolder = QStringLiteral ( " KPdf " ) ;
2020-09-09 12:13:09 +00:00
# endif
2014-05-10 13:31:59 +00:00
}
2007-01-26 16:35:30 +00:00
bool Generator : : hasFeature ( GeneratorFeature feature ) const
2007-01-12 22:49:14 +00:00
{
2007-09-14 13:31:55 +00:00
Q_D ( const Generator ) ;
2007-01-26 16:35:30 +00:00
return d - > m_features . contains ( feature ) ;
2007-01-12 22:49:14 +00:00
}
2007-01-29 08:17:45 +00:00
void Generator : : signalPixmapRequestDone ( PixmapRequest * request )
2006-10-20 16:51:46 +00:00
{
2007-09-14 13:31:55 +00:00
Q_D ( Generator ) ;
2006-10-25 17:43:15 +00:00
if ( d - > m_document )
d - > m_document - > requestDone ( request ) ;
else {
2008-02-01 00:30:48 +00:00
delete request ;
}
2006-10-20 16:51:46 +00:00
}
2008-05-04 15:10:32 +00:00
void Generator : : signalTextGenerationDone ( Page * page , TextPage * textPage )
{
Q_D ( Generator ) ;
if ( d - > m_document )
d - > m_document - > textGenerationDone ( page ) ;
else
delete textPage ;
}
2017-10-03 07:29:18 +00:00
void Generator : : signalPartialPixmapRequest ( PixmapRequest * request , const QImage & image )
{
2018-02-01 18:42:37 +00:00
if ( request - > shouldAbortRender ( ) )
return ;
PagePrivate * pagePrivate = PagePrivate : : get ( request - > page ( ) ) ;
pagePrivate - > setPixmap ( request - > observer ( ) , new QPixmap ( QPixmap : : fromImage ( image ) ) , request - > normalizedRect ( ) , true /* isPartialPixmap */ ) ;
2017-10-03 07:29:18 +00:00
const int pageNumber = request - > page ( ) - > number ( ) ;
request - > observer ( ) - > notifyPageChanged ( pageNumber , Okular : : DocumentObserver : : Pixmap ) ;
}
2007-03-17 12:11:41 +00:00
const Document * Generator : : document ( ) const
2006-10-20 16:51:46 +00:00
{
2007-09-14 13:31:55 +00:00
Q_D ( const Generator ) ;
2008-03-19 17:01:00 +00:00
if ( d - > m_document ) {
return d - > m_document - > m_parent ;
}
2017-09-05 21:27:18 +00:00
return nullptr ;
2006-10-20 16:51:46 +00:00
}
2007-01-26 16:35:30 +00:00
void Generator : : setFeature ( GeneratorFeature feature , bool on )
{
2007-09-14 13:31:55 +00:00
Q_D ( Generator ) ;
2007-01-26 16:35:30 +00:00
if ( on )
d - > m_features . insert ( feature ) ;
else
d - > m_features . remove ( feature ) ;
}
2007-09-14 22:16:00 +00:00
QVariant Generator : : documentMetaData ( const QString & key , const QVariant & option ) const
2017-03-02 20:04:59 +00:00
{
Q_D ( const Generator ) ;
if ( ! d - > m_document )
return QVariant ( ) ;
if ( key = = QLatin1String ( " PaperColor " ) )
return documentMetaData ( PaperColorMetaData , option ) ;
if ( key = = QLatin1String ( " GraphicsAntialias " ) )
return documentMetaData ( GraphicsAntialiasMetaData , option ) ;
if ( key = = QLatin1String ( " TextAntialias " ) )
return documentMetaData ( TextAntialiasMetaData , option ) ;
if ( key = = QLatin1String ( " TextHinting " ) )
return documentMetaData ( TextHintingMetaData , option ) ;
return QVariant ( ) ;
}
2017-03-02 21:45:45 +00:00
QVariant Generator : : documentMetaData ( const DocumentMetaDataKey key , const QVariant & option ) const
2007-09-14 22:16:00 +00:00
{
Q_D ( const Generator ) ;
if ( ! d - > m_document )
return QVariant ( ) ;
return d - > m_document - > documentMetaData ( key , option ) ;
}
2007-09-15 11:35:53 +00:00
QMutex * Generator : : userMutex ( ) const
{
Q_D ( const Generator ) ;
2020-01-30 08:28:17 +00:00
return & d - > m_mutex ;
2007-09-15 11:35:53 +00:00
}
2008-05-18 23:06:21 +00:00
void Generator : : updatePageBoundingBox ( int page , const NormalizedRect & boundingBox )
{
Q_D ( Generator ) ;
if ( d - > m_document ) // still connected to document?
d - > m_document - > setPageBoundingBox ( page , boundingBox ) ;
}
2008-08-01 20:26:22 +00:00
void Generator : : requestFontData ( const Okular : : FontInfo & /*font*/ , QByteArray * /*data*/ )
{
}
2007-01-26 16:35:30 +00:00
2020-02-20 17:45:46 +00:00
void Generator : : setDPI ( const QSizeF & dpi ) // clazy:exclude=function-args-by-value TODO remove the & when we do a BIC change elsewhere
2014-01-13 00:15:55 +00:00
{
Q_D ( Generator ) ;
d - > m_dpi = dpi ;
}
QSizeF Generator : : dpi ( ) const
{
Q_D ( const Generator ) ;
return d - > m_dpi ;
}
2015-05-29 04:24:06 +00:00
QAbstractItemModel * Generator : : layersModel ( ) const
{
2017-09-05 21:27:18 +00:00
return nullptr ;
2015-05-29 04:24:06 +00:00
}
2018-02-01 18:42:37 +00:00
TextRequest : : TextRequest ( )
: d ( new TextRequestPrivate )
{
d - > mPage = nullptr ;
d - > mShouldAbortExtraction = 0 ;
}
TextRequest : : TextRequest ( Page * page )
: d ( new TextRequestPrivate )
{
d - > mPage = page ;
d - > mShouldAbortExtraction = 0 ;
}
TextRequest : : ~ TextRequest ( )
{
delete d ;
}
Page * TextRequest : : page ( ) const
{
return d - > mPage ;
}
bool TextRequest : : shouldAbortExtraction ( ) const
{
return d - > mShouldAbortExtraction ! = 0 ;
}
TextRequestPrivate * TextRequestPrivate : : get ( const TextRequest * req )
{
return req - > d ;
}
2013-02-24 21:58:53 +00:00
PixmapRequest : : PixmapRequest ( DocumentObserver * observer , int pageNumber , int width , int height , int priority , PixmapRequestFeatures features )
2007-09-30 21:44:31 +00:00
: d ( new PixmapRequestPrivate )
2006-10-20 16:51:46 +00:00
{
2013-02-24 21:58:53 +00:00
d - > mObserver = observer ;
2006-10-25 17:43:15 +00:00
d - > mPageNumber = pageNumber ;
2017-10-14 12:47:20 +00:00
d - > mWidth = ceil ( width * qApp - > devicePixelRatio ( ) ) ;
d - > mHeight = ceil ( height * qApp - > devicePixelRatio ( ) ) ;
2006-10-25 17:43:15 +00:00
d - > mPriority = priority ;
2013-02-24 21:58:53 +00:00
d - > mFeatures = features ;
2008-03-07 15:50:48 +00:00
d - > mForce = false ;
2012-08-24 16:32:39 +00:00
d - > mTile = false ;
2012-07-08 16:52:00 +00:00
d - > mNormalizedRect = NormalizedRect ( ) ;
2017-10-03 07:29:18 +00:00
d - > mPartialUpdatesWanted = false ;
2018-02-01 18:42:37 +00:00
d - > mShouldAbortRender = 0 ;
2006-10-20 16:51:46 +00:00
}
2006-10-25 15:35:53 +00:00
PixmapRequest : : ~ PixmapRequest ( )
{
2006-10-25 17:43:15 +00:00
delete d ;
2006-10-25 15:35:53 +00:00
}
2013-02-24 21:58:53 +00:00
DocumentObserver * PixmapRequest : : observer ( ) const
2006-10-25 15:35:53 +00:00
{
2013-02-24 21:58:53 +00:00
return d - > mObserver ;
2006-10-25 15:35:53 +00:00
}
int PixmapRequest : : pageNumber ( ) const
{
2006-10-25 17:43:15 +00:00
return d - > mPageNumber ;
2006-10-25 15:35:53 +00:00
}
int PixmapRequest : : width ( ) const
{
2006-10-25 17:43:15 +00:00
return d - > mWidth ;
2006-10-25 15:35:53 +00:00
}
int PixmapRequest : : height ( ) const
2006-10-22 11:25:08 +00:00
{
2006-10-25 17:43:15 +00:00
return d - > mHeight ;
2006-10-22 11:25:08 +00:00
}
2006-10-25 15:35:53 +00:00
int PixmapRequest : : priority ( ) const
{
2006-10-25 17:43:15 +00:00
return d - > mPriority ;
2006-10-25 15:35:53 +00:00
}
bool PixmapRequest : : asynchronous ( ) const
{
2013-02-24 21:58:53 +00:00
return d - > mFeatures & Asynchronous ;
}
bool PixmapRequest : : preload ( ) const
{
return d - > mFeatures & Preload ;
2006-10-25 15:35:53 +00:00
}
Page * PixmapRequest : : page ( ) const
{
2006-10-25 17:43:15 +00:00
return d - > mPage ;
2006-10-25 15:35:53 +00:00
}
2012-08-24 16:32:39 +00:00
void PixmapRequest : : setTile ( bool tile )
{
d - > mTile = tile ;
}
bool PixmapRequest : : isTile ( ) const
{
return d - > mTile ;
}
2012-07-08 16:52:00 +00:00
void PixmapRequest : : setNormalizedRect ( const NormalizedRect & rect )
2012-05-28 02:52:26 +00:00
{
2012-07-08 16:52:00 +00:00
if ( d - > mNormalizedRect = = rect )
2012-05-28 02:52:26 +00:00
return ;
2012-07-08 16:52:00 +00:00
d - > mNormalizedRect = rect ;
2012-05-28 02:52:26 +00:00
}
2012-11-10 17:30:01 +00:00
const NormalizedRect & PixmapRequest : : normalizedRect ( ) const
2012-05-28 02:52:26 +00:00
{
2012-07-08 16:52:00 +00:00
return d - > mNormalizedRect ;
2012-05-28 02:52:26 +00:00
}
2017-10-03 07:29:18 +00:00
void PixmapRequest : : setPartialUpdatesWanted ( bool partialUpdatesWanted )
{
d - > mPartialUpdatesWanted = partialUpdatesWanted ;
}
bool PixmapRequest : : partialUpdatesWanted ( ) const
{
return d - > mPartialUpdatesWanted ;
}
2018-02-01 18:42:37 +00:00
bool PixmapRequest : : shouldAbortRender ( ) const
{
return d - > mShouldAbortRender ! = 0 ;
}
2014-02-19 22:40:43 +00:00
Okular : : TilesManager * PixmapRequestPrivate : : tilesManager ( ) const
{
return mPage - > d - > tilesManager ( mObserver ) ;
}
2018-02-01 18:42:37 +00:00
PixmapRequestPrivate * PixmapRequestPrivate : : get ( const PixmapRequest * req )
{
return req - > d ;
}
2007-12-04 21:36:32 +00:00
void PixmapRequestPrivate : : swap ( )
2006-11-20 07:53:32 +00:00
{
2007-12-04 21:36:32 +00:00
qSwap ( mWidth , mHeight ) ;
2006-11-20 07:53:32 +00:00
}
2012-07-02 06:22:51 +00:00
2007-04-12 20:43:37 +00:00
class Okular : : ExportFormatPrivate : public QSharedData
2006-10-25 15:35:53 +00:00
{
2006-10-25 17:43:15 +00:00
public :
2014-09-11 13:18:05 +00:00
ExportFormatPrivate ( const QString & description , const QMimeType & mimeType , const QIcon & icon = QIcon ( ) )
2007-04-12 20:43:37 +00:00
: QSharedData ( )
, mDescription ( description )
, mMimeType ( mimeType )
, mIcon ( icon )
{
}
~ ExportFormatPrivate ( )
2006-10-25 17:43:15 +00:00
{
}
2006-10-25 15:35:53 +00:00
2006-10-25 17:43:15 +00:00
QString mDescription ;
2014-09-11 13:18:05 +00:00
QMimeType mMimeType ;
2014-08-13 09:54:49 +00:00
QIcon mIcon ;
2006-10-25 15:35:53 +00:00
} ;
ExportFormat : : ExportFormat ( )
2014-09-11 13:18:05 +00:00
: d ( new ExportFormatPrivate ( QString ( ) , QMimeType ( ) ) )
2006-10-25 15:35:53 +00:00
{
}
2014-09-11 13:18:05 +00:00
ExportFormat : : ExportFormat ( const QString & description , const QMimeType & mimeType )
2007-04-12 20:43:37 +00:00
: d ( new ExportFormatPrivate ( description , mimeType ) )
2006-10-25 15:35:53 +00:00
{
}
2014-09-11 13:18:05 +00:00
ExportFormat : : ExportFormat ( const QIcon & icon , const QString & description , const QMimeType & mimeType )
2007-04-12 20:43:37 +00:00
: d ( new ExportFormatPrivate ( description , mimeType , icon ) )
2006-10-25 15:35:53 +00:00
{
}
ExportFormat : : ~ ExportFormat ( )
{
}
ExportFormat : : ExportFormat ( const ExportFormat & other )
2007-04-12 20:43:37 +00:00
: d ( other . d )
2006-10-25 15:35:53 +00:00
{
}
ExportFormat & ExportFormat : : operator = ( const ExportFormat & other )
{
2006-10-25 17:43:15 +00:00
if ( this = = & other )
return * this ;
2006-10-25 15:35:53 +00:00
2007-04-12 20:43:37 +00:00
d = other . d ;
2006-10-25 15:35:53 +00:00
2006-10-25 17:43:15 +00:00
return * this ;
2006-10-25 15:35:53 +00:00
}
QString ExportFormat : : description ( ) const
{
2006-10-25 17:43:15 +00:00
return d - > mDescription ;
2006-10-25 15:35:53 +00:00
}
2014-09-11 13:18:05 +00:00
QMimeType ExportFormat : : mimeType ( ) const
2006-10-25 15:35:53 +00:00
{
2006-10-25 17:43:15 +00:00
return d - > mMimeType ;
2006-10-25 15:35:53 +00:00
}
2014-08-13 09:54:49 +00:00
QIcon ExportFormat : : icon ( ) const
2006-10-25 15:35:53 +00:00
{
2006-10-25 17:43:15 +00:00
return d - > mIcon ;
2006-10-25 15:35:53 +00:00
}
2006-10-22 11:25:08 +00:00
2007-03-10 20:51:50 +00:00
bool ExportFormat : : isNull ( ) const
{
2014-09-11 13:18:05 +00:00
return ! d - > mMimeType . isValid ( ) | | d - > mDescription . isNull ( ) ;
2007-03-10 20:51:50 +00:00
}
2007-04-21 11:09:41 +00:00
ExportFormat ExportFormat : : standardFormat ( StandardExportFormat type )
2007-03-10 21:32:09 +00:00
{
2014-09-11 13:18:05 +00:00
QMimeDatabase db ;
2007-04-21 11:09:41 +00:00
switch ( type ) {
case PlainText :
2015-10-29 12:37:11 +00:00
return ExportFormat ( QIcon : : fromTheme ( QStringLiteral ( " text-x-generic " ) ) , i18n ( " Plain &Text... " ) , db . mimeTypeForName ( QStringLiteral ( " text/plain " ) ) ) ;
2007-04-21 11:09:41 +00:00
break ;
case PDF :
2015-10-29 12:37:11 +00:00
return ExportFormat ( QIcon : : fromTheme ( QStringLiteral ( " application-pdf " ) ) , i18n ( " PDF " ) , db . mimeTypeForName ( QStringLiteral ( " application/pdf " ) ) ) ;
2007-04-21 11:09:41 +00:00
break ;
2008-08-07 13:45:43 +00:00
case OpenDocumentText :
return ExportFormat (
2015-10-29 12:37:11 +00:00
QIcon : : fromTheme ( QStringLiteral ( " application-vnd.oasis.opendocument.text " ) ) , i18nc ( " This is the document format " , " OpenDocument Text " ) , db . mimeTypeForName ( QStringLiteral ( " application/vnd.oasis.opendocument.text " ) ) ) ;
2008-09-01 12:00:50 +00:00
break ;
case HTML :
2015-10-29 12:37:11 +00:00
return ExportFormat ( QIcon : : fromTheme ( QStringLiteral ( " text-html " ) ) , i18nc ( " This is the document format " , " HTML " ) , db . mimeTypeForName ( QStringLiteral ( " text/html " ) ) ) ;
2008-08-07 13:45:43 +00:00
break ;
2007-04-21 11:09:41 +00:00
}
return ExportFormat ( ) ;
2007-03-10 21:32:09 +00:00
}
2007-04-12 20:43:37 +00:00
bool ExportFormat : : operator = = ( const ExportFormat & other ) const
{
return d = = other . d ;
}
bool ExportFormat : : operator ! = ( const ExportFormat & other ) const
{
return d ! = other . d ;
}
2007-07-30 23:58:04 +00:00
QDebug operator < < ( QDebug str , const Okular : : PixmapRequest & req )
2005-11-20 15:30:15 +00:00
{
2018-02-01 18:42:37 +00:00
PixmapRequestPrivate * reqPriv = PixmapRequestPrivate : : get ( & req ) ;
str < < " PixmapRequest: " < < & req ;
str < < " - observer: " < < ( qulonglong ) req . observer ( ) ;
str < < " - page: " < < req . pageNumber ( ) ;
str < < " - width: " < < req . width ( ) ;
str < < " - height: " < < req . height ( ) ;
str < < " - priority: " < < req . priority ( ) ;
str < < " - async: " < < ( req . asynchronous ( ) ? " true " : " false " ) ;
str < < " - tile: " < < ( req . isTile ( ) ? " true " : " false " ) ;
str < < " - rect: " < < req . normalizedRect ( ) ;
str < < " - preload: " < < ( req . preload ( ) ? " true " : " false " ) ;
str < < " - partialUpdates: " < < ( req . partialUpdatesWanted ( ) ? " true " : " false " ) ;
str < < " - shouldAbort: " < < ( req . shouldAbortRender ( ) ? " true " : " false " ) ;
str < < " - force: " < < ( reqPriv - > mForce ? " true " : " false " ) ;
2006-10-22 13:34:47 +00:00
return str ;
2005-11-20 15:30:15 +00:00
}
2006-06-10 12:59:09 +00:00
2010-04-14 23:07:27 +00:00
/* kate: replace-tabs on; indent-width 4; */