mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 21:50:54 +03:00
implemented language parameter for multiline ImageDraw methods, updated release notes
This commit is contained in:
parent
9f390a5192
commit
8bd4bbb808
|
@ -297,7 +297,7 @@ Methods
|
||||||
|
|
||||||
.. versionadded:: 6.0.0
|
.. versionadded:: 6.0.0
|
||||||
|
|
||||||
.. py:method:: PIL.ImageDraw.ImageDraw.multiline_text(xy, text, fill=None, font=None, anchor=None, spacing=0, align="left", direction=None, features=None)
|
.. py:method:: PIL.ImageDraw.ImageDraw.multiline_text(xy, text, fill=None, font=None, anchor=None, spacing=0, align="left", direction=None, features=None, language=None)
|
||||||
|
|
||||||
Draws the string at the given position.
|
Draws the string at the given position.
|
||||||
|
|
||||||
|
@ -326,6 +326,16 @@ Methods
|
||||||
|
|
||||||
.. versionadded:: 4.2.0
|
.. versionadded:: 4.2.0
|
||||||
|
|
||||||
|
:param language: Language of the text. Different languages may use
|
||||||
|
different glyph shapes or ligatures. This parameter tells
|
||||||
|
the font which language the text is in, and to apply the
|
||||||
|
correct substitutions as appropriate, if available.
|
||||||
|
It should be a `BCP47 language code
|
||||||
|
<https://www.w3.org/International/articles/language-tags/>`
|
||||||
|
Requires libraqm.
|
||||||
|
|
||||||
|
.. versionadded:: 6.0.0
|
||||||
|
|
||||||
.. py:method:: PIL.ImageDraw.ImageDraw.textsize(text, font=None, spacing=4, direction=None, features=None, language=None)
|
.. py:method:: PIL.ImageDraw.ImageDraw.textsize(text, font=None, spacing=4, direction=None, features=None, language=None)
|
||||||
|
|
||||||
Return the size of the given string, in pixels.
|
Return the size of the given string, in pixels.
|
||||||
|
@ -362,7 +372,7 @@ Methods
|
||||||
|
|
||||||
.. versionadded:: 6.0.0
|
.. versionadded:: 6.0.0
|
||||||
|
|
||||||
.. py:method:: PIL.ImageDraw.ImageDraw.multiline_textsize(text, font=None, spacing=4, direction=None, features=None)
|
.. py:method:: PIL.ImageDraw.ImageDraw.multiline_textsize(text, font=None, spacing=4, direction=None, features=None, language=None)
|
||||||
|
|
||||||
Return the size of the given string, in pixels.
|
Return the size of the given string, in pixels.
|
||||||
|
|
||||||
|
@ -388,6 +398,16 @@ Methods
|
||||||
|
|
||||||
.. versionadded:: 4.2.0
|
.. versionadded:: 4.2.0
|
||||||
|
|
||||||
|
:param language: Language of the text. Different languages may use
|
||||||
|
different glyph shapes or ligatures. This parameter tells
|
||||||
|
the font which language the text is in, and to apply the
|
||||||
|
correct substitutions as appropriate, if available.
|
||||||
|
It should be a `BCP47 language code
|
||||||
|
<https://www.w3.org/International/articles/language-tags/>`
|
||||||
|
Requires libraqm.
|
||||||
|
|
||||||
|
.. versionadded:: 6.0.0
|
||||||
|
|
||||||
.. py:method:: PIL.ImageDraw.getdraw(im=None, hints=None)
|
.. py:method:: PIL.ImageDraw.getdraw(im=None, hints=None)
|
||||||
|
|
||||||
.. warning:: This method is experimental.
|
.. warning:: This method is experimental.
|
||||||
|
|
|
@ -99,6 +99,21 @@ version.
|
||||||
|
|
||||||
Use ``PIL.__version__`` instead.
|
Use ``PIL.__version__`` instead.
|
||||||
|
|
||||||
|
New ``language`` parameter
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Text rendering functions now accept a ``language`` parameter, to request language-specific glyphs and ligatures from the font
|
||||||
|
|
||||||
|
The following functions accept the new parameter:
|
||||||
|
|
||||||
|
* ``PIL.ImageDraw.ImageDraw.text()``
|
||||||
|
* ``PIL.ImageDraw.ImageDraw.multiline_text()``
|
||||||
|
* ``PIL.ImageDraw.ImageDraw.textsize()``
|
||||||
|
* ``PIL.ImageDraw.ImageDraw.multiline_textsize()``
|
||||||
|
* ``PIL.ImageFont.ImageFont.getsize()``
|
||||||
|
* ``PIL.ImageFont.ImageFont.getsize_multiline()``
|
||||||
|
* ``PIL.ImageFont.ImageFont.getmask()``
|
||||||
|
|
||||||
API Additions
|
API Additions
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
|
|
@ -282,13 +282,17 @@ class ImageDraw(object):
|
||||||
self.draw.draw_bitmap(xy, mask, ink)
|
self.draw.draw_bitmap(xy, mask, ink)
|
||||||
|
|
||||||
def multiline_text(self, xy, text, fill=None, font=None, anchor=None,
|
def multiline_text(self, xy, text, fill=None, font=None, anchor=None,
|
||||||
spacing=4, align="left", direction=None, features=None):
|
spacing=4, align="left", direction=None, features=None,
|
||||||
|
language=None):
|
||||||
widths = []
|
widths = []
|
||||||
max_width = 0
|
max_width = 0
|
||||||
lines = self._multiline_split(text)
|
lines = self._multiline_split(text)
|
||||||
line_spacing = self.textsize('A', font=font)[1] + spacing
|
line_spacing = self.textsize('A', font=font)[1] + spacing
|
||||||
for line in lines:
|
for line in lines:
|
||||||
line_width, line_height = self.textsize(line, font)
|
line_width, line_height = self.textsize(line, font,
|
||||||
|
direction=direction,
|
||||||
|
features=features,
|
||||||
|
language=language)
|
||||||
widths.append(line_width)
|
widths.append(line_width)
|
||||||
max_width = max(max_width, line_width)
|
max_width = max(max_width, line_width)
|
||||||
left, top = xy
|
left, top = xy
|
||||||
|
@ -302,29 +306,30 @@ class ImageDraw(object):
|
||||||
else:
|
else:
|
||||||
raise ValueError('align must be "left", "center" or "right"')
|
raise ValueError('align must be "left", "center" or "right"')
|
||||||
self.text((left, top), line, fill, font, anchor,
|
self.text((left, top), line, fill, font, anchor,
|
||||||
direction=direction, features=features)
|
direction=direction, features=features, language=language)
|
||||||
top += line_spacing
|
top += line_spacing
|
||||||
left = xy[0]
|
left = xy[0]
|
||||||
|
|
||||||
def textsize(self, text, font=None, spacing=4, direction=None,
|
def textsize(self, text, font=None, spacing=4, direction=None,
|
||||||
features=None):
|
features=None, language=None):
|
||||||
"""Get the size of a given string, in pixels."""
|
"""Get the size of a given string, in pixels."""
|
||||||
if self._multiline_check(text):
|
if self._multiline_check(text):
|
||||||
return self.multiline_textsize(text, font, spacing,
|
return self.multiline_textsize(text, font, spacing,
|
||||||
direction, features)
|
direction, features, language)
|
||||||
|
|
||||||
if font is None:
|
if font is None:
|
||||||
font = self.getfont()
|
font = self.getfont()
|
||||||
return font.getsize(text, direction, features)
|
return font.getsize(text, direction, features, language)
|
||||||
|
|
||||||
def multiline_textsize(self, text, font=None, spacing=4, direction=None,
|
def multiline_textsize(self, text, font=None, spacing=4, direction=None,
|
||||||
features=None):
|
features=None, language=None):
|
||||||
max_width = 0
|
max_width = 0
|
||||||
lines = self._multiline_split(text)
|
lines = self._multiline_split(text)
|
||||||
line_spacing = self.textsize('A', font=font)[1] + spacing
|
line_spacing = self.textsize('A', font=font)[1] + spacing
|
||||||
for line in lines:
|
for line in lines:
|
||||||
line_width, line_height = self.textsize(line, font, spacing,
|
line_width, line_height = self.textsize(line, font, spacing,
|
||||||
direction, features)
|
direction, features,
|
||||||
|
language)
|
||||||
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user