Skip to content

Commit

Permalink
Fixed handling of fit failure in Page.insert_htmlbox().
Browse files Browse the repository at this point in the history
This addresses #3916.
  • Loading branch information
julian-smith-artifex-com committed Oct 4, 2024
1 parent f5ee8fd commit 8892bb9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2105,8 +2105,7 @@ def insert_htmlbox(
scale_max = None if scale_low == 0 else 1 / scale_low

fit = story.fit_scale(temp_rect, scale_min=1, scale_max=scale_max)

if fit.big_enough is False: # there was no fit
if not fit.big_enough: # there was no fit
return (-1, scale_low)

filled = fit.filled
Expand Down
8 changes: 8 additions & 0 deletions tests/test_textbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,11 @@ def test_3559():
text_insert="""<body><h3></h3></body>"""
rect = pymupdf.Rect(100, 100, 200, 200)
page.insert_htmlbox(rect, text_insert)


def test_3916():
doc = pymupdf.open()
rect = pymupdf.Rect(100, 100, 101, 101) # Too small for the text.
page = doc.new_page()
spare_height, scale = page.insert_htmlbox(rect, "Hello, World!", scale_low=0.5)
assert spare_height == -1

0 comments on commit 8892bb9

Please sign in to comment.