Okular

generator.cpp
1/*
2 SPDX-FileCopyrightText: 2005 Piotr Szymanski <niedakh@gmail.com>
3 SPDX-FileCopyrightText: 2008 Albert Astals Cid <aacid@kde.org>
4
5 Work sponsored by the LiMux project of the city of Munich:
6 SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB a KDAB Group company <info@kdab.com>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#include "config-okular.h"
12
13#include "generator.h"
14#include "generator_p.h"
15#include "observer.h"
16
17#include <QApplication>
18#include <QEventLoop>
19#include <QPrinter>
20
21#include <KLocalizedString>
22#include <QDebug>
23#include <QIcon>
24#include <QMimeDatabase>
25#include <QTimer>
26
27#if HAVE_KWALLET
28#include <KWallet>
29#endif
30
31#include "document_p.h"
32#include "page.h"
33#include "page_p.h"
34#include "textpage.h"
35#include "utils.h"
36
37using namespace Okular;
38
39GeneratorPrivate::GeneratorPrivate()
40 : q_ptr(nullptr)
41 , m_document(nullptr)
42 , mPixmapGenerationThread(nullptr)
43 , mTextPageGenerationThread(nullptr)
44 , mPixmapReady(true)
45 , mTextPageReady(true)
46 , m_closing(false)
47 , m_closingLoop(nullptr)
48 , m_dpi(72.0, 72.0)
49{
50 qRegisterMetaType<Okular::Page *>();
51}
52
53GeneratorPrivate::~GeneratorPrivate()
54{
55 if (mPixmapGenerationThread) {
56 mPixmapGenerationThread->wait();
57 }
58
59 delete mPixmapGenerationThread;
60
61 if (mTextPageGenerationThread) {
62 mTextPageGenerationThread->wait();
63 }
64
65 delete mTextPageGenerationThread;
66}
67
68PixmapGenerationThread *GeneratorPrivate::pixmapGenerationThread()
69{
70 if (mPixmapGenerationThread) {
71 return mPixmapGenerationThread;
72 }
73
74 Q_Q(Generator);
75 mPixmapGenerationThread = new PixmapGenerationThread(q);
77 mPixmapGenerationThread, &PixmapGenerationThread::finished, q, [this] { pixmapGenerationFinished(); }, Qt::QueuedConnection);
78
79 return mPixmapGenerationThread;
80}
81
82TextPageGenerationThread *GeneratorPrivate::textPageGenerationThread()
83{
84 if (mTextPageGenerationThread) {
85 return mTextPageGenerationThread;
86 }
87
88 Q_Q(Generator);
89 mTextPageGenerationThread = new TextPageGenerationThread(q);
91 mTextPageGenerationThread, &TextPageGenerationThread::finished, q, [this] { textpageGenerationFinished(); }, Qt::QueuedConnection);
92
93 return mTextPageGenerationThread;
94}
95
96void GeneratorPrivate::pixmapGenerationFinished()
97{
98 Q_Q(Generator);
99 PixmapRequest *request = mPixmapGenerationThread->request();
100 const QImage &img = mPixmapGenerationThread->image();
101 mPixmapGenerationThread->endGeneration();
102
103 QMutexLocker locker(threadsLock());
104
105 if (m_closing) {
106 mPixmapReady = true;
107 delete request;
108 if (mTextPageReady) {
109 locker.unlock();
110 m_closingLoop->quit();
111 }
112 return;
113 }
114
115 if (!request->shouldAbortRender()) {
116 request->page()->setPixmap(request->observer(), new QPixmap(QPixmap::fromImage(img)), request->normalizedRect());
117 const int pageNumber = request->page()->number();
118
119 if (mPixmapGenerationThread->calcBoundingBox()) {
120 q->updatePageBoundingBox(pageNumber, mPixmapGenerationThread->boundingBox());
121 }
122 } else {
123 // Cancel the text page generation too if it's still running
124 if (mTextPageGenerationThread && mTextPageGenerationThread->isRunning()) {
125 mTextPageGenerationThread->abortExtraction();
126 mTextPageGenerationThread->wait();
127 }
128 }
129
130 mPixmapReady = true;
131 q->signalPixmapRequestDone(request);
132}
133
134void GeneratorPrivate::textpageGenerationFinished()
135{
136 Q_Q(Generator);
137 Page *page = mTextPageGenerationThread->page();
138 mTextPageGenerationThread->endGeneration();
139
140 QMutexLocker locker(threadsLock());
141 mTextPageReady = true;
142
143 if (m_closing) {
144 delete mTextPageGenerationThread->textPage();
145 if (mPixmapReady) {
146 locker.unlock();
147 m_closingLoop->quit();
148 }
149 return;
150 }
151
152 if (mTextPageGenerationThread->textPage()) {
153 TextPage *tp = mTextPageGenerationThread->textPage();
154 page->setTextPage(tp);
155 q->signalTextGenerationDone(page, tp);
156 }
157}
158
159QMutex *GeneratorPrivate::threadsLock()
160{
161 return &m_threadsMutex;
162}
163
164QVariant GeneratorPrivate::metaData(const QString &, const QVariant &) const
165{
166 return QVariant();
167}
168
169QImage GeneratorPrivate::image(PixmapRequest *)
170{
171 return QImage();
172}
173
174Generator::Generator(QObject *parent, const QVariantList &args)
175 : Generator(*new GeneratorPrivate(), parent, args)
176{
177 // the delegated constructor does it all
178}
179
180Generator::Generator(GeneratorPrivate &dd, QObject *parent, const QVariantList &args)
181 : QObject(parent)
182 , d_ptr(&dd)
183{
184 d_ptr->q_ptr = this;
185 Q_UNUSED(args)
186}
187
189{
190 delete d_ptr;
191}
192
193bool Generator::loadDocument(const QString &fileName, QVector<Page *> &pagesVector)
194{
195 Q_UNUSED(fileName);
196 Q_UNUSED(pagesVector);
197
198 return false;
199}
200
202{
203 return false;
204}
205
207{
208 return loadDocument(fileName, pagesVector) ? Document::OpenSuccess : Document::OpenError;
209}
210
212{
213 return loadDocumentFromData(fileData, pagesVector) ? Document::OpenSuccess : Document::OpenError;
214}
215
217{
218 return SwapBackingFileError;
219}
220
222{
223 Q_D(Generator);
224
225 d->m_closing = true;
226
227 d->threadsLock()->lock();
228 if (!(d->mPixmapReady && d->mTextPageReady)) {
229 QEventLoop loop;
230 d->m_closingLoop = &loop;
231
232 d->threadsLock()->unlock();
233
234 loop.exec();
235
236 d->m_closingLoop = nullptr;
237 } else {
238 d->threadsLock()->unlock();
239 }
240
241 bool ret = doCloseDocument();
242
243 d->m_closing = false;
244
245 return ret;
246}
247
249{
250 Q_D(const Generator);
251 return d->mPixmapReady;
252}
253
254bool Generator::canSign() const
255{
256 return false;
257}
258
259bool Generator::sign(const NewSignatureData &, const QString &)
260{
261 return false;
262}
263
264CertificateStore *Generator::certificateStore() const
265{
266 return nullptr;
267}
268
270{
271 Q_D(Generator);
272 d->mPixmapReady = false;
273
274 const bool calcBoundingBox = !request->isTile() && !request->page()->isBoundingBoxKnown();
275
276 if (request->asynchronous() && hasFeature(Threaded)) {
277 if (d->textPageGenerationThread()->isFinished() && !canGenerateTextPage()) {
278 // It can happen that the text generation has already finished but
279 // mTextPageReady is still false because textpageGenerationFinished
280 // didn't have time to run, if so queue ourselves
281 QTimer::singleShot(0, this, [this, request] { generatePixmap(request); });
282 return;
283 }
284
285 /**
286 * We create the text page for every page that is visible to the
287 * user, so he can use the text extraction tools without a delay.
288 */
289 if (hasFeature(TextExtraction) && !request->page()->hasTextPage() && canGenerateTextPage() && !d->m_closing) {
290 d->mTextPageReady = false;
291 d->textPageGenerationThread()->setPage(request->page());
292
293 // dummy is used as a way to make sure the lambda gets disconnected each time it is executed
294 // since not all the times the pixmap generation thread starts we want the text generation thread to also start
295 QObject *dummy = new QObject();
296 connect(d_ptr->pixmapGenerationThread(), &QThread::started, dummy, [this, dummy] {
297 delete dummy;
298 d_ptr->textPageGenerationThread()->startGeneration();
299 });
300 }
301 // pixmap generation thread must be started *after* connect(), else we may miss the start signal and get lock-ups (see bug 396137)
302 d->pixmapGenerationThread()->startGeneration(request, calcBoundingBox);
303
304 return;
305 }
306
307 const QImage &img = image(request);
308 request->page()->setPixmap(request->observer(), new QPixmap(QPixmap::fromImage(img)), request->normalizedRect());
309 const int pageNumber = request->page()->number();
310
311 d->mPixmapReady = true;
312
314 if (calcBoundingBox) {
316 }
317}
318
320{
321 Q_D(const Generator);
322 return d->mTextPageReady;
323}
324
326{
327 TextRequest treq(page);
328 TextPage *tp = textPage(&treq);
329 page->setTextPage(tp);
330 signalTextGenerationDone(page, tp);
331}
332
334{
335 Q_D(Generator);
336 return d->image(request);
337}
338
340{
341 return nullptr;
342}
343
345{
346 Q_UNUSED(keys);
347
348 return DocumentInfo();
349}
350
352{
353 return nullptr;
354}
355
360
362{
363 return nullptr;
364}
365
370
372{
373 return false;
374}
375
380
382{
383 return true;
384}
385
389
391{
392 return PageSize::List();
393}
394
396{
397}
398
400{
401 return Document::UnknownPrintError;
402}
403
404BackendOpaqueAction::OpaqueActionResult Generator::opaqueAction(const BackendOpaqueAction * /*action*/)
405{
406 return BackendOpaqueAction::DoNothing;
407}
408
409void Generator::freeOpaqueActionContents(const BackendOpaqueAction & /*action*/)
410{
411}
412
413QVariant Generator::metaData(const QString &key, const QVariant &option) const
414{
415 Q_D(const Generator);
416 return d->metaData(key, option);
417}
418
423
425{
426 return false;
427}
428
429void Generator::walletDataForFile(const QString &fileName, QString *walletName, QString *walletFolder, QString *walletKey) const
430{
431#if HAVE_KWALLET
432 *walletKey = fileName.section(QLatin1Char('/'), -1, -1);
433 *walletName = KWallet::Wallet::NetworkWallet();
434 *walletFolder = QStringLiteral("KPdf");
435#endif
436}
437
439{
440 Q_D(const Generator);
441 return d->m_features.contains(feature);
442}
443
445{
446 Q_D(Generator);
447 if (d->m_document) {
448 d->m_document->requestDone(request);
449 } else {
450 delete request;
451 }
452}
453
455{
456 Q_D(Generator);
457 if (d->m_document) {
458 d->m_document->textGenerationDone(page);
459 } else {
460 delete textPage;
461 }
462}
463
465{
466 if (request->shouldAbortRender()) {
467 return;
468 }
469
470 PagePrivate *pagePrivate = PagePrivate::get(request->page());
471 pagePrivate->setPixmap(request->observer(), new QPixmap(QPixmap::fromImage(image)), request->normalizedRect(), true /* isPartialPixmap */);
472
473 const int pageNumber = request->page()->number();
475}
476
478{
479 Q_D(const Generator);
480 if (d->m_document) {
481 return d->m_document->m_parent;
482 }
483 return nullptr;
484}
485
490
492{
493 Q_D(Generator);
494 if (on) {
495 d->m_features.insert(feature);
496 } else {
497 d->m_features.remove(feature);
498 }
499}
500
502{
503 Q_D(const Generator);
504 if (!d->m_document) {
505 return QVariant();
506 }
507
508 return d->m_document->documentMetaData(key, option);
509}
510
512{
513 Q_D(const Generator);
514 return &d->m_mutex;
515}
516
517void Generator::updatePageBoundingBox(int page, const NormalizedRect &boundingBox)
518{
519 Q_D(Generator);
520 if (d->m_document) { // still connected to document?
521 d->m_document->setPageBoundingBox(page, boundingBox);
522 }
523}
524
526{
527 return {};
528}
529
531{
532 Q_D(Generator);
533 d->m_dpi = dpi;
534}
535
537{
538 Q_D(const Generator);
539 return d->m_dpi;
540}
541
543{
544 return nullptr;
545}
546
547TextRequest::TextRequest()
548 : d(new TextRequestPrivate)
549{
550 d->mPage = nullptr;
551 d->mShouldAbortExtraction = 0;
552}
553
554TextRequest::TextRequest(Page *page)
555 : d(new TextRequestPrivate)
556{
557 d->mPage = page;
558 d->mShouldAbortExtraction = 0;
559}
560
562{
563 delete d;
564}
565
567{
568 return d->mPage;
569}
570
572{
573 return d->mShouldAbortExtraction != 0;
574}
575
576TextRequestPrivate *TextRequestPrivate::get(const TextRequest *req)
577{
578 return req->d;
579}
580
581PixmapRequest::PixmapRequest(DocumentObserver *observer, int pageNumber, int width, int height, qreal dpr, int priority, PixmapRequestFeatures features)
582 : d(new PixmapRequestPrivate)
583{
584 d->mObserver = observer;
585 d->mPageNumber = pageNumber;
586 d->mWidth = ceil(width * dpr);
587 d->mHeight = ceil(height * dpr);
588 d->mPriority = priority;
589 d->mFeatures = features;
590 d->mForce = false;
591 d->mTile = false;
592 d->mNormalizedRect = NormalizedRect();
593 d->mPartialUpdatesWanted = false;
594 d->mShouldAbortRender = 0;
595}
596
598{
599 delete d;
600}
601
603{
604 return d->mObserver;
605}
606
608{
609 return d->mPageNumber;
610}
611
613{
614 return d->mWidth;
615}
616
618{
619 return d->mHeight;
620}
621
623{
624 return d->mPriority;
625}
626
628{
629 return d->mFeatures & Asynchronous;
630}
631
633{
634 return d->mFeatures & Preload;
635}
636
638{
639 return d->mPage;
640}
641
643{
644 d->mTile = tile;
645}
646
648{
649 return d->mTile;
650}
651
653{
654 if (d->mNormalizedRect == rect) {
655 return;
656 }
657
658 d->mNormalizedRect = rect;
659}
660
662{
663 return d->mNormalizedRect;
664}
665
666void PixmapRequest::setPartialUpdatesWanted(bool partialUpdatesWanted)
667{
668 d->mPartialUpdatesWanted = partialUpdatesWanted;
669}
670
672{
673 return d->mPartialUpdatesWanted;
674}
675
677{
678 return d->mShouldAbortRender != 0;
679}
680
681Okular::TilesManager *PixmapRequestPrivate::tilesManager() const
682{
683 return mPage->d->tilesManager(mObserver);
684}
685
686PixmapRequestPrivate *PixmapRequestPrivate::get(const PixmapRequest *req)
687{
688 return req->d;
689}
690
691void PixmapRequestPrivate::swap()
692{
693 std::swap(mWidth, mHeight);
694}
695
696class Okular::ExportFormatPrivate : public QSharedData
697{
698public:
699 ExportFormatPrivate(const QString &description, const QMimeType &mimeType, const QIcon &icon = QIcon())
700 : QSharedData()
701 , mDescription(description)
702 , mMimeType(mimeType)
703 , mIcon(icon)
704 {
705 }
706 ~ExportFormatPrivate()
707 {
708 }
709
710 QString mDescription;
711 QMimeType mMimeType;
712 QIcon mIcon;
713};
714
716 : d(new ExportFormatPrivate(QString(), QMimeType()))
717{
718}
719
720ExportFormat::ExportFormat(const QString &description, const QMimeType &mimeType)
721 : d(new ExportFormatPrivate(description, mimeType))
722{
723}
724
725ExportFormat::ExportFormat(const QIcon &icon, const QString &description, const QMimeType &mimeType)
726 : d(new ExportFormatPrivate(description, mimeType, icon))
727{
728}
729
733
735 : d(other.d)
736{
737}
738
740{
741 if (this == &other) {
742 return *this;
743 }
744
745 d = other.d;
746
747 return *this;
748}
749
751{
752 return d->mDescription;
753}
754
756{
757 return d->mMimeType;
758}
759
761{
762 return d->mIcon;
763}
764
766{
767 return !d->mMimeType.isValid() || d->mDescription.isNull();
768}
769
771{
772 QMimeDatabase db;
773 switch (type) {
774 case PlainText:
775 return ExportFormat(QIcon::fromTheme(QStringLiteral("text-x-generic")), i18n("Plain &Text..."), db.mimeTypeForName(QStringLiteral("text/plain")));
776 break;
777 case PDF:
778 return ExportFormat(QIcon::fromTheme(QStringLiteral("application-pdf")), i18n("PDF"), db.mimeTypeForName(QStringLiteral("application/pdf")));
779 break;
780 case OpenDocumentText:
781 return ExportFormat(
782 QIcon::fromTheme(QStringLiteral("application-vnd.oasis.opendocument.text")), i18nc("This is the document format", "OpenDocument Text"), db.mimeTypeForName(QStringLiteral("application/vnd.oasis.opendocument.text")));
783 break;
784 case HTML:
785 return ExportFormat(QIcon::fromTheme(QStringLiteral("text-html")), i18nc("This is the document format", "HTML"), db.mimeTypeForName(QStringLiteral("text/html")));
786 break;
787 }
788 return ExportFormat();
789}
790
791bool ExportFormat::operator==(const ExportFormat &other) const
792{
793 return d == other.d;
794}
795
796bool ExportFormat::operator!=(const ExportFormat &other) const
797{
798 return d != other.d;
799}
800
802{
803 PixmapRequestPrivate *reqPriv = PixmapRequestPrivate::get(&req);
804
805 str << "PixmapRequest:" << &req;
806 str << "- observer:" << (qulonglong)req.observer();
807 str << "- page:" << req.pageNumber();
808 str << "- width:" << req.width();
809 str << "- height:" << req.height();
810 str << "- priority:" << req.priority();
811 str << "- async:" << (req.asynchronous() ? "true" : "false");
812 str << "- tile:" << (req.isTile() ? "true" : "false");
813 str << "- rect:" << req.normalizedRect();
814 str << "- preload:" << (req.preload() ? "true" : "false");
815 str << "- partialUpdates:" << (req.partialUpdatesWanted() ? "true" : "false");
816 str << "- shouldAbort:" << (req.shouldAbortRender() ? "true" : "false");
817 str << "- force:" << (reqPriv->mForce ? "true" : "false");
818 return str;
819}
820
821/* kate: replace-tabs on; indent-width 4; */
static const QString NetworkWallet()
Encapsulates data that describes an action.
Definition action.h:41
A helper class to store information about x509 certificate.
The DocumentInfo structure can be filled in by generators to display metadata about the currently ope...
Definition document.h:76
Base class for objects being notified when something changes.
Definition observer.h:29
virtual void notifyPageChanged(int page, int flags)
This method is called whenever the content on page described by the passed flags has been changed.
Definition observer.cpp:29
@ Pixmap
Pixmaps has been changed.
Definition observer.h:45
A DOM tree that describes the Table of Contents.
Definition document.h:1531
The Document.
Definition document.h:192
DocumentAdditionalActionType
Describes the additional actions available in the Document.
Definition document.h:775
OpenResult
Describes the result of an open document operation.
Definition document.h:210
Defines an entry for the export menu.
Definition generator.h:80
QMimeType mimeType() const
Returns the mime type of the format.
~ExportFormat()
Destroys the export format.
QString description() const
Returns the description of the format.
ExportFormat()
Creates an empty export format.
static ExportFormat standardFormat(StandardExportFormat type)
Builds a standard format for the specified type .
bool isNull() const
Returns whether the export format is null/valid.
QIcon icon() const
Returns the icon for GUI representations of the format.
ExportFormat & operator=(const ExportFormat &other)
StandardExportFormat
Type of standard export format.
Definition generator.h:149
@ PDF
PDF, aka Portable Document Format.
Definition generator.h:151
@ HTML
OpenDocument Text format.
Definition generator.h:153
@ OpenDocumentText
OpenDocument Text format.
Definition generator.h:152
@ PlainText
Plain text.
Definition generator.h:150
A small class that represents the information of a font.
Definition fontinfo.h:25
[Abstract Class] The information generator.
Definition generator.h:189
virtual void walletDataForFile(const QString &fileName, QString *walletName, QString *walletFolder, QString *walletKey) const
This method is called to know which wallet data should be used for the given file name.
virtual void freeOpaqueActionContents(const BackendOpaqueAction &action)
Frees the contents of the opaque action (if any);.
virtual void pageSizeChanged(const PageSize &pageSize, const PageSize &oldPageSize)
This method is called when the page size has been changed by the user.
virtual BackendOpaqueAction::OpaqueActionResult opaqueAction(const BackendOpaqueAction *action)
Calls the backend to execute a BackendOpaqueAction action and returns BackendOpaqueAction result.
virtual void generatePixmap(PixmapRequest *request)
This method can be called to trigger the generation of a new pixmap as described by request.
void generateTextPage(Page *page)
This method can be called to trigger the generation of a text page for the given page.
virtual const DocumentSynopsis * generateDocumentSynopsis()
Returns the 'table of content' object of the document or 0 if no table of content is available.
Generator(QObject *parent=nullptr, const QVariantList &args=QVariantList())
Creates a new generator.
virtual ExportFormat::List exportFormats() const
Returns the list of additional supported export formats.
virtual QAbstractItemModel * layersModel() const
Returns the 'layers model' object of the document or NULL if layers model is not available.
SwapBackingFileResult
Describes the result of an swap file operation.
Definition generator.h:279
DocumentMetaDataKey
Internal document setting.
Definition generator.h:576
virtual bool loadDocument(const QString &fileName, QVector< Page * > &pagesVector)
Loads the document with the given fileName and fills the pagesVector with the parsed pages.
void signalPartialPixmapRequest(Okular::PixmapRequest *request, const QImage &image)
This method can be called to trigger a partial pixmap update for the given request Make sure you call...
virtual Document::OpenResult loadDocumentWithPassword(const QString &fileName, QVector< Page * > &pagesVector, const QString &password)
Loads the document with the given fileName and password and fills the pagesVector with the parsed pag...
virtual void rotationChanged(Rotation orientation, Rotation oldOrientation)
This method is called when the orientation has been changed by the user.
virtual QVariant metaData(const QString &key, const QVariant &option) const
This method returns the meta data of the given key with the given option of the document.
virtual const QList< EmbeddedFile * > * embeddedFiles() const
Returns the 'list of embedded files' object of the document or 0 if no list of embedded files is avai...
bool hasFeature(GeneratorFeature feature) const
Query for the specified feature.
void signalTextGenerationDone(Page *page, TextPage *textPage)
This method must be called when a text generation has been finished.
bool closeDocument()
This method is called when the document is closed and not used any longer.
QSizeF dpi() const
Returns DPI, previously set via setDPI()
virtual TextPage * textPage(TextRequest *request)
Returns the text page for the given request.
virtual bool isAllowed(Permission action) const
Returns whether the given action is allowed in the document.
virtual FontInfo::List fontsForPage(int page)
Returns the 'list of embedded fonts' object of the specified page of the document.
~Generator() override
Destroys the generator.
GeneratorFeature
Describe the possible optional features that a Generator can provide.
Definition generator.h:202
@ Threaded
Whether the Generator supports asynchronous generation of pictures or text pages.
Definition generator.h:203
@ TextExtraction
Whether the Generator can extract text from the document in the form of TextPage's.
Definition generator.h:204
virtual Document::OpenResult loadDocumentFromDataWithPassword(const QByteArray &fileData, QVector< Page * > &pagesVector, const QString &password)
Loads the document from the raw data fileData and password and fills the pagesVector with the parsed ...
virtual SwapBackingFileResult swapBackingFile(const QString &newFileName, QVector< Okular::Page * > &newPagesVector)
Changes the path of the file we are reading from.
void setDPI(const QSizeF dpi)
Update DPI of the generator.
virtual DocumentInfo generateDocumentInfo(const QSet< DocumentInfo::Key > &keys) const
Returns the general information object of the document.
virtual PageSizeMetric pagesSizeMetric() const
This method returns the metric of the page size.
virtual bool exportTo(const QString &fileName, const ExportFormat &format)
This method is called to export the document in the given format and save it under the given fileName...
QVariant documentMetaData(const DocumentMetaDataKey key, const QVariant &option=QVariant()) const
Request a meta data of the Document, if available, like an internal setting.
PageSizeMetric
This enum identifies the metric of the page size.
Definition generator.h:394
@ None
The page size is not defined in a physical metric.
Definition generator.h:395
const Document * document() const
Returns a pointer to the document.
virtual bool canGenerateTextPage() const
This method returns whether the generator is ready to handle a new text page request.
void setFeature(GeneratorFeature feature, bool on=true)
Toggle the feature .
void signalPixmapRequestDone(PixmapRequest *request)
This method must be called when the pixmap request triggered by generatePixmap() has been finished.
PageLayout
This enum identifies default page layouts.
Definition generator.h:370
@ NoLayout
Layout not specified.
Definition generator.h:371
virtual Okular::Action * additionalDocumentAction(Document::DocumentAdditionalActionType type)
Retrieves the additional document action for the specified type .
void updatePageBoundingBox(int page, const NormalizedRect &boundingBox)
Set the bounding box of a page after the page has already been handed to the Document.
virtual Document::PrintError print(QPrinter &printer)
This method is called to print the document to the given printer.
virtual PageSize::List pageSizes() const
Returns the list of supported page sizes.
virtual bool doCloseDocument()=0
This method is called when the document is closed and not used any longer.
virtual bool loadDocumentFromData(const QByteArray &fileData, QVector< Page * > &pagesVector)
Loads the document from the raw data fileData and fills the pagesVector with the parsed pages.
virtual QByteArray requestFontData(const Okular::FontInfo &font)
Gets the font data for the given font.
virtual PageLayout defaultPageLayout() const
This method returns the default page layout.
virtual bool canGeneratePixmap() const
This method returns whether the generator is ready to handle a new pixmap request.
virtual QImage image(PixmapRequest *request)
Returns the image of the page as specified in the passed pixmap request.
QMutex * userMutex() const
Return the pointer to a mutex the generator can use freely.
virtual bool defaultPageContinuous() const
This method returns if the default page layout is continuous.
Data needed to create a new signature.
Definition document.h:1638
A NormalizedRect is a rectangle which can be defined by two NormalizedPoints.
Definition area.h:189
A small class that represents the size of a page.
Definition pagesize.h:24
Collector for all the data belonging to a page.
Definition page.h:48
void setTextPage(TextPage *text)
Sets the text page.
Definition page.cpp:585
int number() const
Returns the number of the page in the document.
Definition page.cpp:160
bool hasTextPage() const
Returns whether the page provides a text page (TextPage).
Definition page.cpp:256
void setPixmap(DocumentObserver *observer, QPixmap *pixmap, const NormalizedRect &rect=NormalizedRect())
Sets the region described by rect with pixmap for the given observer.
Definition page.cpp:547
bool isBoundingBoxKnown() const
Returns whether the bounding box of the page has been computed.
Definition page.cpp:200
Describes a pixmap type request.
Definition generator.h:645
bool preload() const
Returns whether the generation request is for a page that is not important i.e.
void setTile(bool tile)
Sets whether the generator should render only the given normalized rect or the entire page.
bool asynchronous() const
Returns whether the generation should be done synchronous or asynchronous.
bool shouldAbortRender() const
Should the request be aborted if possible?
PixmapRequest(DocumentObserver *observer, int pageNumber, int width, int height, qreal dpr, int priority, PixmapRequestFeatures features)
Creates a new pixmap request.
~PixmapRequest()
Destroys the pixmap request.
void setPartialUpdatesWanted(bool partialUpdatesWanted)
Sets whether the request should report back updates if possible.
int width() const
Returns the page width of the requested pixmap.
int height() const
Returns the page height of the requested pixmap.
int priority() const
Returns the priority (less it better, 0 is maximum) of the request.
const NormalizedRect & normalizedRect() const
Returns the normalized region of the page to request.
bool partialUpdatesWanted() const
Should the request report back updates if possible?
int pageNumber() const
Returns the page number of the request.
void setNormalizedRect(const NormalizedRect &rect)
Sets the region of the page to request.
Page * page() const
Returns a pointer to the page where the pixmap shall be generated for.
bool isTile() const
Returns whether the generator should render just the region given by normalizedRect() or the entire p...
DocumentObserver * observer() const
Returns the observer of the request.
Represents the textual information of a Page.
Definition textpage.h:102
Describes a text request.
Definition generator.h:781
bool shouldAbortExtraction() const
Should the request be aborted if possible?
Page * page() const
Returns a pointer to the page where the pixmap shall be generated for.
~TextRequest()
Destroys the pixmap request.
static NormalizedRect imageBoundingBox(const QImage *image)
Compute the smallest rectangle that contains all non-white pixels in image), in normalized [0,...
Definition utils.cpp:69
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
KCALUTILS_EXPORT QString mimeType()
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
global.h
Definition action.h:17
Permission
Describes the DRM capabilities.
Definition global.h:24
Rotation
A rotation.
Definition global.h:46
int exec(ProcessEventsFlags flags)
QIcon fromTheme(const QString &name)
QMimeType mimeTypeForName(const QString &nameOrAlias) const const
QObject(QObject *parent)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags)
QString section(QChar sep, qsizetype start, qsizetype end, SectionFlags flags) const const
QueuedConnection
void started()
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:02:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.