Fix drawTiledPixmap() to use the correct origin

This commit is contained in:
Kovid Goyal 2012-12-31 14:44:19 +05:30
parent ed89e9b465
commit 88a13dc8ee
2 changed files with 13 additions and 5 deletions

View File

@ -153,12 +153,12 @@ class PdfEngine(QPaintEngine):
def drawTiledPixmap(self, rect, pixmap, point):
self.apply_graphics_state()
brush = QBrush(pixmap)
bl = rect.topLeft()
color, opacity, pattern, do_fill = self.graphics.convert_brush(
brush, -point, 1.0, self.pdf, self.pdf_system,
brush, bl-point, 1.0, self.pdf, self.pdf_system,
self.painter().transform())
self.pdf.save_stack()
self.pdf.apply_fill(color, pattern)
bl = rect.topLeft()
self.pdf.draw_rect(bl.x(), bl.y(), rect.width(), rect.height(),
stroke=False, fill=True)
self.pdf.restore_stack()

View File

@ -11,8 +11,9 @@ import os
from tempfile import gettempdir
from PyQt4.Qt import (QBrush, QColor, QPoint, QPixmap, QPainterPath, QRectF,
QApplication, QPainter, Qt, QImage)
QBrush, QColor, QPoint, QPixmap, QPainterPath, QRectF, Qt
QApplication, QPainter, Qt, QImage, QLinearGradient,
QPointF)
QBrush, QColor, QPoint, QPixmap, QPainterPath, QRectF, Qt, QPointF
from calibre.ebooks.pdf.render.engine import PdfDevice
@ -66,7 +67,14 @@ def full(dev):
w = xmax/4
p.fillRect(0, ymax/3, w, w, b)
p.fillRect(xmax/3, ymax/3, w, w, QBrush(pix))
p.drawTiledPixmap(QRectF(2*xmax/3, ymax/3, w, w), pix)
x, y = 2*xmax/3, ymax/3
p.drawTiledPixmap(QRectF(x, y, w, w), pix, QPointF(10, 10))
x, y = 1, ymax/1.9
g = QLinearGradient(QPointF(x, y), QPointF(x+w, y+w))
g.setColorAt(0, QColor('#00f'))
g.setColorAt(1, QColor('#006'))
p.fillRect(x, y, w, w, QBrush(g))
finally:
p.end()
if isinstance(dev, PdfDevice):