Search for a string on a page. Args: text: string to be searched for clip: restrict search to this rectangle quads: (bool) return quads instead of rectangles flags: bit switches, default: join hyphened words textpage: a pre-created TextPage Returns:
(*args, **kwargs)
| 424 | |
| 425 | |
| 426 | def search_for(*args, **kwargs) -> list: |
| 427 | """Search for a string on a page. |
| 428 | |
| 429 | Args: |
| 430 | text: string to be searched for |
| 431 | clip: restrict search to this rectangle |
| 432 | quads: (bool) return quads instead of rectangles |
| 433 | flags: bit switches, default: join hyphened words |
| 434 | textpage: a pre-created TextPage |
| 435 | Returns: |
| 436 | a list of rectangles or quads, each containing one occurrence. |
| 437 | """ |
| 438 | if len(args) != 2: |
| 439 | raise ValueError("bad number of positional parameters") |
| 440 | page, text = args |
| 441 | quads = kwargs.get("quads", 0) |
| 442 | clip = kwargs.get("clip") |
| 443 | textpage = kwargs.get("textpage") |
| 444 | if clip != None: |
| 445 | clip = Rect(clip) |
| 446 | flags = kwargs.get( |
| 447 | "flags", |
| 448 | TEXT_DEHYPHENATE |
| 449 | | TEXT_PRESERVE_WHITESPACE |
| 450 | | TEXT_PRESERVE_LIGATURES |
| 451 | | TEXT_MEDIABOX_CLIP, |
| 452 | ) |
| 453 | |
| 454 | CheckParent(page) |
| 455 | tp = textpage |
| 456 | if tp is None: |
| 457 | tp = page.get_textpage(clip=clip, flags=flags) # create TextPage |
| 458 | elif getattr(tp, "parent") != page: |
| 459 | raise ValueError("not a textpage of this page") |
| 460 | rlist = tp.search(text, quads=quads) |
| 461 | if textpage is None: |
| 462 | del tp |
| 463 | return rlist |
| 464 | |
| 465 | |
| 466 | def search_page_for( |
nothing calls this directly
no test coverage detected
searching dependent graphs…