Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests #18

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Tests/test_font_pcf.py
Expand Up @@ -76,6 +76,8 @@ def test_textsize(request, tmp_path):
tempname = save_font(request, tmp_path)
font = ImageFont.load(tempname)
for i in range(255):
with pytest.warns(DeprecationWarning):
font.getsize(chr(i))
(ox, oy, dx, dy) = font.getbbox(chr(i))
assert ox == 0
assert oy == 0
Expand Down
6 changes: 4 additions & 2 deletions Tests/test_imagefont.py
Expand Up @@ -316,15 +316,17 @@ def test_rotated_transposed_font(self):
# Original font
draw.font = font
with pytest.warns(DeprecationWarning) as log:
assert font.getsize("A") == (12, 16)
box_size_a = draw.textsize(word)
assert len(log) == 1
assert len(log) == 2
bbox_a = draw.textbbox((10, 10), word)

# Rotated font
draw.font = transposed_font
with pytest.warns(DeprecationWarning) as log:
assert transposed_font.getsize("A") == (16, 12)
box_size_b = draw.textsize(word)
assert len(log) == 1
assert len(log) == 2
bbox_b = draw.textbbox((20, 20), word)

# Check (w,h) of box a is (h,w) of box b
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/ImageDraw.rst
Expand Up @@ -437,9 +437,9 @@ Methods
.. py:method:: ImageDraw.textsize(text, font=None, spacing=4, direction=None, features=None, language=None, stroke_width=0)

.. deprecated:: 9.2.0
Use :py:meth:`textlength()` to measure the offset of following text with
1/64 pixel precision.
Use :py:meth:`textbbox()` to get the exact bounding box based on an anchor.
Use :py:meth:`textlength()` to measure the offset of following text with
1/64 pixel precision.
Use :py:meth:`textbbox()` to get the exact bounding box based on an anchor.

Return the size of the given string, in pixels.

Expand Down Expand Up @@ -486,7 +486,7 @@ Methods
.. py:method:: ImageDraw.multiline_textsize(text, font=None, spacing=4, direction=None, features=None, language=None, stroke_width=0)

.. deprecated:: 9.2.0
Use :py:meth:`.multiline_textbbox` instead.
Use :py:meth:`.multiline_textbbox` instead.

Return the size of the given string, in pixels.

Expand Down
14 changes: 7 additions & 7 deletions src/PIL/ImageFont.py
Expand Up @@ -138,7 +138,7 @@ def _load_pilfont_data(self, file, image):
def getsize(self, text, *args, **kwargs):
"""
.. deprecated:: 9.2.0
Use :py:meth:`.getbbox` or :py:meth:`.getlength` instead.
Use :py:meth:`.getbbox` or :py:meth:`.getlength` instead.

Returns width and height (in pixels) of given text.

Expand Down Expand Up @@ -428,9 +428,9 @@ def getsize(
):
"""
.. deprecated:: 9.2.0
Use :py:meth:`getlength()` to measure the offset of following text with
1/64 pixel precision.
Use :py:meth:`getbbox()` to get the exact bounding box based on an anchor.
Use :py:meth:`getlength()` to measure the offset of following text with
1/64 pixel precision.
Use :py:meth:`getbbox()` to get the exact bounding box based on an anchor.

Returns width and height (in pixels) of given text if rendered in font with
provided direction, features, and language.
Expand Down Expand Up @@ -498,7 +498,7 @@ def getsize_multiline(
):
"""
.. deprecated:: 9.2.0
Use :py:meth:`.ImageDraw.multiline_textbbox` instead.
Use :py:meth:`.ImageDraw.multiline_textbbox` instead.

Returns width and height (in pixels) of given text if rendered in font
with provided direction, features, and language, while respecting
Expand Down Expand Up @@ -556,7 +556,7 @@ def getsize_multiline(
def getoffset(self, text):
"""
.. deprecated:: 9.2.0
Use :py:meth:`.getbbox` instead.
Use :py:meth:`.getbbox` instead.

Returns the offset of given text. This is the gap between the
starting coordinate and the first marking. Note that this gap is
Expand Down Expand Up @@ -849,7 +849,7 @@ def __init__(self, font, orientation=None):
def getsize(self, text, *args, **kwargs):
"""
.. deprecated:: 9.2.0
Use :py:meth:`.getbbox` or :py:meth:`.getlength` instead.
Use :py:meth:`.getbbox` or :py:meth:`.getlength` instead.
"""
if not kwargs.get("__internal__"):
deprecate("getsize", 10, "getbbox or getlength")
Expand Down