diff --git a/buildconfig/stubs/pygame/font.pyi b/buildconfig/stubs/pygame/font.pyi index 683a28ef2b..51a3ee20e4 100644 --- a/buildconfig/stubs/pygame/font.pyi +++ b/buildconfig/stubs/pygame/font.pyi @@ -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 diff --git a/docs/reST/ref/font.rst b/docs/reST/ref/font.rst index 644a3b52b2..3c43bb3193 100644 --- a/docs/reST/ref/font.rst +++ b/docs/reST/ref/font.rst @@ -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 ## diff --git a/src_c/doc/font_doc.h b/src_c/doc/font_doc.h index 4ac4af922c..34c682864b 100644 --- a/src_c/doc/font_doc.h +++ b/src_c/doc/font_doc.h @@ -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" diff --git a/src_c/font.c b/src_c/font.c index 94b50da68a..aab791cb91 100644 --- a/src_c/font.c +++ b/src_c/font.c @@ -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) { @@ -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*/ diff --git a/test/font_test.py b/test/font_test.py index ffc9e5024c..16419b26b3 100644 --- a/test/font_test.py +++ b/test/font_test.py @@ -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):