Skip to content

Commit

Permalink
Revert "Drop support for textsize completely"
Browse files Browse the repository at this point in the history
This reverts commit 400c85f.
  • Loading branch information
avalentino committed Jul 9, 2023
1 parent 400c85f commit 546ad0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions pycoast/cw_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ def _draw_text_box(
):
"""Add a text box at position (x,y)."""
if box_outline is not None:
left, top, right, bottom = draw.textbbox(text_position, text, font)
text_size = right - left, top - bottom
if hasattr(draw, "textsize"):
text_size = draw.textsize(text, font)
else:
left, top, right, bottom = draw.textbbox(text_position, text, font)
text_size = right - left, top - bottom
margin = 2
xUL = text_position[0] - margin
yUL = text_position[1]
Expand Down
7 changes: 5 additions & 2 deletions pycoast/cw_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ def is_agg(self) -> bool:

def _draw_text(self, draw, position, txt, font, align="cc", **kwargs):
"""Draw text with agg module."""
left, top, right, bottom = draw.textbbox(position, txt, font)
txt_width, txt_height = right - left, top - bottom
if hasattr(draw, "textsize"):
txt_width, txt_height = draw.textsize(txt, font)
else:
left, top, right, bottom = draw.textbbox(position, txt, font)
txt_width, txt_height = right - left, top - bottom
x_pos, y_pos = position
ax, ay = align.lower()
if ax == "r":
Expand Down

0 comments on commit 546ad0d

Please sign in to comment.