123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- #include "sys-defines.h"
- #include "extern.h"
- enum { ACCEPTED = 0x1, CLIPPED_FIRST = 0x2, CLIPPED_SECOND = 0x4 };
- static void _emit_regis_vector (plIntPoint istart, plIntPoint iend, bool skip_null, char *tmpbuf);
- void
- _pl_r_paint_path (S___(Plotter *_plotter))
- {
- char tmpbuf[32];
- if (_plotter->drawstate->pen_type == 0
- && _plotter->drawstate->fill_type == 0)
-
- return;
- switch ((int)_plotter->drawstate->path->type)
- {
- case (int)PATH_SEGMENT_LIST:
- {
- int i;
-
- if (_plotter->drawstate->path->num_segments == 0)
- break;
- if (_plotter->drawstate->path->num_segments == 1)
- break;
- if (_plotter->drawstate->fill_type)
-
- {
- bool within_display = true;
-
- for (i = 0; i < _plotter->drawstate->path->num_segments; i++)
- {
- double x, y;
- int i_x, i_y;
-
- x = XD(_plotter->drawstate->path->segments[i].p.x,
- _plotter->drawstate->path->segments[i].p.y);
- y = YD(_plotter->drawstate->path->segments[i].p.x,
- _plotter->drawstate->path->segments[i].p.y);
- i_x = IROUND(x);
- i_y = IROUND(y);
- if (i_x < REGIS_DEVICE_X_MIN
- || i_x > REGIS_DEVICE_X_MAX
- || i_y < REGIS_DEVICE_Y_MIN
- || i_y > REGIS_DEVICE_Y_MAX)
- {
- within_display = false;
- break;
- }
- }
- if (within_display)
-
- {
- double x, y;
- plIntPoint first, oldpoint, newpoint;
- _pl_r_set_fill_color (S___(_plotter));
- x = XD(_plotter->drawstate->path->segments[0].p.x,
- _plotter->drawstate->path->segments[0].p.y);
- y = YD(_plotter->drawstate->path->segments[0].p.x,
- _plotter->drawstate->path->segments[0].p.y);
- first.x = IROUND(x);
- first.y = IROUND(y);
- _pl_r_regis_move (R___(_plotter) first.x, first.y);
- _write_string (_plotter->data, "F(");
- _write_string (_plotter->data, "V");
- oldpoint = first;
- for (i = 1; i < _plotter->drawstate->path->num_segments; i++)
- {
- x = XD(_plotter->drawstate->path->segments[i].p.x,
- _plotter->drawstate->path->segments[i].p.y);
- y = YD(_plotter->drawstate->path->segments[i].p.x,
- _plotter->drawstate->path->segments[i].p.y);
- newpoint.x = IROUND(x);
- newpoint.y = IROUND(y);
-
- _emit_regis_vector (oldpoint, newpoint,
- i > 1 ? true : false, tmpbuf);
- _write_string (_plotter->data, tmpbuf);
- oldpoint = newpoint;
- }
-
- _emit_regis_vector (newpoint, first, true, tmpbuf);
- _write_string (_plotter->data, tmpbuf);
-
- _write_string (_plotter->data, ")\n");
- _plotter->regis_position_is_unknown = true;
- }
- else
-
- {
-
- }
- }
- if (_plotter->drawstate->pen_type)
-
- {
- bool attributes_set = false;
- bool path_in_progress = false;
- for (i = 1; i < _plotter->drawstate->path->num_segments; i++)
- {
- plPoint start, end;
- plIntPoint istart, iend;
- int clipval;
-
-
- start.x = XD(_plotter->drawstate->path->segments[i-1].p.x,
- _plotter->drawstate->path->segments[i-1].p.y);
- start.y = YD(_plotter->drawstate->path->segments[i-1].p.x,
- _plotter->drawstate->path->segments[i-1].p.y);
- end.x = XD(_plotter->drawstate->path->segments[i].p.x,
- _plotter->drawstate->path->segments[i].p.y);
- end.y = YD(_plotter->drawstate->path->segments[i].p.x,
- _plotter->drawstate->path->segments[i].p.y);
-
- clipval = _clip_line (&start.x, &start.y, &end.x, &end.y,
- REGIS_DEVICE_X_MIN_CLIP,
- REGIS_DEVICE_X_MAX_CLIP,
- REGIS_DEVICE_Y_MIN_CLIP,
- REGIS_DEVICE_Y_MAX_CLIP);
- if (!(clipval & ACCEPTED))
- {
- if (path_in_progress)
- _write_string (_plotter->data, "\n");
- path_in_progress = false;
- continue;
- }
- if (clipval & CLIPPED_FIRST)
- {
- if (path_in_progress)
- _write_string (_plotter->data, "\n");
- path_in_progress = false;
- }
-
- istart.x = IROUND(start.x);
- istart.y = IROUND(start.y);
- iend.x = IROUND(end.x);
- iend.y = IROUND(end.y);
-
- if (path_in_progress
- && istart.x == iend.x && istart.y == iend.y)
-
- continue;
- if (attributes_set == false)
-
- {
- _pl_r_set_attributes (S___(_plotter));
- _pl_r_set_pen_color (S___(_plotter));
- attributes_set = true;
- }
- if (path_in_progress == false)
- {
-
- _pl_r_regis_move (R___(_plotter) istart.x, istart.y);
-
-
- _write_string (_plotter->data, "V");
- if (iend.x != istart.x || iend.y != istart.y)
-
- _write_string (_plotter->data, "[]");
- path_in_progress = true;
- }
-
- _emit_regis_vector (istart, iend, true, tmpbuf);
- _write_string (_plotter->data, tmpbuf);
-
-
- _plotter->regis_pos.x = iend.x;
- _plotter->regis_pos.y = iend.y;
- }
-
- if (path_in_progress == true)
- _write_string (_plotter->data, "\n");
- }
- }
- break;
-
- case (int)PATH_CIRCLE:
- {
- double xd, yd, radius_d;
- int i_x, i_y, i_radius;
- plPoint pc;
- double radius;
-
- pc = _plotter->drawstate->path->pc;
- radius = _plotter->drawstate->path->radius;
-
- xd = XD(pc.x, pc.y);
- yd = YD(pc.x, pc.y);
- radius_d = sqrt (XDV(radius,0) * XDV(radius,0)
- + YDV(radius,0) * YDV(radius,0));
- i_x = IROUND(xd);
- i_y = IROUND(yd);
- i_radius = IROUND(radius_d);
-
- if (i_x - i_radius < REGIS_DEVICE_X_MIN
- || i_x + i_radius > REGIS_DEVICE_X_MAX
- || i_y - i_radius < REGIS_DEVICE_Y_MIN
- || i_y + i_radius > REGIS_DEVICE_Y_MAX)
-
- {
- plPath *oldpath = _plotter->drawstate->path;
-
- _plotter->drawstate->path = _flatten_path (oldpath);
- _plotter->paint_path (S___(_plotter));
- _delete_plPath (_plotter->drawstate->path);
- _plotter->drawstate->path = oldpath;
- }
- else
-
- {
- if (_plotter->drawstate->fill_type)
-
- {
- _pl_r_set_fill_color (S___(_plotter));
- _pl_r_regis_move (R___(_plotter) i_x, i_y);
- if (i_radius > 0)
- {
- sprintf (tmpbuf, "F(C[+%d])\n", i_radius);
- _plotter->regis_position_is_unknown = true;
- }
- else
- sprintf (tmpbuf, "V[]\n");
- _write_string (_plotter->data, tmpbuf);
- }
-
- if (_plotter->drawstate->pen_type)
-
- {
- _pl_r_set_attributes (S___(_plotter));
- _pl_r_set_pen_color (S___(_plotter));
- _pl_r_regis_move (R___(_plotter) i_x, i_y);
- if (i_radius > 0)
- {
- sprintf (tmpbuf, "C[+%d]\n", i_radius);
- _plotter->regis_position_is_unknown = true;
- }
- else
- sprintf (tmpbuf, "V[]\n");
- _write_string (_plotter->data, tmpbuf);
- }
- }
- }
- break;
- default:
- break;
- }
- }
- void
- _pl_r_regis_move (R___(Plotter *_plotter) int xx, int yy)
- {
- char tmpbuf[32];
- plIntPoint newpoint;
-
-
- if (xx < REGIS_DEVICE_X_MIN || xx > REGIS_DEVICE_X_MAX
- || yy < REGIS_DEVICE_Y_MIN || yy > REGIS_DEVICE_Y_MAX)
- return;
- newpoint.x = xx;
- newpoint.y = yy;
- if (_plotter->regis_position_is_unknown)
- {
- sprintf (tmpbuf, "P[%d,%d]\n", xx, yy);
- _write_string (_plotter->data, tmpbuf);
- }
- else if (xx != _plotter->regis_pos.x || yy != _plotter->regis_pos.y)
- {
- _write_string (_plotter->data, "P");
- _emit_regis_vector (_plotter->regis_pos, newpoint, false, tmpbuf);
- _write_string (_plotter->data, tmpbuf);
- _write_string (_plotter->data, "\n");
- }
-
- _plotter->regis_position_is_unknown = false;
- _plotter->regis_pos = newpoint;
- }
- static void
- _emit_regis_vector (plIntPoint istart, plIntPoint iend, bool skip_null, char *tmpbuf)
- {
- plIntVector v;
- bool xneg = false, yneg = false;
- char xrelbuf[32], yrelbuf[32], xbuf[32], ybuf[32];
- int xrellen, yrellen, xlen, ylen;
- char *x, *y;
- v.x = iend.x - istart.x;
- v.y = iend.y - istart.y;
-
- if (v.x == 0 && v.y == 0)
- {
- if (skip_null == false)
- sprintf (tmpbuf, "[]");
- else
- *tmpbuf = '\0';
- return;
- }
-
- if (v.x < 0)
- {
- xneg = true;
- v.x = -v.x;
- }
- if (v.y < 0)
- {
- yneg = true;
- v.y = -v.y;
- }
- sprintf (xrelbuf, "%s%d", (xneg ? "-" : "+"), v.x);
- xrellen = strlen (xrelbuf);
- sprintf (yrelbuf, "%s%d", (yneg ? "-" : "+"), v.y);
- yrellen = strlen (yrelbuf);
- sprintf (xbuf, "%d", iend.x);
- xlen = strlen (xbuf);
- sprintf (ybuf, "%d", iend.y);
- ylen = strlen (ybuf);
-
-
- x = (xrellen <= xlen ? xrelbuf : xbuf);
- y = (yrellen <= ylen ? yrelbuf : ybuf);
-
- if (v.x == 0)
- sprintf (tmpbuf, "[,%s]", y);
- else if (v.y == 0)
- sprintf (tmpbuf, "[%s]", x);
- else
- sprintf (tmpbuf, "[%s,%s]", x, y);
- }
- bool
- _pl_r_paint_paths (S___(Plotter *_plotter))
- {
- return false;
- }
- bool
- _pl_r_path_is_flushable (S___(Plotter *_plotter))
- {
- return true;
- }
- void
- _pl_r_maybe_prepaint_segments (R___(Plotter *_plotter) int prev_num_segments)
- {
- }
|