1 | /* |
---|
2 | |
---|
3 | Copyright 2014 Adam Reichold |
---|
4 | |
---|
5 | This file is part of qpdfview. |
---|
6 | |
---|
7 | qpdfview is free software: you can redistribute it and/or modify |
---|
8 | it under the terms of the GNU General Public License as published by |
---|
9 | the Free Software Foundation, either version 2 of the License, or |
---|
10 | (at your option) any later version. |
---|
11 | |
---|
12 | qpdfview is distributed in the hope that it will be useful, |
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | GNU General Public License for more details. |
---|
16 | |
---|
17 | You should have received a copy of the GNU General Public License |
---|
18 | along with qpdfview. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | |
---|
20 | */ |
---|
21 | |
---|
22 | #ifndef FITZMODEL_H |
---|
23 | #define FITZMODEL_H |
---|
24 | |
---|
25 | #include <QMutex> |
---|
26 | |
---|
27 | extern "C" |
---|
28 | { |
---|
29 | |
---|
30 | #include <mupdf/fitz/context.h> |
---|
31 | |
---|
32 | typedef struct fz_page_s fz_page; |
---|
33 | typedef struct fz_document_s fz_document; |
---|
34 | |
---|
35 | } |
---|
36 | |
---|
37 | #include "model.h" |
---|
38 | |
---|
39 | namespace qpdfview |
---|
40 | { |
---|
41 | |
---|
42 | class FitzPlugin; |
---|
43 | |
---|
44 | namespace Model |
---|
45 | { |
---|
46 | class FitzPage : public Page |
---|
47 | { |
---|
48 | friend class FitzDocument; |
---|
49 | |
---|
50 | public: |
---|
51 | ~FitzPage(); |
---|
52 | |
---|
53 | QSizeF size() const; |
---|
54 | |
---|
55 | QImage render(qreal horizontalResolution, qreal verticalResolution, Rotation rotation, const QRect& boundingRect) const; |
---|
56 | |
---|
57 | QList< Link* > links() const; |
---|
58 | |
---|
59 | private: |
---|
60 | Q_DISABLE_COPY(FitzPage) |
---|
61 | |
---|
62 | FitzPage(const class FitzDocument* parent, fz_page* page); |
---|
63 | |
---|
64 | const class FitzDocument* m_parent; |
---|
65 | |
---|
66 | fz_page* m_page; |
---|
67 | |
---|
68 | }; |
---|
69 | |
---|
70 | class FitzDocument : public Document |
---|
71 | { |
---|
72 | friend class FitzPage; |
---|
73 | friend class qpdfview::FitzPlugin; |
---|
74 | |
---|
75 | public: |
---|
76 | ~FitzDocument(); |
---|
77 | |
---|
78 | int numberOfPages() const; |
---|
79 | |
---|
80 | Page* page(int index) const; |
---|
81 | |
---|
82 | bool canBePrintedUsingCUPS() const; |
---|
83 | |
---|
84 | void setPaperColor(const QColor& paperColor); |
---|
85 | |
---|
86 | void loadOutline(QStandardItemModel* outlineModel) const; |
---|
87 | |
---|
88 | private: |
---|
89 | Q_DISABLE_COPY(FitzDocument) |
---|
90 | |
---|
91 | FitzDocument(fz_context* context, fz_document* document); |
---|
92 | |
---|
93 | mutable QMutex m_mutex; |
---|
94 | fz_context* m_context; |
---|
95 | fz_document* m_document; |
---|
96 | |
---|
97 | QColor m_paperColor; |
---|
98 | |
---|
99 | }; |
---|
100 | } |
---|
101 | |
---|
102 | class FitzPlugin : public QObject, Plugin |
---|
103 | { |
---|
104 | Q_OBJECT |
---|
105 | Q_INTERFACES(qpdfview::Plugin) |
---|
106 | |
---|
107 | #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) |
---|
108 | |
---|
109 | Q_PLUGIN_METADATA(IID "local.qpdfview.Plugin") |
---|
110 | |
---|
111 | #endif // QT_VERSION |
---|
112 | |
---|
113 | public: |
---|
114 | FitzPlugin(QObject* parent = 0); |
---|
115 | ~FitzPlugin(); |
---|
116 | |
---|
117 | Model::Document* loadDocument(const QString& filePath) const; |
---|
118 | |
---|
119 | private: |
---|
120 | QMutex m_mutex[FZ_LOCK_MAX]; |
---|
121 | fz_locks_context m_locks_context; |
---|
122 | fz_context* m_context; |
---|
123 | |
---|
124 | static void lock(void* user, int lock); |
---|
125 | static void unlock(void* user, int lock); |
---|
126 | |
---|
127 | }; |
---|
128 | |
---|
129 | } // qpdfview |
---|
130 | |
---|
131 | #endif // FITZMODEL_H |
---|