Skip to content

Commit

Permalink
Merge pull request #6533 from nulano/document_imagedraw_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 25, 2022
2 parents f8b7464 + ced381e commit 7a06bc6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
43 changes: 38 additions & 5 deletions docs/reference/ImageDraw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,51 @@ Functions
must be the same as the image mode. If omitted, the mode
defaults to the mode of the image.

Methods
-------
Attributes
----------

.. py:method:: ImageDraw.getfont()
.. 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
Get the current default font.
The current default font.

To set the default font for all future ImageDraw instances::
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, :py:attr:`ImageDraw.font`.

If the current default font is ``None``,
it is initialized with :py:func:`.ImageFont.load_default`.

:returns: An image font.

.. py:method:: ImageDraw.arc(xy, start, end, fill=None, width=0)
Expand Down
10 changes: 9 additions & 1 deletion src/PIL/ImageDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,25 @@ def __init__(self, im, mode=None):
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
Expand Down

0 comments on commit 7a06bc6

Please sign in to comment.