@@ -517,6 +517,44 @@ text_layout(
517517 return count ;
518518}
519519
520+ static PyObject *
521+ font_hascharacters (FontObject * self , PyObject * args ) {
522+ int i ;
523+ char * buffer = NULL ;
524+ FT_ULong ch ;
525+ Py_ssize_t count ;
526+ FT_GlyphSlot glyph ;
527+ PyObject * string ;
528+
529+ if (!PyArg_ParseTuple (args , "O" , & string )) {
530+ return NULL ;
531+ }
532+
533+ if (PyUnicode_Check (string )) {
534+ count = PyUnicode_GET_LENGTH (string );
535+ } else if (PyBytes_Check (string )) {
536+ PyBytes_AsStringAndSize (string , & buffer , & count );
537+ } else {
538+ PyErr_SetString (PyExc_TypeError , "expected string or bytes" );
539+ return 0 ;
540+ }
541+ if (count == 0 ) {
542+ return Py_True ;
543+ }
544+
545+ for (i = 0 ; i < count ; i ++ ) {
546+ if (buffer ) {
547+ ch = buffer [i ];
548+ } else {
549+ ch = PyUnicode_READ_CHAR (string , i );
550+ }
551+ if (FT_Get_Char_Index (self -> face , ch ) == 0 ) {
552+ return Py_False ;
553+ }
554+ }
555+ return Py_True ;
556+ }
557+
520558static PyObject *
521559font_getlength (FontObject * self , PyObject * args ) {
522560 int length ; /* length along primary axis, in 26.6 precision */
@@ -1451,6 +1489,7 @@ static PyMethodDef font_methods[] = {
14511489 {"render" , (PyCFunction )font_render , METH_VARARGS },
14521490 {"getsize" , (PyCFunction )font_getsize , METH_VARARGS },
14531491 {"getlength" , (PyCFunction )font_getlength , METH_VARARGS },
1492+ {"hascharacters" , (PyCFunction )font_hascharacters , METH_VARARGS },
14541493#if FREETYPE_MAJOR > 2 || (FREETYPE_MAJOR == 2 && FREETYPE_MINOR > 9 ) || \
14551494 (FREETYPE_MAJOR == 2 && FREETYPE_MINOR == 9 && FREETYPE_PATCH == 1 )
14561495 {"getvarnames" , (PyCFunction )font_getvarnames , METH_NOARGS },
0 commit comments