Combine UCS2 & UTF-8 logic.
This commit is contained in:
parent
9c5608d8d2
commit
6465e367eb
|
@ -118,11 +118,13 @@
|
||||||
#include "ImportStep.h"
|
#include "ImportStep.h"
|
||||||
#include "edgecluster.h"
|
#include "edgecluster.h"
|
||||||
|
|
||||||
|
//needed in AppPartPy???
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
#include FT_OUTLINE_H
|
#include FT_OUTLINE_H
|
||||||
#include FT_GLYPH_H
|
#include FT_GLYPH_H
|
||||||
#include FT_TYPES_H
|
#include FT_TYPES_H
|
||||||
|
//??
|
||||||
|
|
||||||
#include "FT2FC.h"
|
#include "FT2FC.h"
|
||||||
|
|
||||||
|
@ -325,19 +327,22 @@ static PyObject * makeWireString(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* dir;
|
const char* dir;
|
||||||
const char* fontfile;
|
const char* fontfile;
|
||||||
const char* text;
|
|
||||||
float height;
|
float height;
|
||||||
int track = 0;
|
int track = 0;
|
||||||
|
|
||||||
std::string sdir,sfontfile;
|
const char* text;
|
||||||
|
PyObject *intext;
|
||||||
|
|
||||||
|
Py_UNICODE *unichars;
|
||||||
|
Py_ssize_t pysize;
|
||||||
|
|
||||||
|
// std::string sdir,sfontfile;
|
||||||
|
|
||||||
std::vector <std::vector <TopoDS_Wire> > ret;
|
std::vector <std::vector <TopoDS_Wire> > ret;
|
||||||
std::vector<TopoDS_Wire>::iterator iWire;
|
std::vector<TopoDS_Wire>::iterator iWire;
|
||||||
std::vector<std::vector<TopoDS_Wire> >:: iterator iChar;
|
std::vector<std::vector<TopoDS_Wire> >:: iterator iChar;
|
||||||
|
|
||||||
PyObject *WireList, *CharList, *intext;
|
PyObject *WireList, *CharList;
|
||||||
Py_UNICODE *unichars;
|
|
||||||
Py_ssize_t pysize;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "Ossf|i", &intext,
|
if (!PyArg_ParseTuple(args, "Ossf|i", &intext,
|
||||||
&dir,
|
&dir,
|
||||||
|
@ -348,46 +353,39 @@ static PyObject * makeWireString(PyObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sdir = dir; // c string to std::string
|
// sdir = dir; // c string to std::string
|
||||||
sfontfile = fontfile;
|
// sfontfile = fontfile;
|
||||||
|
|
||||||
if (PyString_Check(intext)) {
|
if (PyString_Check(intext)) {
|
||||||
// Base::Console().Message("** makeWireString obj is pystring.\n");
|
|
||||||
// handle c type string
|
// handle c type string
|
||||||
try {
|
PyObject *p = Base::PyAsUnicodeObject(PyString_AsString(intext)); //ascii/utf8 to PyUni
|
||||||
text = PyString_AsString(intext);
|
|
||||||
// Base::Console().Message("** makeWireString pystring => text:<%s>\n", text);
|
|
||||||
PyObject *p = Base::PyAsUnicodeObject(text);
|
|
||||||
if (!p) {
|
if (!p) {
|
||||||
Base::Console().Message("** makeWireString Base::PyAsUnicode returns NULL.\n");
|
Base::Console().Message("** makeWireString can't convert PyString.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pysize = PyUnicode_GetSize(p);
|
pysize = PyUnicode_GetSize(p);
|
||||||
unichars = PyUnicode_AS_UNICODE(p);
|
unichars = PyUnicode_AS_UNICODE(p);
|
||||||
// Base::Console().Message("** makeWireString pystring len: %d\n", pysize);
|
|
||||||
ret = FT2FCpu(unichars,pysize,sdir,sfontfile,height,track); // get vector of wire chars
|
|
||||||
}
|
|
||||||
catch (Standard_DomainError) {
|
|
||||||
PyErr_SetString(PyExc_Exception, "makeWireString failed 1");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (PyUnicode_Check(intext)) {
|
else if (PyUnicode_Check(intext)) {
|
||||||
// Base::Console().Message("** makeWireString obj is unicode.\n");
|
// handle ucs-2/4 input (Py_UNICODE object)
|
||||||
// handle ucs-2/4 version (Py_UNICODE object)
|
pysize = PyUnicode_GetSize(intext);
|
||||||
try {
|
// Base::Console().Message("** makeWireString intext is Unicode len: '%d'.\n", pysize);
|
||||||
Py_ssize_t pysize = PyUnicode_GetSize(intext);
|
|
||||||
unichars = PyUnicode_AS_UNICODE(intext);
|
unichars = PyUnicode_AS_UNICODE(intext);
|
||||||
// Base::Console().Message("** makeWireString unicode len: %d\n", pysize);
|
|
||||||
ret = FT2FCpu(unichars,pysize,sdir,sfontfile,height,track); // get vector of wire chars
|
|
||||||
}
|
|
||||||
catch (Standard_DomainError) {
|
|
||||||
PyErr_SetString(PyExc_Exception, "makeWireString failed 2");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Base::Console().Message("** makeWireString bad string.\n");
|
Base::Console().Message("** makeWireString bad text parameter.\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ret = FT2FCpu(unichars,pysize,dir,fontfile,height,track); // get vector of wire chars
|
||||||
|
}
|
||||||
|
catch (Standard_DomainError) { // Standard_DomainError is OCC error.
|
||||||
|
PyErr_SetString(PyExc_Exception, "makeWireString failed - OCC");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
catch (std::runtime_error& e) { // FT2 or FT2FC errors
|
||||||
|
PyErr_SetString(PyExc_Exception, e.what());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ void getFTChar(FT_Face FTFont, UNICHAR c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get kerning values for this char pair
|
// get kerning values for this char pair
|
||||||
//TODO: should check FT_HASKERNING flag
|
//TODO: should check FT_HASKERNING flag?
|
||||||
FT_Vector getKerning(FT_Face FTFont, UNICHAR lc, UNICHAR rc) {
|
FT_Vector getKerning(FT_Face FTFont, UNICHAR lc, UNICHAR rc) {
|
||||||
FT_Vector retXY;
|
FT_Vector retXY;
|
||||||
FT_Error error;
|
FT_Error error;
|
||||||
|
@ -237,8 +237,8 @@ std::vector<TopoDS_Wire> getGlyphContours(FT_Face FTFont, UNICHAR currchar, int
|
||||||
|
|
||||||
// get string's wires (contours) in FC/OCC coords
|
// get string's wires (contours) in FC/OCC coords
|
||||||
FT2FCRET _FT2FC(const std::vector<UNICHAR> stringvec,
|
FT2FCRET _FT2FC(const std::vector<UNICHAR> stringvec,
|
||||||
const std::string FontPath,
|
const char * FontPath,
|
||||||
const std::string FontName,
|
const char * FontName,
|
||||||
const float stringheight, // in fc coords
|
const float stringheight, // in fc coords
|
||||||
const int tracking) { // in fc coords
|
const int tracking) { // in fc coords
|
||||||
FT_Library FTLib;
|
FT_Library FTLib;
|
||||||
|
@ -263,7 +263,11 @@ FT2FCRET _FT2FC(const std::vector<UNICHAR> stringvec,
|
||||||
ErrorMsg << "FT_Init_FreeType failed: " << error;
|
ErrorMsg << "FT_Init_FreeType failed: " << error;
|
||||||
throw std::runtime_error(ErrorMsg.str());
|
throw std::runtime_error(ErrorMsg.str());
|
||||||
}
|
}
|
||||||
FontSpec = FontPath + FontName;
|
|
||||||
|
std::string tmpPath = FontPath; // can't concat const char*
|
||||||
|
std::string tmpName = FontName;
|
||||||
|
FontSpec = tmpPath + tmpName;
|
||||||
|
|
||||||
FaceIndex = 0; // some fonts have multiple faces
|
FaceIndex = 0; // some fonts have multiple faces
|
||||||
|
|
||||||
// NOTE: FT blows up if font file not found. It does not return an error!!!
|
// NOTE: FT blows up if font file not found. It does not return an error!!!
|
||||||
|
@ -280,7 +284,7 @@ FT2FCRET _FT2FC(const std::vector<UNICHAR> stringvec,
|
||||||
ErrorMsg << "FT_New_Face failed: " << error;
|
ErrorMsg << "FT_New_Face failed: " << error;
|
||||||
throw std::runtime_error(ErrorMsg.str());
|
throw std::runtime_error(ErrorMsg.str());
|
||||||
}
|
}
|
||||||
//TODO: check that FTFont is scalable.
|
//TODO: check that FTFont is scalable?
|
||||||
|
|
||||||
// FT2 blows up if char size is not set to some non-zero value.
|
// FT2 blows up if char size is not set to some non-zero value.
|
||||||
// This sets size to 48 point. Magic.
|
// This sets size to 48 point. Magic.
|
||||||
|
@ -341,8 +345,8 @@ FT2FCRET FT2FCc(const char *cstring,
|
||||||
|
|
||||||
FT2FCRET FT2FCpu(const Py_UNICODE *pustring,
|
FT2FCRET FT2FCpu(const Py_UNICODE *pustring,
|
||||||
const size_t length,
|
const size_t length,
|
||||||
const std::string FontPath,
|
const char *FontPath,
|
||||||
const std::string FontName,
|
const char *FontName,
|
||||||
const float stringheight, // in fc coords
|
const float stringheight, // in fc coords
|
||||||
const int tracking) { // in fc coords
|
const int tracking) { // in fc coords
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
const int tracking);*/
|
const int tracking);*/
|
||||||
std::vector <std::vector <TopoDS_Wire> > FT2FCpu(const Py_UNICODE *unichars,
|
std::vector <std::vector <TopoDS_Wire> > FT2FCpu(const Py_UNICODE *unichars,
|
||||||
const size_t length,
|
const size_t length,
|
||||||
const std::string FontPath,
|
const char *FontPath,
|
||||||
const std::string FontName,
|
const char *FontName,
|
||||||
const float stringheight,
|
const float stringheight,
|
||||||
const int tracking);
|
const int tracking);
|
||||||
#endif // FT2FC_H
|
#endif // FT2FC_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user