@@ -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 ();
@@ -270,44 +260,35 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream)
270260 points.push_back (points.front ());
271261 }
272262
273- // For output, a vector is more convenient than a list.
274- std::vector<FlaggedPoint> points_v (points.begin (), points.end ());
275263 // The first point
276264 stack (stream, 3 );
277- PSMoveto (stream, points_v .front ().x , points_v .front ().y );
265+ PSMoveto (stream, points .front ().x , points .front ().y );
278266
279267 // Step through the remaining points
280- for (size_t p = 1 ; p < points_v.size (); )
268+ std::list<FlaggedPoint>::const_iterator it = points.begin ();
269+ for (it++; it != points.end (); /* incremented inside */ )
281270 {
282- const FlaggedPoint& point = points_v. at (p) ;
271+ const FlaggedPoint& point = *it ;
283272 if (point.flag == ON_PATH)
284273 {
285274 stack (stream, 3 );
286275 PSLineto (stream, point.x , point.y );
287- p ++;
276+ it ++;
288277 } else {
289- assert (points_v.at (p-1 ).flag == ON_PATH);
290- assert (points_v.at (p+1 ).flag == ON_PATH);
278+ std::list<FlaggedPoint>::const_iterator prev = it, next = it;
279+ prev--;
280+ next++;
281+ assert (prev->flag == ON_PATH);
282+ assert (next->flag == ON_PATH);
291283 stack (stream, 7 );
292284 PSCurveto (stream,
293- points_v. at (p- 1 ). x , points_v. at (p- 1 ). y ,
285+ prev-> x , prev-> y ,
294286 point.x , point.y ,
295- points_v.at (p+1 ).x , points_v.at (p+1 ).y );
296- p += 2 ;
287+ next->x , next->y );
288+ it++;
289+ it++;
297290 }
298291 }
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- }
311292 }
312293
313294 /* Now, we can fill the whole thing. */
0 commit comments