mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 09:14:27 +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
|
||||
|
||||
.. 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.
|
||||
|
||||
|
@ -326,6 +326,16 @@ Methods
|
|||
|
||||
.. 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)
|
||||
|
||||
Return the size of the given string, in pixels.
|
||||
|
@ -362,7 +372,7 @@ Methods
|
|||
|
||||
.. 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.
|
||||
|
||||
|
@ -388,6 +398,16 @@ Methods
|
|||
|
||||
.. 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)
|
||||
|
||||
.. warning:: This method is experimental.
|
||||
|
|
|
@ -99,6 +99,21 @@ version.
|
|||
|
||||
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
|
||||
=============
|
||||
|
||||
|
|
|
@ -282,13 +282,17 @@ class ImageDraw(object):
|
|||
self.draw.draw_bitmap(xy, mask, ink)
|
||||
|
||||
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 = []
|
||||
max_width = 0
|
||||
lines = self._multiline_split(text)
|
||||
line_spacing = self.textsize('A', font=font)[1] + spacing
|
||||
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)
|
||||
max_width = max(max_width, line_width)
|
||||
left, top = xy
|
||||
|
@ -302,29 +306,30 @@ class ImageDraw(object):
|
|||
else:
|
||||
raise ValueError('align must be "left", "center" or "right"')
|
||||
self.text((left, top), line, fill, font, anchor,
|
||||
direction=direction, features=features)
|
||||
direction=direction, features=features, language=language)
|
||||
top += line_spacing
|
||||
left = xy[0]
|
||||
|
||||
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."""
|
||||
if self._multiline_check(text):
|
||||
return self.multiline_textsize(text, font, spacing,
|
||||
direction, features)
|
||||
direction, features, language)
|
||||
|
||||
if font is None:
|
||||
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,
|
||||
features=None):
|
||||
features=None, language=None):
|
||||
max_width = 0
|
||||
lines = self._multiline_split(text)
|
||||
line_spacing = self.textsize('A', font=font)[1] + spacing
|
||||
for line in lines:
|
||||
line_width, line_height = self.textsize(line, font, spacing,
|
||||
direction, features)
|
||||
direction, features,
|
||||
language)
|
||||
max_width = max(max_width, line_width)
|
||||
return max_width, len(lines)*line_spacing - spacing
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user