MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / test_richtext

Function test_richtext

tests/test_annots.py:564–613  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

562 assert len(top_colors) == 1
563
564def 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
616def test_4447():

Callers

nothing calls this directly

Calls 4

new_pageMethod · 0.80
add_freetext_annotMethod · 0.80
get_pixmapMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…