mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
PDF Output: Fix bug causing left and right margins to be applied to the cover page. Also fix the preserve cover aspect ratio option not working correctly
This commit is contained in:
parent
272560e857
commit
4c674042c0
@ -315,6 +315,8 @@ class PdfDevice(QPaintDevice): # {{{
|
|||||||
self.page_width, self.page_height = page_size
|
self.page_width, self.page_height = page_size
|
||||||
self.body_width = self.page_width - left_margin - right_margin
|
self.body_width = self.page_width - left_margin - right_margin
|
||||||
self.body_height = self.page_height - top_margin - bottom_margin
|
self.body_height = self.page_height - top_margin - bottom_margin
|
||||||
|
self.left_margin, self.right_margin = left_margin, right_margin
|
||||||
|
self.top_margin, self.bottom_margin = top_margin, bottom_margin
|
||||||
self.engine = PdfEngine(file_object, self.page_width, self.page_height,
|
self.engine = PdfEngine(file_object, self.page_width, self.page_height,
|
||||||
left_margin, top_margin, right_margin,
|
left_margin, top_margin, right_margin,
|
||||||
bottom_margin, self.width(), self.height(),
|
bottom_margin, self.width(), self.height(),
|
||||||
@ -351,6 +353,14 @@ class PdfDevice(QPaintDevice): # {{{
|
|||||||
def init_page(self):
|
def init_page(self):
|
||||||
self.engine.init_page()
|
self.engine.init_page()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def full_page_rect(self):
|
||||||
|
page_width = self.page_width * self.xdpi / 72.0
|
||||||
|
lm = self.left_margin * self.xdpi / 72.0
|
||||||
|
page_height = self.page_height * self.ydpi / 72.0
|
||||||
|
tm = self.top_margin * self.ydpi / 72.0
|
||||||
|
return (-lm, -tm, page_width, page_height)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_page_num(self):
|
def current_page_num(self):
|
||||||
return self.engine.current_page_num
|
return self.engine.current_page_num
|
||||||
|
@ -106,7 +106,7 @@ def draw_image_page(page_rect, painter, p, preserve_aspect_ratio=True):
|
|||||||
page_rect.height())
|
page_rect.height())
|
||||||
dx = int((page_rect.width() - nnw)/2.)
|
dx = int((page_rect.width() - nnw)/2.)
|
||||||
dy = int((page_rect.height() - nnh)/2.)
|
dy = int((page_rect.height() - nnh)/2.)
|
||||||
page_rect.moveTo(dx, dy)
|
page_rect.translate(dx, dy)
|
||||||
page_rect.setHeight(nnh)
|
page_rect.setHeight(nnh)
|
||||||
page_rect.setWidth(nnw)
|
page_rect.setWidth(nnw)
|
||||||
painter.drawPixmap(page_rect, p, p.rect())
|
painter.drawPixmap(page_rect, p, p.rect())
|
||||||
@ -192,7 +192,7 @@ class PDFWriter(QObject):
|
|||||||
p.loadFromData(self.cover_data)
|
p.loadFromData(self.cover_data)
|
||||||
if not p.isNull():
|
if not p.isNull():
|
||||||
self.doc.init_page()
|
self.doc.init_page()
|
||||||
draw_image_page(QRect(0, 0, self.doc.width(), self.doc.height()),
|
draw_image_page(QRect(*self.doc.full_page_rect),
|
||||||
self.painter, p,
|
self.painter, p,
|
||||||
preserve_aspect_ratio=self.opts.preserve_cover_aspect_ratio)
|
preserve_aspect_ratio=self.opts.preserve_cover_aspect_ratio)
|
||||||
self.doc.end_page()
|
self.doc.end_page()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user