(self, w: int, h: int)
| 81 | self._pixmap = px |
| 82 | |
| 83 | def _load_pdf(self, w: int, h: int) -> QPixmap: |
| 84 | try: |
| 85 | from PySide6.QtPdf import QPdfDocument |
| 86 | doc = QPdfDocument(None) |
| 87 | doc.load(self.file_path) |
| 88 | if doc.pageCount() < 1: |
| 89 | doc.close() |
| 90 | return self._placeholder(w, h) |
| 91 | pt = doc.pagePointSize(0) |
| 92 | if pt.width() <= 0: |
| 93 | doc.close() |
| 94 | return self._placeholder(w, h) |
| 95 | # Render at 2× display size for crispness, then downscale |
| 96 | scale = w / pt.width() |
| 97 | img_w = max(1, round(pt.width() * scale * 2)) |
| 98 | img_h = max(1, round(pt.height() * scale * 2)) |
| 99 | qimg = doc.render(0, QSize(img_w, img_h)) |
| 100 | doc.close() |
| 101 | return QPixmap.fromImage(qimg).scaled( |
| 102 | w, h, Qt.KeepAspectRatio, Qt.SmoothTransformation |
| 103 | ) |
| 104 | except Exception: |
| 105 | return self._placeholder(w, h) |
| 106 | |
| 107 | @staticmethod |
| 108 | def _placeholder(w: int, h: int) -> QPixmap: |
no test coverage detected