@@ -37,6 +37,14 @@ class FcFontSet(Structure):
3737 ]
3838
3939
40+ def string_to_cstring (string : str ) -> c_char_p :
41+ return c_char_p (bytes (ord (c ) for c in string ))
42+
43+
44+ FC_FONTFORMAT = string_to_cstring ("fontformat" )
45+ FC_FILE = string_to_cstring ("file" )
46+
47+
4048class LinuxFonts (SystemFonts ):
4149 _font_config = None
4250 VALID_FONT_FORMATS = [
@@ -57,17 +65,17 @@ def get_system_fonts_filename() -> Set[str]:
5765
5866 config = LinuxFonts ._font_config .FcInitLoadConfigAndFonts ()
5967 pat = LinuxFonts ._font_config .FcPatternCreate ()
60- os = LinuxFonts ._font_config .FcObjectSetBuild (b"file" , b"fontformat" , 0 )
61- fs = LinuxFonts ._font_config .FcFontList (config , pat , None )
68+ os = LinuxFonts ._font_config .FcObjectSetBuild (FC_FILE , FC_FONTFORMAT , 0 )
69+ fs = LinuxFonts ._font_config .FcFontList (config , pat , os )
6270
6371 for i in range (fs .contents .nfont ):
6472 font = fs .contents .fonts [i ]
6573 file_path_ptr = c_char_p ()
6674 font_format_ptr = c_char_p ()
6775
6876 if (
69- LinuxFonts ._font_config .FcPatternGetString (font , b"fontformat" , 0 , byref (font_format_ptr )) == FC_RESULT .FC_RESULT_MATCH
70- and LinuxFonts ._font_config .FcPatternGetString (font , b"file" , 0 , byref (file_path_ptr )) == FC_RESULT .FC_RESULT_MATCH
77+ LinuxFonts ._font_config .FcPatternGetString (font , FC_FONTFORMAT , 0 , byref (font_format_ptr )) == FC_RESULT .FC_RESULT_MATCH
78+ and LinuxFonts ._font_config .FcPatternGetString (font , FC_FILE , 0 , byref (file_path_ptr )) == FC_RESULT .FC_RESULT_MATCH
7179 ):
7280 font_format = FC_FONT_FORMAT (font_format_ptr .value )
7381
@@ -110,3 +118,19 @@ def _load_font_config_library():
110118 # https://www.freedesktop.org/software/fontconfig/fontconfig-devel/fcpatternget-type.html
111119 LinuxFonts ._font_config .FcPatternGetString .restype = FC_RESULT
112120 LinuxFonts ._font_config .FcPatternGetString .argtypes = [c_void_p , c_char_p , c_int , POINTER (c_char_p )]
121+
122+ # https://www.freedesktop.org/software/fontconfig/fontconfig-devel/fcconfigdestroy.html
123+ LinuxFonts ._font_config .FcConfigDestroy .restype = None
124+ LinuxFonts ._font_config .FcConfigDestroy .argtypes = [c_void_p ]
125+
126+ # https://www.freedesktop.org/software/fontconfig/fontconfig-devel/fcpatterndestroy.html
127+ LinuxFonts ._font_config .FcPatternDestroy .restype = None
128+ LinuxFonts ._font_config .FcPatternDestroy .argtypes = [c_void_p ]
129+
130+ # https://www.freedesktop.org/software/fontconfig/fontconfig-devel/fcobjectsetdestroy.html
131+ LinuxFonts ._font_config .FcObjectSetDestroy .restype = None
132+ LinuxFonts ._font_config .FcObjectSetDestroy .argtypes = [c_void_p ]
133+
134+ # https://www.freedesktop.org/software/fontconfig/fontconfig-devel/fcfontsetdestroy.html
135+ LinuxFonts ._font_config .FcFontSetDestroy .restype = None
136+ LinuxFonts ._font_config .FcFontSetDestroy .argtypes = [c_void_p ]
0 commit comments