| 1 | // Copyright (C) 2024 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qpdfoutputintent.h" |
| 5 | |
| 6 | #ifndef QT_NO_PDF |
| 7 | |
| 8 | #include <QtCore/qfile.h> |
| 9 | #include <QtCore/qshareddata.h> |
| 10 | #include <QtCore/qstring.h> |
| 11 | #include <QtCore/qurl.h> |
| 12 | |
| 13 | #include <QtGui/qcolorspace.h> |
| 14 | |
| 15 | QT_BEGIN_NAMESPACE |
| 16 | |
| 17 | class QPdfOutputIntentPrivate : public QSharedData |
| 18 | { |
| 19 | public: |
| 20 | QPdfOutputIntentPrivate() |
| 21 | { |
| 22 | QFile colorProfileFile(QStringLiteral(":/qpdf/sRGB2014.icc" )); |
| 23 | bool ok = colorProfileFile.open(flags: QIODevice::ReadOnly); |
| 24 | Q_ASSERT(ok); |
| 25 | outputProfile = QColorSpace::fromIccProfile(iccProfile: colorProfileFile.readAll()); |
| 26 | } |
| 27 | |
| 28 | QString outputConditionIdentifier = QStringLiteral("sRGB_IEC61966-2-1_black_scaled" ); |
| 29 | QString outputCondition = QStringLiteral("sRGB IEC61966 v2.1 with black scaling" ); |
| 30 | QUrl registryName = QStringLiteral("http://www.color.org" ); |
| 31 | QColorSpace outputProfile; |
| 32 | }; |
| 33 | |
| 34 | /*! |
| 35 | \class QPdfOutputIntent |
| 36 | \inmodule QtGui |
| 37 | \ingroup painting |
| 38 | \since 6.8 |
| 39 | |
| 40 | The QPdfOutputIntent class contains metadata that characterize |
| 41 | the printing condition for which painting data has been prepared |
| 42 | when generating a PDF file. |
| 43 | |
| 44 | \sa QPdfWriter |
| 45 | */ |
| 46 | |
| 47 | /*! |
| 48 | Constructs a new PDF output intent. |
| 49 | */ |
| 50 | QPdfOutputIntent::QPdfOutputIntent() |
| 51 | : d(new QPdfOutputIntentPrivate) |
| 52 | {} |
| 53 | |
| 54 | /*! |
| 55 | Constructs a copy of the output intent \a other. |
| 56 | */ |
| 57 | QPdfOutputIntent::QPdfOutputIntent(const QPdfOutputIntent &other) = default; |
| 58 | |
| 59 | /*! |
| 60 | \fn QPdfOutputIntent::QPdfOutputIntent(QPdfOutputIntent &&other) noexcept |
| 61 | |
| 62 | Constructs a QPdfOutputIntent object by moving from \a other. |
| 63 | */ |
| 64 | |
| 65 | /*! |
| 66 | Assigns the output intent \a other over this intent. |
| 67 | */ |
| 68 | QPdfOutputIntent &QPdfOutputIntent::operator=(const QPdfOutputIntent &other) = default; |
| 69 | |
| 70 | /*! |
| 71 | \fn QPdfOutputIntent &QPdfOutputIntent::operator=(QPdfOutputIntent &&other) noexcept |
| 72 | |
| 73 | Move-assigns the output intent \a other over this intent. |
| 74 | */ |
| 75 | |
| 76 | /*! |
| 77 | Destroys this output intent. |
| 78 | */ |
| 79 | QPdfOutputIntent::~QPdfOutputIntent() = default; |
| 80 | |
| 81 | /*! |
| 82 | \fn void QPdfOutputIntent::swap(QPdfOutputIntent &other) noexcept |
| 83 | \memberswap{output intent} |
| 84 | */ |
| 85 | |
| 86 | /*! |
| 87 | Returns the identifier of the output condition. |
| 88 | |
| 89 | If a registry name is provided, then this identifier should should |
| 90 | match the reference name of an entry in that registry. |
| 91 | |
| 92 | The default identifier is \c{sRGB_IEC61966-2-1_black_scaled}. |
| 93 | |
| 94 | \sa setOutputConditionIdentifier() |
| 95 | */ |
| 96 | QString QPdfOutputIntent::outputConditionIdentifier() const |
| 97 | { |
| 98 | return d->outputConditionIdentifier; |
| 99 | } |
| 100 | |
| 101 | /*! |
| 102 | Sets the identifier of the output condition to \a identifier. |
| 103 | |
| 104 | If a registry name is provided, then this identifier should should |
| 105 | match the reference name of an entry in that registry. |
| 106 | |
| 107 | \sa setOutputCondition(), setRegistryName() |
| 108 | */ |
| 109 | void QPdfOutputIntent::setOutputConditionIdentifier(const QString &identifier) |
| 110 | { |
| 111 | d.detach(); |
| 112 | d->outputConditionIdentifier = identifier; |
| 113 | } |
| 114 | |
| 115 | /*! |
| 116 | Returns the human-readable output condition. |
| 117 | |
| 118 | This is a string that concisely identifies the characterized |
| 119 | printing condition in a form that will be meaningful to a |
| 120 | human operator. |
| 121 | |
| 122 | The default output condition is |
| 123 | \c{sRGB IEC61966 v2.1 with black scaling}. |
| 124 | |
| 125 | \sa setOutputCondition() |
| 126 | */ |
| 127 | QString QPdfOutputIntent::outputCondition() const |
| 128 | { |
| 129 | return d->outputCondition; |
| 130 | } |
| 131 | |
| 132 | /*! |
| 133 | Sets the human-readable output condition to \a condition. |
| 134 | |
| 135 | \sa setOutputConditionIdentifier(), setRegistryName() |
| 136 | */ |
| 137 | void QPdfOutputIntent::setOutputCondition(const QString &condition) |
| 138 | { |
| 139 | d.detach(); |
| 140 | d->outputCondition = condition; |
| 141 | } |
| 142 | |
| 143 | /*! |
| 144 | Returns the URL of a characterization registry for the intended |
| 145 | printing condition. |
| 146 | |
| 147 | The default registry is \c{http://www.color.org}. |
| 148 | |
| 149 | \sa setOutputConditionIdentifier() |
| 150 | */ |
| 151 | QUrl QPdfOutputIntent::registryName() const |
| 152 | { |
| 153 | return d->registryName; |
| 154 | } |
| 155 | |
| 156 | /*! |
| 157 | Sets the URL of the characterization registry to \a name. |
| 158 | |
| 159 | \sa setOutputConditionIdentifier() |
| 160 | */ |
| 161 | void QPdfOutputIntent::setRegistryName(const QUrl &name) |
| 162 | { |
| 163 | d.detach(); |
| 164 | d->registryName = name; |
| 165 | } |
| 166 | |
| 167 | /*! |
| 168 | Returns the output device profile. |
| 169 | |
| 170 | The default profile is the sRGB v2 profile available |
| 171 | from the |
| 172 | \l{https://www.color.org/srgbprofiles.xalter#v2}{International |
| 173 | Color Consortium}. |
| 174 | */ |
| 175 | QColorSpace QPdfOutputIntent::outputProfile() const |
| 176 | { |
| 177 | return d->outputProfile; |
| 178 | } |
| 179 | |
| 180 | /*! |
| 181 | Sets the output device profile to \a profile. |
| 182 | |
| 183 | \note PDF/X-4 requires all the color specifications in the |
| 184 | document to match the same colorspace of \a profile. It is |
| 185 | the application's responsibility to ensure this is the case. |
| 186 | |
| 187 | \sa QColorSpace::fromIccProfile, QPdfWriter::setColorModel |
| 188 | */ |
| 189 | void QPdfOutputIntent::setOutputProfile(const QColorSpace &profile) |
| 190 | { |
| 191 | d.detach(); |
| 192 | d->outputProfile = profile; |
| 193 | } |
| 194 | |
| 195 | QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QPdfOutputIntentPrivate) |
| 196 | |
| 197 | QT_END_NAMESPACE |
| 198 | |
| 199 | #endif // QT_NO_PDF |
| 200 | |