1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
/*
Copyright 2020 Johan Björklund
Copyright 2015 Adam Reichold
This file is part of qpdfview.
qpdfview is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
qpdfview is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with qpdfview. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RENDERPARAM_H
#define RENDERPARAM_H
#include <QSharedDataPointer>
#include "global.h"
namespace qpdfview
{
enum RenderFlag
{
InvertColors = 1 << 0,
ConvertToGrayscale = 1 << 1,
TrimMargins = 1 << 2,
DarkenWithPaperColor = 1 << 3,
LightenWithPaperColor = 1 << 4,
InvertLightness = 1 << 5
};
Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
class RenderParam
{
public:
RenderParam(qreal scaleFactor = 1.0, Rotation rotation = RotateBy0,
RenderFlags flags = RenderFlags()) : d(new SharedData)
{
d->resolutionX = 72;
d->resolutionY = 72;
d->devicePixelRatio = 1.0;
d->scaleFactor = scaleFactor;
d->rotation = rotation;
d->flags = flags;
}
int resolutionX() const { return d->resolutionX; }
int resolutionY() const { return d->resolutionY; }
void setResolution(int resolutionX, int resolutionY)
{
d->resolutionX = resolutionX;
d->resolutionY = resolutionY;
}
qreal devicePixelRatio() const { return d->devicePixelRatio; }
void setDevicePixelRatio(qreal devicePixelRatio) { d->devicePixelRatio = devicePixelRatio; }
qreal scaleFactor() const { return d->scaleFactor; }
void setScaleFactor(qreal scaleFactor) { d->scaleFactor = scaleFactor; }
Rotation rotation() const { return d->rotation; }
void setRotation(Rotation rotation) { d->rotation = rotation; }
RenderFlags flags() const { return d->flags; }
void setFlags(RenderFlags flags) { d->flags = flags; }
void setFlag(RenderFlag flag, bool enabled = true)
{
if(enabled)
{
d->flags |= flag;
}
else
{
d->flags &= ~flag;
}
}
bool invertColors() const { return d->flags.testFlag(InvertColors); }
void setInvertColors(bool invertColors) { setFlag(InvertColors, invertColors); }
bool invertLightness() const { return d->flags.testFlag(InvertLightness); }
void setInvertLightness(bool invertLightness) { setFlag(InvertLightness, invertLightness); }
bool convertToGrayscale() const { return d->flags.testFlag(ConvertToGrayscale); }
void setConvertToGrayscale(bool convertToGrayscale) { setFlag(ConvertToGrayscale, convertToGrayscale); }
bool trimMargins() const { return d->flags.testFlag(TrimMargins); }
void setTrimMargins(bool trimMargins) { setFlag(TrimMargins, trimMargins); }
bool darkenWithPaperColor() const { return d->flags.testFlag(DarkenWithPaperColor); }
void setDarkenWithPaperColor(bool darkenWithPaperColor) { setFlag(DarkenWithPaperColor, darkenWithPaperColor); }
bool lightenWithPaperColor() const { return d->flags.testFlag(LightenWithPaperColor); }
void setLightenWithPaperColor(bool lightenWithPaperColor) { setFlag(LightenWithPaperColor, lightenWithPaperColor); }
bool operator==(const RenderParam& other) const
{
if(d == other.d)
{
return true;
}
else
{
return d->resolutionX == other.d->resolutionX
&& d->resolutionY == other.d->resolutionY
&& qFuzzyCompare(d->devicePixelRatio, other.d->devicePixelRatio)
&& qFuzzyCompare(d->scaleFactor, other.d->scaleFactor)
&& d->rotation == other.d->rotation
&& d->flags == other.d->flags;
}
}
bool operator!=(const RenderParam& other) const { return !operator==(other); }
static const RenderParam defaultInstance;
private:
struct SharedData : public QSharedData
{
int resolutionX;
int resolutionY;
qreal devicePixelRatio;
qreal scaleFactor;
Rotation rotation;
RenderFlags flags;
};
QSharedDataPointer< SharedData > d;
};
inline QDataStream& operator<<(QDataStream& stream, const RenderParam& that)
{
stream << that.resolutionX()
<< that.resolutionY()
<< that.devicePixelRatio()
<< that.scaleFactor()
<< that.rotation()
<< that.flags();
return stream;
}
} // qpdfview
#endif // RENDERPARAM_H
|