@@ -309,15 +309,36 @@ solves no longer exists, it will likely be removed in the future.
309309
310310 .. attribute :: outline
311311
312- | :sl:`Gets or sets the font's outline value `
312+ | :sl:`Gets or sets the font's outline thickness (pixels) `
313313 | :sg:`outline -> int`
314314
315315 The outline value of the font.
316316
317317 When set to 0, the font will be drawn normally. When positive,
318- the text will be drawn as a hollow outline. This can be drawn
319- underneath unoutlined text to create a text outline effect. Larger values
320- produce a thicker outline. Negative values are not valid.
318+ the text will be drawn as a hollow outline. The outline grows in all
319+ directions a number of pixels equal to the value set. Negative values
320+ are not allowed.
321+
322+ This can be drawn underneath unoutlined text to create a text outline
323+ effect. For example: ::
324+
325+ def render_outlined(
326+ font: pygame.Font,
327+ text: str,
328+ text_color: pygame.typing.ColorLike,
329+ outline_color: pygame.typing.ColorLike,
330+ outline_width: int,
331+ ) -> pygame.Surface:
332+ old_outline = font.outline
333+ if old_outline != 0:
334+ font.outline = 0
335+ base_text_surf = font.render(text, True, text_color)
336+ font.outline = outline_width
337+ outlined_text_surf = font.render(text, True, outline_color)
338+
339+ outlined_text_surf.blit(base_text_surf, (outline_width, outline_width))
340+ font.outline = old_outline
341+ return outlined_text_surf
321342
322343 .. versionadded :: 2.5.6
323344
0 commit comments