~adamreichold/qpdfview/trunk

1898.1.5 by Adam Reichold
Move render parameters into separate header.
1
/*
2
2110 by Adam Reichold
Merge invert lightness functionality.
3
Copyright 2020 Johan Björklund
1898.1.5 by Adam Reichold
Move render parameters into separate header.
4
Copyright 2015 Adam Reichold
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
23
#ifndef RENDERPARAM_H
24
#define RENDERPARAM_H
25
1898.1.10 by Adam Reichold
Make the render parameters implicitly shared so that render tasks and their pages can share this which should reduce memory consumption for tiling.
26
#include <QSharedDataPointer>
27
1898.1.5 by Adam Reichold
Move render parameters into separate header.
28
#include "global.h"
29
30
namespace qpdfview
31
{
32
1898.1.6 by Adam Reichold
Reduce size of render parameter by using a single flags field instead of individual bools.
33
enum RenderFlag
34
{
35
    InvertColors = 1 << 0,
36
    ConvertToGrayscale = 1 << 1,
1898.2.1 by Adam Reichold
Add render flags to lighten and darken the background using the paper color.
37
    TrimMargins = 1 << 2,
1898.2.3 by Adam Reichold
Rename the compose-background setting to the more general composition-mode.
38
    DarkenWithPaperColor = 1 << 3,
2108.1.1 by Johan Björklund
Invert light
39
    LightenWithPaperColor = 1 << 4,
2108.1.2 by Johan Björklund
Name change to "Invert lightness" and other fixes
40
    InvertLightness = 1 << 5
1898.1.6 by Adam Reichold
Reduce size of render parameter by using a single flags field instead of individual bools.
41
};
42
43
Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
44
1898.1.10 by Adam Reichold
Make the render parameters implicitly shared so that render tasks and their pages can share this which should reduce memory consumption for tiling.
45
class RenderParam
46
{
47
public:
2111 by Adam Reichold
Add setting to ignore logical DPI as it is reported incorrectly in some multi monitor setups.
48
    RenderParam(qreal scaleFactor = 1.0, Rotation rotation = RotateBy0,
2117 by Adam Reichold
First stab at making the application compatible with Qt versions 4, 5 and 6.
49
                RenderFlags flags = RenderFlags()) : d(new SharedData)
1898.1.10 by Adam Reichold
Make the render parameters implicitly shared so that render tasks and their pages can share this which should reduce memory consumption for tiling.
50
    {
2111 by Adam Reichold
Add setting to ignore logical DPI as it is reported incorrectly in some multi monitor setups.
51
        d->resolutionX = 72;
52
        d->resolutionY = 72;
53
        d->devicePixelRatio = 1.0;
1898.1.10 by Adam Reichold
Make the render parameters implicitly shared so that render tasks and their pages can share this which should reduce memory consumption for tiling.
54
        d->scaleFactor = scaleFactor;
55
        d->rotation = rotation;
56
        d->flags = flags;
57
    }
58
59
    int resolutionX() const { return d->resolutionX; }
60
    int resolutionY() const { return d->resolutionY; }
61
    void setResolution(int resolutionX, int resolutionY)
62
    {
63
        d->resolutionX = resolutionX;
64
        d->resolutionY = resolutionY;
65
    }
66
67
    qreal devicePixelRatio() const { return d->devicePixelRatio; }
68
    void setDevicePixelRatio(qreal devicePixelRatio) { d->devicePixelRatio = devicePixelRatio; }
69
70
    qreal scaleFactor() const { return d->scaleFactor; }
71
    void setScaleFactor(qreal scaleFactor) { d->scaleFactor = scaleFactor; }
72
73
    Rotation rotation() const { return d->rotation; }
74
    void setRotation(Rotation rotation) { d->rotation = rotation; }
75
76
    RenderFlags flags() const { return d->flags; }
77
    void setFlags(RenderFlags flags) { d->flags = flags; }
78
    void setFlag(RenderFlag flag, bool enabled = true)
79
    {
80
        if(enabled)
1898.1.6 by Adam Reichold
Reduce size of render parameter by using a single flags field instead of individual bools.
81
        {
1898.1.10 by Adam Reichold
Make the render parameters implicitly shared so that render tasks and their pages can share this which should reduce memory consumption for tiling.
82
            d->flags |= flag;
1898.1.6 by Adam Reichold
Reduce size of render parameter by using a single flags field instead of individual bools.
83
        }
84
        else
85
        {
1898.1.10 by Adam Reichold
Make the render parameters implicitly shared so that render tasks and their pages can share this which should reduce memory consumption for tiling.
86
            d->flags &= ~flag;
1898.1.6 by Adam Reichold
Reduce size of render parameter by using a single flags field instead of individual bools.
87
        }
88
    }
1898.1.5 by Adam Reichold
Move render parameters into separate header.
89
1898.1.10 by Adam Reichold
Make the render parameters implicitly shared so that render tasks and their pages can share this which should reduce memory consumption for tiling.
90
    bool invertColors() const { return d->flags.testFlag(InvertColors); }
91
    void setInvertColors(bool invertColors) { setFlag(InvertColors, invertColors); }
92
2108.1.2 by Johan Björklund
Name change to "Invert lightness" and other fixes
93
    bool invertLightness() const { return d->flags.testFlag(InvertLightness); }
94
    void setInvertLightness(bool invertLightness) { setFlag(InvertLightness, invertLightness); }
2108.1.1 by Johan Björklund
Invert light
95
1898.1.10 by Adam Reichold
Make the render parameters implicitly shared so that render tasks and their pages can share this which should reduce memory consumption for tiling.
96
    bool convertToGrayscale() const { return d->flags.testFlag(ConvertToGrayscale); }
97
    void setConvertToGrayscale(bool convertToGrayscale) { setFlag(ConvertToGrayscale, convertToGrayscale); }
98
99
    bool trimMargins() const { return d->flags.testFlag(TrimMargins); }
100
    void setTrimMargins(bool trimMargins) { setFlag(TrimMargins, trimMargins); }
1898.1.5 by Adam Reichold
Move render parameters into separate header.
101
1898.2.3 by Adam Reichold
Rename the compose-background setting to the more general composition-mode.
102
    bool darkenWithPaperColor() const { return d->flags.testFlag(DarkenWithPaperColor); }
103
    void setDarkenWithPaperColor(bool darkenWithPaperColor) { setFlag(DarkenWithPaperColor, darkenWithPaperColor); }
1898.2.1 by Adam Reichold
Add render flags to lighten and darken the background using the paper color.
104
1898.2.3 by Adam Reichold
Rename the compose-background setting to the more general composition-mode.
105
    bool lightenWithPaperColor() const { return d->flags.testFlag(LightenWithPaperColor); }
106
    void setLightenWithPaperColor(bool lightenWithPaperColor) { setFlag(LightenWithPaperColor, lightenWithPaperColor); }
1898.2.1 by Adam Reichold
Add render flags to lighten and darken the background using the paper color.
107
1898.1.5 by Adam Reichold
Move render parameters into separate header.
108
    bool operator==(const RenderParam& other) const
109
    {
1898.1.18 by Adam Reichold
Improve the render parameter comparison operations and respect the partial dependence of the displayed size of the render parameters.
110
        if(d == other.d)
111
        {
112
            return true;
113
        }
114
        else
115
        {
116
            return d->resolutionX == other.d->resolutionX
117
                    && d->resolutionY == other.d->resolutionY
118
                    && qFuzzyCompare(d->devicePixelRatio, other.d->devicePixelRatio)
119
                    && qFuzzyCompare(d->scaleFactor, other.d->scaleFactor)
120
                    && d->rotation == other.d->rotation
121
                    && d->flags == other.d->flags;
122
        }
1898.1.5 by Adam Reichold
Move render parameters into separate header.
123
    }
124
125
    bool operator!=(const RenderParam& other) const { return !operator==(other); }
126
2112 by Adam Reichold
Use a default instance of RenderParam more consistently.
127
    static const RenderParam defaultInstance;
128
1898.1.10 by Adam Reichold
Make the render parameters implicitly shared so that render tasks and their pages can share this which should reduce memory consumption for tiling.
129
private:
1898.1.15 by Adam Reichold
Hide the render parameters shared data from access without hiding the memory layout for inline and make sure to evict the cache upon changing trim margins as the state cache entries contain null crop rectangles.
130
    struct SharedData : public QSharedData
131
    {
132
        int resolutionX;
133
        int resolutionY;
134
        qreal devicePixelRatio;
135
136
        qreal scaleFactor;
137
        Rotation rotation;
138
139
        RenderFlags flags;
140
141
    };
142
143
    QSharedDataPointer< SharedData > d;
1898.1.10 by Adam Reichold
Make the render parameters implicitly shared so that render tasks and their pages can share this which should reduce memory consumption for tiling.
144
1898.1.5 by Adam Reichold
Move render parameters into separate header.
145
};
146
1898.1.6 by Adam Reichold
Reduce size of render parameter by using a single flags field instead of individual bools.
147
inline QDataStream& operator<<(QDataStream& stream, const RenderParam& that)
148
{
1898.1.10 by Adam Reichold
Make the render parameters implicitly shared so that render tasks and their pages can share this which should reduce memory consumption for tiling.
149
    stream << that.resolutionX()
150
           << that.resolutionY()
151
           << that.devicePixelRatio()
152
           << that.scaleFactor()
153
           << that.rotation()
1898.1.15 by Adam Reichold
Hide the render parameters shared data from access without hiding the memory layout for inline and make sure to evict the cache upon changing trim margins as the state cache entries contain null crop rectangles.
154
           << that.flags();
1898.1.6 by Adam Reichold
Reduce size of render parameter by using a single flags field instead of individual bools.
155
156
   return stream;
157
}
158
1898.1.5 by Adam Reichold
Move render parameters into separate header.
159
} // qpdfview
160
161
#endif // RENDERPARAM_H
162