mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
88a13dc8ee
commit
c84fa4bf80
@ -17,14 +17,7 @@ QBrush, QColor, QPoint, QPixmap, QPainterPath, QRectF, Qt, QPointF
|
||||
|
||||
from calibre.ebooks.pdf.render.engine import PdfDevice
|
||||
|
||||
def full(dev):
|
||||
p = QPainter(dev)
|
||||
if isinstance(dev, PdfDevice):
|
||||
dev.init_page()
|
||||
|
||||
xmax, ymax = p.viewport().width(), p.viewport().height()
|
||||
b = p.brush()
|
||||
try:
|
||||
def full(p, xmax, ymax):
|
||||
p.drawRect(0, 0, xmax, ymax)
|
||||
p.drawPolyline(QPoint(0, 0), QPoint(xmax, 0), QPoint(xmax, ymax),
|
||||
QPoint(0, ymax), QPoint(0, 0))
|
||||
@ -73,8 +66,16 @@ def full(dev):
|
||||
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'))
|
||||
g.setColorAt(1, QColor('#fff'))
|
||||
p.fillRect(x, y, w, w, QBrush(g))
|
||||
|
||||
def run(dev, func):
|
||||
p = QPainter(dev)
|
||||
if isinstance(dev, PdfDevice):
|
||||
dev.init_page()
|
||||
xmax, ymax = p.viewport().width(), p.viewport().height()
|
||||
try:
|
||||
func(p, xmax, ymax)
|
||||
finally:
|
||||
p.end()
|
||||
if isinstance(dev, PdfDevice):
|
||||
@ -94,8 +95,8 @@ def main():
|
||||
img.setDotsPerMeterX(100*39.37)
|
||||
img.setDotsPerMeterY(100*39.37)
|
||||
img.fill(Qt.white)
|
||||
func(dev)
|
||||
func(img)
|
||||
run(dev, func)
|
||||
run(img, func)
|
||||
path = os.path.join(tdir, 'painter.png')
|
||||
img.save(path)
|
||||
print ('PDF written to:', pdf)
|
||||
|
Loading…
x
Reference in New Issue
Block a user