sas*_*alm 3 c++ unicode freetype visual-studio
我有一个使用 freetype 的 MSVC 项目,现在我正在尝试将其移至 Unicode。但是 freetype 函数不接受文件路径的 LPCTSTR 参数,它们需要“const char*”。所以代码就像
WINDOWS_FONT WindowsFont;
// ....
FT_New_Face (pLibrary, WindowsFont.pszFileName, i, &face); // WindowsFont.pszFileName is LPTSTR
Run Code Online (Sandbox Code Playgroud)
曾经在项目是 ascii 时工作,但在 Unicode 时不再工作。有没有办法让 freetype 接受 Unicode 文件名,一些预处理器定义可能将其切换为 unicode?
C++ 标准 (2003) 中没有 wfopen。由于 freetype 是可移植的,它只使用 fopen,它只能接受 const char* 文件名。因此,要么将文件加载到内存(或内存映射它),然后使用 FT_New_Memory_Face 创建字体或将 wchar_t pszFileName 转换为 8 位编码,可能会因无法转换而丢失字符。
在 linux 上,您可以尝试使用setlocale
fopen 将接受 UTF8 字符串,将 wchar_t 字符串转换为 UTF8。但是在 Windows 上它不起作用。因此,要么将文件加载到内存中,要么将 pszFileName 转换为 8 位编码,然后将其传递给 FT_New_Face。