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 | |
84 | Swaps the output intent \a other with this output intent. This |
85 | operation is very fast and never fails. |
86 | */ |
87 | |
88 | /*! |
89 | Returns the identifier of the output condition. |
90 | |
91 | If a registry name is provided, then this identifier should should |
92 | match the reference name of an entry in that registry. |
93 | |
94 | The default identifier is \c{sRGB_IEC61966-2-1_black_scaled}. |
95 | |
96 | \sa setOutputConditionIdentifier() |
97 | */ |
98 | QString QPdfOutputIntent::outputConditionIdentifier() const |
99 | { |
100 | return d->outputConditionIdentifier; |
101 | } |
102 | |
103 | /*! |
104 | Sets the identifier of the output condition to \a identifier. |
105 | |
106 | If a registry name is provided, then this identifier should should |
107 | match the reference name of an entry in that registry. |
108 | |
109 | \sa setOutputCondition(), setRegistryName() |
110 | */ |
111 | void QPdfOutputIntent::setOutputConditionIdentifier(const QString &identifier) |
112 | { |
113 | d.detach(); |
114 | d->outputConditionIdentifier = identifier; |
115 | } |
116 | |
117 | /*! |
118 | Returns the human-readable output condition. |
119 | |
120 | This is a string that concisely identifies the characterized |
121 | printing condition in a form that will be meaningful to a |
122 | human operator. |
123 | |
124 | The default output condition is |
125 | \c{sRGB IEC61966 v2.1 with black scaling}. |
126 | |
127 | \sa setOutputCondition() |
128 | */ |
129 | QString QPdfOutputIntent::outputCondition() const |
130 | { |
131 | return d->outputCondition; |
132 | } |
133 | |
134 | /*! |
135 | Sets the human-readable output condition to \a condition. |
136 | |
137 | \sa setOutputConditionIdentifier(), setRegistryName() |
138 | */ |
139 | void QPdfOutputIntent::setOutputCondition(const QString &condition) |
140 | { |
141 | d.detach(); |
142 | d->outputCondition = condition; |
143 | } |
144 | |
145 | /*! |
146 | Returns the URL of a characterization registry for the intended |
147 | printing condition. |
148 | |
149 | The default registry is \c{http://www.color.org}. |
150 | |
151 | \sa setOutputConditionIdentifier() |
152 | */ |
153 | QUrl QPdfOutputIntent::registryName() const |
154 | { |
155 | return d->registryName; |
156 | } |
157 | |
158 | /*! |
159 | Sets the URL of the characterization registry to \a name. |
160 | |
161 | \sa setOutputConditionIdentifier() |
162 | */ |
163 | void QPdfOutputIntent::setRegistryName(const QUrl &name) |
164 | { |
165 | d.detach(); |
166 | d->registryName = name; |
167 | } |
168 | |
169 | /*! |
170 | Returns the output device profile. |
171 | |
172 | The default profile is the sRGB v2 profile available |
173 | from the |
174 | \l{https://www.color.org/srgbprofiles.xalter#v2}{International |
175 | Color Consortium}. |
176 | */ |
177 | QColorSpace QPdfOutputIntent::outputProfile() const |
178 | { |
179 | return d->outputProfile; |
180 | } |
181 | |
182 | /*! |
183 | Sets the output device profile to \a profile. |
184 | |
185 | \note PDF/X-4 requires all the color specifications in the |
186 | document to match the same colorspace of \a profile. It is |
187 | the application's responsibility to ensure this is the case. |
188 | |
189 | \sa QColorSpace::fromIccProfile, QPdfWriter::setColorModel |
190 | */ |
191 | void QPdfOutputIntent::setOutputProfile(const QColorSpace &profile) |
192 | { |
193 | d.detach(); |
194 | d->outputProfile = profile; |
195 | } |
196 | |
197 | QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QPdfOutputIntentPrivate) |
198 | |
199 | QT_END_NAMESPACE |
200 | |
201 | #endif // QT_NO_PDF |
202 | |