diff --git a/manimpango/register_font.pxd b/manimpango/register_font.pxd index ce3924a9..b9b64c61 100644 --- a/manimpango/register_font.pxd +++ b/manimpango/register_font.pxd @@ -1,4 +1,12 @@ +from libc.stddef cimport wchar_t + +cdef extern from "Python.h": + wchar_t* PyUnicode_AsWideCharString( + object unicode, + Py_ssize_t* size + ) + cdef extern from "fontconfig/fontconfig.h": ctypedef int FcBool ctypedef struct FcConfig: @@ -13,8 +21,7 @@ cdef extern from "fontconfig/fontconfig.h": # Windows and macOS specific API's IF UNAME_SYSNAME == "Windows": cdef extern from "windows.h": - ctypedef Py_UNICODE WCHAR - ctypedef const WCHAR* LPCWSTR + ctypedef const wchar_t* LPCWSTR ctypedef enum DWORD: FR_PRIVATE int AddFontResourceExW( diff --git a/manimpango/register_font.pyx b/manimpango/register_font.pyx index bb55cb79..5e121f04 100644 --- a/manimpango/register_font.pyx +++ b/manimpango/register_font.pyx @@ -97,8 +97,9 @@ ELIF UNAME_SYSNAME == "Windows": a=Path(font_path) assert a.exists(), f"font doesn't exist at {a.absolute()}" font_path = os.fspath(a.absolute()) + cdef LPCWSTR wchar_path = PyUnicode_AsWideCharString(font_path, NULL) fontAddStatus = AddFontResourceExW( - font_path, + wchar_path, FR_PRIVATE, 0 ) @@ -129,8 +130,9 @@ ELIF UNAME_SYSNAME == "Windows": a=Path(font_path) assert a.exists(), f"font doesn't exist at {a.absolute()}" font_path = os.fspath(a.absolute()) + cdef LPCWSTR wchar_path = PyUnicode_AsWideCharString(font_path, NULL) return RemoveFontResourceExW( - font_path, + wchar_path, FR_PRIVATE, 0 )