From c941e458c4e49cc67ebf92d1695063c87dab3870 Mon Sep 17 00:00:00 2001 From: HyeokSuLee Date: Fri, 3 May 2024 19:11:10 +0900 Subject: [PATCH] Support nonASCII character filename on Windows os --- ttf2mesh.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ttf2mesh.c b/ttf2mesh.c index 9269ab3..8ce6557 100644 --- a/ttf2mesh.c +++ b/ttf2mesh.c @@ -1756,7 +1756,19 @@ int ttf_load_from_file(const char *filename, ttf_t **output, bool headers_only) *output = NULL; /* open file and get it size */ +#ifdef _WIN32 + // Convert the filename to wide-character string + int wlen = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0); + wchar_t *wfilename = (wchar_t *)malloc(wlen * sizeof(wchar_t)); + MultiByteToWideChar(CP_UTF8, 0, filename, -1, wfilename, wlen); + + // Open the file using wide-character function + f = _wfopen(wfilename, L"rb"); + free(wfilename); +#else + // Open the file using standard function f = fopen(filename, "rb"); +#endif check(f != NULL, TTF_ERR_OPEN); check(fread(&sfntVersion, 1, 4, f) == 4, TTF_ERR_FMT); check(big32toh(sfntVersion) == 0x00010000, TTF_ERR_FMT);