Skip to content

Commit 067bf0c

Browse files
committed
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.
1 parent 3c6a107 commit 067bf0c

File tree

1 file changed

+6
-28
lines changed

1 file changed

+6
-28
lines changed

ttconv/pprdrv_tt2.cpp

+6-28
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream)
203203
/* Step thru the coutours. */
204204
/* I believe that a contour is a detatched */
205205
/* set of curves and lines. */
206-
i=j=k=0;
207-
while ( i < num_ctr )
206+
for(i = j = k = 0;
207+
i != NOMOREOUTCTR && i < num_ctr;
208+
k = nextinctr(i, k), (k == NOMOREINCTR && (i = k = nextoutctr(i))))
208209
{
209210
// A TrueType contour consists of on-path and off-path points.
210211
// Two consecutive on-path points are to be joined with a
@@ -224,24 +225,13 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream)
224225
}
225226
}
226227

227-
// For any two consecutive off-path points, insert the implied
228-
// on-path point.
229-
230228
if (points.size() == 0) {
231-
k=nextinctr(i,k);
232-
233-
if (k==NOMOREINCTR)
234-
{
235-
i=k=nextoutctr(i);
236-
}
237-
238-
if (i==NOMOREOUTCTR)
239-
{
240-
break;
241-
}
229+
// Don't try to access the last element of an empty list
242230
continue;
243231
}
244232

233+
// For any two consecutive off-path points, insert the implied
234+
// on-path point.
245235
FlaggedPoint prev = points.back();
246236
for (std::list<FlaggedPoint>::iterator it = points.begin();
247237
it != points.end();
@@ -296,18 +286,6 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream)
296286
p += 2;
297287
}
298288
}
299-
300-
k=nextinctr(i,k);
301-
302-
if (k==NOMOREINCTR)
303-
{
304-
i=k=nextoutctr(i);
305-
}
306-
307-
if (i==NOMOREOUTCTR)
308-
{
309-
break;
310-
}
311289
}
312290

313291
/* Now, we can fill the whole thing. */

0 commit comments

Comments
 (0)