mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix generate_cover() on windows using non-antialiased text at small cover sizes
This commit is contained in:
parent
d67b951c59
commit
3bb158e3ec
@ -186,28 +186,34 @@ class Block(object):
|
|||||||
if hasattr(l, 'draw'):
|
if hasattr(l, 'draw'):
|
||||||
# Etch effect for the text
|
# Etch effect for the text
|
||||||
painter.save()
|
painter.save()
|
||||||
|
painter.setRenderHints(QPainter.TextAntialiasing | QPainter.Antialiasing)
|
||||||
|
painter.save()
|
||||||
painter.setPen(QColor(255, 255, 255, 125))
|
painter.setPen(QColor(255, 255, 255, 125))
|
||||||
l.draw(painter, QPointF(1, 1))
|
l.draw(painter, QPointF(1, 1))
|
||||||
painter.restore()
|
painter.restore()
|
||||||
l.draw(painter, QPointF())
|
l.draw(painter, QPointF())
|
||||||
|
painter.restore()
|
||||||
|
|
||||||
def layout_text(prefs, img, title, subtitle, footer, max_height, style):
|
def layout_text(prefs, img, title, subtitle, footer, max_height, style):
|
||||||
width = img.width() - 2 * style.hmargin
|
width = img.width() - 2 * style.hmargin
|
||||||
title, subtitle, footer = title, subtitle, footer
|
title, subtitle, footer = title, subtitle, footer
|
||||||
title_font = QFont(prefs.title_font_family or 'Liberation Serif')
|
title_font = QFont(prefs.title_font_family or 'Liberation Serif')
|
||||||
title_font.setPixelSize(prefs.title_font_size)
|
title_font.setPixelSize(prefs.title_font_size)
|
||||||
|
title_font.setStyleStrategy(QFont.PreferAntialias)
|
||||||
title_block = Block(title, width, title_font, img, max_height, style.TITLE_ALIGN)
|
title_block = Block(title, width, title_font, img, max_height, style.TITLE_ALIGN)
|
||||||
title_block.position = style.hmargin, style.vmargin
|
title_block.position = style.hmargin, style.vmargin
|
||||||
subtitle_block = Block()
|
subtitle_block = Block()
|
||||||
if subtitle:
|
if subtitle:
|
||||||
subtitle_font = QFont(prefs.subtitle_font_family or 'Liberation Sans')
|
subtitle_font = QFont(prefs.subtitle_font_family or 'Liberation Sans')
|
||||||
subtitle_font.setPixelSize(prefs.subtitle_font_size)
|
subtitle_font.setPixelSize(prefs.subtitle_font_size)
|
||||||
|
subtitle_font.setStyleStrategy(QFont.PreferAntialias)
|
||||||
gap = 2 * title_block.leading
|
gap = 2 * title_block.leading
|
||||||
mh = max_height - title_block.height - gap
|
mh = max_height - title_block.height - gap
|
||||||
subtitle_block = Block(subtitle, width, subtitle_font, img, mh, style.SUBTITLE_ALIGN)
|
subtitle_block = Block(subtitle, width, subtitle_font, img, mh, style.SUBTITLE_ALIGN)
|
||||||
subtitle_block.position = style.hmargin, title_block.position.y + title_block.height + gap
|
subtitle_block.position = style.hmargin, title_block.position.y + title_block.height + gap
|
||||||
|
|
||||||
footer_font = QFont(prefs.footer_font_family or 'Liberation Serif')
|
footer_font = QFont(prefs.footer_font_family or 'Liberation Serif')
|
||||||
|
footer_font.setStyleStrategy(QFont.PreferAntialias)
|
||||||
footer_font.setPixelSize(prefs.footer_font_size)
|
footer_font.setPixelSize(prefs.footer_font_size)
|
||||||
footer_block = Block(footer, width, footer_font, img, max_height, style.FOOTER_ALIGN)
|
footer_block = Block(footer, width, footer_font, img, max_height, style.FOOTER_ALIGN)
|
||||||
footer_block.position = style.hmargin, img.height() - style.vmargin - footer_block.height
|
footer_block.position = style.hmargin, img.height() - style.vmargin - footer_block.height
|
||||||
@ -582,7 +588,9 @@ def generate_masthead(title, output_path=None, width=600, height=60, as_qimage=F
|
|||||||
img = QImage(width, height, QImage.Format_ARGB32)
|
img = QImage(width, height, QImage.Format_ARGB32)
|
||||||
img.fill(Qt.white)
|
img.fill(Qt.white)
|
||||||
p = QPainter(img)
|
p = QPainter(img)
|
||||||
|
p.setRenderHints(QPainter.Antialiasing | QPainter.TextAntialiasing)
|
||||||
f = QFont(font_family)
|
f = QFont(font_family)
|
||||||
|
f.setStyleStrategy(QFont.PreferAntialias)
|
||||||
f.setPixelSize((height * 3) // 4), f.setBold(True)
|
f.setPixelSize((height * 3) // 4), f.setBold(True)
|
||||||
p.setFont(f)
|
p.setFont(f)
|
||||||
p.drawText(img.rect(), Qt.AlignLeft | Qt.AlignVCenter, sanitize(title))
|
p.drawText(img.rect(), Qt.AlignLeft | Qt.AlignVCenter, sanitize(title))
|
||||||
@ -598,7 +606,7 @@ def generate_masthead(title, output_path=None, width=600, height=60, as_qimage=F
|
|||||||
def test(scale=0.25):
|
def test(scale=0.25):
|
||||||
from PyQt5.Qt import QLabel, QApplication, QPixmap, QMainWindow, QWidget, QScrollArea, QGridLayout
|
from PyQt5.Qt import QLabel, QApplication, QPixmap, QMainWindow, QWidget, QScrollArea, QGridLayout
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
mi = Metadata('xxx', ['Kovid Goyal', 'John & Doe', 'Author'])
|
mi = Metadata('Unknown', ['Kovid Goyal', 'John & Doe', 'Author'])
|
||||||
mi.series = 'A series of styles'
|
mi.series = 'A series of styles'
|
||||||
m = QMainWindow()
|
m = QMainWindow()
|
||||||
sa = QScrollArea(m)
|
sa = QScrollArea(m)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user