123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- #include "sys-defines.h"
- #include "extern.h"
- int
- _API_endpath (S___(Plotter *_plotter))
- {
- int i;
- if (!_plotter->data->open)
- {
- _plotter->error (R___(_plotter)
- "endpath: invalid operation");
- return -1;
- }
-
- _API_endsubpath (S___(_plotter));
- if (_plotter->drawstate->num_paths == 0)
-
- return 0;
-
-
-
- if (!_plotter->drawstate->points_are_connected)
-
- {
- if (_plotter->drawstate->pen_type != 0)
-
- {
- plPath **saved_paths;
- int saved_num_paths;
- double radius = 0.5 * _plotter->drawstate->line_width;
- int i;
-
-
- saved_paths = _plotter->drawstate->paths;
- saved_num_paths = _plotter->drawstate->num_paths;
- _plotter->drawstate->paths = (plPath **)NULL;
- _plotter->drawstate->num_paths = 0;
-
-
- _API_savestate (S___(_plotter));
-
- _API_filltype (R___(_plotter) 1);
- _API_fillcolor (R___(_plotter)
- _plotter->drawstate->fgcolor.red,
- _plotter->drawstate->fgcolor.green,
- _plotter->drawstate->fgcolor.blue);
- _API_pentype (R___(_plotter) 0);
- _API_linemod (R___(_plotter) "solid");
-
-
- for (i = 0; i < saved_num_paths; i++)
- {
- plPath *path;
- bool closed;
- int j;
- path = saved_paths[i];
-
- if (path->type != PATH_SEGMENT_LIST || path->num_segments < 2)
- continue;
-
- if ((path->num_segments >= 3)
- && (path->segments[path->num_segments - 1].p.x ==
- path->segments[0].p.x)
- && (path->segments[path->num_segments - 1].p.y ==
- path->segments[0].p.y))
- closed = true;
- else
- closed = false;
-
-
- for (j = 0; j < path->num_segments - (closed ? 1 : 0); j++)
- _API_fcircle (R___(_plotter)
- path->segments[j].p.x,
- path->segments[j].p.y,
- radius);
- if (closed)
-
- _plotter->drawstate->pos = path->segments[0].p;
- }
-
-
- _API_restorestate (S___(_plotter));
-
- _plotter->drawstate->paths = saved_paths;
- _plotter->drawstate->num_paths = saved_num_paths;
- }
- }
- else
-
- {
- if (_plotter->drawstate->num_paths == 1)
-
- {
- _plotter->drawstate->path = _plotter->drawstate->paths[0];
- _plotter->paint_path (S___(_plotter));
- _plotter->drawstate->path = (plPath *)NULL;
- }
- else
-
- {
-
- if (_plotter->paint_paths (S___(_plotter)) == false)
-
- {
- int fill_type, pen_type;
-
- fill_type = _plotter->drawstate->fill_type;
- pen_type = _plotter->drawstate->pen_type;
-
- if (fill_type && _plotter->data->have_solid_fill)
-
- {
- plPath **merged_paths;
- _plotter->drawstate->fill_type = fill_type;
- _plotter->drawstate->pen_type = 0;
-
- merged_paths = _merge_paths ((const plPath **)_plotter->drawstate->paths,
- _plotter->drawstate->num_paths);
- for (i = 0; i < _plotter->drawstate->num_paths; i++)
- {
-
- if (merged_paths[i] == (plPath *)NULL)
- continue;
-
- _plotter->drawstate->path = merged_paths[i];
- _plotter->paint_path (S___(_plotter));
- if (merged_paths[i] != _plotter->drawstate->paths[i])
- _delete_plPath (merged_paths[i]);
- }
- _plotter->drawstate->path = (plPath *)NULL;
- }
-
- if (pen_type)
-
- {
- _plotter->drawstate->pen_type = pen_type;
- _plotter->drawstate->fill_type = 0;
- for (i = 0; i < _plotter->drawstate->num_paths; i++)
- {
- _plotter->drawstate->path = _plotter->drawstate->paths[i];
- _plotter->paint_path (S___(_plotter));
- }
- _plotter->drawstate->path = (plPath *)NULL;
- }
-
-
- _plotter->drawstate->fill_type = fill_type;
- _plotter->drawstate->pen_type = pen_type;
- }
- }
- }
-
-
- for (i = 0; i < _plotter->drawstate->num_paths; i++)
- _delete_plPath (_plotter->drawstate->paths[i]);
- free (_plotter->drawstate->paths);
- _plotter->drawstate->paths = (plPath **)NULL;
- _plotter->drawstate->num_paths = 0;
- return 0;
- }
- int
- _API_endsubpath (S___(Plotter *_plotter))
- {
- if (!_plotter->data->open)
- {
- _plotter->error (R___(_plotter)
- "endsubpath: invalid operation");
- return -1;
- }
- if (_plotter->drawstate->path)
-
- {
- if (_plotter->drawstate->num_paths == 0)
- _plotter->drawstate->paths =
- (plPath **)_pl_xmalloc(sizeof (plPath *));
- else
- _plotter->drawstate->paths =
- (plPath **)_pl_xrealloc(_plotter->drawstate->paths,
- (_plotter->drawstate->num_paths + 1)
- * sizeof (plPath *));
- _plotter->drawstate->paths[_plotter->drawstate->num_paths++] =
- _plotter->drawstate->path;
- _plotter->drawstate->path = (plPath *)NULL;
- }
- return 0;
- }
- int
- _API_closepath (S___(Plotter *_plotter))
- {
- if (!_plotter->data->open)
- {
- _plotter->error (R___(_plotter)
- "closepath: invalid operation");
- return -1;
- }
-
- return 0;
- }
|