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:
Kovid Goyal 2013-03-09 09:28:53 +05:30
parent 272560e857
commit 4c674042c0
2 changed files with 12 additions and 2 deletions

View File

@ -315,6 +315,8 @@ class PdfDevice(QPaintDevice): # {{{
self.page_width, self.page_height = page_size
self.body_width = self.page_width - left_margin - right_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,
left_margin, top_margin, right_margin,
bottom_margin, self.width(), self.height(),
@ -351,6 +353,14 @@ class PdfDevice(QPaintDevice): # {{{
def init_page(self):
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
def current_page_num(self):
return self.engine.current_page_num

View File

@ -106,7 +106,7 @@ def draw_image_page(page_rect, painter, p, preserve_aspect_ratio=True):
page_rect.height())
dx = int((page_rect.width() - nnw)/2.)
dy = int((page_rect.height() - nnh)/2.)
page_rect.moveTo(dx, dy)
page_rect.translate(dx, dy)
page_rect.setHeight(nnh)
page_rect.setWidth(nnw)
painter.drawPixmap(page_rect, p, p.rect())
@ -192,7 +192,7 @@ class PDFWriter(QObject):
p.loadFromData(self.cover_data)
if not p.isNull():
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,
preserve_aspect_ratio=self.opts.preserve_cover_aspect_ratio)
self.doc.end_page()