From e3b5b0b177dcdf4be3cdd4169010cad2e2bdd574 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Fri, 14 Feb 2020 20:35:42 -0500 Subject: [PATCH] [Part]Handle CJK font names for ShapeString --- src/Mod/Part/App/AppPartPy.cpp | 15 +++++++++++++++ src/Mod/Part/App/FT2FC.cpp | 24 +++++++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index ac8ca05e82..748735779c 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -89,6 +89,9 @@ # include #endif +#include +#include + #include #include @@ -1802,7 +1805,19 @@ private: try { if (useFontSpec) { +#ifdef FC_OS_WIN32 +// Windows doesn't do Utf8 by default and FreeType doesn't do wchar. +// this is a hacky work around. +// copy fontspec to Ascii temp name + std::string tempFile = Base::FileInfo::getTempFileName(); //utf8/ascii + Base::FileInfo fiIn(fontspec); + fiIn.copyTo(tempFile.c_str()); + CharList = FT2FC(unichars,pysize,tempFile.c_str(),height,track); + Base::FileInfo fiTemp(tempFile); + fiTemp.deleteFile(); +#else CharList = FT2FC(unichars,pysize,fontspec,height,track); +#endif } else { CharList = FT2FC(unichars,pysize,dir,fontfile,height,track); diff --git a/src/Mod/Part/App/FT2FC.cpp b/src/Mod/Part/App/FT2FC.cpp index 830d61be4c..c8e9a4bd11 100644 --- a/src/Mod/Part/App/FT2FC.cpp +++ b/src/Mod/Part/App/FT2FC.cpp @@ -120,13 +120,23 @@ PyObject* FT2FC(const Py_UNICODE *PyUString, throw std::runtime_error(ErrorMsg.str()); } - // FT does not return an error if font file not found? - std::ifstream is; - is.open (FontSpec); - if (!is) { - ErrorMsg << "Font file not found: " << FontSpec; - throw std::runtime_error(ErrorMsg.str()); - } + +#ifdef FC_OS_WIN32 + Base::FileInfo fi(FontSpec); + if (!fi.isReadable()) { + ErrorMsg << "Font file not found (Win): " << FontSpec; + throw std::runtime_error(ErrorMsg.str()); + } +#else + // FT does not return an error if font file not found? + std::ifstream is; + is.open (FontSpec); + if (!is) { + ErrorMsg << "Font file not found: " << FontSpec; + throw std::runtime_error(ErrorMsg.str()); + } +#endif + error = FT_New_Face(FTLib,FontSpec,FaceIndex, &FTFont); if(error) {