diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 19879ad40..507fb6ece 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -4570,12 +4570,12 @@ class _ShapeString(_DraftObject): if obj.Placement: plm = obj.Placement # TODO: os.path.splitunc() for Win/Samba net files? - head, tail = os.path.splitdrive(obj.FontFile) # os.path.splitdrive() for Win - head, tail = os.path.split(tail) - head = head + '/' # os.split drops last '/' from head + #head, tail = os.path.splitdrive(obj.FontFile) # os.path.splitdrive() for Win + #head, tail = os.path.split(tail) + #head = head + '/' # os.split drops last '/' from head + print "_ShapeString FontFile: ", obj.FontFile CharList = Part.makeWireString(obj.String, - head, - tail, + obj.FontFile, obj.Size, obj.Tracking) SSChars = [] diff --git a/src/Mod/Draft/DraftGui.py b/src/Mod/Draft/DraftGui.py index 76485565a..e24baa06b 100644 --- a/src/Mod/Draft/DraftGui.py +++ b/src/Mod/Draft/DraftGui.py @@ -1073,7 +1073,7 @@ class DraftToolBar: dialogCaption, dialogDir, dialogFilter) - print fname + # print fname #fname = str(fname.toUtf8()) # QString to PyString fname = fname[0].decode("utf8") # print "debug: D_G DraftToolBar.pickFile type(fname): " str(type(fname)) diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index 9e0851069..6af124ecb 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -326,8 +326,10 @@ show(PyObject *self, PyObject *args) static PyObject * makeWireString(PyObject *self, PyObject *args) { PyObject *intext; - const char* dir; + const char* dir; const char* fontfile; + const char* fontspec; + bool useFontSpec = false; float height; int track = 0; @@ -336,35 +338,51 @@ static PyObject * makeWireString(PyObject *self, PyObject *args) PyObject *CharList; - if (!PyArg_ParseTuple(args, "Ossf|i", &intext, - &dir, - &fontfile, - &height, - &track)) { - Base::Console().Message("** makeWireString bad args.\n"); - return NULL; - } - + if (PyArg_ParseTuple(args, "Ossf|i", &intext, // compatibility with old version + &dir, + &fontfile, + &height, + &track)) { + Base::Console().Message("** makeWireString dir + font\n"); + useFontSpec = false; } + else { + PyErr_Clear(); + if (PyArg_ParseTuple(args, "Osf|i", &intext, + &fontspec, + &height, + &track)) { + Base::Console().Message("** makeWireString useFontSpec\n"); + useFontSpec = true; } + else { + Base::Console().Message("** makeWireString bad args.\n"); + return NULL; } + } + if (PyString_Check(intext)) { PyObject *p = Base::PyAsUnicodeObject(PyString_AsString(intext)); if (!p) { Base::Console().Message("** makeWireString can't convert PyString.\n"); return NULL; } - pysize = PyUnicode_GetSize(p); + pysize = PyUnicode_GetSize(p); unichars = PyUnicode_AS_UNICODE(p); } - else if (PyUnicode_Check(intext)) { - pysize = PyUnicode_GetSize(intext); + else if (PyUnicode_Check(intext)) { + pysize = PyUnicode_GetSize(intext); unichars = PyUnicode_AS_UNICODE(intext); } else { - Base::Console().Message("** makeWireString bad text parameter.\n"); + Base::Console().Message("** makeWireString bad text parameter.\n"); return NULL; } - try { - CharList = FT2FC(unichars,pysize,dir,fontfile,height,track); // get list of wire chars + try { + if (useFontSpec) { + Base::Console().Message("** makeWireString trying fontspec\n"); + CharList = FT2FC(unichars,pysize,fontspec,height,track); } + else { + Base::Console().Message("** makeWireString trying dir + file\n"); + CharList = FT2FC(unichars,pysize,dir,fontfile,height,track); } } catch (Standard_DomainError) { // Standard_DomainError is OCC error. PyErr_SetString(PyExc_Exception, "makeWireString failed - Standard_DomainError"); diff --git a/src/Mod/Part/App/FT2FC.cpp b/src/Mod/Part/App/FT2FC.cpp index f1986e3f7..673f14323 100644 --- a/src/Mod/Part/App/FT2FC.cpp +++ b/src/Mod/Part/App/FT2FC.cpp @@ -71,11 +71,24 @@ PyObject* getGlyphContours(FT_Face FTFont, UNICHAR currchar, int PenPos, float S FT_Vector getKerning(FT_Face FTFont, UNICHAR lc, UNICHAR rc); TopoShapeWirePy* edgesToWire(std::vector Edges); -// get string's wires (contours) in FC/OCC coords +// for compatibility with old version - separate path & filename PyObject* FT2FC(const Py_UNICODE *PyUString, const size_t length, const char *FontPath, const char *FontName, + const float stringheight, + const int tracking) { + std::string FontSpec; + std::string tmpPath = FontPath; // can't concat const char* + std::string tmpName = FontName; + FontSpec = tmpPath + tmpName; + return (FT2FC(PyUString,length,FontSpec.c_str(),stringheight,tracking)); +} + +// get string's wires (contours) in FC/OCC coords +PyObject* FT2FC(const Py_UNICODE *PyUString, + const size_t length, + const char *FontSpec, const float stringheight, // fc coords const int tracking) { // fc coords FT_Library FTLib; @@ -85,7 +98,7 @@ PyObject* FT2FC(const Py_UNICODE *PyUString, FT_Vector kern; FT_UInt FTLoadFlags = FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP; - std::string FontSpec; + //std::string FontSpec; std::stringstream ErrorMsg; float scalefactor; UNICHAR prevchar = 0, currchar = 0; @@ -100,20 +113,20 @@ PyObject* FT2FC(const Py_UNICODE *PyUString, throw std::runtime_error(ErrorMsg.str()); } - std::string tmpPath = FontPath; // can't concat const char* - std::string tmpName = FontName; - FontSpec = tmpPath + tmpName; + //std::string tmpPath = FontPath; // can't concat const char* + //std::string tmpName = FontName; + //FontSpec = tmpPath + tmpName; // FT does not return an error if font file not found? std::ifstream is; - is.open (FontSpec.c_str()); + is.open (FontSpec); if (!is) { ErrorMsg << "Font file not found: " << FontSpec; throw std::runtime_error(ErrorMsg.str()); } // maybe boost::filesystem::exists for x-platform?? - error = FT_New_Face(FTLib,FontSpec.c_str(),FaceIndex, &FTFont); + error = FT_New_Face(FTLib,FontSpec,FaceIndex, &FTFont); if(error) { ErrorMsg << "FT_New_Face failed: " << error; throw std::runtime_error(ErrorMsg.str()); diff --git a/src/Mod/Part/App/FT2FC.h b/src/Mod/Part/App/FT2FC.h index 20fda5705..aabcb3d1a 100644 --- a/src/Mod/Part/App/FT2FC.h +++ b/src/Mod/Part/App/FT2FC.h @@ -29,12 +29,19 @@ // Public header for FT2FC.cpp #ifndef FT2FC_H #define FT2FC_H -// public function +// public functions PyObject* FT2FC(const Py_UNICODE *unichars, const size_t length, const char *FontPath, const char *FontName, const float stringheight, const int tracking); + +PyObject* FT2FC(const Py_UNICODE *unichars, + const size_t length, + const char *FontSpec, + const float stringheight, + const int tracking); + #endif // FT2FC_H