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

KDE's Doxygen guidelines are available online.