~adamreichold/qpdfview/trunk

1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
1
/*
2
2079 by Adam Reichold
Merge update to Fitz plug-in including support for EPUB, XPS, CBZ and FB2 by S. Razi Alavizadeh.
3
Copyright 2018 S. Razi Alavizadeh
4
Copyright 2014, 2018 Adam Reichold
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
5
6
This file is part of qpdfview.
7
8
qpdfview is free software: you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation, either version 2 of the License, or
11
(at your option) any later version.
12
13
qpdfview is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with qpdfview.  If not, see <http://www.gnu.org/licenses/>.
20
21
*/
22
1518 by Adam Reichold
Make proper use of application and anonymous namespaces and fix a few header guards.
23
#ifndef FITZMODEL_H
24
#define FITZMODEL_H
25
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
26
#include <QMutex>
27
28
extern "C"
29
{
30
1432.2.4 by Adam Reichold
Be more economical about the Fitz headers.
31
#include <mupdf/fitz/context.h>
32
2107 by Adam Reichold
Fix build of Fitz plug-in using MuPDF v1.17.
33
typedef struct fz_page fz_page;
34
typedef struct fz_document fz_document;
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
35
36
}
37
38
#include "model.h"
39
1518 by Adam Reichold
Make proper use of application and anonymous namespaces and fix a few header guards.
40
namespace qpdfview
41
{
42
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
43
class FitzPlugin;
44
1521 by Adam Reichold
Follow Qt Creator style guide and use capital letter for namespaces and refactor Djvu link loading code.
45
namespace Model
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
46
{
47
    class FitzPage : public Page
48
    {
49
        friend class FitzDocument;
50
51
    public:
52
        ~FitzPage();
53
54
        QSizeF size() const;
55
2041.2.12 by Adam Reichold
Fix usage of QList in the bookmark and search models and various small performance issues reported by the clazy tool using the checks of "level0,level1,level2,no-missing-qobject-macro,no-qstring-allocations,no-copyable-polymorphic,no-ctor-missing-parent-argument,no-reserve-candidates".
56
        QImage render(qreal horizontalResolution, qreal verticalResolution, Rotation rotation, QRect boundingRect) const;
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
57
1432.2.5 by Adam Reichold
Make Fitz includes and libraries configurable and add basic link-loading support.
58
        QList< Link* > links() const;
59
2075.2.2 by Razi Alavizadeh
Support to select text by fitz plugin
60
        QString text(const QRectF& rect) const;
61
2075.2.3 by Razi Alavizadeh
Implement search capability for fitz plugin
62
        QList< QRectF > search(const QString& text, bool matchCase, bool wholeWords) const;
63
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
64
    private:
65
        Q_DISABLE_COPY(FitzPage)
66
1432.2.7 by Adam Reichold
Reduce size of Fitz pages by using a parent pointer and make the plug-in respect the paper color.
67
        FitzPage(const class FitzDocument* parent, fz_page* page);
68
69
        const class FitzDocument* m_parent;
70
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
71
        fz_page* m_page;
2100 by Adam Reichold
Memoize bounding rectangle in Fitz as this should not change during page lifetime.
72
        const fz_rect m_boundingRect;
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
73
2101 by Adam Reichold
Opportunistically share display lists between tiles in Fitz plug-in to reduce rendering latency.
74
        struct DisplayList;
75
        mutable DisplayList* m_displayList;
76
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
77
    };
78
79
    class FitzDocument : public Document
80
    {
1432.2.7 by Adam Reichold
Reduce size of Fitz pages by using a parent pointer and make the plug-in respect the paper color.
81
        friend class FitzPage;
1518 by Adam Reichold
Make proper use of application and anonymous namespaces and fix a few header guards.
82
        friend class qpdfview::FitzPlugin;
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
83
84
    public:
85
        ~FitzDocument();
86
87
        int numberOfPages() const;
88
89
        Page* page(int index) const;
90
1432.2.6 by Adam Reichold
Add outline loading and printing PDF using CUPS to the Fitz plug-in.
91
        bool canBePrintedUsingCUPS() const;
92
1875 by Adam Reichold
Disable tab-key navigation within the properties dock.
93
        void setPaperColor(const QColor& paperColor);
1432.2.7 by Adam Reichold
Reduce size of Fitz pages by using a parent pointer and make the plug-in respect the paper color.
94
2040 by Adam Reichold
Improve naming consistency in the model accessor methods.
95
        Outline outline() const;
1432.2.6 by Adam Reichold
Add outline loading and printing PDF using CUPS to the Fitz plug-in.
96
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
97
    private:
98
        Q_DISABLE_COPY(FitzDocument)
99
100
        FitzDocument(fz_context* context, fz_document* document);
101
102
        mutable QMutex m_mutex;
103
        fz_context* m_context;
104
        fz_document* m_document;
105
1432.2.7 by Adam Reichold
Reduce size of Fitz pages by using a parent pointer and make the plug-in respect the paper color.
106
        QColor m_paperColor;
107
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
108
    };
109
}
110
111
class FitzPlugin : public QObject, Plugin
112
{
113
    Q_OBJECT
1518 by Adam Reichold
Make proper use of application and anonymous namespaces and fix a few header guards.
114
    Q_INTERFACES(qpdfview::Plugin)
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
115
116
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
117
118
    Q_PLUGIN_METADATA(IID "local.qpdfview.Plugin")
119
120
#endif // QT_VERSION
121
122
public:
123
    FitzPlugin(QObject* parent = 0);
1432.2.3 by Adam Reichold
Remove an unnecessary copy from the Fitz render method and free the main context in the plug-in destructor.
124
    ~FitzPlugin();
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
125
1521 by Adam Reichold
Follow Qt Creator style guide and use capital letter for namespaces and refactor Djvu link loading code.
126
    Model::Document* loadDocument(const QString& filePath) const;
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
127
128
private:
129
    QMutex m_mutex[FZ_LOCK_MAX];
2100 by Adam Reichold
Memoize bounding rectangle in Fitz as this should not change during page lifetime.
130
    fz_locks_context m_locksContext;
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
131
    fz_context* m_context;
132
133
    static void lock(void* user, int lock);
134
    static void unlock(void* user, int lock);
135
136
};
1518 by Adam Reichold
Make proper use of application and anonymous namespaces and fix a few header guards.
137
138
} // qpdfview
139
140
#endif // FITZMODEL_H