Merge pull request #418 from zbelial/render_quality

display pages in same width and not sacrificing render quality, again
master
Andy Stewart 5 years ago committed by GitHub
commit 2199397e50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      app/pdf-viewer/buffer.py

@ -352,7 +352,6 @@ class PdfViewerWidget(QWidget):
else:
self.page_cache_pixmap_dict.clear()
self.page_cache_scale = scale
self.page_cache_trans = fitz.Matrix(scale, scale)
page = self.document[index]
if self.inpdf:
@ -360,6 +359,15 @@ class PdfViewerWidget(QWidget):
if self.is_mark_link:
page = self.add_mark_link(index)
if rotation % 180 != 0:
self.page_width = self.original_page_height
self.page_height = self.original_page_width
else:
self.page_width = self.original_page_width
self.page_height = self.original_page_height
scale = scale * self.page_width / page.rect.width
# follow page search text
if self.is_mark_search:
page = self.add_mark_search_text(page, index)
@ -373,14 +381,7 @@ class PdfViewerWidget(QWidget):
col = self.handle_color(QColor(self.emacs_var_dict["eaf-emacs-theme-background-color"]), self.inverted_mode)
page.drawRect(page.CropBox, color=col, fill=col, overlay=False)
trans = self.page_cache_trans if self.page_cache_trans is not None else fitz.Matrix(scale, scale)
pixmap = page.getPixmap(matrix=trans, alpha=False)
if rotation % 180 != 0:
self.page_width = self.original_page_height
self.page_height = self.original_page_width
else:
self.page_width = self.original_page_width
self.page_height = self.original_page_height
pixmap = page.getPixmap(matrix=fitz.Matrix(scale, scale), alpha=False)
if self.inverted_mode:
pixmap.invertIRect(pixmap.irect)
@ -452,9 +453,9 @@ class PdfViewerWidget(QWidget):
imagebboxlist.remove(item)
for bbox in imagebboxlist:
if self.inpdf:
pixmap.invertIRect(bbox * page.rotationMatrix * self.scale)
pixmap.invertIRect(bbox * page.rotationMatrix * scale)
else:
pixmap.invertIRect(bbox * self.scale)
pixmap.invertIRect(bbox * scale)
img = QImage(pixmap.samples, pixmap.width, pixmap.height, pixmap.stride, QImage.Format_RGB888)
qpixmap = QPixmap.fromImage(img)
@ -504,16 +505,17 @@ class PdfViewerWidget(QWidget):
painter.translate(0, translate_y)
# Render pages in visible area.
render_x = 0
render_y = 0
for index in list(range(start_page_index, last_page_index)):
if index < self.page_total_number:
# Get page image.
qpixmap = self.get_page_pixmap(index, self.scale, self.rotation)
# Init render rect.
render_width = self.page_width * self.scale
render_height = self.page_height * self.scale
render_width = qpixmap.width()
render_height = qpixmap.height()
render_x = (self.rect().width() - render_width) / 2
render_y = (index - start_page_index) * self.scale * self.page_height
# Add padding between pages.
if (index - start_page_index) > 0:
@ -523,12 +525,10 @@ class PdfViewerWidget(QWidget):
if self.read_mode == "fit_to_customize" and render_width >= self.rect().width():
render_x = max(min(render_x + self.horizontal_offset, 0), self.rect().width() - render_width) # limit the visiable area size
# Different page has different width, if pixmap size is not equal render_width, page render will slight blurry.
#
# And we can't draw pixmap will pixmap's width and height,
# because it will cause render width is not same if different page has different width.
painter.drawPixmap(QRect(render_x, render_y, render_width, render_height), qpixmap)
render_y += render_height
# Clean unused pixmap cache that avoid use too much memory.
self.clean_unused_page_cache_pixmap()

Loading…
Cancel
Save