Skip to content
Closed
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
1 change: 1 addition & 0 deletions buildconfig/stubs/pygame/font.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ class Font:
def set_direction(self, direction: int) -> None: ...
def get_point_size(self) -> int: ...
def set_point_size(self, val: int, /) -> None: ...
def set_kerning(self, value: bool, /) -> None: ...

FontType = Font
13 changes: 13 additions & 0 deletions docs/reST/ref/font.rst
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,19 @@ solves no longer exists, it will likely be removed in the future.

.. ## font.set_direction ##

.. method:: set_kerning

| :sl:`set whether kerning is enabled for font rendering or not`
| :sg:`set_kerning(bool, /) -> None`

Turns 'kerning' on and off when rendering text with this font. Kerning is a spacing adjustment between
certain letter pairs e.g. 'W' & 'o'. Kerning information is built into fonts. This setting
defaults to True.

.. versionadded:: 2.5.0

.. ## font.set_kerning ##

.. ## pygame.font.Font ##

.. ## pygame.font ##
1 change: 1 addition & 0 deletions src_c/doc/font_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@
#define DOC_FONT_FONT_GETDESCENT "get_descent() -> int\nget the descent of the font"
#define DOC_FONT_FONT_SETSCRIPT "set_script(str, /) -> None\nset the script code for text shaping"
#define DOC_FONT_FONT_SETDIRECTION "set_direction(direction) -> None\nset the script direction for text shaping"
#define DOC_FONT_FONT_SETKERNING "set_kerning(bool, /) -> None\nset whether kerning is enabled for font rendering or not"
18 changes: 18 additions & 0 deletions src_c/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,23 @@ font_get_ptsize(PyObject *self, PyObject *args)
#endif
}

static PyObject *
font_set_kerning(PyObject *self, PyObject *arg)
{
if (!PgFont_GenerationCheck(self)) {
return RAISE_FONT_QUIT_ERROR();
}
TTF_Font *font = PyFont_AsFont(self);
int val = PyObject_IsTrue(arg);
if (val == -1) {
return NULL;
}

TTF_SetFontKerning(font, val);

Py_RETURN_NONE;
}

static PyObject *
font_set_ptsize(PyObject *self, PyObject *arg)
{
Expand Down Expand Up @@ -1084,6 +1101,7 @@ static PyMethodDef font_methods[] = {
{"set_script", font_set_script, METH_O, DOC_FONT_FONT_SETSCRIPT},
{"set_direction", (PyCFunction)font_set_direction,
METH_VARARGS | METH_KEYWORDS, DOC_FONT_FONT_SETDIRECTION},
{"set_kerning", font_set_kerning, METH_O, DOC_FONT_FONT_SETKERNING},
{NULL, NULL, 0, NULL}};

/*font object internals*/
Expand Down
1 change: 1 addition & 0 deletions test/font_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ def test_font_method_should_raise_exception_after_quit(self):
("size", ("any text",)),
("set_script", ("is it other text",)),
("set_direction", ("is it text",)),
("set_kerning", (False,)),
]
version = pygame.font.get_sdl_ttf_version()
if version >= (2, 0, 18):
Expand Down