1 cdef extern from "fontconfig/fontconfig.h" : 2 ctypedef struct FcPattern : 3 pass 4 ctypedef struct FcConfig : 5 pass 6 cdef enum FcResult '_FcResult' : 7 FcResultMatch = 0, FcResultNoMatch, FcResultTypeMismatch, FcResultNoId, 8 FcResultOutOfMemory 9 10 ctypedef char FcChar8 11 FcPattern *FcNameParse(FcChar8 *name) 12 FcPattern *FcFontMatch(FcConfig *config, FcPattern *match, FcResult *res) 13 FcResult FcPatternGetInteger(FcPattern *pattern, char *typeid, int index, int *res) 14 FcResult FcPatternGetString(FcPattern *pattern, char *typeid, int index, FcChar8 **res) 15 void FcPatternPrint(FcPattern *pattern) 16 void FcPatternDestroy(FcPattern *pattern) 17 18 FcConfig *FcConfigGetCurrent() 19 20 cdef class fcPattern : 21 cdef FcPattern *_pattern 22 23 def __init__(self, char *name) : 24 cdef FcPattern *temp 25 cdef FcResult res 26 27 temp = FcNameParse(<FcChar8 *>name) 28 self._pattern = FcFontMatch(FcConfigGetCurrent(), temp, &res) 29 if res != FcResultMatch : 30 print "Failed to match" + str(res) 31 self._pattern = <FcPattern *>0 32 33 def __destroy__(self) : 34 FcPatternDestroy(self._pattern) 35 36 def getInteger(self, char *typeid, int index) : 37 cdef int res 38 if self._pattern == <FcPattern *>0 or FcPatternGetInteger(self._pattern, typeid, index, &res) != FcResultMatch : return None 39 return res 40 41 def getString(self, char *typeid, int index) : 42 cdef FcChar8 *res 43 if self._pattern == <FcPattern *>0 or FcPatternGetString(self._pattern, typeid, index, &res) != FcResultMatch : return None 44 return <char *>res 45 46 def debugPrint(self) : 47 FcPatternPrint(self._pattern) 48