Skip to content

Commit

Permalink
Stop using deprecated API: Py_UNICODE
Browse files Browse the repository at this point in the history
Py_UNICODE is to be removed in python 3.12
  • Loading branch information
naveen521kk committed Oct 2, 2023
1 parent ad3c441 commit 921c923
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 9 additions & 2 deletions manimpango/register_font.pxd
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions manimpango/register_font.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<bytes>font_path,
wchar_path,
FR_PRIVATE,
0
)
Expand Down Expand Up @@ -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(
<bytes>font_path,
wchar_path,
FR_PRIVATE,
0
)
Expand Down

0 comments on commit 921c923

Please sign in to comment.