()
| 296 | |
| 297 | |
| 298 | def test_4613(): |
| 299 | print() |
| 300 | text = 3 * 'abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n' |
| 301 | story = pymupdf.Story(text) |
| 302 | rect = pymupdf.Rect(10, 10, 100, 100) |
| 303 | |
| 304 | # Test default operation where we get additional scaling down because of |
| 305 | # the long words in our text. |
| 306 | print(f'test_4613(): ### Testing default operation.') |
| 307 | with pymupdf.open() as doc: |
| 308 | page = doc.new_page() |
| 309 | spare_height, scale = page.insert_htmlbox(rect, story) |
| 310 | print(f'test_4613(): {spare_height=} {scale=}') |
| 311 | # The additional down-scaling from the long word widths results in |
| 312 | # spare vertical space. |
| 313 | page.draw_rect(rect, (1, 0, 0)) |
| 314 | path = os.path.normpath(f'{__file__}/../../tests/test_4613.pdf') |
| 315 | doc.save(path) |
| 316 | |
| 317 | path_pixmap = os.path.normpath(f'{__file__}/../../tests/test_4613.png') |
| 318 | path_pixmap_expected = os.path.normpath(f'{__file__}/../../tests/resources/test_4613.png') |
| 319 | pixmap = page.get_pixmap(dpi=300) |
| 320 | pixmap.save(path_pixmap) |
| 321 | |
| 322 | pixmap_diff = gentle_compare.pixmaps_diff(path_pixmap_expected, pixmap) |
| 323 | pixmap_diff.save(os.path.normpath(f'{__file__}/../../tests/test_4613-diff.png')) |
| 324 | |
| 325 | rms = gentle_compare.pixmaps_rms(pixmap, path_pixmap_expected) |
| 326 | print(f'{rms=}') |
| 327 | assert rms == 0, f'{rms=}' |
| 328 | |
| 329 | assert abs(spare_height - 45.7536) < 0.1 |
| 330 | assert abs(scale - 0.4009) < 0.01 |
| 331 | |
| 332 | new_text = page.get_text('text', clip=rect) |
| 333 | print(f'test_4613(): new_text:') |
| 334 | print(textwrap.indent(new_text, ' ')) |
| 335 | assert new_text == text |
| 336 | |
| 337 | # Check with _scale_word_width=False - ignore too-wide words. |
| 338 | print(f'test_4613(): ### Testing with _scale_word_width=False.') |
| 339 | with pymupdf.open() as doc: |
| 340 | page = doc.new_page() |
| 341 | spare_height, scale = page.insert_htmlbox(rect, story, _scale_word_width=False) |
| 342 | print(f'test_4613(): _scale_word_width=False: {spare_height=} {scale=}') |
| 343 | # With _scale_word_width=False we allow long words to extend beyond the |
| 344 | # rect, so we should have spare_height == 0 and only a small amount of |
| 345 | # down-scaling. |
| 346 | assert spare_height == 0 |
| 347 | assert abs(scale - 0.914) < 0.01 |
| 348 | new_text = page.get_text('text', clip=rect) |
| 349 | print(f'test_4613(): new_text:') |
| 350 | print(textwrap.indent(new_text, ' ')) |
| 351 | assert new_text == textwrap.dedent(''' |
| 352 | abcdefghijklmno |
| 353 | ABCDEFGHIJKLM |
| 354 | abcdefghijklmno |
| 355 | ABCDEFGHIJKLM |
nothing calls this directly
no test coverage detected
searching dependent graphs…