123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- #include "sys-defines.h"
- #include "extern.h"
- int
- _API_savestate(S___(Plotter *_plotter))
- {
- plDrawState *oldstate = _plotter->drawstate;
- plDrawState *drawstate;
- char *fill_rule, *line_mode, *join_mode, *cap_mode;
- char *font_name, *true_font_name;
- if (!_plotter->data->open)
- {
- _plotter->error (R___(_plotter)
- "savestate: invalid operation");
- return -1;
- }
-
- drawstate = (plDrawState *)_pl_xmalloc (sizeof(plDrawState));
-
-
- memcpy (drawstate, oldstate, sizeof(plDrawState));
-
- fill_rule = (char *)_pl_xmalloc (strlen (oldstate->fill_rule) + 1);
- line_mode = (char *)_pl_xmalloc (strlen (oldstate->line_mode) + 1);
- join_mode = (char *)_pl_xmalloc (strlen (oldstate->join_mode) + 1);
- cap_mode = (char *)_pl_xmalloc (strlen (oldstate->cap_mode) + 1);
- strcpy (fill_rule, oldstate->fill_rule);
- strcpy (line_mode, oldstate->line_mode);
- strcpy (join_mode, oldstate->join_mode);
- strcpy (cap_mode, oldstate->cap_mode);
- drawstate->fill_rule = fill_rule;
- drawstate->line_mode = line_mode;
- drawstate->join_mode = join_mode;
- drawstate->cap_mode = cap_mode;
-
- if (oldstate->dash_array_len > 0)
- {
- int i;
- double *dash_array;
- dash_array = (double *)_pl_xmalloc (oldstate->dash_array_len * sizeof(double));
- for (i = 0; i < oldstate->dash_array_len; i++)
- dash_array[i] = oldstate->dash_array[i];
- drawstate->dash_array = dash_array;
- }
-
- font_name = (char *)_pl_xmalloc (strlen (oldstate->font_name) + 1);
- strcpy (font_name, oldstate->font_name);
- drawstate->font_name = font_name;
- true_font_name = (char *)_pl_xmalloc (strlen (oldstate->true_font_name) + 1);
- strcpy (true_font_name, oldstate->true_font_name);
- drawstate->true_font_name = true_font_name;
-
- drawstate->path = (plPath *)NULL;
- drawstate->paths = (plPath **)NULL;
- drawstate->num_paths = 0;
-
- drawstate->previous = oldstate;
- _plotter->drawstate = drawstate;
-
- _plotter->push_state (S___(_plotter));
- return 0;
- }
- int
- _API_restorestate(S___(Plotter *_plotter))
- {
- plDrawState *oldstate = _plotter->drawstate->previous;
- if (!_plotter->data->open)
- {
- _plotter->error (R___(_plotter)
- "restorestate: invalid operation");
- return -1;
- }
- if (_plotter->drawstate->previous == NULL)
-
- {
- _plotter->error (R___(_plotter)
- "restorestate: invalid operation");
- return -1;
- }
- _API_endpath (S___(_plotter));
-
- _plotter->pop_state (S___(_plotter));
-
- free ((char *)_plotter->drawstate->fill_rule);
- free ((char *)_plotter->drawstate->line_mode);
- free ((char *)_plotter->drawstate->join_mode);
- free ((char *)_plotter->drawstate->cap_mode);
- free ((char *)_plotter->drawstate->true_font_name);
- free ((char *)_plotter->drawstate->font_name);
-
-
- if (_plotter->drawstate->dash_array_len > 0)
- free ((double *)_plotter->drawstate->dash_array);
-
- free (_plotter->drawstate);
- _plotter->drawstate = oldstate;
- return 0;
- }
- void
- _pl_g_push_state (S___(Plotter *_plotter))
- {
- return;
- }
- void
- _pl_g_pop_state (S___(Plotter *_plotter))
- {
- return;
- }
|