Skip to content

Commit

Permalink
[C] Including getbbox into try-except block
Browse files Browse the repository at this point in the history
  • Loading branch information
zephyr-sh committed May 7, 2024
1 parent 0729580 commit 3cdba43
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 3 additions & 4 deletions wordcanvas/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,10 @@ def split_text(text: str):
matches = list(text)
return matches

left, top, right, bottom = font.getbbox(text, direction=direction)
width = max(right - left, 1)
height = max(bottom - top, 1)

try:
left, top, right, bottom = font.getbbox(text, direction=direction)
width = max(right - left, 1)
height = max(bottom - top, 1)
_, offset = font.getmask2(text, direction=direction)
except Exception as e:
raise ValueError(
Expand Down
3 changes: 1 addition & 2 deletions wordcanvas/text2image.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ def text2image(
np.ndarray: A NumPy array representing the generated image.
"""

left, top, right, bottom = font.getbbox(text, direction=direction)

try:
left, top, right, bottom = font.getbbox(text, direction=direction)
_, _offset = font.getmask2(text, direction=direction)
except Exception as e:
raise ValueError(
Expand Down

0 comments on commit 3cdba43

Please sign in to comment.