Okular

generator.h
1 /***************************************************************************
2  * Copyright (C) 2004-5 by Enrico Ros <[email protected]> *
3  * Copyright (C) 2005 by Piotr Szymanski <[email protected]> *
4  * Copyright (C) 2008 by Albert Astals Cid <[email protected]> *
5  * Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group *
6  * company, [email protected] Work sponsored by the *
7  * LiMux project of the city of Munich *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  ***************************************************************************/
14 
15 #ifndef _OKULAR_GENERATOR_H_
16 #define _OKULAR_GENERATOR_H_
17 
18 #include "okularcore_export.h"
19 #include "document.h"
20 #include "fontinfo.h"
21 #include "global.h"
22 #include "pagesize.h"
23 
24 #include <QList>
25 #include <QObject>
26 #include <QSharedDataPointer>
27 #include <QSizeF>
28 #include <QString>
29 #include <QVariant>
30 #include <QVector>
31 
32 #include <QMimeType>
33 #include <kpluginfactory.h>
34 
35 #define OKULAR_EXPORT_PLUGIN(classname, json ) \
36  static_assert(json[0] != '\0', "arg2 must be a string literal"); \
37  K_PLUGIN_CLASS_WITH_JSON(classname, json)
38 
39 class QByteArray;
40 class QMutex;
41 class QPrinter;
42 class QIcon;
43 
44 namespace Okular {
45 
46 class BackendOpaqueAction;
47 class DocumentFonts;
48 class DocumentInfo;
49 class DocumentObserver;
50 class DocumentSynopsis;
51 class EmbeddedFile;
52 class ExportFormatPrivate;
53 class FontInfo;
54 class GeneratorPrivate;
55 class Page;
56 class PixmapRequest;
57 class PixmapRequestPrivate;
58 class TextPage;
59 class TextRequest;
60 class TextRequestPrivate;
61 class NormalizedRect;
62 
63 /* Note: on contents generation and asynchronous queries.
64  * Many observers may want to request data synchronously or asynchronously.
65  * - Sync requests. These should be done in-place.
66  * - Async request must be done in real background. That usually means a
67  * thread, such as QThread derived classes.
68  * Once contents are available, they must be immediately stored in the
69  * Page they refer to, and a signal is emitted as soon as storing
70  * (even for sync or async queries) has been done.
71  */
72 
80 class OKULARCORE_EXPORT ExportFormat
81 {
82  public:
83  typedef QList<ExportFormat> List;
84 
90  ExportFormat();
91 
98  ExportFormat( const QString &description, const QMimeType &mimeType );
99 
107  ExportFormat( const QIcon &icon, const QString &description, const QMimeType &mimeType );
108 
112  ~ExportFormat();
113 
117  ExportFormat( const ExportFormat &other );
118 
122  ExportFormat& operator=( const ExportFormat &other );
123 
127  QString description() const;
128 
132  QMimeType mimeType() const;
133 
137  QIcon icon() const;
138 
145  bool isNull() const;
146 
151  {
153  PDF,
155  HTML
156  };
157 
161  static ExportFormat standardFormat( StandardExportFormat type );
162 
163  bool operator==( const ExportFormat &other ) const;
164 
165  bool operator!=( const ExportFormat &other ) const;
166 
167  private:
169  friend class ExportFormatPrivate;
172 };
173 
190 class OKULARCORE_EXPORT Generator : public QObject
191 {
193  friend class PixmapGenerationThread;
194  friend class TextPageGenerationThread;
196 
197  Q_OBJECT
198 
199  public:
205  {
216  SupportsCancelling
217  };
218 
222  explicit Generator(QObject* parent = nullptr, const QVariantList& args = QVariantList());
223 
227  ~Generator() override;
228 
237  virtual bool loadDocument( const QString & fileName, QVector< Page * > & pagesVector );
238 
249  virtual bool loadDocumentFromData( const QByteArray & fileData, QVector< Page * > & pagesVector );
250 
261  virtual Document::OpenResult loadDocumentWithPassword( const QString & fileName, QVector< Page * > & pagesVector, const QString &password );
262 
275  virtual Document::OpenResult loadDocumentFromDataWithPassword( const QByteArray & fileData, QVector< Page * > & pagesVector, const QString &password );
276 
283  {
284  SwapBackingFileError, //< The document could not be swapped
285  SwapBackingFileNoOp, //< The document was swapped and nothing needs to be done
286  SwapBackingFileReloadInternalData //< The document was swapped and internal data (forms, annotations, etc) needs to be reloaded
287  };
288 
297  virtual SwapBackingFileResult swapBackingFile( const QString & newFileName, QVector<Okular::Page*> & newPagesVector );
298 
305  bool closeDocument();
306 
311  virtual bool canGeneratePixmap() const;
312 
317  virtual void generatePixmap( PixmapRequest * request );
318 
323  virtual bool canGenerateTextPage() const;
324 
333  void generateTextPage( Page * page );
334 
340  virtual DocumentInfo generateDocumentInfo( const QSet<DocumentInfo::Key> &keys ) const;
341 
346  virtual const DocumentSynopsis * generateDocumentSynopsis();
347 
355  virtual FontInfo::List fontsForPage( int page );
356 
361  virtual const QList<EmbeddedFile*> * embeddedFiles() const;
362 
367  {
370  Pixels
371  };
372 
376  virtual PageSizeMetric pagesSizeMetric() const;
377 
382  virtual bool isAllowed( Permission action ) const;
383 
387  virtual void rotationChanged( Rotation orientation, Rotation oldOrientation );
388 
392  virtual PageSize::List pageSizes() const;
393 
397  virtual void pageSizeChanged( const PageSize &pageSize, const PageSize &oldPageSize );
398 
402  virtual bool print( QPrinter &printer );
403 
409  {
411  UnknownPrintError,
412  TemporaryFileOpenPrintError,
413  FileConversionPrintError,
414  PrintingProcessCrashPrintError,
415  PrintingProcessStartPrintError,
416  PrintToFilePrintError,
417  InvalidPrinterStatePrintError,
418  UnableToFindFilePrintError,
419  NoFileToPrintError,
420  NoBinaryToPrintError,
421  InvalidPageSizePrintError
422  };
423 
428  virtual QVariant metaData( const QString &key, const QVariant &option ) const;
429 
433  virtual ExportFormat::List exportFormats() const;
434 
439  virtual bool exportTo( const QString &fileName, const ExportFormat &format );
440 
446  virtual void walletDataForFile( const QString &fileName, QString *walletName, QString *walletFolder, QString *walletKey ) const;
447 
451  bool hasFeature( GeneratorFeature feature ) const;
452 
458  void setDPI(const QSizeF &dpi); // TODO remove the & when we do a BIC change elsewhere
459 
466  virtual QAbstractItemModel * layersModel() const;
467 
471  virtual void opaqueAction( const BackendOpaqueAction *action );
472 
473  Q_SIGNALS:
480  void error( const QString &message, int duration );
481 
488  void warning( const QString &message, int duration );
489 
496  void notice( const QString &message, int duration );
497 
498  protected:
503  void signalPixmapRequestDone( PixmapRequest * request );
504 
508  void signalTextGenerationDone( Page *page, TextPage *textPage );
509 
516  virtual bool doCloseDocument() = 0;
517 
527  virtual QImage image( PixmapRequest *request );
528 
539  virtual TextPage* textPage( TextRequest *request );
540 
544  const Document * document() const;
545 
549  void setFeature( GeneratorFeature feature, bool on = true );
550 
558  TextHintingMetaData
559  };
560 
567  QVariant documentMetaData( const DocumentMetaDataKey key, const QVariant &option = QVariant() ) const;
568 
573  OKULARCORE_DEPRECATED QVariant documentMetaData( const QString &key, const QVariant &option = QVariant() ) const;
574 
578  QMutex* userMutex() const;
579 
587  void updatePageBoundingBox( int page, const NormalizedRect & boundingBox );
588 
593  QSizeF dpi() const;
594 
595  protected Q_SLOTS:
601  void requestFontData(const Okular::FontInfo &font, QByteArray *data);
602 
608  void signalPartialPixmapRequest( Okular::PixmapRequest *request, const QImage &image );
609 
610  protected:
615  // TODO Make print() return a PrintError instead of bool and remove this function when a BIC change happens somewhere else
616  Q_INVOKABLE Okular::Generator::PrintError printError() const;
617 
619  Generator(GeneratorPrivate &dd, QObject *parent, const QVariantList &args);
620  Q_DECLARE_PRIVATE( Generator )
621  GeneratorPrivate *d_ptr;
622 
623  friend class Document;
624  friend class DocumentPrivate;
626 
627  private:
628  Q_DISABLE_COPY( Generator )
629 };
630 
634 class OKULARCORE_EXPORT PixmapRequest
635 {
636  friend class Document;
637  friend class DocumentPrivate;
638 
639  public:
640  enum PixmapRequestFeature
641  {
642  NoFeature = 0,
643  Asynchronous = 1,
644  Preload = 2
645  };
646  Q_DECLARE_FLAGS( PixmapRequestFeatures, PixmapRequestFeature )
647 
648 
658  PixmapRequest( DocumentObserver *observer, int pageNumber, int width, int height, int priority, PixmapRequestFeatures features );
659 
663  ~PixmapRequest();
664 
668  DocumentObserver *observer() const;
669 
673  int pageNumber() const;
674 
678  int width() const;
679 
683  int height() const;
684 
689  int priority() const;
690 
698  bool asynchronous() const;
699 
704  bool preload() const;
705 
709  Page *page() const;
710 
717  void setTile( bool tile );
718 
725  bool isTile() const;
726 
732  void setNormalizedRect( const NormalizedRect &rect );
733 
739  const NormalizedRect& normalizedRect() const;
740 
746  void setPartialUpdatesWanted(bool partialUpdatesWanted);
747 
753  bool partialUpdatesWanted() const;
754 
760  bool shouldAbortRender() const;
761 
762  private:
763  Q_DISABLE_COPY( PixmapRequest )
764 
765  friend class PixmapRequestPrivate;
766  PixmapRequestPrivate* const d;
767 };
768 
774 class OKULARCORE_EXPORT TextRequest
775 {
776  public:
780  explicit TextRequest( Page *page );
781 
782  TextRequest();
783 
787  ~TextRequest();
788 
792  Page *page() const;
793 
797  bool shouldAbortExtraction() const;
798 
799  private:
800  Q_DISABLE_COPY( TextRequest )
801 
802  friend TextRequestPrivate;
803  TextRequestPrivate* const d;
804 };
805 
806 }
807 
808 Q_DECLARE_METATYPE(Okular::Generator::PrintError)
809 Q_DECLARE_METATYPE(Okular::PixmapRequest*)
810 
811 #define OkularGeneratorInterface_iid "org.kde.okular.Generator"
812 Q_DECLARE_INTERFACE(Okular::Generator, OkularGeneratorInterface_iid)
813 
814 #ifndef QT_NO_DEBUG_STREAM
815 OKULARCORE_EXPORT QDebug operator<<( QDebug str, const Okular::PixmapRequest &req );
816 #endif
817 
818 #endif
819 
820 /* kate: replace-tabs on; indent-width 4; */
Whether the Generator supports export to PDF & PS through the Print Dialog.
Definition: generator.h:213
DocumentMetaDataKey
Internal document setting.
Definition: generator.h:554
Rotation
A rotation.
Definition: global.h:50
Represents the textual information of a Page.
Definition: textpage.h:108
PageSizeMetric
This enum identifies the metric of the page size.
Definition: generator.h:366
Whether the Generator can read a document directly from its raw data.
Definition: generator.h:208
A NormalizedRect is a rectangle which can be defined by two NormalizedPoints.
Definition: area.h:192
Returns (bool) text antialias from Settings (option is not used)
Definition: generator.h:556
Whether the Generator can provide information about the fonts used in the document.
Definition: generator.h:209
Describes a text request.
Definition: generator.h:774
Whether the Generator supports postscript-based file printing.
Definition: generator.h:212
global.h
Definition: action.h:19
The page size is given in 1/72 inches.
Definition: generator.h:369
OpenResult
Describes the result of an open document operation.
Definition: document.h:211
Whether the Generator can hot-swap the file it&#39;s reading from.
Definition: generator.h:215
Whether the Generator supports asynchronous generation of pictures or text pages. ...
Definition: generator.h:206
A small class that represents the information of a font.
Definition: fontinfo.h:27
There was no print error.
Definition: generator.h:410
OpenDocument Text format.
Definition: generator.h:154
The Document.
Definition: document.h:192
Collector for all the data belonging to a page.
Definition: page.h:52
Whether the Generator can change the size of the document pages.
Definition: generator.h:210
Will create the object in an asynchronous way.
Definition: global.h:64
Returns (QColor) the paper color if set in Settings or the default color (white) if option is true (o...
Definition: generator.h:555
StandardExportFormat
Type of standard export format.
Definition: generator.h:150
Whether the Generator supports native cross-platform printing (QPainter-based).
Definition: generator.h:211
The DocumentInfo structure can be filled in by generators to display metadata about the currently ope...
Definition: document.h:74
PDF, aka Portable Document Format.
Definition: generator.h:153
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
Returns (bool)graphic antialias from Settings (option is not used)
Definition: generator.h:557
The page size is not defined in a physical metric.
Definition: generator.h:368
Defines an entry for the export menu.
Definition: generator.h:80
A small class that represents the size of a page.
Definition: pagesize.h:26
PrintError
Possible print errors.
Definition: generator.h:408
Base class for objects being notified when something changes.
Definition: observer.h:31
Whether the Generator can render tiles.
Definition: generator.h:214
Permission
Describes the DRM capabilities.
Definition: global.h:26
Whether the Generator can extract text from the document in the form of TextPage&#39;s.
Definition: generator.h:207
SwapBackingFileResult
Describes the result of an swap file operation.
Definition: generator.h:282
A DOM tree that describes the Table of Contents.
Definition: document.h:1376
Describes a pixmap type request.
Definition: generator.h:634
[Abstract Class] The information generator.
Definition: generator.h:190
GeneratorFeature
Describe the possible optional features that a Generator can provide.
Definition: generator.h:204
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jul 6 2020 22:35:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.