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

Function test_textbox5

tests/test_textbox.py:108–134  ·  view source on GitHub ↗

Using basic text insertion.

()

Source from the content-addressed store, hash-verified

106
107
108def test_textbox5():
109 """Using basic text insertion."""
110 small_glyph_heights0 = pymupdf.TOOLS.set_small_glyph_heights()
111 pymupdf.TOOLS.set_small_glyph_heights(True)
112 try:
113 doc = pymupdf.open()
114 page = doc.new_page()
115 r = pymupdf.Rect(100, 100, 150, 150)
116 text = "words and words and words and more words..."
117 rc = -1
118 fontsize = 12
119 page.draw_rect(r)
120 while rc < 0:
121 rc = page.insert_textbox(
122 r,
123 text,
124 fontsize=fontsize,
125 align=pymupdf.TEXT_ALIGN_JUSTIFY,
126 )
127 fontsize -= 0.5
128
129 blocks = page.get_text("blocks")
130 bbox = pymupdf.Rect(blocks[0][:4])
131 assert bbox in r
132 finally:
133 # Must restore small_glyph_heights, otherwise other tests can fail.
134 pymupdf.TOOLS.set_small_glyph_heights(small_glyph_heights0)
135
136
137def test_2637():

Callers

nothing calls this directly

Calls 5

new_pageMethod · 0.80
draw_rectMethod · 0.45
insert_textboxMethod · 0.45
get_textMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…