[e0e368b] | 1 | /* |
---|
| 2 | |
---|
| 3 | Copyright 2015 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 RENDERPARAM_H |
---|
| 23 | #define RENDERPARAM_H |
---|
| 24 | |
---|
| 25 | #include <QSharedDataPointer> |
---|
| 26 | |
---|
| 27 | #include "global.h" |
---|
| 28 | |
---|
| 29 | namespace qpdfview |
---|
| 30 | { |
---|
| 31 | |
---|
| 32 | enum RenderFlag |
---|
| 33 | { |
---|
| 34 | InvertColors = 1 << 0, |
---|
| 35 | ConvertToGrayscale = 1 << 1, |
---|
| 36 | TrimMargins = 1 << 2, |
---|
| 37 | DarkenWithPaperColor = 1 << 3, |
---|
| 38 | LightenWithPaperColor = 1 << 4 |
---|
| 39 | }; |
---|
| 40 | |
---|
| 41 | Q_DECLARE_FLAGS(RenderFlags, RenderFlag) |
---|
| 42 | |
---|
| 43 | class RenderParam |
---|
| 44 | { |
---|
| 45 | public: |
---|
| 46 | RenderParam(int resolutionX = 72, int resolutionY = 72, qreal devicePixelRatio = 1.0, |
---|
| 47 | qreal scaleFactor = 1.0, Rotation rotation = RotateBy0, |
---|
| 48 | RenderFlags flags = 0) : d(new SharedData) |
---|
| 49 | { |
---|
| 50 | d->resolutionX = resolutionX; |
---|
| 51 | d->resolutionY = resolutionY; |
---|
| 52 | d->devicePixelRatio = devicePixelRatio; |
---|
| 53 | d->scaleFactor = scaleFactor; |
---|
| 54 | d->rotation = rotation; |
---|
| 55 | d->flags = flags; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | int resolutionX() const { return d->resolutionX; } |
---|
| 59 | int resolutionY() const { return d->resolutionY; } |
---|
| 60 | void setResolution(int resolutionX, int resolutionY) |
---|
| 61 | { |
---|
| 62 | d->resolutionX = resolutionX; |
---|
| 63 | d->resolutionY = resolutionY; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | qreal devicePixelRatio() const { return d->devicePixelRatio; } |
---|
| 67 | void setDevicePixelRatio(qreal devicePixelRatio) { d->devicePixelRatio = devicePixelRatio; } |
---|
| 68 | |
---|
| 69 | qreal scaleFactor() const { return d->scaleFactor; } |
---|
| 70 | void setScaleFactor(qreal scaleFactor) { d->scaleFactor = scaleFactor; } |
---|
| 71 | |
---|
| 72 | Rotation rotation() const { return d->rotation; } |
---|
| 73 | void setRotation(Rotation rotation) { d->rotation = rotation; } |
---|
| 74 | |
---|
| 75 | RenderFlags flags() const { return d->flags; } |
---|
| 76 | void setFlags(RenderFlags flags) { d->flags = flags; } |
---|
| 77 | void setFlag(RenderFlag flag, bool enabled = true) |
---|
| 78 | { |
---|
| 79 | if(enabled) |
---|
| 80 | { |
---|
| 81 | d->flags |= flag; |
---|
| 82 | } |
---|
| 83 | else |
---|
| 84 | { |
---|
| 85 | d->flags &= ~flag; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | bool invertColors() const { return d->flags.testFlag(InvertColors); } |
---|
| 90 | void setInvertColors(bool invertColors) { setFlag(InvertColors, invertColors); } |
---|
| 91 | |
---|
| 92 | bool convertToGrayscale() const { return d->flags.testFlag(ConvertToGrayscale); } |
---|
| 93 | void setConvertToGrayscale(bool convertToGrayscale) { setFlag(ConvertToGrayscale, convertToGrayscale); } |
---|
| 94 | |
---|
| 95 | bool trimMargins() const { return d->flags.testFlag(TrimMargins); } |
---|
| 96 | void setTrimMargins(bool trimMargins) { setFlag(TrimMargins, trimMargins); } |
---|
| 97 | |
---|
| 98 | bool darkenWithPaperColor() const { return d->flags.testFlag(DarkenWithPaperColor); } |
---|
| 99 | void setDarkenWithPaperColor(bool darkenWithPaperColor) { setFlag(DarkenWithPaperColor, darkenWithPaperColor); } |
---|
| 100 | |
---|
| 101 | bool lightenWithPaperColor() const { return d->flags.testFlag(LightenWithPaperColor); } |
---|
| 102 | void setLightenWithPaperColor(bool lightenWithPaperColor) { setFlag(LightenWithPaperColor, lightenWithPaperColor); } |
---|
| 103 | |
---|
| 104 | bool operator==(const RenderParam& other) const |
---|
| 105 | { |
---|
| 106 | if(d == other.d) |
---|
| 107 | { |
---|
| 108 | return true; |
---|
| 109 | } |
---|
| 110 | else |
---|
| 111 | { |
---|
| 112 | return d->resolutionX == other.d->resolutionX |
---|
| 113 | && d->resolutionY == other.d->resolutionY |
---|
| 114 | && qFuzzyCompare(d->devicePixelRatio, other.d->devicePixelRatio) |
---|
| 115 | && qFuzzyCompare(d->scaleFactor, other.d->scaleFactor) |
---|
| 116 | && d->rotation == other.d->rotation |
---|
| 117 | && d->flags == other.d->flags; |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | bool operator!=(const RenderParam& other) const { return !operator==(other); } |
---|
| 122 | |
---|
| 123 | private: |
---|
| 124 | struct SharedData : public QSharedData |
---|
| 125 | { |
---|
| 126 | int resolutionX; |
---|
| 127 | int resolutionY; |
---|
| 128 | qreal devicePixelRatio; |
---|
| 129 | |
---|
| 130 | qreal scaleFactor; |
---|
| 131 | Rotation rotation; |
---|
| 132 | |
---|
| 133 | RenderFlags flags; |
---|
| 134 | |
---|
| 135 | }; |
---|
| 136 | |
---|
| 137 | QSharedDataPointer< SharedData > d; |
---|
| 138 | |
---|
| 139 | }; |
---|
| 140 | |
---|
| 141 | inline QDataStream& operator<<(QDataStream& stream, const RenderParam& that) |
---|
| 142 | { |
---|
| 143 | stream << that.resolutionX() |
---|
| 144 | << that.resolutionY() |
---|
| 145 | << that.devicePixelRatio() |
---|
| 146 | << that.scaleFactor() |
---|
| 147 | << that.rotation() |
---|
| 148 | << that.flags(); |
---|
| 149 | |
---|
| 150 | return stream; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | } // qpdfview |
---|
| 154 | |
---|
| 155 | #endif // RENDERPARAM_H |
---|
| 156 | |
---|