Skip to content

Commit c2b985e

Browse files
authored
Merge pull request #82 from ManimCommunity/some-fixes
Don't use copy module in `list_fonts()`
2 parents 2ab665d + 3fc04fb commit c2b985e

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

manimpango/register_font.pyx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from pathlib import Path
22
from pango cimport *
3-
import copy
43
import os
54

65
cpdef bint fc_register_font(str font_path):
@@ -211,7 +210,7 @@ cpdef list list_fonts():
211210
:class:`list` :
212211
List of fonts sorted alphabetically.
213212
"""
214-
cdef PangoFontMap* fontmap=pango_cairo_font_map_new()
213+
cdef PangoFontMap* fontmap = pango_cairo_font_map_new()
215214
if fontmap == NULL:
216215
raise MemoryError("Pango.FontMap can't be created.")
217216
cdef int n_families=0
@@ -221,16 +220,16 @@ cpdef list list_fonts():
221220
&families,
222221
&n_families
223222
)
224-
if families is NULL or n_families==0:
223+
if families is NULL or n_families == 0:
225224
raise MemoryError("Pango returned unexpected length on families.")
226-
family_list=[]
225+
family_list = []
227226
for i in range(n_families):
228-
name = copy.deepcopy(pango_font_family_get_name(families[i]).decode('utf-8'))
227+
name = pango_font_family_get_name(families[i])
229228
# according to pango's docs, the `char *` returned from
230229
# `pango_font_family_get_name`is owned by pango, and python
231-
# shouldn't interfere with it. So, rather we are making a
232-
# deepcopy so that we don't worry about it.
233-
family_list.append(name)
230+
# shouldn't interfere with it. I hope Cython handles it.
231+
# https://cython.readthedocs.io/en/stable/src/tutorial/strings.html#dealing-with-const
232+
family_list.append(name.decode())
234233
g_free(families)
235234
g_object_unref(fontmap)
236235
family_list.sort()

0 commit comments

Comments
 (0)