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>
This commit is contained in:
Eirik Aavitsland 2021-09-23 16:40:27 +02:00
parent 2cb42cd849
commit 6d41b64d45

View File

@ -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