Assert correct char bbox in page.get_texttrace(). Search for a unique char on page and confirm that page.get_texttrace() returns the same bbox as the search method.
()
| 293 | |
| 294 | |
| 295 | def test_2533(): |
| 296 | """Assert correct char bbox in page.get_texttrace(). |
| 297 | |
| 298 | Search for a unique char on page and confirm that page.get_texttrace() |
| 299 | returns the same bbox as the search method. |
| 300 | """ |
| 301 | if not pymupdf.g_use_extra: |
| 302 | print('Not running test_2533() because use_extra=0 known to fail') |
| 303 | return |
| 304 | pymupdf.TOOLS.set_small_glyph_heights(True) |
| 305 | try: |
| 306 | doc = pymupdf.open(os.path.join(scriptdir, "resources", "test_2533.pdf")) |
| 307 | page = doc[0] |
| 308 | NEEDLE = "民" |
| 309 | ord_NEEDLE = ord(NEEDLE) |
| 310 | for span in page.get_texttrace(): |
| 311 | for char in span["chars"]: |
| 312 | if char[0] == ord_NEEDLE: |
| 313 | bbox = pymupdf.Rect(char[3]) |
| 314 | break |
| 315 | bbox2 = page.search_for(NEEDLE)[0] |
| 316 | assert bbox2 == bbox, f'{bbox=} {bbox2=} {bbox2-bbox=}.' |
| 317 | finally: |
| 318 | pymupdf.TOOLS.set_small_glyph_heights(False) |
| 319 | |
| 320 | |
| 321 | def test_2645(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…