From da8b6d4a818c8f8198039efc1684d5510335db12 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Wed, 20 Mar 2013 19:39:03 -0400 Subject: [PATCH] Eliminate temporary vector in FT2FC. --- src/Mod/Part/App/AppPartPy.cpp | 8 +---- src/Mod/Part/App/FT2FC.cpp | 55 +++++++++++++--------------------- src/Mod/Part/App/FT2FC.h | 9 ++---- 3 files changed, 24 insertions(+), 48 deletions(-) diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index 6fafa1937..2d3b5db8e 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -336,8 +336,6 @@ static PyObject * makeWireString(PyObject *self, PyObject *args) Py_UNICODE *unichars; Py_ssize_t pysize; -// std::string sdir,sfontfile; - std::vector > ret; std::vector::iterator iWire; std::vector >:: iterator iChar; @@ -352,9 +350,6 @@ static PyObject * makeWireString(PyObject *self, PyObject *args) Base::Console().Message("** makeWireString bad args.\n"); return NULL; } - -// sdir = dir; // c string to std::string -// sfontfile = fontfile; if (PyString_Check(intext)) { // handle c type string @@ -369,7 +364,6 @@ static PyObject * makeWireString(PyObject *self, PyObject *args) else if (PyUnicode_Check(intext)) { // handle ucs-2/4 input (Py_UNICODE object) pysize = PyUnicode_GetSize(intext); -// Base::Console().Message("** makeWireString intext is Unicode len: '%d'.\n", pysize); unichars = PyUnicode_AS_UNICODE(intext); } else { @@ -378,7 +372,7 @@ static PyObject * makeWireString(PyObject *self, PyObject *args) } 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. PyErr_SetString(PyExc_Exception, "makeWireString failed - OCC"); diff --git a/src/Mod/Part/App/FT2FC.cpp b/src/Mod/Part/App/FT2FC.cpp index ab0bdbb19..7ab73a76c 100644 --- a/src/Mod/Part/App/FT2FC.cpp +++ b/src/Mod/Part/App/FT2FC.cpp @@ -37,13 +37,9 @@ std::vector getGlyphContours(); FT_Vector getKerning(UNICHAR lc, UNICHAR rc); TopoDS_Wire edgesToWire(std::vector Edges); -//bool DEBUG=true; - struct FTDC_Ctx { // FT Decomp Context for 1 char std::vector TWires; std::vector Edges; -// int ConCnt; -// int SegCnt; UNICHAR currchar; int penpos; float scalefactor; @@ -69,7 +65,6 @@ TopoDS_Wire edgesToWire(std::vector Edges) { // p points to the context where we remember what happened previously (last point, etc) static int move_cb(const FT_Vector* pt, void* p) { FTDC_Ctx* dc = (FTDC_Ctx*) p; -// dc->ConCnt++; if (!dc->Edges.empty()){ // empty on first contour. (or messed up font) TopoDS_Wire newwire; newwire = edgesToWire(dc->Edges); @@ -94,7 +89,6 @@ static int line_cb(const FT_Vector* pt, void* p) { BRepBuilderAPI_MakeEdge makeEdge(v1,v2); TopoDS_Edge edge = makeEdge.Edge(); dc->Edges.push_back(edge); -// dc->SegCnt++; dc->LastVert.x = pt->x + dc->penpos; dc->LastVert.y = pt->y; 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); TopoDS_Edge edge = makeEdge.Edge(); dc->Edges.push_back(edge); -// dc->SegCnt++; dc->LastVert.x = pt1->x + dc->penpos; dc->LastVert.y = pt1->y; 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); TopoDS_Edge edge = makeEdge.Edge(); dc->Edges.push_back(edge); -// dc->SegCnt++; dc->LastVert.x = pt2->x + dc->penpos; dc->LastVert.y = pt2->y; return 0; @@ -236,11 +228,17 @@ std::vector getGlyphContours(FT_Face FTFont, UNICHAR currchar, int } // get string's wires (contours) in FC/OCC coords -FT2FCRET _FT2FC(const std::vector stringvec, +FT2FCRET FT2FC(const Py_UNICODE *pustring, + const size_t length, + const char *FontPath, + const char *FontName, + const float stringheight, // in fc coords + const int tracking) { // in fc coords +/*FT2FCRET _FT2FC(const std::vector stringvec, const char * FontPath, const char * FontName, const float stringheight, // in fc coords - const int tracking) { // in fc coords + const int tracking) { // in fc coords*/ FT_Library FTLib; FT_Face FTFont; FT_Error error; @@ -252,12 +250,11 @@ FT2FCRET _FT2FC(const std::vector stringvec, float scalefactor; UNICHAR prevchar,currchar; int cadv,PenPos; - size_t i, length; +// size_t i, length; + size_t i; std::vector CharWires; FT2FCRET Ret; -// std::cout << "FT2FC started: "<< FontPath << std::endl; - error = FT_Init_FreeType(&FTLib); if(error) { ErrorMsg << "FT_Init_FreeType failed: " << error; @@ -270,22 +267,23 @@ FT2FCRET _FT2FC(const std::vector stringvec, 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; is.open (FontSpec.c_str()); if (!is) { ErrorMsg << "Font file not found: " << FontSpec; throw std::runtime_error(ErrorMsg.str()); } - // maybe boost::filesystem::exists for x-platform?? + // maybe boost::filesystem::exists for x-platform?? error = FT_New_Face(FTLib,FontSpec.c_str(),FaceIndex, &FTFont); if(error) { ErrorMsg << "FT_New_Face failed: " << error; 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. // This sets size to 48 point. Magic. error = FT_Set_Char_Size(FTFont, @@ -301,9 +299,11 @@ FT2FCRET _FT2FC(const std::vector stringvec, prevchar = 0; PenPos = 0; scalefactor = float(stringheight/FTFont->height); - length = stringvec.size(); +// length = stringvec.size(); +// for (i=0;iglyph->advance.x; kern = getKerning(FTFont,prevchar,currchar); @@ -329,21 +329,8 @@ FT2FCRET _FT2FC(const std::vector stringvec, 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 stringvec(length, 0); - for (i=0;i > FT2FCc(const char *cstring, - const std::string FontPath, - const std::string FontName, - const float stringheight, - const int tracking);*/ -std::vector > FT2FCpu(const Py_UNICODE *unichars, +// public function +std::vector > FT2FC(const Py_UNICODE *unichars, const size_t length, const char *FontPath, const char *FontName,