mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-29 14:34:13 +03:00
Replaced __internal__ argument with warning filters
This commit is contained in:
parent
729fe6f8b0
commit
8a6050ee5b
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import numbers
|
import numbers
|
||||||
|
import warnings
|
||||||
|
|
||||||
from . import Image, ImageColor
|
from . import Image, ImageColor
|
||||||
from ._deprecate import deprecate
|
from ._deprecate import deprecate
|
||||||
|
@ -375,15 +376,16 @@ class ImageDraw:
|
||||||
|
|
||||||
def _multiline_spacing(self, font, spacing, stroke_width):
|
def _multiline_spacing(self, font, spacing, stroke_width):
|
||||||
# this can be replaced with self.textbbox(...)[3] when textsize is removed
|
# this can be replaced with self.textbbox(...)[3] when textsize is removed
|
||||||
return (
|
with warnings.catch_warnings():
|
||||||
self.textsize(
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
"A",
|
return (
|
||||||
font=font,
|
self.textsize(
|
||||||
stroke_width=stroke_width,
|
"A",
|
||||||
__internal__=True,
|
font=font,
|
||||||
)[1]
|
stroke_width=stroke_width,
|
||||||
+ spacing
|
)[1]
|
||||||
)
|
+ spacing
|
||||||
|
)
|
||||||
|
|
||||||
def text(
|
def text(
|
||||||
self,
|
self,
|
||||||
|
@ -582,34 +584,34 @@ class ImageDraw:
|
||||||
features=None,
|
features=None,
|
||||||
language=None,
|
language=None,
|
||||||
stroke_width=0,
|
stroke_width=0,
|
||||||
__internal__=False,
|
|
||||||
):
|
):
|
||||||
"""Get the size of a given string, in pixels."""
|
"""Get the size of a given string, in pixels."""
|
||||||
if not __internal__:
|
deprecate("textsize", 10, "textbbox or textlength")
|
||||||
deprecate("textsize", 10, "textbbox or textlength")
|
|
||||||
if self._multiline_check(text):
|
if self._multiline_check(text):
|
||||||
return self.multiline_textsize(
|
with warnings.catch_warnings():
|
||||||
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
|
return self.multiline_textsize(
|
||||||
|
text,
|
||||||
|
font,
|
||||||
|
spacing,
|
||||||
|
direction,
|
||||||
|
features,
|
||||||
|
language,
|
||||||
|
stroke_width,
|
||||||
|
)
|
||||||
|
|
||||||
|
if font is None:
|
||||||
|
font = self.getfont()
|
||||||
|
with warnings.catch_warnings():
|
||||||
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
|
return font.getsize(
|
||||||
text,
|
text,
|
||||||
font,
|
|
||||||
spacing,
|
|
||||||
direction,
|
direction,
|
||||||
features,
|
features,
|
||||||
language,
|
language,
|
||||||
stroke_width,
|
stroke_width,
|
||||||
__internal__=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if font is None:
|
|
||||||
font = self.getfont()
|
|
||||||
return font.getsize(
|
|
||||||
text,
|
|
||||||
direction,
|
|
||||||
features,
|
|
||||||
language,
|
|
||||||
stroke_width,
|
|
||||||
__internal__=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
def multiline_textsize(
|
def multiline_textsize(
|
||||||
self,
|
self,
|
||||||
text,
|
text,
|
||||||
|
@ -619,25 +621,24 @@ class ImageDraw:
|
||||||
features=None,
|
features=None,
|
||||||
language=None,
|
language=None,
|
||||||
stroke_width=0,
|
stroke_width=0,
|
||||||
__internal__=False,
|
|
||||||
):
|
):
|
||||||
if not __internal__:
|
deprecate("multiline_textsize", 10, "multiline_textbbox")
|
||||||
deprecate("multiline_textsize", 10, "multiline_textbbox")
|
|
||||||
max_width = 0
|
max_width = 0
|
||||||
lines = self._multiline_split(text)
|
lines = self._multiline_split(text)
|
||||||
line_spacing = self._multiline_spacing(font, spacing, stroke_width)
|
line_spacing = self._multiline_spacing(font, spacing, stroke_width)
|
||||||
for line in lines:
|
with warnings.catch_warnings():
|
||||||
line_width, line_height = self.textsize(
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
line,
|
for line in lines:
|
||||||
font,
|
line_width, line_height = self.textsize(
|
||||||
spacing,
|
line,
|
||||||
direction,
|
font,
|
||||||
features,
|
spacing,
|
||||||
language,
|
direction,
|
||||||
stroke_width,
|
features,
|
||||||
__internal__=True,
|
language,
|
||||||
)
|
stroke_width,
|
||||||
max_width = max(max_width, line_width)
|
)
|
||||||
|
max_width = max(max_width, line_width)
|
||||||
return max_width, len(lines) * line_spacing - spacing
|
return max_width, len(lines) * line_spacing - spacing
|
||||||
|
|
||||||
def textlength(
|
def textlength(
|
||||||
|
@ -662,14 +663,15 @@ class ImageDraw:
|
||||||
return font.getlength(text, mode, direction, features, language)
|
return font.getlength(text, mode, direction, features, language)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
deprecate("textlength support for fonts without getlength", 10)
|
deprecate("textlength support for fonts without getlength", 10)
|
||||||
size = self.textsize(
|
with warnings.catch_warnings():
|
||||||
text,
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
font,
|
size = self.textsize(
|
||||||
direction=direction,
|
text,
|
||||||
features=features,
|
font,
|
||||||
language=language,
|
direction=direction,
|
||||||
__internal__=True,
|
features=features,
|
||||||
)
|
language=language,
|
||||||
|
)
|
||||||
if direction == "ttb":
|
if direction == "ttb":
|
||||||
return size[1]
|
return size[1]
|
||||||
return size[0]
|
return size[0]
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
import warnings
|
||||||
|
|
||||||
from . import Image, ImageColor, ImageDraw, ImageFont, ImagePath
|
from . import Image, ImageColor, ImageDraw, ImageFont, ImagePath
|
||||||
from ._deprecate import deprecate
|
from ._deprecate import deprecate
|
||||||
|
|
||||||
|
@ -180,7 +182,9 @@ class Draw:
|
||||||
.. seealso:: :py:meth:`PIL.ImageDraw.ImageDraw.textsize`
|
.. seealso:: :py:meth:`PIL.ImageDraw.ImageDraw.textsize`
|
||||||
"""
|
"""
|
||||||
deprecate("textsize", 10, "textbbox or textlength")
|
deprecate("textsize", 10, "textbbox or textlength")
|
||||||
return self.draw.textsize(text, font=font.font, __internal__=True)
|
with warnings.catch_warnings():
|
||||||
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
|
return self.draw.textsize(text, font=font.font)
|
||||||
|
|
||||||
def textbbox(self, xy, text, font):
|
def textbbox(self, xy, text, font):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -147,8 +147,7 @@ class ImageFont:
|
||||||
|
|
||||||
:return: (width, height)
|
:return: (width, height)
|
||||||
"""
|
"""
|
||||||
if not kwargs.get("__internal__"):
|
deprecate("getsize", 10, "getbbox or getlength")
|
||||||
deprecate("getsize", 10, "getbbox or getlength")
|
|
||||||
return self.font.getsize(text)
|
return self.font.getsize(text)
|
||||||
|
|
||||||
def getmask(self, text, mode="", *args, **kwargs):
|
def getmask(self, text, mode="", *args, **kwargs):
|
||||||
|
@ -425,7 +424,6 @@ class FreeTypeFont:
|
||||||
features=None,
|
features=None,
|
||||||
language=None,
|
language=None,
|
||||||
stroke_width=0,
|
stroke_width=0,
|
||||||
__internal__=False,
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
.. deprecated:: 9.2.0
|
.. deprecated:: 9.2.0
|
||||||
|
@ -479,8 +477,7 @@ class FreeTypeFont:
|
||||||
|
|
||||||
:return: (width, height)
|
:return: (width, height)
|
||||||
"""
|
"""
|
||||||
if not __internal__:
|
deprecate("getsize", 10, "getbbox or getlength")
|
||||||
deprecate("getsize", 10, "getbbox or getlength")
|
|
||||||
# vertical offset is added for historical reasons
|
# vertical offset is added for historical reasons
|
||||||
# see https://github.com/python-pillow/Pillow/pull/4910#discussion_r486682929
|
# see https://github.com/python-pillow/Pillow/pull/4910#discussion_r486682929
|
||||||
size, offset = self.font.getsize(text, "L", direction, features, language)
|
size, offset = self.font.getsize(text, "L", direction, features, language)
|
||||||
|
@ -545,14 +542,14 @@ class FreeTypeFont:
|
||||||
deprecate("getsize_multiline", 10, "ImageDraw.multiline_textbbox")
|
deprecate("getsize_multiline", 10, "ImageDraw.multiline_textbbox")
|
||||||
max_width = 0
|
max_width = 0
|
||||||
lines = self._multiline_split(text)
|
lines = self._multiline_split(text)
|
||||||
line_spacing = (
|
with warnings.catch_warnings():
|
||||||
self.getsize("A", stroke_width=stroke_width, __internal__=True)[1] + spacing
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
)
|
line_spacing = self.getsize("A", stroke_width=stroke_width)[1] + spacing
|
||||||
for line in lines:
|
for line in lines:
|
||||||
line_width, line_height = self.getsize(
|
line_width, line_height = self.getsize(
|
||||||
line, direction, features, language, stroke_width, __internal__=True
|
line, direction, features, language, stroke_width
|
||||||
)
|
)
|
||||||
max_width = max(max_width, line_width)
|
max_width = max(max_width, line_width)
|
||||||
|
|
||||||
return max_width, len(lines) * line_spacing - spacing
|
return max_width, len(lines) * line_spacing - spacing
|
||||||
|
|
||||||
|
@ -856,11 +853,9 @@ class TransposedFont:
|
||||||
|
|
||||||
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")
|
||||||
deprecate("getsize", 10, "getbbox or getlength")
|
with warnings.catch_warnings():
|
||||||
try:
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
w, h = self.font.getsize(text, __internal__=True)
|
|
||||||
except TypeError:
|
|
||||||
w, h = self.font.getsize(text)
|
w, h = self.font.getsize(text)
|
||||||
if self.orientation in (Image.Transpose.ROTATE_90, Image.Transpose.ROTATE_270):
|
if self.orientation in (Image.Transpose.ROTATE_90, Image.Transpose.ROTATE_270):
|
||||||
return h, w
|
return h, w
|
||||||
|
|
Loading…
Reference in New Issue
Block a user