Skip to content

Commit 5e02e19

Browse files
committed
Font and Freetype: return empty string if the style name is not defined by the library.
1 parent ddfa563 commit 5e02e19

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

docs/reST/ref/font.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ solves no longer exists, it will likely be removed in the future.
216216
| :sl:`Gets the font's style_name.`
217217
| :sg:`style_name -> str`
218218
219-
Read only. Returns the font's style name. Style names are arbitrary, here are some examples:
219+
Read only. Returns the font's style name. Style names are arbitrary, can be an empty string.
220+
Here are some examples:
220221

221222
'Black', 'Bold', 'Bold Italic', 'BoldOblique', 'Book', 'BookOblique', 'Condensed', 'Condensed Oblique',
222223
'ExtraLight', 'Italic', 'Light', 'LightOblique', 'Medium', 'MediumOblique', 'Oblique', 'Regular',

docs/reST/ref/freetype.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ loaded. This module must be imported explicitly to be used. ::
229229
| :sl:`Gets the font's style_name.`
230230
| :sg:`style_name -> str`
231231
232-
Read only. Returns the font's style name. Style names are arbitrary, here are some examples:
232+
Read only. Returns the font's style name. Style names are arbitrary, can be an empty string.
233+
Here are some examples:
233234

234235
'Black', 'Bold', 'Bold Italic', 'BoldOblique', 'Book', 'BookOblique', 'Condensed', 'Condensed Oblique',
235236
'ExtraLight', 'Italic', 'Light', 'LightOblique', 'Medium', 'MediumOblique', 'Oblique', 'Regular',

src_c/_freetype.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ _ftfont_getname(pgFontObject *self, void *closure)
10991099
{
11001100
if (pgFont_IS_ALIVE(self)) {
11011101
const char *name = _PGFT_Font_GetName(self->freetype, self);
1102-
return name ? PyUnicode_FromString(name) : NULL;
1102+
return PyUnicode_FromString(name ? name : "");
11031103
}
11041104

11051105
PyErr_SetString(PyExc_AttributeError, "<uninitialized Font object>");
@@ -1111,7 +1111,7 @@ _ftfont_getstylename(pgFontObject *self, void *closure)
11111111
{
11121112
if (pgFont_IS_ALIVE(self)) {
11131113
const char *stylename = _PGFT_Font_GetStyleName(self->freetype, self);
1114-
return stylename ? PyUnicode_FromString(stylename) : NULL;
1114+
return PyUnicode_FromString(stylename ? stylename : "");
11151115
}
11161116

11171117
PyErr_SetString(PyExc_AttributeError, "<uninitialized Font object>");

src_c/font.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,12 +662,7 @@ font_getter_name(PyObject *self, void *closure)
662662
TTF_Font *font = PyFont_AsFont(self);
663663
const char *font_name = TTF_FontFaceFamilyName(font);
664664

665-
if (font_name) {
666-
return PyUnicode_FromString(font_name);
667-
}
668-
else {
669-
return RAISE(pgExc_SDLError, TTF_GetError());
670-
}
665+
return PyUnicode_FromString(font_name ? font_name : "");
671666
}
672667

673668
static PyObject *
@@ -679,7 +674,7 @@ font_getter_style_name(PyObject *self, void *closure)
679674

680675
TTF_Font *font = PyFont_AsFont(self);
681676
const char *font_style_name = TTF_FontFaceStyleName(font);
682-
return PyUnicode_FromString(font_style_name);
677+
return PyUnicode_FromString(font_style_name ? font_style_name : "");
683678
}
684679

685680
static PyObject *

0 commit comments

Comments
 (0)