Okular

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

KDE's Doxygen guidelines are available online.