Skip to content

Commit 9aa955d

Browse files
committed
Optimize painting the background
This eliminates some extra work, increasing performance and decreasing memory usage.
1 parent 09107b5 commit 9aa955d

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

qpageview/pdf.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,6 @@ def draw(self, page, painter, key, tile, paperColor=None):
284284
with locking.lock(doc):
285285
image = doc.render(num, renderSize, renderOptions)
286286

287-
if paperColor:
288-
# QtPdf leaves the page background transparent, so we need to
289-
# paint it ourselves
290-
content = image.copy()
291-
bgPainter = QPainter(image)
292-
bgPainter.fillRect(image.rect(), paperColor)
293-
bgPainter.drawImage(0, 0, content)
294-
bgPainter.end()
295-
296287
if tile != (0, 0, key.width, key.height):
297288
# Crop the image to the tile boundaries
298289
image = image.copy(matrix.mapRect(QRect(*map(int, tile))))
@@ -305,6 +296,8 @@ def draw(self, page, painter, key, tile, paperColor=None):
305296

306297
# Erase the target area and draw the image
307298
painter.eraseRect(target)
299+
if paperColor:
300+
painter.fillRect(target, paperColor)
308301
painter.drawImage(target, image, QRectF(image.rect()))
309302

310303

0 commit comments

Comments
 (0)