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

Function test_2637

tests/test_textbox.py:137–156  ·  view source on GitHub ↗

Ensure correct calculation of fitting text.

()

Source from the content-addressed store, hash-verified

135
136
137def test_2637():
138 """Ensure correct calculation of fitting text."""
139 doc = pymupdf.open()
140 page = doc.new_page()
141 text = (
142 "The morning sun painted the sky with hues of orange and pink. "
143 "Birds chirped harmoniously, greeting the new day. "
144 "Nature awakened, filling the air with life and promise."
145 )
146 rect = pymupdf.Rect(50, 50, 500, 280)
147 fontsize = 50
148 rc = -1
149 while rc < 0: # look for largest font size that makes the text fit
150 rc = page.insert_textbox(rect, text, fontname="hebo", fontsize=fontsize)
151 fontsize -= 1
152
153 # confirm text won't lap outside rect
154 blocks = page.get_text("blocks")
155 bbox = pymupdf.Rect(blocks[0][:4])
156 assert bbox in rect
157
158
159def test_htmlbox1():

Callers

nothing calls this directly

Calls 3

new_pageMethod · 0.80
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…