|
10 | 10 | import gentle_compare
|
11 | 11 |
|
12 | 12 |
|
13 |
| -pymupdf.TOOLS.set_annot_stem("jorj") |
14 |
| - |
15 | 13 | red = (1, 0, 0)
|
16 | 14 | blue = (0, 0, 1)
|
17 | 15 | gold = (1, 1, 0)
|
@@ -226,38 +224,46 @@ def test_1645():
|
226 | 224 | '''
|
227 | 225 | Test fix for #1645.
|
228 | 226 | '''
|
229 |
| - path_in = os.path.abspath( f'{__file__}/../resources/symbol-list.pdf') |
230 |
| - |
231 |
| - if pymupdf.mupdf_version_tuple >= (1, 26): |
232 |
| - path_expected = os.path.abspath( f'{__file__}/../../tests/resources/test_1645_expected_1.26.pdf') |
233 |
| - elif pymupdf.mupdf_version_tuple >= (1, 25): |
234 |
| - path_expected = os.path.abspath( f'{__file__}/../../tests/resources/test_1645_expected_1.25.pdf') |
235 |
| - elif pymupdf.mupdf_version_tuple >= (1, 24, 2): |
236 |
| - path_expected = os.path.abspath( f'{__file__}/../../tests/resources/test_1645_expected_1.24.2.pdf') |
237 |
| - else: |
238 |
| - path_expected = os.path.abspath( f'{__file__}/../../tests/resources/test_1645_expected_1.24.pdf') |
239 |
| - path_out = os.path.abspath( f'{__file__}/../test_1645_out.pdf') |
240 |
| - doc = pymupdf.open(path_in) |
241 |
| - page = doc[0] |
242 |
| - page_bounds = page.bound() |
243 |
| - annot_loc = pymupdf.Rect(page_bounds.x0, page_bounds.y0, page_bounds.x0 + 75, page_bounds.y0 + 15) |
244 |
| - # Check type of page.derotation_matrix - this is #2911. |
245 |
| - assert isinstance(page.derotation_matrix, pymupdf.Matrix), \ |
246 |
| - f'Bad type for page.derotation_matrix: {type(page.derotation_matrix)=} {page.derotation_matrix=}.' |
247 |
| - page.add_freetext_annot( |
248 |
| - annot_loc * page.derotation_matrix, |
249 |
| - "TEST", |
250 |
| - fontsize=18, |
251 |
| - fill_color=pymupdf.utils.getColor("FIREBRICK1"), |
252 |
| - rotate=page.rotation, |
253 |
| - ) |
254 |
| - doc.save(path_out, garbage=1, deflate=True, no_new_id=True) |
255 |
| - print(f'Have created {path_out}. comparing with {path_expected}.') |
256 |
| - with open( path_out, 'rb') as f: |
257 |
| - out = f.read() |
258 |
| - with open( path_expected, 'rb') as f: |
259 |
| - expected = f.read() |
260 |
| - assert out == expected, f'Files differ: {path_out} {path_expected}' |
| 227 | + # The expected output files assume annot_stem is 'jorj'. We need to always |
| 228 | + # restore this before returning (this is checked by conftest.py). |
| 229 | + annot_stem = pymupdf.JM_annot_id_stem |
| 230 | + pymupdf.TOOLS.set_annot_stem('jorj') |
| 231 | + try: |
| 232 | + path_in = os.path.abspath( f'{__file__}/../resources/symbol-list.pdf') |
| 233 | + |
| 234 | + if pymupdf.mupdf_version_tuple >= (1, 26): |
| 235 | + path_expected = os.path.abspath( f'{__file__}/../../tests/resources/test_1645_expected_1.26.pdf') |
| 236 | + elif pymupdf.mupdf_version_tuple >= (1, 25): |
| 237 | + path_expected = os.path.abspath( f'{__file__}/../../tests/resources/test_1645_expected_1.25.pdf') |
| 238 | + elif pymupdf.mupdf_version_tuple >= (1, 24, 2): |
| 239 | + path_expected = os.path.abspath( f'{__file__}/../../tests/resources/test_1645_expected_1.24.2.pdf') |
| 240 | + else: |
| 241 | + path_expected = os.path.abspath( f'{__file__}/../../tests/resources/test_1645_expected_1.24.pdf') |
| 242 | + path_out = os.path.abspath( f'{__file__}/../test_1645_out.pdf') |
| 243 | + doc = pymupdf.open(path_in) |
| 244 | + page = doc[0] |
| 245 | + page_bounds = page.bound() |
| 246 | + annot_loc = pymupdf.Rect(page_bounds.x0, page_bounds.y0, page_bounds.x0 + 75, page_bounds.y0 + 15) |
| 247 | + # Check type of page.derotation_matrix - this is #2911. |
| 248 | + assert isinstance(page.derotation_matrix, pymupdf.Matrix), \ |
| 249 | + f'Bad type for page.derotation_matrix: {type(page.derotation_matrix)=} {page.derotation_matrix=}.' |
| 250 | + page.add_freetext_annot( |
| 251 | + annot_loc * page.derotation_matrix, |
| 252 | + "TEST", |
| 253 | + fontsize=18, |
| 254 | + fill_color=pymupdf.utils.getColor("FIREBRICK1"), |
| 255 | + rotate=page.rotation, |
| 256 | + ) |
| 257 | + doc.save(path_out, garbage=1, deflate=True, no_new_id=True) |
| 258 | + print(f'Have created {path_out}. comparing with {path_expected}.') |
| 259 | + with open( path_out, 'rb') as f: |
| 260 | + out = f.read() |
| 261 | + with open( path_expected, 'rb') as f: |
| 262 | + expected = f.read() |
| 263 | + assert out == expected, f'Files differ: {path_out} {path_expected}' |
| 264 | + finally: |
| 265 | + # Restore annot_stem. |
| 266 | + pymupdf.TOOLS.set_annot_stem(annot_stem) |
261 | 267 |
|
262 | 268 | def test_1824():
|
263 | 269 | '''
|
|
0 commit comments