Check fix for #3347 - link destination rectangles when source/destination pages have different sizes.
()
| 159 | |
| 160 | |
| 161 | def test_3347(): |
| 162 | ''' |
| 163 | Check fix for #3347 - link destination rectangles when source/destination |
| 164 | pages have different sizes. |
| 165 | ''' |
| 166 | doc = pymupdf.open() |
| 167 | doc.new_page(width=500, height=800) |
| 168 | doc.new_page(width=800, height=500) |
| 169 | rects = [ |
| 170 | (0, pymupdf.Rect(10, 20, 50, 40), pymupdf.utils.getColor('red')), |
| 171 | (0, pymupdf.Rect(300, 350, 400, 450), pymupdf.utils.getColor('green')), |
| 172 | (1, pymupdf.Rect(20, 30, 40, 50), pymupdf.utils.getColor('blue')), |
| 173 | (1, pymupdf.Rect(350, 300, 450, 400), pymupdf.utils.getColor('black')) |
| 174 | ] |
| 175 | |
| 176 | for page, rect, color in rects: |
| 177 | doc[page].draw_rect(rect, color=color) |
| 178 | |
| 179 | for (from_page, from_rect, _), (to_page, to_rect, _) in zip(rects, rects[1:] + rects[:1]): |
| 180 | doc[from_page].insert_link({ |
| 181 | 'kind': 1, |
| 182 | 'from': from_rect, |
| 183 | 'page': to_page, |
| 184 | 'to': to_rect.top_left, |
| 185 | }) |
| 186 | |
| 187 | links_expected = [ |
| 188 | (0, {'kind': 1, 'xref': 11, 'from': pymupdf.Rect(10.0, 20.0, 50.0, 40.0), 'page': 0, 'to': pymupdf.Point(300.0, 350.0), 'zoom': 0.0, 'id': 'fitz-L0'}), |
| 189 | (0, {'kind': 1, 'xref': 12, 'from': pymupdf.Rect(300.0, 350.0, 400.0, 450.0), 'page': 1, 'to': pymupdf.Point(20.0, 30.0), 'zoom': 0.0, 'id': 'fitz-L1'}), |
| 190 | (1, {'kind': 1, 'xref': 13, 'from': pymupdf.Rect(20.0, 30.0, 40.0, 50.0), 'page': 1, 'to': pymupdf.Point(350.0, 300.0), 'zoom': 0.0, 'id': 'fitz-L0'}), |
| 191 | (1, {'kind': 1, 'xref': 14, 'from': pymupdf.Rect(350.0, 300.0, 450.0, 400.0), 'page': 0, 'to': pymupdf.Point(10.0, 20.0), 'zoom': 0.0, 'id': 'fitz-L1'}), |
| 192 | ] |
| 193 | |
| 194 | path = os.path.normpath(f'{__file__}/../../tests/test_3347_out.pdf') |
| 195 | doc.save(path) |
| 196 | print(f'Have saved to {path=}.') |
| 197 | |
| 198 | links_actual = list() |
| 199 | for page_i, page in enumerate(doc): |
| 200 | links = page.get_links() |
| 201 | for link_i, link in enumerate(links): |
| 202 | print(f'{page_i=} {link_i=}: {link!r}') |
| 203 | links_actual.append( (page_i, link) ) |
| 204 | |
| 205 | assert links_actual == links_expected |
| 206 | |
| 207 | |
| 208 | def test_3400(): |