Mercurial > hgrepos > Python2 > PyMuPDF
comparison tests/test_linequad.py @ 1:1d09e1dec1d9 upstream
ADD: PyMuPDF v1.26.4: the original sdist.
It does not yet contain MuPDF. This normally will be downloaded when
building PyMuPDF.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:37:51 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 1:1d09e1dec1d9 |
|---|---|
| 1 """ | |
| 2 Check approx. equality of search quads versus quads recovered from | |
| 3 text extractions. | |
| 4 """ | |
| 5 import os | |
| 6 | |
| 7 import pymupdf | |
| 8 | |
| 9 scriptdir = os.path.abspath(os.path.dirname(__file__)) | |
| 10 filename = os.path.join(scriptdir, "resources", "quad-calc-0.pdf") | |
| 11 | |
| 12 | |
| 13 def test_quadcalc(): | |
| 14 text = " angle 327" # search for this text | |
| 15 doc = pymupdf.open(filename) | |
| 16 page = doc[0] | |
| 17 # This special page has one block with one line, and | |
| 18 # its last span contains the searched text. | |
| 19 block = page.get_text("dict", flags=0)["blocks"][0] | |
| 20 line = block["lines"][0] | |
| 21 # compute quad of last span in line | |
| 22 lineq = pymupdf.recover_line_quad(line, spans=line["spans"][-1:]) | |
| 23 | |
| 24 # let text search find the text returning quad coordinates | |
| 25 rl = page.search_for(text, quads=True) | |
| 26 searchq = rl[0] | |
| 27 assert abs(searchq.ul - lineq.ul) <= 1e-4 | |
| 28 assert abs(searchq.ur - lineq.ur) <= 1e-4 | |
| 29 assert abs(searchq.ll - lineq.ll) <= 1e-4 | |
| 30 assert abs(searchq.lr - lineq.lr) <= 1e-4 |
