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,64 +17,65 @@ QBrush, QColor, QPoint, QPixmap, QPainterPath, QRectF, Qt, QPointF
|
|||||||
|
|
||||||
from calibre.ebooks.pdf.render.engine import PdfDevice
|
from calibre.ebooks.pdf.render.engine import PdfDevice
|
||||||
|
|
||||||
def full(dev):
|
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))
|
||||||
|
pp = QPainterPath()
|
||||||
|
pp.addRect(0, 0, xmax, ymax)
|
||||||
|
p.drawPath(pp)
|
||||||
|
p.save()
|
||||||
|
for i in xrange(3):
|
||||||
|
col = [0, 0, 0, 200]
|
||||||
|
col[i] = 255
|
||||||
|
p.setOpacity(0.3)
|
||||||
|
p.fillRect(0, 0, xmax/10, xmax/10, QBrush(QColor(*col)))
|
||||||
|
p.setOpacity(1)
|
||||||
|
p.drawRect(0, 0, xmax/10, xmax/10)
|
||||||
|
p.translate(xmax/10, xmax/10)
|
||||||
|
p.scale(1, 1.5)
|
||||||
|
p.restore()
|
||||||
|
|
||||||
|
# p.scale(2, 2)
|
||||||
|
# p.rotate(45)
|
||||||
|
p.drawPixmap(0, 0, xmax/4, xmax/4, QPixmap(I('library.png')))
|
||||||
|
p.drawRect(0, 0, xmax/4, xmax/4)
|
||||||
|
|
||||||
|
f = p.font()
|
||||||
|
f.setPointSize(20)
|
||||||
|
# f.setLetterSpacing(f.PercentageSpacing, 200)
|
||||||
|
f.setUnderline(True)
|
||||||
|
# f.setOverline(True)
|
||||||
|
# f.setStrikeOut(True)
|
||||||
|
f.setFamily('Calibri')
|
||||||
|
p.setFont(f)
|
||||||
|
# p.setPen(QColor(0, 0, 255))
|
||||||
|
# p.scale(2, 2)
|
||||||
|
# p.rotate(45)
|
||||||
|
p.drawText(QPoint(xmax/3.9, 30), 'Some—text not By’s ū --- Д AV ff ff')
|
||||||
|
|
||||||
|
b = QBrush(Qt.HorPattern)
|
||||||
|
b.setColor(QColor(Qt.blue))
|
||||||
|
pix = QPixmap(I('console.png'))
|
||||||
|
w = xmax/4
|
||||||
|
p.fillRect(0, ymax/3, w, w, b)
|
||||||
|
p.fillRect(xmax/3, ymax/3, w, w, QBrush(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('#fff'))
|
||||||
|
p.fillRect(x, y, w, w, QBrush(g))
|
||||||
|
|
||||||
|
def run(dev, func):
|
||||||
p = QPainter(dev)
|
p = QPainter(dev)
|
||||||
if isinstance(dev, PdfDevice):
|
if isinstance(dev, PdfDevice):
|
||||||
dev.init_page()
|
dev.init_page()
|
||||||
|
|
||||||
xmax, ymax = p.viewport().width(), p.viewport().height()
|
xmax, ymax = p.viewport().width(), p.viewport().height()
|
||||||
b = p.brush()
|
|
||||||
try:
|
try:
|
||||||
p.drawRect(0, 0, xmax, ymax)
|
func(p, xmax, ymax)
|
||||||
p.drawPolyline(QPoint(0, 0), QPoint(xmax, 0), QPoint(xmax, ymax),
|
|
||||||
QPoint(0, ymax), QPoint(0, 0))
|
|
||||||
pp = QPainterPath()
|
|
||||||
pp.addRect(0, 0, xmax, ymax)
|
|
||||||
p.drawPath(pp)
|
|
||||||
p.save()
|
|
||||||
for i in xrange(3):
|
|
||||||
col = [0, 0, 0, 200]
|
|
||||||
col[i] = 255
|
|
||||||
p.setOpacity(0.3)
|
|
||||||
p.fillRect(0, 0, xmax/10, xmax/10, QBrush(QColor(*col)))
|
|
||||||
p.setOpacity(1)
|
|
||||||
p.drawRect(0, 0, xmax/10, xmax/10)
|
|
||||||
p.translate(xmax/10, xmax/10)
|
|
||||||
p.scale(1, 1.5)
|
|
||||||
p.restore()
|
|
||||||
|
|
||||||
# p.scale(2, 2)
|
|
||||||
# p.rotate(45)
|
|
||||||
p.drawPixmap(0, 0, xmax/4, xmax/4, QPixmap(I('library.png')))
|
|
||||||
p.drawRect(0, 0, xmax/4, xmax/4)
|
|
||||||
|
|
||||||
f = p.font()
|
|
||||||
f.setPointSize(20)
|
|
||||||
# f.setLetterSpacing(f.PercentageSpacing, 200)
|
|
||||||
f.setUnderline(True)
|
|
||||||
# f.setOverline(True)
|
|
||||||
# f.setStrikeOut(True)
|
|
||||||
f.setFamily('Calibri')
|
|
||||||
p.setFont(f)
|
|
||||||
# p.setPen(QColor(0, 0, 255))
|
|
||||||
# p.scale(2, 2)
|
|
||||||
# p.rotate(45)
|
|
||||||
p.drawText(QPoint(xmax/3.9, 30), 'Some—text not By’s ū --- Д AV ff ff')
|
|
||||||
|
|
||||||
b = QBrush(Qt.HorPattern)
|
|
||||||
b.setColor(QColor(Qt.blue))
|
|
||||||
pix = QPixmap(I('console.png'))
|
|
||||||
w = xmax/4
|
|
||||||
p.fillRect(0, ymax/3, w, w, b)
|
|
||||||
p.fillRect(xmax/3, ymax/3, w, w, QBrush(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:
|
finally:
|
||||||
p.end()
|
p.end()
|
||||||
if isinstance(dev, PdfDevice):
|
if isinstance(dev, PdfDevice):
|
||||||
@ -94,8 +95,8 @@ def main():
|
|||||||
img.setDotsPerMeterX(100*39.37)
|
img.setDotsPerMeterX(100*39.37)
|
||||||
img.setDotsPerMeterY(100*39.37)
|
img.setDotsPerMeterY(100*39.37)
|
||||||
img.fill(Qt.white)
|
img.fill(Qt.white)
|
||||||
func(dev)
|
run(dev, func)
|
||||||
func(img)
|
run(img, func)
|
||||||
path = os.path.join(tdir, 'painter.png')
|
path = os.path.join(tdir, 'painter.png')
|
||||||
img.save(path)
|
img.save(path)
|
||||||
print ('PDF written to:', pdf)
|
print ('PDF written to:', pdf)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user