diff options
author | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2021-09-23 16:40:27 +0200 |
---|---|---|
committer | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2021-09-29 22:07:43 +0200 |
commit | 6d41b64d45cda12370653300fdc2d2685c450014 (patch) | |
tree | 7e7a1da28967554af944136a629359c368867cba /src/gui/painting | |
parent | 2cb42cd849b60e72e2de44ed469c2b743b154b06 (diff) |
Avoid generating large pdf files when using dashed cosmetic pens
There was a bug in the pdf writer for cosmetic pens when they were
drawn using native pdf strokes (QTBUG-68537). The workaround that was
done for that bug was to disable native atroking for such pens, so
they would always be emulated. The drawback of that was that painting
with dashed cosmetic pens would then produce unexpectedly large pdf
files, since it would contain individual strokes for every dash.
This change fixes the original bug and removes the workaround,
re-enabling native stroking for cosmetic lines.
Pick-to: 6.2 5.15
Fixes: QTBUG-86094
Change-Id: I58d06ad2db81206025ca2de394f072e822c03d47
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Albert Astals Cid <albert.astals.cid@kdab.com>
Reviewed-by: André de la Rocha <andre.rocha@qt.io>
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qpdf.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 548c3d0049..d3d7483cd0 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -856,14 +856,14 @@ void QPdfEngine::drawRects (const QRectF *rects, int rectCount) if (!d->hasPen && !d->hasBrush) return; - if (d->simplePen || !d->hasPen) { - // draw strokes natively in this case for better output - if (!d->simplePen && !d->stroker.matrix.isIdentity()) + if ((d->simplePen && !d->needsTransform) || !d->hasPen) { + // draw natively in this case for better output + if (!d->hasPen && d->needsTransform) // i.e. this is just a fillrect *d->currentPage << "q\n" << QPdf::generateMatrix(d->stroker.matrix); for (int i = 0; i < rectCount; ++i) *d->currentPage << rects[i].x() << rects[i].y() << rects[i].width() << rects[i].height() << "re\n"; *d->currentPage << (d->hasPen ? (d->hasBrush ? "B\n" : "S\n") : "f\n"); - if (!d->simplePen && !d->stroker.matrix.isIdentity()) + if (!d->hasPen && d->needsTransform) *d->currentPage << "Q\n"; } else { QPainterPath p; @@ -1136,12 +1136,12 @@ void QPdfEngine::updateState(const QPaintEngineState &state) d->pen = state.pen(); } d->hasPen = d->pen.style() != Qt::NoPen; + bool oldCosmetic = d->stroker.cosmeticPen; d->stroker.setPen(d->pen, state.renderHints()); QBrush penBrush = d->pen.brush(); - bool cosmeticPen = d->pen.isCosmetic(); bool oldSimple = d->simplePen; - d->simplePen = (d->hasPen && !cosmeticPen && (penBrush.style() == Qt::SolidPattern) && penBrush.isOpaque() && d->opacity == 1.0); - if (oldSimple != d->simplePen) + d->simplePen = (d->hasPen && (penBrush.style() == Qt::SolidPattern) && penBrush.isOpaque() && d->opacity == 1.0); + if (oldSimple != d->simplePen || oldCosmetic != d->stroker.cosmeticPen) flags |= DirtyTransform; } else if (flags & DirtyHints) { d->stroker.setPen(d->pen, state.renderHints()); @@ -1227,7 +1227,7 @@ void QPdfEngine::setupGraphicsState(QPaintEngine::DirtyFlags flags) *d->currentPage << "q\n"; d->needsTransform = false; if (!d->stroker.matrix.isIdentity()) { - if (d->simplePen) + if (d->simplePen && !d->stroker.cosmeticPen) *d->currentPage << QPdf::generateMatrix(d->stroker.matrix); else d->needsTransform = true; // I.e. page-wide xf not set, local xf needed |