From 6d41b64d45cda12370653300fdc2d2685c450014 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Thu, 23 Sep 2021 16:40:27 +0200 Subject: [PATCH] Avoid generating large pdf files when using dashed cosmetic pens MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Albert Astals Cid Reviewed-by: André de la Rocha --- src/gui/painting/qpdf.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 548c3d00494..d3d7483cd0d 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