123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616 |
- #include "sys-defines.h"
- #include "extern.h"
- #define DIST(p0,p1) (sqrt( ((p0).x - (p1).x)*((p0).x - (p1).x) \
- + ((p0).y - (p1).y)*((p0).y - (p1).y)))
- void
- _pl_h_paint_path (S___(Plotter *_plotter))
- {
- if (_plotter->drawstate->pen_type == 0
- && _plotter->drawstate->fill_type == 0)
-
- return;
- switch ((int)_plotter->drawstate->path->type)
- {
- case (int)PATH_SEGMENT_LIST:
- {
- plIntPathSegment *xarray;
- plPoint p0, pp1, pc, savedpoint;
- bool closed, use_polygon_buffer;
- double last_x, last_y;
- int i, polyline_len;
- bool identical_user_coordinates = true;
-
- if (_plotter->drawstate->path->num_segments == 0)
- break;
- if (_plotter->drawstate->path->num_segments == 1)
- break;
- if ((_plotter->drawstate->path->num_segments >= 3)
- && (_plotter->drawstate->path->segments[_plotter->drawstate->path->num_segments - 1].p.x == _plotter->drawstate->path->segments[0].p.x)
- && (_plotter->drawstate->path->segments[_plotter->drawstate->path->num_segments - 1].p.y == _plotter->drawstate->path->segments[0].p.y))
- closed = true;
- else
- closed = false;
-
-
-
-
- xarray = (plIntPathSegment *)_pl_xmalloc (_plotter->drawstate->path->num_segments * sizeof(plIntPathSegment));
-
-
- xarray[0].p.x = IROUND(XD(_plotter->drawstate->path->segments[0].p.x,
- _plotter->drawstate->path->segments[0].p.y));
- xarray[0].p.y = IROUND(YD(_plotter->drawstate->path->segments[0].p.x,
- _plotter->drawstate->path->segments[0].p.y));
- polyline_len = 1;
-
- last_x = _plotter->drawstate->path->segments[0].p.x;
- last_y = _plotter->drawstate->path->segments[0].p.y;
-
- for (i = 1; i < _plotter->drawstate->path->num_segments; i++)
- {
- plPathSegment datapoint;
- double xuser, yuser, xdev, ydev;
- int device_x, device_y;
-
- datapoint = _plotter->drawstate->path->segments[i];
- xuser = datapoint.p.x;
- yuser = datapoint.p.y;
- if (xuser != last_x || yuser != last_y)
-
- identical_user_coordinates = false;
-
- xdev = XD(xuser, yuser);
- ydev = YD(xuser, yuser);
- device_x = IROUND(xdev);
- device_y = IROUND(ydev);
-
- if (device_x != xarray[polyline_len-1].p.x
- || device_y != xarray[polyline_len-1].p.y)
-
- {
- plPathSegmentType element_type;
- int device_xc, device_yc;
-
- xarray[polyline_len].p.x = device_x;
- xarray[polyline_len].p.y = device_y;
- element_type = datapoint.type;
- xarray[polyline_len].type = element_type;
-
- if (element_type == S_ARC)
-
- {
- double angle;
-
- device_xc = IROUND(XD(datapoint.pc.x, datapoint.pc.y));
- device_yc = IROUND(YD(datapoint.pc.x, datapoint.pc.y));
- xarray[polyline_len].pc.x = device_xc;
- xarray[polyline_len].pc.y = device_yc;
- p0.x = last_x;
- p0.y = last_y;
- pp1 = datapoint.p;
- pc = datapoint.pc;
- angle = _angle_of_arc (p0, pp1, pc);
-
- if (!_plotter->drawstate->transform.nonreflection)
- angle = -angle;
- xarray[polyline_len].angle = angle;
- }
- else if (element_type == S_CUBIC)
-
- {
- xarray[polyline_len].pc.x
- = IROUND(XD(datapoint.pc.x, datapoint.pc.y));
- xarray[polyline_len].pc.y
- = IROUND(YD(datapoint.pc.x, datapoint.pc.y));
- xarray[polyline_len].pd.x
- = IROUND(XD(datapoint.pd.x, datapoint.pd.y));
- xarray[polyline_len].pd.y
- = IROUND(YD(datapoint.pd.x, datapoint.pd.y));
- }
-
-
- last_x = datapoint.p.x;
- last_y = datapoint.p.y;
- polyline_len++;
- }
- }
-
-
-
- if (_plotter->drawstate->path->num_segments > 1 && polyline_len == 1)
-
- {
- if (identical_user_coordinates == false
- || _plotter->drawstate->cap_type == PL_CAP_ROUND)
- {
- double r = 0.5 * _plotter->drawstate->line_width;
- double device_frame_radius;
-
-
-
-
- savedpoint = _plotter->drawstate->pos;
- _plotter->drawstate->pos =
- _plotter->drawstate->path->segments[0].p;
- _pl_h_set_position (S___(_plotter));
- _plotter->drawstate->pos = savedpoint;
-
-
- {
-
- _pl_h_set_fill_color (R___(_plotter) true);
- _pl_h_set_attributes (S___(_plotter));
- }
-
- device_frame_radius =
- sqrt(XDV(r,0)*XDV(r,0)+YDV(r,0)*YDV(r,0));
-
-
- if (_plotter->hpgl_bad_pen == false)
-
- {
- sprintf (_plotter->data->page->point, "WG%d,0,360;",
- IROUND(device_frame_radius));
- _update_buffer (_plotter->data->page);
- }
-
- if (_plotter->hpgl_version < 2)
- _pl_h_set_attributes (S___(_plotter));
- }
-
-
- free (xarray);
- break;
- }
-
-
-
-
- use_polygon_buffer = (_plotter->hpgl_version == 2
- || (_plotter->hpgl_version == 1
- && (polyline_len > 2
- || _plotter->drawstate->fill_type)) ? true : false);
-
-
- _pl_h_set_pen_color (R___(_plotter) HPGL_OBJECT_PATH);
-
-
- if (_plotter->hpgl_bad_pen && _plotter->hpgl_version == 1)
- {
-
- free (xarray);
- break;
- }
-
-
- _pl_h_set_attributes (S___(_plotter));
-
- savedpoint = _plotter->drawstate->pos;
- _plotter->drawstate->pos = _plotter->drawstate->path->segments[0].p;
- _pl_h_set_position (S___(_plotter));
- _plotter->drawstate->pos = savedpoint;
-
- if (use_polygon_buffer)
-
- {
-
- strcpy (_plotter->data->page->point, "PM0;");
- _update_buffer (_plotter->data->page);
- }
-
- if (use_polygon_buffer || _plotter->drawstate->pen_type)
-
- {
-
- if (_plotter->hpgl_pendown == false)
- {
- strcpy (_plotter->data->page->point, "PD;");
- _update_buffer (_plotter->data->page);
- _plotter->hpgl_pendown = true;
- }
-
-
- i = 1;
- while (i < polyline_len)
- {
- switch ((int)xarray[i].type)
- {
- case (int)S_LINE:
-
- strcpy (_plotter->data->page->point, "PA");
- _update_buffer (_plotter->data->page);
- sprintf (_plotter->data->page->point, "%d,%d",
- xarray[i].p.x, xarray[i].p.y);
- _update_buffer (_plotter->data->page);
- i++;
- while (i < polyline_len && xarray[i].type == S_LINE)
- {
- sprintf (_plotter->data->page->point,
- ",%d,%d", xarray[i].p.x, xarray[i].p.y);
- _update_buffer (_plotter->data->page);
- i++;
- }
- sprintf (_plotter->data->page->point, ";");
- _update_buffer (_plotter->data->page);
- break;
-
- case (int)S_CUBIC:
-
- strcpy (_plotter->data->page->point, "BZ");
- _update_buffer (_plotter->data->page);
- sprintf (_plotter->data->page->point, "%d,%d,%d,%d,%d,%d",
- xarray[i].pc.x, xarray[i].pc.y,
- xarray[i].pd.x, xarray[i].pd.y,
- xarray[i].p.x, xarray[i].p.y);
- _update_buffer (_plotter->data->page);
- i++;
- while (i < polyline_len && xarray[i].type == S_CUBIC)
- {
- sprintf (_plotter->data->page->point, ",%d,%d,%d,%d,%d,%d",
- xarray[i].pc.x, xarray[i].pc.y,
- xarray[i].pd.x, xarray[i].pd.y,
- xarray[i].p.x, xarray[i].p.y);
- _update_buffer (_plotter->data->page);
- i++;
- }
- sprintf (_plotter->data->page->point, ";");
- _update_buffer (_plotter->data->page);
- break;
-
- case (int)S_ARC:
- {
- double degrees;
- int int_degrees;
-
- degrees = 180.0 * xarray[i].angle / M_PI;
- int_degrees = IROUND (degrees);
- if (_plotter->hpgl_version > 0)
-
- {
- if (degrees == (double)int_degrees)
- sprintf (_plotter->data->page->point, "AA%d,%d,%d;",
- xarray[i].pc.x, xarray[i].pc.y,
- int_degrees);
- else
- sprintf (_plotter->data->page->point, "AA%d,%d,%.3f;",
- xarray[i].pc.x, xarray[i].pc.y,
- degrees);
- }
- else
-
-
- sprintf (_plotter->data->page->point, "AA%d,%d,%d;",
- xarray[i].pc.x, xarray[i].pc.y,
- int_degrees);
- _update_buffer (_plotter->data->page);
- i++;
- }
- break;
-
- default:
-
- i++;
- break;
- }
- }
- }
-
- if (use_polygon_buffer)
-
- {
- if (!closed)
-
- {
- strcpy (_plotter->data->page->point, "PU;");
- _update_buffer (_plotter->data->page);
- _plotter->hpgl_pendown = false;
- strcpy (_plotter->data->page->point, "PM2;");
- _update_buffer (_plotter->data->page);
- }
- else
-
- {
- strcpy (_plotter->data->page->point, "PM2;");
- _update_buffer (_plotter->data->page);
- strcpy (_plotter->data->page->point, "PU;");
- _update_buffer (_plotter->data->page);
- _plotter->hpgl_pendown = false;
- }
-
- if (_plotter->drawstate->fill_type)
-
- {
-
- _pl_h_set_fill_color (R___(_plotter) false);
- if (_plotter->hpgl_bad_pen == false)
-
- {
- switch (_plotter->drawstate->fill_rule_type)
- {
- case PL_FILL_ODD_WINDING:
- default:
- strcpy (_plotter->data->page->point, "FP;");
- break;
- case PL_FILL_NONZERO_WINDING:
- if (_plotter->hpgl_version == 2)
- strcpy (_plotter->data->page->point, "FP1;");
- else
- strcpy (_plotter->data->page->point, "FP;");
- break;
- }
- _update_buffer (_plotter->data->page);
- }
-
- if (_plotter->hpgl_version < 2)
- _pl_h_set_attributes (S___(_plotter));
- }
-
- if (_plotter->drawstate->pen_type)
-
- {
-
- _pl_h_set_pen_color (R___(_plotter) HPGL_OBJECT_PATH);
- if (_plotter->hpgl_bad_pen == false)
-
- {
- _pl_h_set_pen_color (R___(_plotter) HPGL_OBJECT_PATH);
- strcpy (_plotter->data->page->point, "EP;");
- _update_buffer (_plotter->data->page);
- }
- }
- }
-
-
- _plotter->hpgl_position_is_unknown = true;
-
-
- free (xarray);
- }
- break;
-
- case (int)PATH_BOX:
- {
- plPoint p0, p1, savedpoint;
- p0 = _plotter->drawstate->path->p0;
- p1 = _plotter->drawstate->path->p1;
-
- _pl_h_set_attributes (S___(_plotter));
-
- savedpoint = _plotter->drawstate->pos;
- _plotter->drawstate->pos = p0;
- _pl_h_set_position (S___(_plotter));
- _plotter->drawstate->pos = savedpoint;
-
- if (_plotter->drawstate->fill_type)
-
- {
-
- _pl_h_set_fill_color (R___(_plotter) false);
- if (_plotter->hpgl_bad_pen == false)
-
- {
- sprintf (_plotter->data->page->point, "RA%d,%d;",
- IROUND(XD(p1.x,p1.y)), IROUND(YD(p1.x,p1.y)));
- _update_buffer (_plotter->data->page);
- }
-
- if (_plotter->hpgl_version < 2)
- _pl_h_set_attributes (S___(_plotter));
- }
-
- if (_plotter->drawstate->pen_type)
-
- {
-
- _pl_h_set_pen_color (R___(_plotter) HPGL_OBJECT_PATH);
- if (_plotter->hpgl_bad_pen == false)
-
- {
- sprintf (_plotter->data->page->point, "EA%d,%d;",
- IROUND(XD(p1.x,p1.y)), IROUND(YD(p1.x,p1.y)));
- _update_buffer (_plotter->data->page);
- }
- }
- }
- break;
- case (int)PATH_CIRCLE:
- {
- plPoint pc, savedpoint;
- double r = _plotter->drawstate->path->radius;
- double radius = sqrt(XDV(r,0)*XDV(r,0)+YDV(r,0)*YDV(r,0));
- pc = _plotter->drawstate->path->pc;
-
-
- _pl_h_set_attributes (S___(_plotter));
- savedpoint = _plotter->drawstate->pos;
- _plotter->drawstate->pos = pc;
- _pl_h_set_position (S___(_plotter));
- _plotter->drawstate->pos = savedpoint;
-
- if (_plotter->drawstate->fill_type)
-
- {
-
- _pl_h_set_fill_color (R___(_plotter) false);
- if (_plotter->hpgl_bad_pen == false)
-
- {
- sprintf (_plotter->data->page->point, "WG%d,0,360;",
- IROUND(radius));
- _update_buffer (_plotter->data->page);
- }
-
- if (_plotter->hpgl_version < 2)
- _pl_h_set_attributes (S___(_plotter));
- }
-
- if (_plotter->drawstate->pen_type)
-
- {
-
- _pl_h_set_pen_color (R___(_plotter) HPGL_OBJECT_PATH);
- if (_plotter->hpgl_bad_pen == false)
-
- {
- sprintf (_plotter->data->page->point, "CI%d;", IROUND(radius));
- _update_buffer (_plotter->data->page);
- }
- }
- }
- break;
- default:
- break;
- }
- }
- void
- _pl_h_set_position (S___(Plotter *_plotter))
- {
- int xnew, ynew;
-
-
- xnew = IROUND(XD(_plotter->drawstate->pos.x, _plotter->drawstate->pos.y));
- ynew = IROUND(YD(_plotter->drawstate->pos.x, _plotter->drawstate->pos.y));
- if (_plotter->hpgl_position_is_unknown == true
- || xnew != _plotter->hpgl_pos.x || ynew != _plotter->hpgl_pos.y)
- {
- if (_plotter->hpgl_pendown == true)
- {
- sprintf (_plotter->data->page->point, "PU;PA%d,%d;", xnew, ynew);
- _plotter->hpgl_pendown = false;
- }
- else
- sprintf (_plotter->data->page->point, "PA%d,%d;", xnew, ynew);
- _update_buffer (_plotter->data->page);
-
- _plotter->hpgl_position_is_unknown = false;
- _plotter->hpgl_pos.x = xnew;
- _plotter->hpgl_pos.y = ynew;
- }
- }
- bool
- _pl_h_paint_paths (S___(Plotter *_plotter))
- {
- return false;
- }
|