Skip to content

Add outline option for rendering fonts #2828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions buildconfig/stubs/pygame/font.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ class Font:
def point_size(self) -> int: ...
@point_size.setter
def point_size(self, value: int) -> None: ...
@property
def outline_width(self) -> int: ...
@outline_width.setter
def outline_width(self, value: int) -> None: ...
@property
def outline_color(self) -> ColorValue: ...
@outline_color.setter
def outline_color(self, value: ColorValue) -> None: ...
def __init__(self, filename: Optional[FileArg] = None, size: int = 20) -> None: ...
def render(
self,
Expand Down
24 changes: 24 additions & 0 deletions docs/reST/ref/font.rst
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,30 @@ solves no longer exists, it will likely be removed in the future.

.. ## Font.point_size ##

.. attribute:: outline_width
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outline_radius is a better name if you're already going to mention radius in the docs description.


| :sl:`Gets or sets the font's outline radius size`
| :sg:`outline_width -> int`

Gets or sets the radius size of the outline in pixels defaulting to 0.

If the value is set to 0, it shows no outline.

.. versionadded:: 2.5.0

.. ## Font.outline_width ##

.. attribute:: outline_color

| :sl:`Gets or sets the font's outline color`
| :sg:`outline_width -> RGB`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You say (0, 0, 0, 255), but that's RGBA.


Gets or sets the color of the outline defaulting to (0, 0, 0, 255)

.. versionadded:: 2.5.0

.. ## Font.outline_color ##

.. method:: render

| :sl:`draw text on a new Surface`
Expand Down
2 changes: 2 additions & 0 deletions src_c/doc/font_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#define DOC_FONT_FONT_STRIKETHROUGH "strikethrough -> bool\nGets or sets whether the font should be rendered with a strikethrough."
#define DOC_FONT_FONT_ALIGN "align -> int\nSet how rendered text is aligned when given a wrap length."
#define DOC_FONT_FONT_POINTSIZE "point_size -> int\nGets or sets the font's point size"
#define DOC_FONT_FONT_OUTLINEWIDTH "outline_width -> int\nGets or sets the font's outline radius size"
#define DOC_FONT_FONT_OUTLINECOLOR "outline_width -> RGB\nGets or sets the font's outline color"
#define DOC_FONT_FONT_RENDER "render(text, antialias, color, bgcolor=None, wraplength=0) -> Surface\ndraw text on a new Surface"
#define DOC_FONT_FONT_SIZE "size(text, /) -> (width, height)\ndetermine the amount of space needed to render text"
#define DOC_FONT_FONT_SETUNDERLINE "set_underline(bool, /) -> None\ncontrol if text is rendered with an underline"
Expand Down
Loading