MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / test_3347

Function test_3347

tests/test_toc.py:161–205  ·  view source on GitHub ↗

Check fix for #3347 - link destination rectangles when source/destination pages have different sizes.

()

Source from the content-addressed store, hash-verified

159
160
161def 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
208def test_3400():

Callers

nothing calls this directly

Calls 6

new_pageMethod · 0.80
insert_linkMethod · 0.80
get_linksMethod · 0.80
draw_rectMethod · 0.45
saveMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…