Skip to content

Commit bb83234

Browse files
committed
Deduplicated font outline getter and setter logic.
1 parent dba6448 commit bb83234

File tree

1 file changed

+7
-28
lines changed

1 file changed

+7
-28
lines changed

src_c/font.c

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -954,41 +954,20 @@ font_setter_outline(PyObject *self, PyObject *value, void *closure)
954954
static PyObject *
955955
font_get_outline(PyObject *self, PyObject *_null)
956956
{
957-
if (!PgFont_GenerationCheck(self)) {
958-
return RAISE_FONT_QUIT_ERROR();
959-
}
960-
#if SDL_TTF_VERSION_ATLEAST(2, 0, 12)
961-
TTF_Font *font = PyFont_AsFont(self);
962-
return PyLong_FromLong(TTF_GetFontOutline(font));
963-
#else
964-
return RAISE(pgExc_SDLError,
965-
"pygame.font not compiled with a new enough SDL_ttf version. "
966-
"Needs SDL_ttf 2.0.12 or above.");
967-
#endif
957+
/* logic is identical to the getter, aside from the closure in the signature */
958+
return font_getter_outline(self, NULL);
968959
}
969960

970961
static PyObject *
971962
font_set_outline(PyObject *self, PyObject *arg)
972963
{
973-
if (!PgFont_GenerationCheck(self)) {
974-
return RAISE_FONT_QUIT_ERROR();
975-
}
976-
#if SDL_TTF_VERSION_ATLEAST(2, 0, 12)
977-
TTF_Font *font = PyFont_AsFont(self);
978-
long val = PyLong_AsLong(arg);
979-
if (val == -1 && PyErr_Occurred()) {
964+
/* logic is identical to the setter, but we need to massage the return type
965+
from int to PyObject*) */
966+
if(font_setter_outline(self, arg, NULL) < 0)
967+
{
980968
return NULL;
981969
}
982-
if (val < 0) {
983-
return RAISE(PyExc_ValueError, "outline must be >= 0");
984-
}
985-
TTF_SetFontOutline(font, (int)val);
986-
Py_RETURN_NONE;
987-
#else
988-
return RAISE(pgExc_SDLError,
989-
"pygame.font not compiled with a new enough SDL_ttf version. "
990-
"Needs SDL_ttf 2.0.12 or above.");
991-
#endif
970+
return Py_None;
992971
}
993972

994973
static PyObject *

0 commit comments

Comments
 (0)