123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612 |
- #include "sys-defines.h"
- #include "extern.h"
- #include "xmi.h"
- #define DIST(p1, p2) sqrt( ((p1).x - (p2).x) * ((p1).x - (p2).x) \
- + ((p1).y - (p2).y) * ((p1).y - (p2).y))
- void
- _pl_i_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:
- {
- int i, polyline_len;
- bool identical_user_coordinates = true;
- double xu_last, yu_last;
- miGC *pGC;
- miPoint *miPoints, offset;
- miPixel fgPixel, bgPixel;
- miPixel pixels[2];
- plPoint p0, p1, pc;
-
-
- if (_plotter->drawstate->path->num_segments == 0)
- break;
- if (_plotter->drawstate->path->num_segments == 1)
- break;
- if (_plotter->drawstate->path->num_segments == 2
- && _plotter->drawstate->path->segments[1].type == S_ARC)
-
- {
- p0 = _plotter->drawstate->path->segments[0].p;
- p1 = _plotter->drawstate->path->segments[1].p;
- pc = _plotter->drawstate->path->segments[1].pc;
-
-
- _pl_i_draw_elliptic_arc (R___(_plotter) p0, p1, pc);
- break;
- }
- if (_plotter->drawstate->path->num_segments == 2
- && _plotter->drawstate->path->segments[1].type == S_ELLARC)
-
- {
- p0 = _plotter->drawstate->path->segments[0].p;
- p1 = _plotter->drawstate->path->segments[1].p;
- pc = _plotter->drawstate->path->segments[1].pc;
-
-
- _pl_i_draw_elliptic_arc_2 (R___(_plotter) p0, p1, pc);
-
- break;
- }
-
-
- miPoints = (miPoint *)_pl_xmalloc (_plotter->drawstate->path->num_segments * sizeof(miPoint));
- polyline_len = 0;
- xu_last = 0.0;
- yu_last = 0.0;
- identical_user_coordinates = true;
- for (i = 0; i < _plotter->drawstate->path->num_segments; i++)
- {
- double xu, yu;
- int device_x, device_y;
-
- xu = _plotter->drawstate->path->segments[i].p.x;
- yu = _plotter->drawstate->path->segments[i].p.y;
- if (i > 0 && (xu != xu_last || yu != yu_last))
-
- identical_user_coordinates = false;
- device_x = IROUND(XD(xu, yu));
- device_y = IROUND(YD(xu, yu));
- if ((polyline_len == 0)
- || (device_x != miPoints[polyline_len-1].x)
- || (device_y != miPoints[polyline_len-1].y))
-
- {
- miPoints[polyline_len].x = device_x;
- miPoints[polyline_len].y = device_y;
- polyline_len++;
- }
- xu_last = xu;
- yu_last = yu;
- }
-
-
- bgPixel.type = MI_PIXEL_INDEX_TYPE;
- bgPixel.u.index = _plotter->drawstate->i_bg_color_index;
- pixels[0] = bgPixel;
- pixels[1] = bgPixel;
-
-
- pGC = miNewGC (2, pixels);
- _set_common_mi_attributes (_plotter->drawstate, (void *)pGC);
-
- if (_plotter->drawstate->fill_type)
-
- {
-
- miPolygonShape polygon_shape
- = (_plotter->drawstate->path->primitive ? MI_SHAPE_CONVEX : MI_SHAPE_GENERAL);
-
-
- _pl_i_set_fill_color (S___(_plotter));
- fgPixel.type = MI_PIXEL_INDEX_TYPE;
- fgPixel.u.index = _plotter->drawstate->i_fill_color_index;
- pixels[0] = bgPixel;
- pixels[1] = fgPixel;
- miSetGCPixels (pGC, 2, pixels);
-
-
- if (_plotter->drawstate->path->num_segments > 1
- && polyline_len == 1)
-
- miDrawPoints ((miPaintedSet *)_plotter->i_painted_set, pGC,
- MI_COORD_MODE_ORIGIN, 1, miPoints);
- else
-
- miFillPolygon ((miPaintedSet *)_plotter->i_painted_set, pGC,
- polygon_shape,
- MI_COORD_MODE_ORIGIN, polyline_len, miPoints);
- }
-
- if (_plotter->drawstate->pen_type)
-
- {
-
- _pl_i_set_pen_color (S___(_plotter));
- fgPixel.type = MI_PIXEL_INDEX_TYPE;
- fgPixel.u.index = _plotter->drawstate->i_pen_color_index;
- pixels[0] = bgPixel;
- pixels[1] = fgPixel;
- miSetGCPixels (pGC, 2, pixels);
-
- if (polyline_len == 1)
-
- {
- if (identical_user_coordinates == false
- || _plotter->drawstate->cap_type == PL_CAP_ROUND)
- {
- unsigned int sp_size
- = (unsigned int)_plotter->drawstate->quantized_device_line_width;
- if (sp_size == 0)
- sp_size = 1;
-
- if (sp_size == 1)
-
- miDrawPoints ((miPaintedSet *)_plotter->i_painted_set, pGC,
- MI_COORD_MODE_ORIGIN, 1, miPoints);
- else
-
- {
- int sp_offset;
- miArc arc;
-
- sp_offset =
- (_plotter->drawstate->quantized_device_line_width + 1) / 2;
- arc.x = miPoints[0].x - sp_offset;
- arc.y = miPoints[0].y - sp_offset;
- arc.width = sp_size;
- arc.height = sp_size;
- arc.angle1 = 0;
- arc.angle2 = 64 * 360;
- miFillArcs ((miPaintedSet *)_plotter->i_painted_set,
- pGC, 1, &arc);
- }
- }
- }
- else
-
- miDrawLines ((miPaintedSet *)_plotter->i_painted_set, pGC,
- MI_COORD_MODE_ORIGIN, polyline_len, miPoints);
- }
-
-
- miDeleteGC (pGC);
- free (miPoints);
-
-
- offset.x = 0;
- offset.y = 0;
- miCopyPaintedSetToCanvas ((miPaintedSet *)_plotter->i_painted_set,
- (miCanvas *)_plotter->i_canvas,
- offset);
- miClearPaintedSet ((miPaintedSet *)_plotter->i_painted_set);
- }
-
-
- _plotter->i_frame_nonempty = true;
- break;
-
- case (int)PATH_ELLIPSE:
- {
- int ninetymult;
- int x_orientation, y_orientation;
- int xorigin, yorigin;
- unsigned int squaresize_x, squaresize_y;
- plPoint pc;
- double rx, ry, angle;
- pc = _plotter->drawstate->path->pc;
- rx = _plotter->drawstate->path->rx;
- ry = _plotter->drawstate->path->ry;
- angle = _plotter->drawstate->path->angle;
-
- ninetymult = IROUND(angle / 90.0);
- if (angle == (double) (90 * ninetymult))
- {
- angle = 0.0;
- if (ninetymult % 2)
- {
- double temp;
-
- temp = rx;
- rx = ry;
- ry = temp;
- }
- }
-
- rx = (rx < 0.0 ? -rx : rx);
- ry = (ry < 0.0 ? -ry : ry);
-
-
- x_orientation = (_plotter->drawstate->transform.m[0] >= 0 ? 1 : -1);
- y_orientation = (_plotter->drawstate->transform.m[3] >= 0 ? 1 : -1);
-
-
- xorigin = IROUND(XD(pc.x - x_orientation * rx,
- pc.y - y_orientation * ry));
- yorigin = IROUND(YD(pc.x - x_orientation * rx,
- pc.y - y_orientation * ry));
- squaresize_x = (unsigned int)IROUND(XDV(2 * x_orientation * rx, 0.0));
- squaresize_y = (unsigned int)IROUND(YDV(0.0, 2 * y_orientation * ry));
-
-
- _pl_i_draw_elliptic_arc_internal (R___(_plotter)
- xorigin, yorigin,
- squaresize_x, squaresize_y,
- 0, 64 * 360);
- }
- break;
-
- default:
- break;
- }
- }
- void
- _pl_i_draw_elliptic_arc (R___(Plotter *_plotter) plPoint p0, plPoint p1, plPoint pc)
- {
- double radius;
- double theta0, theta1;
- int startangle, anglerange;
- int x_orientation, y_orientation;
- int xorigin, yorigin;
- unsigned int squaresize_x, squaresize_y;
-
- x_orientation = (_plotter->drawstate->transform.m[0] >= 0 ? 1 : -1);
- y_orientation = (_plotter->drawstate->transform.m[3] >= 0 ? 1 : -1);
-
- radius = DIST(pc, p0);
-
- xorigin = IROUND(XD(pc.x - x_orientation * radius,
- pc.y - y_orientation * radius));
- yorigin = IROUND(YD(pc.x - x_orientation * radius,
- pc.y - y_orientation * radius));
- squaresize_x = (unsigned int)IROUND(XDV(2 * x_orientation * radius, 0.0));
- squaresize_y = (unsigned int)IROUND(YDV(0.0, 2 * y_orientation * radius));
- theta0 = _xatan2 (-y_orientation * (p0.y - pc.y),
- x_orientation * (p0.x - pc.x)) / M_PI;
- theta1 = _xatan2 (-y_orientation * (p1.y - pc.y),
- x_orientation * (p1.x - pc.x)) / M_PI;
- if (theta1 < theta0)
- theta1 += 2.0;
- if (theta0 < 0.0)
- {
- theta0 += 2.0;
- theta1 += 2.0;
- }
- if (theta1 - theta0 > 1.0)
- {
- double tmp;
-
- tmp = theta0;
- theta0 = theta1;
- theta1 = tmp;
- theta1 += 2.0;
- }
- if (theta0 >= 2.0 && theta1 >= 2.0)
-
- {
- theta0 -= 2.0;
- theta1 -= 2.0;
- }
- startangle = IROUND(64 * theta0 * 180.0);
- anglerange = IROUND(64 * (theta1 - theta0) * 180.0);
- _pl_i_draw_elliptic_arc_internal (R___(_plotter)
- xorigin, yorigin,
- squaresize_x, squaresize_y,
- startangle, anglerange);
- }
- void
- _pl_i_draw_elliptic_arc_2 (R___(Plotter *_plotter) plPoint p0, plPoint p1, plPoint pc)
- {
- double rx, ry;
- double x0, y0, x1, y1, xc, yc;
- int startangle, endangle, anglerange;
- int x_orientation, y_orientation;
- int xorigin, yorigin;
- unsigned int squaresize_x, squaresize_y;
-
- x_orientation = (_plotter->drawstate->transform.m[0] >= 0 ? 1 : -1);
- y_orientation = (_plotter->drawstate->transform.m[3] >= 0 ? 1 : -1);
- xc = pc.x, yc = pc.y;
- x0 = p0.x, y0 = p0.y;
- x1 = p1.x, y1 = p1.y;
- if (y0 == yc && x1 == xc)
-
- {
-
- rx = (x0 > xc) ? x0 - xc : xc - x0;
- ry = (y1 > yc) ? y1 - yc : yc - y1;
-
- startangle = ((x0 > xc ? 1 : -1) * x_orientation == 1) ? 0 : 180;
- endangle = ((y1 > yc ? 1 : -1) * y_orientation == -1) ? 90 : 270;
- }
- else
-
- {
-
- rx = (x1 > xc) ? x1 - xc : xc - x1;
- ry = (y0 > yc) ? y0 - yc : yc - y0;
-
- startangle = ((y0 > yc ? 1 : -1) * y_orientation == -1) ? 90 : 270;
- endangle = ((x1 > xc ? 1 : -1) * x_orientation == 1) ? 0 : 180;
- }
- if (endangle < startangle)
- endangle += 360;
- anglerange = endangle - startangle;
-
- if (anglerange == 270)
- {
- int tmp;
- tmp = startangle;
- startangle = endangle;
- endangle = tmp;
- anglerange = 90;
- }
-
- if (startangle >= 360)
-
- startangle -= 360;
-
- xorigin = IROUND(XD(xc - x_orientation * rx,
- yc - y_orientation * ry));
- yorigin = IROUND(YD(xc - x_orientation * rx,
- yc - y_orientation * ry));
- squaresize_x = (unsigned int)IROUND(XDV(2 * x_orientation * rx, 0.0));
- squaresize_y = (unsigned int)IROUND(YDV(0.0, 2 * y_orientation * ry));
-
-
- startangle *= 64;
- anglerange *= 64;
- _pl_i_draw_elliptic_arc_internal (R___(_plotter)
- xorigin, yorigin,
- squaresize_x, squaresize_y,
- startangle, anglerange);
- }
- void
- _pl_i_draw_elliptic_arc_internal (R___(Plotter *_plotter) int xorigin, int yorigin, unsigned int squaresize_x, unsigned int squaresize_y, int startangle, int anglerange)
- {
- miGC *pGC;
- miArc arc;
- miPixel fgPixel, bgPixel;
- miPixel pixels[2];
- miPoint offset;
-
- bgPixel.type = MI_PIXEL_INDEX_TYPE;
- bgPixel.u.index = _plotter->drawstate->i_bg_color_index;
- pixels[0] = bgPixel;
- pixels[1] = bgPixel;
-
-
- pGC = miNewGC (2, pixels);
- _set_common_mi_attributes (_plotter->drawstate, pGC);
-
-
- arc.x = xorigin;
- arc.y = yorigin;
- arc.width = squaresize_x;
- arc.height = squaresize_y;
- arc.angle1 = startangle;
- arc.angle2 = anglerange;
-
- if (_plotter->drawstate->fill_type)
-
- {
-
- _pl_i_set_fill_color (S___(_plotter));
- fgPixel.type = MI_PIXEL_INDEX_TYPE;
- fgPixel.u.index = _plotter->drawstate->i_fill_color_index;
- pixels[0] = bgPixel;
- pixels[1] = fgPixel;
- miSetGCPixels (pGC, 2, pixels);
-
-
- if (squaresize_x <= 1 || squaresize_y <= 1)
-
- {
- miPoint point;
- point.x = xorigin;
- point.y = yorigin;
- miDrawPoints ((miPaintedSet *)_plotter->i_painted_set,
- pGC, MI_COORD_MODE_ORIGIN, 1, &point);
- }
- else
-
- miFillArcs ((miPaintedSet *)_plotter->i_painted_set, pGC, 1, &arc);
- }
-
- if (_plotter->drawstate->pen_type)
-
- {
- unsigned int sp_size = 0;
-
- _pl_i_set_pen_color (S___(_plotter));
- fgPixel.type = MI_PIXEL_INDEX_TYPE;
- fgPixel.u.index = _plotter->drawstate->i_pen_color_index;
- pixels[0] = bgPixel;
- pixels[1] = fgPixel;
- miSetGCPixels (pGC, 2, pixels);
-
- if (squaresize_x <= 1 || squaresize_y <= 1)
-
- {
- int sp_offset;
- sp_size
- = (unsigned int)_plotter->drawstate->quantized_device_line_width;
- sp_offset
- = (int)(_plotter->drawstate->quantized_device_line_width + 1) / 2;
-
- if (sp_size == 0)
- sp_size = 1;
- arc.x -= sp_offset;
- arc.y -= sp_offset;
- arc.width = sp_size;
- arc.height = sp_size;
- arc.angle1 = 0;
- arc.angle2 = 64 * 360;
- }
-
-
- if (squaresize_x <= 1 || squaresize_y <= 1)
-
- {
- if (sp_size == 1)
-
- {
- miPoint point;
-
- point.x = xorigin;
- point.y = yorigin;
- miDrawPoints ((miPaintedSet *)_plotter->i_painted_set,
- pGC, MI_COORD_MODE_ORIGIN, 1, &point);
- }
- else
-
- miFillArcs((miPaintedSet *)_plotter->i_painted_set, pGC, 1, &arc);
- }
- else
-
- miDrawArcs_r ((miPaintedSet *)_plotter->i_painted_set, pGC, 1, &arc,
- (miEllipseCache *)(_plotter->i_arc_cache_data));
- }
-
-
- miDeleteGC (pGC);
-
-
- offset.x = 0;
- offset.y = 0;
- miCopyPaintedSetToCanvas ((miPaintedSet *)_plotter->i_painted_set,
- (miCanvas *)_plotter->i_canvas,
- offset);
- miClearPaintedSet ((miPaintedSet *)_plotter->i_painted_set);
- }
- bool
- _pl_i_paint_paths (S___(Plotter *_plotter))
- {
- return false;
- }
|