@@ -163,6 +163,7 @@ class PathNanRemover : protected EmbeddedQueue<4>
163
163
VertexSource *m_source;
164
164
bool m_remove_nans;
165
165
bool m_has_curves;
166
+ bool valid_segment_exists;
166
167
167
168
public:
168
169
/* has_curves should be true if the path contains bezier curve
@@ -172,7 +173,9 @@ class PathNanRemover : protected EmbeddedQueue<4>
172
173
PathNanRemover (VertexSource &source, bool remove_nans, bool has_curves)
173
174
: m_source(&source), m_remove_nans(remove_nans), m_has_curves(has_curves)
174
175
{
175
- // empty
176
+ // ignore all close/end_poly commands until after the first valid
177
+ // (nan-free) command is encountered
178
+ valid_segment_exists = false ;
176
179
}
177
180
178
181
inline void rewind (unsigned path_id)
@@ -202,8 +205,13 @@ class PathNanRemover : protected EmbeddedQueue<4>
202
205
are found along the way, the queue is emptied, and
203
206
the next curve segment is handled. */
204
207
code = m_source->vertex (x, y);
208
+ /* The vertices attached to STOP and CLOSEPOLY left are never
209
+ used, so we leave them as-is even if NaN. However, CLOSEPOLY
210
+ only makes sense if a valid MOVETO command has already been
211
+ emitted. */
205
212
if (code == agg::path_cmd_stop ||
206
- code == (agg::path_cmd_end_poly | agg::path_flags_close)) {
213
+ (code == (agg::path_cmd_end_poly | agg::path_flags_close) &&
214
+ valid_segment_exists)) {
207
215
return code;
208
216
}
209
217
@@ -224,6 +232,7 @@ class PathNanRemover : protected EmbeddedQueue<4>
224
232
}
225
233
226
234
if (!has_nan) {
235
+ valid_segment_exists = true ;
227
236
break ;
228
237
}
229
238
@@ -251,21 +260,23 @@ class PathNanRemover : protected EmbeddedQueue<4>
251
260
code = m_source->vertex (x, y);
252
261
253
262
if (code == agg::path_cmd_stop ||
254
- code == (agg::path_cmd_end_poly | agg::path_flags_close)) {
263
+ (code == (agg::path_cmd_end_poly | agg::path_flags_close) &&
264
+ valid_segment_exists)) {
255
265
return code;
256
266
}
257
267
258
268
if (!(std::isfinite (*x) && std::isfinite (*y))) {
259
269
do {
260
270
code = m_source->vertex (x, y);
261
271
if (code == agg::path_cmd_stop ||
262
- code == (agg::path_cmd_end_poly | agg::path_flags_close)) {
272
+ (code == (agg::path_cmd_end_poly | agg::path_flags_close) &&
273
+ valid_segment_exists)) {
263
274
return code;
264
275
}
265
276
} while (!(std::isfinite (*x) && std::isfinite (*y)));
266
277
return agg::path_cmd_move_to;
267
278
}
268
-
279
+ valid_segment_exists = true ;
269
280
return code;
270
281
}
271
282
}
0 commit comments