Test creation of rich text FreeText annotations. We create the same annotation on different pages in different ways, with and without using Annotation.update(), and then assert equality of the respective images.
()
| 562 | assert len(top_colors) == 1 |
| 563 | |
| 564 | def test_richtext(): |
| 565 | """Test creation of rich text FreeText annotations. |
| 566 | |
| 567 | We create the same annotation on different pages in different ways, |
| 568 | with and without using Annotation.update(), and then assert equality |
| 569 | of the respective images. |
| 570 | """ |
| 571 | ds = """font-size: 11pt; font-family: sans-serif;""" |
| 572 | bullet = chr(0x2610) + chr(0x2611) + chr(0x2612) |
| 573 | text = f"""<p style="text-align:justify;margin-top:-25px;"> |
| 574 | PyMuPDF <span style="color: red;">འདི་ ཡིག་ཆ་བཀྲམ་སྤེལ་གྱི་དོན་ལུ་ པའི་ཐོན་ཐུམ་སྒྲིལ་དྲག་ཤོས་དང་མགྱོགས་ཤོས་ཅིག་ཨིན།</span> |
| 575 | <span style="color:blue;">Here is some <b>bold</b> and <i>italic</i> text, followed by <b><i>bold-italic</i></b>. Text-based check boxes: {bullet}.</span> |
| 576 | </p>""" |
| 577 | gold = (1, 1, 0) |
| 578 | doc = pymupdf.open() |
| 579 | |
| 580 | # First page. |
| 581 | page = doc.new_page() |
| 582 | rect = pymupdf.Rect(100, 100, 350, 200) |
| 583 | p2 = rect.tr + (50, 30) |
| 584 | p3 = p2 + (0, 30) |
| 585 | annot = page.add_freetext_annot( |
| 586 | rect, |
| 587 | text, |
| 588 | fill_color=gold, |
| 589 | opacity=0.5, |
| 590 | rotate=90, |
| 591 | border_width=1, |
| 592 | dashes=None, |
| 593 | richtext=True, |
| 594 | callout=(p3, p2, rect.tr), |
| 595 | ) |
| 596 | |
| 597 | pix1 = page.get_pixmap() |
| 598 | |
| 599 | # Second page. |
| 600 | # the annotation is created with minimal parameters, which are supplied |
| 601 | # in a separate call to the .update() method. |
| 602 | page = doc.new_page() |
| 603 | annot = page.add_freetext_annot( |
| 604 | rect, |
| 605 | text, |
| 606 | border_width=1, |
| 607 | dashes=None, |
| 608 | richtext=True, |
| 609 | callout=(p3, p2, rect.tr), |
| 610 | ) |
| 611 | annot.update(fill_color=gold, opacity=0.5, rotate=90) |
| 612 | pix2 = page.get_pixmap() |
| 613 | assert pix1.samples == pix2.samples |
| 614 | |
| 615 | |
| 616 | def test_4447(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…