~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
33
typedef struct fz_page_s fz_page;
34
typedef struct fz_document_s 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;
72
73
    };
74
75
    class FitzDocument : public Document
76
    {
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.
77
        friend class FitzPage;
1518 by Adam Reichold
Make proper use of application and anonymous namespaces and fix a few header guards.
78
        friend class qpdfview::FitzPlugin;
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
79
80
    public:
81
        ~FitzDocument();
82
83
        int numberOfPages() const;
84
85
        Page* page(int index) const;
86
1432.2.6 by Adam Reichold
Add outline loading and printing PDF using CUPS to the Fitz plug-in.
87
        bool canBePrintedUsingCUPS() const;
88
1875 by Adam Reichold
Disable tab-key navigation within the properties dock.
89
        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.
90
2040 by Adam Reichold
Improve naming consistency in the model accessor methods.
91
        Outline outline() const;
1432.2.6 by Adam Reichold
Add outline loading and printing PDF using CUPS to the Fitz plug-in.
92
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
93
    private:
94
        Q_DISABLE_COPY(FitzDocument)
95
96
        FitzDocument(fz_context* context, fz_document* document);
97
98
        mutable QMutex m_mutex;
99
        fz_context* m_context;
100
        fz_document* m_document;
101
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.
102
        QColor m_paperColor;
103
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
104
    };
105
}
106
107
class FitzPlugin : public QObject, Plugin
108
{
109
    Q_OBJECT
1518 by Adam Reichold
Make proper use of application and anonymous namespaces and fix a few header guards.
110
    Q_INTERFACES(qpdfview::Plugin)
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
111
112
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
113
114
    Q_PLUGIN_METADATA(IID "local.qpdfview.Plugin")
115
116
#endif // QT_VERSION
117
118
public:
119
    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.
120
    ~FitzPlugin();
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
121
1521 by Adam Reichold
Follow Qt Creator style guide and use capital letter for namespaces and refactor Djvu link loading code.
122
    Model::Document* loadDocument(const QString& filePath) const;
1432.2.1 by Adam Reichold
Add simplistic Fitz (the rendering library of MuPDF) plug-in.
123
124
private:
125
    QMutex m_mutex[FZ_LOCK_MAX];
126
    fz_locks_context m_locks_context;
127
    fz_context* m_context;
128
129
    static void lock(void* user, int lock);
130
    static void unlock(void* user, int lock);
131
132
};
1518 by Adam Reichold
Make proper use of application and anonymous namespaces and fix a few header guards.
133
134
} // qpdfview
135
136
#endif // FITZMODEL_H