Eliminate temporary vector in FT2FC.
This commit is contained in:
parent
6465e367eb
commit
da8b6d4a81
|
@ -336,8 +336,6 @@ static PyObject * makeWireString(PyObject *self, PyObject *args)
|
||||||
Py_UNICODE *unichars;
|
Py_UNICODE *unichars;
|
||||||
Py_ssize_t pysize;
|
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;
|
||||||
|
@ -353,9 +351,6 @@ static PyObject * makeWireString(PyObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sdir = dir; // c string to std::string
|
|
||||||
// sfontfile = fontfile;
|
|
||||||
|
|
||||||
if (PyString_Check(intext)) {
|
if (PyString_Check(intext)) {
|
||||||
// handle c type string
|
// handle c type string
|
||||||
PyObject *p = Base::PyAsUnicodeObject(PyString_AsString(intext)); //ascii/utf8 to PyUni
|
PyObject *p = Base::PyAsUnicodeObject(PyString_AsString(intext)); //ascii/utf8 to PyUni
|
||||||
|
@ -369,7 +364,6 @@ static PyObject * makeWireString(PyObject *self, PyObject *args)
|
||||||
else if (PyUnicode_Check(intext)) {
|
else if (PyUnicode_Check(intext)) {
|
||||||
// handle ucs-2/4 input (Py_UNICODE object)
|
// handle ucs-2/4 input (Py_UNICODE object)
|
||||||
pysize = PyUnicode_GetSize(intext);
|
pysize = PyUnicode_GetSize(intext);
|
||||||
// Base::Console().Message("** makeWireString intext is Unicode len: '%d'.\n", pysize);
|
|
||||||
unichars = PyUnicode_AS_UNICODE(intext);
|
unichars = PyUnicode_AS_UNICODE(intext);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -378,7 +372,7 @@ static PyObject * makeWireString(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ret = FT2FCpu(unichars,pysize,dir,fontfile,height,track); // get vector of wire chars
|
ret = FT2FC(unichars,pysize,dir,fontfile,height,track); // get vector of wire chars
|
||||||
}
|
}
|
||||||
catch (Standard_DomainError) { // Standard_DomainError is OCC error.
|
catch (Standard_DomainError) { // Standard_DomainError is OCC error.
|
||||||
PyErr_SetString(PyExc_Exception, "makeWireString failed - OCC");
|
PyErr_SetString(PyExc_Exception, "makeWireString failed - OCC");
|
||||||
|
|
|
@ -37,13 +37,9 @@ std::vector<TopoDS_Wire> getGlyphContours();
|
||||||
FT_Vector getKerning(UNICHAR lc, UNICHAR rc);
|
FT_Vector getKerning(UNICHAR lc, UNICHAR rc);
|
||||||
TopoDS_Wire edgesToWire(std::vector<TopoDS_Edge> Edges);
|
TopoDS_Wire edgesToWire(std::vector<TopoDS_Edge> Edges);
|
||||||
|
|
||||||
//bool DEBUG=true;
|
|
||||||
|
|
||||||
struct FTDC_Ctx { // FT Decomp Context for 1 char
|
struct FTDC_Ctx { // FT Decomp Context for 1 char
|
||||||
std::vector<TopoDS_Wire> TWires;
|
std::vector<TopoDS_Wire> TWires;
|
||||||
std::vector<TopoDS_Edge> Edges;
|
std::vector<TopoDS_Edge> Edges;
|
||||||
// int ConCnt;
|
|
||||||
// int SegCnt;
|
|
||||||
UNICHAR currchar;
|
UNICHAR currchar;
|
||||||
int penpos;
|
int penpos;
|
||||||
float scalefactor;
|
float scalefactor;
|
||||||
|
@ -69,7 +65,6 @@ TopoDS_Wire edgesToWire(std::vector<TopoDS_Edge> Edges) {
|
||||||
// p points to the context where we remember what happened previously (last point, etc)
|
// p points to the context where we remember what happened previously (last point, etc)
|
||||||
static int move_cb(const FT_Vector* pt, void* p) {
|
static int move_cb(const FT_Vector* pt, void* p) {
|
||||||
FTDC_Ctx* dc = (FTDC_Ctx*) p;
|
FTDC_Ctx* dc = (FTDC_Ctx*) p;
|
||||||
// dc->ConCnt++;
|
|
||||||
if (!dc->Edges.empty()){ // empty on first contour. (or messed up font)
|
if (!dc->Edges.empty()){ // empty on first contour. (or messed up font)
|
||||||
TopoDS_Wire newwire;
|
TopoDS_Wire newwire;
|
||||||
newwire = edgesToWire(dc->Edges);
|
newwire = edgesToWire(dc->Edges);
|
||||||
|
@ -94,7 +89,6 @@ static int line_cb(const FT_Vector* pt, void* p) {
|
||||||
BRepBuilderAPI_MakeEdge makeEdge(v1,v2);
|
BRepBuilderAPI_MakeEdge makeEdge(v1,v2);
|
||||||
TopoDS_Edge edge = makeEdge.Edge();
|
TopoDS_Edge edge = makeEdge.Edge();
|
||||||
dc->Edges.push_back(edge);
|
dc->Edges.push_back(edge);
|
||||||
// dc->SegCnt++;
|
|
||||||
dc->LastVert.x = pt->x + dc->penpos;
|
dc->LastVert.x = pt->x + dc->penpos;
|
||||||
dc->LastVert.y = pt->y;
|
dc->LastVert.y = pt->y;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -123,7 +117,6 @@ static int quad_cb(const FT_Vector* pt0, const FT_Vector* pt1, void* p) {
|
||||||
BRepBuilderAPI_MakeEdge makeEdge(bcseg, v1, v2);
|
BRepBuilderAPI_MakeEdge makeEdge(bcseg, v1, v2);
|
||||||
TopoDS_Edge edge = makeEdge.Edge();
|
TopoDS_Edge edge = makeEdge.Edge();
|
||||||
dc->Edges.push_back(edge);
|
dc->Edges.push_back(edge);
|
||||||
// dc->SegCnt++;
|
|
||||||
dc->LastVert.x = pt1->x + dc->penpos;
|
dc->LastVert.x = pt1->x + dc->penpos;
|
||||||
dc->LastVert.y = pt1->y;
|
dc->LastVert.y = pt1->y;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -155,7 +148,6 @@ static int cubic_cb(const FT_Vector* pt0, const FT_Vector* pt1, const FT_Vector*
|
||||||
BRepBuilderAPI_MakeEdge makeEdge(bcseg, v1, v2);
|
BRepBuilderAPI_MakeEdge makeEdge(bcseg, v1, v2);
|
||||||
TopoDS_Edge edge = makeEdge.Edge();
|
TopoDS_Edge edge = makeEdge.Edge();
|
||||||
dc->Edges.push_back(edge);
|
dc->Edges.push_back(edge);
|
||||||
// dc->SegCnt++;
|
|
||||||
dc->LastVert.x = pt2->x + dc->penpos;
|
dc->LastVert.x = pt2->x + dc->penpos;
|
||||||
dc->LastVert.y = pt2->y;
|
dc->LastVert.y = pt2->y;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -236,11 +228,17 @@ 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 Py_UNICODE *pustring,
|
||||||
|
const size_t length,
|
||||||
const char *FontPath,
|
const char *FontPath,
|
||||||
const char *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
|
||||||
|
/*FT2FCRET _FT2FC(const std::vector<UNICHAR> stringvec,
|
||||||
|
const char * FontPath,
|
||||||
|
const char * FontName,
|
||||||
|
const float stringheight, // in fc coords
|
||||||
|
const int tracking) { // in fc coords*/
|
||||||
FT_Library FTLib;
|
FT_Library FTLib;
|
||||||
FT_Face FTFont;
|
FT_Face FTFont;
|
||||||
FT_Error error;
|
FT_Error error;
|
||||||
|
@ -252,12 +250,11 @@ FT2FCRET _FT2FC(const std::vector<UNICHAR> stringvec,
|
||||||
float scalefactor;
|
float scalefactor;
|
||||||
UNICHAR prevchar,currchar;
|
UNICHAR prevchar,currchar;
|
||||||
int cadv,PenPos;
|
int cadv,PenPos;
|
||||||
size_t i, length;
|
// size_t i, length;
|
||||||
|
size_t i;
|
||||||
std::vector<TopoDS_Wire> CharWires;
|
std::vector<TopoDS_Wire> CharWires;
|
||||||
FT2FCRET Ret;
|
FT2FCRET Ret;
|
||||||
|
|
||||||
// std::cout << "FT2FC started: "<< FontPath << std::endl;
|
|
||||||
|
|
||||||
error = FT_Init_FreeType(&FTLib);
|
error = FT_Init_FreeType(&FTLib);
|
||||||
if(error) {
|
if(error) {
|
||||||
ErrorMsg << "FT_Init_FreeType failed: " << error;
|
ErrorMsg << "FT_Init_FreeType failed: " << error;
|
||||||
|
@ -270,7 +267,7 @@ FT2FCRET _FT2FC(const std::vector<UNICHAR> stringvec,
|
||||||
|
|
||||||
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 does not return an error if font file not found.
|
||||||
std::ifstream is;
|
std::ifstream is;
|
||||||
is.open (FontSpec.c_str());
|
is.open (FontSpec.c_str());
|
||||||
if (!is) {
|
if (!is) {
|
||||||
|
@ -284,7 +281,8 @@ 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? only relevant for hinting etc?
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -301,9 +299,11 @@ FT2FCRET _FT2FC(const std::vector<UNICHAR> stringvec,
|
||||||
prevchar = 0;
|
prevchar = 0;
|
||||||
PenPos = 0;
|
PenPos = 0;
|
||||||
scalefactor = float(stringheight/FTFont->height);
|
scalefactor = float(stringheight/FTFont->height);
|
||||||
length = stringvec.size();
|
// length = stringvec.size();
|
||||||
|
// for (i=0;i<length;i++) {
|
||||||
for (i=0;i<length;i++) {
|
for (i=0;i<length;i++) {
|
||||||
currchar = stringvec[i];
|
currchar = pustring[i];
|
||||||
|
// currchar = stringvec[i];
|
||||||
getFTChar(FTFont,currchar);
|
getFTChar(FTFont,currchar);
|
||||||
cadv = FTFont->glyph->advance.x;
|
cadv = FTFont->glyph->advance.x;
|
||||||
kern = getKerning(FTFont,prevchar,currchar);
|
kern = getKerning(FTFont,prevchar,currchar);
|
||||||
|
@ -329,21 +329,8 @@ FT2FCRET _FT2FC(const std::vector<UNICHAR> stringvec,
|
||||||
|
|
||||||
return(Ret);
|
return(Ret);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
FT2FCRET FT2FCc(const char *cstring,
|
|
||||||
const std::string FontPath,
|
|
||||||
const std::string FontName,
|
|
||||||
const float stringheight, // in fc coords
|
|
||||||
const int tracking) { // in fc coords
|
|
||||||
size_t i, length;
|
|
||||||
length = strlen(cstring);
|
|
||||||
std::vector<UNICHAR> stringvec(length, 0);
|
|
||||||
for (i=0;i<length;i++)
|
|
||||||
stringvec[i] = cstring[i];
|
|
||||||
return (_FT2FC(stringvec,FontPath,FontName,stringheight,tracking));
|
|
||||||
}*/
|
|
||||||
|
|
||||||
FT2FCRET FT2FCpu(const Py_UNICODE *pustring,
|
/*FT2FCRET FT2FCpu(const Py_UNICODE *pustring,
|
||||||
const size_t length,
|
const size_t length,
|
||||||
const char *FontPath,
|
const char *FontPath,
|
||||||
const char *FontName,
|
const char *FontName,
|
||||||
|
@ -355,5 +342,5 @@ FT2FCRET FT2FCpu(const Py_UNICODE *pustring,
|
||||||
stringvec[i] = pustring[i];
|
stringvec[i] = pustring[i];
|
||||||
return (_FT2FC(stringvec,FontPath,FontName,stringheight,tracking));
|
return (_FT2FC(stringvec,FontPath,FontName,stringheight,tracking));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,8 @@
|
||||||
|
|
||||||
#ifndef FT2FC_H
|
#ifndef FT2FC_H
|
||||||
#define FT2FC_H
|
#define FT2FC_H
|
||||||
// public functions
|
// public function
|
||||||
/*std::vector <std::vector <TopoDS_Wire> > FT2FCc(const char *cstring,
|
std::vector <std::vector <TopoDS_Wire> > FT2FC(const Py_UNICODE *unichars,
|
||||||
const std::string FontPath,
|
|
||||||
const std::string FontName,
|
|
||||||
const float stringheight,
|
|
||||||
const int tracking);*/
|
|
||||||
std::vector <std::vector <TopoDS_Wire> > FT2FCpu(const Py_UNICODE *unichars,
|
|
||||||
const size_t length,
|
const size_t length,
|
||||||
const char *FontPath,
|
const char *FontPath,
|
||||||
const char *FontName,
|
const char *FontName,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user