From ae96cad31dbb8d2fc719ac8b9ea12a31a9c7457e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jouni=20K=2E=20Seppa=CC=88nen?= Date: Sat, 9 Jun 2012 13:48:12 +0300 Subject: [PATCH 1/3] Don't use iteration constructor Apparently some compilers don't support that. --- ttconv/pprdrv_tt2.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ttconv/pprdrv_tt2.cpp b/ttconv/pprdrv_tt2.cpp index 1f52397794ce..e3b6fcc95909 100644 --- a/ttconv/pprdrv_tt2.cpp +++ b/ttconv/pprdrv_tt2.cpp @@ -271,7 +271,15 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream) } // For output, a vector is more convenient than a list. - std::vector points_v(points.begin(), points.end()); + std::vector points_v; + points_v.reserve(points.size()); + for (std::list::iterator it = points.begin(); + it != points.end(); + it++) + { + points_v.push_back(*it); + } + // The first point stack(stream, 3); PSMoveto(stream, points_v.front().x, points_v.front().y); From 067bf0c7c8bcdfb1f83875b5dd916ededcbcc0fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jouni=20K=2E=20Seppa=CC=88nen?= Date: Sat, 9 Jun 2012 14:05:53 +0300 Subject: [PATCH 2/3] Simplify a loop in ttconv Replace a while loop with complicated break and continue cases by a for loop that has the iteration and end-condition testing in one place only. --- ttconv/pprdrv_tt2.cpp | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/ttconv/pprdrv_tt2.cpp b/ttconv/pprdrv_tt2.cpp index 1f52397794ce..ef880a758a50 100644 --- a/ttconv/pprdrv_tt2.cpp +++ b/ttconv/pprdrv_tt2.cpp @@ -203,8 +203,9 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream) /* Step thru the coutours. */ /* I believe that a contour is a detatched */ /* set of curves and lines. */ - i=j=k=0; - while ( i < num_ctr ) + for(i = j = k = 0; + i != NOMOREOUTCTR && i < num_ctr; + k = nextinctr(i, k), (k == NOMOREINCTR && (i = k = nextoutctr(i)))) { // A TrueType contour consists of on-path and off-path points. // Two consecutive on-path points are to be joined with a @@ -224,24 +225,13 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream) } } - // For any two consecutive off-path points, insert the implied - // on-path point. - if (points.size() == 0) { - k=nextinctr(i,k); - - if (k==NOMOREINCTR) - { - i=k=nextoutctr(i); - } - - if (i==NOMOREOUTCTR) - { - break; - } + // Don't try to access the last element of an empty list continue; } + // For any two consecutive off-path points, insert the implied + // on-path point. FlaggedPoint prev = points.back(); for (std::list::iterator it = points.begin(); it != points.end(); @@ -296,18 +286,6 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream) p += 2; } } - - k=nextinctr(i,k); - - if (k==NOMOREINCTR) - { - i=k=nextoutctr(i); - } - - if (i==NOMOREOUTCTR) - { - break; - } } /* Now, we can fill the whole thing. */ From 1bade3bc69ac6fe628996842cdb6417b7777ecec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jouni=20K=2E=20Seppa=CC=88nen?= Date: Sat, 9 Jun 2012 16:48:56 +0300 Subject: [PATCH 3/3] Do output directly from list Having the prev and next iterators is not much worse than indexing the vector, and initializing the vector became too verbose. --- ttconv/pprdrv_tt2.cpp | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/ttconv/pprdrv_tt2.cpp b/ttconv/pprdrv_tt2.cpp index e3b6fcc95909..1efaef0b68b8 100644 --- a/ttconv/pprdrv_tt2.cpp +++ b/ttconv/pprdrv_tt2.cpp @@ -270,38 +270,33 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream) points.push_back(points.front()); } - // For output, a vector is more convenient than a list. - std::vector points_v; - points_v.reserve(points.size()); - for (std::list::iterator it = points.begin(); - it != points.end(); - it++) - { - points_v.push_back(*it); - } - // The first point stack(stream, 3); - PSMoveto(stream, points_v.front().x, points_v.front().y); + PSMoveto(stream, points.front().x, points.front().y); // Step through the remaining points - for (size_t p = 1; p < points_v.size(); ) + std::list::const_iterator it = points.begin(); + for (it++; it != points.end(); /* incremented inside */) { - const FlaggedPoint& point = points_v.at(p); + const FlaggedPoint& point = *it; if (point.flag == ON_PATH) { stack(stream, 3); PSLineto(stream, point.x, point.y); - p++; + it++; } else { - assert(points_v.at(p-1).flag == ON_PATH); - assert(points_v.at(p+1).flag == ON_PATH); + std::list::const_iterator prev = it, next = it; + prev--; + next++; + assert(prev->flag == ON_PATH); + assert(next->flag == ON_PATH); stack(stream, 7); PSCurveto(stream, - points_v.at(p-1).x, points_v.at(p-1).y, + prev->x, prev->y, point.x, point.y, - points_v.at(p+1).x, points_v.at(p+1).y); - p += 2; + next->x, next->y); + it++; + it++; } }