Document ImageDraw attributes

This commit is contained in:
nulano 2022-08-25 00:21:55 +02:00
parent cb6c94123e
commit ced381edaa
No known key found for this signature in database
GPG Key ID: B650CDF63B705766
2 changed files with 47 additions and 6 deletions

View File

@ -139,17 +139,50 @@ Functions
must be the same as the image mode. If omitted, the mode
defaults to the mode of the image.
Attributes
----------
.. py:attribute:: ImageDraw.fill
:type: bool
:value: False
Selects whether :py:attr:`ImageDraw.ink` should be used as a fill or outline color.
.. py:attribute:: ImageDraw.font
The current default font.
Can be set per instance::
from PIL import ImageDraw, ImageFont
draw = ImageDraw.Draw(image)
draw.font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")
Or globally for all future ImageDraw instances::
from PIL import ImageDraw, ImageFont
ImageDraw.ImageDraw.font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")
.. py:attribute:: ImageDraw.fontmode
The current font drawing mode.
Set to ``"1"`` to disable antialiasing or ``"L"`` to enable it.
.. py:attribute:: ImageDraw.ink
:type: int
The internal representation of the current default color.
Methods
-------
.. py:method:: ImageDraw.getfont()
Get the current default font.
Get the current default font, :py:attr:`ImageDraw.font`.
To set the default font for all future ImageDraw instances::
from PIL import ImageDraw, ImageFont
ImageDraw.ImageDraw.font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")
If the current default font is ``None``,
it is initialized with :py:func:`.ImageFont.load_default`.
:returns: An image font.

View File

@ -87,17 +87,25 @@ class ImageDraw:
self.fontmode = "1"
else:
self.fontmode = "L" # aliasing is okay for other modes
self.fill = 0
self.fill = False
def getfont(self):
"""
Get the current default font.
To set the default font for this ImageDraw instance::
from PIL import ImageDraw, ImageFont
draw.font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")
To set the default font for all future ImageDraw instances::
from PIL import ImageDraw, ImageFont
ImageDraw.ImageDraw.font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")
If the current default font is ``None``,
it is initialized with ``ImageFont.load_default()``.
:returns: An image font."""
if not self.font:
# FIXME: should add a font repository