diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-10-18 18:42:05 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2024-02-02 16:06:45 +0100 |
commit | 0092f06a648ba29c9643ae19a88ed2eb6ea1300f (patch) | |
tree | 2923ebdfc8023b8da36faf0e4c91d99808cde93e /src/printsupport/kernel/qprintengine_pdf.cpp | |
parent | efc579145ef33655a4aaad5a41124cb103bfbe7a (diff) |
Add CMYK support for pens/fills in the PDF engine
Insofar, painting with a CMYK color (pen/brush) was completely ignored
by QPdfWriter, although the PDF format can faithfully represent CMYK
colors.
This commit adds support for CMYK colors in the PDF engine. The support
is opt-in, in the name of backwards compatibility; an enumeration on
QPdfWriter controls the output.
QPrinter was using a hidden hook in QPdfEngine in order to do grayscale
printing; this hook can now be made public API through the same
enumeration.
This work has been kindly sponsored by the QGIS project
(https://qgis.org/).
[ChangeLog][QtGui][QPdfWriter] QPdfWriter can now use CMYK colors
directly, without converting them into RGB colors.
Change-Id: Ia27c19ec81a58ab68ddc8b9c89c4e57d7d637301
Reviewed-by: Lars Knoll <lars@knoll.priv.no>
Diffstat (limited to 'src/printsupport/kernel/qprintengine_pdf.cpp')
-rw-r--r-- | src/printsupport/kernel/qprintengine_pdf.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/printsupport/kernel/qprintengine_pdf.cpp b/src/printsupport/kernel/qprintengine_pdf.cpp index daf5010feb..1e2910464a 100644 --- a/src/printsupport/kernel/qprintengine_pdf.cpp +++ b/src/printsupport/kernel/qprintengine_pdf.cpp @@ -104,7 +104,14 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va d->collate = value.toBool(); break; case PPK_ColorMode: - d->grayscale = (QPrinter::ColorMode(value.toInt()) == QPrinter::GrayScale); + switch (QPrinter::ColorMode(value.toInt())) { + case QPrinter::GrayScale: + d->colorModel = QPdfEngine::ColorModel::Grayscale; + break; + case QPrinter::Color: + d->colorModel = QPdfEngine::ColorModel::RGB; + break; + } break; case PPK_Creator: d->creator = value.toString(); @@ -221,7 +228,7 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const ret = d->collate; break; case PPK_ColorMode: - ret = d->grayscale ? QPrinter::GrayScale : QPrinter::Color; + ret = d->printerColorMode(); break; case PPK_Creator: ret = d->creator; @@ -367,6 +374,22 @@ QPdfPrintEnginePrivate::~QPdfPrintEnginePrivate() { } +QPrinter::ColorMode QPdfPrintEnginePrivate::printerColorMode() const +{ + switch (colorModel) { + case QPdfEngine::ColorModel::RGB: + case QPdfEngine::ColorModel::CMYK: + case QPdfEngine::ColorModel::Auto: + return QPrinter::Color; + case QPdfEngine::ColorModel::Grayscale: + return QPrinter::GrayScale; + } + + Q_UNREACHABLE(); + return QPrinter::Color; +} + + QT_END_NAMESPACE #endif // QT_NO_PRINTER |