1443: Fix ShapeString user font selection on Windows

This commit is contained in:
WandererFan 2014-02-26 19:28:24 -05:00 committed by wmayer
parent a48ec3ce45
commit b3d1b7a2ea
5 changed files with 68 additions and 30 deletions

View File

@ -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 = []

View File

@ -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))

View File

@ -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");

View File

@ -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<TopoDS_Edge> 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());

View File

@ -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